Monday, February 2, 2015

Nagios monitoring by SSH

On remote host: 192.168.1.10

[root@ubuntu ~]# useradd nagios -m -d /home/nagios
[root@ubuntu ~]# su - nagios
[nagios@ubuntu ~]$ mkdir .ssh
[nagios@ubuntu ~]$ touch authorized_keys
[nagios@ubuntu ~]$ mkdir /home/nagios/plugins
[nagios@ubuntu ~]$ passwd nagios >> put password for it

On Nagios server: 192.168.1.20

login as nagios user:

su - nagios
now you should probably on /home/nagios/

nagios@xxx:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/nagios/.ssh/id_rsa): 
Created directory '/home/nagios/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/nagios/.ssh/id_rsa.
Your public key has been saved in /home/nagios/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 nagios@xxx
The key's randomart image is:
+--[ DSA 1024]----+
| .. |
| o.= |
| Boo |
| oo .. |
| S .. |
| o o . |
| o Eoo.|
| . . ++o|
| . ++.*|
+-----------------+

create /home/nagios/.ssh folder in remote host by ssh

nagios@xxx:~> ssh nagios@192.168.1.20 mkdir -p .ssh
nagios@192.168.1.20's password:

now add new public key to remote host to .ssh/authorized_keys :

nagios@xxx:~> cat .ssh/id_rsa.pub | ssh nagios@192.168.1.20 'cat >> .ssh/authorized_keys'
nagios@192.168.1.20's password:

 try to login ssh without type password

ssh nagios@192.168.1.20

if above still not working try following below.
  • Put the public key in .ssh/authorized_keys2
  • Change the permissions of .ssh to 700
  • Change the permissions of .ssh/authorized_keys2 to 640

Now make sure you can ssh to the client without putting in your password.

cd /usr/local/nagios/libexec/
scp * nagios@192.168.1.20:/home/nagios/plugins/


Now on the server
[nagios@xxx ~]$ /usr/local/icinga/libexec/check_by_ssh -H 192.168.1.20 -C "/home/nagios/plugins/check_users -w 0 -c 1" -t 20
USERS CRITICAL - 2 users currently logged in |users=2;0;1;0


example for command.cfg

define command {
command_name check_by_ssh
command_line $USER1$/check_by_ssh -H $HOSTADDRESS$ -C $ARG1$
}


and host.cfg

define service{
        use                             generic-service         
        host_name                       VIP-VAS-kannel-01
        service_description             CPU LOAD
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              3
        normal_check_interval           1
        retry_check_interval            1
        notification_interval           120
        notification_period             24x7
        notification_options            w,u,c,r
        check_command                   check_by_ssh!"/home/nagios/plugins/check_load -w 80 -c 90" -t 60
        contact_groups                  RNDADMIN
        servicegroups                   CPULoad
        }


How to yum install packages from ISO file without internet. (CentOS)



  1. If you have the ISO burnt into a DVD, insert the DVD into the CentOS system. If the ISO is not burnt into a DVD, but present as a separate file on the file system, then skip the next two steps and go directly to step 4 in this list.
  2. Check if the DVD has been mounted automatically. To do this execute the following command:
    mount | grep CentOS
    
    If this command returns an output, it means the DVD has been mounted. For example, the following example output shows that the DVD has been mounted to /media/CentOS_6.4_Finalautomatically.
    /dev/sr0 on /media/CentOS_6.4_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=500,gid=500,iocharset=utf8,mode=0400,dmode=0500)
    
  3. If the CD has been mounted automatically, then ignore this step. Otherwise, mount it manually.
    mkdir /media/CentOS
    mount -t iso9660 /dev/sr0 /media/CentOS
    
  4. If the ISO is present on the file system, mount it to /media/CentOS using the mount command with -o loop option.
    mount -o loop CentOS-6.4-x86_64-bin-DVD1.iso /media/CentOS/
    
  5. Execute: cat /etc/yum.repos.d/CentOS-Media.repo and read the information provided as comments in this file. See the repo name within square brackets. It is c6-media by default. Also, see the locations specified for baseurl property. These URLs point to local directories /media/CentOS/media/cdrom and /media/cdrecorder/ by default.
  6. If the DVD is mounted to a mount point specified in the baseurl property, then ignore this step. Otherwise, create a symbolic link at a location specified in the baseurl property with the mount point as its target. An example follows.
    ln -s /media/CentOS_6.4_Final /media/CentOS
    
  7. In the shell, execute the yum command while disabling all repos except the repo specified in /etc/yum.repos.d/CentOS-Media.repo:
    yum --disablerepo=\* --enablerepo=c6-media install gcc