Herramientas de usuario

Herramientas del sitio


manuales:nagios:capacitacion:desarrollo_de_plugins_de_nagios

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anteriorRevisión previa
Próxima revisiónAmbos lados, revisión siguiente
manuales:nagios:capacitacion:desarrollo_de_plugins_de_nagios [2015/10/16 14:55] cayumanuales:nagios:capacitacion:desarrollo_de_plugins_de_nagios [2015/10/22 14:51] cayu
Línea 1: Línea 1:
 ====== Desarrollo de plugins de Nagios ====== ====== Desarrollo de plugins de Nagios ======
- 
 ==== Ejemplo de plugins SNMP ==== ==== Ejemplo de plugins SNMP ====
- 
 snmpd.conf snmpd.conf
 <code> <code>
Línea 61: Línea 59:
  check_interval                  240  check_interval                  240
  notification_interval          300  notification_interval          300
 +}
 +</code>
 +
 +==== Ejemplos de scripts generales ====
 +== check_heartbeat ==
 +
 +Script simple para chequear el estado de HeartBeat y sus nodos, muy útil por cierto
 +
 +<file bash 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"
 +}
 +</file>
 +
 +== check_systemimager ==
 +
 +Script para chequear que nuestras imágenes estén actualizadas a la fecha
 +
 +<file php 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);
 +?>
 +</file>
 +
 +
 +<code>
 +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"
 } }
 </code> </code>
manuales/nagios/capacitacion/desarrollo_de_plugins_de_nagios.txt · Última modificación: 2016/07/27 15:12 por cayu