All,
Some metrics are readily accessible via SNMP on our hosts. However, the
requirement to specify a hostname for the SNMP plugin requires us to
maintain separate configuration files per host, in order to have an
appropriate hostname set in the collected metrics.
I'd like to propose that SNMP (and other plugins that connect to a
remote host) default to using the current host, if none is specified.
This would allow much simpler configurations like the following to work:
<Host>
Version 2
Community "some_community_string"
Collect "metric_1" "metric_2" "metric_3"
</Host>
I've attached a patch against 5.1.0 for snmp.c that uses "hostname_g" as
the default host name and address when unspecified. The patch also
supports defaults when an empty hostname is provided, such as <Host "">,
and outputs debug information when defaults are used.
Thoughts? Concerns?
Thanks,
Scott Severtson
Chief Architect
Digital Measures
--- collectd-5.1.0.orig/src/snmp.c 2012-04-02 04:04:58.000000000 -0400
+++ collectd-5.1.0.patch/src/snmp.c 2012-06-08 10:54:52.146328594 -0400
@@ -553,12 +553,6 @@
user_data_t cb_data;
struct timespec cb_interval;
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
- {
- WARNING ("snmp plugin: `Host' needs exactly one string argument.");
- return (-1);
- }
-
hd = (host_definition_t *) malloc (sizeof (host_definition_t));
if (hd == NULL)
return (-1);
@@ -566,11 +560,18 @@
hd->version = 2;
C_COMPLAIN_INIT (&hd->complaint);
- hd->name = strdup (ci->values[0].value.string);
- if (hd->name == NULL)
+ if ((ci->values_num != 1)
+ || (ci->values[0].type != OCONFIG_TYPE_STRING)
+ || (ci->values[0].value.string == NULL)
+ || (strcmp("", ci->values[0].value.string) == 0))
{
- free (hd);
- return (-1);
+ DEBUG ("snmp plugin: No host name provided; using default host name { name = %s }",
+ hostname_g);
+ hd->name = hostname_g;
+ }
+ else
+ {
+ hd->name = strdup (ci->values[0].value.string);
}
hd->sess_handle = NULL;
@@ -605,9 +606,9 @@
{
if (hd->address == NULL)
{
- WARNING ("snmp plugin: `Address' not given for host `%s'", hd->name);
- status = -1;
- break;
+ DEBUG ("snmp plugin: No address provided; using default host name { name = %s, address = %s }",
+ hd->name, hostname_g);
+ hd->address = hostname_g;
}
if (hd->community == NULL)
{
_______________________________________________
collectd mailing list
[email protected]
http://mailman.verplant.org/listinfo/collectd