I have a powershell script that I am trying to get Nagios to use for monitoring a csv log file. When I try to run it I am not getting what I believe I should but if I run the script locally it works. I am obviously missing something but not sure what I need to change or add to my nsclient.ini file.
It takes two arguments – a filename and the number of minutes to look back in the csv log.
The response codes are the normal Nagios client responses:
• 0 = OK
• 2 = Critical
• 3 = Unknown, File Not Found
We need an alert any time it responds with 2 or if there are two consecutive runs with a response of 3.
./check_nrpe -H <host> -c csv_monitor -a 'D:\Websites\ClicPublic\App_Data\logs\logfile.csv 5'
No output available from command (cmd /c echo scripts/powershell/csv_monitor.ps1 $ARG1$; exit $LastExitCode |'powershell.exe'=0 '/noprofile'=0 '-command'=0 '-).'=0
./check_nrpe -H <host> -c csv_monitor -a D:\Websites\ClicPublic\App_Data\logs\logfile.csv 5
File Not Found
./check_nrpe -H <host> -c csv_monitor -a D:\Websites\ClicPublic\App_Data\logs\logfile.csv
File Not Found
./check_nrpe -H <host> -c csv_monitor -a 'D:\Websites\ClicPublic\App_Data\logs\logfile.csv'
No output available from command (cmd /c echo scripts/powershell/csv_monitor.ps1 $ARG1$; exit $LastExitCode |'powershell.exe'=0 '/noprofile'=0 '-command'=0 '-).'=0
Last edited by jkinning on Fri Apr 07, 2017 12:58 pm, edited 1 time in total.
./check_nrpe -H <host> -c csv_monitor -a 'D:\Websites\\ClicPublic\\App_Data\\logs\\logfile.csv 20'
Getting coords for zip code: 41018 Finished getting all agents in range by zip.
./check_nrpe -H <host> -c csv_monitor -a 'D:\Websites\\ClicPublic\\App_Data\\logs\\logfile.csv 1'
No output available from command (cmd /c echo scripts/powershell/csv_monitor.ps1 $ARG1$; exit $LastExitCode |'powershell.exe'=0 '/noprofile'=0 '-command'=0 '-).'=0
The first line is what we are wanting to be CRITICAL with that output. So I get the output but Nagios doesn't see it as a critical message, normally I see CRITICAL:
The other line is an OK but I can't figure out how to just have it say OK and not give me all the other output.
Looking over the Powershell, it seems like there may be a case where the file is found to exist but there are no errors found in it which would result in no calls to Write-Host, which is why NRPE says "No output available".
If ($errors.Count -ge 1) {
#if there are any records in the response array, return Critical
$exitCode = $CRITICAL
Write-Host($errors)
}
else {
Write-Host("No errors found")
}
That did help but I am not sure why Nagios isn't picking up the status codes. When I run it from Nagios I am not seeing the OK: or CRITICAL: for Nagios to know to send out notifications.
./check_nrpe -H <host> -c csv_monitor -a 'D:\Websites\ClicPublic\App_Data\logs\logfile.csv 20'
Getting all agents in range by zip code: zipCode=41018, maximumAgents=10 Finished getting all agents in range by zip.
./check_nrpe -H <host> -c csv_monitor -a 'D:\Websites\ClicPublic\App_Data\logs\logfile.csv 5'
No errors found
I am thinking I should see something more like this
./check_nrpe -H <host> -c csv_monitor -a 'D:\Websites\ClicPublic\App_Data\logs\logfile.csv 20'
CRITICAL:Getting all agents in range by zip code: zipCode=41018, maximumAgents=10 Finished getting all agents in range by zip.
./check_nrpe -H <host> -c csv_monitor -a 'D:\Websites\ClicPublic\App_Data\logs\logfile.csv 5'
OK:No errors found
OK/CRITICAL/et. al won't get appended to the status output unless you explicitly do that in the script's output (via stdout or the Windows equivalent) itself. The exit code will still be preserved though, and that's ultimately what Nagios XI cares about in terms of alerting. The status output is simply for the user's benefit.
[root@xi-stable tmp]# /usr/local/nagios/libexec/check_nrpe -H 192.168.67.99 -c test -a 0
This is an ok.
[root@xi-stable tmp]# echo $?
0
[root@xi-stable tmp]# /usr/local/nagios/libexec/check_nrpe -H 192.168.67.99 -c test -a 1
This is a warning.
[root@xi-stable tmp]# echo $?
1
[root@xi-stable tmp]# /usr/local/nagios/libexec/check_nrpe -H 192.168.67.99 -c test -a 2
This is a critical.
[root@xi-stable tmp]# echo $?
2
if ($args[0] -eq 0) {
Write-Host "This is an ok."
exit 0
}
if ($args[0] -eq 1) {
Write-Host "This is a warning."
exit 1
}
if ($args[0] -eq 2) {
Write-Host "This is a critical."
exit 2
}