summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2013-03-26 14:28:46 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-02-24 19:18:26 (GMT)
commit1394683c55854592aa731b8c76d451b76fe2dbfd (patch)
treee4ab0bdc978ff0932becfad12567d0593751c627
parent5a3da44e1e41cc7cc7c3f08385541346acca8855 (diff)
added scripts to monitor output of ats-watch
-rw-r--r--ats-watch/99_ats-watch.rules3
-rwxr-xr-xats-watch/ats-watch.pl42
2 files changed, 45 insertions, 0 deletions
diff --git a/ats-watch/99_ats-watch.rules b/ats-watch/99_ats-watch.rules
new file mode 100644
index 0000000..11a67da
--- /dev/null
+++ b/ats-watch/99_ats-watch.rules
@@ -0,0 +1,3 @@
+# /etc/udev/rules.d/99_ats-watch.rules
+
+SUBSYSTEMS=="usb", KERNEL=="ttyACM*", ATTRS{product}=="ats-watch", SYMLINK+="ats-watch"
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";
+ }
+}