Nagios Server Client - Config

[root@crmsrv /]# apt-get install nagios-nrpe-server sudo
[root@crmsrv /]# pico -w /etc/nagios/nrpe.cfg
server_address=192.168.0.20
allowed_hosts=127.0.0.1,82.197.134.3 # Monitor-Server

command[check_mysql]=/usr/lib/nagios/plugins/check_mysql -H localhost -u root --password='...'
command[check_load]=/usr/lib/nagios/plugins/check_load -w 5,7,9 -c 10,15,20
command[check_3ware]=/usr/lib/nagios/plugins/check_3ware
command[check_users]=/usr/lib/nagios/plugins/check_users -w 3 -c 5
command[check_disk_root]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
command[check_disk_data]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /data
command[check_disk_usr]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /usr
command[check_disk_var]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /var
command[check_procs]=/usr/lib/nagios/plugins/check_procs -w 250 -c 400 -s RSZDT
command[check_zombie]=/usr/lib/nagios/plugins/check_procs -w 250 -c 400 -s Z
command[check_swap]=/usr/lib/nagios/plugins/check_swap -av -w 80% -c 20%
command[check_samba]=/usr/lib/nagios/plugins/check_disk_smb -H 10.200.200.253 -s crm -u CRM --password='...'
command[check_mem]=/usr/lib/nagios/plugins/check_procs -w 4000000 -c 5000000 --metric=VSZ
command[check_cpu]=/usr/lib/nagios/plugins/check_procs  -w 80 -c 96 --metric=CPU
[root@crmsrv /]# pico -w /usr/lib/nagios/plugins/check_3ware

Sie müssen dieses Skript an Ihre Bedürfnisse anpassen.


  - !/usr/bin/php -n
<?php

define('DEVICE', 'c0');
define('SUDO', '/usr/bin/sudo');
define('TWCLI', '/usr/sbin/tw-cli');

$fp = popen(SUDO." ".TWCLI." info ".DEVICE, "r");
$c  = explode("\n", trim(stream_get_contents($fp)));
$h  = array_flip(explode(" ", preg_replace('/\s\s+/', ' ', $c[0])));
$d  = explode(" ", preg_replace('/\s\s+/', ' ', $c[2]));

if ($d[$h['Status']] != 'OK') {
  echo $c[2];
     if ($d[$h['Status']] == 'REBUILDING') exit(1);
     else                                  exit(2);
}

$h = array_flip(explode(" ", preg_replace('/\s\s+/', ' ', $c[4])));

for ($i=6; $i<count($c); $i++) {

    if (!trim($c[$i])) break;

    $d = array_map('trim', explode(" ", preg_replace('/\s\s+/', ' ', $c[$i])));
    if (!isset($d[$h['Status']]) || $d[$h['Unit']] == '-') continue;

    if ($d[$h['Status']] != 'OK') {
        echo $c[$i];
        exit(2);
    }
}

echo $c[2];
exit(0);

?>

[root@crmsrv /]# chmod +x /usr/lib/nagios/plugins/check_3ware

[root@crmsrv /]# visudo

Fügen Sie die folgenden Zeilen an das Ende der Datei an.

nagios ALL=NOPASSWD: /usr/sbin/tw-cli

Sie können es nun testen. Sie können es ohne Password ausführen:

[root@crmsrv /]# sudo -u nagios /usr/lib/nagios/plugins/check_3ware

für LSI MegaRAID SAS-Controller

Zuerst ist megactl_0_4_1.deb oder megactl_0_4_1_i386.deb zu installieren mit:

[root@crmsrv /]# dpkg -i Megactl_0.4.1.deb

[root@crmsrv /]# pico -w /usr/lib/nagios/plugins/check_lsi

Sie müssen dieses Skript an Ihre Bedürfnisse anpassen.


  - !/bin/bash

HOST=$(hostname)
SUDO=/usr/bin/sudo
MEGACTL=/usr/sbin/megasasctl
ADMIN=test@example.com

CHECKRAID=$($SUDO $MEGACTL | grep -i 'degraded\|fail')

if (( $? != 0 ))
then
  echo "OK - $HOST - RAID OK"
     exit 0;
else
  echo -e "$($SUDO $MEGACTL)" | mail $ADMIN -s "$HOST RAID Error"
     RAIDDETAILS=$($SUDO $MEGACTL | grep -i 'rebuild')
     if (( $? == 0 ))
     then
         echo "WARNING - $HOST - RAID rebuilding"
         exit 1;
     else
         echo "CRITICAL - $HOST - RAID critical"
         exit 2;
     fi
fi

echo "CRITICAL - $HOST - RAID unknown"
exit 3;

[root@crmsrv /]# chmod +x /usr/lib/nagios/plugins/check_lsi

[root@crmsrv /]# visudo

Fügen Sie die folgenden Zeilen an das Ende der Datei an.

nagios ALL=NOPASSWD: /usr/sbin/megasasctl

Sie können es nun testen. Sie können es ohne Password ausführen:

[root@crmsrv /]# sudo -u nagios /usr/lib/nagios/plugins/check_lsi

für HP SmartArray Controller

Zuerst HP Array Configuration Utility CLI installieren:

Datei /etc/apt/sources.list bearbeiten und folgende Zeile anfügen:

deb http://hwraid.le-vert.net/debian squeeze main

[root@crmsrv /]# apt-get update [root@crmsrv /]# apt-get install hpacucli

Anschliessend das Script konfigurieren:

[root@crmsrv /]# pico -w /usr/lib/nagios/plugins/check_hpsmart

Sie müssen dieses Skript an Ihre Bedürfnisse anpassen.


  - !/usr/bin/php -n
<?php

define('SLOT', '1');
define('SUDO', '/usr/bin/sudo');
define('ACUCLI', '/usr/sbin/hpacucli');

$fp_controller = popen(SUDO." ".ACUCLI." controller slot=".SLOT." show status", "r");
$fp_drives     = popen(SUDO." ".ACUCLI." controller slot=".SLOT." pd all show status", "r");
$controller    = array_map('trim', explode("\n", trim(stream_get_contents($fp_controller))));
$drives        = array_map('trim', explode("\n", trim(stream_get_contents($fp_drives))));

if (count($controller) < 2) {
  echo 'No Controller-Information found.';
         exit(2);
}
elseif (!count($drives)) {
  echo 'No physical drives found.';
         exit(2);
}

if (substr($controller[1], -2) != 'OK') {
  echo $controller[0].' - '.$controller[1];
         exit(2);
}
elseif (isset($controller[2]) && substr($controller[2], -2) != 'OK') {
  echo $controller[0].' - '.$controller[2];
         exit(1);
}
elseif (isset($controller[3]) && substr($controller[3], -2) != 'OK') {
  echo $controller[0].' - '.$controller[3];
         exit(1);
}

foreach ($drives as $drive) {
  if (substr($drive, -2) == 'OK') {
                 continue;
         }

       echo $controller[0].' - '.$drive;

       if (substr($drive, -6) == 'Failed') exit(2);
       else                                exit(1);
}

echo $controller[0].' OK';
exit(0);

?>

[root@crmsrv /]# chmod +x /usr/lib/nagios/plugins/check_hpsmart
[root@crmsrv /]# visudo

Fügen Sie die folgenden Zeilen an das Ende der Datei an.

nagios ALL=NOPASSWD: /usr/sbin/hpacucli

Sie können es nun testen. Sie können es ohne Password ausführen:

[root@crmsrv /]# sudo -u nagios /usr/lib/nagios/plugins/check_hpsmart
[root@crmsrv /]# apt-get install smartmontools
[root@crmsrv /]# pico -w /usr/lib/nagios/plugins/check_3ware_temp

Sie müssen dieses Skript an Ihre Bedürfnisse anpassen.

#!/bin/bash

ret=`/usr/bin/sudo /usr/sbin/smartctl -a -d 3ware,$1 /dev/twa0 | grep Temperature | awk '{print $10}'`

