Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / snmp / snmp__memory_openwrt @ 29da235b

Historique | Voir | Annoter | Télécharger (2,41 ko)

1
#!/usr/bin/perl -w
2
#
3
# Copyright (C) 2008 J.M.Roth
4
#
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; version 2 dated June,
8
# 1991.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
#
19
#
20
# $Log$
21
#
22
# Inspired by snmp__processes
23
#
24
#%# family=snmpauto
25
#%# capabilities=snmpconf
26

    
27
use strict;
28
use Net::SNMP;
29

    
30
my $DEBUG = 0;
31

    
32
my $host      = $ENV{host}      || undef;
33
my $port      = $ENV{port}      || 161;
34
my $community = $ENV{community} || "public";
35
my $iface     = $ENV{interface} || undef;
36

    
37
my $response;
38

    
39
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
40
{
41
	print "require 1.3.6.1.2.1.25.2.3.1.5.2\n"; # Number
42
	print "require 1.3.6.1.2.1.25.2.3.1.6.2\n"; # Number
43
	exit 0;
44
}
45

    
46
my @split_result = split(/_/, $0);
47
$host = $split_result[1];
48
if ($host =~ /^([^:]+):(\d+)$/)
49
{
50
    $host = $1;
51
    $port = $2;
52
}
53
if ($host eq '' || !defined $host)
54
{
55
	print "# Debug: $0 -- $1\n" if $DEBUG;
56
	die "# Error: couldn't understand what I'm supposed to monitor.";
57
}
58

    
59
my ($session, $error) = Net::SNMP->session(
60
		-hostname  => $host,
61
		-community => $community,
62
		-port      => $port
63
	);
64

    
65
if (!defined ($session))
66
{
67
	die "Croaking: $error";
68
}
69

    
70
if (defined $ARGV[0] and $ARGV[0] eq "config")
71
{
72
	print "host_name $host\n";
73
	print "graph_title Memory usage
74
graph_args --base 1000 -l 0 
75
graph_vlabel kB
76
graph_category system
77
graph_info This graph shows total and used memory on the host.
78
memsize.label total
79
memused.label used
80
memsize.info The total memory.
81
memused.info The memory in use.
82
memsize.draw LINE1
83
memused.draw LINE2
84
";
85

    
86
	exit 0;
87
}
88

    
89
print "memsize.value ", &get_single ($session, "1.3.6.1.2.1.25.2.3.1.5.2"), "\n";
90
print "memused.value ", &get_single ($session, "1.3.6.1.2.1.25.2.3.1.6.2"), "\n";
91

    
92
sub get_single
93
{
94
	my $handle = shift;
95
	my $oid    = shift;
96

    
97
	print "# Getting single $oid...\n" if $DEBUG;
98

    
99
	$response = $handle->get_request ($oid);
100

    
101
	if (!defined $response->{$oid})
102
	{
103
	    return undef;
104
	}
105
	else
106
	{
107
	    return $response->{$oid};
108
	}
109
}