NSClient++ calling a Powershell script
NSClient++ calling a Powershell script
I am trying to get this Powershell script to run by the NSClient++ agent. This script requires a service account or an account in which is allowed to access this particular database. Do I create an AD account for this or what account does the NSClient++ run under when Nagios calls it?
It expects 4 command line parameters:
QueueType (e.g. DB, DEAD, EVENT, PROCESS, QUEUE))
QueueLimit (the threshold to check – i.e. has the queue depth exceeded this number?)
Dbconn – the database connection string (it presumes that the account running the script has Read access to the ZL database)
Sendto – for testing, an email address to send the results to
(You may enter 0 for the QueueLimit to force the event to trigger. Also, feel free to modify the script so the calling process will receive the expected output/return code.)
The syntax for the script is:
Zl_monitor_filearchiving_queues.ps1 –QueueType “DEAD” –QueueLimit 20 -Dbconn=”SQLTEST_ZLBD_Dev,4000” –sendto [email protected]
(the sendto is for testing purposes.)
It expects 4 command line parameters:
QueueType (e.g. DB, DEAD, EVENT, PROCESS, QUEUE))
QueueLimit (the threshold to check – i.e. has the queue depth exceeded this number?)
Dbconn – the database connection string (it presumes that the account running the script has Read access to the ZL database)
Sendto – for testing, an email address to send the results to
(You may enter 0 for the QueueLimit to force the event to trigger. Also, feel free to modify the script so the calling process will receive the expected output/return code.)
The syntax for the script is:
Zl_monitor_filearchiving_queues.ps1 –QueueType “DEAD” –QueueLimit 20 -Dbconn=”SQLTEST_ZLBD_Dev,4000” –sendto [email protected]
(the sendto is for testing purposes.)
You do not have the required permissions to view the files attached to this post.
Re: NSClient++ calling a Powershell script
By default, the NSClient++ service is installed and runs using the "Local System account" but if your plugin needs to run as a different user, you could change the login account NSClient++ logs in as.
If you need an AD account to access that database, you can try and use it and see if the NSClient++ service uses that account to run the powershell script.
If you need an AD account to access that database, you can try and use it and see if the NSClient++ service uses that account to run the powershell script.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: NSClient++ calling a Powershell script
I am able to call the powershell script when I change the logon and run under the service account with access to the database. The script needs 3 arguments -
QueueType (e.g. DB, DEAD, EVENT, PROCESS, QUEUE))
QueueLimit (the threshold to check – i.e. has the queue depth exceeded this number?)
Dbconn – the database connection string
I added the following to my nsclient.ini file:
Using the terminal I try to run from the Nagios server
I get this returned
QueueType (e.g. DB, DEAD, EVENT, PROCESS, QUEUE))
QueueLimit (the threshold to check – i.e. has the queue depth exceeded this number?)
Dbconn – the database connection string
I added the following to my nsclient.ini file:
Code: Select all
check_zl_queue = cmd /c echo scripts/zl_monitor_file_archiving_queues.ps1 $ARG1$ $ARG2$ $ARG3$; exit $LastExitCode | powershell.exe /noprofile -command -Code: Select all
check_nrpe -H cinzlbd01d -t 30 -c check_zl_queue dead 0 sqltest_zlbd_dev,4000Code: Select all
C:\Program Files\NSClient++\scripts\zl_monitor_file_archiving_queues.ps1 :
Cannot process argument transformation on parameter 'queueType'. Cannot
convert value to type System.String.
At line:1 char:46
+ scripts/zl_monitor_file_archiving_queues.ps1 $ARG1$,$ARG2$,$ARG3$; exit
$LastExi ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [zl_monitor_file_archiving_queu
es.ps1], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,zl_monitor_
file_archiving_queues.ps1Re: NSClient++ calling a Powershell script
When using check_nrpe to run remote commands that have arguments, you need to specify the -a option in the command and if there are more that one argument, you need to encase them in single quotes.
Try this example and see if if it works.
Try this example and see if if it works.
Code: Select all
check_nrpe -H cinzlbd01d -t 30 -c check_zl_queue -a 'dead 0 sqltest_zlbd_dev,4000'-a [arglist]
[arglist] = Optional arguments that should be passed to the command,
separated by a space. If provided, this must be the last
option supplied on the command line.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: NSClient++ calling a Powershell script
When I run the script from the server I get the exit code of 2 which is critical and Nagios would send out a notification. When I run it on the Nagios server terminal as described it looks like the same error.
Code: Select all
check_nrpe -H cinzlbd01d -t 30 -c check_zl_queue -a 'dead 0 sqltest_zlbd_dev,4000'
C:\Program Files\NSClient++\scripts\zl_monitor_file_archiving_queues.ps1 :
Cannot process argument transformation on parameter 'dbconn'. Cannot convert
value to type System.String.
At line:1 char:53
+ scripts/zl_monitor_file_archiving_queues.ps1 dead 0 sqltest_zlbd_dev,4000;
exit ...
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [zl_monitor_file_archiving_queu
es.ps1], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,zl_monitor_
file_archiving_queues.ps1
You do not have the required permissions to view the files attached to this post.
Re: NSClient++ calling a Powershell script
One more change has to be added to the nsclient.ini file, the options for the powershell script.
Edit the nsclient.ini file and change the command from
to
Save the file and restart the nsclient++ service on the windows server.
You may have to edit the above if I missed something.
If you still have errors, can you post the full nsclient.ini file from that server so we can view the settings and the error messages from the nsclient.log file?
Edit the nsclient.ini file and change the command from
Code: Select all
check_zl_queue = cmd /c echo scripts/zl_monitor_file_archiving_queues.ps1 $ARG1$ $ARG2$ $ARG3$; exit $LastExitCode | powershell.exe /noprofile -command -Code: Select all
check_zl_queue = cmd /c echo scripts/zl_monitor_file_archiving_queues.ps1 –QueueType $ARG1$ –QueueLimit $ARG2$ -Dbconn=$ARG3$; exit $LastExitCode | powershell.exe /noprofile -command -You may have to edit the above if I missed something.
If you still have errors, can you post the full nsclient.ini file from that server so we can view the settings and the error messages from the nsclient.log file?
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: NSClient++ calling a Powershell script
Files attached.
Still getting same error.
Still getting same error.
You do not have the required permissions to view the files attached to this post.
- tacolover101
- Posts: 432
- Joined: Mon Apr 10, 2017 11:55 am
Re: NSClient++ calling a Powershell script
one thing to mention, if you're encapsulating anything after -a in single quotes, it will pick up 'dead 0 sqltest_zlibd_dev,4000' all as $ARG1$. try single quoting all of your args out individually.tgriep wrote:One more change has to be added to the nsclient.ini file, the options for the powershell script.
Edit the nsclient.ini file and change the command fromtoCode: Select all
check_zl_queue = cmd /c echo scripts/zl_monitor_file_archiving_queues.ps1 $ARG1$ $ARG2$ $ARG3$; exit $LastExitCode | powershell.exe /noprofile -command -Save the file and restart the nsclient++ service on the windows server.Code: Select all
check_zl_queue = cmd /c echo scripts/zl_monitor_file_archiving_queues.ps1 –QueueType $ARG1$ –QueueLimit $ARG2$ -Dbconn=$ARG3$; exit $LastExitCode | powershell.exe /noprofile -command -
You may have to edit the above if I missed something.
If you still have errors, can you post the full nsclient.ini file from that server so we can view the settings and the error messages from the nsclient.log file?
Re: NSClient++ calling a Powershell script
Thanks tacolover101 for the tip.
What he is saying, the command has to be run line the following example on the XI server
What he is saying, the command has to be run line the following example on the XI server
Code: Select all
check_nrpe -H cinzlbd01d -t 30 -c check_zl_queue -a 'dead' '0' 'sqltest_zlbd_dev,4000'Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: NSClient++ calling a Powershell script
Once I did that I was getting this error message
The database connection stuff was hard coded and I removed the $ARG3$.
Now when I run it I get this
Thinking there is something else I need to since Nagios doesn't see this as "critical". Normally I would expect to see CRITICAL: some verbiage or OK:. Is there something else that needs to be done for Nagios to report the Critical, Warning, OK? I thought it just needed the last exit code.
Code: Select all
/check_nrpe -H cinzlbd01d -t 30 -c check_zl_queue -a 'dead' '0' '"sqltest_zlbd_dev,4000"'
Error when opening DB connection -Dbconn=sqltest_zlbd_dev,4000
Exception calling "Open" with "0" argument(s): "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - No such host is known.)"
Exiting with Return code of: 2
Now when I run it I get this
Code: Select all
check_nrpe -H cinzlbd01d -t 30 -c check_zl_queue -a 'event' '23000'
23186
24096
Exiting with Return code of: 2