Currently i have a PowerShell scripts that are on a laptop. I use nsclient to run the scripts and return what i need to nagios.
Currently i have nagios server installed on centos server. what is the best way to run the same check via the nagios server ?
current power shell script:
$web = Invoke-RestMethod -Uri "http://192.168.44.11/go/getdata?catagor ... &cmd=index"
$web.LEDimage
if ($web.LEDimage -eq "13") {
Write-Output "0 - Booster Working"
exit 0
} else {
Write-Output "2 - Booster not working"
exit 2
}
scripts on the Nagios server
Re: scripts on the Nagios server
You would need do this in your nsclient.ini first:
- Make sure NRPE is enabled
- Make sure your XI server is on the allowed hosts directive
- Restart the NSClient++ service
From the nagios server you would run this:
- Change X.X.X.X to the IP of the NSClient++ agent
- Change command to what you have defined as the command
If you need help, please attach a sanitized copy of your nsclient.ini and let us know the version of NSClient++ you are running, you can find it in Programs and Features in the Control Panel.
Then you can either run Configure > Configuration Wizards > NRPE wizard, or the Linux Server (legacy) wizard one for other NRPE checks, or add the service manually:
https://assets.nagios.com/downloads/nag ... gement.pdf
- Make sure NRPE is enabled
- Make sure your XI server is on the allowed hosts directive
- Restart the NSClient++ service
From the nagios server you would run this:
- Change X.X.X.X to the IP of the NSClient++ agent
- Change command to what you have defined as the command
Code: Select all
/usr/local/nagios/libexec/check_nrpe -2 -H X.X.X.X -c command
Then you can either run Configure > Configuration Wizards > NRPE wizard, or the Linux Server (legacy) wizard one for other NRPE checks, or add the service manually:
https://assets.nagios.com/downloads/nag ... gement.pdf
Re: scripts on the Nagios server
Hello Ssax, i know how to run it on a windows device. I am trying to take this off the laptop and run it strictly from the centos server that my nagios xi sits on. Is this possible ?
Re: scripts on the Nagios server
It's likely possible to do with Powershell Remoting but it's not something that I've seen anyone implement or architect. Please note that architecting a solution is not included as a part of support. If you're able to code, these should point you in the right direction:
https://docs.microsoft.com/en-us/powers ... rshell-7.2
https://www.altaro.com/msp-dojo/encrypt ... owershell/
Thank you!
https://docs.microsoft.com/en-us/powers ... rshell-7.2
https://www.altaro.com/msp-dojo/encrypt ... owershell/
https://docs.microsoft.com/en-us/powers ... rshell-7.2This command lets you run the script on the remote computers, even if the script file isn't accessible to the remote computers
Thank you!
Re: scripts on the Nagios server
I understand its not part of support just seeing my options.
once i have PowerShell on my nagios/centos server
what nagios tool can i use in order run the script from the actual centos/linux server ?
is it possible to install nsclient on a linux server or what have people done for linux server in the past?
once i have PowerShell on my nagios/centos server
what nagios tool can i use in order run the script from the actual centos/linux server ?
is it possible to install nsclient on a linux server or what have people done for linux server in the past?
Re: scripts on the Nagios server
Ssax, is it possible to run powershell scripts with the nrpe agent or the ncpa agent for linux ?
Re: scripts on the Nagios server
To run a powershell script on a Linux server:
Install powershell for linux on the server, transfer the ps1 file to the server, and then call it with pwsh:
Could the above process also be done through NRPE/NCPA/NSClient++?
If the OS where the powershell script resides supports powershell, you can run that powershell script remotely through NRPE/NCPA/NSClient++.
You can install NSClient++ on Linux but that doesn't allow you to run powershell scripts on Linux. If you had a Linux Server with Powershell installed so that it can run powershell scripts, the agent (NRPE/NCPA/NSClient++) would allow you to call them remotely, but NRPE/NCPA/NSClient++ does not have any inherent understanding of how to interpret the plugin/script, it's the backend OS that handles that. Think of the agents as glorified remote-command runners, with NCPA/NSClient++ having some built in checks that don't require plugins, and NRPE not having any built-in checks.
The recommendation would probably be to rewrite them as bash scripts but technically powershell scripts can be run on Linux now. All support and troubleshooting of powershell for Linux issues should be directed to MS.
Install powershell for linux on the server, transfer the ps1 file to the server, and then call it with pwsh:
Code: Select all
pwsh -file /usr/local/nagios/libexec/do_the_thing.ps1
If the OS where the powershell script resides supports powershell, you can run that powershell script remotely through NRPE/NCPA/NSClient++.
You can install NSClient++ on Linux but that doesn't allow you to run powershell scripts on Linux. If you had a Linux Server with Powershell installed so that it can run powershell scripts, the agent (NRPE/NCPA/NSClient++) would allow you to call them remotely, but NRPE/NCPA/NSClient++ does not have any inherent understanding of how to interpret the plugin/script, it's the backend OS that handles that. Think of the agents as glorified remote-command runners, with NCPA/NSClient++ having some built in checks that don't require plugins, and NRPE not having any built-in checks.
The recommendation would probably be to rewrite them as bash scripts but technically powershell scripts can be run on Linux now. All support and troubleshooting of powershell for Linux issues should be directed to MS.
Re: scripts on the Nagios server
See previous response as well.
If you're just checking JSON, you could use Configure > Configuration Wizards > JSON or possibly even using check_http.
If you're just checking JSON, you could use Configure > Configuration Wizards > JSON or possibly even using check_http.
Re: scripts on the Nagios server
thanks for help ssax, please see response from Jeffery that helped me. i just installed ncpa and powershell on linux server and used ps1 as plugin to run the script and create a service in Nagios.
At the end of your ncpa.cfg file, you probably have something like this:
CODE: SELECT ALL
# Windows
.ps1 = powershell -ExecutionPolicy Bypass -File $plugin_name $plugin_args
.vbs = cscript $plugin_name $plugin_args //NoLogo
.wsf = cscript $plugin_name $plugin_args //NoLogo
.bat = cmd /c $plugin_name $plugin_args
change the .ps1 one to be like:
CODE: SELECT ALL
.ps1 = pwsh -ExecutionPolicy Bypass -File $plugin_name $plugin_args
Restart ncpa (systemctl restart ncpa_listener) to make your change take effect and give it a try.
--Jeffrey
At the end of your ncpa.cfg file, you probably have something like this:
CODE: SELECT ALL
# Windows
.ps1 = powershell -ExecutionPolicy Bypass -File $plugin_name $plugin_args
.vbs = cscript $plugin_name $plugin_args //NoLogo
.wsf = cscript $plugin_name $plugin_args //NoLogo
.bat = cmd /c $plugin_name $plugin_args
change the .ps1 one to be like:
CODE: SELECT ALL
.ps1 = pwsh -ExecutionPolicy Bypass -File $plugin_name $plugin_args
Restart ncpa (systemctl restart ncpa_listener) to make your change take effect and give it a try.
--Jeffrey
Re: scripts on the Nagios server
I have powershell installed on linux and have in the script it encrypting a password in a file for the first time then checks for it and then I have it remote launch a powershell script that was run stored on the Linux machine on the windows machine.