-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcheck_testcall.pl
More file actions
executable file
·86 lines (64 loc) · 1.4 KB
/
check_testcall.pl
File metadata and controls
executable file
·86 lines (64 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/perl
# checks if asterisk can make a call
my $number = shift || "2135551212";
use Sys::Hostname;
eval("use Time::ParseDate; \$Time::ParseDate::VERSION") || error("Can't use Time::ParseDate");
my $TO = 'emerg@somehost';
my $LASTCHECK = 20;
my $FROM = "proxy\@somehost.com";
my $CC = "";
my $LOG = "/tmp/some.log";
open(LOG, "<$LOG") || error("Can't read log file $LOG");
my @time = localtime();
my $now = time();
my $lastlog;
while (<LOG>)
{
if (/$number/ && !/1st attempt/)
{
chomp($lastlog = $_);
}
}
close(LOG);
if ($lastlog =~ /(\S+\s+\S+\s+\S+\s+(\d+):(\d+):\d+\s+\S+)/)
{
my ($date, $hour, $min) = ($1, $2, $3);
my $lastcheck = parsedate($date);
# make sure this entry is within $LASTCHECK minutes of now
if ($now - $lastcheck > $LASTCHECK * 60 && $now > 0 && $lastcheck > 0)
{
error("No status checks in last $LASTCHECK minutes ($now - $lastcheck)");
}
}
elsif ($lastlog)
{
error("Can't interpret date from $lastlog ($number)");
}
else
{
error("No logs for $number");
}
# success
exit;
sub error
{
open LOG;
print LOG "Error: " . localtime() . ": $_[0]\n";
close(LOG);
my $time = localtime;
my $host = hostname;
my $num = $number;
$num =~ s/\|.*$//;
$num =~ s/^(\d{3})(\d{3})(\d{4})/$1-$2-$3/;
open(SM, "|/usr/sbin/sendmail -t");
print SM << "EOF";
From: $FROM
To: $TO
Cc: $CC
Subject: $num POSSIBLY DOWN!
$num POSSIBLY DOWN
$time: $_[0] ($host:$0)
EOF
close(SM);
exit;
}