From: Florian Forster Date: Wed, 18 Oct 2017 18:54:37 +0000 (+0200) Subject: Merge remote-tracking branch 'github/pr/2490' X-Git-Tag: collectd-5.8.0~36 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=6cde759904135a88f4e33c6684cb2895bfe5ca27;hp=291879be6c66d00ff8dad09a0e44b332db31459a Merge remote-tracking branch 'github/pr/2490' --- diff --git a/src/collectd-snmp.pod b/src/collectd-snmp.pod index edb95060..d615088e 100644 --- a/src/collectd-snmp.pod +++ b/src/collectd-snmp.pod @@ -36,6 +36,8 @@ collectd-snmp - Documentation of collectd's C Community "community_string" Collect "std_traffic" Interval 120 + Timeout 10 + Retries 1 Address "192.168.0.42" @@ -60,6 +62,8 @@ collectd-snmp - Documentation of collectd's C Community "more_communities" Collect "powerplus_voltge_input" Interval 300 + Timeout 5 + Retries 5 @@ -78,7 +82,7 @@ and ten threads are used. =head1 CONFIGURATION Since the aim of the C is to provide a generic interface to SNMP, -it's configuration is not trivial and may take some time. +its configuration is not trivial and may take some time. Since the C library is used you can use all the environment variables that are interpreted by that package. See L for more details. @@ -281,6 +285,15 @@ switches, embedded devices, rack monitoring systems and so on. Since the B of generated RRD files depends on this setting it's wise to select a reasonable value once and never change it. +=item B I + +How long to wait for a response. The C library default is 1 second. + +=item B I + +The number of times that a query should be retried after the Timeout expires. +The C library default is 5. + =back =head1 SEE ALSO diff --git a/src/collectd.conf.in b/src/collectd.conf.in index c982e554..261abdfd 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -1317,6 +1317,8 @@ # Community "community_string" # Collect "std_traffic" # Interval 120 +# Timeout 10 +# Retries 1 # # # Address "192.168.0.42" @@ -1330,6 +1332,8 @@ # Community "more_communities" # Collect "powerplus_voltge_input" # Interval 300 +# Timeout 5 +# Retries 5 # # diff --git a/src/snmp.c b/src/snmp.c index 466f98d5..0a20e34b 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -71,6 +71,8 @@ struct host_definition_s { char *name; char *address; int version; + cdtime_t timeout; + int retries; /* snmpv1/2 options */ char *community; @@ -582,6 +584,10 @@ static int csnmp_config_add_host(oconfig_item_t *ci) { hd->sess_handle = NULL; hd->interval = 0; + /* These mean that we have not set a timeout or retry value */ + hd->timeout = 0; + hd->retries = -1; + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; status = 0; @@ -592,6 +598,10 @@ static int csnmp_config_add_host(oconfig_item_t *ci) { status = cf_util_get_string(option, &hd->community); else if (strcasecmp("Version", option->key) == 0) status = csnmp_config_add_host_version(hd, option); + else if (strcasecmp("Timeout", option->key) == 0) + cf_util_get_cdtime(option, &hd->timeout); + else if (strcasecmp("Retries", option->key) == 0) + cf_util_get_int(option, &hd->retries); else if (strcasecmp("Collect", option->key) == 0) csnmp_config_add_host_collect(hd, option); else if (strcasecmp("Interval", option->key) == 0) @@ -788,6 +798,15 @@ static void csnmp_host_open_session(host_definition_t *host) { sess.community_len = strlen(host->community); } + /* Set timeout & retries, if they have been changed from the default */ + if (host->timeout != 0) { + /* net-snmp expects microseconds */ + sess.timeout = CDTIME_T_TO_US(host->timeout); + } + if (host->retries >= 0) { + sess.retries = host->retries; + } + /* snmp_sess_open will copy the `struct snmp_session *'. */ host->sess_handle = snmp_sess_open(&sess);