/[mon-modules]/sms.alert
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /sms.alert

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Mon Jan 13 16:04:11 2003 UTC (19 years, 4 months ago) by dpavlin
Branch: MAIN
alert script to send sms messages using smstools from
http://www.isis.de/~s.frings/smstools/

1 dpavlin 1.1 #!/usr/bin/perl -w
2     #
3     # sms.alert - send an alert via smstools
4     #
5     # based on qpage.alert by Jim Trocki, trockij@transmeta.com
6     #
7     # usage:
8     # sms.alter [-f][-l][-u] 385abxxxxxx
9     #
10     # flags:
11     # -u this is upalert
12     # -f send flash sms (directly to screen)
13     # -l send long message (all output, smstools with split it in
14     # multiple smses if needed)
15     #
16    
17     my $sms_outgoing = "/var/spool/sms/outgoing";
18     my $sms_addressbook = "/usr/local/etc/sms.addressbook";
19    
20     use strict;
21     my %opt;
22     use Getopt::Std;
23     getopts ("s:g:fu", \%opt);
24    
25     # read addressbook
26     my %name2phone;
27     if (open(A, $sms_addressbook)) {
28     while(<A>) {
29     chomp;
30     next if (/^[#;]/);
31     my ($phone,$name) = split(/\s+/,$_,2);
32     $name2phone{lc($name)} = $phone;
33     }
34     }
35    
36     #
37     # the first line is summary information, adequate to send to a pager
38     # or email subject line
39     #
40     #
41     # the following lines normally contain more detailed information,
42     # but this is monitor-dependent
43     #
44     my @MSG=<STDIN>;
45     my $summary = shift @MSG;
46     chomp $summary;
47    
48     my ($wday,$mon,$day,$tm) = split (/\s+/, localtime);
49    
50     my $ALERT = $opt{u} ? "UPALERT" : "ALERT";
51    
52     my $sms = "From: mon\n";
53     $sms .= "Flash: yes\n" if $opt{'f'};
54     $sms .= "\n$ALERT $opt{g}/$opt{s} $summary ($wday $mon $day $tm)\n";
55     $sms .= join("\n",@MSG) if $opt{'l'};
56    
57     foreach my $to (@ARGV) {
58     if (open(SMS, "> $sms_outgoing/mon$$")) {
59     my $phone = $to;
60     $phone = $name2phone{lc($to)} if ($name2phone{lc($to)});
61     print SMS "To: $phone\n$sms";
62     close SMS;
63     } else {
64     die "could not open sms file in '$sms_outgoing': $!";
65     }
66     }

  ViewVC Help
Powered by ViewVC 1.1.26