forked from jrossi/snmp-swraid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathswRaidMIB.c
291 lines (251 loc) · 8.4 KB
/
swRaidMIB.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.iterate_access.conf,v 1.12 2006/09/08 15:43:39 dts12 Exp $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "swRaidMIB.h"
#include "swRaidMIB_access.h"
/*
* Initialize the swRaidTable table by defining its contents and how it's structured
*/
void initialize_table_swRaidTable(void)
{
static oid swRaidTable_oid[] = { SWRAIDTABLE_OID };
netsnmp_table_registration_info *table_info;
netsnmp_handler_registration *my_handler;
netsnmp_iterator_info *iinfo;
/*
* create the table registration information structures
*/
table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
my_handler = netsnmp_create_handler_registration("swRaidTable",
swRaidTable_handler,
swRaidTable_oid,
OID_LENGTH
(swRaidTable_oid),
HANDLER_CAN_RONLY);
if (!my_handler || !table_info || !iinfo) {
snmp_log(LOG_ERR, "malloc failed in initialize_table_swRaidTable");
return;
}
/*
* setup the table's definition
*/
netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, 0);
/*
* Define the minimum and maximum accessible columns. This
* optimizes retrival.
*/
table_info->min_column = SWRAIDTABLE_MIN_COL;
table_info->max_column = SWRAIDTABLE_MAX_COL;
/*
* iterator access routines
*/
iinfo->get_first_data_point = swRaidTable_get_first_data_point;
iinfo->get_next_data_point = swRaidTable_get_next_data_point;
/*
* tie the two structures together
*/
iinfo->table_reginfo = table_info;
/*
* registering the table with the master agent
*/
netsnmp_register_table_iterator(my_handler, iinfo);
}
/*
* Initializes the swRaidMIB module
*/
void init_swRaidMIB(void)
{
static oid swRaidMIB_oid[] = { SWRAIDMIB_OID };
static oid swRaidErrorFlag_oid[] = { SWRAIDERRORFLAG_OID };
static oid swRaidErrMessage_oid[] = { SWRAIDERRMESSAGE_OID };
DEBUGMSGTL(("swRaidMIB", "Initializing swRaidMIB\n"));
/*
* Perform swRaidMIB one-time module initialization.
*/
netsnmp_register_scalar(netsnmp_create_handler_registration
("swRaidErrorFlag", swRaidErrorFlag_handler,
swRaidErrorFlag_oid,
OID_LENGTH(swRaidErrorFlag_oid),
HANDLER_CAN_RONLY));
netsnmp_register_scalar(netsnmp_create_handler_registration
("swRaidErrMessage", swRaidErrMessage_handler,
swRaidErrMessage_oid,
OID_LENGTH(swRaidErrMessage_oid),
HANDLER_CAN_RONLY));
/*
* here we initialize all the tables we're planning on supporting
*/
initialize_table_swRaidTable();
/*
* initialize the cache handler for the entire swRaidMIB branch
*/
netsnmp_register_cache_handler(netsnmp_create_handler_registration
("swRaidMIBCache", NULL,
swRaidMIB_oid, OID_LENGTH(swRaidMIB_oid), 0),
SWRAID_CACHE_TIMEOUT,
swRaidMIB_load, swRaidMIB_free);
}
/*
* Handles requests for the swRaidTable table, if anything else needs to be done
*/
int swRaidTable_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
netsnmp_request_info *request;
netsnmp_table_request_info *table_info;
netsnmp_variable_list *var;
void *data_context = NULL;
/*
* column and row index encoded portion
*/
for (request = requests; request; request = request->next) {
var = request->requestvb;
if (request->processed != 0)
continue;
if (reqinfo->mode != MODE_GET) {
snmp_log(LOG_ERR, "problem encountered in swRaidTable_handler: unsupported mode\n");
continue;
}
/*
* get next data context
*/
data_context = netsnmp_extract_iterator_context(request);
if (data_context == NULL) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
/*
* extracts the information about the table from the request
* table_info->colnum contains the column number requested
* table_info->indexes contains a linked list of snmp variable
* bindings for the indexes of the table. Values in the list
* have been set corresponding to the indexes of the
* request
*/
table_info = netsnmp_extract_table_info(request);
if (table_info == NULL)
continue;
switch (table_info->colnum) {
case COLUMN_SWRAIDINDEX:
{
long *retval;
size_t retval_len = 0;
retval = get_swRaidIndex(data_context, &retval_len);
if (retval != NULL)
snmp_set_var_typed_value(var, ASN_INTEGER,
(const u_char *) retval,
retval_len);
}
break;
case COLUMN_SWRAIDDEVICE:
{
char *retval;
size_t retval_len = 0;
retval = get_swRaidDevice(data_context, &retval_len);
if (retval != NULL)
snmp_set_var_typed_value(var, ASN_OCTET_STR,
(const u_char *) retval,
retval_len);
}
break;
case COLUMN_SWRAIDPERSONALITY:
{
char *retval;
size_t retval_len = 0;
retval = get_swRaidPersonality(data_context, &retval_len);
if (retval != NULL)
snmp_set_var_typed_value(var, ASN_OCTET_STR,
(const u_char *) retval,
retval_len);
}
break;
case COLUMN_SWRAIDUNITS:
{
char *retval;
size_t retval_len = 0;
retval = get_swRaidUnits(data_context, &retval_len);
if (retval != NULL)
snmp_set_var_typed_value(var, ASN_OCTET_STR,
(const u_char *) retval,
retval_len);
}
break;
case COLUMN_SWRAIDUNITCOUNT:
{
long *retval;
size_t retval_len = 0;
retval = get_swRaidUnitCount(data_context, &retval_len);
if (retval != NULL)
snmp_set_var_typed_value(var, ASN_INTEGER,
(const u_char *) retval,
retval_len);
}
break;
case COLUMN_SWRAIDSTATUS:
{
long *retval;
size_t retval_len = 0;
retval = get_swRaidStatus(data_context, &retval_len);
if (retval != NULL)
snmp_set_var_typed_value(var, ASN_INTEGER,
(const u_char *) retval,
retval_len);
}
break;
default:
/* We shouldn't get here */
snmp_log(LOG_ERR, "problem encountered in swRaidTable_handler: unknown column\n");
}
}
return SNMP_ERR_NOERROR;
}
/*
* handles requests for swRaidErrorFlag
*/
int swRaidErrorFlag_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
long *retval;
size_t retval_len = 0;
if (reqinfo->mode != MODE_GET) {
snmp_log(LOG_ERR, "unknown mode (%d) in handle_swRaidErrorFlag\n", reqinfo->mode);
return SNMP_ERR_GENERR;
}
retval = get_swRaidErrorFlag(&retval_len);
if (retval != NULL)
snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
(const u_char *) retval,
retval_len);
return SNMP_ERR_NOERROR;
}
/*
* handles requests for swRaidErrMessage
*/
int swRaidErrMessage_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
char *retval;
size_t retval_len = 0;
if (reqinfo->mode != MODE_GET) {
snmp_log(LOG_ERR, "unknown mode (%d) in handle_swRaidErrMessage\n", reqinfo->mode);
return SNMP_ERR_GENERR;
}
retval = get_swRaidErrMessage(&retval_len);
if (retval != NULL)
snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
(const u_char *) retval,
retval_len);
return SNMP_ERR_NOERROR;
}