manuales:nagios:capacitacion:desarrollo_de_plugins_de_nagios
¡Esta es una revisión vieja del documento!
Tabla de Contenidos
Desarrollo de plugins de Nagios
Ejemplo de plugins SNMP
snmpd.conf
exec .1.3.6.1.4.1.2021.555.1 cat /bin/cat /backup/export_full/export_full.exit_status exec .1.3.6.1.4.1.2021.555.2 cat /bin/cat /backup/export_dos/export_dos.exit_status exec .1.3.6.1.4.1.2021.555.3 cat /bin/cat /backup/export_full_DB/export_full_DB.exit_status exec .1.3.6.1.4.1.2021.555.4 cat /bin/cat /backup/export_tres/exportTRES.exit_status
- check_snmp_exit_status.pl
#!/usr/bin/perl use Net::SNMP; $oid = $ARGV[1]; $snmpv3_username = "nagios"; # SNMPv3 username $snmpv3_password = "ClaV3RfsTtD2"; # SNMPv3 password $snmpv3_authprotocol = "md5"; # SNMPv3 hash algorithm (md5 / sha) $snmpv3_privpassword = ""; # SNMPv3 hash algorithm (md5 / sha) $snmpv3_privprotocol = "des"; # SNMPv3 encryption protocol (des / aes / aes128) $version = "3"; $timeout = "2"; $hostname = $ARGV[0]; # Crear la sesion SNMP ($s, $e) = Net::SNMP->session( -username => $snmpv3_username, -authpassword => $snmpv3_password, -authprotocol => $snmpv3_authprotocol, -hostname => $hostname, -version => $version, -timeout => $timeout, ); if ($s){ } else { print "CRITICAL - El agente no responde, SNMP v3 ($e)\n"; exit(2); } $s->get_request($oid); foreach ($s->var_bind_names()) { $oid_consulta = $s->var_bind_list()->{$_}; } $s->close(); if($oid_consulta == 0) { print "OK - El exit status es ".$oid_consulta."\n"; exit 0; } else { print "CRITICAL - El exit status es ".$oid_consulta."\n"; exit 2; }
Configuración de comando en Nagios
define service { host_name srvblabla service_description Control de exit status de backup use linux-service check_command check_snmp_cat_file_exit_status!.1.3.6.1.4.1.2021.555.1.101.1 check_interval 240 notification_interval 300 }
Ejemplos de scripts generales
check_heartbeat
Script simple para chequear el estado de HeartBeat y sus nodos, muy útil por cierto
- check_heartbeat
#!/bin/bash # Author: Emmanuel Bretelle # Date: 12/03/2010 # Description: Retrieve Linux HA cluster status using cl_status # Based on http://www.randombugs.com/linux/howto-monitor-linux-heartbeat-snmp.html # # Autor: Stanila Constantin Adrian # Date: 20/03/2009 # Description: Check the number of active heartbeats # http://www.randombugs.com # Get program path REVISION=1.3 PROGNAME=`/bin/basename $0` PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'` NODE_NAME=`uname -n` CL_ST='/usr/bin/cl_status' #nagios error codes #. $PROGPATH/utils.sh OK=0 WARNING=1 CRITICAL=2 UNKNOWN=3 usage () { echo "\ Nagios plugin to heartbeat. Usage: $PROGNAME $PROGNAME [--help | -h] $PROGNAME [--version | -v] Options: --help -l Print this help information --version -v Print version of plugin " } help () { print_revision $PROGNAME $REVISION echo; usage; echo; support } while test -n "$1" do case "$1" in --help | -h) help exit $STATE_OK;; --version | -v) print_revision $PROGNAME $REVISION exit $STATE_OK;; # -H) # shift # HOST=$1;; # -C) # shift # COMMUNITY=$1;; *) echo "Heartbeat UNKNOWN: Wrong command usage"; exit $UNKNOWN;; esac shift done $CL_ST hbstatus > /dev/null res=$? if [ $res -ne 0 ] then echo "Heartbeat CRITICAL: Heartbeat is not running on this node" exit $CRITICAL fi declare -i I=0 declare -i A=0 NODES=`$CL_ST listnodes` for node in $NODES do status=`$CL_ST nodestatus $node` let I=$I+1 if [ $status == "active" ] then let A=$A+1 fi done if [ $A -eq 0 ] then echo "Heartbeat CRITICAL: $A/$I" exit $CRITICAL elif [ $A -ne $I ] then echo "Heartbeat WARNING: $A/$I" exit $WARNING else echo "Heartbeat OK: $A/$I" exit $OK fi </code> <code> define command { command_name check_ha_by_ssh command_line $USER1$/check_by_ssh -l root -H $HOSTADDRESS$ -C "/usr/local/sbin/check_heartbeat.sh" }
check_systemimager
Script para chequear que nuestras imágenes estén actualizadas a la fecha
- check_systemimager
#!/usr/bin/php -q # Sergio Cayuqueo <cayu@cayu.com.ar> # http://cayu.com.ar <?php $lista_imagenes = shell_exec("si_lsimage --verbose|grep Image"); $lista_imagenes = preg_split("/[\n]+/",$lista_imagenes); $fecha_actual = date('Y.m.d'); foreach($lista_imagenes as $imagen) { if(strlen($imagen)>0) { if(@!$i) { $i=1; } $imagen = preg_split("/[\s]+/",$imagen); $imagenes[$i]['nombre'] = $imagen[2]; $imagenes[$i]['actualizada'] = $imagen[4]; $imagenes[$i]['ip'] = $imagen[8]; if($imagen[4] == $fecha_actual) { $imagenes[$i]['estado'] = "ok" ; } else { $imagenes[$i]['estado'] = "critical" ; $critical=1; } $i++; } } if(@$critical) { $head = "CRITICAL - Hubo un desfasaje en una o mas imagenes\n"; $exit = 2; } else { $head = "OK - Todas las imagenes actualizadas a la fecha\n"; $exit = 0; } print $head; foreach($imagenes as $imagen) { if(strlen($imagen['nombre'])<9) { $tab = "\t\t"; } else { $tab = "\t"; } if($imagen['estado'] == "ok") { print "OK - ".$imagen['nombre']." ".$tab.$imagen['ip']."\n"; } else { print "CRITICAL - ".$imagen['nombre']." ".$tab.$imagen['ip']." \t actualizado a : ".$imagen['actualizada']."\n"; } } exit($exit); ?>
define command { command_name check_si_by_ssh command_line $USER1$/check_by_ssh -l root -H $HOSTADDRESS$ -C "/usr/local/sbin/check_systemimager.php" }
manuales/nagios/capacitacion/desarrollo_de_plugins_de_nagios.1445525507.txt.gz · Última modificación: 2015/10/22 14:51 por cayu