Get script result from remote Linux server

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Get script result from remote Linux server

Postby yellowdog » Tue Jun 05, 2018 7:45 am

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.
yellowdog
 
Posts: 4
Joined: Mon Dec 02, 2013 7:22 am

Re: Get script result from remote Linux server

Postby npolovenko » Tue Jun 05, 2018 2:39 pm

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/nagiosxi/docs/Installing_The_XI_Linux_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.
User avatar
npolovenko
Support Tech
 
Posts: 1763
Joined: Mon May 15, 2017 5:00 pm

Re: Get script result from remote Linux server

Postby yellowdog » Wed Jun 06, 2018 2:37 am

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
yellowdog
 
Posts: 4
Joined: Mon Dec 02, 2013 7:22 am

Re: Get script result from remote Linux server

Postby npolovenko » Wed Jun 06, 2018 11:55 am

@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.
User avatar
npolovenko
Support Tech
 
Posts: 1763
Joined: Mon May 15, 2017 5:00 pm

Re: Get script result from remote Linux server

Postby yellowdog » Thu Jun 07, 2018 5:31 am

Everything is fine now, thanks a lot.
yellowdog
 
Posts: 4
Joined: Mon Dec 02, 2013 7:22 am

Re: Get script result from remote Linux server

Postby tmcdonald » Thu Jun 07, 2018 9:26 am

Great to hear it! Did you have further (related) questions or are we good to lock this up?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
tmcdonald
Operations Engineer
 
Posts: 9054
Joined: Mon Sep 23, 2013 8:40 am

Re: Get script result from remote Linux server

Postby rhassing » Sat Jun 09, 2018 1:45 am

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
Have I been helpful? Nominate me for a Nagios MVP award!
User avatar
rhassing
 
Posts: 365
Joined: Sat Oct 05, 2013 10:29 pm
Location: Netherlands

Re: Get script result from remote Linux server

Postby scottwilkerson » Mon Jun 11, 2018 11:24 am

Nice tip!
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
CTO
 
Posts: 9590
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises


Return to Nagios Core

Who is online

Users browsing this forum: Google [Bot], smichandu and 14 guests