diff options
author | Ethan Galstad <egalstad@users.sourceforge.net> | 2002-02-28 06:42:51 +0000 |
---|---|---|
committer | Ethan Galstad <egalstad@users.sourceforge.net> | 2002-02-28 06:42:51 +0000 |
commit | 44a321cb8a42d6c0ea2d96a1086a17f2134c89cc (patch) | |
tree | a1a4d9f7b92412a17ab08f34f04eec45433048b7 /contrib/check_ifoperstatus.pl | |
parent | 54fd5d7022ff2d6a59bc52b8869182f3fc77a058 (diff) | |
download | monitoring-plugins-44a321cb8a42d6c0ea2d96a1086a17f2134c89cc.tar.gz |
Initial revision
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'contrib/check_ifoperstatus.pl')
-rw-r--r-- | contrib/check_ifoperstatus.pl | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/contrib/check_ifoperstatus.pl b/contrib/check_ifoperstatus.pl new file mode 100644 index 00000000..3f21cddd --- /dev/null +++ b/contrib/check_ifoperstatus.pl | |||
@@ -0,0 +1,145 @@ | |||
1 | #!/usr/bin/perl -w | ||
2 | # | ||
3 | # check_ifoperstatus.pl - nagios plugin | ||
4 | # | ||
5 | # | ||
6 | # | ||
7 | # | ||
8 | # Copyright (C) 2000 Christoph Kron | ||
9 | # | ||
10 | # This program is free software; you can redistribute it and/or | ||
11 | # modify it under the terms of the GNU General Public License | ||
12 | # as published by the Free Software Foundation; either version 2 | ||
13 | # of the License, or (at your option) any later version. | ||
14 | # | ||
15 | # This program is distributed in the hope that it will be useful, | ||
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | # GNU General Public License for more details. | ||
19 | # | ||
20 | # You should have received a copy of the GNU General Public License | ||
21 | # along with this program; if not, write to the Free Software | ||
22 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
23 | # | ||
24 | # | ||
25 | # Report bugs to: ck@zet.net | ||
26 | # | ||
27 | # 11.01.2000 Version 1.0 | ||
28 | |||
29 | use strict; | ||
30 | |||
31 | use Net::SNMP; | ||
32 | use Getopt::Long; | ||
33 | &Getopt::Long::config('auto_abbrev'); | ||
34 | |||
35 | |||
36 | my $status; | ||
37 | my $TIMEOUT = 15; | ||
38 | |||
39 | my %ERRORS = ('UNKNOWN' , '-1', | ||
40 | 'OK' , '0', | ||
41 | 'WARNING', '1', | ||
42 | 'CRITICAL', '2'); | ||
43 | |||
44 | my %ifOperStatus = ('1','up', | ||
45 | '2','down', | ||
46 | '3','testing', | ||
47 | '4','unknown', | ||
48 | '5','dormant', | ||
49 | '6','notPresent'); | ||
50 | |||
51 | my $state = "UNKNOWN"; | ||
52 | my $answer = ""; | ||
53 | my $snmpkey = 1; | ||
54 | my $community = "public"; | ||
55 | my $port = 161; | ||
56 | my @snmpoids; | ||
57 | my $snmpIfOperStatus; | ||
58 | my $snmpLocIfDescr; | ||
59 | my $hostname; | ||
60 | my $session; | ||
61 | my $error; | ||
62 | my $response; | ||
63 | |||
64 | |||
65 | sub usage { | ||
66 | printf "\nMissing arguments!\n"; | ||
67 | printf "\n"; | ||
68 | printf "Perl Check IfOperStatus plugin for Nagios\n"; | ||
69 | printf "checks operational status of specified interface\n"; | ||
70 | printf "usage: \n"; | ||
71 | printf "ifoperstatus.pl -k <IF_KEY> -c <READCOMMUNITY> -p <PORT> <HOSTNAME>"; | ||
72 | printf "\nCopyright (C) 2000 Christoph Kron\n"; | ||
73 | printf "check_ifoperstatus.pl comes with ABSOLUTELY NO WARRANTY\n"; | ||
74 | printf "This programm is licensed under the terms of the "; | ||
75 | printf "GNU General Public License\n(check source code for details)\n"; | ||
76 | printf "\n\n"; | ||
77 | exit $ERRORS{"UNKNOWN"}; | ||
78 | } | ||
79 | |||
80 | # Just in case of problems, let's not hang Nagios | ||
81 | $SIG{'ALRM'} = sub { | ||
82 | print ("ERROR: No snmp response from $hostname (alarm)\n"); | ||
83 | exit $ERRORS{"UNKNOWN"}; | ||
84 | }; | ||
85 | alarm($TIMEOUT); | ||
86 | |||
87 | |||
88 | $status = GetOptions("key=i",\$snmpkey, | ||
89 | "community=s",\$community, | ||
90 | "port=i",\$port); | ||
91 | if ($status == 0) | ||
92 | { | ||
93 | &usage; | ||
94 | } | ||
95 | |||
96 | #shift; | ||
97 | $hostname = shift || &usage; | ||
98 | |||
99 | ($session, $error) = Net::SNMP->session( | ||
100 | -hostname => $hostname, | ||
101 | -community => $community, | ||
102 | -port => $port | ||
103 | ); | ||
104 | |||
105 | if (!defined($session)) { | ||
106 | $state='UNKNOWN'; | ||
107 | $answer=$error; | ||
108 | print ("$state: $answer"); | ||
109 | exit $ERRORS{$state}; | ||
110 | } | ||
111 | |||
112 | $snmpIfOperStatus = '1.3.6.1.2.1.2.2.1.8' . "." . $snmpkey; | ||
113 | $snmpLocIfDescr = '1.3.6.1.4.1.9.2.2.1.1.28' . "." . $snmpkey; | ||
114 | |||
115 | |||
116 | push(@snmpoids,$snmpIfOperStatus); | ||
117 | push(@snmpoids,$snmpLocIfDescr); | ||
118 | |||
119 | if (!defined($response = $session->get_request(@snmpoids))) { | ||
120 | $answer=$session->error; | ||
121 | $session->close; | ||
122 | $state = 'CRITICAL'; | ||
123 | print ("$state: $answer,$community,$snmpkey"); | ||
124 | exit $ERRORS{$state}; | ||
125 | } | ||
126 | |||
127 | $answer = sprintf("host '%s',%s(%s) is %s\n", | ||
128 | $hostname, | ||
129 | $response->{$snmpLocIfDescr}, | ||
130 | $snmpkey, | ||
131 | $ifOperStatus{$response->{$snmpIfOperStatus}} | ||
132 | ); | ||
133 | |||
134 | $session->close; | ||
135 | |||
136 | if ( $response->{$snmpIfOperStatus} == 1 ) { | ||
137 | $state = 'OK'; | ||
138 | } | ||
139 | else { | ||
140 | $state = 'CRITICAL'; | ||
141 | } | ||
142 | |||
143 | print ("$state: $answer"); | ||
144 | exit $ERRORS{$state}; | ||
145 | |||