Page 1 of 1

Pass in a HostGoup name as part of Service Trap

Posted: Thu Feb 22, 2018 3:22 pm
by nagwindmon
Nagios team,
I've setup a service to check on a few things on windows servers but one of the requirements is to include a HostGroup name in trap that particular server in trouble belongs to. Here is what I have found at MIBs file for Host vs Service traps:

The .5 trap does have it, so I want to make this:
nHostEvent NOTIFICATION-TYPE
OBJECTS { nHostname, nHostStateID, nHostStateType, nHostAttempt,
nHostDurationSec, nHostGroupName, nHostLastCheck, nHostLastChange,
nHostOutput }

::= { nagiosNotify 5 }

(Notice that trap 7 below doesn’t have the nHostGroupName in it)

nSvcEvent NOTIFICATION-TYPE
OBJECTS { nHostname, nHostStateID, nSvcDesc, nSvcStateID, nSvcAttempt,
nSvcDurationSec, nSvcLastCheck, nSvcLastChange,
nSvcOutput }

::= { nagiosNotify 7 }


Look like this:

nSvcEvent NOTIFICATION-TYPE
OBJECTS { nHostname, nHostStateID, nSvcDesc, nSvcStateID, nSvcAttempt,
nSvcDurationSec, nHostGroupName, nSvcGroupName, nSvcLastCheck, nSvcLastChange,
nSvcOutput }

::= { nagiosNotify 7 }


So that the .7 trap populates the nHostGroupName data.

My questions are: is this something I can do and if so, how do I update the trap definition in Nagios once I upload the modified NAGIOS-NOTIFY-MIB.txt file? Any other options/suggestions how to accomplish it?

thanks!

Re: Pass in a HostGoup name as part of Service Trap

Posted: Thu Feb 22, 2018 5:10 pm
by scottwilkerson
you would need to modify the trap sender which I am guessing may be what you are trying to do here
https://support.nagios.com/forum/viewto ... 16&t=47641

That said, I would highly recommend changing the naming structure, and re-building the actual snmptrapsender because your changes could be over written if you update the component

Re: Pass in a HostGoup name as part of Service Trap

Posted: Thu Feb 22, 2018 5:16 pm
by tgriep
I have a question, are you trying to setup the Nagios SNMP Trap Sender to send hostgroup names?

Re: Pass in a HostGoup name as part of Service Trap

Posted: Thu Feb 22, 2018 5:56 pm
by nagwindmon
tgriep wrote:I have a question, are you trying to setup the Nagios SNMP Trap Sender to send hostgroup names?
No, to include a HostGroup name the host belongs to as one of parameters, in .7 Service trap for the host the trap was generated on.

Re: Pass in a HostGoup name as part of Service Trap

Posted: Fri Feb 23, 2018 9:37 am
by tgriep
I do have an example on the entries that have to be added to the MIB file.

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 }

Re: Pass in a HostGoup name as part of Service Trap

Posted: Fri Feb 23, 2018 9:57 am
by tgriep
I have added the full MIB file here so you can see what was done to the file to get the added entries.

Re: Pass in a HostGoup name as part of Service Trap

Posted: Fri Feb 23, 2018 3:23 pm
by nagwindmon
Let me update my MIB file and give it a try...

In meantime is there a way I can see what is inside the Trap once it gets genereated? The actual data Trap contains so to be sure HostGroup name is in it??

Re: Pass in a HostGoup name as part of Service Trap

Posted: Fri Feb 23, 2018 3:41 pm
by tgriep
If you are sending the trap from or to a Linux system, you can run a tcpdump command and decode the traps to the screen so you can view them. Try running this as root.

Code: Select all

tcpdump -i any -n udp port 162 -A -vv