Difference between revisions of "FAQ:Coding 14"
(Latest FAQ revision - preparing for 5.5 release) |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | = I | + | = How can I get the agent to generate a trap (or inform)? = |
− | {{FAQ: | + | <!-- NB: |
+ | There is a mismatch between the template numbering | ||
+ | for this entry, and the FAQ entries that refer to it. | ||
+ | This follows a review of the entries in the | ||
+ | Coding section. | ||
+ | --> | ||
+ | {{FAQ:Coding_18}} | ||
[[FAQ:Coding]] | [[FAQ:Coding]] | ||
{{FAQ:Coding}} | {{FAQ:Coding}} |
Latest revision as of 20:58, 20 July 2009
How can I get the agent to generate a trap (or inform)?
There are two aspects to having the agent generate a trap - knowing how to do this, and knowing when to do so.
Actually generating a trap is reasonably simple - just call one
of the trap API routines (send_easy_trap()
or send_v2trap()
)
with the relevant information (generic and specific trap values,
or a varbind list respectively).
The 'mib2c.notify.conf'
configuration file can be used to
construct a suitable template routine for generating a trap,
including building the variable list from the MIB trap
definition. These variables can then be given suitable values,
before invoking the send_v2trap()
call to actually send the trap.
See the 'snmp_trap_api(3)'
man page for details.
Note that these APIs are only available within the agent (or
subagents), and are not available to stand-alone applications.
The code for 'snmptrap'
shows an approach to use in such a case.
Determining when to generate the trap (either directly or via the mib2c-generated routine) is often harder. If the trap is generated in response to some action within the agent, (e.g. as the result of a SET), then this isn't too much of a problem.
But if the trap is intended to report on a change of status (e.g. a network interface going up or down, or a disk filling up), then actually detecting this is non-trivial. It's necessary to poll the value(s) on a regular basis, save the results and compare them with the new values the next time round.
The simplest way to handle this is via the DisMan Event MIB,
which is designed for exactly this purpose. As long as you can
specify MIB object(s) to monitor, and the values or thresholds
that should trigger a notification, then this module can check
these values regularly, and automatically send a suitable trap
when appropriate. See the 'snmpd.conf(5)'
man
page (under ACTIVE MONITORING) for details.
Otherwise, you'd need to use the routines documented in
'snmp_alarm(3)'
to regularly invoke a monitoring
routine. This
could check the necessary conditions (which need not be MIB
objects), and call the 'snmp_xxx_trap()'
routine
(as generated by 'mib2c.notify.conf'
) when appropriate.
FAQ:Coding
- How do I write C code to integrate with the agent?
- How does the agent fetch the value of a MIB variable from the system?
- Mib2c complains about a missing "mib reference" - what does this mean?
- Mib2c complains about not having a "valid OID" - what does this mean?
- Why doesn't mib2c like the MIB file I'm giving it?
- Mib2c ignores my MIB and generates a pair of 'mib-2' code files. Why?
- What's the difference between the various mib2c configuration files?
- Which mib2c configuration file should I use?
- How can I have mib2c generate code for both scalars and tables?
- Are there any examples, or documentation for generating MIB modules?
- Where should I put the files produced by 'mib2c'?
- Why doesn't my new MIB module report anything?
- Why does the iterator call my get_{first,next} routines so often?
- How can I get the agent to generate a trap (or inform)?
- How can I get an AgentX sub-agent to generate a trap (or inform)?
- How can I get the agent to send an SNMPv1 (or SNMPv2c) trap?
- How can I get the agent to include varbinds with an SNMPv1 trap?
- How can I get the agent to send an SNMPv1 enterprise-specific trap?
- How can I get the agent to send an SNMPv3 trap (or inform)?
- Why does calling 'send_v2trap' generate an SNMPv1 trap (or vice versa)?
- How can I register a MIB module in a different (SNMPv3) context?