File check_cs121.pl of Package monitoring-plugins-cs121

#!/usr/bin/perl
# Author : Trevor Didlock
# Date : 26/08/2010
# check_temp_probe.pl IP COMMUNITY PROBE

sub print_usage {
    print "check_cs121.pl IP COMMUNITY OPTION warning critical\n";
	print "Options\n";
	print "=======\n";
	print "Load_Phase_1		Displays the load currently on phase 1\n";
	print "Load_Phase_2		Displays the load currently on phase 2\n";
	print "Load_Phase_3		Displays the load currently on phase 3\n";	
	print "UPS_Temp		Display the current UPS Temprature\n";
	print "Input_Voltage_1	Displays the Input Voltage on Line 1\n";
	print "Input_Voltage_2	Displays the Input Voltage on Line 2\n";
	print "Input_Voltage_3	Displays the Input Voltage on Line 3\n";
}

$PROGNAME = "check_cs121.pl";

if  ( @ARGV[0] eq "" || @ARGV[1] eq "" || @ARGV[2] eq "" || @ARGV[3] eq "" || @ARGV[4] eq "" ) {
    print_usage();
    exit 0;
}

$STATE_CRITICAL = 2;
$STATE_WARNING = 1;
$STATE_UNKNONW = 3;

$IP=@ARGV[0];
$COMMUNITY=@ARGV[1];
$OPTION=@ARGV[2];
$warning=@ARGV[3];
$critical=@ARGV[4];

