Page 1 of 1

Powershell via NRPE not returning Perf data correctly

Posted: Tue Apr 16, 2019 3:23 am
by btsmnagios
I have written a script that connect to my shares and returns the size info of the shares, this works correctly and returns the data to Nagios with the correct statement and the size info, but when I start adding in the perf data as per the documentation using the pipe character as the separator and formatting in the correct way the data in the variables are being returned as 0, I have attached a picture showing the check and the first line returned is what should be after the pipe | with the data in and the second line is what should actually be returned but the data is becoming 0 after the pipe, below is the code I am using, thanks for any help in advance
ShareSize Check.JPG

----Code----
$ShareName = $Result.ShareName
$ShareSize = $Result.ShareSize
$FreeSpace = $Result.FreeSpace
$TotalSize = $Result.TotalSize


$Message = "OK - $ShareName`, ShareSize:- $ShareSize`GB, FreeSpace:- $FreeSpace`GB, TotalSize:- $TotalSize`GB"
$perfdata = "'ShareSize'=$ShareSize`GB 'FreeSpace'=$FreeSpace`GB 'TotalSize'=$TotalSize`GB;"

write-host $perfdata
write-host $Message"|"$perfdata
Exit 0

Re: Powershell via NRPE not returning Perf data correctly

Posted: Tue Apr 16, 2019 9:01 am
by lmiltchev
I believe the problem is caused by the commas in the numbers. You can try getting rid of them, maybe using something like this:

Code: Select all

$ShareName = $Result.ShareName
$ShareSize = $Result.ShareSize
$FreeSpace = $Result.FreeSpace
$TotalSize = $Result.TotalSize


$Message = "OK - $ShareName`, ShareSize:- $ShareSize`GB, FreeSpace:- $FreeSpace`GB, TotalSize:- $TotalSize`GB"
$output =  "'ShareSize'=$ShareSize`GB 'FreeSpace'=$FreeSpace`GB 'TotalSize'=$TotalSize`GB;"
$perfdata = '{0:f2}' -f $output

write-host $perfdata
write-host $Message"|"$perfdata
Exit 0

Re: Powershell via NRPE not returning Perf data correctly

Posted: Tue Apr 16, 2019 3:07 pm
by btsmnagios
Thank you so much for your help you were correct, as soon as I removed the comma it worked, only need to sort out NRPE timing out after 60 seconds now, thanks again

Re: Powershell via NRPE not returning Perf data correctly

Posted: Tue Apr 16, 2019 3:09 pm
by lmiltchev
I am glad I could help! :)

Let us know if you have any further questions.