Problem with Nagios check_by_ssh plugin is that it requires also the nagios-plugins to be installed on the client server. At least part of the nagios-plugins, because in the end all we need is to perform the local checks using ssh remote cmds.
So I put in a file nagiosclient.tar with the check scripts including some perl.The focus hereis to check Disk,Memory,Cpu of Linux remote servers. Without using SNMP, NRPE just plain SSH. I think its a great solution mainly because NRPE is a pain to install in Linux, in Windows its quite easy and I always try to use it combined with SNMP. SNMP is nice but its limited in what it can monitor, and sometimes it can get really messy. So lets start configuring SSH.
1. Set the SSH key authentication between Server and Client
Before we start we need the same user account and same password in both hosts!
Automatic login from host A / user b to Host B / user b. You don’t want to enter any passwords, because you want to call ssh from a within a shell script.
First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:
a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory ‘/home/a/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):
a@A:~> ssh b@B mkdir -p .ssh
Finally append a’s new public key to b@B:.ssh/authorized_keys and enter b’s password one last time:
a@A:~> cat .ssh/id_rsa.pub | ssh b@B ‘cat >> .ssh/authorized_keys’
From now on you can log into B as b from A as a without password:
a@A:~> ssh b@B hostname
2. Download nagios.tar and setup into remote client server
# cd /home/nagios
# wget http://www.xoroz.com/files/nagiosclient.tar.gz
# tar -zxvf nagiosclient.tar.gz
Check that Files are at /home/nagios/nagios
# chmod 755 /home/nagios/nagios
# chown nagios:nagios -R /
Now test it from the Nagios Server
check_dirsize.sh check_file_size.sh check_load2 check_mem.pl check_swap utils.pm
check_disk check_load check_log check_procs check_users utils.sh
7 thoughts on “check_by_ssh”
Hi! tnx for nice how-to, but i’m kinda fresh with Nagios, so i reall don’t know how to test this from Nagios Server, what else should i do on server side.
Testing it is really easy, just try to execute a remote command
ssh b@B ls
should get a list of the remote B server, if key authentication works.
Once you have done the 2nd part, download the nagios plugins into the remote server,
you could then call the nagios plugins to check Disk,Memory etc. like:
ssh b@B ls ‘/home/nagios/nagios/check_mem.pl’
Let me know if you need more help.
Thanks again. First part is clear to me, and second also.
I was wondering about getting results on Nagios interface. Yeah, I’m really beginning, so I really need to study configuring before.
So it is possible to call command like:
“ssh b@B /home/nagios/nagios/check_users -w 20 -c 50”
inside an object definition file and then get results in web interface?
Tnx for your help!
Well if the cmd works from the shell, next you will need to configure Nagios.
I use Centreon as the Web interface to configure Nagios, but you can also do it by cmd line or install centreon. But even if u install centreon I would recommend do it by hand to learn the internal of nagios, check out this howto
I’ve managed to configure it by hand properly and it works nice. Really thanks for this how-to. I’ll check centreon too