if [ $ret -gt 45 ];
then
   echo "DISK $1 WARNING: Temperature high at Disk $1 ($ret °C)|hdtemp=$ret;";
   exit 1;
else
   echo "DISK $1 OK: Temperature normal at Disk $1 ($ret °C)|hdtemp=$ret;";
   exit 0
fi
[root@crmsrv /]# chmod +x /usr/lib/nagios/plugins/check_3ware_temp
[root@crmsrv /]# visudo

Fügen Sie die folgenden Zeilen an das Ende der Datei an.

nagios ALL=NOPASSWD: /usr/sbin/smartctl

Sie können es nun testen. Sie können es ohne Password ausführen:

[root@crmsrv /]# sudo -u nagios /usr/lib/nagios/plugins/check_3ware_temp 0
[root@crmsrv /]# /etc/init.d/nagios-nrpe-server restart
[root@monitor /]# pico -w /etc/nagios3/conf.d/_hostname_.cfg

Tauschen Sie host mit dem hostnamen.

define host {
        use         linux-server
        host_name   host
        alias       intranet.host.com
        address     163.54.123.25
        }

define service{
        use                             remote-service
        host_name                       host
        contact_groups                  admins
        service_description             PING
        check_command                   check_ping!300.0,20%!500.0,60%
        }

define service{
        use                             remote-service         
        host_name                       host
        contact_groups                  admins
        service_description             HTTPS
        check_command                   check_https
        }

define service{
        use                             remote-service         
        host_name                       host
        contact_groups                  admins
        service_description             SSH
        check_command                   check_ssh_port!22
        }

define service{
        use                             remote-service
        host_name                       host
        contact_groups                  admins
        service_description             USERS
        check_command                   check_nrpe!check_users
        }

define service{
        use                             remote-service
        host_name                       host
        contact_groups                  admins
        service_description             LOAD
        check_command                   check_nrpe!check_load
        }

define service{
        use                             remote-service
        host_name                       host
        contact_groups                  admins
        service_description             DISK /
        check_command                   check_nrpe!check_disk_root
        }

define service{
        use                             remote-service
        host_name                       host
        contact_groups                  admins
        service_description             DISK /data
        check_command                   check_nrpe!check_disk_data
        }

define service{
        use                             remote-service
        host_name                       host
        contact_groups                  admins
        service_description             DISK /usr
        check_command                   check_nrpe!check_disk_usr
        }

define service{
        use                             remote-service
        host_name                       host
        contact_groups                  admins
        service_description             DISK /var
        check_command                   check_nrpe!check_disk_var
        }

define service{
        use                             remote-service
        host_name                       host
        contact_groups                  admins
        service_description             ZOMBIE
        check_command                   check_nrpe!check_zombie
        }

define service{
        use                             remote-service
        host_name                       host
        contact_groups                  admins
        service_description             PROCS
        check_command                   check_nrpe!check_procs
        }

define service{
        use                             remote-service
        host_name                       host
        contact_groups                  admins
        service_description             MYSQL
        check_command                   check_nrpe!check_mysql
        }

define service{
        use                             remote-service
        host_name                       host
        contact_groups                  admins
        service_description             SWAP
        check_command                   check_nrpe!check_swap
        }

define service{
        use                             remote-service
        host_name                       host
        contact_groups                  admins
        service_description             CPU
        check_command                   check_nrpe!check_cpu
        }

define service{
        use                             remote-service
        host_name                       host
        contact_groups                  admins
        service_description             MEM
        check_command                   check_nrpe!check_mem
        }

define service{
        use                             remote-service
        host_name                       host
        contact_groups                  admins
        service_description             3WARE
        check_command                   check_nrpe!check_3ware
        }

define service{
        use                             remote-service
        host_name                       host
        contact_groups                  admins
        service_description             SAMBA
        check_command                   check_nrpe!check_samba
        }
[root@monitor /]# /etc/init.d/nagios3 restart