Get script result from remote Linux server

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
yellowdog
Posts: 20
Joined: Mon Dec 02, 2013 7:22 am

Get script result from remote Linux server

Post 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.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Get script result from remote Linux server

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
yellowdog
Posts: 20
Joined: Mon Dec 02, 2013 7:22 am

Re: Get script result from remote Linux server

Post 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
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Get script result from remote Linux server

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
yellowdog
Posts: 20
Joined: Mon Dec 02, 2013 7:22 am

Re: Get script result from remote Linux server

Post by yellowdog »

Everything is fine now, thanks a lot.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Get script result from remote Linux server

Post by tmcdonald »

Great to hear it! Did you have further (related) questions or are we good to lock this up?
Former Nagios employee
User avatar
rhassing
Posts: 412
Joined: Sat Oct 05, 2013 10:29 pm
Location: Netherlands

Re: Get script result from remote Linux server

Post 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/
Rob Hassing
Image
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Get script result from remote Linux server

Post by scottwilkerson »

Nice tip!
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked