Zum Inhalt springen

Nagios3 unter Debian Linux: Unterschied zwischen den Versionen

Aus LHlab Wiki
Zeile 147: Zeile 147:
<pre>
<pre>
define contact{
define contact{
         contact_name                    contact_sms
         contact_name                    contact_mail_sms
         alias                          Admin SMS
         alias                          Admin Mail and SMS
         service_notification_period    24x7
         service_notification_period    24x7
         host_notification_period        24x7
         host_notification_period        24x7
         service_notification_options    c
         service_notification_options    c
         host_notification_options      d
         host_notification_options      d
         #service_notification_commands  notify-service-by-email
         service_notification_commands  notify-service-by-email
         #host_notification_commands      notify-host-by-email
         host_notification_commands      notify-host-by-email
         #email                          mail@domain.de
         email                          mail@domain.de
         service_notification_commands  service-notify-by-gnokii
         service_notification_commands  service-notify-by-gnokii
         host_notification_commands      host-notify-by-gnokii
         host_notification_commands      host-notify-by-gnokii
         pager                          +491744556677
         pager                          +491744556677
         }
         }
define contactgroup{
        contactgroup_name      smsmailadmins
        alias                  SMS and Mail Administrators
        members                contact_mail_sms
        }
</pre>
Nun kann man die "smsmailadmins" Gruppe in den Services zur Alarmierung nutzen:<br>
Ich habe hierfür einen neuen Service "critical-service" angelegt:<br>
''/etc/nagios3/conf.d/generic-service_nagios2.cfg''
<pre>
define service{
        name                            critical-service ; The 'name' of this service template
        active_checks_enabled          1      ; Active service checks are enabled
        passive_checks_enabled          1      ; Passive service checks are enabled/accepted
        parallelize_check              1      ; Active service checks should be parallelized (disabling this can lead to major performance problems)
        obsess_over_service            1      ; We should obsess over this service (if necessary)
        check_freshness                0      ; Default is to NOT check service 'freshness'
        notifications_enabled          1      ; Service notifications are enabled
        event_handler_enabled          1      ; Service event handler is enabled
        flap_detection_enabled          1      ; Flap detection is enabled
        failure_prediction_enabled      1      ; Failure prediction is enabled
        process_perf_data              1      ; Process performance data
        retain_status_information      1      ; Retain status information across program restarts
        retain_nonstatus_information    1      ; Retain non-status information across program restarts
                notification_interval          0              ; Only send notifications on status change by default.
                is_volatile                    0
                check_period                    24x7
                normal_check_interval          3
                retry_check_interval            2
                max_check_attempts              4
                notification_period            24x7
                notification_options            w,u,c,r
                contact_groups                  smsmailadmins
        register                        0      ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
        }
</pre>
Dieser kann dann zum Beispiel bei der DNS Server Abfrage verwendet werden:
<pre>
define service {
        host_name                      hostname
        service_description            DNS
        check_command                  check_dns
        use                            critical-service
        notification_interval          0 ; set > 0 if you want to be renotified
}
</pre>
</pre>



Version vom 18. Oktober 2010, 10:07 Uhr

Warnung Work in Progress

Diese Seite wird erst noch aufgebaut. Bitte noch keine Änderungen vornehmen, ohne mit dem ursprünglichen Author zu sprechen!
Vielen Dank

Nagios 3 - Der Monitoring Server

Installation Nagios3

Konfiguration Nagios3

NConf Installation

Webseite des Herstellers: http://www.nconf.org

Abhängigkeiten installieren

Folgende Pakete müssen vor der Installation auf dem System vorhanden sein:

  • Apache Webserver
  • PHP4.4 oder höher mit php-mysql (bei LDAP Auth auch php-ldap)
  • MySQL 5.0.2 inkl. InnoDB
  • Perl 5.6 oder höher mit perl-DBI und perl-dbd-mysql
  • ein Nagios Binary

Diese können mittels aptitude ggf. nachinstalliert werden.

Datenbank vorbereiten

am Datenbankserver anmelden:

mysql -u root -p

Und nun die Datenbank anlegen:

create database nconf;
grant select, insert, update, delete, create, drop, alter ON `nconf`.* to 'nconf'@'hostname' identified by 'nconfpass';

Nconf Installieren

Zuerst von der Downloadpage des Herstellers auf den Server laden und entpacken:

cd /usr/src/
wget http://sourceforge.net/projects/nconf/files/nconf/1.2.6-0/nconf-1.2.6-0.tgz/download
tar -xzvf nconf-1.2.6-0.tgz

Nun in den Apache vhost kopieren und die richtigen Rechte setzten:

mv nconf /var/www/
cd /var/www/
chown www-data:www-data ./config ./output ./temp

Nun kann die Datenbank gefüttert werden:

mysql -u root -p -D nconf < /var/www/INSTALL/create_database.sql

Nconf Konfigurieren

Zum konfigurieren kann nun folgender Pfad in einem Browser geöffnet werden:

http://<HOSTNAME>/nconf/INSTALL.php 

Hier werden dann die Abhängigkeiten geprüft und bei einem Klick auf next kommt man zur Datenbankeinrichtung. Bei einem weiteren Klick auf next prüft er die Datenbankverbindung. Ist diese erfolgreich gelangt man weiter zur General configuration. Diese habe ich auf den Default Werten stehen gelassen. Genau wie die nächste Seite Authentication configuration, hier brauche ich nichts einstellen, da der ganze vhost eh Passwortgeschützt ist. Nachdem nochmals alles geprüft wird und die Configfiles angelegt wurden sollten folgende Dateien gelöscht werden:

cd /var/www/nconf
rm INSTALL.php
rm UPDATE.php
rm -rf INSTALL
rm -rf UPDATE

Nun noch das Nagios Binary in den richtigen Ordner kopieren:

/var/www/nconf/bin/nagios

Dieses sollte bei einem nagios3 unter /usr/sbin/nagios3 zu finden sein.

Nconf starten

Beim folgendem Aufruf begrüßt einen die NCONF Startpage:

http://<HOSTNAME>/nconf/

NRPE - Der Linux Nagios Client

NSClient - Der Windows Nagios Client

SMS Benachrichtigungen verschicken mit Nagios & Gnokii

Installation Gnokii

aptitude install gnokii

Konfiguration Gnokii

Ich nutze ein Sony Ericsson K530i am USB Port, hier meine Konfig. /etc/gnokiirc

[global]
port = /dev/ttyACM0
model = AT
initlength = default
connection = serial
use_locking = yes
serial_baudrate = 19200
smsc_timeout = 10
[xgnokii]
allow_breakage = 0
[gnokiid]
bindir = /usr/sbin/
[connect_script]
TELEPHONE = 12345678
[disconnect_script]
[logging]
debug = off
rlpdebug = off
xdebug = off

Konfigurationstest:

gnokii --config /etc/gnokiirc --monitor once

hier sollte ungefähr folgende Ausgabe kommen:

GNOKII Version 0.6.26
Entering monitor mode...
Network: D2, Germany (262 07)
LAC: a102 (4xx1x), CellID: 00xxea2x (5xx3x)
RFLevel: 16
Battery: 89
Power Source: AC-DC
SIM: Used 20, Free 730
Phone: Used 65, Free 2435
DC: Used 11, Free 19
LD: Used 11, Free 19
MC: Used 12, Free 18
ON: Used 0, Free 1000
RC: Used 7, Free 23
CALL0: IDLE
CALL1: IDLE
Leaving monitor mode...

Eine Test SMS kann so verschickt werden:

echo "Hello world" | gnokii --config /etc/gnokiirc --sendsms 01721234456 -r

Konfiguration der Nagios SMS Benachrichtigung

Zuerst das Skript anlegen welches für den SMS Versand zuständig ist:
/usr/lib/nagios/plugins/sms_notification_by_gnokii

#!/bin/sh
#
# Gnokii Plugin script
# (c) Horst venzke
# v 0.1 - 17.01.2004

mess=$2
number=$1
echo "${mess}" | gnokii --sendsms ${number}

Dann noch dem Skript das Ausführrecht geben:

chmod +x /usr/lib/nagios/plugins/sms_notification_by_gnokii

Nun kann die SMS Benachrichtigung in die Nagios Konfiguration aufgenommen werden. Hierfür müssen folgende Zeilen in die /etc/nagios3/commands.cfg in der NOTIFICATION COMMANDS Sektion eingefügt werden:

define command {
        command_name service-notify-by-gnokii
        command_line $USER1$/sms_notification_by_gnokii $CONTACTPAGER$ "$NOTIFICATIONTYPE$ - $HOSTNAME$/$SERVICEDESC$ is $SERVICESTATE$ - $SERVICEOUTPUT$"
        }

define command {
        command_name host-notify-by-gnokii
        command_line $USER1$/sms_notification_by_gnokii $CONTACTPAGER$ "Nagios Host Alert - $HOSTALIAS$ is $HOSTSTATE$; $OUTPUT$; $DATETIME$"
        }

So, nun kann die neue SMS Benachrichtigung in der Kontakt Datei verwendet werden:
/etc/nagios3/conf.d/contacts_nagios2.cfg

define contact{
        contact_name                    contact_mail_sms
        alias                           Admin Mail and SMS
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    c
        host_notification_options       d
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
        email                           mail@domain.de
        service_notification_commands   service-notify-by-gnokii
        host_notification_commands      host-notify-by-gnokii
        pager                           +491744556677
        }

define contactgroup{
        contactgroup_name       smsmailadmins
        alias                   SMS and Mail Administrators
        members                 contact_mail_sms
        }

Nun kann man die "smsmailadmins" Gruppe in den Services zur Alarmierung nutzen:
Ich habe hierfür einen neuen Service "critical-service" angelegt:
/etc/nagios3/conf.d/generic-service_nagios2.cfg

define service{
        name                            critical-service ; The 'name' of this service template
        active_checks_enabled           1       ; Active service checks are enabled
        passive_checks_enabled          1       ; Passive service checks are enabled/accepted
        parallelize_check               1       ; Active service checks should be parallelized (disabling this can lead to major performance problems)
        obsess_over_service             1       ; We should obsess over this service (if necessary)
        check_freshness                 0       ; Default is to NOT check service 'freshness'
        notifications_enabled           1       ; Service notifications are enabled
        event_handler_enabled           1       ; Service event handler is enabled
        flap_detection_enabled          1       ; Flap detection is enabled
        failure_prediction_enabled      1       ; Failure prediction is enabled
        process_perf_data               1       ; Process performance data
        retain_status_information       1       ; Retain status information across program restarts
        retain_nonstatus_information    1       ; Retain non-status information across program restarts
                notification_interval           0               ; Only send notifications on status change by default.
                is_volatile                     0
                check_period                    24x7
                normal_check_interval           3
                retry_check_interval            2
                max_check_attempts              4
                notification_period             24x7
                notification_options            w,u,c,r
                contact_groups                  smsmailadmins
        register                        0       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
        }

Dieser kann dann zum Beispiel bei der DNS Server Abfrage verwendet werden:

define service {
        host_name                       hostname
        service_description             DNS
        check_command                   check_dns
        use                             critical-service
        notification_interval           0 ; set > 0 if you want to be renotified
}

Handy Verbindung mit dem Server überwachen

Da ich ab und an das Problem hatte das die USB Verbindung vom Handy zum Server unterbrochen wurde oder gar ganz weg war, hab ich hier ein kleines Nagios Plugin geschrieben, welches überwacht ob das Handy für gnokii auslesbar ist.
check_phone.sh

#!/bin/sh
#########################################################################################
#check_phone.sh
#by A. Laub andreas@laub-home.de
#this Script reads a Backup Logfile which contains one line in this format:
#       201005131629 ERROR: Backup has Problems
#   or
#       201005131629 SUCCESS: Backup runs well
#date Format is: date +%Y%m%d%H%M
#
#run script:
#       check_phone.sh [LOGFILE] [TIME]
#
#License:
#This program is free software: you can redistribute it and/or modify it
#under the terms of the GNU General Public License as published by the
#Free Software Foundation, either version 3 of the License, or (at your option)
#any later version.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
#or FITNESS FOR A PARTICULAR PURPOSE.
########################################################################################

#Load the Pathes
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PATH

/usr/bin/gnokii --config /etc/gnokiirc --monitor once > /dev/null 2>&1
ERRORCODE=$?

if [ $ERRORCODE = 5 ]; then
        echo "OK - Mobile Phone is connected"
        exit 0
fi
if [ $ERRORCODE = 2 ]; then
        echo "CRITICAL - Mobile Phone is not connected"
        exit 2
fi
echo "CRITICAL - other Error"
exit 2

Dieses Script sollte am besten nach /usr/lib/nagios/plugins/ kopiert werden und das Ausführecht bekommen.
Nun die Plugin Konfigurationsdatei unter /etc/nagios-plugins/config anlegen:
check_phone.cfg

# 'check_mobile' command definition
define command{
        command_name    check_phone
        command_line    /usr/lib/nagios/plugins/check_phone.sh
        }

Und nun das ganze in die Nagios Konfiguration des Hostes:
zum Beispiel:

# check mobile phone
define service {
        host_name                       nagios-server
        service_description             Mobile Phone
        check_command                   check_phone
        use                             longtime-service
        notification_interval           0 ; set > 0 if you want to be renotified
}

Quellen