Send Generic Macros on SNMP TRAP

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
ingenieria.itoc
Posts: 10
Joined: Mon Oct 10, 2016 1:46 pm

Send Generic Macros on SNMP TRAP

Post by ingenieria.itoc »

Hi

Can you help me with my case?

I need send generic macros through of SNMP TRAP.

I will integrate two nagios core with HP OMi , and after that I apply correlation for events of two Nagios but i need to receive SNMP Traps with all macros generic and default of Nagios.

At moment only I have default macros of Nagios

Example default macros Nagios on SNMP TRAP:

Generic: 6; Specific: 7; Enterprise: .1.3.6.1.4.1.20006.1;
Variables:

Code: Select all

[1] .1.3.6.1.4.1.20006.1.3.1.2 (OctetString): http://www.naranya.com 
[2] .1.3.6.1.4.1.20006.1.3.1.10 (OctetString): COLOCADO QUERETARO 
[3] .1.3.6.1.4.1.20006.1.3.1.6 (OctetString): HTTP 
[4] .1.3.6.1.4.1.20006.1.3.1.7 (Integer): 2 
[5] .1.3.6.1.4.1.20006.1.3.1.17 (OctetString): CRITICAL 
[6] .1.3.6.1.4.1.20006.1.3.1.17 (OctetString): CRITICAL - Socket timeout after 20 seconds  
Example of the generic macros I need send on the SNMP TRAP

Code: Select all

define host{
        use                     triara-host
        host_name               http://www.clarovideo.com
        alias                   http://www.clarovideo.com
        address                 http://www.clarovideo.com
        _itoc_cliente           America Movil            #Generic Macro
        _itoc_plataforma        Akamai Techologies   #Generic Macro
        _itoc_grupo_whatsapp    Triara-Multimedia    #Generic Macro
        check_command           check_dummy
        flap_detection_enabled  1
        hostgroups              URLS_VIP
        contact_groups          soporten1
        notifications_enabled   0
        }

Code: Select all

define service{
        use                             local-service
        host_name                       http://www.clarovideo.com
        service_description             Check URL Desde Monterrey
        check_command                   check_url_itoc!www.clarovideo.com
        _itoc_seguimiento_ok          El servicio ha sido restablecido         #Generic Macro
        _itoc_seguimiento_alerta       Se presenta alerta en URL VIP, especialista favor de confirmar si se requiere notificar al cliente   #Generic Macro
        _itoc_solicitud_oper_ok         Actividad restablecida.      #Generic Macr
        _itoc_solicitud_oper_alerta     Favor de notificar a las areas correspondientes   #Generic Macro
        flap_detection_enabled          0
        check_interval                  1
        retry_interval                  1
        max_check_attempts              3
        contact_groups                  soporten1
        notifications_enabled           1
        }
Any idea

Regards
Last edited by dwhitfield on Wed Oct 12, 2016 3:56 pm, edited 1 time in total.
Reason: edited code block for consistency
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Send Generic Macros on SNMP TRAP

Post by ssax »

It should be doable, I have it about 90% done but I need to restore my VM so that it works and I can test it. I will let you know tomorrow the status and hopefully have a solution for you.

Thank you
ingenieria.itoc
Posts: 10
Joined: Mon Oct 10, 2016 1:46 pm

Re: Send Generic Macros on SNMP TRAP

Post by ingenieria.itoc »

ssax wrote:It should be doable, I have it about 90% done but I need to restore my VM so that it works and I can test it. I will let you know tomorrow the status and hopefully have a solution for you.

Thank you



Hi, exist a new status for this case ?

Kind Regards
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Send Generic Macros on SNMP TRAP

Post by ssax »

Yes, you would need to edit the xi_host_event_handler and xi_service_event_handler commands and add them in:

*** Note: This will get reverted if you upgrade and will need to be reimplemented.
*** Make sure that you have known-good backups/vm snapshots before making any modifications

In Configure > Core Config Manager > Commands:

xi_host_event_handler

Code: Select all

/usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_event.php --handler-type=host --host="$HOSTNAME$" --hostaddress="$HOSTADDRESS$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --lasthoststate=$LASTHOSTSTATE$ --lasthoststateid=$LASTHOSTSTATEID$ --hoststatetype=$HOSTSTATETYPE$ --currentattempt=$HOSTATTEMPT$ --maxattempts=$MAXHOSTATTEMPTS$ --hosteventid=$HOSTEVENTID$ --hostproblemid=$HOSTPROBLEMID$ --hostoutput="$HOSTOUTPUT$" --longhostoutput="$LONGHOSTOUTPUT$" --hostdowntime=$HOSTDOWNTIME$ --itoc_cliente='$_HOSTITOC_CLIENTE$' --itoc_plataforma='$_HOSTITOC_PLATAFORMA$' --itoc_grupo_whatsapp='$_HOSTITOC_GRUPO_WHATSAPP$'
xi_service_event_handler

Code: Select all

/usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_event.php --handler-type=service --host="$HOSTNAME$" --service="$SERVICEDESC$" --hostaddress="$HOSTADDRESS$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --hosteventid=$HOSTEVENTID$ --hostproblemid=$HOSTPROBLEMID$ --servicestate=$SERVICESTATE$ --servicestateid=$SERVICESTATEID$ --lastservicestate=$LASTSERVICESTATE$ --lastservicestateid=$LASTSERVICESTATEID$ --servicestatetype=$SERVICESTATETYPE$ --currentattempt=$SERVICEATTEMPT$ --maxattempts=$MAXSERVICEATTEMPTS$ --serviceeventid=$SERVICEEVENTID$ --serviceproblemid=$SERVICEPROBLEMID$ --serviceoutput="$SERVICEOUTPUT$" --longserviceoutput="$LONGSERVICEOUTPUT$" --servicedowntime=$SERVICEDOWNTIME$ --itoc_seguimiento_ok='$_SERVICEITOC_SEGUIMIENTO_OK$' --itoc_seguimiento_alerta='$_SERVICEITOC_SEGUIMIENTO_ALERTA$' --itoc_solicitud_oper_ok='$_SERVICEITOC_SOLICITUD_OPER_OK$' --itoc_solicitud_oper_alerta='$_SERVICEITOC_SOLICITUD_OPER_ALERTA$'
Then you edit this file:

Code: Select all

/usr/local/nagiosxi/html/includes/components/snmptrapsender/snmptrapsender.inc.php
Change line 380 to:

Code: Select all

$trap_command = "/usr/bin/snmptrap -v 2c -c $community $tcp$address$port '' NAGIOS-NOTIFY-MIB::nHostEvent nHostname s \"%host%\" nHostStateID i %hoststateid% nHostOutput s \"%hostoutput%\" 1.2.3.4.5.6 s '%itoc_cliente%' 1.2.3.4.5.7 s '%itoc_plataforma%' 1.2.3.4.5.8 s '%itoc_grupo_whatsapp%'";
Change line 434 to:

Code: Select all

$trap_command = "/usr/bin/snmptrap -v 2c -c $community $tcp$address$port '' NAGIOS-NOTIFY-MIB::nSvcEvent nSvcHostname s \"%host%\" nSvcDesc s \"%service%\" nSvcStateID i %servicestateid% nSvcOutput s \"%serviceoutput%\" 1.2.3.4.5.6 s '%itoc_seguimiento_ok%' 1.2.3.4.5.7 s '%itoc_seguimiento_alerta%' 1.2.3.4.5.8 s '%itoc_solicitud_oper_ok%' 1.2.3.4.5.9 s '%itoc_solicitud_oper_alerta%'";

That should do it, let me know if you have any questions.
Locked