#!/usr/bin/perl
# Author : Roderick Derks (roderick@r71.nl)
# Rewrite for IBM 2005 B16 by Core Competence IT (marco@ccit.nl)
# Date : 01/11/2008
# check_snmp_brocade
#
# supported types: IBM_2005_B16
##########################################################


# globale variabelen:
use vars qw($opt_h $opt_H $opt_C $opt_g);
use Getopt::Std;

#&getopts("h:H:C:t:p:a:b:c:d:g")||die "ERROR: Onbekende optie. -help voor help\n";
&getopts("h:H:C:t:g")||die "ERROR: Onbekende optie. -help voor help\n";
if ($opt_h) { 
    &print_usage;
   }

sub print_usage {
    print "check_snmp_brocade -H [ IP|HOSTNAME ] -C SNMPCOMMUNITY\n";
    exit $STATE_UNKNOWN;
}

$PROGNAME = "check_snmp_brocade";

$STATE_CRITICAL = 2;
$STATE_WARNING = 1;
$STATE_UNKNOWN = 3;
$STATE_OK = 0;

$IP=$opt_H;
$COMMUNITY=$opt_C;

$type		=`snmpwalk -v 1 -c $COMMUNITY $IP SNMPv2-SMI::mib-2.47.1.1.1.1.2.1`;
chomp $type;
$type		=~s/SNMPv2-SMI::mib-2.47.1.1.1.1.2.1 = STRING: //g;
$type		=~s/\"//g;
if ( $type eq IBM_2005_B16) 
{ 
$result_01	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.1`;
$result_02	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.2`;
$result_03	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.3`;
$result_04	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.4`;
$result_05	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.5`;
$result_06	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.1`;
$result_07	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.2`;
$result_08	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.3`;
$result_09	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.4`;
$result_10	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.5`;
$result_11	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.6`;

chomp $result_01;
chomp $result_02;
chomp $result_03;
chomp $result_04;
chomp $result_05;
chomp $result_06;
chomp $result_07;
chomp $result_08;
chomp $result_09;
chomp $result_10;
chomp $result_11;

 $result_temp_probe1    =$result_01;
 $result_temp_probe2    =$result_02;
 $result_rpm_fan1       =$result_03;
 $result_rpm_fan2       =$result_04;
 $result_rpm_fan3       =$result_05;
 $status_temp_probe1    =$result_06;
 $status_temp_probe2    =$result_07;
 $status_rpm_fan1       =$result_08;
 $status_rpm_fan2       =$result_09;
 $status_rpm_fan3       =$result_10;
 $status_powersupply1   =$result_11;

 # FILTER
 if ( $result_temp_probe1 ) {
      $result_temp_probe1 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.1 = INTEGER: //g;
    }
 else {
    print "Unknown  : No response while querying for the temperature of probe 1 of $IP\n";
    exit $STATE_UNKNOWN;
 }
 if ( $result_temp_probe2 ) {
      $result_temp_probe2 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.2 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature of probe 2 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $result_rpm_fan1 ) {
      $result_rpm_fan1 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.3 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm of fan 1 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $result_rpm_fan2 ) {
      $result_rpm_fan2 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.4 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm of fan 2 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $result_rpm_fan3 ) {
     $result_rpm_fan3 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.5 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm of fan 3 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_temp_probe1 ) {
      $status_temp_probe1 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.1 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature status of probe 1 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_temp_probe2 ) {
      $status_temp_probe2 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.2 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature status of probe 2 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_rpm_fan1 ) {
      $status_rpm_fan1 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.3 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm status of fan 1 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_rpm_fan2 ) {
      $status_rpm_fan2 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.4 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm status of fan 2 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_rpm_fan3 ) {
      $status_rpm_fan3 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.5 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm status of fan 3 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_powersupply1 ) {
      $status_powersupply1 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.6 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the status of power supply 1 of $IP\n";
     exit $STATE_UNKNOWN;
 }


 $OUTPUT="Probe1: $result_temp_probe1 degr - Probe2: $result_temp_probe2 degr - fan1: $result_rpm_fan1 rpm - fan2: $result_rpm_fan2 rpm - fan3: $result_rpm_fan3 rpm |TEMP_PROBE1=$result_temp_probe1 TEMP_PROBE2=$result_temp_probe2 RPM_FAN1=$result_rpm_fan1 RPM_FAN2=$result_rpm_fan2 RPM_FAN3=$result_rpm_fan3";

 if ( $status_temp_probe1 == 4 and $status_temp_probe2 == 4 and $status_rpm_fan1 == 4 and $status_rpm_fan2 == 4 and $status_rpm_fan3 == 4 and $status_powersupply1 == 4 ) {
    print "Overall status switch is HEALTHY. $OUTPUT\n";
    exit $STATE_OK;
   }
else {
    print "Overall switch status NOT HEALTHY, problems with a fan or a powersupply. To check the switch go to: http://$IP -- $OUTPUT\n";
    exit $STATE_CRITICAL;
    }

}
elsif ( $type eq IBM_2005_B32)
{
$result_01	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.1`;
$result_02	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.2`;
$result_03	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.3`;
$result_04	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.4`;
$result_05	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.5`;
$result_06	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.6`;
$result_07	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.7`;
$result_08	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.8`;

$result_09	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.1`;
$result_10	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.2`;
$result_11	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.3`;
$result_12	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.4`;
$result_13	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.5`;
$result_14	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.6`;
$result_15	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.7`;
$result_16	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.8`;
$result_17	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.9`;
$result_18	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.10`;

# Temperature
chomp $result_01;
chomp $result_02;
chomp $result_03;
chomp $result_04;
chomp $result_05;

#Fan
chomp $result_06;
chomp $result_07;
chomp $result_08;

#State
chomp $result_09;
chomp $result_10;
chomp $result_11;
chomp $result_12;
chomp $result_13;
chomp $result_14;
chomp $result_15;
chomp $result_16;
chomp $result_17;
chomp $result_18;


 $result_temp_probe1    =$result_01;
 $result_temp_probe2    =$result_02;
 $result_temp_probe3    =$result_03;
 $result_temp_probe4    =$result_04;
 $result_temp_probe5    =$result_05;
  
 $result_rpm_fan1       =$result_06;
 $result_rpm_fan2       =$result_07;
 $result_rpm_fan3       =$result_08;
 
 $status_temp_probe1    =$result_09;
 $status_temp_probe2    =$result_10;
 $status_temp_probe3    =$result_11;
 $status_temp_probe4    =$result_12;
 $status_temp_probe5    =$result_13;
 $status_rpm_fan1       =$result_14;
 $status_rpm_fan2       =$result_15;
 $status_rpm_fan3       =$result_16;
 $status_powersupply1   =$result_17;
 $status_powersupply2   =$result_18;

 # FILTER
 if ( $result_temp_probe1 ) {
      $result_temp_probe1 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.1 = INTEGER: //g;
    }
 else {
    print "Unknown  : No response while querying for the temperature of probe 1 of $IP\n";
    exit $STATE_UNKNOWN;
 }
 if ( $result_temp_probe2 ) {
      $result_temp_probe2 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.2 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature of probe 2 of $IP\n";
     exit $STATE_UNKNOWN;
 }
  if ( $result_temp_probe3 ) {
      $result_temp_probe3 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.3 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature of probe 3 of $IP\n";
     exit $STATE_UNKNOWN;
 }
  if ( $result_temp_probe4 ) {
      $result_temp_probe4 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.4 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature of probe 4 of $IP\n";
     exit $STATE_UNKNOWN;
 }
   if ( $result_temp_probe5 ) {
      $result_temp_probe5 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.5 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature of probe 5 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $result_rpm_fan1 ) {
      $result_rpm_fan1 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.6 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm of fan 1 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $result_rpm_fan2 ) {
      $result_rpm_fan2 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.7 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm of fan 2 of $IP\n";
     exit $STATE_UNKNOWN;
 }
  if ( $result_rpm_fan3 ) {
      $result_rpm_fan3 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.8 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm of fan 3 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_temp_probe1 ) {
      $status_temp_probe1 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.1 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature status of probe 1 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_temp_probe2 ) {
      $status_temp_probe2 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.2 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature status of probe 2 of $IP\n";
     exit $STATE_UNKNOWN;
 }
  if ( $status_temp_probe3 ) {
      $status_temp_probe3 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.3 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature status of probe 3 of $IP\n";
     exit $STATE_UNKNOWN;
 }
  if ( $status_temp_probe4 ) {
      $status_temp_probe4 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.4 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature status of probe 4 of $IP\n";
     exit $STATE_UNKNOWN;
 }
   if ( $status_temp_probe5 ) {
      $status_temp_probe5 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.5 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature status of probe 5 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_rpm_fan1 ) {
      $status_rpm_fan1 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.6 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm status of fan 1 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_rpm_fan2 ) {
      $status_rpm_fan2 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.7 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm status of fan 2 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_rpm_fan3 ) {
      $status_rpm_fan3 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.8 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm status of fan 8 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_powersupply1 ) {
      $status_powersupply1 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.9 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the status of power supply 1 of $IP\n";
     exit $STATE_UNKNOWN;
 }
  if ( $status_powersupply2 ) {
      $status_powersupply2 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.10 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the status of power supply 2 of $IP\n";
     exit $STATE_UNKNOWN;
 }


 $OUTPUT="Probe1: $result_temp_probe1 degr - Probe2: $result_temp_probe2 degr - Probe3: $result_temp_probe3 degr - Probe4: $result_temp_probe4 degr - Probe5: $result_temp_probe5 degr - fan1: $result_rpm_fan1 rpm - fan2: $result_rpm_fan2 rpm - fan3: $result_rpm_fan3 rpm|TEMP_PROBE1=$result_temp_probe1 TEMP_PROBE2=$result_temp_probe2 TEMP_PROBE3=$result_temp_probe3 TEMP_PROBE4=$result_temp_probe4 TEMP_PROBE5=$result_temp_probe5 RPM_FAN1=$result_rpm_fan1 RPM_FAN2=$result_rpm_fan2 RPM_FAN3=$result_rpm_fan3";

 if ( $status_temp_probe1 == 4 and $status_temp_probe2 == 4 and $status_temp_probe3 == 4 and $status_temp_probe4 == 4 and $status_temp_probe5 == 4 and $status_rpm_fan1 == 4 and $status_rpm_fan2 == 4 and $status_rpm_fan3 == 4 and $status_powersupply1 == 4 and $status_powersupply2 == 4) {
    print "Overall status switch is HEALTHY. $OUTPUT\n";
    exit $STATE_OK;
   }
else {
    print "Overall switch status NOT HEALTHY, problems with a fan or a powersupply. To check the switch go to: http://$IP -- $OUTPUT\n";
    exit $STATE_CRITICAL;
    }
}
elsif ( $type eq IBM_2005_B5K)
{
$result_01	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.1`;
$result_02	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.2`;
$result_03	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.3`;
$result_04	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.4`;
$result_05	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.5`;
$result_06	=`snmpwalk -v 1 -c $COMMUNITY $IP 1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.6`;

$result_07	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.1`;
$result_08	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.2`;
$result_09	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.3`;
$result_10	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.4`;
$result_11	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.5`;
$result_12	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.6`;
$result_13	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.7`;
$result_14	=`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.1588.2.1.1.1.1.22.1.3.8`;

# Temperature
chomp $result_01;
chomp $result_02;
chomp $result_03;
chomp $result_04;

#Fan
chomp $result_05;
chomp $result_06;

#State
chomp $result_07;
chomp $result_08;
chomp $result_09;
chomp $result_10;
chomp $result_11;
chomp $result_12;
chomp $result_13;
chomp $result_14;


 $result_temp_probe1    =$result_01;
 $result_temp_probe2    =$result_02;
 $result_temp_probe3    =$result_03;
 $result_temp_probe4    =$result_04;
   
 $result_rpm_fan1       =$result_05;
 $result_rpm_fan2       =$result_06;
  
 $status_temp_probe1    =$result_07;
 $status_temp_probe2    =$result_08;
 $status_temp_probe3    =$result_09;
 $status_temp_probe4    =$result_10;
 $status_rpm_fan1       =$result_11;
 $status_rpm_fan2       =$result_12;
 $status_powersupply1   =$result_13;
 $status_powersupply2   =$result_14;

 # FILTER
 if ( $result_temp_probe1 ) {
      $result_temp_probe1 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.1 = INTEGER: //g;
    }
 else {
    print "Unknown  : No response while querying for the temperature of probe 1 of $IP\n";
    exit $STATE_UNKNOWN;
 }
 if ( $result_temp_probe2 ) {
      $result_temp_probe2 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.2 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature of probe 2 of $IP\n";
     exit $STATE_UNKNOWN;
 }
  if ( $result_temp_probe3 ) {
      $result_temp_probe3 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.3 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature of probe 3 of $IP\n";
     exit $STATE_UNKNOWN;
 }
  if ( $result_temp_probe4 ) {
      $result_temp_probe4 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.4 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature of probe 4 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $result_rpm_fan1 ) {
      $result_rpm_fan1 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.5 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm of fan 1 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $result_rpm_fan2 ) {
      $result_rpm_fan2 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.4.6 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm of fan 2 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_temp_probe1 ) {
      $status_temp_probe1 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.1 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature status of probe 1 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_temp_probe2 ) {
      $status_temp_probe2 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.2 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature status of probe 2 of $IP\n";
     exit $STATE_UNKNOWN;
 }
  if ( $status_temp_probe3 ) {
      $status_temp_probe3 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.3 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature status of probe 3 of $IP\n";
     exit $STATE_UNKNOWN;
 }
  if ( $status_temp_probe4 ) {
      $status_temp_probe4 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.4 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the temperature status of probe 4 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_rpm_fan1 ) {
      $status_rpm_fan1 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.5 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm status of fan 1 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_rpm_fan2 ) {
      $status_rpm_fan2 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.6 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the rpm status of fan 2 of $IP\n";
     exit $STATE_UNKNOWN;
 }
 if ( $status_powersupply1 ) {
      $status_powersupply1 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.7 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the status of power supply 1 of $IP\n";
     exit $STATE_UNKNOWN;
 }
  if ( $status_powersupply2 ) {
      $status_powersupply2 =~s/SNMPv2-SMI::enterprises.1588.2.1.1.1.1.22.1.3.8 = INTEGER: //g;
    }
 else {
     print "Unknown  : No response while querying for the status of power supply 2 of $IP\n";
     exit $STATE_UNKNOWN;
 }


 $OUTPUT="Probe1: $result_temp_probe1 degr - Probe2: $result_temp_probe2 degr - Probe3: $result_temp_probe3 degr - Probe4: $result_temp_probe4 degr - fan1: $result_rpm_fan1 rpm - fan2: $result_rpm_fan2 rpm|TEMP_PROBE1=$result_temp_probe1 TEMP_PROBE2=$result_temp_probe2 TEMP_PROBE3=$result_temp_probe3 TEMP_PROBE4=$result_temp_probe4 TEMP_PROBE5=$result_temp_probe5 RPM_FAN1=$result_rpm_fan1 RPM_FAN2=$result_rpm_fan2";

 if ( $status_temp_probe1 == 4 and $status_temp_probe2 == 4 and $status_temp_probe3 == 4 and $status_temp_probe4 == 4 and $status_rpm_fan1 == 4 and $status_rpm_fan2 == 4 and $status_powersupply1 == 4 and $status_powersupply2 == 4) {
    print "Overall status switch is HEALTHY. $OUTPUT\n";
    exit $STATE_OK;
   }
else {
    print "Overall switch status NOT HEALTHY, problems with a fan or a powersupply. To check the switch go to: http://$IP -- $OUTPUT\n";
    exit $STATE_CRITICAL;
    }
}
# status results:
# 1 unknown
# 2 faulty
# 3 below-min
# 4 nominal
# 5 above-max
# 6 absent
# For Temperature, valid values include 3 (below-min), 4 (nominal), and 5 (above-max).
# For Fan, valid values include 3 (below-min), 4 (nominal), and 6 (absent).
# For Power Supply, valid values include 2 (faulty), 4 (nominal), and 6 (absent).

# folowing code just to test
# $status_powersupply2 = 3;
# print "$result_temp_fan1 $result_temp_fan2 $result_temp_fan3 $result_rpm_fan1 $result_rpm_fan2 $result_rpm_fan3 $status_temp_fan1 $status_temp_fan2 $status_temp_fan3 $status_rpm_fan1 $status_rpm_fan2 $status_rpm_fan3 $status_powersupply1 $status_powersupply2\n";