if ( $OPTION eq "Load_Phase_1" ) {
	$resultat =`snmpwalk -v2c -c $COMMUNITY $IP .1.3.6.1.2.1.33.1.4.4.1.5.1`;
	@pourcentage = split (/"/,$resultat);
	$i=0;
	foreach ( @pourcentage ) {
		s/SNMPv2-SMI::mib-2.33.1.4.4.1.5.1 = INTEGER://g;		
		$use_total+=$_;
		$i++;
	}
	if ( $resultat ) {
		$use = $use_total;
		if ( $use < $warning ) {
			print "OK : Load on Phase 1 is $use%\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_OK;
		} elsif ( $use < $critical ) {
			print "WARNING : Load on Phase 1 is $use%\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_WARNING;
		} else {
			print "CRITICAL : Load on Phase 1 is $use%\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_CRITICAL;
		}
	} else {
		print "Unkonwn  : No response\n";
		exit $STATE_UNKNONW;
	}
}
if ( $OPTION eq "Load_Phase_2" ) {
	$resultat =`snmpwalk -v2c -c $COMMUNITY $IP .1.3.6.1.2.1.33.1.4.4.1.5.2`;
	@pourcentage = split (/"/,$resultat);
	$i=0;
	foreach ( @pourcentage ) {
		s/SNMPv2-SMI::mib-2.33.1.4.4.1.5.2 = INTEGER://g;		
		$use_total+=$_;
		$i++;
	}
	if ( $resultat ) {
		$use = $use_total;
		if ( $use < $warning ) {
			print "OK : Load on Phase 2 is $use%\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_OK;
		} elsif ( $use < $critical ) {
			print "WARNING : Load on Phase 2 is $use%\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_WARNING;
		} else {
			print "CRITICAL : Load on Phase 2 is $use%\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_CRITICAL;
		}
	} else {
		print "Unkonwn  : No response\n";
		exit $STATE_UNKNONW;
	}
}
if ( $OPTION eq "Load_Phase_3" ) {
	$resultat =`snmpwalk -v2c -c $COMMUNITY $IP .1.3.6.1.2.1.33.1.4.4.1.5.3`;
	@pourcentage = split (/"/,$resultat);
	$i=0;
	foreach ( @pourcentage ) {
		s/SNMPv2-SMI::mib-2.33.1.4.4.1.5.3 = INTEGER://g;		
		$use_total+=$_;
		$i++;
	}
	if ( $resultat ) {
		$use = $use_total;
		if ( $use < $warning ) {
			print "OK : Load on Phase 3 is $use%\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_OK;
		} elsif ( $use < $critical ) {
			print "WARNING : Load on Phase 3 is $use%\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_WARNING;
		} else {
			print "CRITICAL : Load on Phase 3 is $use%\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_CRITICAL;
		}
	} else {
		print "Unkonwn  : No response\n";
		exit $STATE_UNKNONW;
	}
}
if ( $OPTION eq "UPS_Temp" ) {
	$resultat =`snmpwalk -v2c -c $COMMUNITY $IP .1.3.6.1.2.1.33.1.2.7.0`;
	@pourcentage = split (/"/,$resultat);
	$i=0;
	foreach ( @pourcentage ) {
		s/SNMPv2-SMI::mib-2.33.1.2.7.0 = INTEGER://g;		
		$use_total+=$_;
		$i++;
	}
	if ( $resultat ) {
		$use = $use_total;
		if ( $use < $warning ) {
			print "OK : UPS Temprature is currently $use\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_OK;
		} elsif ( $use < $critical ) {
			print "WARNING : UPS Temprature is currently $use\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_WARNING;
		} else {
			print "CRITICAL : UPS Temprature is currently $use\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_CRITICAL;
		}
	} else {
		print "Unkonwn  : No response\n";
		exit $STATE_UNKNONW;
	}
}
if ( $OPTION eq "Input_Voltage_1" ) {
	$resultat =`snmpwalk -v2c -c $COMMUNITY $IP .1.3.6.1.2.1.33.1.3.3.1.3.1`;
	@pourcentage = split (/"/,$resultat);
	$i=0;
	foreach ( @pourcentage ) {
		s/SNMPv2-SMI::mib-2.33.1.3.3.1.3.1 = INTEGER://g;		
		$use_total+=$_;
		$i++;
	}
	if ( $resultat ) {
		$use = $use_total;
		if ( $use < $warning ) {
			print "OK : Input Voltage on Line 1 is currently $use\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_OK;
		} elsif ( $use < $critical ) {
			print "WARNING : Input Voltage on Line 1 is currently $use\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_WARNING;
		} else {
			print "CRITICAL : Input Voltage on Line 1 is currently $use\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_CRITICAL;
		}
	} else {
		print "Unkonwn  : No response\n";
		exit $STATE_UNKNONW;
	}
}
if ( $OPTION eq "Input_Voltage_2" ) {
	$resultat =`snmpwalk -v2c -c $COMMUNITY $IP .1.3.6.1.2.1.33.1.3.3.1.3.2`;
	@pourcentage = split (/"/,$resultat);
	$i=0;
	foreach ( @pourcentage ) {
		s/SNMPv2-SMI::mib-2.33.1.3.3.1.3.2 = INTEGER://g;		
		$use_total+=$_;
		$i++;
	}
	if ( $resultat ) {
		$use = $use_total;
		if ( $use < $warning ) {
			print "OK : Input Voltage on Line 2 is currently $use\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_OK;
		} elsif ( $use < $critical ) {
			print "WARNING : Input Voltage on Line 2 is currently $use\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_WARNING;
		} else {
			print "CRITICAL : Input Voltage on Line 2 is currently $use\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_CRITICAL;
		}
	} else {
		print "Unkonwn  : No response\n";
		exit $STATE_UNKNONW;
	}
}
if ( $OPTION eq "Input_Voltage_3" ) {
	$resultat =`snmpwalk -v2c -c $COMMUNITY $IP .1.3.6.1.2.1.33.1.3.3.1.3.3`;
	@pourcentage = split (/"/,$resultat);
	$i=0;
	foreach ( @pourcentage ) {
		s/SNMPv2-SMI::mib-2.33.1.3.3.1.3.3 = INTEGER://g;		
		$use_total+=$_;
		$i++;
	}
	if ( $resultat ) {
		$use = $use_total;
		if ( $use < $warning ) {
			print "OK : Input Voltage on Line 3 is currently $use\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_OK;
		} elsif ( $use < $critical ) {
			print "WARNING : Input Voltage on Line 3 is currently $use\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_WARNING;
		} else {
			print "CRITICAL : Input Voltage on Line 3 is currently $use\n | '$OPTION'=$use;$warning;$critical ";
			exit $STATE_CRITICAL;
		}
	} else {
		print "Unkonwn  : No response\n";
		exit $STATE_UNKNONW;
	}
}
openSUSE Build Service is sponsored by