lunes, 11 de marzo de 2013

SNMPTraps y Centreon 2.4


Hola,

 durante estos días me he tenido que enfrentar con un problema que ha surgido al chequear el NAS de EMC (antiguo celerra).  La monitorización se realiza con el sistema de monitorización Centreon que a su vez en sus capas más bajas utiliza Nagios.  Dejo para proximos post el funcionamiento cliente-servidor del protocolo SNMP y la monitorización por NRPE de Centreon. En este caso nos centraremos en como Centreon 2.4 recibe alertas de forma pasiva desde dispositivos que tenga habilitado SNMPTrap. 

La idea básica es que uno de nuestros sistemas al tener algún cambio de estado o mal funcionamiento envíe un mensaje por SNMP a nuestro servidor de monitorización. Esté último nos avisará mediante alertas y correo. Se realizá por SNMPTrap y no por NRPE para evitar instalar agentes y software no soportado por el fabricante, en este caso por EMC.

Como trata Centreon los SNMP Traps

En la versión 2.4 de Centreon el circuito de un mensaje o Trap es el siguiente; el servidor de Centreon tiene configurado el demonio de snmpd, escuchando mensajes snmp en la red destinados a él. Hay otro demonio que es ejecutado junto con él llamado snmptrapd que recibe el trap, y lo envía a un traductor snmptt que comprueba si hay una MIB. Si la hay genera un comando de Centreon (centTrapHandler) para insertarlo como mensaje en Nagios. Posteriormente envía una alerta y correo. Un poco complicado ¿verdad?

SNMPD --> SNMPTRAPD --> SNMPTT --> CENTTRAPHANDLER --> CENTREON

Bien, nuestro servidor está configurado de está forma y recibe las alertas por snmptrap sin problemas, excepto las que envía el NAS.  

Configuración de SNMP Traps para EMC

El primer paso que hay que realizar es buscar el fichero de MIB de nuestro dispositivo en la web del fabricante. El nuestro es el siguiente:



--------------------------------------------------------------------------
-- Copyright (c) 1998-2002, All rights reserved by
--
-- EMC Corporation
-- 171 South Street
-- Hopkinton, MA 01748 USA
--
-- This software is furnished under a license and may be used and copied
-- inclusion of the above copyright notice. This software or  any  other
-- only  in  accordance  with  the  terms  of such  license and with the
-- copies thereof may not be provided or otherwise made available to any
-- other person. No title to and ownership of  the  software  is  hereby
-- transferred.
--
-- The information in this software is subject to change without notice
-- and should not be construed as a commitment by EMC Corporation.
--
-- EMC Corporation assumes no responsibility for the use or reliability
-- of this software.
--
----------------------------------------------------------------------------
--
--
-- EMC Celerra Management Information Base description
--
----------------------------------------------------------------------------
----------------------------------------------------------------------------
--
-- Author Identification
--
-- gma      Gary Ma, EMC
-- WZ       Weining Zhu, EMC
-- alc      Angela Cocks, EMC
--
----------------------------------------------------------------------------
--
--  003  alc   07-19-02   Added Web GUI event
--  002  WZ    07-02-02   Added Jserver Alert trap type
--  001  WZ    04-18-01   Added Control Station started trap type
--  000  gma   11-05-98   Created Original Module
--
----------------------------------------------------------------------------
EMC-CELERRA DEFINITIONS ::= BEGIN
   IMPORTS
       enterprises, Opaque
 FROM RFC1155-SMI
       DisplayString
          FROM RFC1213-MIB
       OBJECT-TYPE
          FROM RFC-1212
       TRAP-TYPE
          FROM RFC-1215;
--     emc
--        FROM EMC-MIB;

       emc OBJECT IDENTIFIER ::= { enterprises 1139  }
       emcCelerra OBJECT IDENTIFIER ::= { emc 2 }
