summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason D. McCormick <jason@mfamily.org>2020-04-07 14:21:55 -0400
committerJason D. McCormick <jason@mfamily.org>2020-04-07 14:21:55 -0400
commit514767dc3e5f8ee03d8f3d0e62daca512bfe7f0e (patch)
treeaf2610a94748d812ec8052e84a82c5c7f9539ca0
parent77fe087b2edc25a90361ea80691530f376e2dc46 (diff)
reorg and add allster
-rwxr-xr-xallstar/allstar-monitor87
-rw-r--r--allstar/allstar-monitor.crond5
2 files changed, 92 insertions, 0 deletions
diff --git a/allstar/allstar-monitor b/allstar/allstar-monitor
new file mode 100755
index 0000000..f3be769
--- /dev/null
+++ b/allstar/allstar-monitor
@@ -0,0 +1,87 @@
+#!/usr/bin/perl
+
+use strict;
+
+use File::Temp qw/tempfile/;
+
+my $lastline = qx(/usr/bin/tail -n 1 /var/log/asterisk/messages);
+chomp($lastline);
+
+
+if(
+ ( $lastline =~ /chan_iax2.c: Max retries exceeded to host/g ) ||
+ ( $lastline =~ /chan_echolink.c: Cannot find DB entry for Callsign/g )
+ ){
+
+ ( my $lts = $lastline ) =~ s/^\[([A-Za-z0-9\s\:]+)\] [NW].*/$1/g;
+
+ # sadly perl(Date:Time) not on these so we'll do it the hacky way
+ my $now = qx(/usr/bin/date "+%b %d %H:%M:%S");
+ chomp($now);
+
+ ( my $logdate = $lts ) =~ s/^([A-Za-z]+\s\s?[0-9]+)\s[0-9].*$/$1/;
+ $logdate =~ s/\s\s/ 0/g;
+
+ ( my $nowdate = $now ) =~ s/^([A-Za-z]+\s[0-9]+)\s[0-9].*$/$1/;
+
+ # If the log entries aren't on the same day, bail out
+ if( $logdate ne $nowdate ){
+ exit 0;
+ }
+
+ # turn everything into seconds
+ ( my $logtime = $lts ) =~ s/^.*\s(\d\d\:\d\d\:\d\d)$/$1/;
+ ( my $nowtime = $now ) =~ s/^.*\s(\d\d\:\d\d\:\d\d)$/$1/;
+
+ ( my $lh, my $lm, my $ls ) = split(/:/, $logtime);
+ ( my $nh, my $nm, my $ns ) = split(/:/, $nowtime);
+
+ $lh *= 3600;
+ $nh *= 3600;
+ $lm *= 60;
+ $nm *= 60;
+
+ if( ( ($nh + $nm + $ns) - ( $lh + $lm + $ls ) ) < 300 ){
+
+ # The init script for asterisk is really weak. Find
+ # all of the pids that are child pids of the
+ # safe_asterisk process which is launched as a nohup
+ # process rooted in /bin/sh. The astdn.sh script
+ # just does not work right at all to kill stuck children
+ my $sapid = qx(/usr/bin/pgrep safe_asterisk);
+
+ # be maximally safe and don't do anything if there is
+ # no safe_asterisk process
+ if( length($sapid) > 0 ){
+ my $apids = qx(/usr/bin/pstree -p $sapid);
+ $apids =~ s/[^\d]/ /g;
+ $apids =~ s/\s+/ /g;
+ system("/usr/bin/kill -9 $apids > /dev/null 2>&1");
+ sleep 1;
+ unlink "/var/run/asterisk.ctl";
+ unlink "/var/run/asterisk.pid";
+ exec("/usr/local/sbin/astup.sh > /dev/null 2>&1");
+ }
+
+ my $msg;
+ $msg .= "From: Asterisk <root\@megalink.network>\n";
+ $msg .= "To: zabbix\@megalink.network\n";
+ $msg .= "Subject: Restarted Asterisk on pi-echo39\n";
+ $msg .= "\n";
+ $msg .= "This is the iax_monitor program on pi-echo39.\n";
+ $msg .= "\n";
+ $msg .= "Asterisk was cycled at " . qx(/usr/bin/date) . " due to the IAX Max Retries bug.\n";
+ $msg .= "\n";
+ $msg .= "Last Log:\n";
+ $msg .= " " . $lastline . "\n";
+ $msg .= "\n\n";
+ $msg .= "Be well, John Spartan!\n";
+
+ (my $ofh , my $outfile ) = tempfile( UNLINK => 1 );
+
+ print $ofh $msg;
+ system( sprintf("/usr/bin/cat %s | /usr/bin/ssmtp -oi -oem %s", $outfile, "zabbix\@megalink.network") );
+
+ }
+}
+exit 0;
diff --git a/allstar/allstar-monitor.crond b/allstar/allstar-monitor.crond
new file mode 100644
index 0000000..e7afb9f
--- /dev/null
+++ b/allstar/allstar-monitor.crond
@@ -0,0 +1,5 @@
+# Run the hourly jobs
+SHELL=/bin/bash
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+MAILTO=zabbix@megalink.network
+*/5 * * * * root /usr/local/sbin/allstar-monitor