Not able to Run Powershell Script using NRPE

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Not able to Run Powershell Script using NRPE

Post by WillemDH »

Try again like this:

Code: Select all

./check_nrpe -H 192.168.30.64 -t 60 -c topcpu -a 'vm-restore-cy1 memwarn 85 memcrit 95'
Nagios XI 5.8.1
https://outsideit.net
CloudOps
Posts: 88
Joined: Mon Feb 08, 2016 12:52 am

Re: Not able to Run Powershell Script using NRPE

Post by CloudOps »

WillemDH wrote:Try again like this:

Code: Select all

./check_nrpe -H 192.168.30.64 -t 60 -c topcpu -a 'vm-restore-cy1 memwarn 85 memcrit 95'
if i use -a then i am getting this error :

[root@VM-NAGIOSXI-TEST libexec]# ./check_nrpe -H 192.168.30.64 -c topcpu -a 'vm-restore-cy1 memwarn 85 memcrit 95'
Arguments not allowed see nsclient.log for details
[root@VM-NAGIOSXI-TEST libexec]#

and if i try without -t 300 then i am getting socket timeout after 10 seconds :

[root@VM-NAGIOSXI-TEST libexec]# ./check_nrpe -H 192.168.30.64 -c topcpu "vm-restore-cy1 memwarn 85 memcrit 95"
CHECK_NRPE: Socket timeout after 10 seconds.

and if i use -t 300 then same error :

[root@VM-NAGIOSXI-TEST libexec]# ./check_nrpe -H 192.168.30.64 -c topcpu 'vm-restore-cy1 memwarn 85 memcrit 95' -t 300
CHECK_NRPE: Received 0 bytes from daemon. Check the remote server logs for error messages.

i am attaching my nsclinet configuration file.
You do not have the required permissions to view the files attached to this post.
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Not able to Run Powershell Script using NRPE

Post by WillemDH »

You need this:

Code: Select all

[/settings/external scripts]
allow arguments = true
allow nasty characters = true
Nagios XI 5.8.1
https://outsideit.net
CloudOps
Posts: 88
Joined: Mon Feb 08, 2016 12:52 am

Re: Not able to Run Powershell Script using NRPE

Post by CloudOps »

WillemDH wrote:You need this:

Code: Select all

[/settings/external scripts]
allow arguments = true
allow nasty characters = true
I have added the above lines, but i am not getting the outpu, still getting the same error :

2016-03-24 06:38:17: error:c:\source\nscp\service\NSClient++.cpp:906: Failed to execute command
2016-03-24 06:40:49: error:c:\source\nscp\include\socket/connection.hpp:149: Failed to send data: The file handle supplied is not valid

Thanks
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Not able to Run Powershell Script using NRPE

Post by lmiltchev »

Did you copy the script from "C:\Program Files\NSClient++\plugins" back to "C:\Program Files\NSClient++\scripts" directory?

Also, you allow arguments under the NRPE section but they need to be allowed under the external scripts section, too. In my nsclient.ini, I have:

Code: Select all

[/settings/external scripts]
allow arguments = 1
allow nasty characters=1
You may need to add this section, and restart NSClient++ service.

BTW, if you want to load all of the defaults in the nsclient.ini, open CMD prompt, and run:

Code: Select all

cd "C:\Program Files\NSClient++
nscp settings --generate --add-defaults --load-all
Be sure to check out our Knowledgebase for helpful articles and solutions!
CloudOps
Posts: 88
Joined: Mon Feb 08, 2016 12:52 am

Re: Not able to Run Powershell Script using NRPE

Post by CloudOps »

lmiltchev wrote:Did you copy the script from "C:\Program Files\NSClient++\plugins" back to "C:\Program Files\NSClient++\scripts" directory?

Also, you allow arguments under the NRPE section but they need to be allowed under the external scripts section, too. In my nsclient.ini, I have:

Code: Select all

[/settings/external scripts]
allow arguments = 1
allow nasty characters=1
You may need to add this section, and restart NSClient++ service.

