Page 2 of 2

Re: add hostgroups to service SNMP traps

Posted: Wed Feb 22, 2017 3:10 pm
by peter.zanetti
If I recreated how our host groups are set up but as service groups and then tried to add a servicegroupname /s to that command, do you think that would work?

Re: add hostgroups to service SNMP traps

Posted: Wed Feb 22, 2017 3:38 pm
by tgriep
That didn't work as well. I am thinking that the SNMP Trap Sender Component needs to be changed to add that to it.

Re: add hostgroups to service SNMP traps

Posted: Thu Feb 23, 2017 8:57 am
by peter.zanetti
Is that an easy change that we could make? What directory is the SNMP Trap Sender component in?

Re: add hostgroups to service SNMP traps

Posted: Thu Feb 23, 2017 12:41 pm
by tgriep
I modified the component to add the hostgroupnames when a trap is sent and it wasn't too difficult.
What you have to to is edit the component and also add the hostgroupnames entries in the NAGIOS-NOTIFY-MIB.txt file you have to import in to the device that is receiving the traps.

First, edit this file on the Nagios server

Code: Select all

/usr/local/nagiosxi/html/includes/components/snmptrapsender/snmptrapsender.inc.php
Change this line from

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%\"";
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%\" nHostHostgroupnames s \"%hostgroupnames%\"";
Then change this line from

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%\"";
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%\" nSvcHostgroupnames s \"%hostgroupnames%\"";
Save the file.

Next you need to add these entries to the NAGIOS-NOTIFY-MIB.txt that is uploaded to the device.
The one you edit is located in this folder

Code: Select all

/usr/local/nagiosxi/html/includes/components/snmptrapsender/mibs
And after the changes, copy the file to this folder

Code: Select all

/usr/share/snmp/mibs/
Edit the NAGIOS-NOTIFY-MIB.txt and change the following from

Code: Select all

HostEventEntry ::= SEQUENCE {
  nHostEventIndex    Integer32,
  nHostname          OCTET STRING,
  nHostAlias         OCTET STRING,
  nHostStateID       HostStateID,
  nHostStateType     HostStateType,
  nHostAttempt       Integer32,
  nHostDurationSec   Integer32,
  nHostGroupName     OCTET STRING,
  nHostLastCheck     Integer32,
  nHostLastChange    Integer32, 
  nHostLastUp        Integer32,
  nHostLastDown      Integer32,
  nHostLastUnreachable Integer32,
  nHostOutput        OCTET STRING,
  nHostPerfData      OCTET STRING
  }
to

Code: Select all

HostEventEntry ::= SEQUENCE {
  nHostEventIndex    Integer32,
  nHostname          OCTET STRING,
  nHostAlias         OCTET STRING,
  nHostStateID       HostStateID,
  nHostStateType     HostStateType,
  nHostAttempt       Integer32,
  nHostDurationSec   Integer32,
  nHostGroupName     OCTET STRING,
  nHostLastCheck     Integer32,
  nHostLastChange    Integer32, 
  nHostLastUp        Integer32,
  nHostLastDown      Integer32,
  nHostLastUnreachable Integer32,
  nHostOutput        OCTET STRING,
  nHostPerfData      OCTET STRING
  nHostHostgroupnames    OCTET STRING
  }
That added the "nHostHostgroupnames OCTET STRING" line.
Next you need to add the OID for that entry
Add the following

Code: Select all

nHostHostgroupnames OBJECT-TYPE  
  SYNTAX     OCTET STRING
  MAX-ACCESS read-only  
  STATUS     current  
  DESCRIPTION
    "This object contains The Hostgroups the Host is in."
  ::= { nagiosHostEventEntry 16 }
Under this line

Code: Select all

::= { nagiosHostEventEntry 15 }
Next change this from

Code: Select all

SvcEventEntry ::= SEQUENCE {
  nSvcEventIndex    Integer32,
  nSvcHostname      OCTET STRING,
  nSvcHostAlias     OCTET STRING,
  nSvcHostStateID   HostStateID,
  nSvcHostStateType HostStateType,
  nSvcDesc          OCTET STRING,
  nSvcStateID       ServiceStateID,
  nSvcAttempt       Integer32,
  nSvcDurationSec   Integer32,
  nSvcGroupName     OCTET STRING,
  nSvcLastCheck     Integer32,
  nSvcLastChange    Integer32,
  nSvcLastOK        Integer32,
  nSvcLastWarn      Integer32,
  nSvcLastCrit      Integer32,
  nSvcLastUnkn      Integer32,
  nSvcOutput        OCTET STRING,
  nSvcPerfData      OCTET STRING
  }
to

Code: Select all

SvcEventEntry ::= SEQUENCE {
  nSvcEventIndex    Integer32,
  nSvcHostname      OCTET STRING,
  nSvcHostAlias     OCTET STRING,
  nSvcHostStateID   HostStateID,
  nSvcHostStateType HostStateType,
  nSvcDesc          OCTET STRING,
  nSvcStateID       ServiceStateID,
  nSvcAttempt       Integer32,
  nSvcDurationSec   Integer32,
  nSvcGroupName     OCTET STRING,
  nSvcLastCheck     Integer32,
  nSvcLastChange    Integer32,
  nSvcLastOK        Integer32,
  nSvcLastWarn      Integer32,
  nSvcLastCrit      Integer32,
  nSvcLastUnkn      Integer32,
  nSvcOutput        OCTET STRING,
  nSvcPerfData      OCTET STRING
  nSvcHostgroupnames      OCTET STRING
  }
That added the "nSvcHostgroupnames OCTET STRING" line.
Next you need to add the OID for that entry
Add the following

Code: Select all

nSvcHostgroupnames      OBJECT-TYPE
  SYNTAX          OCTET STRING
  MAX-ACCESS      read-only  
  STATUS          current       
  DESCRIPTION
    "This object contains the Hostgroup the Host associated to this service."
  ::= { nagiosSvcEventEntry 19 }
under this line

Code: Select all

::= { nagiosSvcEventEntry 18 }
Save the file and over write the copy in the /usr/share/snmp/mibs/ folder.
Then, you will have to import that MIB file to your device that is receiving the Traps and you should start to see the Hostgroupnames in the trap.
Now, if the host is not in a hostgroup, this will be sent in the trap, %hostgroupnames%, an empty macro. You may want to add some code to not send it if the hostgroupnames macro is empty.