Logoj0ke.net Open Build Service > Projects > server:monitoring > nagios-plugins-snmp > check_snmp_cisco_memutil
Sign Up | Log In

File check_snmp_cisco_memutil of Package nagios-plugins-snmp

x
 
1
#!/usr/bin/perl
2
# CVS: @(#): $Id: check_snmp_cisco_memutil,v 1.1 2005/11/07 16:23:16 jamespeel Exp $
3
#
4
# AUTHORS:
5
#   Copyright (C) 2004, 2005 Altinity Limited
6
#
7
#    This file is part of Opsview
8
#
9
#    Opsview is free software; you can redistribute it and/or modify
10
#    it under the terms of the GNU General Public License as published by
11
#    the Free Software Foundation; either version 2 of the License, or
12
#    (at your option) any later version.
13
#
14
#    Opsview is distributed in the hope that it will be useful,
15
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
16
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
#    GNU General Public License for more details.
18
#
19
#    You should have received a copy of the GNU General Public License
20
#    along with Opsview; if not, write to the Free Software
21
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
#
23
24
25
use lib qw ( /usr/local/nagios/lib );
26
use Net::SNMP;
27
use Getopt::Std;
28
29
$script    = "check_snmp_cisco_memutil";
30
$script_version = "2.1.0";
31
32
$metric = 1;
33
$oid_sysDescr = ".1.3.6.1.2.1.1.1.0";
34
$oid_mem5minUsed = "1.3.6.1.4.1.9.9.48.1.1.1.5.1";
35
$oid_mem5minFree = "1.3.6.1.4.1.9.9.48.1.1.1.6.1";
36
37
38
$ipaddress = "192.168.10.30";
39
$version = "1";
40
$community = "public";
41
$timeout = 2;
42
$warning = 90;
43
$critical = 95;
44
$status = 0;
45
$returnstring = "";
46
47
$configfilepath = "/etc/nagios";
48
49
# Do we have enough information?
50
if (@ARGV < 1) {
51
     print "Too few arguments\n";
52
     usage();
53
}
54
55
getopts("h:H:C:w:c:");
56
if ($opt_h){
57
    usage();
58
    exit(0);
59
}
60
if ($opt_H){
61
    $hostname = $opt_H;
62
    # print "Hostname $opt_H\n";
63
}
64
else {
65
    print "No hostname specified\n";
66
    usage();
67
}
68
if ($opt_C){
69
    $community = $opt_C;
70
    # print "Using community $opt_C\n";
71
}
72
else {
73
    # print "Using community $community\n";
74
}
75
if ($opt_w){
76
    $warning = $opt_w;
77
    # print "Warning threshold: $opt_w%\n";
78
}
79
if ($opt_c){
80
    $critical = $opt_c;
81
    # print "Critical threshold: $opt_c%\n";
82
}
83
84
85
# Create the SNMP session
86
my ($s, $e) = Net::SNMP->session(
87
     -community  =>  $community,
88
     -hostname   =>  $hostname,
89
     -version    =>  $version,
90
     -timeout    =>  $timeout,
91
);
92
93
main();
94
95
# Close the session
96
$s->close();
97
98
if ($returnstring eq ""){
99
    $status = 3;
100
}
101
102
if ($status == 0){
103
    print "Status is OK - $returnstring\n";
104
    # print "$returnstring\n";
105
}
106
elsif ($status == 1){
107
    print "Status is a WARNING level - $returnstring\n";
108
}
109
elsif ($status == 2){
110
    print "Status is CRITICAL - $returnstring\n";
111
}
112
else{
113
    print "Status is UNKNOWN\n";
114
}
115
 
116
exit $status;
117
118
####################################################################
119
# This is where we gather data via SNMP and return results         #
120
####################################################################
121
122
sub main {
123
124
    if (!defined($s->get_request($oid_mem5minUsed))) {
125
        if (!defined($s->get_request($oid_sysDescr))) {
126
            $returnstring = "SNMP agent not responding";
127
            $status = 1;
128
            return 1;
129
        }
130
        else {
131
            $returnstring = "SNMP OID does not exist";
132
            $status = 1;
133
            return 1;
134
        }
135
    }
136
     foreach ($s->var_bind_names()) {
137
         $mem5minused = $s->var_bind_list()->{$_};
138
    }
139
140
    if (!defined($s->get_request($oid_mem5minFree))) {
141
        if (!defined($s->get_request($oid_sysDescr))) {
142
            $returnstring = "SNMP agent not responding";
143
            $status = 1;
144
            return 1;
145
        }
146
        else {
147
            $returnstring = "SNMP OID does not exist";
148
            $status = 1;
149
            return 1;
150
        }
151
    }
152
     foreach ($s->var_bind_names()) {
153
         $mem5minfree = $s->var_bind_list()->{$_};
154
    }
155
    
156
    $memtotal = $mem5minused + $mem5minfree;
157
    $mempcused = ((100 / $memtotal) * $mem5minused);
158
    
159
    $temp = sprintf "MEMORY: total: %.2f MB, used: %.2f MB (%.0f%%), free: %.2f MB", ($memtotal / 1000000), ($mem5minused / 1000000), $mempcused, ($mem5minfree / 1000000);
160
    
161
    
162
    append($temp);
163
164
165
    if ($mempcused >= $warning){
166
        $status = 1;
167
    }
168
    if ($mempcused >= $critical){
169
        $status = 2;
170
    }
171
}
172
173
####################################################################
174
# help and usage information                                       #
175
####################################################################
176
177
sub usage {
178
    print << "USAGE";
179
--------------------------------------------------------------------     
180
$script v$script_version
181
182
Memory utilisation on Cisco devices
183
184
Usage: $script -H <hostname> -c <community> [...]
185
Options: -H         Hostname or IP address
186
                 -C         Community (default is public)
187
                 -w         Warning threshold (as %)
188
                 -c         Critical threshold (as %)
189
190
--------------------------------------------------------------------     
191
Copyright 2004 Altinity Limited  
192
     
193
This program is free software; you can redistribute it or modify
194
it under the terms of the GNU General Public License
195
--------------------------------------------------------------------
196
197
USAGE
198
     exit 1;
199
}
200
201
####################################################################
202
# Appends string to existing $returnstring                         #
203
####################################################################
204
205
sub append {
206
    my $appendstring =    @_[0];    
207
    $returnstring = "$returnstring$appendstring";
208
}
209
210
211