diff options
author | Christian Pointner <equinox@spreadspace.org> | 2013-03-26 14:28:46 +0000 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2013-03-26 14:28:46 +0000 |
commit | f1250ae5d6ac8435cd0d16fe8925e686500b8480 (patch) | |
tree | d9ecf5db5f67bcdf2da7ce56f9147f449afcace5 /ats-watch/ats-watch.pl | |
parent | fixed LUFA_BOARD (diff) |
added scripts to monitor output of ats-watch
git-svn-id: https://svn.spreadspace.org/avr/trunk@204 aa12f405-d877-488e-9caf-2d797e2a1cc7
Diffstat (limited to 'ats-watch/ats-watch.pl')
-rwxr-xr-x | ats-watch/ats-watch.pl | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/ats-watch/ats-watch.pl b/ats-watch/ats-watch.pl new file mode 100755 index 0000000..f374295 --- /dev/null +++ b/ats-watch/ats-watch.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl -w + +use strict; +use Device::SerialPort; +use Mail::Sendmail; + +my $port = new Device::SerialPort("/dev/ats-watch"); +$port->baudrate(38400); +$port->parity("none"); +$port->databits(8); +$port->stopbits(1); +$port->handshake("none"); +$port->read_const_time(500); +$port->read_char_time(5); +$port->write_settings; + +$port->lookclear; +$port->write("s"); + +my %mail = ( To => 'logs@helsinki.at', + From => 'noreply@helsinki.at', + ); + +while(1) { + my ($count, $line) = $port->read(100); + if($count > 0) { + if($line =~ /Status: (\w+), Input (\w) is selected \(A: (\w+), B: (\w+)\)/) { + my $state = $1; + if($3 ne 'Online' && $4 ne 'Online') { + $state = 'critical'; + } elsif($3 ne 'Online' || $4 ne 'Online') { + $state = 'degraded'; + } + $mail{Subject} = "[ATS-Watch] PDU0 state $state"; + $mail{Message} = "Current State: $1\n" . "Current Input: $2\n" . "Input A: $3\n" . "Input B: $4\n"; + } else { + $mail{Subject} = '[ATS-Watch] PDU0 state unknown'; + $mail{Message} = $line; + } + sendmail( %mail ) or print $Mail::Sendmail::error . "\n"; + } +} |