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 {
75 /* snmpv1/2 options */
78 /* snmpv3 security options */
81 size_t auth_protocol_len;
82 char *auth_passphrase;
84 size_t priv_protocol_len;
85 char *priv_passphrase;
90 c_complain_t complaint;
92 data_definition_t **data_list;
95 typedef struct host_definition_s host_definition_t;
97 /* These two types are used to cache values in `csnmp_read_table' to handle
99 struct csnmp_list_instances_s {
101 char instance[DATA_MAX_NAME_LEN];
102 struct csnmp_list_instances_s *next;
104 typedef struct csnmp_list_instances_s csnmp_list_instances_t;
106 struct csnmp_table_values_s {
109 struct csnmp_table_values_s *next;
111 typedef struct csnmp_table_values_s csnmp_table_values_t;
116 static data_definition_t *data_head = NULL;
121 static int csnmp_read_host(user_data_t *ud);
126 static void csnmp_oid_init(oid_t *dst, oid const *src, size_t n) {
127 assert(n <= STATIC_ARRAY_SIZE(dst->oid));
128 memcpy(dst->oid, src, sizeof(*src) * n);
132 static int csnmp_oid_compare(oid_t const *left, oid_t const *right) {
133 return snmp_oid_compare(left->oid, left->oid_len, right->oid, right->oid_len);
136 static int csnmp_oid_suffix(oid_t *dst, oid_t const *src, oid_t const *root) {
137 /* Make sure "src" is in "root"s subtree. */
138 if (src->oid_len <= root->oid_len)
140 if (snmp_oid_ncompare(root->oid, root->oid_len, src->oid, src->oid_len,
141 /* n = */ root->oid_len) != 0)
144 memset(dst, 0, sizeof(*dst));
145 dst->oid_len = src->oid_len - root->oid_len;
146 memcpy(dst->oid, &src->oid[root->oid_len],
147 dst->oid_len * sizeof(dst->oid[0]));
151 static int csnmp_oid_to_string(char *buffer, size_t buffer_size,
153 char oid_str[MAX_OID_LEN][16];
154 char *oid_str_ptr[MAX_OID_LEN];
156 for (size_t i = 0; i < o->oid_len; i++) {
157 snprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]);
158 oid_str_ptr[i] = oid_str[i];
161 return strjoin(buffer, buffer_size, oid_str_ptr, o->oid_len, ".");
164 static void csnmp_host_close_session(host_definition_t *host) /* {{{ */
166 if (host->sess_handle == NULL)
169 snmp_sess_close(host->sess_handle);
170 host->sess_handle = NULL;
171 } /* }}} void csnmp_host_close_session */
173 static void csnmp_host_definition_destroy(void *arg) /* {{{ */
175 host_definition_t *hd;
182 if (hd->name != NULL) {
183 DEBUG("snmp plugin: Destroying host definition for host `%s'.", hd->name);
186 csnmp_host_close_session(hd);
190 sfree(hd->community);
192 sfree(hd->auth_passphrase);
193 sfree(hd->priv_passphrase);
195 sfree(hd->data_list);
198 } /* }}} void csnmp_host_definition_destroy */
200 /* Many functions to handle the configuration. {{{ */
201 /* First there are many functions which do configuration stuff. It's a big
202 * bloated and messy, I'm afraid. */
205 * Callgraph for the config stuff:
207 * +-> call_snmp_init_once
208 * +-> csnmp_config_add_data
209 * ! +-> csnmp_config_add_data_instance
210 * ! +-> csnmp_config_add_data_instance_prefix
211 * ! +-> csnmp_config_add_data_values
212 * +-> csnmp_config_add_host
213 * +-> csnmp_config_add_host_version
214 * +-> csnmp_config_add_host_collect
215 * +-> csnmp_config_add_host_auth_protocol
216 * +-> csnmp_config_add_host_priv_protocol
217 * +-> csnmp_config_add_host_security_level
219 static void call_snmp_init_once(void) {
220 static int have_init = 0;
223 init_snmp(PACKAGE_NAME);
225 } /* void call_snmp_init_once */
227 static int csnmp_config_add_data_instance(data_definition_t *dd,
228 oconfig_item_t *ci) {
229 char buffer[DATA_MAX_NAME_LEN];
232 status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
237 /* Instance is an OID */
238 dd->instance.oid.oid_len = MAX_OID_LEN;
240 if (!read_objid(buffer, dd->instance.oid.oid, &dd->instance.oid.oid_len)) {
241 ERROR("snmp plugin: read_objid (%s) failed.", buffer);
245 /* Instance is a simple string */
246 sstrncpy(dd->instance.string, buffer, sizeof(dd->instance.string));
250 } /* int csnmp_config_add_data_instance */
252 static int csnmp_config_add_data_instance_prefix(data_definition_t *dd,
253 oconfig_item_t *ci) {
257 WARNING("snmp plugin: data %s: InstancePrefix is ignored when `Table' "
258 "is set to `false'.",
263 status = cf_util_get_string(ci, &dd->instance_prefix);
265 } /* int csnmp_config_add_data_instance_prefix */
267 static int csnmp_config_add_data_values(data_definition_t *dd,
268 oconfig_item_t *ci) {
269 if (ci->values_num < 1) {
270 WARNING("snmp plugin: `Values' needs at least one argument.");
274 for (int i = 0; i < ci->values_num; i++)
275 if (ci->values[i].type != OCONFIG_TYPE_STRING) {
276 WARNING("snmp plugin: `Values' needs only string argument.");
282 dd->values = malloc(sizeof(*dd->values) * ci->values_num);
283 if (dd->values == NULL)
285 dd->values_len = (size_t)ci->values_num;
287 for (int i = 0; i < ci->values_num; i++) {
288 dd->values[i].oid_len = MAX_OID_LEN;
290 if (NULL == snmp_parse_oid(ci->values[i].value.string, dd->values[i].oid,
291 &dd->values[i].oid_len)) {
292 ERROR("snmp plugin: snmp_parse_oid (%s) failed.",
293 ci->values[i].value.string);
302 } /* int csnmp_config_add_data_instance */
304 static int csnmp_config_add_data_blacklist(data_definition_t *dd,
305 oconfig_item_t *ci) {
306 if (ci->values_num < 1)
309 for (int i = 0; i < ci->values_num; i++) {
310 if (ci->values[i].type != OCONFIG_TYPE_STRING) {
311 WARNING("snmp plugin: `Ignore' needs only string argument.");
319 for (int i = 0; i < ci->values_num; ++i) {
320 if (strarray_add(&(dd->ignores), &(dd->ignores_len),
321 ci->values[i].value.string) != 0) {
322 ERROR("snmp plugin: Can't allocate memory");
323 strarray_free(dd->ignores, dd->ignores_len);
328 } /* int csnmp_config_add_data_blacklist */
330 static int csnmp_config_add_data_blacklist_match_inverted(data_definition_t *dd,
331 oconfig_item_t *ci) {
332 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
333 WARNING("snmp plugin: `InvertMatch' needs exactly one boolean argument.");
337 dd->invert_match = ci->values[0].value.boolean ? 1 : 0;
340 } /* int csnmp_config_add_data_blacklist_match_inverted */
342 static int csnmp_config_add_data(oconfig_item_t *ci) {
343 data_definition_t *dd;
346 dd = calloc(1, sizeof(*dd));
350 status = cf_util_get_string(ci, &dd->name);
359 for (int i = 0; i < ci->children_num; i++) {
360 oconfig_item_t *option = ci->children + i;
362 if (strcasecmp("Type", option->key) == 0)
363 status = cf_util_get_string(option, &dd->type);
364 else if (strcasecmp("Table", option->key) == 0)
365 status = cf_util_get_boolean(option, &dd->is_table);
366 else if (strcasecmp("Instance", option->key) == 0)
367 status = csnmp_config_add_data_instance(dd, option);
368 else if (strcasecmp("InstancePrefix", option->key) == 0)
369 status = csnmp_config_add_data_instance_prefix(dd, option);
370 else if (strcasecmp("Values", option->key) == 0)
371 status = csnmp_config_add_data_values(dd, option);
372 else if (strcasecmp("Shift", option->key) == 0)
373 status = cf_util_get_double(option, &dd->shift);
374 else if (strcasecmp("Scale", option->key) == 0)
375 status = cf_util_get_double(option, &dd->scale);
376 else if (strcasecmp("Ignore", option->key) == 0)
377 status = csnmp_config_add_data_blacklist(dd, option);
378 else if (strcasecmp("InvertMatch", option->key) == 0)
379 status = csnmp_config_add_data_blacklist_match_inverted(dd, option);
381 WARNING("snmp plugin: Option `%s' not allowed here.", option->key);
387 } /* for (ci->children) */
389 while (status == 0) {
390 if (dd->type == NULL) {
391 WARNING("snmp plugin: `Type' not given for data `%s'", dd->name);
395 if (dd->values == NULL) {
396 WARNING("snmp plugin: No `Value' given for data `%s'", dd->name);
402 } /* while (status == 0) */
406 sfree(dd->instance_prefix);
413 DEBUG("snmp plugin: dd = { name = %s, type = %s, is_table = %s, values_len = "
415 dd->name, dd->type, (dd->is_table != 0) ? "true" : "false",
418 if (data_head == NULL)
421 data_definition_t *last;
423 while (last->next != NULL)
429 } /* int csnmp_config_add_data */
431 static int csnmp_config_add_host_version(host_definition_t *hd,
432 oconfig_item_t *ci) {
435 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
436 WARNING("snmp plugin: The `Version' config option needs exactly one number "
441 version = (int)ci->values[0].value.number;
442 if ((version < 1) || (version > 3)) {
443 WARNING("snmp plugin: `Version' must either be `1', `2', or `3'.");
447 hd->version = version;
450 } /* int csnmp_config_add_host_address */
452 static int csnmp_config_add_host_collect(host_definition_t *host,
453 oconfig_item_t *ci) {
454 data_definition_t *data;
455 data_definition_t **data_list;
458 if (ci->values_num < 1) {
459 WARNING("snmp plugin: `Collect' needs at least one argument.");
463 for (int i = 0; i < ci->values_num; i++)
464 if (ci->values[i].type != OCONFIG_TYPE_STRING) {
465 WARNING("snmp plugin: All arguments to `Collect' must be strings.");
469 data_list_len = host->data_list_len + ci->values_num;
471 realloc(host->data_list, sizeof(data_definition_t *) * data_list_len);
472 if (data_list == NULL)
474 host->data_list = data_list;
476 for (int i = 0; i < ci->values_num; i++) {
477 for (data = data_head; data != NULL; data = data->next)
478 if (strcasecmp(ci->values[i].value.string, data->name) == 0)
482 WARNING("snmp plugin: No such data configured: `%s'",
483 ci->values[i].value.string);
487 DEBUG("snmp plugin: Collect: host = %s, data[%i] = %s;", host->name,
488 host->data_list_len, data->name);
490 host->data_list[host->data_list_len] = data;
491 host->data_list_len++;
492 } /* for (values_num) */
495 } /* int csnmp_config_add_host_collect */
497 static int csnmp_config_add_host_auth_protocol(host_definition_t *hd,
498 oconfig_item_t *ci) {
502 status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
506 if (strcasecmp("MD5", buffer) == 0) {
507 hd->auth_protocol = usmHMACMD5AuthProtocol;
508 hd->auth_protocol_len = sizeof(usmHMACMD5AuthProtocol) / sizeof(oid);
509 } else if (strcasecmp("SHA", buffer) == 0) {
510 hd->auth_protocol = usmHMACSHA1AuthProtocol;
511 hd->auth_protocol_len = sizeof(usmHMACSHA1AuthProtocol) / sizeof(oid);
513 WARNING("snmp plugin: The `AuthProtocol' config option must be `MD5' or "
518 DEBUG("snmp plugin: host = %s; host->auth_protocol = %s;", hd->name,
519 hd->auth_protocol == usmHMACMD5AuthProtocol ? "MD5" : "SHA");
522 } /* int csnmp_config_add_host_auth_protocol */
524 static int csnmp_config_add_host_priv_protocol(host_definition_t *hd,
525 oconfig_item_t *ci) {
529 status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
533 if (strcasecmp("AES", buffer) == 0) {
534 hd->priv_protocol = usmAESPrivProtocol;
535 hd->priv_protocol_len = sizeof(usmAESPrivProtocol) / sizeof(oid);
536 } else if (strcasecmp("DES", buffer) == 0) {
537 hd->priv_protocol = usmDESPrivProtocol;
538 hd->priv_protocol_len = sizeof(usmDESPrivProtocol) / sizeof(oid);
540 WARNING("snmp plugin: The `PrivProtocol' config option must be `AES' or "
545 DEBUG("snmp plugin: host = %s; host->priv_protocol = %s;", hd->name,
546 hd->priv_protocol == usmAESPrivProtocol ? "AES" : "DES");
549 } /* int csnmp_config_add_host_priv_protocol */
551 static int csnmp_config_add_host_security_level(host_definition_t *hd,
552 oconfig_item_t *ci) {
556 status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
560 if (strcasecmp("noAuthNoPriv", buffer) == 0)
561 hd->security_level = SNMP_SEC_LEVEL_NOAUTH;
562 else if (strcasecmp("authNoPriv", buffer) == 0)
563 hd->security_level = SNMP_SEC_LEVEL_AUTHNOPRIV;
564 else if (strcasecmp("authPriv", buffer) == 0)
565 hd->security_level = SNMP_SEC_LEVEL_AUTHPRIV;
567 WARNING("snmp plugin: The `SecurityLevel' config option must be "
568 "`noAuthNoPriv', `authNoPriv', or `authPriv'.");
572 DEBUG("snmp plugin: host = %s; host->security_level = %d;", hd->name,
576 } /* int csnmp_config_add_host_security_level */
578 static int csnmp_config_add_host(oconfig_item_t *ci) {
579 host_definition_t *hd;
582 /* Registration stuff. */
583 char cb_name[DATA_MAX_NAME_LEN];
585 hd = calloc(1, sizeof(*hd));
589 C_COMPLAIN_INIT(&hd->complaint);
591 status = cf_util_get_string(ci, &hd->name);
597 hd->sess_handle = NULL;
600 for (int i = 0; i < ci->children_num; i++) {
601 oconfig_item_t *option = ci->children + i;
604 if (strcasecmp("Address", option->key) == 0)
605 status = cf_util_get_string(option, &hd->address);
606 else if (strcasecmp("Community", option->key) == 0)
607 status = cf_util_get_string(option, &hd->community);
608 else if (strcasecmp("Version", option->key) == 0)
609 status = csnmp_config_add_host_version(hd, option);
610 else if (strcasecmp("Collect", option->key) == 0)
611 csnmp_config_add_host_collect(hd, option);
612 else if (strcasecmp("Interval", option->key) == 0)
613 cf_util_get_cdtime(option, &hd->interval);
614 else if (strcasecmp("Username", option->key) == 0)
615 status = cf_util_get_string(option, &hd->username);
616 else if (strcasecmp("AuthProtocol", option->key) == 0)
617 status = csnmp_config_add_host_auth_protocol(hd, option);
618 else if (strcasecmp("PrivacyProtocol", option->key) == 0)
619 status = csnmp_config_add_host_priv_protocol(hd, option);
620 else if (strcasecmp("AuthPassphrase", option->key) == 0)
621 status = cf_util_get_string(option, &hd->auth_passphrase);
622 else if (strcasecmp("PrivacyPassphrase", option->key) == 0)
623 status = cf_util_get_string(option, &hd->priv_passphrase);
624 else if (strcasecmp("SecurityLevel", option->key) == 0)
625 status = csnmp_config_add_host_security_level(hd, option);
626 else if (strcasecmp("Context", option->key) == 0)
627 status = cf_util_get_string(option, &hd->context);
630 "snmp plugin: csnmp_config_add_host: Option `%s' not allowed here.",
637 } /* for (ci->children) */
639 while (status == 0) {
640 if (hd->address == NULL) {
641 WARNING("snmp plugin: `Address' not given for host `%s'", hd->name);
645 if (hd->community == NULL && hd->version < 3) {
646 WARNING("snmp plugin: `Community' not given for host `%s'", hd->name);
650 if (hd->version == 3) {
651 if (hd->username == NULL) {
652 WARNING("snmp plugin: `Username' not given for host `%s'", hd->name);
656 if (hd->security_level == 0) {
657 WARNING("snmp plugin: `SecurityLevel' not given for host `%s'",
662 if (hd->security_level == SNMP_SEC_LEVEL_AUTHNOPRIV ||
663 hd->security_level == SNMP_SEC_LEVEL_AUTHPRIV) {
664 if (hd->auth_protocol == NULL) {
665 WARNING("snmp plugin: `AuthProtocol' not given for host `%s'",
670 if (hd->auth_passphrase == NULL) {
671 WARNING("snmp plugin: `AuthPassphrase' not given for host `%s'",
677 if (hd->security_level == SNMP_SEC_LEVEL_AUTHPRIV) {
678 if (hd->priv_protocol == NULL) {
679 WARNING("snmp plugin: `PrivacyProtocol' not given for host `%s'",
684 if (hd->priv_passphrase == NULL) {
685 WARNING("snmp plugin: `PrivacyPassphrase' not given for host `%s'",
694 } /* while (status == 0) */
697 csnmp_host_definition_destroy(hd);
701 DEBUG("snmp plugin: hd = { name = %s, address = %s, community = %s, version "
703 hd->name, hd->address, hd->community, hd->version);
705 snprintf(cb_name, sizeof(cb_name), "snmp-%s", hd->name);
707 status = plugin_register_complex_read(
708 /* group = */ NULL, cb_name, csnmp_read_host, hd->interval,
710 .data = hd, .free_func = csnmp_host_definition_destroy,
713 ERROR("snmp plugin: Registering complex read function failed.");
718 } /* int csnmp_config_add_host */
720 static int csnmp_config(oconfig_item_t *ci) {
721 call_snmp_init_once();
723 for (int i = 0; i < ci->children_num; i++) {
724 oconfig_item_t *child = ci->children + i;
725 if (strcasecmp("Data", child->key) == 0)
726 csnmp_config_add_data(child);
727 else if (strcasecmp("Host", child->key) == 0)
728 csnmp_config_add_host(child);
730 WARNING("snmp plugin: Ignoring unknown config option `%s'.", child->key);
732 } /* for (ci->children) */
735 } /* int csnmp_config */
737 /* }}} End of the config stuff. Now the interesting part begins */
739 static void csnmp_host_open_session(host_definition_t *host) {
740 struct snmp_session sess;
743 if (host->sess_handle != NULL)
744 csnmp_host_close_session(host);
746 snmp_sess_init(&sess);
747 sess.peername = host->address;
748 switch (host->version) {
750 sess.version = SNMP_VERSION_1;
753 sess.version = SNMP_VERSION_3;
756 sess.version = SNMP_VERSION_2c;
760 if (host->version == 3) {
761 sess.securityName = host->username;
762 sess.securityNameLen = strlen(host->username);
763 sess.securityLevel = host->security_level;
765 if (sess.securityLevel == SNMP_SEC_LEVEL_AUTHNOPRIV ||
766 sess.securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) {
767 sess.securityAuthProto = host->auth_protocol;
768 sess.securityAuthProtoLen = host->auth_protocol_len;
769 sess.securityAuthKeyLen = USM_AUTH_KU_LEN;
770 error = generate_Ku(sess.securityAuthProto, sess.securityAuthProtoLen,
771 (u_char *)host->auth_passphrase,
772 strlen(host->auth_passphrase), sess.securityAuthKey,
773 &sess.securityAuthKeyLen);
774 if (error != SNMPERR_SUCCESS) {
775 ERROR("snmp plugin: host %s: Error generating Ku from auth_passphrase. "
781 if (sess.securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) {
782 sess.securityPrivProto = host->priv_protocol;
783 sess.securityPrivProtoLen = host->priv_protocol_len;
784 sess.securityPrivKeyLen = USM_PRIV_KU_LEN;
785 error = generate_Ku(sess.securityAuthProto, sess.securityAuthProtoLen,
786 (u_char *)host->priv_passphrase,
787 strlen(host->priv_passphrase), sess.securityPrivKey,
788 &sess.securityPrivKeyLen);
789 if (error != SNMPERR_SUCCESS) {
790 ERROR("snmp plugin: host %s: Error generating Ku from priv_passphrase. "
796 if (host->context != NULL) {
797 sess.contextName = host->context;
798 sess.contextNameLen = strlen(host->context);
800 } else /* SNMPv1/2 "authenticates" with community string */
802 sess.community = (u_char *)host->community;
803 sess.community_len = strlen(host->community);
806 /* snmp_sess_open will copy the `struct snmp_session *'. */
807 host->sess_handle = snmp_sess_open(&sess);
809 if (host->sess_handle == NULL) {
812 snmp_error(&sess, NULL, NULL, &errstr);
814 ERROR("snmp plugin: host %s: snmp_sess_open failed: %s", host->name,
815 (errstr == NULL) ? "Unknown problem" : errstr);
818 } /* void csnmp_host_open_session */
820 /* TODO: Check if negative values wrap around. Problem: negative temperatures.
822 static value_t csnmp_value_list_to_value(struct variable_list *vl, int type,
823 double scale, double shift,
824 const char *host_name,
825 const char *data_name) {
827 uint64_t tmp_unsigned = 0;
828 int64_t tmp_signed = 0;
830 /* Set to true when the original SNMP type appears to have been signed. */
831 _Bool prefer_signed = 0;
833 if ((vl->type == ASN_INTEGER) || (vl->type == ASN_UINTEGER) ||
834 (vl->type == ASN_COUNTER)
836 || (vl->type == ASN_TIMETICKS)
838 || (vl->type == ASN_GAUGE)) {
839 tmp_unsigned = (uint32_t)*vl->val.integer;
840 tmp_signed = (int32_t)*vl->val.integer;
842 if (vl->type == ASN_INTEGER)
845 DEBUG("snmp plugin: Parsed int32 value is %" PRIu64 ".", tmp_unsigned);
846 } else if (vl->type == ASN_COUNTER64) {
847 tmp_unsigned = (uint32_t)vl->val.counter64->high;
848 tmp_unsigned = tmp_unsigned << 32;
849 tmp_unsigned += (uint32_t)vl->val.counter64->low;
850 tmp_signed = (int64_t)tmp_unsigned;
851 DEBUG("snmp plugin: Parsed int64 value is %" PRIu64 ".", tmp_unsigned);
852 } else if (vl->type == ASN_OCTET_STR) {
853 /* We'll handle this later.. */
855 char oid_buffer[1024] = {0};
857 snprint_objid(oid_buffer, sizeof(oid_buffer) - 1, vl->name,
861 if (vl->type == ASN_NULL)
862 INFO("snmp plugin: OID \"%s\" is undefined (type ASN_NULL)", oid_buffer);
865 WARNING("snmp plugin: I don't know the ASN type #%i "
866 "(OID: \"%s\", data block \"%s\", host block \"%s\")",
867 (int)vl->type, oid_buffer,
868 (data_name != NULL) ? data_name : "UNKNOWN",
869 (host_name != NULL) ? host_name : "UNKNOWN");
874 if (vl->type == ASN_OCTET_STR) {
877 if (vl->val.string != NULL) {
879 size_t string_length;
881 string_length = sizeof(string) - 1;
882 if (vl->val_len < string_length)
883 string_length = vl->val_len;
885 /* The strings we get from the Net-SNMP library may not be null
886 * terminated. That is why we're using `memcpy' here and not `strcpy'.
887 * `string_length' is set to `vl->val_len' which holds the length of the
889 memcpy(string, vl->val.string, string_length);
890 string[string_length] = 0;
892 status = parse_value(string, &ret, type);
894 ERROR("snmp plugin: host %s: csnmp_value_list_to_value: Parsing string "
896 (host_name != NULL) ? host_name : "UNKNOWN",
897 DS_TYPE_TO_STRING(type), string);
903 case DS_TYPE_COUNTER:
905 case DS_TYPE_ABSOLUTE:
906 memset(&ret, 0, sizeof(ret));
914 ERROR("snmp plugin: csnmp_value_list_to_value: Unknown "
915 "data source type: %i.",
920 } /* if (vl->type == ASN_OCTET_STR) */
921 else if (type == DS_TYPE_COUNTER) {
922 ret.counter = tmp_unsigned;
923 } else if (type == DS_TYPE_GAUGE) {
926 else if (prefer_signed)
927 ret.gauge = (scale * tmp_signed) + shift;
929 ret.gauge = (scale * tmp_unsigned) + shift;
930 } else if (type == DS_TYPE_DERIVE) {
932 ret.derive = (derive_t)tmp_signed;
934 ret.derive = (derive_t)tmp_unsigned;
935 } else if (type == DS_TYPE_ABSOLUTE) {
936 ret.absolute = (absolute_t)tmp_unsigned;
938 ERROR("snmp plugin: csnmp_value_list_to_value: Unknown data source "
945 } /* value_t csnmp_value_list_to_value */
947 /* csnmp_strvbcopy_hexstring converts the bit string contained in "vb" to a hex
948 * representation and writes it to dst. Returns zero on success and ENOMEM if
949 * dst is not large enough to hold the string. dst is guaranteed to be
951 static int csnmp_strvbcopy_hexstring(char *dst, /* {{{ */
952 const struct variable_list *vb,
960 buffer_free = dst_size;
962 for (size_t i = 0; i < vb->val_len; i++) {
965 status = snprintf(buffer_ptr, buffer_free, (i == 0) ? "%02x" : ":%02x",
966 (unsigned int)vb->val.bitstring[i]);
969 if (((size_t)status) >= buffer_free) /* truncated */
971 dst[dst_size - 1] = 0;
973 } else /* if (status < buffer_free) */
975 buffer_ptr += (size_t)status;
976 buffer_free -= (size_t)status;
981 } /* }}} int csnmp_strvbcopy_hexstring */
983 /* csnmp_strvbcopy copies the octet string or bit string contained in vb to
984 * dst. If non-printable characters are detected, it will switch to a hex
985 * representation of the string. Returns zero on success, EINVAL if vb does not
986 * contain a string and ENOMEM if dst is not large enough to contain the
988 static int csnmp_strvbcopy(char *dst, /* {{{ */
989 const struct variable_list *vb, size_t dst_size) {
993 if (vb->type == ASN_OCTET_STR)
994 src = (char *)vb->val.string;
995 else if (vb->type == ASN_BIT_STR)
996 src = (char *)vb->val.bitstring;
997 else if (vb->type == ASN_IPADDRESS) {
998 return snprintf(dst, dst_size,
999 "%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 "",
1000 (uint8_t)vb->val.string[0], (uint8_t)vb->val.string[1],
1001 (uint8_t)vb->val.string[2], (uint8_t)vb->val.string[3]);
1007 num_chars = dst_size - 1;
1008 if (num_chars > vb->val_len)
1009 num_chars = vb->val_len;
1011 for (size_t i = 0; i < num_chars; i++) {
1012 /* Check for control characters. */
1013 if ((unsigned char)src[i] < 32)
1014 return csnmp_strvbcopy_hexstring(dst, vb, dst_size);
1018 dst[dst_size - 1] = 0;
1020 if (dst_size <= vb->val_len)
1024 } /* }}} int csnmp_strvbcopy */
1026 static int csnmp_instance_list_add(csnmp_list_instances_t **head,
1027 csnmp_list_instances_t **tail,
1028 const struct snmp_pdu *res,
1029 const host_definition_t *hd,
1030 const data_definition_t *dd) {
1031 csnmp_list_instances_t *il;
1032 struct variable_list *vb;
1035 uint32_t is_matched;
1037 /* Set vb on the last variable */
1038 for (vb = res->variables; (vb != NULL) && (vb->next_variable != NULL);
1039 vb = vb->next_variable)
1044 csnmp_oid_init(&vb_name, vb->name, vb->name_length);
1046 il = calloc(1, sizeof(*il));
1048 ERROR("snmp plugin: calloc failed.");
1053 status = csnmp_oid_suffix(&il->suffix, &vb_name, &dd->instance.oid);
1059 /* Get instance name */
1060 if ((vb->type == ASN_OCTET_STR) || (vb->type == ASN_BIT_STR) ||
1061 (vb->type == ASN_IPADDRESS)) {
1064 csnmp_strvbcopy(il->instance, vb, sizeof(il->instance));
1066 for (uint32_t i = 0; i < dd->ignores_len; i++) {
1067 status = fnmatch(dd->ignores[i], il->instance, 0);
1069 if (dd->invert_match == 0) {
1078 if (dd->invert_match != 0 && is_matched == 0) {
1082 for (ptr = il->instance; *ptr != '\0'; ptr++) {
1083 if ((*ptr > 0) && (*ptr < 32))
1085 else if (*ptr == '/')
1088 DEBUG("snmp plugin: il->instance = `%s';", il->instance);
1090 value_t val = csnmp_value_list_to_value(
1091 vb, DS_TYPE_COUNTER,
1092 /* scale = */ 1.0, /* shift = */ 0.0, hd->name, dd->name);
1093 snprintf(il->instance, sizeof(il->instance), "%llu", val.counter);
1096 /* TODO: Debugging output */
1105 } /* int csnmp_instance_list_add */
1107 static int csnmp_dispatch_table(host_definition_t *host,
1108 data_definition_t *data,
1109 csnmp_list_instances_t *instance_list,
1110 csnmp_table_values_t **value_table) {
1111 const data_set_t *ds;
1112 value_list_t vl = VALUE_LIST_INIT;
1114 csnmp_list_instances_t *instance_list_ptr;
1115 csnmp_table_values_t *value_table_ptr[data->values_len];
1119 oid_t current_suffix;
1121 ds = plugin_get_ds(data->type);
1123 ERROR("snmp plugin: DataSet `%s' not defined.", data->type);
1126 assert(ds->ds_num == data->values_len);
1127 assert(data->values_len > 0);
1129 instance_list_ptr = instance_list;
1131 for (i = 0; i < data->values_len; i++)
1132 value_table_ptr[i] = value_table[i];
1134 sstrncpy(vl.host, host->name, sizeof(vl.host));
1135 sstrncpy(vl.plugin, "snmp", sizeof(vl.plugin));
1137 vl.interval = host->interval;
1141 _Bool suffix_skipped = 0;
1143 /* Determine next suffix to handle. */
1144 if (instance_list != NULL) {
1145 if (instance_list_ptr == NULL) {
1150 memcpy(¤t_suffix, &instance_list_ptr->suffix,
1151 sizeof(current_suffix));
1153 /* no instance configured */
1154 csnmp_table_values_t *ptr = value_table_ptr[0];
1160 memcpy(¤t_suffix, &ptr->suffix, sizeof(current_suffix));
1163 /* Update all the value_table_ptr to point at the entry with the same
1164 * trailing partial OID */
1165 for (i = 0; i < data->values_len; i++) {
1167 (value_table_ptr[i] != NULL) &&
1168 (csnmp_oid_compare(&value_table_ptr[i]->suffix, ¤t_suffix) < 0))
1169 value_table_ptr[i] = value_table_ptr[i]->next;
1171 if (value_table_ptr[i] == NULL) {
1174 } else if (csnmp_oid_compare(&value_table_ptr[i]->suffix,
1175 ¤t_suffix) > 0) {
1176 /* This suffix is missing in the subtree. Indicate this with the
1177 * "suffix_skipped" flag and try the next instance / suffix. */
1181 } /* for (i = 0; i < columns; i++) */
1186 /* Matching the values failed. Start from the beginning again. */
1187 if (suffix_skipped) {
1188 if (instance_list != NULL)
1189 instance_list_ptr = instance_list_ptr->next;
1191 value_table_ptr[0] = value_table_ptr[0]->next;
1196 /* if we reach this line, all value_table_ptr[i] are non-NULL and are set
1197 * to the same subid. instance_list_ptr is either NULL or points to the
1198 * same subid, too. */
1200 for (i = 1; i < data->values_len; i++) {
1201 assert(value_table_ptr[i] != NULL);
1202 assert(csnmp_oid_compare(&value_table_ptr[i - 1]->suffix,
1203 &value_table_ptr[i]->suffix) == 0);
1205 assert((instance_list_ptr == NULL) ||
1206 (csnmp_oid_compare(&instance_list_ptr->suffix,
1207 &value_table_ptr[0]->suffix) == 0));
1210 sstrncpy(vl.type, data->type, sizeof(vl.type));
1213 char temp[DATA_MAX_NAME_LEN];
1215 if (instance_list_ptr == NULL)
1216 csnmp_oid_to_string(temp, sizeof(temp), ¤t_suffix);
1218 sstrncpy(temp, instance_list_ptr->instance, sizeof(temp));
1220 if (data->instance_prefix == NULL)
1221 sstrncpy(vl.type_instance, temp, sizeof(vl.type_instance));
1223 snprintf(vl.type_instance, sizeof(vl.type_instance), "%s%s",
1224 data->instance_prefix, temp);
1227 vl.values_len = data->values_len;
1228 value_t values[vl.values_len];
1231 for (i = 0; i < data->values_len; i++)
1232 vl.values[i] = value_table_ptr[i]->value;
1234 /* If we get here `vl.type_instance' and all `vl.values' have been set
1235 * vl.type_instance can be empty, i.e. a blank port description on a
1236 * switch if you're using IF-MIB::ifDescr as Instance.
1238 if (vl.type_instance[0] != '\0')
1239 plugin_dispatch_values(&vl);
1241 /* prevent leakage of pointer to local variable. */
1245 if (instance_list != NULL)
1246 instance_list_ptr = instance_list_ptr->next;
1248 value_table_ptr[0] = value_table_ptr[0]->next;
1249 } /* while (have_more) */
1252 } /* int csnmp_dispatch_table */
1254 static int csnmp_read_table(host_definition_t *host, data_definition_t *data) {
1255 struct snmp_pdu *req;
1256 struct snmp_pdu *res = NULL;
1257 struct variable_list *vb;
1259 const data_set_t *ds;
1261 size_t oid_list_len = data->values_len + 1;
1262 /* Holds the last OID returned by the device. We use this in the GETNEXT
1263 * request to proceed. */
1264 oid_t oid_list[oid_list_len];
1265 /* Set to false when an OID has left its subtree so we don't re-request it
1267 _Bool oid_list_todo[oid_list_len];
1272 /* `value_list_head' and `value_list_tail' implement a linked list for each
1273 * value. `instance_list_head' and `instance_list_tail' implement a linked
1275 * instance names. This is used to jump gaps in the table. */
1276 csnmp_list_instances_t *instance_list_head;
1277 csnmp_list_instances_t *instance_list_tail;
1278 csnmp_table_values_t **value_list_head;
1279 csnmp_table_values_t **value_list_tail;
1281 DEBUG("snmp plugin: csnmp_read_table (host = %s, data = %s)", host->name,
1284 if (host->sess_handle == NULL) {
1285 DEBUG("snmp plugin: csnmp_read_table: host->sess_handle == NULL");
1289 ds = plugin_get_ds(data->type);
1291 ERROR("snmp plugin: DataSet `%s' not defined.", data->type);
1295 if (ds->ds_num != data->values_len) {
1296 ERROR("snmp plugin: DataSet `%s' requires %zu values, but config talks "
1298 data->type, ds->ds_num, data->values_len);
1301 assert(data->values_len > 0);
1303 /* We need a copy of all the OIDs, because GETNEXT will destroy them. */
1304 memcpy(oid_list, data->values, data->values_len * sizeof(oid_t));
1305 if (data->instance.oid.oid_len > 0)
1306 memcpy(oid_list + data->values_len, &data->instance.oid, sizeof(oid_t));
1307 else /* no InstanceFrom option specified. */
1310 for (i = 0; i < oid_list_len; i++)
1311 oid_list_todo[i] = 1;
1313 /* We're going to construct n linked lists, one for each "value".
1314 * value_list_head will contain pointers to the heads of these linked lists,
1315 * value_list_tail will contain pointers to the tail of the lists. */
1316 value_list_head = calloc(data->values_len, sizeof(*value_list_head));
1317 value_list_tail = calloc(data->values_len, sizeof(*value_list_tail));
1318 if ((value_list_head == NULL) || (value_list_tail == NULL)) {
1319 ERROR("snmp plugin: csnmp_read_table: calloc failed.");
1320 sfree(value_list_head);
1321 sfree(value_list_tail);
1325 instance_list_head = NULL;
1326 instance_list_tail = NULL;
1329 while (status == 0) {
1330 req = snmp_pdu_create(SNMP_MSG_GETNEXT);
1332 ERROR("snmp plugin: snmp_pdu_create failed.");
1337 size_t oid_list_todo_num = 0;
1338 size_t var_idx[oid_list_len];
1339 memset(var_idx, 0, sizeof(var_idx));
1341 for (i = 0; i < oid_list_len; i++) {
1342 /* Do not rerequest already finished OIDs */
1343 if (!oid_list_todo[i])
1345 snmp_add_null_var(req, oid_list[i].oid, oid_list[i].oid_len);
1346 var_idx[oid_list_todo_num] = i;
1347 oid_list_todo_num++;
1350 if (oid_list_todo_num == 0) {
1351 /* The request is still empty - so we are finished */
1352 DEBUG("snmp plugin: all variables have left their subtree");
1359 status = snmp_sess_synch_response(host->sess_handle, req, &res);
1361 /* snmp_sess_synch_response always frees our req PDU */
1364 if ((status != STAT_SUCCESS) || (res == NULL)) {
1365 char *errstr = NULL;
1367 snmp_sess_error(host->sess_handle, NULL, NULL, &errstr);
1369 c_complain(LOG_ERR, &host->complaint,
1370 "snmp plugin: host %s: snmp_sess_synch_response failed: %s",
1371 host->name, (errstr == NULL) ? "Unknown problem" : errstr);
1378 csnmp_host_close_session(host);
1385 assert(res != NULL);
1386 c_release(LOG_INFO, &host->complaint,
1387 "snmp plugin: host %s: snmp_sess_synch_response successful.",
1390 vb = res->variables;
1396 if (res->errstat != SNMP_ERR_NOERROR) {
1397 if (res->errindex != 0) {
1398 /* Find the OID which caused error */
1399 for (i = 1, vb = res->variables; vb != NULL && i != res->errindex;
1400 vb = vb->next_variable, i++)
1404 if ((res->errindex == 0) || (vb == NULL)) {
1405 ERROR("snmp plugin: host %s; data %s: response error: %s (%li) ",
1406 host->name, data->name, snmp_errstring(res->errstat),
1412 char oid_buffer[1024] = {0};
1413 snprint_objid(oid_buffer, sizeof(oid_buffer) - 1, vb->name,
1415 NOTICE("snmp plugin: host %s; data %s: OID `%s` failed: %s", host->name,
1416 data->name, oid_buffer, snmp_errstring(res->errstat));
1418 /* Get value index from todo list and skip OID found */
1419 assert(res->errindex <= oid_list_todo_num);
1420 i = var_idx[res->errindex - 1];
1421 assert(i < oid_list_len);
1422 oid_list_todo[i] = 0;
1429 for (vb = res->variables, i = 0; (vb != NULL);
1430 vb = vb->next_variable, i++) {
1431 /* Calculate value index from todo list */
1432 while ((i < oid_list_len) && !oid_list_todo[i])
1435 /* An instance is configured and the res variable we process is the
1436 * instance value (last index) */
1437 if ((data->instance.oid.oid_len > 0) && (i == data->values_len)) {
1438 if ((vb->type == SNMP_ENDOFMIBVIEW) ||
1440 data->instance.oid.oid, data->instance.oid.oid_len, vb->name,
1441 vb->name_length, data->instance.oid.oid_len) != 0)) {
1442 DEBUG("snmp plugin: host = %s; data = %s; Instance left its subtree.",
1443 host->name, data->name);
1444 oid_list_todo[i] = 0;
1448 /* Allocate a new `csnmp_list_instances_t', insert the instance name and
1449 * add it to the list */
1450 if (csnmp_instance_list_add(&instance_list_head, &instance_list_tail,
1451 res, host, data) != 0) {
1452 ERROR("snmp plugin: host %s: csnmp_instance_list_add failed.",
1457 } else /* The variable we are processing is a normal value */
1459 csnmp_table_values_t *vt;
1464 csnmp_oid_init(&vb_name, vb->name, vb->name_length);
1466 /* Calculate the current suffix. This is later used to check that the
1467 * suffix is increasing. This also checks if we left the subtree */
1468 ret = csnmp_oid_suffix(&suffix, &vb_name, data->values + i);
1470 DEBUG("snmp plugin: host = %s; data = %s; i = %zu; "
1471 "Value probably left its subtree.",
1472 host->name, data->name, i);
1473 oid_list_todo[i] = 0;
1477 /* Make sure the OIDs returned by the agent are increasing. Otherwise
1479 * table matching algorithm will get confused. */
1480 if ((value_list_tail[i] != NULL) &&
1481 (csnmp_oid_compare(&suffix, &value_list_tail[i]->suffix) <= 0)) {
1482 DEBUG("snmp plugin: host = %s; data = %s; i = %zu; "
1483 "Suffix is not increasing.",
1484 host->name, data->name, i);
1485 oid_list_todo[i] = 0;
1489 vt = calloc(1, sizeof(*vt));
1491 ERROR("snmp plugin: calloc failed.");
1497 csnmp_value_list_to_value(vb, ds->ds[i].type, data->scale,
1498 data->shift, host->name, data->name);
1499 memcpy(&vt->suffix, &suffix, sizeof(vt->suffix));
1502 if (value_list_tail[i] == NULL)
1503 value_list_head[i] = vt;
1505 value_list_tail[i]->next = vt;
1506 value_list_tail[i] = vt;
1509 /* Copy OID to oid_list[i] */
1510 memcpy(oid_list[i].oid, vb->name, sizeof(oid) * vb->name_length);
1511 oid_list[i].oid_len = vb->name_length;
1513 } /* for (vb = res->variables ...) */
1518 } /* while (status == 0) */
1526 csnmp_dispatch_table(host, data, instance_list_head, value_list_head);
1528 /* Free all allocated variables here */
1529 while (instance_list_head != NULL) {
1530 csnmp_list_instances_t *next = instance_list_head->next;
1531 sfree(instance_list_head);
1532 instance_list_head = next;
1535 for (i = 0; i < data->values_len; i++) {
1536 while (value_list_head[i] != NULL) {
1537 csnmp_table_values_t *next = value_list_head[i]->next;
1538 sfree(value_list_head[i]);
1539 value_list_head[i] = next;
1543 sfree(value_list_head);
1544 sfree(value_list_tail);
1547 } /* int csnmp_read_table */
1549 static int csnmp_read_value(host_definition_t *host, data_definition_t *data) {
1550 struct snmp_pdu *req;
1551 struct snmp_pdu *res = NULL;
1552 struct variable_list *vb;
1554 const data_set_t *ds;
1555 value_list_t vl = VALUE_LIST_INIT;
1560 DEBUG("snmp plugin: csnmp_read_value (host = %s, data = %s)", host->name,
1563 if (host->sess_handle == NULL) {
1564 DEBUG("snmp plugin: csnmp_read_value: host->sess_handle == NULL");
1568 ds = plugin_get_ds(data->type);
1570 ERROR("snmp plugin: DataSet `%s' not defined.", data->type);
1574 if (ds->ds_num != data->values_len) {
1575 ERROR("snmp plugin: DataSet `%s' requires %zu values, but config talks "
1577 data->type, ds->ds_num, data->values_len);
1581 vl.values_len = ds->ds_num;
1582 vl.values = malloc(sizeof(*vl.values) * vl.values_len);
1583 if (vl.values == NULL)
1585 for (i = 0; i < vl.values_len; i++) {
1586 if (ds->ds[i].type == DS_TYPE_COUNTER)
1587 vl.values[i].counter = 0;
1589 vl.values[i].gauge = NAN;
1592 sstrncpy(vl.host, host->name, sizeof(vl.host));
1593 sstrncpy(vl.plugin, "snmp", sizeof(vl.plugin));
1594 sstrncpy(vl.type, data->type, sizeof(vl.type));
1595 sstrncpy(vl.type_instance, data->instance.string, sizeof(vl.type_instance));
1597 vl.interval = host->interval;
1599 req = snmp_pdu_create(SNMP_MSG_GET);
1601 ERROR("snmp plugin: snmp_pdu_create failed.");
1606 for (i = 0; i < data->values_len; i++)
1607 snmp_add_null_var(req, data->values[i].oid, data->values[i].oid_len);
1609 status = snmp_sess_synch_response(host->sess_handle, req, &res);
1611 if ((status != STAT_SUCCESS) || (res == NULL)) {
1612 char *errstr = NULL;
1614 snmp_sess_error(host->sess_handle, NULL, NULL, &errstr);
1615 ERROR("snmp plugin: host %s: snmp_sess_synch_response failed: %s",
1616 host->name, (errstr == NULL) ? "Unknown problem" : errstr);
1623 csnmp_host_close_session(host);
1628 for (vb = res->variables; vb != NULL; vb = vb->next_variable) {
1631 snprint_variable(buffer, sizeof(buffer), vb->name, vb->name_length, vb);
1632 DEBUG("snmp plugin: Got this variable: %s", buffer);
1633 #endif /* COLLECT_DEBUG */
1635 for (i = 0; i < data->values_len; i++)
1636 if (snmp_oid_compare(data->values[i].oid, data->values[i].oid_len,
1637 vb->name, vb->name_length) == 0)
1639 csnmp_value_list_to_value(vb, ds->ds[i].type, data->scale,
1640 data->shift, host->name, data->name);
1641 } /* for (res->variables) */
1645 DEBUG("snmp plugin: -> plugin_dispatch_values (&vl);");
1646 plugin_dispatch_values(&vl);
1650 } /* int csnmp_read_value */
1652 static int csnmp_read_host(user_data_t *ud) {
1653 host_definition_t *host;
1660 if (host->interval == 0)
1661 host->interval = plugin_get_interval();
1663 if (host->sess_handle == NULL)
1664 csnmp_host_open_session(host);
1666 if (host->sess_handle == NULL)
1670 for (i = 0; i < host->data_list_len; i++) {
1671 data_definition_t *data = host->data_list[i];
1674 status = csnmp_read_table(host, data);
1676 status = csnmp_read_value(host, data);
1686 } /* int csnmp_read_host */
1688 static int csnmp_init(void) {
1689 call_snmp_init_once();
1692 } /* int csnmp_init */
1694 static int csnmp_shutdown(void) {
1695 data_definition_t *data_this;
1696 data_definition_t *data_next;
1698 /* When we get here, the read threads have been stopped and all the
1699 * `host_definition_t' will be freed. */
1700 DEBUG("snmp plugin: Destroying all data definitions.");
1702 data_this = data_head;
1704 while (data_this != NULL) {
1705 data_next = data_this->next;
1707 sfree(data_this->name);
1708 sfree(data_this->type);
1709 sfree(data_this->values);
1710 sfree(data_this->ignores);
1713 data_this = data_next;
1717 } /* int csnmp_shutdown */
1719 void module_register(void) {
1720 plugin_register_complex_config("snmp", csnmp_config);
1721 plugin_register_init("snmp", csnmp_init);
1722 plugin_register_shutdown("snmp", csnmp_shutdown);
1723 } /* void module_register */