Debian Codegraph @

agent/mibgroup/disman/expr/expErrorTable.c

raw
1 /*
2 * DisMan Expression MIB:
3 * Implementation of the expExpressionErrorTable MIB interface
4 * See 'expExpression.c' for active behaviour of this table.
5 *
6 * (Based on mib2c.table_data.conf output)
7 */
8
9 #include <net-snmp/net-snmp-config.h>
10 #include <net-snmp/net-snmp-features.h>
11 #include <net-snmp/net-snmp-includes.h>
12 #include <net-snmp/agent/net-snmp-agent-includes.h>
13 #include "disman/expr/expExpression.h"
14 #include "disman/expr/expErrorTable.h"
15
16 netsnmp_feature_require(table_tdata);
17
18 static Netsnmp_Node_Handler expErrorTable_handler;
19
20 static netsnmp_handler_registration *error_table_reg;
21 static netsnmp_table_registration_info *error_table_info;
22
23 /* Initializes the expExpressionErrorTable module */
24 void
25 init_expErrorTable(void)
26 {
27 static oid expErrorTable_oid[] = { 1, 3, 6, 1, 2, 1, 90, 1, 2, 2 };
28 size_t expErrorTable_oid_len = OID_LENGTH(expErrorTable_oid);
29
30 /*
31 * Ensure the expression table container is available...
32 */
33 init_expr_table_data();
34
35 /*
36 * ... then set up the MIB interface to the expExpressionErrorTable slice
37 */
38 error_table_reg = netsnmp_create_handler_registration("expErrorTable",
39 expErrorTable_handler,
40 expErrorTable_oid,
41 expErrorTable_oid_len,
42 HANDLER_CAN_RWRITE);
43
44 error_table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
45 netsnmp_table_helper_add_indexes(error_table_info,
46 /* index: expExpressionOwner */
47 ASN_OCTET_STR,
48 /* index: expExpressionName */
49 ASN_OCTET_STR,
50 0);
51
52 error_table_info->min_column = COLUMN_EXPERRORTIME;
53 error_table_info->max_column = COLUMN_EXPERRORINSTANCE;
54
55 /* Register this using the (common) expr_table_data container */
56 netsnmp_tdata_register(error_table_reg, expr_table_data, error_table_info);
57 DEBUGMSGTL(("disman:expr:init", "Expression Error Table container (%p)\n",
58 expr_table_data));
59 }
60
61 void
62 shutdown_expErrorTable(void)
63 {
64 }
65
66 /** handles requests for the expExpressionErrorTable table */
67 int
68 expErrorTable_handler(netsnmp_mib_handler *handler,
69 netsnmp_handler_registration *reginfo,
70 netsnmp_agent_request_info *reqinfo,
71 netsnmp_request_info *requests)
72 {
73
74 netsnmp_request_info *request;
75 netsnmp_table_request_info *tinfo;
76 struct expExpression *entry;
77
78 DEBUGMSGTL(("disman:expr:mib", "Expression Error Table handler (%d)\n",
79 reqinfo->mode));
80
81 switch (reqinfo->mode) {
82 /*
83 * Read-support (also covers GetNext requests)
84 */
85 case MODE_GET:
86 for (request = requests; request; request = request->next) {
87 if (request->processed)
88 continue;
89
90 entry = (struct expExpression *)
91 netsnmp_tdata_extract_entry(request);
92 tinfo = netsnmp_extract_table_info(request);
93 if (!entry || !(entry->flags & EXP_FLAG_VALID))
94 continue;
95
96 /*
97 * "Entries only appear in this table ... when there
98 * has been an error for that [matching] expression"
99 */
100 if (entry->expErrorCount == 0)
101 continue;
102
103 switch (tinfo->colnum) {
104 case COLUMN_EXPERRORTIME:
105 snmp_set_var_typed_integer(request->requestvb, ASN_TIMETICKS,
106 entry->expErrorTime);
107 break;
108 case COLUMN_EXPERRORINDEX:
109 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
110 entry->expErrorIndex);
111 break;
112 case COLUMN_EXPERRORCODE:
113 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
114 entry->expErrorCode);
115 break;
116 case COLUMN_EXPERRORINSTANCE:
117 snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID,
118 (u_char *) entry->expErrorInstance,
119 entry->expErrorInst_len*sizeof(oid));
120 break;
121 }
122 }
123 break;
124 }
125 DEBUGMSGTL(("disman:expr:mib", "Expression Error handler - done \n"));
126 return SNMP_ERR_NOERROR;
127 }