X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsnmp.c;h=b8bbee44b05d86f4ce5503f8e7a5a3c0a3b29a62;hb=ab6ab6ad6428ba0a0987a20a7d1cfa47d6cc6f8b;hp=53d9d2d9ce238ce571a3d6fb423a34bf0d6baf6f;hpb=b4f54ca965c7895c46fa9211085025fb499b00e3;p=collectd.git diff --git a/src/snmp.c b/src/snmp.c index 53d9d2d9..b8bbee44 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -69,7 +69,7 @@ struct host_definition_s int version; void *sess_handle; c_complain_t complaint; - uint32_t interval; + cdtime_t interval; data_definition_t **data_list; int data_list_len; }; @@ -123,7 +123,7 @@ static int csnmp_oid_suffix (oid_t *dst, oid_t const *src, oid_t const *root) { /* Make sure "src" is in "root"s subtree. */ - if (src->oid_len >= root->oid_len) + if (src->oid_len <= root->oid_len) return (EINVAL); if (snmp_oid_ncompare (root->oid, root->oid_len, src->oid, src->oid_len, @@ -207,7 +207,6 @@ static void csnmp_host_definition_destroy (void *arg) /* {{{ */ * +-> csnmp_config_add_host_community * +-> csnmp_config_add_host_version * +-> csnmp_config_add_host_collect - * +-> csnmp_config_add_host_interval */ static void call_snmp_init_once (void) { @@ -591,22 +590,6 @@ static int csnmp_config_add_host_collect (host_definition_t *host, return (0); } /* int csnmp_config_add_host_collect */ -static int csnmp_config_add_host_interval (host_definition_t *hd, oconfig_item_t *ci) -{ - if ((ci->values_num != 1) - || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) - { - WARNING ("snmp plugin: The `Interval' config option needs exactly one number argument."); - return (-1); - } - - hd->interval = ci->values[0].value.number >= 0 - ? (uint32_t) ci->values[0].value.number - : 0; - - return (0); -} /* int csnmp_config_add_host_interval */ - static int csnmp_config_add_host (oconfig_item_t *ci) { host_definition_t *hd; @@ -655,7 +638,7 @@ static int csnmp_config_add_host (oconfig_item_t *ci) else if (strcasecmp ("Collect", option->key) == 0) csnmp_config_add_host_collect (hd, option); else if (strcasecmp ("Interval", option->key) == 0) - csnmp_config_add_host_interval (hd, option); + cf_util_get_cdtime (option, &hd->interval); else { WARNING ("snmp plugin: csnmp_config_add_host: Option `%s' not allowed here.", option->key); @@ -699,9 +682,7 @@ static int csnmp_config_add_host (oconfig_item_t *ci) cb_data.data = hd; cb_data.free_func = csnmp_host_definition_destroy; - memset (&cb_interval, 0, sizeof (cb_interval)); - if (hd->interval != 0) - cb_interval.tv_sec = (time_t) hd->interval; + CDTIME_T_TO_TIMESPEC (hd->interval, &cb_interval); status = plugin_register_complex_read (/* group = */ NULL, cb_name, csnmp_read_host, /* interval = */ &cb_interval, @@ -1050,6 +1031,7 @@ static int csnmp_instance_list_add (csnmp_list_instances_t **head, csnmp_list_instances_t *il; struct variable_list *vb; oid_t vb_name; + int status; /* Set vb on the last variable */ for (vb = res->variables; @@ -1067,9 +1049,16 @@ static int csnmp_instance_list_add (csnmp_list_instances_t **head, ERROR ("snmp plugin: malloc failed."); return (-1); } - csnmp_oid_suffix (&il->suffix, &vb_name, root); + memset (il, 0, sizeof (*il)); il->next = NULL; + status = csnmp_oid_suffix (&il->suffix, &vb_name, root); + if (status != 0) + { + sfree (il); + return (status); + } + /* Get instance name */ if ((vb->type == ASN_OCTET_STR) || (vb->type == ASN_BIT_STR)) { @@ -1435,16 +1424,17 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) { csnmp_table_values_t *vt; oid_t vb_name; + oid_t suffix; csnmp_oid_init (&vb_name, vb->name, vb->name_length); - /* Check if we left the subtree */ - if (snmp_oid_ncompare (data->values[i].oid, - data->values[i].oid_len, - vb->name, vb->name_length, - data->values[i].oid_len) != 0) + /* Calculate the current suffix. This is later used to check that the + * suffix is increasing. This also checks if we left the subtree */ + status = csnmp_oid_suffix (&suffix, &vb_name, data->values + i); + if (status != 0) { - DEBUG ("snmp plugin: host = %s; data = %s; Value %i left its subtree.", + DEBUG ("snmp plugin: host = %s; data = %s; Value %i failed. " + "It probably left its subtree.", host->name, data->name, i); continue; } @@ -1452,10 +1442,10 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) /* Make sure the OIDs returned by the agent are increasing. Otherwise our * table matching algorithm will get confused. */ if ((value_list_tail[i] != NULL) - && (csnmp_oid_compare (&vb_name, &value_list_tail[i]->suffix) <= 0)) + && (csnmp_oid_compare (&suffix, &value_list_tail[i]->suffix) <= 0)) { DEBUG ("snmp plugin: host = %s; data = %s; i = %i; " - "SUBID is not increasing.", + "Suffix is not increasing.", host->name, data->name, i); continue; } @@ -1469,9 +1459,9 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) } memset (vt, 0, sizeof (*vt)); - csnmp_oid_suffix (&vt->suffix, &vb_name, data->values + i); vt->value = csnmp_value_list_to_value (vb, ds->ds[i].type, data->scale, data->shift); + memcpy (&vt->suffix, &suffix, sizeof (vt->suffix)); vt->next = NULL; if (value_list_tail[i] == NULL) @@ -1639,8 +1629,8 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data) static int csnmp_read_host (user_data_t *ud) { host_definition_t *host; - time_t time_start; - time_t time_end; + cdtime_t time_start; + cdtime_t time_end; int status; int success; int i; @@ -1650,9 +1640,7 @@ static int csnmp_read_host (user_data_t *ud) if (host->interval == 0) host->interval = interval_g; - time_start = time (NULL); - DEBUG ("snmp plugin: csnmp_read_host (%s) started at %u;", host->name, - (unsigned int) time_start); + time_start = cdtime (); if (host->sess_handle == NULL) csnmp_host_open_session (host); @@ -1674,14 +1662,14 @@ static int csnmp_read_host (user_data_t *ud) success++; } - time_end = time (NULL); - DEBUG ("snmp plugin: csnmp_read_host (%s) finished at %u;", host->name, - (unsigned int) time_end); - if ((uint32_t) (time_end - time_start) > host->interval) + time_end = cdtime (); + if ((time_end - time_start) > host->interval) { - WARNING ("snmp plugin: Host `%s' should be queried every %"PRIu32 - " seconds, but reading all values takes %u seconds.", - host->name, host->interval, (unsigned int) (time_end - time_start)); + WARNING ("snmp plugin: Host `%s' should be queried every %.3f " + "seconds, but reading all values takes %.3f seconds.", + host->name, + CDTIME_T_TO_DOUBLE (host->interval), + CDTIME_T_TO_DOUBLE (time_end - time_start)); } if (success == 0)