Projet

Général

Profil

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

root / plugins / other / snmp__uptime @ e908d2d2

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

1 6eccc14b Lars Strand
#!/usr/bin/perl -w
2
#
3
# Copyright (C) 2006 Lars Strand
4
#
5
# Munin plugin to monitor uptime by use of SNMP.
6
# Based on snmp__users plugin.
7
#
8
# This program is free software; you can redistribute it and/or
9
# modify it under the terms of the GNU General Public License
10
# as published by the Free Software Foundation; version 2 dated June,
11
# 1991.
12
#
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with this program; if not, write to the Free Software
20
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
#
22
# $Log$
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
36
my $response;
37
38
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
39
{
40
    print "require 1.3.6.1.2.1.1.3.0 \n";
41
    exit 0;
42
}
43
44
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_uptime$/)
45
{
46
    $host  = $1;
47
    if ($host =~ /^([^:]+):(\d+)$/)
48
    {
49
	$host = $1;
50
	$port = $2;
51
    }
52
}
53
elsif (!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
if (defined $ARGV[0] and $ARGV[0] eq "config")
60
{
61
    print "host_name $host\n";
62
    print "graph_title Uptime
63
graph_category system
64
graph_args --base 1000 -l 0 
65
graph_vlabel uptime
66
graph_info This graph shows the uptime (in days) of the system.
67
uptime.label uptime
68
uptime.draw AREA
69
";
70
    exit 0;
71
}
72
73
my ($session, $error) = Net::SNMP->session(
74
     -hostname  => $host,
75
     -community => $community,
76
     -port      => $port,
77
     -translate => ['-timeticks']
78
    );
79
80
if (!defined ($session))
81
{
82
    die "Croaking: $error";
83
}
84
85
printf "uptime.value %.2f\n",  &get_single($session, "1.3.6.1.2.1.1.3.0");
86
87
sub get_single
88
{
89
    my $handle = shift;
90
    my $oid    = shift;
91
    
92
    print "# Getting single $oid...\n" if $DEBUG;
93
    
94
    
95
    $response = $handle->get_request($oid);
96
    
97
    if (!defined $response->{$oid})
98
    {
99
	return undef;
100
    }
101
    else
102
    {
103
	return (($response->{$oid}/100)/(60*60*24));
104
    }
105
}