4
# Licensed to the Apache Software Foundation (ASF) under one
5
# or more contributor license agreements. See the NOTICE file
6
# distributed with this work for additional information
7
# regarding copyright ownership. The ASF licenses this file
8
# to you under the Apache License, Version 2.0 (the
9
# "License"); you may not use this file except in compliance
10
# with the License. You may obtain a copy of the License at
12
# http://www.apache.org/licenses/LICENSE-2.0
14
# Unless required by applicable law or agreed to in writing,
15
# software distributed under the License is distributed on an
16
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
# KIND, either express or implied. See the License for the
18
# specific language governing permissions and limitations
27
my $base_proc = "1.3.6.1.2.1.25.3.3.1";
28
my $proc_load = "1.3.6.1.2.1.25.3.3.1.2";
30
my $o_community = undef;
37
print "Usage: $0 -H <host> -C <snmp_community> -w <warn level> -c <crit level>\n";
40
Getopt::Long::Configure ("bundling");
43
'C:s' => \$o_community,
47
if (!defined $o_host || !defined $o_community || !defined $o_crit || !defined $o_warn) {
55
print "Unable to contact host: $o_host\n";
61
($session, $error) = Net::SNMP->session(
63
-community => $o_community,
65
-timeout => $o_timeout
67
if (!defined($session)) {
68
printf("Error opening session: %s.\n", $error);
73
my $resultat = (Net::SNMP->VERSION < 4) ?
74
$session->get_table($base_proc)
75
: $session->get_table(Baseoid => $base_proc);
77
if (!defined($resultat)) {
78
printf("ERROR: Description table : %s.\n", $session->error);
85
my ($cpu_used,$ncpu)=(0,0);
86
foreach my $key ( keys %$resultat) {
87
if ($key =~ /$proc_load/) {
88
$cpu_used += $$resultat{$key};
94
print "Can't find CPU usage information : UNKNOWN\n";
100
print "$ncpu CPU, ", $ncpu==1 ? "load" : "average load";
101
printf(" %.1f%%",$cpu_used);
104
if ($cpu_used > $o_crit) {
105
print " > $o_crit% : CRITICAL\n";
108
if ($cpu_used > $o_warn) {
109
print " > $o_warn% : WARNING\n";
113
print " < $o_warn% : OK\n" if ($exit_val eq 0);