add hostgroups to service SNMP traps
-
peter.zanetti
- Posts: 90
- Joined: Wed Oct 01, 2014 8:34 am
Re: add hostgroups to service SNMP traps
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
That didn't work as well. I am thinking that the SNMP Trap Sender Component needs to be changed to add that to it.
Be sure to check out our Knowledgebase for helpful articles and solutions!
-
peter.zanetti
- Posts: 90
- Joined: Wed Oct 01, 2014 8:34 am
Re: add hostgroups to service SNMP traps
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
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
Change this line from
to
Then change this line from
to
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
And after the changes, copy the file to this folder
Edit the NAGIOS-NOTIFY-MIB.txt and change the following from
to
That added the "nHostHostgroupnames OCTET STRING" line.
Next you need to add the OID for that entry
Add the following
Under this line
Next change this from
to
That added the "nSvcHostgroupnames OCTET STRING" line.
Next you need to add the OID for that entry
Add the following
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.
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.phpCode: 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%\"";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%\"";
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%\"";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%\"";
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/mibsCode: Select all
/usr/share/snmp/mibs/
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
}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
}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 }Code: Select all
::= { nagiosHostEventEntry 15 }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
}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
}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 }Code: Select all
::= { nagiosSvcEventEntry 18 }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.
Be sure to check out our Knowledgebase for helpful articles and solutions!