1 #include <net-snmp/net-snmp-config.h>
9 #include <net-snmp/net-snmp-includes.h>
10 #include <net-snmp/agent/net-snmp-agent-includes.h>
12 #include <net-snmp/agent/debug_handler.h>
18 /** @defgroup debug debug: print out debugging information about the handler chain being called.
19 * This is a useful module for run-time
20 * debugging of requests as the pass this handler in a calling chain.
21 * All debugging output is done via the standard debugging routines
22 * with a token name of "helper:debug", so use the -Dhelper:debug
23 * command line flag to see the output when running the snmpd
24 * demon. It's not recommended you compile this into a handler chain
25 * during compile time, but instead use the "injectHandler" token in
26 * the snmpd.conf file (or similar) to add it to the chain later:
28 * injectHandler debug my_module_name
30 * to see an example output, try:
32 * injectHandler debug mibII/system
34 * and then run snmpwalk on the "system" group.
40 /** returns a debug handler that can be injected into a given
44 netsnmp_get_debug_handler(void)
46 return netsnmp_create_handler("debug", netsnmp_debug_helper);
49 /** @internal debug print variables in a chain */
51 debug_print_requests(netsnmp_request_info *requests)
53 netsnmp_request_info *request;
55 for (request = requests; request; request = request->next) {
56 DEBUGMSGTL(("helper:debug", " #%2d: ", request->index));
57 DEBUGMSGVAR(("helper:debug", request->requestvb));
58 DEBUGMSG(("helper:debug", "\n"));
60 if (request->processed)
61 DEBUGMSGTL(("helper:debug", " [processed]\n"));
62 if (request->delegated)
63 DEBUGMSGTL(("helper:debug", " [delegated]\n"));
65 DEBUGMSGTL(("helper:debug", " [status = %d]\n",
67 if (request->parent_data) {
68 netsnmp_data_list *lst;
69 DEBUGMSGTL(("helper:debug", " [parent data ="));
70 for (lst = request->parent_data; lst; lst = lst->next) {
71 DEBUGMSG(("helper:debug", " %s", lst->name));
73 DEBUGMSG(("helper:debug", "]\n"));
79 /** @internal Implements the debug handler */
81 netsnmp_debug_helper(netsnmp_mib_handler *handler,
82 netsnmp_handler_registration *reginfo,
83 netsnmp_agent_request_info *reqinfo,
84 netsnmp_request_info *requests)
87 netsnmp_mib_handler *hptr;
90 DEBUGMSGTL(("helper:debug", "Entering Debugging Helper:\n"));
91 DEBUGMSGTL(("helper:debug", " Handler Registration Info:\n"));
92 DEBUGMSGTL(("helper:debug", " Name: %s\n",
93 reginfo->handlerName));
94 DEBUGMSGTL(("helper:debug", " Context: %s\n",
95 reginfo->contextName));
96 DEBUGMSGTL(("helper:debug", " Base OID: "));
97 DEBUGMSGOID(("helper:debug", reginfo->rootoid, reginfo->rootoid_len));
98 DEBUGMSG(("helper:debug", "\n"));
100 DEBUGMSGTL(("helper:debug", " Modes: 0x%x = ",
102 for (count = 0, i = reginfo->modes; i; i = i >> 1, count++) {
104 DEBUGMSG(("helper:debug", "%s | ",
105 se_find_label_in_slist("handler_can_mode",
109 DEBUGMSG(("helper:debug", "\n"));
111 DEBUGMSGTL(("helper:debug", " Priority: %d\n",
114 DEBUGMSGTL(("helper:debug", " Handler Calling Chain:\n"));
115 DEBUGMSGTL(("helper:debug", " "));
116 for (hptr = reginfo->handler; hptr; hptr = hptr->next) {
117 DEBUGMSG(("helper:debug", " -> %s", hptr->handler_name));
119 DEBUGMSG(("helper:debug", " [myvoid = %x]", hptr->myvoid));
121 DEBUGMSG(("helper:debug", "\n"));
123 DEBUGMSGTL(("helper:debug", " Request information:\n"));
124 DEBUGMSGTL(("helper:debug", " Mode: %s (%d = 0x%x)\n",
125 se_find_label_in_slist("agent_mode", reqinfo->mode),
126 reqinfo->mode, reqinfo->mode));
127 DEBUGMSGTL(("helper:debug", " Request Variables:\n"));
128 debug_print_requests(requests);
130 DEBUGMSGTL(("helper:debug", " --- calling next handler --- \n"));
131 ret = netsnmp_call_next_handler(handler, reginfo, reqinfo, requests);
133 DEBUGMSGTL(("helper:debug", " Results:\n"));
134 DEBUGMSGTL(("helper:debug", " Returned code: %d\n", ret));
135 DEBUGMSGTL(("helper:debug", " Returned Variables:\n"));
136 debug_print_requests(requests);
138 DEBUGMSGTL(("helper:debug", "Exiting Debugging Helper:\n"));
142 /** initializes the debug helper which then registers a debug
143 * handler as a run-time injectable handler for configuration file
147 netsnmp_init_debug_helper(void)
149 netsnmp_register_handler_by_name("debug", netsnmp_get_debug_handler());