I'm using NSCLient to run some NRPE checks on Windows Server boxes. The checks run Powershell scripts but the problem I'm having is NSClient is adding random line breaks after 79 characters. I'm guessing this is because the default Powershell/CMD console width is 80 characters (Is this right?) but I need the check to not add these new lines (They screw up the performance data and Nagios get's upset).
I've tried changing the console size from a standard Powershell instance but that didn't work, is there any way to specify the console size with a command line flag? The help files weren't much use.
An example of the output I'm getting from Nagios' check_nrpe
vmxnet3 ethernet adapter _2:728.370961294234isatap.{1c6435bc-27c9-452b-a6fe-668^M
dced31461}:0| 'Network Usage (Bytes/sec) (vmxnet3 ethernet adapter _2)'=728.370^M
961294234 'Network Usage (Bytes/sec) (isatap.{1c6435bc-27c9-452b-a6fe-668dced31^M
461})'=0
(The issue isn't with the control characters, Nagios doesn't seem to notice them, but the new-lines themselves)
Powershell script;
#
# Check Network Usage
#
#Check for argument variables
if ( $($args.count) -lt 2 ) {
"Usage: ./check_network.ps1 [warn level] [crit level]"
exit 3
}
$warn = [int]$args[0]
$crit = [int]$args[1]
#Create buffers for the Nagios output
$ExitStatus = 0
$TextOP = ""
$PerfDataOP = ""
#Get the average network usage for the last 5 seconds
$PerfData = Get-Counter -Counter "\network interface(*)\bytes total/sec" -SampleInterval 5 -MaxSamples 1
foreach($InterfacePerf in $PerfData.CounterSamples) {
#Write the outputs
$TextOP = %{"{0}" -f $TextOP,$InterfacePerf.InstanceName,$InterfacePerf.CookedValue}
$PerfDataOP = %{"{0} 'Network Usage (Bytes/sec) ({1})'={2}" -f $PerfDataOP,$InterfacePerf.InstanceName,$InterfacePerf.CookedValue}
#Trigger alerts
#If level is higher than crit, and the status is 'OK' or 'Warn'
if ( $InterfacePerf.CookedValue -gt $crit -and $ExitStatus -lt 2 ) {
$ExitStatus = 2
} elseif ( $InterfacePerf.CookedValue -gt $warn -and $ExitStatus -eq 0 ) {#warning
$ExitStatus = 1
}
}
#Exit and return status
"$TextOP|$PerfDataOP"
exit $ExitStatus