scripts on the Nagios server

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
localit
Posts: 40
Joined: Thu Oct 29, 2020 12:50 pm

scripts on the Nagios server

Post by localit »

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
}
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: scripts on the Nagios server

Post by ssax »

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

Code: Select all

/usr/local/nagios/libexec/check_nrpe -2 -H X.X.X.X -c 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
localit
Posts: 40
Joined: Thu Oct 29, 2020 12:50 pm

Re: scripts on the Nagios server

Post by localit »

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 ?
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: scripts on the Nagios server

Post by ssax »

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/
This command lets you run the script on the remote computers, even if the script file isn't accessible to the remote computers
https://docs.microsoft.com/en-us/powers ... rshell-7.2

Thank you!
localit
Posts: 40
Joined: Thu Oct 29, 2020 12:50 pm

Re: scripts on the Nagios server

Post by localit »

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?
localit
Posts: 40
Joined: Thu Oct 29, 2020 12:50 pm

Re: scripts on the Nagios server

Post by localit »

Ssax, is it possible to run powershell scripts with the nrpe agent or the ncpa agent for linux ?
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: scripts on the Nagios server

Post by ssax »

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:

Code: Select all

pwsh -file /usr/local/nagios/libexec/do_the_thing.ps1
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.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: scripts on the Nagios server

Post by ssax »

See previous response as well.

If you're just checking JSON, you could use Configure > Configuration Wizards > JSON or possibly even using check_http.
localit
Posts: 40
Joined: Thu Oct 29, 2020 12:50 pm

Re: scripts on the Nagios server

Post by localit »

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
btayl
Posts: 123
Joined: Mon Aug 24, 2020 8:51 am

Re: scripts on the Nagios server

Post by btayl »

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.
Locked