-------------------------------------------------------------------
--
--       Celerra Event Group
--
-------------------------------------------------------------------
       celEventTable OBJECT-TYPE
          SYNTAX SEQUENCE OF CelEvent
          ACCESS not-accessible
          STATUS mandatory
          DESCRIPTION
                   "A table containing information
   about an particular event."
          ::= { emcCelerra 1}
       celEvent OBJECT-TYPE
          SYNTAX CelEvent
          ACCESS not-accessible
          STATUS mandatory
          DESCRIPTION
                   "Information about an particular event."
          INDEX {celEventFacility,
                 celEventID}
          ::= { celEventTable 1}
       CelEvent ::= SEQUENCE { celEventFacility INTEGER,
                               celEventID INTEGER,
                               celEventSeverity INTEGER,
                               celEventDescr DisplayString}
                           
       celEventFacility OBJECT-TYPE
          SYNTAX INTEGER
          ACCESS read-only
          STATUS mandatory
          DESCRIPTION
                 "The number representing the facility which generates
                  the event. For now, the value could be:
                  first 128 - default Dart facility
                  129 - master control
                  130 - event log
                  131 - box monitor
                  132 - video service
                  133 - callhome application
                  134 - AAF backup control station."
          ::= { celEvent 1 }
       celEventID OBJECT-TYPE
          SYNTAX INTEGER
          ACCESS read-only
          STATUS mandatory
          DESCRIPTION
                  "The event id which identifies the particular event
                  within a facility."
          ::= { celEvent 2 }
       celEventSeverity OBJECT-TYPE
          SYNTAX INTEGER
          ACCESS read-only
          STATUS mandatory
          DESCRIPTION
                   "Severity of the event."
          ::= { celEvent 3 }
       celEventDescr OBJECT-TYPE
          SYNTAX DisplayString
          ACCESS read-only
          STATUS mandatory
          DESCRIPTION
                   "text description of the event."
          ::= { celEvent 4 }
     
----------------------------
--
--     Trap definitions
--
----------------------------
       celReboot TRAP-TYPE
          ENTERPRISE emcCelerra
          VARIABLES { celEvent }
          DESCRIPTION
                   "Trap message will be sent in the event of a Data Mover
                    Reboots. The trap message includes the facility, event id,
                    serverity and a text description of the event."
          ::= 1
       celMasterCtlFault TRAP-TYPE
          ENTERPRISE emcCelerra
          VARIABLES { celEvent }
          DESCRIPTION
                   "Trap message will be sent in the event of Master Control
                    serious fault.
                    unexpected daemon exit or control station heartbeat
                    missing."
          ::= 2
       celHWFailure TRAP-TYPE
          ENTERPRISE emcCelerra
          VARIABLES { celEvent }
          DESCRIPTION
                   "Trap message will be sent in the event of celerra hardware
                    failure."
          ::= 3
       celSlotStale TRAP-TYPE
          ENTERPRISE emcCelerra
          VARIABLES { celEvent }
          DESCRIPTION
                   "Trap message will be sent in the event of celerra stale
                    reason code."
          ::= 4
       celSlotPanicked TRAP-TYPE
          ENTERPRISE emcCelerra
          VARIABLES { celEvent }
          DESCRIPTION
                   "Trap message will be sent in the event of panicked
                    slot."
          ::= 5
       celIntfFailure TRAP-TYPE
          ENTERPRISE emcCelerra
          VARIABLES { celEvent }
          DESCRIPTION
                   "Trap message will be sent in the event of both interfaces
                    failure."
          ::= 6
       celAAF TRAP-TYPE
          ENTERPRISE emcCelerra
          VARIABLES { celEvent }
          DESCRIPTION
                   "Trap message will be sent in the event of AAF."
          ::= 7
       celCSStart TRAP-TYPE
          ENTERPRISE emcCelerra
          VARIABLES { celEvent }
          DESCRIPTION
                   "Trap message will be sent in the event of Control Station started."
          ::= 8
       celJServer TRAP-TYPE
          ENTERPRISE emcCelerra
          VARIABLES { celEvent }
          DESCRIPTION
                   "Trap message will be sent in the event of a JServer alert."
          ::= 9
       celWebGUI TRAP-TYPE
          ENTERPRISE emcCelerra
          VARIABLES { celEvent }
          DESCRIPTION
                   "Trap message will be sent in the event of a Web GUI notification request."
          ::= 10
END



Nos vamos a Centreon y seleccionamos Configuration  Services  Manufacturer y hacemos click en Add . Añadiremos EMC como nuevo fabricante.  Luego iremos a Configuration  Services  MIBs y seleccionaremos nuestro fabricante "EMC" y buscaremos nuestro fichero. 

Si todo hay ido bien nuestras MIBS estarán dentro de la base de datos de Centreon.


Para que se distribuya está información de la MIBS a snmptt, se ha de ir a Configuration  Nagios  Snmp traps y hacer click en Generate.

Creamos las respectivas alarmas y les asignamos sus respectivas MIBs. Con esto ya tendriamos configuradas las alertas  y traps.

Podeis ver más captura y detalles en el siguiente link:

Troubleshooting

Aquí es donde hay que empezar ha hacer un seguimiento del mensaje y comprobar donde se rompe la cadena. 

Crearemos un nuevo host y copiaremos las alertas de servicio para poder hacer pruebas desde nuestro PC. Al lanzar las traps de SNMP desde mi equipo funcionan.

