2 * collectd - src/snmp.c
3 * Copyright (C) 2007-2012 Florian octo Forster
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Florian octo Forster <octo at collectd.org>
31 #include "utils_complain.h"
33 #include <net-snmp/net-snmp-config.h>
34 #include <net-snmp/net-snmp-includes.h>
39 * Private data structes
45 typedef struct oid_s oid_t;
48 char string[DATA_MAX_NAME_LEN];
51 typedef union instance_u instance_t;
53 struct data_definition_s {
54 char *name; /* used to reference this from the `Collect' option */
55 char *type; /* used to find the data_set */
58 char *instance_prefix;
63 struct data_definition_s *next;
68 typedef struct data_definition_s data_definition_t;
70 struct host_definition_s {
77 /* snmpv1/2 options */
80 /* snmpv3 security options */
83 size_t auth_protocol_len;
84 char *auth_passphrase;
86 size_t priv_protocol_len;
87 char *priv_passphrase;
92 c_complain_t complaint;
94 data_definition_t **data_list;
97 typedef struct host_definition_s host_definition_t;
99 /* These two types are used to cache values in `csnmp_read_table' to handle
101 struct csnmp_list_instances_s {
103 char instance[DATA_MAX_NAME_LEN];
104 struct csnmp_list_instances_s *next;
106 typedef struct csnmp_list_instances_s csnmp_list_instances_t;
108 struct csnmp_table_values_s {
111 struct csnmp_table_values_s *next;
113 typedef struct csnmp_table_values_s csnmp_table_values_t;
118 static data_definition_t *data_head = NULL;
123 static int csnmp_read_host(user_data_t *ud);
128 static void csnmp_oid_init(oid_t *dst, oid const *src, size_t n) {
129 assert(n <= STATIC_ARRAY_SIZE(dst->oid));
130 memcpy(dst->oid, src, sizeof(*src) * n);
134 static int csnmp_oid_compare(oid_t const *left, oid_t const *right) {
135 return snmp_oid_compare(left->oid, left->oid_len, right->oid, right->oid_len);
138 static int csnmp_oid_suffix(oid_t *dst, oid_t const *src, oid_t const *root) {
139 /* Make sure "src" is in "root"s subtree. */
140 if (src->oid_len <= root->oid_len)
142 if (snmp_oid_ncompare(root->oid, root->oid_len, src->oid, src->oid_len,
143 /* n = */ root->oid_len) != 0)
146 memset(dst, 0, sizeof(*dst));
147 dst->oid_len = src->oid_len - root->oid_len;
148 memcpy(dst->oid, &src->oid[root->oid_len],
149 dst->oid_len * sizeof(dst->oid[0]));
153 static int csnmp_oid_to_string(char *buffer, size_t buffer_size,
155 char oid_str[MAX_OID_LEN][16];
156 char *oid_str_ptr[MAX_OID_LEN];
158 for (size_t i = 0; i < o->oid_len; i++) {
159 snprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]);
160 oid_str_ptr[i] = oid_str[i];
163 return strjoin(buffer, buffer_size, oid_str_ptr, o->oid_len, ".");
166 static void csnmp_host_close_session(host_definition_t *host) /* {{{ */
168 if (host->sess_handle == NULL)
171 snmp_sess_close(host->sess_handle);
172 host->sess_handle = NULL;
173 } /* }}} void csnmp_host_close_session */
175 static void csnmp_host_definition_destroy(void *arg) /* {{{ */
177 host_definition_t *hd;
184 if (hd->name != NULL) {
185 DEBUG("snmp plugin: Destroying host definition for host `%s'.", hd->name);
188 csnmp_host_close_session(hd);
192 sfree(hd->community);
194 sfree(hd->auth_passphrase);
195 sfree(hd->priv_passphrase);
197 sfree(hd->data_list);
200 } /* }}} void csnmp_host_definition_destroy */
202 /* Many functions to handle the configuration. {{{ */
203 /* First there are many functions which do configuration stuff. It's a big
204 * bloated and messy, I'm afraid. */
207 * Callgraph for the config stuff:
209 * +-> call_snmp_init_once
210 * +-> csnmp_config_add_data
211 * ! +-> csnmp_config_add_data_instance
212 * ! +-> csnmp_config_add_data_instance_prefix
213 * ! +-> csnmp_config_add_data_values
214 * +-> csnmp_config_add_host
215 * +-> csnmp_config_add_host_version
216 * +-> csnmp_config_add_host_collect
217 * +-> csnmp_config_add_host_auth_protocol
218 * +-> csnmp_config_add_host_priv_protocol
219 * +-> csnmp_config_add_host_security_level
221 static void call_snmp_init_once(void) {
222 static int have_init = 0;
225 init_snmp(PACKAGE_NAME);
227 } /* void call_snmp_init_once */
229 static int csnmp_config_add_data_instance(data_definition_t *dd,
230 oconfig_item_t *ci) {
231 char buffer[DATA_MAX_NAME_LEN];
234 status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
239 /* Instance is an OID */
240 dd->instance.oid.oid_len = MAX_OID_LEN;
242 if (!read_objid(buffer, dd->instance.oid.oid, &dd->instance.oid.oid_len)) {
243 ERROR("snmp plugin: read_objid (%s) failed.", buffer);
247 /* Instance is a simple string */
248 sstrncpy(dd->instance.string, buffer, sizeof(dd->instance.string));
252 } /* int csnmp_config_add_data_instance */
254 static int csnmp_config_add_data_instance_prefix(data_definition_t *dd,
255 oconfig_item_t *ci) {
259 WARNING("snmp plugin: data %s: InstancePrefix is ignored when `Table' "
260 "is set to `false'.",
265 status = cf_util_get_string(ci, &dd->instance_prefix);
267 } /* int csnmp_config_add_data_instance_prefix */
269 static int csnmp_config_add_data_values(data_definition_t *dd,
270 oconfig_item_t *ci) {
271 if (ci->values_num < 1) {
272 WARNING("snmp plugin: `Values' needs at least one argument.");
276 for (int i = 0; i < ci->values_num; i++)
277 if (ci->values[i].type != OCONFIG_TYPE_STRING) {
278 WARNING("snmp plugin: `Values' needs only string argument.");
284 dd->values = malloc(sizeof(*dd->values) * ci->values_num);
285 if (dd->values == NULL)
287 dd->values_len = (size_t)ci->values_num;
289 for (int i = 0; i < ci->values_num; i++) {
290 dd->values[i].oid_len = MAX_OID_LEN;
292 if (NULL == snmp_parse_oid(ci->values[i].value.string, dd->values[i].oid,
293 &dd->values[i].oid_len)) {
294 ERROR("snmp plugin: snmp_parse_oid (%s) failed.",
295 ci->values[i].value.string);
304 } /* int csnmp_config_add_data_instance */
306 static int csnmp_config_add_data_blacklist(data_definition_t *dd,
307 oconfig_item_t *ci) {
308 if (ci->values_num < 1)
311 for (int i = 0; i < ci->values_num; i++) {
312 if (ci->values[i].type != OCONFIG_TYPE_STRING) {
313 WARNING("snmp plugin: `Ignore' needs only string argument.");
321 for (int i = 0; i < ci->values_num; ++i) {
322 if (strarray_add(&(dd->ignores), &(dd->ignores_len),
323 ci->values[i].value.string) != 0) {
324 ERROR("snmp plugin: Can't allocate memory");
325 strarray_free(dd->ignores, dd->ignores_len);
330 } /* int csnmp_config_add_data_blacklist */
332 static int csnmp_config_add_data(oconfig_item_t *ci) {
333 data_definition_t *dd = calloc(1, sizeof(*dd));
337 int status = cf_util_get_string(ci, &dd->name);
346 for (int i = 0; i < ci->children_num; i++) {
347 oconfig_item_t *option = ci->children + i;
349 if (strcasecmp("Type", option->key) == 0)
350 status = cf_util_get_string(option, &dd->type);
351 else if (strcasecmp("Table", option->key) == 0)
352 status = cf_util_get_boolean(option, &dd->is_table);
353 else if (strcasecmp("Instance", option->key) == 0)
354 status = csnmp_config_add_data_instance(dd, option);
355 else if (strcasecmp("InstancePrefix", option->key) == 0)
356 status = csnmp_config_add_data_instance_prefix(dd, option);
357 else if (strcasecmp("Values", option->key) == 0)
358 status = csnmp_config_add_data_values(dd, option);
359 else if (strcasecmp("Shift", option->key) == 0)
360 status = cf_util_get_double(option, &dd->shift);
361 else if (strcasecmp("Scale", option->key) == 0)
362 status = cf_util_get_double(option, &dd->scale);
363 else if (strcasecmp("Ignore", option->key) == 0)
364 status = csnmp_config_add_data_blacklist(dd, option);
365 else if (strcasecmp("InvertMatch", option->key) == 0)
366 status = cf_util_get_boolean(option, &dd->invert_match);
368 WARNING("snmp plugin: Option `%s' not allowed here.", option->key);
374 } /* for (ci->children) */
376 while (status == 0) {
377 if (dd->type == NULL) {
378 WARNING("snmp plugin: `Type' not given for data `%s'", dd->name);
382 if (dd->values == NULL) {
383 WARNING("snmp plugin: No `Value' given for data `%s'", dd->name);
389 } /* while (status == 0) */
393 sfree(dd->instance_prefix);
400 DEBUG("snmp plugin: dd = { name = %s, type = %s, is_table = %s, values_len = "
402 dd->name, dd->type, (dd->is_table != 0) ? "true" : "false",
405 if (data_head == NULL)
408 data_definition_t *last;
410 while (last->next != NULL)
416 } /* int csnmp_config_add_data */
418 static int csnmp_config_add_host_version(host_definition_t *hd,
419 oconfig_item_t *ci) {
422 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
423 WARNING("snmp plugin: The `Version' config option needs exactly one number "
428 version = (int)ci->values[0].value.number;
429 if ((version < 1) || (version > 3)) {
430 WARNING("snmp plugin: `Version' must either be `1', `2', or `3'.");
434 hd->version = version;
437 } /* int csnmp_config_add_host_address */
439 static int csnmp_config_add_host_collect(host_definition_t *host,
440 oconfig_item_t *ci) {
441 data_definition_t *data;
442 data_definition_t **data_list;
445 if (ci->values_num < 1) {
446 WARNING("snmp plugin: `Collect' needs at least one argument.");
450 for (int i = 0; i < ci->values_num; i++)
451 if (ci->values[i].type != OCONFIG_TYPE_STRING) {
452 WARNING("snmp plugin: All arguments to `Collect' must be strings.");
456 data_list_len = host->data_list_len + ci->values_num;
458 realloc(host->data_list, sizeof(data_definition_t *) * data_list_len);
459 if (data_list == NULL)
461 host->data_list = data_list;
463 for (int i = 0; i < ci->values_num; i++) {
464 for (data = data_head; data != NULL; data = data->next)
465 if (strcasecmp(ci->values[i].value.string, data->name) == 0)
469 WARNING("snmp plugin: No such data configured: `%s'",
470 ci->values[i].value.string);
474 DEBUG("snmp plugin: Collect: host = %s, data[%i] = %s;", host->name,
475 host->data_list_len, data->name);
477 host->data_list[host->data_list_len] = data;
478 host->data_list_len++;
479 } /* for (values_num) */
482 } /* int csnmp_config_add_host_collect */
484 static int csnmp_config_add_host_auth_protocol(host_definition_t *hd,
485 oconfig_item_t *ci) {
489 status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
493 if (strcasecmp("MD5", buffer) == 0) {
494 hd->auth_protocol = usmHMACMD5AuthProtocol;
495 hd->auth_protocol_len = sizeof(usmHMACMD5AuthProtocol) / sizeof(oid);
496 } else if (strcasecmp("SHA", buffer) == 0) {
497 hd->auth_protocol = usmHMACSHA1AuthProtocol;
498 hd->auth_protocol_len = sizeof(usmHMACSHA1AuthProtocol) / sizeof(oid);
500 WARNING("snmp plugin: The `AuthProtocol' config option must be `MD5' or "
505 DEBUG("snmp plugin: host = %s; host->auth_protocol = %s;", hd->name,
506 hd->auth_protocol == usmHMACMD5AuthProtocol ? "MD5" : "SHA");
509 } /* int csnmp_config_add_host_auth_protocol */
511 static int csnmp_config_add_host_priv_protocol(host_definition_t *hd,
512 oconfig_item_t *ci) {
516 status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
520 if (strcasecmp("AES", buffer) == 0) {
521 hd->priv_protocol = usmAESPrivProtocol;
522 hd->priv_protocol_len = sizeof(usmAESPrivProtocol) / sizeof(oid);
523 } else if (strcasecmp("DES", buffer) == 0) {
524 hd->priv_protocol = usmDESPrivProtocol;
525 hd->priv_protocol_len = sizeof(usmDESPrivProtocol) / sizeof(oid);
527 WARNING("snmp plugin: The `PrivProtocol' config option must be `AES' or "
532 DEBUG("snmp plugin: host = %s; host->priv_protocol = %s;", hd->name,
533 hd->priv_protocol == usmAESPrivProtocol ? "AES" : "DES");
536 } /* int csnmp_config_add_host_priv_protocol */
538 static int csnmp_config_add_host_security_level(host_definition_t *hd,
539 oconfig_item_t *ci) {
543 status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
547 if (strcasecmp("noAuthNoPriv", buffer) == 0)
548 hd->security_level = SNMP_SEC_LEVEL_NOAUTH;
549 else if (strcasecmp("authNoPriv", buffer) == 0)
550 hd->security_level = SNMP_SEC_LEVEL_AUTHNOPRIV;
551 else if (strcasecmp("authPriv", buffer) == 0)
552 hd->security_level = SNMP_SEC_LEVEL_AUTHPRIV;
554 WARNING("snmp plugin: The `SecurityLevel' config option must be "
555 "`noAuthNoPriv', `authNoPriv', or `authPriv'.");
559 DEBUG("snmp plugin: host = %s; host->security_level = %d;", hd->name,
563 } /* int csnmp_config_add_host_security_level */
565 static int csnmp_config_add_host(oconfig_item_t *ci) {
566 host_definition_t *hd;
569 /* Registration stuff. */
570 char cb_name[DATA_MAX_NAME_LEN];
572 hd = calloc(1, sizeof(*hd));
576 C_COMPLAIN_INIT(&hd->complaint);
578 status = cf_util_get_string(ci, &hd->name);
584 hd->sess_handle = NULL;
587 /* These mean that we have not set a timeout or retry value */
591 for (int i = 0; i < ci->children_num; i++) {
592 oconfig_item_t *option = ci->children + i;
595 if (strcasecmp("Address", option->key) == 0)
596 status = cf_util_get_string(option, &hd->address);
597 else if (strcasecmp("Community", option->key) == 0)
598 status = cf_util_get_string(option, &hd->community);
599 else if (strcasecmp("Version", option->key) == 0)
600 status = csnmp_config_add_host_version(hd, option);
601 else if (strcasecmp("Timeout", option->key) == 0)
602 cf_util_get_cdtime(option, &hd->timeout);
603 else if (strcasecmp("Retries", option->key) == 0)
604 cf_util_get_int(option, &hd->retries);
605 else if (strcasecmp("Collect", option->key) == 0)
606 csnmp_config_add_host_collect(hd, option);
607 else if (strcasecmp("Interval", option->key) == 0)
608 cf_util_get_cdtime(option, &hd->interval);
609 else if (strcasecmp("Username", option->key) == 0)
610 status = cf_util_get_string(option, &hd->username);
611 else if (strcasecmp("AuthProtocol", option->key) == 0)
612 status = csnmp_config_add_host_auth_protocol(hd, option);
613 else if (strcasecmp("PrivacyProtocol", option->key) == 0)
614 status = csnmp_config_add_host_priv_protocol(hd, option);
615 else if (strcasecmp("AuthPassphrase", option->key) == 0)
616 status = cf_util_get_string(option, &hd->auth_passphrase);
617 else if (strcasecmp("PrivacyPassphrase", option->key) == 0)
618 status = cf_util_get_string(option, &hd->priv_passphrase);
619 else if (strcasecmp("SecurityLevel", option->key) == 0)
620 status = csnmp_config_add_host_security_level(hd, option);
621 else if (strcasecmp("Context", option->key) == 0)
622 status = cf_util_get_string(option, &hd->context);
625 "snmp plugin: csnmp_config_add_host: Option `%s' not allowed here.",
632 } /* for (ci->children) */
634 while (status == 0) {
635 if (hd->address == NULL) {
636 WARNING("snmp plugin: `Address' not given for host `%s'", hd->name);
640 if (hd->community == NULL && hd->version < 3) {
641 WARNING("snmp plugin: `Community' not given for host `%s'", hd->name);
645 if (hd->version == 3) {
646 if (hd->username == NULL) {
647 WARNING("snmp plugin: `Username' not given for host `%s'", hd->name);
651 if (hd->security_level == 0) {
652 WARNING("snmp plugin: `SecurityLevel' not given for host `%s'",
657 if (hd->security_level == SNMP_SEC_LEVEL_AUTHNOPRIV ||
658 hd->security_level == SNMP_SEC_LEVEL_AUTHPRIV) {
659 if (hd->auth_protocol == NULL) {
660 WARNING("snmp plugin: `AuthProtocol' not given for host `%s'",
665 if (hd->auth_passphrase == NULL) {
666 WARNING("snmp plugin: `AuthPassphrase' not given for host `%s'",
672 if (hd->security_level == SNMP_SEC_LEVEL_AUTHPRIV) {
673 if (hd->priv_protocol == NULL) {
674 WARNING("snmp plugin: `PrivacyProtocol' not given for host `%s'",
679 if (hd->priv_passphrase == NULL) {
680 WARNING("snmp plugin: `PrivacyPassphrase' not given for host `%s'",
689 } /* while (status == 0) */
692 csnmp_host_definition_destroy(hd);
696 DEBUG("snmp plugin: hd = { name = %s, address = %s, community = %s, version "
698 hd->name, hd->address, hd->community, hd->version);
700 snprintf(cb_name, sizeof(cb_name), "snmp-%s", hd->name);
702 status = plugin_register_complex_read(
703 /* group = */ NULL, cb_name, csnmp_read_host, hd->interval,
705 .data = hd, .free_func = csnmp_host_definition_destroy,
708 ERROR("snmp plugin: Registering complex read function failed.");
713 } /* int csnmp_config_add_host */
715 static int csnmp_config(oconfig_item_t *ci) {
716 call_snmp_init_once();
718 for (int i = 0; i < ci->children_num; i++) {
719 oconfig_item_t *child = ci->children + i;
720 if (strcasecmp("Data", child->key) == 0)
721 csnmp_config_add_data(child);
722 else if (strcasecmp("Host", child->key) == 0)
723 csnmp_config_add_host(child);
725 WARNING("snmp plugin: Ignoring unknown config option `%s'.", child->key);
727 } /* for (ci->children) */
730 } /* int csnmp_config */
732 /* }}} End of the config stuff. Now the interesting part begins */
734 static void csnmp_host_open_session(host_definition_t *host) {
735 struct snmp_session sess;
738 if (host->sess_handle != NULL)
739 csnmp_host_close_session(host);
741 snmp_sess_init(&sess);
742 sess.peername = host->address;
743 switch (host->version) {
745 sess.version = SNMP_VERSION_1;
748 sess.version = SNMP_VERSION_3;
751 sess.version = SNMP_VERSION_2c;
755 if (host->version == 3) {
756 sess.securityName = host->username;
757 sess.securityNameLen = strlen(host->username);
758 sess.securityLevel = host->security_level;
760 if (sess.securityLevel == SNMP_SEC_LEVEL_AUTHNOPRIV ||
761 sess.securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) {
762 sess.securityAuthProto = host->auth_protocol;
763 sess.securityAuthProtoLen = host->auth_protocol_len;
764 sess.securityAuthKeyLen = USM_AUTH_KU_LEN;
765 error = generate_Ku(sess.securityAuthProto, sess.securityAuthProtoLen,
766 (u_char *)host->auth_passphrase,
767 strlen(host->auth_passphrase), sess.securityAuthKey,
768 &sess.securityAuthKeyLen);
769 if (error != SNMPERR_SUCCESS) {
770 ERROR("snmp plugin: host %s: Error generating Ku from auth_passphrase. "
776 if (sess.securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) {
777 sess.securityPrivProto = host->priv_protocol;
778 sess.securityPrivProtoLen = host->priv_protocol_len;
779 sess.securityPrivKeyLen = USM_PRIV_KU_LEN;
780 error = generate_Ku(sess.securityAuthProto, sess.securityAuthProtoLen,
781 (u_char *)host->priv_passphrase,
782 strlen(host->priv_passphrase), sess.securityPrivKey,
783 &sess.securityPrivKeyLen);
784 if (error != SNMPERR_SUCCESS) {
785 ERROR("snmp plugin: host %s: Error generating Ku from priv_passphrase. "
791 if (host->context != NULL) {
792 sess.contextName = host->context;
793 sess.contextNameLen = strlen(host->context);
795 } else /* SNMPv1/2 "authenticates" with community string */
797 sess.community = (u_char *)host->community;
798 sess.community_len = strlen(host->community);
801 /* Set timeout & retries, if they have been changed from the default */
802 if (host->timeout != 0) {
803 /* net-snmp expects microseconds */
804 sess.timeout = CDTIME_T_TO_US(host->timeout);
806 if (host->retries >= 0) {
807 sess.retries = host->retries;
810 /* snmp_sess_open will copy the `struct snmp_session *'. */
811 host->sess_handle = snmp_sess_open(&sess);
813 if (host->sess_handle == NULL) {
816 snmp_error(&sess, NULL, NULL, &errstr);
818 ERROR("snmp plugin: host %s: snmp_sess_open failed: %s", host->name,
819 (errstr == NULL) ? "Unknown problem" : errstr);
822 } /* void csnmp_host_open_session */
824 /* TODO: Check if negative values wrap around. Problem: negative temperatures.
826 static value_t csnmp_value_list_to_value(struct variable_list *vl, int type,
827 double scale, double shift,
828 const char *host_name,
829 const char *data_name) {
831 uint64_t tmp_unsigned = 0;
832 int64_t tmp_signed = 0;
834 /* Set to true when the original SNMP type appears to have been signed. */
835 _Bool prefer_signed = 0;
837 if ((vl->type == ASN_INTEGER) || (vl->type == ASN_UINTEGER) ||
838 (vl->type == ASN_COUNTER)
840 || (vl->type == ASN_TIMETICKS)
842 || (vl->type == ASN_GAUGE)) {
843 tmp_unsigned = (uint32_t)*vl->val.integer;
844 tmp_signed = (int32_t)*vl->val.integer;
846 if (vl->type == ASN_INTEGER)
849 DEBUG("snmp plugin: Parsed int32 value is %" PRIu64 ".", tmp_unsigned);
850 } else if (vl->type == ASN_COUNTER64) {
851 tmp_unsigned = (uint32_t)vl->val.counter64->high;
852 tmp_unsigned = tmp_unsigned << 32;
853 tmp_unsigned += (uint32_t)vl->val.counter64->low;
854 tmp_signed = (int64_t)tmp_unsigned;
855 DEBUG("snmp plugin: Parsed int64 value is %" PRIu64 ".", tmp_unsigned);
856 } else if (vl->type == ASN_OCTET_STR) {
857 /* We'll handle this later.. */
859 char oid_buffer[1024] = {0};
861 snprint_objid(oid_buffer, sizeof(oid_buffer) - 1, vl->name,
865 if (vl->type == ASN_NULL)
866 INFO("snmp plugin: OID \"%s\" is undefined (type ASN_NULL)", oid_buffer);
869 WARNING("snmp plugin: I don't know the ASN type #%i "
870 "(OID: \"%s\", data block \"%s\", host block \"%s\")",
871 (int)vl->type, oid_buffer,
872 (data_name != NULL) ? data_name : "UNKNOWN",
873 (host_name != NULL) ? host_name : "UNKNOWN");
878 if (vl->type == ASN_OCTET_STR) {
881 if (vl->val.string != NULL) {
883 size_t string_length;
885 string_length = sizeof(string) - 1;
886 if (vl->val_len < string_length)
887 string_length = vl->val_len;
889 /* The strings we get from the Net-SNMP library may not be null
890 * terminated. That is why we're using `memcpy' here and not `strcpy'.
891 * `string_length' is set to `vl->val_len' which holds the length of the
893 memcpy(string, vl->val.string, string_length);
894 string[string_length] = 0;
896 status = parse_value(string, &ret, type);
898 ERROR("snmp plugin: host %s: csnmp_value_list_to_value: Parsing string "
900 (host_name != NULL) ? host_name : "UNKNOWN",
901 DS_TYPE_TO_STRING(type), string);
907 case DS_TYPE_COUNTER:
909 case DS_TYPE_ABSOLUTE:
910 memset(&ret, 0, sizeof(ret));
918 ERROR("snmp plugin: csnmp_value_list_to_value: Unknown "
919 "data source type: %i.",
924 } /* if (vl->type == ASN_OCTET_STR) */
925 else if (type == DS_TYPE_COUNTER) {
926 ret.counter = tmp_unsigned;
927 } else if (type == DS_TYPE_GAUGE) {
930 else if (prefer_signed)
931 ret.gauge = (scale * tmp_signed) + shift;
933 ret.gauge = (scale * tmp_unsigned) + shift;
934 } else if (type == DS_TYPE_DERIVE) {
936 ret.derive = (derive_t)tmp_signed;
938 ret.derive = (derive_t)tmp_unsigned;
939 } else if (type == DS_TYPE_ABSOLUTE) {
940 ret.absolute = (absolute_t)tmp_unsigned;
942 ERROR("snmp plugin: csnmp_value_list_to_value: Unknown data source "
949 } /* value_t csnmp_value_list_to_value */
951 /* csnmp_strvbcopy_hexstring converts the bit string contained in "vb" to a hex
952 * representation and writes it to dst. Returns zero on success and ENOMEM if
953 * dst is not large enough to hold the string. dst is guaranteed to be
955 static int csnmp_strvbcopy_hexstring(char *dst, /* {{{ */
956 const struct variable_list *vb,
964 buffer_free = dst_size;
966 for (size_t i = 0; i < vb->val_len; i++) {
969 status = snprintf(buffer_ptr, buffer_free, (i == 0) ? "%02x" : ":%02x",
970 (unsigned int)vb->val.bitstring[i]);
973 if (((size_t)status) >= buffer_free) /* truncated */
975 dst[dst_size - 1] = 0;
977 } else /* if (status < buffer_free) */
979 buffer_ptr += (size_t)status;
980 buffer_free -= (size_t)status;
985 } /* }}} int csnmp_strvbcopy_hexstring */
987 /* csnmp_strvbcopy copies the octet string or bit string contained in vb to
988 * dst. If non-printable characters are detected, it will switch to a hex
989 * representation of the string. Returns zero on success, EINVAL if vb does not
990 * contain a string and ENOMEM if dst is not large enough to contain the
992 static int csnmp_strvbcopy(char *dst, /* {{{ */
993 const struct variable_list *vb, size_t dst_size) {
997 if (vb->type == ASN_OCTET_STR)
998 src = (char *)vb->val.string;
999 else if (vb->type == ASN_BIT_STR)
1000 src = (char *)vb->val.bitstring;
1001 else if (vb->type == ASN_IPADDRESS) {
1002 return snprintf(dst, dst_size,
1003 "%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 "",
1004 (uint8_t)vb->val.string[0], (uint8_t)vb->val.string[1],
1005 (uint8_t)vb->val.string[2], (uint8_t)vb->val.string[3]);
1011 num_chars = dst_size - 1;
1012 if (num_chars > vb->val_len)
1013 num_chars = vb->val_len;
1015 for (size_t i = 0; i < num_chars; i++) {
1016 /* Check for control characters. */
1017 if ((unsigned char)src[i] < 32)
1018 return csnmp_strvbcopy_hexstring(dst, vb, dst_size);
1022 dst[dst_size - 1] = 0;
1024 if (dst_size <= vb->val_len)
1028 } /* }}} int csnmp_strvbcopy */
1030 static int csnmp_instance_list_add(csnmp_list_instances_t **head,
1031 csnmp_list_instances_t **tail,
1032 const struct snmp_pdu *res,
1033 const host_definition_t *hd,
1034 const data_definition_t *dd) {
1035 csnmp_list_instances_t *il;
1036 struct variable_list *vb;
1040 /* Set vb on the last variable */
1041 for (vb = res->variables; (vb != NULL) && (vb->next_variable != NULL);
1042 vb = vb->next_variable)
1047 csnmp_oid_init(&vb_name, vb->name, vb->name_length);
1049 il = calloc(1, sizeof(*il));
1051 ERROR("snmp plugin: calloc failed.");
1056 status = csnmp_oid_suffix(&il->suffix, &vb_name, &dd->instance.oid);
1062 /* Get instance name */
1063 if ((vb->type == ASN_OCTET_STR) || (vb->type == ASN_BIT_STR) ||
1064 (vb->type == ASN_IPADDRESS)) {
1067 csnmp_strvbcopy(il->instance, vb, sizeof(il->instance));
1068 _Bool is_matched = 0;
1069 for (uint32_t i = 0; i < dd->ignores_len; i++) {
1070 status = fnmatch(dd->ignores[i], il->instance, 0);
1072 if (!dd->invert_match) {
1081 if (dd->invert_match && !is_matched) {
1085 for (ptr = il->instance; *ptr != '\0'; ptr++) {
1086 if ((*ptr > 0) && (*ptr < 32))
1088 else if (*ptr == '/')
1091 DEBUG("snmp plugin: il->instance = `%s';", il->instance);
1093 value_t val = csnmp_value_list_to_value(
1094 vb, DS_TYPE_COUNTER,
1095 /* scale = */ 1.0, /* shift = */ 0.0, hd->name, dd->name);
1096 snprintf(il->instance, sizeof(il->instance), "%" PRIu64,
1097 (uint64_t)val.counter);
1100 /* TODO: Debugging output */
1109 } /* int csnmp_instance_list_add */
1111 static int csnmp_dispatch_table(host_definition_t *host,
1112 data_definition_t *data,
1113 csnmp_list_instances_t *instance_list,
1114 csnmp_table_values_t **value_table) {
1115 const data_set_t *ds;
1116 value_list_t vl = VALUE_LIST_INIT;
1118 csnmp_list_instances_t *instance_list_ptr;
1119 csnmp_table_values_t *value_table_ptr[data->values_len];
1123 oid_t current_suffix;
1125 ds = plugin_get_ds(data->type);
1127 ERROR("snmp plugin: DataSet `%s' not defined.", data->type);
1130 assert(ds->ds_num == data->values_len);
1131 assert(data->values_len > 0);
1133 instance_list_ptr = instance_list;
1135 for (i = 0; i < data->values_len; i++)
1136 value_table_ptr[i] = value_table[i];
1138 sstrncpy(vl.host, host->name, sizeof(vl.host));
1139 sstrncpy(vl.plugin, "snmp", sizeof(vl.plugin));
1141 vl.interval = host->interval;
1145 _Bool suffix_skipped = 0;
1147 /* Determine next suffix to handle. */
1148 if (instance_list != NULL) {
1149 if (instance_list_ptr == NULL) {
1154 memcpy(¤t_suffix, &instance_list_ptr->suffix,
1155 sizeof(current_suffix));
1157 /* no instance configured */
1158 csnmp_table_values_t *ptr = value_table_ptr[0];
1164 memcpy(¤t_suffix, &ptr->suffix, sizeof(current_suffix));
1167 /* Update all the value_table_ptr to point at the entry with the same
1168 * trailing partial OID */
1169 for (i = 0; i < data->values_len; i++) {
1171 (value_table_ptr[i] != NULL) &&
1172 (csnmp_oid_compare(&value_table_ptr[i]->suffix, ¤t_suffix) < 0))
1173 value_table_ptr[i] = value_table_ptr[i]->next;
1175 if (value_table_ptr[i] == NULL) {
1178 } else if (csnmp_oid_compare(&value_table_ptr[i]->suffix,
1179 ¤t_suffix) > 0) {
1180 /* This suffix is missing in the subtree. Indicate this with the
1181 * "suffix_skipped" flag and try the next instance / suffix. */
1185 } /* for (i = 0; i < columns; i++) */
1190 /* Matching the values failed. Start from the beginning again. */
1191 if (suffix_skipped) {
1192 if (instance_list != NULL)
1193 instance_list_ptr = instance_list_ptr->next;
1195 value_table_ptr[0] = value_table_ptr[0]->next;
1200 /* if we reach this line, all value_table_ptr[i] are non-NULL and are set
1201 * to the same subid. instance_list_ptr is either NULL or points to the
1202 * same subid, too. */
1204 for (i = 1; i < data->values_len; i++) {
1205 assert(value_table_ptr[i] != NULL);
1206 assert(csnmp_oid_compare(&value_table_ptr[i - 1]->suffix,
1207 &value_table_ptr[i]->suffix) == 0);
1209 assert((instance_list_ptr == NULL) ||
1210 (csnmp_oid_compare(&instance_list_ptr->suffix,
1211 &value_table_ptr[0]->suffix) == 0));
1214 sstrncpy(vl.type, data->type, sizeof(vl.type));
1217 char temp[DATA_MAX_NAME_LEN];
1219 if (instance_list_ptr == NULL)
1220 csnmp_oid_to_string(temp, sizeof(temp), ¤t_suffix);
1222 sstrncpy(temp, instance_list_ptr->instance, sizeof(temp));
1224 if (data->instance_prefix == NULL)
1225 sstrncpy(vl.type_instance, temp, sizeof(vl.type_instance));
1227 snprintf(vl.type_instance, sizeof(vl.type_instance), "%s%s",
1228 data->instance_prefix, temp);
1231 vl.values_len = data->values_len;
1232 value_t values[vl.values_len];
1235 for (i = 0; i < data->values_len; i++)
1236 vl.values[i] = value_table_ptr[i]->value;
1238 /* If we get here `vl.type_instance' and all `vl.values' have been set
1239 * vl.type_instance can be empty, i.e. a blank port description on a
1240 * switch if you're using IF-MIB::ifDescr as Instance.
1242 if (vl.type_instance[0] != '\0')
1243 plugin_dispatch_values(&vl);
1245 /* prevent leakage of pointer to local variable. */
1249 if (instance_list != NULL)
1250 instance_list_ptr = instance_list_ptr->next;
1252 value_table_ptr[0] = value_table_ptr[0]->next;
1253 } /* while (have_more) */
1256 } /* int csnmp_dispatch_table */
1258 static int csnmp_read_table(host_definition_t *host, data_definition_t *data) {
1259 struct snmp_pdu *req;
1260 struct snmp_pdu *res = NULL;
1261 struct variable_list *vb;
1263 const data_set_t *ds;
1265 size_t oid_list_len = data->values_len + 1;
1266 /* Holds the last OID returned by the device. We use this in the GETNEXT
1267 * request to proceed. */
1268 oid_t oid_list[oid_list_len];
1269 /* Set to false when an OID has left its subtree so we don't re-request it
1271 _Bool oid_list_todo[oid_list_len];
1276 /* `value_list_head' and `value_list_tail' implement a linked list for each
1277 * value. `instance_list_head' and `instance_list_tail' implement a linked
1279 * instance names. This is used to jump gaps in the table. */
1280 csnmp_list_instances_t *instance_list_head;
1281 csnmp_list_instances_t *instance_list_tail;
1282 csnmp_table_values_t **value_list_head;
1283 csnmp_table_values_t **value_list_tail;
1285 DEBUG("snmp plugin: csnmp_read_table (host = %s, data = %s)", host->name,
1288 if (host->sess_handle == NULL) {
1289 DEBUG("snmp plugin: csnmp_read_table: host->sess_handle == NULL");
1293 ds = plugin_get_ds(data->type);
1295 ERROR("snmp plugin: DataSet `%s' not defined.", data->type);
1299 if (ds->ds_num != data->values_len) {
1300 ERROR("snmp plugin: DataSet `%s' requires %" PRIsz
1301 " values, but config talks "
1303 data->type, ds->ds_num, data->values_len);
1306 assert(data->values_len > 0);
1308 /* We need a copy of all the OIDs, because GETNEXT will destroy them. */
1309 memcpy(oid_list, data->values, data->values_len * sizeof(oid_t));
1310 if (data->instance.oid.oid_len > 0)
1311 memcpy(oid_list + data->values_len, &data->instance.oid, sizeof(oid_t));
1312 else /* no InstanceFrom option specified. */
1315 for (i = 0; i < oid_list_len; i++)
1316 oid_list_todo[i] = 1;
1318 /* We're going to construct n linked lists, one for each "value".
1319 * value_list_head will contain pointers to the heads of these linked lists,
1320 * value_list_tail will contain pointers to the tail of the lists. */
1321 value_list_head = calloc(data->values_len, sizeof(*value_list_head));
1322 value_list_tail = calloc(data->values_len, sizeof(*value_list_tail));
1323 if ((value_list_head == NULL) || (value_list_tail == NULL)) {
1324 ERROR("snmp plugin: csnmp_read_table: calloc failed.");
1325 sfree(value_list_head);
1326 sfree(value_list_tail);
1330 instance_list_head = NULL;
1331 instance_list_tail = NULL;
1334 while (status == 0) {
1335 req = snmp_pdu_create(SNMP_MSG_GETNEXT);
1337 ERROR("snmp plugin: snmp_pdu_create failed.");
1342 size_t oid_list_todo_num = 0;
1343 size_t var_idx[oid_list_len];
1344 memset(var_idx, 0, sizeof(var_idx));
1346 for (i = 0; i < oid_list_len; i++) {
1347 /* Do not rerequest already finished OIDs */
1348 if (!oid_list_todo[i])
1350 snmp_add_null_var(req, oid_list[i].oid, oid_list[i].oid_len);
1351 var_idx[oid_list_todo_num] = i;
1352 oid_list_todo_num++;
1355 if (oid_list_todo_num == 0) {
1356 /* The request is still empty - so we are finished */
1357 DEBUG("snmp plugin: all variables have left their subtree");
1364 status = snmp_sess_synch_response(host->sess_handle, req, &res);
1366 /* snmp_sess_synch_response always frees our req PDU */
1369 if ((status != STAT_SUCCESS) || (res == NULL)) {
1370 char *errstr = NULL;
1372 snmp_sess_error(host->sess_handle, NULL, NULL, &errstr);
1374 c_complain(LOG_ERR, &host->complaint,
1375 "snmp plugin: host %s: snmp_sess_synch_response failed: %s",
1376 host->name, (errstr == NULL) ? "Unknown problem" : errstr);
1383 csnmp_host_close_session(host);
1390 assert(res != NULL);
1391 c_release(LOG_INFO, &host->complaint,
1392 "snmp plugin: host %s: snmp_sess_synch_response successful.",
1395 vb = res->variables;
1401 if (res->errstat != SNMP_ERR_NOERROR) {
1402 if (res->errindex != 0) {
1403 /* Find the OID which caused error */
1404 for (i = 1, vb = res->variables; vb != NULL && i != res->errindex;
1405 vb = vb->next_variable, i++)
1409 if ((res->errindex == 0) || (vb == NULL)) {
1410 ERROR("snmp plugin: host %s; data %s: response error: %s (%li) ",
1411 host->name, data->name, snmp_errstring(res->errstat),
1417 char oid_buffer[1024] = {0};
1418 snprint_objid(oid_buffer, sizeof(oid_buffer) - 1, vb->name,
1420 NOTICE("snmp plugin: host %s; data %s: OID `%s` failed: %s", host->name,
1421 data->name, oid_buffer, snmp_errstring(res->errstat));
1423 /* Get value index from todo list and skip OID found */
1424 assert(res->errindex <= oid_list_todo_num);
1425 i = var_idx[res->errindex - 1];
1426 assert(i < oid_list_len);
1427 oid_list_todo[i] = 0;
1434 for (vb = res->variables, i = 0; (vb != NULL);
1435 vb = vb->next_variable, i++) {
1436 /* Calculate value index from todo list */
1437 while ((i < oid_list_len) && !oid_list_todo[i]) {
1440 if (i >= oid_list_len) {
1444 /* An instance is configured and the res variable we process is the
1445 * instance value (last index) */
1446 if ((data->instance.oid.oid_len > 0) && (i == data->values_len)) {
1447 if ((vb->type == SNMP_ENDOFMIBVIEW) ||
1449 data->instance.oid.oid, data->instance.oid.oid_len, vb->name,
1450 vb->name_length, data->instance.oid.oid_len) != 0)) {
1451 DEBUG("snmp plugin: host = %s; data = %s; Instance left its subtree.",
1452 host->name, data->name);
1453 oid_list_todo[i] = 0;
1457 /* Allocate a new `csnmp_list_instances_t', insert the instance name and
1458 * add it to the list */
1459 if (csnmp_instance_list_add(&instance_list_head, &instance_list_tail,
1460 res, host, data) != 0) {
1461 ERROR("snmp plugin: host %s: csnmp_instance_list_add failed.",
1466 } else /* The variable we are processing is a normal value */
1468 csnmp_table_values_t *vt;
1473 csnmp_oid_init(&vb_name, vb->name, vb->name_length);
1475 /* Calculate the current suffix. This is later used to check that the
1476 * suffix is increasing. This also checks if we left the subtree */
1477 ret = csnmp_oid_suffix(&suffix, &vb_name, data->values + i);
1479 DEBUG("snmp plugin: host = %s; data = %s; i = %" PRIsz "; "
1480 "Value probably left its subtree.",
1481 host->name, data->name, i);
1482 oid_list_todo[i] = 0;
1486 /* Make sure the OIDs returned by the agent are increasing. Otherwise
1488 * table matching algorithm will get confused. */
1489 if ((value_list_tail[i] != NULL) &&
1490 (csnmp_oid_compare(&suffix, &value_list_tail[i]->suffix) <= 0)) {
1491 DEBUG("snmp plugin: host = %s; data = %s; i = %" PRIsz "; "
1492 "Suffix is not increasing.",
1493 host->name, data->name, i);
1494 oid_list_todo[i] = 0;
1498 vt = calloc(1, sizeof(*vt));
1500 ERROR("snmp plugin: calloc failed.");
1506 csnmp_value_list_to_value(vb, ds->ds[i].type, data->scale,
1507 data->shift, host->name, data->name);
1508 memcpy(&vt->suffix, &suffix, sizeof(vt->suffix));
1511 if (value_list_tail[i] == NULL)
1512 value_list_head[i] = vt;
1514 value_list_tail[i]->next = vt;
1515 value_list_tail[i] = vt;
1518 /* Copy OID to oid_list[i] */
1519 memcpy(oid_list[i].oid, vb->name, sizeof(oid) * vb->name_length);
1520 oid_list[i].oid_len = vb->name_length;
1522 } /* for (vb = res->variables ...) */
1527 } /* while (status == 0) */
1534 csnmp_dispatch_table(host, data, instance_list_head, value_list_head);
1536 /* Free all allocated variables here */
1537 while (instance_list_head != NULL) {
1538 csnmp_list_instances_t *next = instance_list_head->next;
1539 sfree(instance_list_head);
1540 instance_list_head = next;
1543 for (i = 0; i < data->values_len; i++) {
1544 while (value_list_head[i] != NULL) {
1545 csnmp_table_values_t *next = value_list_head[i]->next;
1546 sfree(value_list_head[i]);
1547 value_list_head[i] = next;
1551 sfree(value_list_head);
1552 sfree(value_list_tail);
1555 } /* int csnmp_read_table */
1557 static int csnmp_read_value(host_definition_t *host, data_definition_t *data) {
1558 struct snmp_pdu *req;
1559 struct snmp_pdu *res = NULL;
1560 struct variable_list *vb;
1562 const data_set_t *ds;
1563 value_list_t vl = VALUE_LIST_INIT;
1568 DEBUG("snmp plugin: csnmp_read_value (host = %s, data = %s)", host->name,
1571 if (host->sess_handle == NULL) {
1572 DEBUG("snmp plugin: csnmp_read_value: host->sess_handle == NULL");
1576 ds = plugin_get_ds(data->type);
1578 ERROR("snmp plugin: DataSet `%s' not defined.", data->type);
1582 if (ds->ds_num != data->values_len) {
1583 ERROR("snmp plugin: DataSet `%s' requires %" PRIsz
1584 " values, but config talks "
1586 data->type, ds->ds_num, data->values_len);
1590 vl.values_len = ds->ds_num;
1591 vl.values = malloc(sizeof(*vl.values) * vl.values_len);
1592 if (vl.values == NULL)
1594 for (i = 0; i < vl.values_len; i++) {
1595 if (ds->ds[i].type == DS_TYPE_COUNTER)
1596 vl.values[i].counter = 0;
1598 vl.values[i].gauge = NAN;
1601 sstrncpy(vl.host, host->name, sizeof(vl.host));
1602 sstrncpy(vl.plugin, "snmp", sizeof(vl.plugin));
1603 sstrncpy(vl.type, data->type, sizeof(vl.type));
1604 sstrncpy(vl.type_instance, data->instance.string, sizeof(vl.type_instance));
1606 vl.interval = host->interval;
1608 req = snmp_pdu_create(SNMP_MSG_GET);
1610 ERROR("snmp plugin: snmp_pdu_create failed.");
1615 for (i = 0; i < data->values_len; i++)
1616 snmp_add_null_var(req, data->values[i].oid, data->values[i].oid_len);
1618 status = snmp_sess_synch_response(host->sess_handle, req, &res);
1620 if ((status != STAT_SUCCESS) || (res == NULL)) {
1621 char *errstr = NULL;
1623 snmp_sess_error(host->sess_handle, NULL, NULL, &errstr);
1624 ERROR("snmp plugin: host %s: snmp_sess_synch_response failed: %s",
1625 host->name, (errstr == NULL) ? "Unknown problem" : errstr);
1632 csnmp_host_close_session(host);
1637 for (vb = res->variables; vb != NULL; vb = vb->next_variable) {
1640 snprint_variable(buffer, sizeof(buffer), vb->name, vb->name_length, vb);
1641 DEBUG("snmp plugin: Got this variable: %s", buffer);
1642 #endif /* COLLECT_DEBUG */
1644 for (i = 0; i < data->values_len; i++)
1645 if (snmp_oid_compare(data->values[i].oid, data->values[i].oid_len,
1646 vb->name, vb->name_length) == 0)
1648 csnmp_value_list_to_value(vb, ds->ds[i].type, data->scale,
1649 data->shift, host->name, data->name);
1650 } /* for (res->variables) */
1654 DEBUG("snmp plugin: -> plugin_dispatch_values (&vl);");
1655 plugin_dispatch_values(&vl);
1659 } /* int csnmp_read_value */
1661 static int csnmp_read_host(user_data_t *ud) {
1662 host_definition_t *host;
1669 if (host->interval == 0)
1670 host->interval = plugin_get_interval();
1672 if (host->sess_handle == NULL)
1673 csnmp_host_open_session(host);
1675 if (host->sess_handle == NULL)
1679 for (i = 0; i < host->data_list_len; i++) {
1680 data_definition_t *data = host->data_list[i];
1683 status = csnmp_read_table(host, data);
1685 status = csnmp_read_value(host, data);
1695 } /* int csnmp_read_host */
1697 static int csnmp_init(void) {
1698 call_snmp_init_once();
1701 } /* int csnmp_init */
1703 static int csnmp_shutdown(void) {
1704 data_definition_t *data_this;
1705 data_definition_t *data_next;
1707 /* When we get here, the read threads have been stopped and all the
1708 * `host_definition_t' will be freed. */
1709 DEBUG("snmp plugin: Destroying all data definitions.");
1711 data_this = data_head;
1713 while (data_this != NULL) {
1714 data_next = data_this->next;
1716 sfree(data_this->name);
1717 sfree(data_this->type);
1718 sfree(data_this->values);
1719 sfree(data_this->ignores);
1722 data_this = data_next;
1726 } /* int csnmp_shutdown */
1728 void module_register(void) {
1729 plugin_register_complex_config("snmp", csnmp_config);
1730 plugin_register_init("snmp", csnmp_init);
1731 plugin_register_shutdown("snmp", csnmp_shutdown);
1732 } /* void module_register */