Page 1 of 3
Run command
Posted: Tue Sep 24, 2019 11:26 am
by fsodah
Is it possible to run direct command via nagios on my remote linux and capture that into my nagios to get me the status of specific process. Like run a command to find the status of the cluster is up or not.
Re: Run command
Posted: Tue Sep 24, 2019 12:46 pm
by mbellerue
Absolutely. There are a couple of different ways to achieve this. Assuming that the command on your Linux server is called check_mycluster.py, and it returns 0 for good, 1 for warning, 2 for critical, and anything else for unknown. If your command doesn't do this, you could also write a wrapper shell script that runs your command, and returns one of those codes. For now, let's just work with check_mycluster.py.
In order to get Nagios to run this command, you can:
* install an agent (like
NCPA) on the Linux system, and copy check_mycluster.py to the plugins directory. From there, you can create an NCPA check that calls your check_mycluster.py plugin. More information here,
https://www.nagios.org/ncpa/help/2.1/active.html
* use the check_by_ssh plugin, which will ssh into a remote system, execute a given command, and bring the return message and exit code back to Nagios. More information here,
https://nagios-plugins.org/doc/man/check_by_ssh.html
Re: Run command
Posted: Tue Sep 24, 2019 1:08 pm
by fsodah
installing NCPA is a must ??? I need to check if redhat certify installing packages outside the repos
Re: Run command
Posted: Tue Sep 24, 2019 1:12 pm
by mbellerue
No, my apologies. These are two different ways of accomplishing this task. If you don't want to, or can't install NCPA in your environment, you can use the check_by_ssh plugin from the Nagios XI server. That will ssh into your Linux host, and execute a command without needing any additional clients on the Linux host.
Re: Run command
Posted: Tue Sep 24, 2019 1:18 pm
by fsodah
100% ... I can not install any third party on these servers, it would be great if you could show me an example how to work with check_by_ssh call a command and get it the response back and sending it out to admin via mail or sms.
Re: Run command
Posted: Tue Sep 24, 2019 3:56 pm
by mbellerue
check_by_ssh uses a lot of the same command line switches as the standard OpenSSH client.
-H for your host
-p for your port
-l for your user
-i for your identity file
There's also -C, for the command that you want to have run on the Linux host. So your command looks something like this.
Code: Select all
/usr/local/nagios/libexec/check_by_ssh -H <LinuxHostIP> -p <port> -l <username> -i <sshkey> -C "/path/to/check_mycluster.py"
Also, there's this document which may be helpful.
https://assets.nagios.com/downloads/nag ... ng_SSH.pdf
Re: Run command
Posted: Wed Sep 25, 2019 3:28 am
by fsodah
Fair ... but how I can call these command from core config manager / config wizard ... since i use only that to add my hosts for notifications
Re: Run command
Posted: Wed Sep 25, 2019 9:35 am
by mbellerue
Oh I see, I was coming at this from angle of running the plugin. From inside of Nagios XI, we need to create the check command, then create the service to monitor, etc. Here is a doc that talks about plugins, and getting check commands setup.
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
Since check_by_ssh is a plugin that is already part of Nagios XI, you can skip down to the section titled, Define A Command. I'm also going to include a screenshot of the command definition page with our example check_by_ssh populated. One of the things I like to do when creating new commands in Nagios is to create them with my own prefix. Or at the very least, avoid the check_ prefix. This helps to quickly identify which check commands are the commands that I've created.
Edit:
I just realized that you had another thread, and I've already sent you that document. But that document should help in both cases.
Re: Run command
Posted: Wed Sep 25, 2019 10:11 am
by fsodah
Great I will try it and get back to you
Re: Run command
Posted: Wed Sep 25, 2019 11:21 am
by mbellerue
Okay, we will leave this thread open and wait to hear back.