diff --git a/upscheck/upscheck b/upscheck/upscheck new file mode 100644 index 0000000..8890ffc --- /dev/null +++ b/upscheck/upscheck @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +use LWP::Simple; + +my %ups; +my $content = get("http://intra.wsr.ac.at/informationssysteme/ups/"); +for my $line (split(/\n/, $content)) { + my ($oid, $value) = split(/\t/, $line); + $ups{$oid} = $value; +} + +if (!defined $ups{'UPS-MIB::upsEstimatedMinutesRemaining.0'} || + !defined $ups{'UPS-MIB::upsEstimatedChargeRemaining.0'} +) { + die "can't get current charge"; +} + +my $min_minutes = rand(10) + 5; +my $min_charge = rand(10) + 5; + +if ($ups{'UPS-MIB::upsEstimatedMinutesRemaining.0'} < $min_minutes || + $ups{'UPS-MIB::upsEstimatedChargeRemaining.0'} < $min_charge +) { + print STDERR "charge low: shutting down\n"; + system("/sbin/shutdown", "-h", "+1"); +}