2 * Note: this file originally auto-generated by mib2c using
3 * : mib2c.iterate.conf 15999 2007-03-25 22:32:02Z dts12 $
9 #include "netsnmpbridge.h"
10 #include "store_mibdata.h"
12 #define REPEAT_TIME (1)
14 std::vector<vsdata>::iterator vs_iterator;
15 std::vector<rsdata>::iterator rs_iterator;
18 static oid snmptrap_oid[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };
21 std::string trap_message;
23 //collect mib callback id
24 static unsigned int reg_id = 0;
27 set_l7vsError_trap_value(const std::string &in_str)
29 trap_message = in_str;
33 send_l7vsError_trap(void)
35 netsnmp_variable_list *var_list = NULL;
36 oid l7vsError_oid[] = { 1, 3, 6, 1, 4, 1, 60000, 1, 0, 1 };
38 * Set the snmpTrapOid.0 value
40 snmp_varlist_add_variable(&var_list,
41 snmptrap_oid, OID_LENGTH(snmptrap_oid),
43 (u_char *)l7vsError_oid, sizeof(l7vsError_oid));
45 * Add any extra (optional) objects here
47 snmp_varlist_add_variable(&var_list,
48 snmptrap_oid, OID_LENGTH(snmptrap_oid),
50 (u_char *)trap_message.c_str(), trap_message.length());
52 * Send the trap to the list of configured destinations
55 send_v2trap(var_list);
56 snmp_free_varbind(var_list);
57 return SNMP_ERR_NOERROR;
61 /** Initializes the UltraMonkeyL7 module */
63 init_UltraMonkeyL7(MessengerClient *message)
65 static oid VSCount_oid[] = { 1, 3, 6, 1, 4, 1, 60000, 1, 1, 1 };
66 static oid RSCount_oid[] = { 1, 3, 6, 1, 4, 1, 60000, 1, 1, 3 };
68 // DEBUGMSGTL(("UltraMonkeyL7", "Initializing\n"));
70 netsnmp_register_scalar(netsnmp_create_handler_registration
71 ("VSCount", handle_VSCount, VSCount_oid,
72 OID_LENGTH(VSCount_oid), HANDLER_CAN_RONLY));
73 netsnmp_register_scalar(netsnmp_create_handler_registration
74 ("RSCount", handle_RSCount, RSCount_oid,
75 OID_LENGTH(RSCount_oid), HANDLER_CAN_RONLY));
78 * here we initialize all the tables we're planning on supporting
80 initialize_table_VSTable();
81 initialize_table_RSTable();
83 reg_id = snmp_alarm_register(REPEAT_TIME, SA_REPEAT, collect_mib, message);
91 handle_VSCount(netsnmp_mib_handler *handler,
92 netsnmp_handler_registration *reginfo,
93 netsnmp_agent_request_info *reqinfo,
94 netsnmp_request_info *requests)
96 snmp_log(LOG_INFO, "handle_vscount\n"); // TODO remove
97 switch (reqinfo->mode) {
99 std::size_t vs_count = l7ag_store_mibdata::getInstance().getVSdatacount();
100 snmp_log(LOG_INFO, "vs_count %d\n", vs_count); // TODO remove
101 snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
102 (u_char *) &vs_count,
103 sizeof(std::size_t));
108 * we should never get here, so this is a really bad error
110 snmp_log(LOG_ERR, "unknown mode (%d) in handle_VSCount\n",
112 return SNMP_ERR_GENERR;
115 return SNMP_ERR_NOERROR;
119 handle_RSCount(netsnmp_mib_handler *handler,
120 netsnmp_handler_registration *reginfo,
121 netsnmp_agent_request_info *reqinfo,
122 netsnmp_request_info *requests)
124 snmp_log(LOG_INFO, "handle_rscount\n");
125 switch (reqinfo->mode) {
127 std::size_t rs_count = l7ag_store_mibdata::getInstance().getRSdatacount();
128 snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
129 (u_char *) &rs_count,
130 sizeof(std::size_t));
131 snmp_log(LOG_INFO, "rs_count %d\n", rs_count);
136 * we should never get here, so this is a really bad error
138 snmp_log(LOG_ERR, "unknown mode (%d) in handle_RSCount\n",
140 return SNMP_ERR_GENERR;
143 return SNMP_ERR_NOERROR;
146 // TODO what is this comment???
147 // Determine the first/last column names
150 * Initialize the VSTable table by defining its contents and how it's structured
153 initialize_table_VSTable(void)
155 static oid VSTable_oid[] = { 1, 3, 6, 1, 4, 1, 60000, 1, 1, 2 };
156 size_t VSTable_oid_len = OID_LENGTH(VSTable_oid);
157 netsnmp_handler_registration *reg;
158 netsnmp_iterator_info *iinfo;
159 netsnmp_table_registration_info *table_info;
161 reg = netsnmp_create_handler_registration("VSTable", VSTable_handler,
162 VSTable_oid, VSTable_oid_len,
165 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
166 netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: IndexVS */
168 table_info->min_column = COLUMN_INDEXVS;
169 table_info->max_column = COLUMN_RSCOUNTVS;
171 iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
172 iinfo->get_first_data_point = VSTable_get_first_data_point;
173 iinfo->get_next_data_point = VSTable_get_next_data_point;
174 iinfo->table_reginfo = table_info;
176 netsnmp_register_table_iterator(reg, iinfo);
179 * Initialise the contents of the table here
184 * Example iterator hook routines - using 'get_next' to do most of the work
186 netsnmp_variable_list*
187 VSTable_get_first_data_point(void **my_loop_context,
188 void **my_data_context,
189 netsnmp_variable_list *put_index_data,
190 netsnmp_iterator_info *mydata)
192 *my_loop_context = l7ag_store_mibdata::getInstance().getVS_first_data_point(); //store_mibdataのデータの先頭を取得
193 vs_iterator = l7ag_store_mibdata::getInstance().getVS_first_data_iterator();
194 return VSTable_get_next_data_point(my_loop_context, my_data_context,
195 put_index_data, mydata);
198 netsnmp_variable_list*
199 VSTable_get_next_data_point(void **my_loop_context,
200 void **my_data_context,
201 netsnmp_variable_list *put_index_data,
202 netsnmp_iterator_info *mydata)
204 struct vsdata *entry = (struct vsdata *) * my_loop_context;
205 netsnmp_variable_list *idx = put_index_data;
208 snmp_set_var_typed_integer(idx, ASN_INTEGER, entry->index);
209 idx = idx->next_variable;
210 *my_data_context = (void *) l7ag_store_mibdata::getInstance().getVS_data_point(vs_iterator); //ここはstore_mibdataからvectorのiteratorからデータのポインタを取得
212 *my_loop_context = (void *) l7ag_store_mibdata::getInstance().getVS_data_point(vs_iterator); //vectorのiteratorから次のデータのポインタを取得
213 return put_index_data;
220 /** handles requests for the VSTable table */
222 VSTable_handler(netsnmp_mib_handler *handler,
223 netsnmp_handler_registration *reginfo,
224 netsnmp_agent_request_info *reqinfo,
225 netsnmp_request_info *requests)
228 netsnmp_request_info *request;
229 netsnmp_table_request_info *table_info;
230 struct vsdata *table_entry;
232 switch (reqinfo->mode) {
234 * Read-support (also covers GetNext requests)
237 for (request = requests; request; request = request->next) {
238 table_entry = (struct vsdata *)
239 netsnmp_extract_iterator_context(request);
240 table_info = netsnmp_extract_table_info(request);
242 switch (table_info->colnum) {
245 netsnmp_set_request_error(reqinfo, request,
246 SNMP_NOSUCHINSTANCE);
249 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
252 case COLUMN_QOSTHREASHOLDUP:
254 netsnmp_set_request_error(reqinfo, request,
255 SNMP_NOSUCHINSTANCE);
258 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
259 table_entry->QoSThreasholdUp);
261 case COLUMN_QOSTHREASHOLDDOWN:
263 netsnmp_set_request_error(reqinfo, request,
264 SNMP_NOSUCHINSTANCE);
267 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
268 table_entry->QoSThreasholdDown);
271 case COLUMN_RSCOUNTVS:
273 netsnmp_set_request_error(reqinfo, request,
274 SNMP_NOSUCHINSTANCE);
277 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
278 table_entry->RSCountatVS);
282 netsnmp_set_request_error(reqinfo, request,
290 return SNMP_ERR_NOERROR;
293 // Determine the first/last column names
295 /** Initialize the RSTable table by defining its contents and how it's structured */
297 initialize_table_RSTable(void)
299 static oid RSTable_oid[] = { 1, 3, 6, 1, 4, 1, 60000, 1, 1, 4 };
300 size_t RSTable_oid_len = OID_LENGTH(RSTable_oid);
301 netsnmp_handler_registration *reg;
302 netsnmp_iterator_info *iinfo;
303 netsnmp_table_registration_info *table_info;
305 reg = netsnmp_create_handler_registration("RSTable", RSTable_handler,
306 RSTable_oid, RSTable_oid_len,
309 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
310 netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: IndexRS */
312 table_info->min_column = COLUMN_INDEXRS;
313 table_info->max_column = COLUMN_INACTIVECONN;
315 iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
316 iinfo->get_first_data_point = RSTable_get_first_data_point;
317 iinfo->get_next_data_point = RSTable_get_next_data_point;
318 iinfo->table_reginfo = table_info;
320 netsnmp_register_table_iterator(reg, iinfo);
323 * Initialise the contents of the table here
328 * Example iterator hook routines - using 'get_next' to do most of the work
330 netsnmp_variable_list *
331 RSTable_get_first_data_point(void **my_loop_context,
332 void **my_data_context,
333 netsnmp_variable_list *put_index_data,
334 netsnmp_iterator_info *mydata)
336 *my_loop_context = l7ag_store_mibdata::getInstance().getRS_first_data_point();
337 rs_iterator = l7ag_store_mibdata::getInstance().getRS_first_data_iterator();
338 return RSTable_get_next_data_point(my_loop_context, my_data_context,
339 put_index_data, mydata);
342 netsnmp_variable_list *
343 RSTable_get_next_data_point(void **my_loop_context,
344 void **my_data_context,
345 netsnmp_variable_list *put_index_data,
346 netsnmp_iterator_info *mydata)
348 struct rsdata *entry = (struct rsdata *) * my_loop_context;
349 netsnmp_variable_list *idx = put_index_data;
352 snmp_set_var_typed_integer(idx, ASN_INTEGER, entry->index);
353 idx = idx->next_variable;
354 *my_data_context = (void *) l7ag_store_mibdata::getInstance().getRS_data_point(rs_iterator);
355 *my_loop_context = (void *) l7ag_store_mibdata::getInstance().getRS_data_point(rs_iterator);
356 return put_index_data;
363 /** handles requests for the RSTable table */
365 RSTable_handler(netsnmp_mib_handler *handler,
366 netsnmp_handler_registration *reginfo,
367 netsnmp_agent_request_info *reqinfo,
368 netsnmp_request_info *requests)
371 netsnmp_request_info *request;
372 netsnmp_table_request_info *table_info;
373 struct rsdata *table_entry;
375 switch (reqinfo->mode) {
377 * Read-support (also covers GetNext requests)
380 for (request = requests; request; request = request->next) {
381 table_entry = (struct rsdata *)
382 netsnmp_extract_iterator_context(request);
383 table_info = netsnmp_extract_table_info(request);
385 switch (table_info->colnum) {
388 netsnmp_set_request_error(reqinfo, request,
389 SNMP_NOSUCHINSTANCE);
392 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
397 netsnmp_set_request_error(reqinfo, request,
398 SNMP_NOSUCHINSTANCE);
401 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
402 table_entry->virtualServiceIndex);
406 netsnmp_set_request_error(reqinfo, request,
407 SNMP_NOSUCHINSTANCE);
410 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
411 table_entry->weight);
413 case COLUMN_ACTIVECONN:
415 netsnmp_set_request_error(reqinfo, request,
416 SNMP_NOSUCHINSTANCE);
419 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
420 table_entry->activeConn);
422 case COLUMN_INACTIVECONN:
424 netsnmp_set_request_error(reqinfo, request,
425 SNMP_NOSUCHINSTANCE);
428 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
429 table_entry->inactiveConn);
432 netsnmp_set_request_error(reqinfo, request,
440 return SNMP_ERR_NOERROR;
444 collect_mib(unsigned int clientreg, void *clientarg)
446 snmp_log(LOG_INFO, "called\n"); // TODO remove
447 MessengerClient *message = (MessengerClient *) clientarg;
448 snmp_log(LOG_INFO, "%d\n", message->socketfd); // TODO remove
449 unsigned long long int buf_size = sizeof(struct l7ag_message_header)
450 + sizeof(struct l7ag_payload_header)
451 + sizeof(struct l7ag_mibrequest_message);
452 char *sendbuf = (char *) calloc(1, buf_size);
453 struct l7ag_message_header *msg_head = (struct l7ag_message_header *) sendbuf;
454 memcpy(msg_head->magic, "MSG", 4); // TODO remove
455 msg_head->version = 1;
456 msg_head->size = buf_size;
457 msg_head->payload_count = 1;
458 // TODO set time msg_head->time = 1;
459 struct l7ag_payload_header *payload = (struct l7ag_payload_header *)(msg_head + 1);
460 memcpy(payload->magic, "PAY", 4); // TODO remove
461 payload->message_id = MESSAGE_ID_MIBCOLLECTREQUEST;
462 payload->payload_datasize = sizeof(struct l7ag_payload_header) + sizeof(struct l7ag_mibrequest_message);
463 struct l7ag_mibrequest_message *request = (struct l7ag_mibrequest_message *)(payload + 1);
464 memset(request, 0, sizeof(struct l7ag_mibrequest_message));
465 memcpy(request->magic, "REQ", 4); // TODO remove
467 int ret = message->send(buf_size, sendbuf);
468 snmp_log(LOG_INFO, "ret %d\n", ret); // TODO remove