The following are some instructions that shows how to add sending of the Hostgroup information in the SNMPTrapSender component.
You can use this as a template to add the fields you want.
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
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
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
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.