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.
CloudOps
Posts: 88
Joined: Mon Feb 08, 2016 12:52 am

Not able to Run Powershell Script using NRPE

Post by CloudOps »

Hi All,

I am not able to run Powershell script using NRPE, i am getting below error :

[root@VM-NAGIOSXI-TEST libexec]# ./check_nrpe -H 172.26.2.13 -c topcpu
The command (topcpu) returned an invalid return code: -196608
[root@VM-NAGIOSXI-TEST libexec]#


I have changed the powershell excution ploicy to remote signed. I am attaching my nsclient configuration file.
You do not have the required permissions to view the files attached to this post.
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Not able to Run Powershell Script using NRPE

Post by gormank »

Your command:

Code: Select all

topcpu = cmd /c echo scripts\resourcecheck.ps1; | powershell.exe -command 
Not sure why you're using the echo, and suspicious of the relative path. You're also piping the string "scripts\resourcecheck.ps1" to powershell, not the contents of resourcesheck.ps1. Run this to see:

Code: Select all

cmd /c echo scripts\resourcecheck.ps1
You'd need to change it to something like to make it work, but even then you're using cmd.exe and PS, which is a turtle all by itself:

Code: Select all

cmd /c type c:\path\to\scripts\resourcecheck.ps1
Maybe copy your script to the plugins dir and execute from there:

Code: Select all

topcpu="powershell.exe C:\Program Files\NSClient++\plugins\resourcecheck.ps1"
First get the command to run from any dir in a cmd.exe window before attempting to run from nsclient.

I created a test.ps1 that just ad dir in it and it ran as:

Code: Select all

powershell.exe test.ps1 and simply test.ps1
I'd associate ps1 w/ powereshell.exe (if not already done):

Code: Select all

topcpu="C:\Program Files\NSClient++\plugins\resourcecheck.ps1"
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 run the "resourcecheck.ps1" script locally, on the Windows machine, and show the output? Do you mind showing the actual script?
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 »

gormank wrote:Your command:

Code: Select all

topcpu = cmd /c echo scripts\resourcecheck.ps1; | powershell.exe -command 
Not sure why you're using the echo, and suspicious of the relative path. You're also piping the string "scripts\resourcecheck.ps1" to powershell, not the contents of resourcesheck.ps1. Run this to see:

Code: Select all

cmd /c echo scripts\resourcecheck.ps1
You'd need to change it to something like to make it work, but even then you're using cmd.exe and PS, which is a turtle all by itself:

Code: Select all

cmd /c type c:\path\to\scripts\resourcecheck.ps1
Maybe copy your script to the plugins dir and execute from there:

Code: Select all

topcpu="powershell.exe C:\Program Files\NSClient++\plugins\resourcecheck.ps1"
First get the command to run from any dir in a cmd.exe window before attempting to run from nsclient.

I created a test.ps1 that just ad dir in it and it ran as:

Code: Select all

powershell.exe test.ps1 and simply test.ps1
I'd associate ps1 w/ powereshell.exe (if not already done):

Code: Select all

topcpu="C:\Program Files\NSClient++\plugins\resourcecheck.ps1"
i have modified the path, now i am getting below error :

./check_nrpe -H 172.26.2.13 -c topcpu -t 160
CHECK_NRPE: Received 0 bytes from daemon. Check the remote server logs for error messages.

In nsclient logs i can see the below error :

2016-03-23 04:04:02: error:c:\source\nscp\include\socket/connection.hpp:149: Failed to send data: The file handle supplied is not valid
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Not able to Run Powershell Script using NRPE

Post by gormank »

Paste the following into a cmd prompt window on 172.26.2.13 and paste the result. Don't run it from the plugins dir.

Code: Select all

"C:\Program Files\NSClient++\plugins\resourcecheck.ps1"
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 »

@CloudOps
Can you zip up your "resourcecheck.ps1" script, and upload it on the forum?
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 »

gormank wrote:Paste the following into a cmd prompt window on 172.26.2.13 and paste the result. Don't run it from the plugins dir.

Code: Select all

"C:\Program Files\NSClient++\plugins\resourcecheck.ps1"
when i am running the above command its just pop up the complete script in notepad. any idea?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Not able to Run Powershell Script using NRPE

Post by rkennedy »

Please post the powershell file for us to look at.
Former Nagios Employee
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Not able to Run Powershell Script using NRPE

Post by gormank »

In addition to posting the script try running it:

Code: Select all

powershell.exe "C:\Program Files\NSClient++\plugins\resourcecheck.ps1"
CloudOps
Posts: 88
Joined: Mon Feb 08, 2016 12:52 am

Re: Not able to Run Powershell Script using NRPE

Post by CloudOps »

gormank wrote:In addition to posting the script try running it:

Code: Select all

powershell.exe "C:\Program Files\NSClient++\plugins\resourcecheck.ps1"
Hi gormank/rkennedy,

I have attached the error image. also attaching the script.

Thanks,
You do not have the required permissions to view the files attached to this post.
Locked