author | Florian Forster <octo@collectd.org> | |
Sat, 25 Feb 2012 17:16:59 +0000 (18:16 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Sat, 25 Feb 2012 17:16:59 +0000 (18:16 +0100) |
Conflicts:
src/amqp.c
Change-Id: I85ab3ee2b51830ad0b5d474cf1f18b5c828d6588
src/amqp.c
Change-Id: I85ab3ee2b51830ad0b5d474cf1f18b5c828d6588
contrib/exec-nagios.conf | patch | blob | history | |
contrib/exec-nagios.px | patch | blob | history | |
src/amqp.c | patch | blob | history | |
src/bind.c | patch | blob | history | |
src/df.c | patch | blob | history |
index 26dd621c50a240f3308f63514e22add8c6dcbf6a..71644f78dee8d87bb059a93db23bff5d32e799c7 100644 (file)
--- a/contrib/exec-nagios.conf
+++ b/contrib/exec-nagios.conf
# Run `perldoc exec-nagios.px' for details on this config file.
+NRPEConfig /etc/nrpe.cfg
+
Interval 300
<Script /usr/lib/nagios/check_tcp>
diff --git a/contrib/exec-nagios.px b/contrib/exec-nagios.px
index 4b112f95139aa97fc0b04b3044c528f3218837f8..c7f18c58c022daef4f9f239005ca7bfd3fc27678 100755 (executable)
--- a/contrib/exec-nagios.px
+++ b/contrib/exec-nagios.px
our $ConfigFile = '/etc/exec-nagios.conf';
our $TypeMap = {};
+our $NRPEMap = {};
our $Scripts = [];
our $Interval = defined ($ENV{'COLLECTD_INTERVAL'}) ? (0 + $ENV{'COLLECTD_INTERVAL'}) : 300;
our $Hostname = defined ($ENV{'COLLECTD_HOSTNAME'}) ? $ENV{'COLLECTD_HOSTNAME'} : '';
Here's a short sample config:
+ NRPEConfig "/etc/nrpe.cfg"
Interval 300
<Script /usr/lib/nagios/check_tcp>
Arguments -H alice -p 22
=over 4
+=item B<NRPEConfig> I<File>
+
+Read the NRPE config and add the command definitions to an alias table. After
+reading the file you can use the NRPE command name rather than the script's
+filename within B<Script> blocks (see below). If both, the NRPE config and the
+B<Script> block, define arguments they will be merged by concatenating the
+arguments together in the order "NRPE-args Script-args".
+
+Please note that this option is rather dumb. It does not support "command
+argument processing" (i.e. replacing C<$ARG1$> and friends), inclusion of other
+NRPE config files, include directories etc.
+
=item B<Interval> I<Seconds>
Sets the interval in which the plugins are executed. This doesn't need to match
=item E<lt>B<Script> I<File>E<gt>
Adds a script to the list of scripts to be executed once per I<Interval>
-seconds. You can use the following optional arguments to specify the operation
-further:
+seconds. If the B<NRPEConfig> is given above the B<Script> block, you may use
+the NRPE command name rather than the script's filename. You can use the
+following optional arguments to specify the operation further:
=over 4
=cut
+sub parse_nrpe_conf
+{
+ my $file = shift;
+ my $fh;
+ my $status;
+
+ $status = open ($fh, '<', $file);
+ if (!$status)
+ {
+ print STDERR "Reading NRPE config from \"$file\" failed: $!\n";
+ return;
+ }
+
+ while (<$fh>)
+ {
+ my $line = $_;
+ chomp ($line);
+
+ if ($line =~ m/^\s*command\[([^\]]+)\]\s*=\s*(.+)$/)
+ {
+ my $alias = $1;
+ my $script;
+ my $arguments;
+
+ ($script, $arguments) = split (' ', $2, 2);
+
+ if ($NRPEMap->{$alias})
+ {
+ print STDERR "Warning: NRPE command \"$alias\" redefined.\n";
+ }
+
+ $NRPEMap->{$alias} = { script => $script };
+ if ($arguments)
+ {
+ $NRPEMap->{$alias}{'arguments'} = $arguments;
+ }
+ }
+ } # while (<$fh>)
+
+ close ($fh);
+} # parse_nrpe_conf
+
sub handle_config_addtype
{
my $list = shift;
}
} # handle_config_addtype
+# Update the script record. This function adds the name of the script /
+# executable to the hash and merges the configured and NRPE arguments if
+# required.
+sub update_script_opts
+{
+ my $opts = shift;
+ my $script = shift;
+ my $nrpe_args = shift;
+
+ $opts->{'script'} = $script;
+
+ if ($nrpe_args)
+ {
+ if ($opts->{'arguments'})
+ {
+ $opts->{'arguments'} = $nrpe_args . ' ' . $opts->{'arguments'};
+ }
+ else
+ {
+ $opts->{'arguments'} = $nrpe_args;
+ }
+ }
+} # update_script_opts
+
sub handle_config_script
{
my $scripts = shift;
my $script = $_;
my $opts = $scripts->{$script};
+ my $nrpe_args = '';
+
+ # Check if the script exists in the NRPE map. If so, replace the alias name
+ # with the actual script name.
+ if ($NRPEMap->{$script})
+ {
+ if ($NRPEMap->{$script}{'arguments'})
+ {
+ $nrpe_args = $NRPEMap->{$script}{'arguments'};
+ }
+ $script = $NRPEMap->{$script}{'script'};
+ }
+
+ # Check if the script exists and is executable.
if (!-e $script)
{
print STDERR "Script `$script' doesn't exist.\n";
}
else
{
+ # Add the script to the global @$Script array.
if (ref ($opts) eq 'ARRAY')
+ {
+ for (@$opts)
{
- for (@$opts)
- {
- my $opt = $_;
- $opt->{'script'} = $script;
- push (@$Scripts, $opt);
- }
- }
- else
- {
- $opts->{'script'} = $script;
- push (@$Scripts, $opts);
+ my $opt = $_;
+ update_script_opts ($opt, $script, $nrpe_args);
+ push (@$Scripts, $opt);
}
+ }
+ else
+ {
+ update_script_opts ($opts, $script, $nrpe_args);
+ push (@$Scripts, $opts);
+ }
}
} # for (keys %$scripts)
} # handle_config_script
{
my $config = shift;
+ if (defined ($config->{'nrpeconfig'}))
+ {
+ if (ref ($config->{'nrpeconfig'}) eq 'ARRAY')
+ {
+ for (@{$config->{'nrpeconfig'}})
+ {
+ parse_nrpe_conf ($_);
+ }
+ }
+ elsif (ref ($config->{'nrpeconfig'}) eq '')
+ {
+ parse_nrpe_conf ($config->{'nrpeconfig'});
+ }
+ else
+ {
+ print STDERR "Cannot handle ref type '"
+ . ref ($config->{'nrpeconfig'}) . "' for option 'NRPEConfig'.\n";
+ }
+ }
+
if (defined ($config->{'addtype'}))
{
if (ref ($config->{'addtype'}) eq 'ARRAY')
diff --git a/src/amqp.c b/src/amqp.c
index adf4792b534b85f3219b6d5423bcc3c7c18a140a..be1f709e120181efdf7ce8181c4f9032f02047ed 100644 (file)
--- a/src/amqp.c
+++ b/src/amqp.c
status = camqp_connect (conf);
if (status != 0)
{
+ struct timespec ts_interval;
ERROR ("amqp plugin: camqp_connect failed. "
"Will sleep for %.3f seconds.",
CDTIME_T_TO_DOUBLE (interval_g));
- sleep (interval_g);
+ CDTIME_T_TO_TIMESPEC (interval_g, &ts_interval);
+ nanosleep (&ts_interval, /* remaining = */ NULL);
continue;
}
status = amqp_simple_wait_frame (conf->connection, &frame);
if (status < 0)
{
+ struct timespec ts_interval;
ERROR ("amqp plugin: amqp_simple_wait_frame failed. "
"Will sleep for %.3f seconds.",
CDTIME_T_TO_DOUBLE (interval_g));
camqp_close_connection (conf);
- sleep (interval_g);
+ CDTIME_T_TO_TIMESPEC (interval_g, &ts_interval);
+ nanosleep (&ts_interval, /* remaining = */ NULL);
continue;
}
diff --git a/src/bind.c b/src/bind.c
index 36e225bfe4c182c8de0396c59a3b7543d9590204..5b7d7a056efe7d1a693c34b6737a191b2dbab63c 100644 (file)
--- a/src/bind.c
+++ b/src/bind.c
list_info_ptr_t list_info =
{
plugin_instance,
- /* type = */ "dns_qtype_gauge"
+ /* type = */ "dns_qtype"
};
ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-qtypes",
doc, path_ctx, current_time, DS_TYPE_COUNTER);
} /* }}} */
+ /* Record types in the cache */
if (view->cacherrsets != 0) /* {{{ */
{
char plugin_instance[DATA_MAX_NAME_LEN];
list_info_ptr_t list_info =
{
plugin_instance,
- /* type = */ "dns_qtype_gauge"
+ /* type = */ "dns_qtype_cached"
};
ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-cache_rr_sets",
diff --git a/src/df.c b/src/df.c
index 371a7fc3db9973b676322a75362d14b633b45a81..41a03cbf6280067815419d8802c5d431c0fd239f 100644 (file)
--- a/src/df.c
+++ b/src/df.c
* report negative free space for user. Notice. blk_reserved
* will start to diminish after this. */
#if HAVE_STATVFS
- /* Cast is needed to avoid compiler warnings.
+ /* Cast and temporary variable are needed to avoid
+ * compiler warnings.
* ((struct statvfs).f_bavail is unsigned (POSIX)) */
- if (((int64_t) statbuf.f_bavail) < 0)
+ int64_t signed_bavail = (int64_t) statbuf.f_bavail;
+ if (signed_bavail < 0)
statbuf.f_bavail = 0;
#elif HAVE_STATFS
if (statbuf.f_bavail < 0)