projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Treewide: cleanup whitespace
[collectd.git]
/
src
/
snmp.c
diff --git
a/src/snmp.c
b/src/snmp.c
index
162426a
..
8b21907
100644
(file)
--- a/
src/snmp.c
+++ b/
src/snmp.c
@@
-310,7
+310,7
@@
static int csnmp_config_add_data_values (data_definition_t *dd, oconfig_item_t *
sfree (dd->values);
dd->values_len = 0;
sfree (dd->values);
dd->values_len = 0;
- dd->values =
(oid_t *) malloc (sizeof (oid_t
) * ci->values_num);
+ dd->values =
malloc (sizeof (*dd->values
) * ci->values_num);
if (dd->values == NULL)
return (-1);
dd->values_len = (size_t) ci->values_num;
if (dd->values == NULL)
return (-1);
dd->values_len = (size_t) ci->values_num;
@@
-384,10
+384,9
@@
static int csnmp_config_add_data (oconfig_item_t *ci)
int status = 0;
int i;
int status = 0;
int i;
- dd =
(data_definition_t *) malloc (sizeof (data_definition_t
));
+ dd =
calloc (1, sizeof (*dd
));
if (dd == NULL)
return (-1);
if (dd == NULL)
return (-1);
- memset (dd, '\0', sizeof (data_definition_t));
status = cf_util_get_string(ci, &dd->name);
if (status != 0)
status = cf_util_get_string(ci, &dd->name);
if (status != 0)
@@
-646,10
+645,9
@@
static int csnmp_config_add_host (oconfig_item_t *ci)
char cb_name[DATA_MAX_NAME_LEN];
user_data_t cb_data;
char cb_name[DATA_MAX_NAME_LEN];
user_data_t cb_data;
- hd =
(host_definition_t *) malloc (sizeof (host_definition_t
));
+ hd =
calloc (1, sizeof (*hd
));
if (hd == NULL)
return (-1);
if (hd == NULL)
return (-1);
- memset (hd, '\0', sizeof (host_definition_t));
hd->version = 2;
C_COMPLAIN_INIT (&hd->complaint);
hd->version = 2;
C_COMPLAIN_INIT (&hd->complaint);
@@
-1106,6
+1104,14
@@
static int csnmp_strvbcopy (char *dst, /* {{{ */
src = (char *) vb->val.string;
else if (vb->type == ASN_BIT_STR)
src = (char *) vb->val.bitstring;
src = (char *) vb->val.string;
else if (vb->type == ASN_BIT_STR)
src = (char *) vb->val.bitstring;
+ else if (vb->type == ASN_IPADDRESS)
+ {
+ return ssnprintf (dst, dst_size, "%"PRIu8".%"PRIu8".%"PRIu8".%"PRIu8"",
+ (uint8_t) vb->val.string[0],
+ (uint8_t) vb->val.string[1],
+ (uint8_t) vb->val.string[2],
+ (uint8_t) vb->val.string[3]);
+ }
else
{
dst[0] = 0;
else
{
dst[0] = 0;
@@
-1154,13
+1160,12
@@
static int csnmp_instance_list_add (csnmp_list_instances_t **head,
csnmp_oid_init (&vb_name, vb->name, vb->name_length);
csnmp_oid_init (&vb_name, vb->name, vb->name_length);
- il =
malloc (
sizeof (*il));
+ il =
calloc (1,
sizeof (*il));
if (il == NULL)
{
if (il == NULL)
{
- ERROR ("snmp plugin:
m
alloc failed.");
+ ERROR ("snmp plugin:
c
alloc failed.");
return (-1);
}
return (-1);
}
- memset (il, 0, sizeof (*il));
il->next = NULL;
status = csnmp_oid_suffix (&il->suffix, &vb_name, &dd->instance.oid);
il->next = NULL;
status = csnmp_oid_suffix (&il->suffix, &vb_name, &dd->instance.oid);
@@
-1171,7
+1176,7
@@
static int csnmp_instance_list_add (csnmp_list_instances_t **head,
}
/* Get instance name */
}
/* Get instance name */
- if ((vb->type == ASN_OCTET_STR) || (vb->type == ASN_BIT_STR))
+ if ((vb->type == ASN_OCTET_STR) || (vb->type == ASN_BIT_STR)
|| (vb->type == ASN_IPADDRESS)
)
{
char *ptr;
{
char *ptr;
@@
-1390,7
+1395,7
@@
static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat
static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
{
struct snmp_pdu *req;
static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
{
struct snmp_pdu *req;
- struct snmp_pdu *res;
+ struct snmp_pdu *res
= NULL
;
struct variable_list *vb;
const data_set_t *ds;
struct variable_list *vb;
const data_set_t *ds;
@@
-1599,14
+1604,13
@@
static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
continue;
}
continue;
}
- vt =
malloc (
sizeof (*vt));
+ vt =
calloc (1,
sizeof (*vt));
if (vt == NULL)
{
if (vt == NULL)
{
- ERROR ("snmp plugin:
m
alloc failed.");
+ ERROR ("snmp plugin:
c
alloc failed.");
status = -1;
break;
}
status = -1;
break;
}
- memset (vt, 0, sizeof (*vt));
vt->value = csnmp_value_list_to_value (vb, ds->ds[i].type,
data->scale, data->shift, host->name, data->name);
vt->value = csnmp_value_list_to_value (vb, ds->ds[i].type,
data->scale, data->shift, host->name, data->name);
@@
-1702,7
+1706,7
@@
static int csnmp_read_value (host_definition_t *host, data_definition_t *data)
}
vl.values_len = ds->ds_num;
}
vl.values_len = ds->ds_num;
- vl.values =
(value_t *) malloc (sizeof (value_t
) * vl.values_len);
+ vl.values =
malloc (sizeof (*vl.values
) * vl.values_len);
if (vl.values == NULL)
return (-1);
for (i = 0; i < vl.values_len; i++)
if (vl.values == NULL)
return (-1);
for (i = 0; i < vl.values_len; i++)
@@
-1747,6
+1751,7
@@
static int csnmp_read_value (host_definition_t *host, data_definition_t *data)
res = NULL;
sfree (errstr);
res = NULL;
sfree (errstr);
+ sfree (vl.values);
csnmp_host_close_session (host);
return (-1);
csnmp_host_close_session (host);
return (-1);
@@
-1783,8
+1788,6
@@
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;
static int csnmp_read_host (user_data_t *ud)
{
host_definition_t *host;
- cdtime_t time_start;
- cdtime_t time_end;
int status;
int success;
int i;
int status;
int success;
int i;
@@
-1794,8
+1797,6
@@
static int csnmp_read_host (user_data_t *ud)
if (host->interval == 0)
host->interval = plugin_get_interval ();
if (host->interval == 0)
host->interval = plugin_get_interval ();
- time_start = cdtime ();
-
if (host->sess_handle == NULL)
csnmp_host_open_session (host);
if (host->sess_handle == NULL)
csnmp_host_open_session (host);
@@
-1816,16
+1817,6
@@
static int csnmp_read_host (user_data_t *ud)
success++;
}
success++;
}
- time_end = cdtime ();
- if ((time_end - time_start) > host->interval)
- {
- 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)
return (-1);
if (success == 0)
return (-1);