Skip to content
Browse files

New SNMP plugins users and load.

  • Loading branch information...
1 parent 4b4feab commit 7c973c2b30148e472ad7d56df110904898a94208 @jomono jomono committed
Showing with 230 additions and 19 deletions.
  1. +2 −1 ChangeLog
  2. +13 −18 node/munin-node-configure-snmp
  3. +107 −0 node/node.d/snmp__load.in
  4. +108 −0 node/node.d/snmp__users.in
View
3 ChangeLog
@@ -20,7 +20,8 @@ munin (1.0.0pre4)
older tr-s (SF#898814).
* Make "graph_scale no" affect y-axis as well as numbers below the graph
(Deb#236834).
- * New SNMP plugins: df, if_err, processes, fc_if (fibre-channel), fc_if_err.
+ * New SNMP plugins: df, if_err, processes, fc_if (fibre-channel), fc_if_err,
+ users, load.
* Cleaned up Solaris plugins.
munin (1.0.0pre3)
View
31 node/munin-node-configure-snmp
@@ -4,7 +4,7 @@ use strict;
use Net::SNMP;
use Socket;
-my $DEBUG = 1;
+my $DEBUG = 0;
my $config = "../build/node/munin-node.conf";
#my $config = "/etc/munin/munin-node.conf";
@@ -21,7 +21,7 @@ my $session;
my $error;
my $response;
-my @plugins = ("if", "if_err", "fc_if", "fc_if_err", "df", "processes");
+my @plugins = ("if", "if_err", "fc_if", "fc_if_err", "df", "processes", "users", "load");
my %plugconf = ();
@@ -43,10 +43,10 @@ while (my $addr = shift)
}
$num = 32 - $num;
$num = 2 ** $num;
- print "# Doing $addr / $num\n";
+ print "# Doing $addr / $num\n" if $DEBUG;
for (my $i = 0; $i < $num; $i++)
{
- print "# Doing $addr -> $i...\n";
+ print "# Doing $addr -> $i...\n" if $DEBUG;
my $tmpaddr = $addr;
if ($tmpaddr =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/)
{
@@ -55,7 +55,7 @@ while (my $addr = shift)
$tmpaddr = gethostbyaddr (inet_aton (join ('.', @tmpaddr)), AF_INET);
$tmpaddr ||= join ('.', @tmpaddr);
}
- print "# ($tmpaddr)\n";
+ print "# ($tmpaddr)\n" if $DEBUG;
do_host ("$tmpaddr", "public");
}
}
@@ -132,15 +132,13 @@ sub snmp_autoconf_plugin
{
if ($req->[0] =~ /\.$/)
{
- print "# Delaying testing of $req->[0], as we need the indexes first.\n";
+ print "# Delaying testing of $req->[0], as we need the indexes first.\n" if $DEBUG;
next;
}
- print "# Testing $req->[0]\n";
my $snmp_val = snmp_get_single ($session, $req->[0]);
- print "# Got $snmp_val...\n";
if (!defined $snmp_val or $snmp_val !~ /$req->[1]/)
{
- print "# Nope. Duh.\n";
+ print "# Nope. Duh.\n" if $DEBUG;
return undef;
}
}
@@ -179,18 +177,16 @@ sub snmp_autoconf_plugin
{
if ($req->[0] !~ /\.$/)
{
- print "# Already tested of $req->[0], before we got hold of the indexes.\n";
+ print "# Already tested of $req->[0], before we got hold of the indexes.\n" if $DEBUG;
next;
}
foreach my $key (keys %$indexes)
{
- print "# Testing $req->[0]$key\n";
my $snmp_val = snmp_get_single ($session, $req->[0] . $key);
- print "# Got $snmp_val...\n";
if (!defined $snmp_val or $snmp_val !~ /$req->[1]/)
{
- print "# Nope. Deleting $key from possible solutions.\n";
+ print "# Nope. Deleting $key from possible solutions.\n" if $DEBUG;
delete $indexes->{$key}; # Disable
}
}
@@ -218,11 +214,11 @@ sub fetch_plugin_config
}
else
{
- print "# Skipping $plugname: Couldn't find plugin \"$libdir/$plugin\".\n";
+ print "# Skipping $plugname: Couldn't find plugin \"$libdir/$plugin\".\n" if $DEBUG;
return 0;
}
- print "# SNMPconfing plugin \"$plugname\" ( $libdir/$plugin )\n";
+ print "# SNMPconfing plugin \"$plugname\" ( $libdir/$plugin )\n" if $DEBUG;
my $fork = open (PLUG, "-|");
@@ -305,12 +301,12 @@ sub snmp_get_index
{
if ($i == 0)
{
- print "# Checking for $ret\n";
+ print "# Checking for $ret\n" if $DEBUG;
$response = $session->get_request($ret);
}
if ($i or !defined $response)
{
- print "# Checking for sibling of $ret\n";
+ print "# Checking for sibling of $ret\n" if $DEBUG;
$response = $session->get_next_request($ret);
}
if (!$response)
@@ -319,7 +315,6 @@ sub snmp_get_index
}
my @keys = keys %$response;
$ret = $keys[0];
- print "# Analyzing $ret\n";
last unless ($ret =~ /^$oid\d+$/);
print "# Index $i: ", join ('|', @keys), "\n" if $DEBUG;
$rhash->{$response->{$ret}} = 1;
View
107 node/node.d/snmp__load.in
@@ -0,0 +1,107 @@
+#!/usr/bin/perl -w
+#
+# $Log$
+# Revision 1.1 2004/05/01 10:50:53 jimmyo
+# New SNMP plugins users and load.
+#
+# Revision 1.1 2004/04/30 20:13:53 jimmyo
+# New SNMP plugin for number of procs.
+#
+# Revision 1.1 2004/04/29 22:29:57 jimmyo
+# New SNMP plugin for disk usage.
+#
+# Revision 1.3 2004/02/22 20:17:58 jimmyo
+# Typo fix
+#
+# Revision 1.2 2004/02/18 21:54:56 jimmyo
+# Did a bit of work on the snmp-thingie.
+#
+# Revision 1.1 2004/01/02 18:50:00 jimmyo
+# Renamed occurrances of lrrd -> munin
+#
+# Revision 1.1.1.1 2004/01/02 15:18:07 jimmyo
+# Import of LRRD CVS tree after renaming to Munin
+#
+# Revision 1.1 2003/12/19 20:53:45 jimmyo
+# Created by jo
+#
+#
+
+use strict;
+use Net::SNMP;
+
+my $DEBUG = 0;
+my $MAXLABEL = 20;
+
+my $host = $ENV{host} || undef;
+my $port = $ENV{port} || 161;
+my $community = $ENV{community} || "public";
+my $iface = $ENV{interface} || undef;
+
+my $response;
+
+if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
+{
+ print "require 1.3.6.1.4.1.2021.10.1.3.2 [0-9]\n"; # Number
+ exit 0;
+}
+
+if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_load$/)
+{
+ $host = $1;
+ if ($host =~ /^([^:]+):(\d+)$/)
+ {
+ $host = $1;
+ $port = $2;
+ }
+}
+else
+{
+ print "# Debug: $0 -- $1\n" if $DEBUG;
+ die "# Error: couldn't understand what I'm supposed to monitor.";
+}
+
+my ($session, $error) = Net::SNMP->session(
+ -hostname => $host,
+ -community => $community,
+ -port => $port
+ );
+
+if (!defined ($session))
+{
+ die "Croaking: $error";
+}
+
+if (defined $ARGV[0] and $ARGV[0] eq "config")
+{
+ print "graph_title Load average
+graph_args --base 1000 -l 0
+graph_vlabel load
+load.label load
+load.draw LINE2
+";
+
+ exit 0;
+}
+
+print "load.value ", &get_single ($session, "1.3.6.1.4.1.2021.10.1.3.2"), "\n";
+
+sub get_single
+{
+ my $handle = shift;
+ my $oid = shift;
+
+ print "# Getting single $oid...\n" if $DEBUG;
+
+ $response = $handle->get_request ($oid);
+
+ if (!defined $response->{$oid})
+ {
+ return undef;
+ }
+ else
+ {
+ return $response->{$oid};
+ }
+}
+
View
108 node/node.d/snmp__users.in
@@ -0,0 +1,108 @@
+#!/usr/bin/perl -w
+#
+# $Log$
+# Revision 1.1 2004/05/01 10:50:53 jimmyo
+# New SNMP plugins users and load.
+#
+# Revision 1.1 2004/04/30 20:13:53 jimmyo
+# New SNMP plugin for number of procs.
+#
+# Revision 1.1 2004/04/29 22:29:57 jimmyo
+# New SNMP plugin for disk usage.
+#
+# Revision 1.3 2004/02/22 20:17:58 jimmyo
+# Typo fix
+#
+# Revision 1.2 2004/02/18 21:54:56 jimmyo
+# Did a bit of work on the snmp-thingie.
+#
+# Revision 1.1 2004/01/02 18:50:00 jimmyo
+# Renamed occurrances of lrrd -> munin
+#
+# Revision 1.1.1.1 2004/01/02 15:18:07 jimmyo
+# Import of LRRD CVS tree after renaming to Munin
+#
+# Revision 1.1 2003/12/19 20:53:45 jimmyo
+# Created by jo
+#
+#
+
+use strict;
+use Net::SNMP;
+
+my $DEBUG = 0;
+my $MAXLABEL = 20;
+
+my $host = $ENV{host} || undef;
+my $port = $ENV{port} || 161;
+my $community = $ENV{community} || "public";
+my $iface = $ENV{interface} || undef;
+
+my $response;
+
+if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
+{
+ print "require 1.3.6.1.2.1.25.1.5.0 [0-9]\n"; # Number
+ exit 0;
+}
+
+if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_users$/)
+{
+ $host = $1;
+ if ($host =~ /^([^:]+):(\d+)$/)
+ {
+ $host = $1;
+ $port = $2;
+ }
+}
+else
+{
+ print "# Debug: $0 -- $1\n" if $DEBUG;
+ die "# Error: couldn't understand what I'm supposed to monitor.";
+}
+
+my ($session, $error) = Net::SNMP->session(
+ -hostname => $host,
+ -community => $community,
+ -port => $port
+ );
+
+if (!defined ($session))
+{
+ die "Croaking: $error";
+}
+
+if (defined $ARGV[0] and $ARGV[0] eq "config")
+{
+ print "graph_title Number of users
+graph_args --base 1000 -l 0
+graph_vlabel number of users
+graph_scale no
+users.label users
+users.draw LINE2
+";
+
+ exit 0;
+}
+
+print "users.value ", &get_single ($session, "1.3.6.1.2.1.25.1.5.0"), "\n";
+
+sub get_single
+{
+ my $handle = shift;
+ my $oid = shift;
+
+ print "# Getting single $oid...\n" if $DEBUG;
+
+ $response = $handle->get_request ($oid);
+
+ if (!defined $response->{$oid})
+ {
+ return undef;
+ }
+ else
+ {
+ return $response->{$oid};
+ }
+}
+

0 comments on commit 7c973c2

Please sign in to comment.
Something went wrong with that request. Please try again.