Its not a buffer limit or an output limit as it perf data is all at the very end of the string, here is my code-
Code: Select all
$adaptername = @()
$adapterdevice = @()
$adaptercount = @()
$num = 0
$out = ""
#Get any warning or critical levels
foreach ($arg in $args) {
$split = $arg.split('=')
if ($split[0] -like "warn") {
$warn = $split[1]
$warn = [int]$warn
}
elseif ($split[0] -like "crit") {
$crit = $split[1]
$crit = [int]$crit
}
}
#Get all connected network devices
$adapterdevice += Get-WmiObject -Class Win32_NetworkAdapter -filter "NetconnectionStatus = '2'" | Select -expand Name
#Find their names
foreach ($adapter in $adapterdevice) {
$adaptername += Get-WmiObject -Class Win32_NetworkAdapter -filter "Name = '$adapter'" | Select -expand NetconnectionID
}
#Find the total bytes per second
foreach ($device in $adapterdevice) {
#Perfmon doesnt like certain characters
$device = $device -replace "[(]","["
$device = $device -replace "[)]","]"
$device = $device -replace "#","_"
$getcount = Get-counter -Counter "\Network Interface($device)\Bytes Total/sec"
$getcount = $getcount.CounterSamples | Select -expand CookedValue
#Turn it into kb
$getcount = ($getcount)/1kb
#round up to nearest whole number
$getcount = "{0:N0}" -f $getcount
$adaptercount += $getcount
#Build the output string
$out += $adaptername[$num] + " : " + $adaptercount[$num] + "<BR>"
$num++
}
$num = 0
#Check if any of them should alert and create perfdata
foreach ($adapter in $adaptercount) {
$adapter = [int]$adapter
$perfdata += "|'" + $adaptername[$num] + "'=" + $adapter + ";" + $warn + ";" + $crit
$num++
if ($warn) {
if ($adapter -ge $warn) { $exitcode = 1 }
}
if ($crit) {
if ($adapter -ge $crit) { $exitcode = 2 }
}
if (!$exitcode) { $exitcode = 0 }
}
#Add perfdata to the end of the return
$out += $perfdata
echo $out
exit $exitcode
This is my command in NSC.ini:
Code: Select all
check_network_adapter = cmd /c echo scripts\\networkadapters.ps1 "$ARG1$" "$ARG2$"; | powershell.exe -command -
Code: Select all
/usr/local/nagios/libexec/check_nrpe -H bcdvmgt01 -t 60 -c check_network_adapter -a warn=100 crit=1000
Code: Select all
Production Adapter - Secondary : 28<BR>Production Adapter - Primary : 44<BR>|'Production Adapter - Secondary'=28;100;1000|'Production Adapter - Primary'=44;100;1000
Code: Select all
Production Adapter - Primary : 4<BR>|'Production Adapter - Primary'=4;100;1000
Any thoughts?