Llegan al SNMPD y SNMPTRAP lo envia a SNMPTT:

Mar  7 09:13:31 myserver snmptrapd[17706]: 2013-03-07 09:13:31 PROVA(via UDP: [192.168.1.2]:57566) TRAP, SNMP v1, community public   .1.3.6.1.6.3.1.1.5.2 Cold Start Trap (0) Uptime: 1:06:38.49     .1.3.6.1.4.1 = STRING: "hello"

SNMPTT generá el comando y lo inserta en Centreon.

EXEC command:/usr/share/centreon/bin/centTrapHandler-2.x 192.168.1.2 PROVA .1.3.6.1.4.1.1139.2.0.1 "Trap message will be sent in the event of a Data Mover 'NOK'" "'NOK' "

Funciona!!

Vamos a probar de enviar el trap desde el NAS para ver cual es el resultado:

Llega al SNMPD y SNMPTRAP lo envia a SNMPTT:

Mar  7 15:00:18 mynas snmptrapd[8875]: 2013-03-07 15:00:18 mynas.mycompany.com [192.168.1.3] (via UDP: [192.168.1.3]:39813) TRAP, SNMP v1, community public        .1.3.6.1.4.1.1139.2 Enterprise Specific Trap (2) Uptime: 195 days, 16:36:06.76  .1.3.6.1.4.1.1139.2.1.1.1 = INTEGER: 81 .1.3.6.1.4.1.1139.2.1.1.2 = INTEGER: 6  .1.3.6.1.4.1.1139.2.1.1.3 = INTEGER: 3  .1.3.6.1.4.1.1139.2.1.1.4 = STRING: "Mar  7 14:53:13 2013 VC:3:6 Slot 2: 1362664806: No virus checker server is available. Virus checking is stopped."

SNMPTT generá el comando.... pero no lo inserta en Centreon!!

EXEC command:/usr/share/centreon/bin/centTrapHandler-2.x 192.168.1.2 mynas .1.3.6.1.4.1.1139.2.0.2 "Trap message will be sent in the event of Master Control '81' '6' '3' 'Mar  7 14:53:13 2013 VC:3:6 Slot 2: 1362664806: No virus checker server is available. Virus checking is stopped.'" "'81' '6' '3' 'Mar  7 14:53:13 2013 VC:3:6 Slot 2: 1362664806: No virus checker server is available. Virus checking is stopped.' 
Para ver que problema da, ejecutamos el comando a ver que error nos muestra.

# perl -w /usr/share/centreon/bin/centTrapHandler-2.x 192.168.1.2 mynas .1.3.6.1.4.1.1139.2.0.2 "Trap message will be sent in the event of Master Control '81' '6' '3' 'Mar  7 14:53:13 2013 VC:3:6 Slot 2: 1362664806: No virus checker server is available. Virus checking is stopped.'" "'81' '6' '3' 'Mar  7 14:53:13 2013 VC:3:6 Slot 2: 1362664806: No virus checker server is available. Virus checking is stopped.' "7: -c: line 0: unexpected EOF while looking for matching `"'7: -c: line 1: syntax error: unexpected end of file

Al parecer no está recogiendo correctamente los parámetros. Los espera entre comillas pero se encuentra un espacio en blanco.

Solución

Tras seguir el script de perl para ver que es lo que hacia, decido mirar en los foros de soporte de Centreon para ver si alguien se había encontrado en el mismo caso... y Eureka!!!

Tal y como comentan en el siguiente link, el proceso de snmptrap es complejo y tiene problemas con el tratamiento de las cadenas:
http://forge.centreon.com/issues/3218

La solución que se aporta es sustituir el sistema de snmptt por un script nuevo en perl que controla todas estás excepciones:
http://forge.centreon.com/issues/3546#change-11678

Aunque el nuevo sistema de traps estará por defecto en la versión 2.5 de Centreon, lo implementamos en la versión 2.4 y funciona sin problemas. Aleluya!!

Espero que os haya ayudado!!! Saludos!!

Algunos links de interés

http://en.doc.centreon.com/HowToManageSNMPTraps
http://www.net-snmp.org/wiki/index.php/TUT:snmptrap
http://snmptt.sourceforge.net/docs/snmptt.shtml



2 comentarios:

  1. Muy bueno, me he peleado muchas veces con el snmptt, si me acuerdo te paso un manual que hice de instalación y configuración de fan, es un centos con todo el software de nagios.

    ResponderEliminar
  2. Gracias Joaquin. Si, pasamelo que le daré un vistazo y haré un articulo.
    Saludos.

    ResponderEliminar