Page 1 of 6
Not able to Run Powershell Script using NRPE
Posted: Tue Mar 22, 2016 3:14 pm
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.
Re: Not able to Run Powershell Script using NRPE
Posted: Tue Mar 22, 2016 3:38 pm
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"
Re: Not able to Run Powershell Script using NRPE
Posted: Tue Mar 22, 2016 4:13 pm
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?
Re: Not able to Run Powershell Script using NRPE
Posted: Tue Mar 22, 2016 5:37 pm
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
Re: Not able to Run Powershell Script using NRPE
Posted: Tue Mar 22, 2016 6:18 pm
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"
Re: Not able to Run Powershell Script using NRPE
Posted: Wed Mar 23, 2016 8:42 am
by lmiltchev
@CloudOps
Can you zip up your "resourcecheck.ps1" script, and upload it on the forum?
Re: Not able to Run Powershell Script using NRPE
Posted: Wed Mar 23, 2016 8:48 am
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?
Re: Not able to Run Powershell Script using NRPE
Posted: Wed Mar 23, 2016 8:51 am
by rkennedy
Please post the powershell file for us to look at.
Re: Not able to Run Powershell Script using NRPE
Posted: Wed Mar 23, 2016 9:09 am
by gormank
In addition to posting the script try running it:
Code: Select all
powershell.exe "C:\Program Files\NSClient++\plugins\resourcecheck.ps1"
Re: Not able to Run Powershell Script using NRPE
Posted: Wed Mar 23, 2016 9:26 am
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,