projects
/
collectd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a664c79
)
contrib/snmp-probe-host.px: Implemented the “--exclude” option.
collectd-4.7
author
Florian Forster
<octo@noris.net>
Wed, 23 Dec 2009 11:40:14 +0000
(12:40 +0100)
committer
Florian Forster
<octo@noris.net>
Wed, 23 Dec 2009 11:40:14 +0000
(12:40 +0100)
contrib/snmp-probe-host.px
patch
|
blob
|
history
diff --git
a/contrib/snmp-probe-host.px
b/contrib/snmp-probe-host.px
index
1d8f975
..
d1a7a88
100755
(executable)
--- a/
contrib/snmp-probe-host.px
+++ b/
contrib/snmp-probe-host.px
@@
-1,7
+1,8
@@
#!/usr/bin/perl
#
# collectd - snmp-probe-host.px
#!/usr/bin/perl
#
# collectd - snmp-probe-host.px
-# Copyright (C) 2008 Florian octo Forster
+# Copyright (C) 2008,2009 Florian octo Forster
+# Copyright (C) 2009 noris network AG
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
@@
-27,6
+28,12
@@
use Config::General ('ParseConfig');
use Getopt::Long ('GetOptions');
use Socket6;
use Getopt::Long ('GetOptions');
use Socket6;
+our %ExcludeOptions =
+(
+ 'IF-MIB64' => qr/^\.?1\.3\.6\.1\.2\.1\.31/,
+ 'IF-MIB32' => qr/^\.?1\.3\.6\.1\.2\.1\.2/
+);
+
sub get_config
{
my %conf;
sub get_config
{
my %conf;
@@
-50,6
+57,7
@@
sub probe_one
{
my $sess = shift;
my $conf = shift;
{
my $sess = shift;
my $conf = shift;
+ my $excludes = @_ ? shift : [];
my @oids;
my $cmd = 'GET';
my $vl;
my @oids;
my $cmd = 'GET';
my $vl;
@@
-90,6
+98,14
@@
sub probe_one
$oid_orig = $tmp;
}
$oid_orig = $tmp;
}
+ for (@$excludes)
+ {
+ if ($oid_orig =~ $_)
+ {
+ return;
+ }
+ }
+
$vb = SNMP::Varbind->new ([$oid_orig]);
if ($cmd eq 'GET')
$vb = SNMP::Varbind->new ([$oid_orig]);
if ($cmd eq 'GET')
@@
-148,6
+164,7
@@
sub probe_all
my $host = shift;
my $community = shift;
my $data = shift;
my $host = shift;
my $community = shift;
my $data = shift;
+ my $excludes = @_ ? shift : [];
my $version = 2;
my @valid_data = ();
my $begin;
my $version = 2;
my @valid_data = ();
my $begin;
@@
-203,7
+220,7
@@
sub probe_all
for (keys %$data)
{
my $name = $_;
for (keys %$data)
{
my $name = $_;
- if (probe_one ($sess, $data->{$name}))
+ if (probe_one ($sess, $data->{$name}
, $excludes
))
{
push (@valid_data, $name);
}
{
push (@valid_data, $name);
}
@@
-258,11
+275,24
@@
Options are:
-C | --config Path to config file holding the SNMP data blocks.
-c | --community SNMP community to use. Default: `public'.
-h | --help Print this information and exit.
-C | --config Path to config file holding the SNMP data blocks.
-c | --community SNMP community to use. Default: `public'.
-h | --help Print this information and exit.
+ -x | --exclude Exclude a specific MIB. Call with "help" for more
+ information.
USAGE
exit (1);
}
USAGE
exit (1);
}
+sub exit_usage_exclude
+{
+ print "Available exclude MIBs:\n\n";
+ for (sort (keys %ExcludeOptions))
+ {
+ print " $_\n";
+ }
+ print "\n";
+ exit (1);
+}
+
=head1 NAME
snmp-probe-host.px - Find out what information an SNMP device provides.
=head1 NAME
snmp-probe-host.px - Find out what information an SNMP device provides.
@@
-294,6
+324,7
@@
my $file = '/etc/collectd/collectd.conf';
my $community = 'public';
my $conf;
my $working_data;
my $community = 'public';
my $conf;
my $working_data;
+my @excludes = ();
=head1 OPTIONS
=head1 OPTIONS
@@
-318,6
+349,19
@@
Defaults to F</etc/collectd/collectd.conf>.
SNMP community to use. Should be pretty straight forward.
SNMP community to use. Should be pretty straight forward.
+=item B<--exclude> I<MIB>
+
+This option can be used to exclude specific data from being enabled in the
+generated config. Currently the following MIBs are understood:
+
+=over 4
+
+=item B<IF-MIB>
+
+Exclude interface information, such as I<ifOctets> and I<ifPackets>.
+
+=back
+
=back
=cut
=back
=cut
@@
-325,6
+369,7
@@
SNMP community to use. Should be pretty straight forward.
GetOptions ('H|host|hostname=s' => \$host,
'C|conf|config=s' => \$file,
'c|community=s' => \$community,
GetOptions ('H|host|hostname=s' => \$host,
'C|conf|config=s' => \$file,
'c|community=s' => \$community,
+ 'x|exclude=s' => \@excludes,
'h|help' => \&exit_usage) or die;
if (!$host)
'h|help' => \&exit_usage) or die;
if (!$host)
@@
-333,6
+378,28
@@
if (!$host)
exit (1);
}
exit (1);
}
+if (@excludes)
+{
+ my $tmp = join (',', @excludes);
+ my @tmp = split (/\s*,\s*/, $tmp);
+
+ @excludes = ();
+ for (@tmp)
+ {
+ my $mib = uc ($_);
+ if ($mib eq 'HELP')
+ {
+ exit_usage_exclude ();
+ }
+ elsif (!exists ($ExcludeOptions{$mib}))
+ {
+ print STDERR "No such MIB: $mib\n";
+ exit_usage_exclude ();
+ }
+ push (@excludes, $ExcludeOptions{$mib});
+ }
+}
+
$conf = get_config ($file) or die ("Cannot read config");
if (!defined ($conf->{'plugin'})
$conf = get_config ($file) or die ("Cannot read config");
if (!defined ($conf->{'plugin'})
@@
-343,7
+410,7
@@
if (!defined ($conf->{'plugin'})
exit (1);
}
exit (1);
}
-probe_all ($host, $community, $conf->{'plugin'}{'snmp'}{'data'});
+probe_all ($host, $community, $conf->{'plugin'}{'snmp'}{'data'}
, \@excludes
);
exit (0);
exit (0);