X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsnmp_agent.c;h=5af0d121526c6a7ed1b42a581858be95b14cfef8;hb=54d75f7f84d48ffc710bd79a2bcce1fc908452d2;hp=74c2d0b027a10f5db5faa8f15828712f1dc2d73e;hpb=8cb75222e06009109fff0750d5b28ca4597438e9;p=collectd.git diff --git a/src/snmp_agent.c b/src/snmp_agent.c index 74c2d0b0..5af0d121 100644 --- a/src/snmp_agent.c +++ b/src/snmp_agent.c @@ -1,17 +1,17 @@ /** * collectd - src/snmp_agent.c * - * Copyright(c) 2016 Intel Corporation. All rights reserved. + * Copyright(c) 2017 Intel Corporation. All rights reserved. * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, @@ -34,17 +34,15 @@ #include "utils_llist.h" #include + #include + #include #define PLUGIN_NAME "snmp_agent" #define ERR_BUF_SIZE 1024 #define TYPE_STRING -1 -#ifndef MIN -#define MIN(x, y) ((x) < (y) ? (x) : (y)) -#endif - struct oid_s { oid oid[MAX_OID_LEN]; size_t oid_len; @@ -69,7 +67,7 @@ struct data_definition_s { char *type; char *type_instance; const table_definition_t *table; - _Bool is_instance; + bool is_instance; oid_t *oids; size_t oids_len; double scale; @@ -88,7 +86,7 @@ struct snmp_agent_ctx_s { }; typedef struct snmp_agent_ctx_s snmp_agent_ctx_t; -snmp_agent_ctx_t *g_agent = NULL; +static snmp_agent_ctx_t *g_agent; #define CHECK_DD_TYPE(_dd, _p, _pi, _t, _ti) \ (_dd->plugin ? !strcmp(_dd->plugin, _p) : 0) && \ @@ -96,6 +94,7 @@ snmp_agent_ctx_t *g_agent = NULL; (_dd->type ? !strcmp(_dd->type, _t) : 0) && \ (_dd->type_instance ? !strcmp(_dd->type_instance, _ti) : 1) +static int snmp_agent_shutdown(void); static void *snmp_agent_thread_run(void *arg); static int snmp_agent_register_oid(oid_t *oid, Netsnmp_Node_Handler *handler); static int snmp_agent_set_vardata(void *dst_buf, size_t *dst_buf_len, @@ -106,13 +105,13 @@ static int snmp_agent_unregister_oid_index(oid_t *oid, int index); static u_char snmp_agent_get_asn_type(oid *oid, size_t oid_len) { struct tree *node = get_tree(oid, oid_len, g_agent->tp); - return (node != NULL ? mib_to_asn_type(node->type) : 0); + return (node != NULL) ? mib_to_asn_type(node->type) : 0; } static char *snmp_agent_get_oid_name(oid *oid, size_t oid_len) { struct tree *node = get_tree(oid, oid_len, g_agent->tp); - return (node != NULL ? node->label : NULL); + return (node != NULL) ? node->label : NULL; } static int snmp_agent_oid_to_string(char *buf, size_t buf_size, @@ -121,17 +120,51 @@ static int snmp_agent_oid_to_string(char *buf, size_t buf_size, char *oid_str_ptr[MAX_OID_LEN]; for (size_t i = 0; i < o->oid_len; i++) { - ssnprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]); + snprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]); oid_str_ptr[i] = oid_str[i]; } - return (strjoin(buf, buf_size, oid_str_ptr, o->oid_len, ".")); + return strjoin(buf, buf_size, oid_str_ptr, o->oid_len, "."); } -static void snmp_agent_dump_data(void) { +/* Prints a configuration storing list. It handles both table columns list + and scalars list */ #if COLLECT_DEBUG +static void snmp_agent_dump_data(llist_t *list) { + char oid_str[DATA_MAX_NAME_LEN]; + for (llentry_t *de = llist_head(list); de != NULL; de = de->next) { + data_definition_t *dd = de->value; + + if (dd->table != NULL) + DEBUG(PLUGIN_NAME ": Column:"); + else + DEBUG(PLUGIN_NAME ": Scalar:"); + + DEBUG(PLUGIN_NAME ": Name: %s", dd->name); + if (dd->plugin) + DEBUG(PLUGIN_NAME ": Plugin: %s", dd->plugin); + if (dd->plugin_instance) + DEBUG(PLUGIN_NAME ": PluginInstance: %s", dd->plugin_instance); + if (dd->is_instance) + DEBUG(PLUGIN_NAME ": Instance: true"); + if (dd->type) + DEBUG(PLUGIN_NAME ": Type: %s", dd->type); + if (dd->type_instance) + DEBUG(PLUGIN_NAME ": TypeInstance: %s", dd->type_instance); + for (size_t i = 0; i < dd->oids_len; i++) { + snmp_agent_oid_to_string(oid_str, sizeof(oid_str), &dd->oids[i]); + DEBUG(PLUGIN_NAME ": OID[%" PRIsz "]: %s", i, oid_str); + } + DEBUG(PLUGIN_NAME ": Scale: %g", dd->scale); + DEBUG(PLUGIN_NAME ": Shift: %g", dd->shift); + } +} + +/* Prints parsed configuration */ +static void snmp_agent_dump_config(void) { char oid_str[DATA_MAX_NAME_LEN]; + /* Printing tables */ for (llentry_t *te = llist_head(g_agent->tables); te != NULL; te = te->next) { table_definition_t *td = te->value; @@ -146,58 +179,19 @@ static void snmp_agent_dump_data(void) { DEBUG(PLUGIN_NAME ": SizeOID: %s", oid_str); } - for (llentry_t *de = llist_head(td->columns); de != NULL; de = de->next) { - data_definition_t *dd = de->value; - - DEBUG(PLUGIN_NAME ": Column:"); - DEBUG(PLUGIN_NAME ": Name: %s", dd->name); - if (dd->plugin) - DEBUG(PLUGIN_NAME ": Plugin: %s", dd->plugin); - if (dd->plugin_instance) - DEBUG(PLUGIN_NAME ": PluginInstance: %s", dd->plugin_instance); - if (dd->is_instance) - DEBUG(PLUGIN_NAME ": Instance: true"); - if (dd->type) - DEBUG(PLUGIN_NAME ": Type: %s", dd->type); - if (dd->type_instance) - DEBUG(PLUGIN_NAME ": TypeInstance: %s", dd->type_instance); - for (int i = 0; i < dd->oids_len; i++) { - snmp_agent_oid_to_string(oid_str, sizeof(oid_str), &dd->oids[i]); - DEBUG(PLUGIN_NAME ": OID[%d]: %s", i, oid_str); - } - DEBUG(PLUGIN_NAME ": Scale: %g", dd->scale); - DEBUG(PLUGIN_NAME ": Shift: %g", dd->shift); - } + snmp_agent_dump_data(td->columns); } - for (llentry_t *e = llist_head(g_agent->scalars); e != NULL; e = e->next) { - data_definition_t *dd = e->value; - - DEBUG(PLUGIN_NAME ": Scalar:"); - DEBUG(PLUGIN_NAME ": Name: %s", dd->name); - if (dd->plugin) - DEBUG(PLUGIN_NAME ": Plugin: %s", dd->plugin); - if (dd->plugin_instance) - DEBUG(PLUGIN_NAME ": PluginInstance: %s", dd->plugin_instance); - if (dd->is_instance) - DEBUG(PLUGIN_NAME ": Instance: true"); - if (dd->type) - DEBUG(PLUGIN_NAME ": Type: %s", dd->type); - if (dd->type_instance) - DEBUG(PLUGIN_NAME ": TypeInstance: %s", dd->type_instance); - for (int i = 0; i < dd->oids_len; i++) { - snmp_agent_oid_to_string(oid_str, sizeof(oid_str), &dd->oids[i]); - DEBUG(PLUGIN_NAME ": OID[%d]: %s", i, oid_str); - } - DEBUG(PLUGIN_NAME ": Scale: %g", dd->scale); - DEBUG(PLUGIN_NAME ": Shift: %g", dd->shift); - } -#endif /* COLLECT_DEBUG */ + /* Printing scalars */ + snmp_agent_dump_data(g_agent->scalars); } +#endif /* COLLECT_DEBUG */ -static int snmp_agent_validate_data(void) { +static int snmp_agent_validate_config(void) { - snmp_agent_dump_data(); +#if COLLECT_DEBUG + snmp_agent_dump_config(); +#endif for (llentry_t *te = llist_head(g_agent->tables); te != NULL; te = te->next) { table_definition_t *td = te->value; @@ -208,20 +202,20 @@ static int snmp_agent_validate_data(void) { if (!dd->plugin) { ERROR(PLUGIN_NAME ": Plugin not defined for '%s'.'%s'", td->name, dd->name); - return (-EINVAL); + return -EINVAL; } if (dd->plugin_instance) { ERROR(PLUGIN_NAME ": PluginInstance should not be defined for table " "data type '%s'.'%s'", td->name, dd->name); - return (-EINVAL); + return -EINVAL; } if (dd->oids_len == 0) { ERROR(PLUGIN_NAME ": No OIDs defined for '%s'.'%s'", td->name, dd->name); - return (-EINVAL); + return -EINVAL; } if (dd->is_instance) { @@ -230,7 +224,7 @@ static int snmp_agent_validate_data(void) { ERROR(PLUGIN_NAME ": Type and TypeInstance are not valid for " "instance data '%s'.'%s'", td->name, dd->name); - return (-EINVAL); + return -EINVAL; } if (dd->oids_len > 1) { @@ -238,14 +232,14 @@ static int snmp_agent_validate_data(void) { PLUGIN_NAME ": Only one OID should be specified for instance data '%s'.'%s'", td->name, dd->name); - return (-EINVAL); + return -EINVAL; } } else { if (!dd->type) { ERROR(PLUGIN_NAME ": Type not defined for data '%s'.'%s'", td->name, dd->name); - return (-EINVAL); + return -EINVAL; } } } @@ -256,79 +250,139 @@ static int snmp_agent_validate_data(void) { if (!dd->plugin) { ERROR(PLUGIN_NAME ": Plugin not defined for '%s'", dd->name); - return (-EINVAL); + return -EINVAL; } if (dd->oids_len == 0) { ERROR(PLUGIN_NAME ": No OIDs defined for '%s'", dd->name); - return (-EINVAL); + return -EINVAL; } if (dd->is_instance) { ERROR(PLUGIN_NAME ": Instance flag can't be specified for scalar data '%s'", dd->name); - return (-EINVAL); + return -EINVAL; } if (!dd->type) { ERROR(PLUGIN_NAME ": Type not defined for data '%s'", dd->name); - return (-EINVAL); + return -EINVAL; + } + } + + return 0; +} + +static void snmp_agent_generate_oid2string(oid_t *oid, size_t offset, + char *key) { + size_t key_len = oid->oid[offset]; + size_t i; + + for (i = 0; i < key_len && offset < oid->oid_len; i++) + key[i] = oid->oid[++offset]; + + key[i] = '\0'; +} + +static int snmp_agent_generate_string2oid(oid_t *oid, const char *key) { + size_t key_len = strlen(key); + + oid->oid[oid->oid_len++] = key_len; + for (size_t i = 0; i < key_len; i++) { + oid->oid[oid->oid_len++] = key[i]; + if (oid->oid_len >= MAX_OID_LEN) { + ERROR(PLUGIN_NAME ": Conversion key string %s to OID failed", key); + return -EINVAL; } } - return (0); + return 0; +} + +static int snmp_agent_register_oid_string(oid_t *oid, const char *key, + Netsnmp_Node_Handler *handler) { + oid_t new_oid; + + memcpy(&new_oid, oid, sizeof(*oid)); + int ret = snmp_agent_generate_string2oid(&new_oid, key); + if (ret != 0) + return ret; + + return snmp_agent_register_oid(&new_oid, handler); +} + +static int snmp_agent_unregister_oid_string(oid_t *oid, const char *key) { + oid_t new_oid; + + memcpy(&new_oid, oid, sizeof(*oid)); + int ret = snmp_agent_generate_string2oid(&new_oid, key); + if (ret != 0) + return ret; + + return unregister_mib(new_oid.oid, new_oid.oid_len); } static int snmp_agent_table_row_remove(table_definition_t *td, const char *instance) { - int *index; - char *ins; + int *index = NULL; + char *ins = NULL; - if ((c_avl_get(td->instance_index, instance, (void **)&index) != 0) || - (c_avl_get(td->index_instance, index, (void **)&ins) != 0)) - return (0); + if (td->index_oid.oid_len) { + if ((c_avl_get(td->instance_index, instance, (void **)&index) != 0) || + (c_avl_get(td->index_instance, index, (void **)&ins) != 0)) + return 0; + } else { + if (c_avl_get(td->instance_index, instance, (void **)&ins) != 0) + return 0; + } pthread_mutex_lock(&g_agent->agentx_lock); + if (td->index_oid.oid_len) + snmp_agent_unregister_oid_index(&td->index_oid, *index); + for (llentry_t *de = llist_head(td->columns); de != NULL; de = de->next) { data_definition_t *dd = de->value; - for (int i = 0; i < dd->oids_len; i++) - snmp_agent_unregister_oid_index(&dd->oids[i], *index); + for (size_t i = 0; i < dd->oids_len; i++) + if (td->index_oid.oid_len) + snmp_agent_unregister_oid_index(&dd->oids[i], *index); + else + snmp_agent_unregister_oid_string(&dd->oids[i], ins); } - snmp_agent_unregister_oid_index(&td->index_oid, *index); - pthread_mutex_unlock(&g_agent->agentx_lock); - DEBUG(PLUGIN_NAME ": Removed row for '%s' table [%d, %s]", td->name, *index, - ins); + DEBUG(PLUGIN_NAME ": Removed row for '%s' table [%d, %s]", td->name, + (index != NULL) ? *index : -1, ins); notification_t n = { - .severity = NOTIF_WARNING, - .time = cdtime(), - .plugin = PLUGIN_NAME - }; + .severity = NOTIF_WARNING, .time = cdtime(), .plugin = PLUGIN_NAME}; sstrncpy(n.host, hostname_g, sizeof(n.host)); sstrncpy(n.plugin_instance, ins, sizeof(n.plugin_instance)); - ssnprintf(n.message, sizeof(n.message), - "Removed data row from table %s instance %s index %d", td->name, - ins, *index); + snprintf(n.message, sizeof(n.message), + "Removed data row from table %s instance %s index %d", td->name, ins, + (index != NULL) ? *index : -1); plugin_dispatch_notification(&n); - c_avl_remove(td->index_instance, index, NULL, (void **)&ins); - c_avl_remove(td->instance_index, instance, NULL, (void **)&index); - sfree(index); - sfree(ins); + if (td->index_oid.oid_len) { + c_avl_remove(td->index_instance, index, NULL, (void **)&ins); + c_avl_remove(td->instance_index, instance, NULL, (void **)&index); + sfree(index); + sfree(ins); + } else { + c_avl_remove(td->instance_index, instance, NULL, (void **)&ins); + sfree(ins); + } - return (0); + return 0; } static int snmp_agent_clear_missing(const value_list_t *vl, __attribute__((unused)) user_data_t *ud) { if (vl == NULL) - return (-EINVAL); + return -EINVAL; for (llentry_t *te = llist_head(g_agent->tables); te != NULL; te = te->next) { table_definition_t *td = te->value; @@ -340,13 +394,13 @@ static int snmp_agent_clear_missing(const value_list_t *vl, if (CHECK_DD_TYPE(dd, vl->plugin, vl->plugin_instance, vl->type, vl->type_instance)) { snmp_agent_table_row_remove(td, vl->plugin_instance); - return (0); + return 0; } } } } - return (0); + return 0; } static void snmp_agent_free_data(data_definition_t **dd) { @@ -356,19 +410,8 @@ static void snmp_agent_free_data(data_definition_t **dd) { /* unregister scalar type OID */ if ((*dd)->table == NULL) { - for (int i = 0; i < (*dd)->oids_len; i++) + for (size_t i = 0; i < (*dd)->oids_len; i++) unregister_mib((*dd)->oids[i].oid, (*dd)->oids[i].oid_len); - } else { - /* unregister all table OIDs */ - int *index; - char *value; - - c_avl_iterator_t *iter = c_avl_get_iterator((*dd)->table->index_instance); - while (c_avl_iterator_next(iter, (void *)&index, (void *)&value) == 0) { - for (int i = 0; i < (*dd)->oids_len; i++) - snmp_agent_unregister_oid_index(&(*dd)->oids[i], *index); - } - c_avl_iterator_destroy(iter); } sfree((*dd)->name); @@ -383,6 +426,43 @@ static void snmp_agent_free_data(data_definition_t **dd) { return; } +static void snmp_agent_free_table_columns(table_definition_t *td) { + if (td->columns == NULL) + return; + + for (llentry_t *de = llist_head(td->columns); de != NULL; de = de->next) { + data_definition_t *dd = de->value; + + if (td->index_oid.oid_len) { + int *index; + char *instance; + + c_avl_iterator_t *iter = c_avl_get_iterator(td->index_instance); + while (c_avl_iterator_next(iter, (void *)&index, (void *)&instance) == + 0) { + for (size_t i = 0; i < dd->oids_len; i++) + snmp_agent_unregister_oid_index(&dd->oids[i], *index); + } + c_avl_iterator_destroy(iter); + } else { + char *instance; + + c_avl_iterator_t *iter = c_avl_get_iterator(dd->table->instance_index); + while (c_avl_iterator_next(iter, (void *)&instance, (void *)&instance) == + 0) { + for (size_t i = 0; i < dd->oids_len; i++) + snmp_agent_unregister_oid_string(&dd->oids[i], instance); + } + c_avl_iterator_destroy(iter); + } + + snmp_agent_free_data(&dd); + } + + llist_destroy(td->columns); + td->columns = NULL; +} /* void snmp_agent_free_table_columns */ + static void snmp_agent_free_table(table_definition_t **td) { if (td == NULL || *td == NULL) @@ -391,23 +471,20 @@ static void snmp_agent_free_table(table_definition_t **td) { if ((*td)->size_oid.oid_len) unregister_mib((*td)->size_oid.oid, (*td)->size_oid.oid_len); + /* Unregister Index OIDs */ if ((*td)->index_oid.oid_len) { int *index; - char *value; + char *instance; c_avl_iterator_t *iter = c_avl_get_iterator((*td)->index_instance); - while (c_avl_iterator_next(iter, (void *)&index, (void *)&value) == 0) + while (c_avl_iterator_next(iter, (void *)&index, (void *)&instance) == 0) snmp_agent_unregister_oid_index(&(*td)->index_oid, *index); c_avl_iterator_destroy(iter); } - for (llentry_t *de = llist_head((*td)->columns); de != NULL; de = de->next) { - data_definition_t *dd = de->value; - snmp_agent_free_data(&dd); - } - - llist_destroy((*td)->columns); + /* Unregister all table columns and their registered OIDs */ + snmp_agent_free_table_columns(*td); void *key = NULL; void *value = NULL; @@ -416,12 +493,15 @@ static void snmp_agent_free_table(table_definition_t **td) { c_avl_destroy((*td)->index_instance); (*td)->index_instance = NULL; - while (c_avl_pick((*td)->instance_index, &key, &value) == 0) { - sfree(key); - sfree(value); + if ((*td)->instance_index != NULL) { + while (c_avl_pick((*td)->instance_index, &key, &value) == 0) { + if (key != value) + sfree(key); + sfree(value); + } + c_avl_destroy((*td)->instance_index); + (*td)->instance_index = NULL; } - c_avl_destroy((*td)->instance_index); - (*td)->instance_index = NULL; sfree((*td)->name); sfree(*td); @@ -454,7 +534,7 @@ static int snmp_agent_form_reply(struct netsnmp_request_info_s *requests, } assert(ds->ds_num == values_num); - assert(oid_index < values_num); + assert(oid_index < (int)values_num); char data[DATA_MAX_NAME_LEN]; size_t data_len = sizeof(data); @@ -470,8 +550,8 @@ static int snmp_agent_form_reply(struct netsnmp_request_info_s *requests, } requests->requestvb->type = dd->oids[oid_index].type; - snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type, data, - data_len); + snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type, + (const u_char *)data, data_len); return SNMP_ERR_NOERROR; } @@ -503,36 +583,47 @@ snmp_agent_table_oid_handler(struct netsnmp_mib_handler_s *handler, for (llentry_t *te = llist_head(g_agent->tables); te != NULL; te = te->next) { table_definition_t *td = te->value; - if (!td->index_oid.oid_len) { - DEBUG(PLUGIN_NAME ": %s:%d NOT IMPLEMENTED", __FUNCTION__, __LINE__); - continue; - } - for (llentry_t *de = llist_head(td->columns); de != NULL; de = de->next) { data_definition_t *dd = de->value; - for (int i = 0; i < dd->oids_len; i++) { + for (size_t i = 0; i < dd->oids_len; i++) { int ret = snmp_oid_ncompare(oid.oid, oid.oid_len, dd->oids[i].oid, dd->oids[i].oid_len, - MIN(oid.oid_len, dd->oids[i].oid_len)); + SNMP_MIN(oid.oid_len, dd->oids[i].oid_len)); if (ret != 0) continue; - int index = oid.oid[oid.oid_len - 1]; char *instance; - ret = c_avl_get(td->index_instance, &index, (void **)&instance); - if (ret != 0) { - DEBUG(PLUGIN_NAME ": Nonexisting index '%d' requested", index); - pthread_mutex_unlock(&g_agent->lock); - return SNMP_NOSUCHINSTANCE; + if (!td->index_oid.oid_len) { + char key[MAX_OID_LEN]; + + memset(key, 0, sizeof(key)); + snmp_agent_generate_oid2string( + &oid, SNMP_MIN(oid.oid_len, dd->oids[i].oid_len), key); + + ret = c_avl_get(td->instance_index, key, (void **)&instance); + if (ret != 0) { + DEBUG(PLUGIN_NAME ": Nonexisting index string '%s' requested", key); + pthread_mutex_unlock(&g_agent->lock); + return SNMP_NOSUCHINSTANCE; + } + } else { + int index = oid.oid[oid.oid_len - 1]; + + ret = c_avl_get(td->index_instance, &index, (void **)&instance); + if (ret != 0) { + DEBUG(PLUGIN_NAME ": Nonexisting index '%d' requested", index); + pthread_mutex_unlock(&g_agent->lock); + return SNMP_NOSUCHINSTANCE; + } } if (dd->is_instance) { requests->requestvb->type = ASN_OCTET_STR; - snmp_set_var_typed_value(requests->requestvb, - requests->requestvb->type, instance, - strlen((instance))); + snmp_set_var_typed_value( + requests->requestvb, requests->requestvb->type, + (const u_char *)instance, strlen((instance))); pthread_mutex_unlock(&g_agent->lock); @@ -575,9 +666,9 @@ static int snmp_agent_table_index_oid_handler( table_definition_t *td = te->value; if (td->index_oid.oid_len && - (snmp_oid_ncompare(oid.oid, oid.oid_len, td->index_oid.oid, - td->index_oid.oid_len, - MIN(oid.oid_len, td->index_oid.oid_len)) == 0)) { + (snmp_oid_ncompare( + oid.oid, oid.oid_len, td->index_oid.oid, td->index_oid.oid_len, + SNMP_MIN(oid.oid_len, td->index_oid.oid_len)) == 0)) { DEBUG(PLUGIN_NAME ": Handle '%s' table index OID", td->name); @@ -592,7 +683,7 @@ static int snmp_agent_table_index_oid_handler( requests->requestvb->type = ASN_INTEGER; snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type, - &index, sizeof(index)); + (const u_char *)&index, sizeof(index)); pthread_mutex_unlock(&g_agent->lock); @@ -631,14 +722,14 @@ static int snmp_agent_table_size_oid_handler( if (td->size_oid.oid_len && (snmp_oid_ncompare(oid.oid, oid.oid_len, td->size_oid.oid, td->size_oid.oid_len, - MIN(oid.oid_len, td->size_oid.oid_len)) == 0)) { + SNMP_MIN(oid.oid_len, td->size_oid.oid_len)) == 0)) { DEBUG(PLUGIN_NAME ": Handle '%s' table size OID", td->name); long size = c_avl_size(td->index_instance); - requests->requestvb->type = td->size_oid.type; + requests->requestvb->type = ASN_INTEGER; snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type, - &size, sizeof(size)); + (const u_char *)&size, sizeof(size)); pthread_mutex_unlock(&g_agent->lock); @@ -679,7 +770,7 @@ snmp_agent_scalar_oid_handler(struct netsnmp_mib_handler_s *handler, de = de->next) { data_definition_t *dd = de->value; - for (int i = 0; i < dd->oids_len; i++) { + for (size_t i = 0; i < dd->oids_len; i++) { int ret = snmp_oid_compare(oid.oid, oid.oid_len, dd->oids[i].oid, dd->oids[i].oid_len); @@ -717,14 +808,14 @@ static int snmp_agent_register_table_oids(void) { for (llentry_t *de = llist_head(td->columns); de != NULL; de = de->next) { data_definition_t *dd = de->value; - for (int i = 0; i < dd->oids_len; i++) { + for (size_t i = 0; i < dd->oids_len; i++) { dd->oids[i].type = snmp_agent_get_asn_type(dd->oids[i].oid, dd->oids[i].oid_len); } } } - return (0); + return 0; } static int snmp_agent_register_scalar_oids(void) { @@ -732,7 +823,7 @@ static int snmp_agent_register_scalar_oids(void) { for (llentry_t *e = llist_head(g_agent->scalars); e != NULL; e = e->next) { data_definition_t *dd = e->value; - for (int i = 0; i < dd->oids_len; i++) { + for (size_t i = 0; i < dd->oids_len; i++) { dd->oids[i].type = snmp_agent_get_asn_type(dd->oids[i].oid, dd->oids[i].oid_len); @@ -744,20 +835,20 @@ static int snmp_agent_register_scalar_oids(void) { } } - return (0); + return 0; } static int snmp_agent_config_data_oids(data_definition_t *dd, oconfig_item_t *ci) { if (ci->values_num < 1) { WARNING(PLUGIN_NAME ": `OIDs' needs at least one argument"); - return (-EINVAL); + return -EINVAL; } for (int i = 0; i < ci->values_num; i++) if (ci->values[i].type != OCONFIG_TYPE_STRING) { WARNING(PLUGIN_NAME ": `OIDs' needs only string argument"); - return (-EINVAL); + return -EINVAL; } if (dd->oids != NULL) @@ -765,7 +856,7 @@ static int snmp_agent_config_data_oids(data_definition_t *dd, dd->oids_len = 0; dd->oids = calloc(ci->values_num, sizeof(*dd->oids)); if (dd->oids == NULL) - return (-ENOMEM); + return -ENOMEM; dd->oids_len = (size_t)ci->values_num; for (int i = 0; i < ci->values_num; i++) { @@ -777,23 +868,23 @@ static int snmp_agent_config_data_oids(data_definition_t *dd, ci->values[i].value.string); sfree(dd->oids); dd->oids_len = 0; - return (-1); + return -1; } } - return (0); + return 0; } static int snmp_agent_config_table_size_oid(table_definition_t *td, oconfig_item_t *ci) { if (ci->values_num < 1) { WARNING(PLUGIN_NAME ": `TableSizeOID' is empty"); - return (-EINVAL); + return -EINVAL; } if (ci->values[0].type != OCONFIG_TYPE_STRING) { WARNING(PLUGIN_NAME ": `TableSizeOID' needs only string argument"); - return (-EINVAL); + return -EINVAL; } td->size_oid.oid_len = MAX_OID_LEN; @@ -803,10 +894,10 @@ static int snmp_agent_config_table_size_oid(table_definition_t *td, ERROR(PLUGIN_NAME ": Failed to parse table size OID (%s)", ci->values[0].value.string); td->size_oid.oid_len = 0; - return (-EINVAL); + return -EINVAL; } - return (0); + return 0; } static int snmp_agent_config_table_index_oid(table_definition_t *td, @@ -814,12 +905,12 @@ static int snmp_agent_config_table_index_oid(table_definition_t *td, if (ci->values_num < 1) { WARNING(PLUGIN_NAME ": `IndexOID' is empty"); - return (-EINVAL); + return -EINVAL; } if (ci->values[0].type != OCONFIG_TYPE_STRING) { WARNING(PLUGIN_NAME ": `IndexOID' needs only string argument"); - return (-EINVAL); + return -EINVAL; } td->index_oid.oid_len = MAX_OID_LEN; @@ -829,14 +920,16 @@ static int snmp_agent_config_table_index_oid(table_definition_t *td, ERROR(PLUGIN_NAME ": Failed to parse table index OID (%s)", ci->values[0].value.string); td->index_oid.oid_len = 0; - return (-EINVAL); + return -EINVAL; } - return (0); + return 0; } -static int snmp_agent_config_table_data(table_definition_t *td, - oconfig_item_t *ci) { +/* This function parses configuration of both scalar and table column + * because they have nearly the same structure */ +static int snmp_agent_config_table_column(table_definition_t *td, + oconfig_item_t *ci) { data_definition_t *dd; int ret = 0; @@ -845,24 +938,25 @@ static int snmp_agent_config_table_data(table_definition_t *td, dd = calloc(1, sizeof(*dd)); if (dd == NULL) { ERROR(PLUGIN_NAME ": Failed to allocate memory for table data definition"); - return (-ENOMEM); + return -ENOMEM; } ret = cf_util_get_string(ci, &dd->name); if (ret != 0) { sfree(dd); - return (-1); + return -1; } dd->scale = 1.0; dd->shift = 0.0; - + /* NULL if it's a scalar */ dd->table = td; for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; - if (strcasecmp("Instance", option->key) == 0) + /* Instance option is reserved for table entry only */ + if (strcasecmp("Instance", option->key) == 0 && td != NULL) ret = cf_util_get_boolean(option, &dd->is_instance); else if (strcasecmp("Plugin", option->key) == 0) ret = cf_util_get_string(option, &dd->plugin); @@ -885,91 +979,36 @@ static int snmp_agent_config_table_data(table_definition_t *td, if (ret != 0) { snmp_agent_free_data(&dd); - return (-1); + return -1; } } llentry_t *entry = llentry_create(dd->name, dd); if (entry == NULL) { snmp_agent_free_data(&dd); - return (-ENOMEM); + return -ENOMEM; } - llist_append(td->columns, entry); + /* Append to column list in parent table */ + if (td != NULL) + llist_append(td->columns, entry); - return (0); + return 0; } -static int snmp_agent_config_data(oconfig_item_t *ci) { - data_definition_t *dd; - int ret = 0; - - assert(ci != NULL); - - dd = calloc(1, sizeof(*dd)); - if (dd == NULL) { - ERROR(PLUGIN_NAME ": Failed to allocate memory for data definition"); - return (-ENOMEM); - } - - ret = cf_util_get_string(ci, &dd->name); - if (ret != 0) { - free(dd); - return (-1); - } - - dd->scale = 1.0; - dd->shift = 0.0; - - for (int i = 0; i < ci->children_num; i++) { - oconfig_item_t *option = ci->children + i; - - if (strcasecmp("Instance", option->key) == 0) - ret = cf_util_get_boolean(option, &dd->is_instance); - else if (strcasecmp("Plugin", option->key) == 0) - ret = cf_util_get_string(option, &dd->plugin); - else if (strcasecmp("PluginInstance", option->key) == 0) - ret = cf_util_get_string(option, &dd->plugin_instance); - else if (strcasecmp("Type", option->key) == 0) - ret = cf_util_get_string(option, &dd->type); - else if (strcasecmp("TypeInstance", option->key) == 0) - ret = cf_util_get_string(option, &dd->type_instance); - else if (strcasecmp("Shift", option->key) == 0) - ret = cf_util_get_double(option, &dd->shift); - else if (strcasecmp("Scale", option->key) == 0) - ret = cf_util_get_double(option, &dd->scale); - else if (strcasecmp("OIDs", option->key) == 0) - ret = snmp_agent_config_data_oids(dd, option); - else { - WARNING(PLUGIN_NAME ": Option `%s' not allowed here", option->key); - ret = -1; - } - - if (ret != 0) { - snmp_agent_free_data(&dd); - return (-1); - } - } - - llentry_t *entry = llentry_create(dd->name, dd); - if (entry == NULL) { - snmp_agent_free_data(&dd); - return (-ENOMEM); - } - - llist_append(g_agent->scalars, entry); - - return (0); +/* Parses scalar configuration entry */ +static int snmp_agent_config_scalar(oconfig_item_t *ci) { + return snmp_agent_config_table_column(NULL, ci); } static int num_compare(const int *a, const int *b) { assert((a != NULL) && (b != NULL)); if (*a < *b) - return (-1); + return -1; else if (*a > *b) - return (1); + return 1; else - return (0); + return 0; } static int snmp_agent_config_table(oconfig_item_t *ci) { @@ -981,20 +1020,20 @@ static int snmp_agent_config_table(oconfig_item_t *ci) { td = calloc(1, sizeof(*td)); if (td == NULL) { ERROR(PLUGIN_NAME ": Failed to allocate memory for table definition"); - return (-ENOMEM); + return -ENOMEM; } ret = cf_util_get_string(ci, &td->name); if (ret != 0) { sfree(td); - return (-1); + return -1; } td->columns = llist_create(); if (td->columns == NULL) { ERROR(PLUGIN_NAME ": Failed to allocate memory for columns list"); snmp_agent_free_table(&td); - return (-ENOMEM); + return -ENOMEM; } for (int i = 0; i < ci->children_num; i++) { @@ -1005,7 +1044,7 @@ static int snmp_agent_config_table(oconfig_item_t *ci) { else if (strcasecmp("SizeOID", option->key) == 0) ret = snmp_agent_config_table_size_oid(td, option); else if (strcasecmp("Data", option->key) == 0) - ret = snmp_agent_config_table_data(td, option); + ret = snmp_agent_config_table_column(td, option); else { WARNING(PLUGIN_NAME ": Option `%s' not allowed here", option->key); ret = -1; @@ -1013,39 +1052,32 @@ static int snmp_agent_config_table(oconfig_item_t *ci) { if (ret != 0) { snmp_agent_free_table(&td); - return (-ENOMEM); + return -ENOMEM; } } - if (td->index_oid.oid_len == 0) { - ERROR(PLUGIN_NAME ": Table %s Index OID is not specified", td->name); - snmp_agent_free_table(&td); - return (-1); - } - - llentry_t *entry = llentry_create(td->name, td); - if (entry == NULL) { - snmp_agent_free_table(&td); - return (-ENOMEM); - } - td->instance_index = c_avl_create((int (*)(const void *, const void *))strcmp); if (td->instance_index == NULL) { snmp_agent_free_table(&td); - return (-ENOMEM); + return -ENOMEM; } td->index_instance = c_avl_create((int (*)(const void *, const void *))num_compare); if (td->index_instance == NULL) { snmp_agent_free_table(&td); - return (-ENOMEM); + return -ENOMEM; } + llentry_t *entry = llentry_create(td->name, td); + if (entry == NULL) { + snmp_agent_free_table(&td); + return -ENOMEM; + } llist_append(g_agent->tables, entry); - return (0); + return 0; } static int snmp_agent_get_value_from_ds_type(const value_t *val, int type, @@ -1068,10 +1100,10 @@ static int snmp_agent_get_value_from_ds_type(const value_t *val, int type, break; default: ERROR(PLUGIN_NAME ": Unknown data source type: %i", type); - return (-EINVAL); + return -EINVAL; } - return (0); + return 0; } static int snmp_agent_set_vardata(void *data, size_t *data_len, u_char asn_type, @@ -1097,13 +1129,13 @@ static int snmp_agent_set_vardata(void *data, size_t *data_len, u_char asn_type, case ASN_TIMETICKS: case ASN_GAUGE: if (*data_len < sizeof(*var.integer)) - return (-EINVAL); + return -EINVAL; *var.integer = new_value; *data_len = sizeof(*var.integer); break; case ASN_COUNTER64: if (*data_len < sizeof(*var.counter64)) - return (-EINVAL); + return -EINVAL; var.counter64->high = (u_long)((int64_t)new_value >> 32); var.counter64->low = (u_long)((int64_t)new_value & 0xFFFFFFFF); *data_len = sizeof(*var.counter64); @@ -1113,22 +1145,22 @@ static int snmp_agent_set_vardata(void *data, size_t *data_len, u_char asn_type, char buf[DATA_MAX_NAME_LEN]; snprintf(buf, sizeof(buf), "%.2f", val->gauge); if (*data_len < strlen(buf)) - return (-EINVAL); + return -EINVAL; *data_len = strlen(buf); memcpy(var.string, buf, *data_len); } else { ERROR(PLUGIN_NAME ": Failed to convert %d ds type to %d asn type", type, asn_type); - return (-EINVAL); + return -EINVAL; } break; default: ERROR(PLUGIN_NAME ": Failed to convert %d ds type to %d asn type", type, asn_type); - return (-EINVAL); + return -EINVAL; } - return (0); + return 0; } static int snmp_agent_register_oid_index(oid_t *oid, int index, @@ -1150,81 +1182,93 @@ static int snmp_agent_update_index(table_definition_t *td, const char *instance) { if (c_avl_get(td->instance_index, instance, NULL) == 0) - return (0); + return 0; int ret; - int *index; + int *index = NULL; char *ins; ins = strdup(instance); if (ins == NULL) - return (-ENOMEM); + return -ENOMEM; - index = calloc(1, sizeof(*index)); - if (index == NULL) { - sfree(ins); - return (-ENOMEM); - } - - *index = c_avl_size(td->instance_index) + 1; - - ret = c_avl_insert(td->instance_index, ins, index); - if (ret != 0) { - sfree(ins); - sfree(index); - return ret; - } + /* need to generate index for the table */ + if (td->index_oid.oid_len) { + index = calloc(1, sizeof(*index)); + if (index == NULL) { + sfree(ins); + return -ENOMEM; + } - ret = c_avl_insert(td->index_instance, index, ins); - if (ret < 0) { - DEBUG(PLUGIN_NAME ": Failed to update index_instance for '%s' table", - td->name); - return ret; - } + *index = c_avl_size(td->instance_index) + 1; - DEBUG(PLUGIN_NAME ": Updated index for '%s' table [%d, %s]", td->name, *index, - ins); + ret = c_avl_insert(td->instance_index, ins, index); + if (ret != 0) { + sfree(ins); + sfree(index); + return ret; + } - /* need to generate index for the table */ - if (td->index_oid.oid_len) { + ret = c_avl_insert(td->index_instance, index, ins); + if (ret < 0) { + DEBUG(PLUGIN_NAME ": Failed to update index_instance for '%s' table", + td->name); + c_avl_remove(td->instance_index, ins, NULL, (void **)&index); + sfree(ins); + sfree(index); + return ret; + } ret = snmp_agent_register_oid_index(&td->index_oid, *index, snmp_agent_table_index_oid_handler); if (ret != 0) return ret; + } else { + /* instance as a key is required for any table */ + ret = c_avl_insert(td->instance_index, ins, ins); + if (ret != 0) { + sfree(ins); + return ret; + } + } - /* register new oids for all columns */ - for (llentry_t *de = llist_head(td->columns); de != NULL; de = de->next) { - data_definition_t *dd = de->value; + /* register new oids for all columns */ + for (llentry_t *de = llist_head(td->columns); de != NULL; de = de->next) { + data_definition_t *dd = de->value; - for (int i = 0; i < dd->oids_len; i++) { + for (size_t i = 0; i < dd->oids_len; i++) { + if (td->index_oid.oid_len) { ret = snmp_agent_register_oid_index(&dd->oids[i], *index, snmp_agent_table_oid_handler); - if (ret != 0) - return ret; + } else { + ret = snmp_agent_register_oid_string(&dd->oids[i], ins, + snmp_agent_table_oid_handler); } + + if (ret != 0) + return ret; } } + DEBUG(PLUGIN_NAME ": Updated index for '%s' table [%d, %s]", td->name, + (index != NULL) ? *index : -1, ins); + notification_t n = { - .severity = NOTIF_OKAY, - .time = cdtime(), - .plugin = PLUGIN_NAME - }; + .severity = NOTIF_OKAY, .time = cdtime(), .plugin = PLUGIN_NAME}; sstrncpy(n.host, hostname_g, sizeof(n.host)); sstrncpy(n.plugin_instance, ins, sizeof(n.plugin_instance)); - ssnprintf(n.message, sizeof(n.message), - "Data row added to table %s instance %s index %d", td->name, ins, - *index); + snprintf(n.message, sizeof(n.message), + "Data row added to table %s instance %s index %d", td->name, ins, + (index != NULL) ? *index : -1); plugin_dispatch_notification(&n); - return (0); + return 0; } static int snmp_agent_write(value_list_t const *vl) { if (vl == NULL) - return (-EINVAL); + return -EINVAL; for (llentry_t *te = llist_head(g_agent->tables); te != NULL; te = te->next) { table_definition_t *td = te->value; @@ -1236,13 +1280,13 @@ static int snmp_agent_write(value_list_t const *vl) { if (CHECK_DD_TYPE(dd, vl->plugin, vl->plugin_instance, vl->type, vl->type_instance)) { snmp_agent_update_index(td, vl->plugin_instance); - return (0); + return 0; } } } } - return (0); + return 0; } static int snmp_agent_collect(const data_set_t *ds, const value_list_t *vl, @@ -1254,31 +1298,36 @@ static int snmp_agent_collect(const data_set_t *ds, const value_list_t *vl, pthread_mutex_unlock(&g_agent->lock); - return (0); + return 0; } static int snmp_agent_preinit(void) { - if (g_agent != NULL) { - /* already initialized if config callback was called before init callback */ - return (0); - } g_agent = calloc(1, sizeof(*g_agent)); if (g_agent == NULL) { ERROR(PLUGIN_NAME ": Failed to allocate memory for snmp agent context"); - return (-ENOMEM); + return -ENOMEM; } g_agent->tables = llist_create(); g_agent->scalars = llist_create(); + if (g_agent->tables == NULL || g_agent->scalars == NULL) { + ERROR(PLUGIN_NAME ": llist_create() failed"); + llist_destroy(g_agent->scalars); + llist_destroy(g_agent->tables); + return -ENOMEM; + } + int err; - /* make us a agentx client. */ + /* make us an agentx client. */ err = netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1); if (err != 0) { ERROR(PLUGIN_NAME ": Failed to set agent role (%d)", err); - return (-1); + llist_destroy(g_agent->scalars); + llist_destroy(g_agent->tables); + return -1; } /* @@ -1289,22 +1338,28 @@ static int snmp_agent_preinit(void) { err = init_agent(PLUGIN_NAME); if (err != 0) { ERROR(PLUGIN_NAME ": Failed to initialize the agent library (%d)", err); - return (-1); + llist_destroy(g_agent->scalars); + llist_destroy(g_agent->tables); + return -1; } init_snmp(PLUGIN_NAME); g_agent->tp = read_all_mibs(); - return (0); + return 0; } static int snmp_agent_init(void) { int ret; - ret = snmp_agent_preinit(); - if (ret != 0) - return ret; + if (g_agent == NULL || ((llist_head(g_agent->scalars) == NULL) && + (llist_head(g_agent->tables) == NULL))) { + ERROR(PLUGIN_NAME ": snmp_agent_init: plugin not configured"); + return -EINVAL; + } + + plugin_register_shutdown(PLUGIN_NAME, snmp_agent_shutdown); ret = snmp_agent_register_scalar_oids(); if (ret != 0) @@ -1314,13 +1369,6 @@ static int snmp_agent_init(void) { if (ret != 0) return ret; - /* create a second thread to listen for requests from AgentX*/ - ret = pthread_create(&g_agent->thread, NULL, &snmp_agent_thread_run, NULL); - if (ret != 0) { - ERROR(PLUGIN_NAME ": Failed to create a separate thread, err %u", ret); - return ret; - } - ret = pthread_mutex_init(&g_agent->lock, NULL); if (ret != 0) { ERROR(PLUGIN_NAME ": Failed to initialize mutex, err %u", ret); @@ -1333,7 +1381,19 @@ static int snmp_agent_init(void) { return ret; } - return (0); + /* create a second thread to listen for requests from AgentX*/ + ret = pthread_create(&g_agent->thread, NULL, &snmp_agent_thread_run, NULL); + if (ret != 0) { + ERROR(PLUGIN_NAME ": Failed to create a separate thread, err %u", ret); + return ret; + } + + if (llist_head(g_agent->tables) != NULL) { + plugin_register_write(PLUGIN_NAME, snmp_agent_collect, NULL); + plugin_register_missing(PLUGIN_NAME, snmp_agent_clear_missing, NULL); + } + + return 0; } static void *snmp_agent_thread_run(void __attribute__((unused)) * arg) { @@ -1364,7 +1424,7 @@ static int snmp_agent_register_oid(oid_t *oid, Netsnmp_Node_Handler *handler) { WARNING(PLUGIN_NAME ": Skipped registration: OID (%s) is not found in main tree", oid_str); - return (0); + return 0; } reg = netsnmp_create_handler_registration(oid_name, handler, oid->oid, @@ -1372,7 +1432,7 @@ static int snmp_agent_register_oid(oid_t *oid, Netsnmp_Node_Handler *handler) { if (reg == NULL) { ERROR(PLUGIN_NAME ": Failed to create handler registration for OID (%s)", oid_str); - return (-1); + return -1; } pthread_mutex_lock(&g_agent->agentx_lock); @@ -1380,20 +1440,20 @@ static int snmp_agent_register_oid(oid_t *oid, Netsnmp_Node_Handler *handler) { if (netsnmp_register_instance(reg) != MIB_REGISTERED_OK) { ERROR(PLUGIN_NAME ": Failed to register handler for OID (%s)", oid_str); pthread_mutex_unlock(&g_agent->agentx_lock); - return (-1); + return -1; } pthread_mutex_unlock(&g_agent->agentx_lock); DEBUG(PLUGIN_NAME ": Registered handler for OID (%s)", oid_str); - return (0); + return 0; } static int snmp_agent_free_config(void) { if (g_agent == NULL) - return (-EINVAL); + return -EINVAL; for (llentry_t *te = llist_head(g_agent->tables); te != NULL; te = te->next) snmp_agent_free_table((table_definition_t **)&te->value); @@ -1403,7 +1463,7 @@ static int snmp_agent_free_config(void) { snmp_agent_free_data((data_definition_t **)&de->value); llist_destroy(g_agent->scalars); - return (0); + return 0; } static int snmp_agent_shutdown(void) { @@ -1413,7 +1473,7 @@ static int snmp_agent_shutdown(void) { if (g_agent == NULL) { ERROR(PLUGIN_NAME ": snmp_agent_shutdown: plugin not initialized"); - return (-EINVAL); + return -EINVAL; } if (pthread_cancel(g_agent->thread) != 0) @@ -1440,13 +1500,13 @@ static int snmp_agent_config(oconfig_item_t *ci) { if (ret != 0) { sfree(g_agent); - return (-EINVAL); + return -EINVAL; } for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("Data", child->key) == 0) { - ret = snmp_agent_config_data(child); + ret = snmp_agent_config_scalar(child); } else if (strcasecmp("Table", child->key) == 0) { ret = snmp_agent_config_table(child); } else { @@ -1459,26 +1519,23 @@ static int snmp_agent_config(oconfig_item_t *ci) { snmp_agent_free_config(); snmp_shutdown(PLUGIN_NAME); sfree(g_agent); - return (-EINVAL); + return -EINVAL; } } - ret = snmp_agent_validate_data(); + ret = snmp_agent_validate_config(); if (ret != 0) { ERROR(PLUGIN_NAME ": Invalid configuration provided"); snmp_agent_free_config(); snmp_shutdown(PLUGIN_NAME); sfree(g_agent); - return (-EINVAL); + return -EINVAL; } - return (0); + return 0; } void module_register(void) { plugin_register_init(PLUGIN_NAME, snmp_agent_init); plugin_register_complex_config(PLUGIN_NAME, snmp_agent_config); - plugin_register_write(PLUGIN_NAME, snmp_agent_collect, NULL); - plugin_register_missing(PLUGIN_NAME, snmp_agent_clear_missing, NULL); - plugin_register_shutdown(PLUGIN_NAME, snmp_agent_shutdown); }