Page 1 of 1

Get script result from remote Linux server

Posted: Tue Jun 05, 2018 7:45 am
by yellowdog
Hello,

I wrote a shell script on a remote Linux server and would like to monitor this result in NAGIOS.
The script return the amount of users connected to a specific application.
The script runs without error when exedcuted on the remote server.

What is the best way to get that information in NAGIOS (check_by_ssh, check_nrpe or something else ...)

For the chosen option, could you give me the main lines to configure on both NAGIOS server and Remote server.

Thanks.

Re: Get script result from remote Linux server

Posted: Tue Jun 05, 2018 2:39 pm
by npolovenko
Hello, @yellowdog. I'd go with the nrpe agent. On the remote server please execute the commands from this tutorial:
https://assets.nagios.com/downloads/nag ... _Agent.pdf

After you install the nrpe place your custom plugin in the /usr/local/nagios/libexec/ folder on the remote server and give it the permissions:

Code: Select all

chmod 777 your_plugin.sh
On the remote server open the /usr/local/nagios/etc/nrpe.cfg file and change:

Code: Select all

allowed_hosts=127.0.0.1
To:

Code: Select all

allowed_hosts=127.0.0.1 192.168.4.172
Where 192.168.4.172 is the Nagios core ip address.

Run:

Code: Select all

service nrpe restart
Then from the Nagios server run the following command and share the output with us:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H 191.114.3.142
Where 191.114.3.142 is the IP address of the remote nrpe server.

Re: Get script result from remote Linux server

Posted: Wed Jun 06, 2018 2:37 am
by yellowdog
The result of the command shows that NAGIOS is able to communicate with the remote server, but now, how do I proceed to run the script on the remote server ?
[root@GLNXNGIOS plugins]# ./check_nrpe -H VLNXDIAP2
NRPE v3.2.0

Re: Get script result from remote Linux server

Posted: Wed Jun 06, 2018 11:55 am
by npolovenko
@yellowdog, On the remote server open the /usr/local/nagios/etc/nrpe.cfg file and add the following command in the commands section:

Code: Select all

command[check_script]=/usr/local/nagios/libexec/script_name.sh
*you can change the check_script name to anything you like
*replace the script_name.sh in the path with the actual script name

Run:

Code: Select all

service nrpe restart
Then from the Nagios server run the following command and share the output with us:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H 191.114.3.142 -c check_script

Re: Get script result from remote Linux server

Posted: Thu Jun 07, 2018 5:31 am
by yellowdog
Everything is fine now, thanks a lot.

Re: Get script result from remote Linux server

Posted: Thu Jun 07, 2018 9:26 am
by tmcdonald
Great to hear it! Did you have further (related) questions or are we good to lock this up?

Re: Get script result from remote Linux server

Posted: Sat Jun 09, 2018 1:45 am
by rhassing
A really nice way to do this is, instead of using NRPE, to use snmp.

See my url to find more info on this:
http://mona.deltics.info/snmp-execute-remote-script/

Re: Get script result from remote Linux server

Posted: Mon Jun 11, 2018 11:24 am
by scottwilkerson
Nice tip!