Code

Fix for regex input of '|', being output causing problems with Nagios' parsing of
[nagiosplug.git] / contrib / check_netapp.pl
1 #!/usr/bin/perl -wT
2 # check_netapp
3
4 # Copyright (C) 2000  Leland E. Vandervort <leland@mmania.com>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty
13 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # you should have received a copy of the GNU General Public License
17 # along with this program (or with Nagios);  if not, write to the
18 # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
19 # Boston, MA 02111-1307, USA
20 ####################################
21 # checks for overtemperature, fans, psu, and nfs operations/second on
22 # Network Appliance Filers.  
23 # Returns:  
24 #  OK if temp, fans, psu OK and Ops/Sec below warning and critical
25 #   Thresholds (default is warning=3500, critical=5000)  
26 #    ** Note:  See the specifications for your Filer model for 
27 #       the thresholds !
28 #  Returns Warning if NFS Ops/Sec is above warning threshold
29 #    (default 3500, or specified by -o command line option)
30 #  Returns Critical if NFS Ops/Sec is above critical threshold
31 #    ( -m option, or default 5000), or if overtem, psufault, or
32 #    fanfault detected.
33 #
34 ####################################
35 #  Notes on operational limits for NetApp Filers:
36 #   Platform                     Maximum Ops/Second (recommended)
37 #   -------------------------------------------------------------
38 #   F230                         1000
39 #   F740                         5500
40 #   F760                         9000
41 ####################################
43 use Net::SNMP;
44 use Getopt::Long;
45 &Getopt::Long::config('auto_abbrev');
47 my $status;
48 my $response = "";
49 my $TIMEOUT = 10;
50 my $community = "public";
51 my $port = 161;
52 my $opsthresh = "3500";
53 my $critical = "5000";
55 my $status_string = "";
57 my %OIDLIST = (
58                 overtemp        =>      '1.3.6.1.4.1.789.1.2.4.1.0',
59                 failedfan       =>      '1.3.6.1.4.1.789.1.2.4.2.0',
60                 failedpsu       =>      '1.3.6.1.4.1.789.1.2.4.4.0',
61                 nfsops          =>      '1.3.6.1.4.1.789.1.2.2.1.0'
62               );
66 my %STATUSCODE = (  'UNKNOWN' => '-1',
67                     'OK' => '0',
68                     'WARNING' => '1',
69                     'CRITICAL' => '2');
71 my $state = "UNKNOWN";
74 $SIG{'ALRM'} = sub {
75     print "ERROR: No snmp response from $hostname (sigALRM)\n";
76     exit($STATUSCODE{"UNKNOWN"});
77 };
79 alarm($TIMEOUT);                    
81 sub get_nfsops {
82         my $nfsops_start = &SNMPGET($OIDLIST{nfsops});
83         sleep(1);
84         my $nfsops_end = &SNMPGET($OIDLIST{nfsops});
85         my $nfsopspersec = $nfsops_end - $nfsops_start;
86         return($nfsopspersec);
87 }
90 sub show_help {
91     printf("\nPerl NetApp filer plugin for Nagios\n");
92     printf("Usage:\n");
93     printf("
94   check_netapp [options] <hostname>
95   Options:
96     -c snmp-community
97     -p snmp-port
98     -o Operations per second warning threshold 
99     -m Operations per second critical threshold
101 ");
102     printf("Copyright (C)2000 Leland E. Vandervort\n");
103     printf("check_netapp comes with absolutely NO WARRANTY either implied or explicit\n");
104     printf("This program is licensed under the terms of the\n");
105     printf("GNU General Public License\n(check source code for details)\n\n\n");
106     exit($STATUSCODE{"UNKNOWN"});
108  
110 $status = GetOptions( "community=s", \$community,
111                       "port=i",      \$port,
112                       "opsthresh=i", \$opsthresh,
113                       "maxops=i",    \$critical );
114                      
115 if($status == 0) {
116     &show_help;
119 sub SNMPGET {
120     $OID = shift;
121     ($session,$error) = Net::SNMP->session(
122         Hostname        =>      $hostname,
123         Community       =>      $community,
124         Port            =>      $port
125         );
126     if(!defined($session)) {
127         printf("$state %s\n", $error);
128         exit($STATUSCODE{$state});
129     }
130     if(!defined($response = $session->get_request($OID))) {
131         printf("$state %s\n", $session->error());
132         $session->close();
133         exit($STATUSCODE{$state});
134     }
135     $session->close();
136     return($response->{$OID});
139 $hostname = shift || &show_help;
141 my $tempcheck = &SNMPGET($OIDLIST{overtemp});
142 if($tempcheck == 1) {
143         $state = "OK";
144         $status_string .= "Temp OK ";
146 else {
147         $state = "CRITICAL";
148         $status_string .= "Temp CRIT";
151 foreach $element ('failedfan','failedpsu') {
152         my $my_return = &SNMPGET($OIDLIST{$element});
153         if(($my_return =~ /no/) || ($my_return == 0)) {
154                 $status_string .= "$element = $my_return ";
155                 $state = "OK";
156         }
157         else {
158                 $status_string .= "$element = $my_return ";
159                 $state = "CRITICAL";
160         }
163 my $tmp_opssec = &get_nfsops();
165 if ($tmp_opssec >= $critical) {
166         $state = "CRITICAL";
168 elsif ($tmp_opssec >= $opsthresh) {
169         $state = "WARNING";
171 else {
172         $state = "OK";
175 $status_string .= "Ops\/Sec = $tmp_opssec ";
177 print "$state $status_string\n";
178 exit($STATUSCODE{$state});