BTW, if you want to load all of the defaults in the nsclient.ini, open CMD prompt, and run:

Code: Select all

cd "C:\Program Files\NSClient++
nscp settings --generate --add-defaults --load-all
I have already copied files to Script folder , added lines to nsclinet. but still issue is there.is there anything i am missing??
You do not have the required permissions to view the files attached to this post.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Not able to Run Powershell Script using NRPE

Post by lmiltchev »

Change your command in the nsclient.ini from this:

Code: Select all

topcpu = cmd /c scripts\resourcecheck.ps1 $ARG1$; exit $LastExitcode | powershell.exe -command
to this:

Code: Select all

topcpu = cmd /c echo scripts\resourcecheck.ps1 $ARG1$; exit $LastExitcode | powershell.exe -command -
Note: Add "echo" before scripts, and "-" after "command" (with a space between them).

Restart NSClient++ service.

Do you see any errors when you run the check now?

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H 192.168.30.64 -t 60 -c topcpu -a 'vm-restore-cy1 -memwarn 85 -memcrit 95'
Be sure to check out our Knowledgebase for helpful articles and solutions!
CloudOps
Posts: 88
Joined: Mon Feb 08, 2016 12:52 am

Re: Not able to Run Powershell Script using NRPE

Post by CloudOps »

lmiltchev wrote:Change your command in the nsclient.ini from this:

Code: Select all

topcpu = cmd /c scripts\resourcecheck.ps1 $ARG1$; exit $LastExitcode | powershell.exe -command
to this:

Code: Select all

topcpu = cmd /c echo scripts\resourcecheck.ps1 $ARG1$; exit $LastExitcode | powershell.exe -command -
Note: Add "echo" before scripts, and "-" after "command" (with a space between them).

Restart NSClient++ service.

Do you see any errors when you run the check now?

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H 192.168.30.64 -t 60 -c topcpu -a 'vm-restore-cy1 -memwarn 85 -memcrit 95'
when i am running this command :
[root@VM-NAGIOSXI-TEST libexec]# ./check_nrpe -H 192.168.30.64 -c topcpu "vm-restore-cy1 memwarn 85 memcrit 95" -t 120
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x80070
6BA)
At C:\Program Files\NSClient++\scripts\resourcecheck.ps1:11 char:27
+ $TotalRAM = (get-WMIObject <<<< win32_operatingsystem -computername $servern
ame
[root@VM-NAGIOSXI-TEST libexec]# ./check_nrpe -H 192.168.30.64 -c topcpu "vm-restore-cy1 memwarn 85 memcrit 95" -t 120

But ther is no issue running the command locally. output attached.
You do not have the required permissions to view the files attached to this post.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Not able to Run Powershell Script using NRPE

Post by lmiltchev »

Can you copy/paste this command to your putty window and show the output of it?

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H 192.168.30.64 -c topcpu -a 'vm-restore-cy1 -memwarn 85 -memcrit 95'
Be sure to check out our Knowledgebase for helpful articles and solutions!
CloudOps
Posts: 88
Joined: Mon Feb 08, 2016 12:52 am

Re: Not able to Run Powershell Script using NRPE

Post by CloudOps »

lmiltchev wrote:Can you copy/paste this command to your putty window and show the output of it?

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H 192.168.30.64 -c topcpu -a 'vm-restore-cy1 -memwarn 85 -memcrit 95'
Here is the output which you have asked :

[root@VM-NAGIOSXI-TEST libexec]# ./check_nrpe -H 192.168.30.64 -c topcpu -a 'vm-restore-cy1.hosting.metricstream.com -memwarn 85 -memcrit 95'
CHECK_NRPE: Socket timeout after 10 seconds.

[root@VM-NAGIOSXI-TEST libexec]# ./check_nrpe -H 192.168.30.64 -t 60 -c topcpu -a 'vm-restore-cy1 -memwarn 85 -memcrit 95'
CHECK_NRPE: Received 0 bytes from daemon. Check the remote server logs for error messages.
Locked