2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

Merge pull request #850 from Dismounted/patch-1

Fix OpenWrt SNMP memory plugin
This commit is contained in:
sumpfralle 2017-06-27 21:27:32 +02:00 committed by GitHub
commit 918222579a

View File

@ -1,76 +1,77 @@
#!/usr/bin/perl -w
#
# Copyright (C) 2008 J.M.Roth
#
# 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 Free Software Foundation; version 2 dated June,
# 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
# $Log$
#
# Inspired by snmp__processes
#
#%# family=snmpauto
#%# capabilities=snmpconf
#!/usr/bin/env perl
# -*- perl -*-
# vim: ft=perl
=head1 NAME
snmp__memory_openwrt - Munin plugin to monitor the memory usage of an OpenWrt
device.
=head1 APPLICABLE SYSTEMS
OpenWrt devices which have snmpd installed.
=head1 CONFIGURATION
As a rule SNMP plugins need site specific configuration. The default
configuration (shown here) will only work on insecure sites/devices.
[snmp_*]
env.version 2
env.community public
In general SNMP is not very secure at all unless you use SNMP version
3 which supports authentication and privacy (encryption). But in any
case the community string for your devices should not be "public".
Please see 'perldoc Munin::Plugin::SNMP' for further configuration
information.
=head1 INTERPRETATION
The total and used memory on the system.
=head1 MIB INFORMATION
This plugin requires support for the HOST-RESOURCES-MIB (RFC 2790). It
reports the contents of the hrStorageSize and hrStorageUsed OIDs.
=head1 MAGIC MARKERS
#%# family=snmpauto
#%# capabilities=snmpconf
=head1 BUGS
None known.
=head1 AUTHOR
Copyright (C) 2017 Hanson Wong
Based on snmp__memory_openwrt (C) 2008 J.M.Roth
=head1 LICENSE
GPLv2.
=cut
use strict;
use Net::SNMP;
use Munin::Plugin::SNMP;
my $DEBUG = 0;
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.2.3.1.5.2\n"; # Number
print "require 1.3.6.1.2.1.25.2.3.1.6.2\n"; # Number
exit 0;
if (defined $ARGV[0] and $ARGV[0] eq 'snmpconf') {
print "require 1.3.6.1.2.1.25.2.3.1.5.1\n";
print "require 1.3.6.1.2.1.25.2.3.1.6.1\n";
exit 0;
}
my @split_result = split(/_/, $0);
$host = $split_result[1];
if ($host =~ /^([^:]+):(\d+)$/)
{
$host = $1;
$port = $2;
}
if ($host eq '' || !defined $host)
{
print "# Debug: $0 -- $1\n" if $DEBUG;
die "# Error: couldn't understand what I'm supposed to monitor.";
}
if (defined $ARGV[0] and $ARGV[0] eq "config") {
my ($host) = Munin::Plugin::SNMP->config_session();
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 "host_name $host\n";
print "graph_title Memory usage
print "host_name $host\n" unless ($host eq 'localhost');
print <<'EOC';
graph_title Memory usage
graph_args --base 1000 -l 0
graph_vlabel kB
graph_category memory
@ -81,29 +82,10 @@ memsize.info The total memory.
memused.info The memory in use.
memsize.draw LINE1
memused.draw LINE2
";
exit 0;
EOC
exit 0;
}
print "memsize.value ", &get_single ($session, "1.3.6.1.2.1.25.2.3.1.5.2"), "\n";
print "memused.value ", &get_single ($session, "1.3.6.1.2.1.25.2.3.1.6.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};
}
}
my $session = Munin::Plugin::SNMP->session();
print "memsize.value ", $session->get_single('1.3.6.1.2.1.25.2.3.1.5.1'), "\n";
print "memused.value ", $session->get_single('1.3.6.1.2.1.25.2.3.1.6.1'), "\n";