#!/usr/local/bin/perl # # Sends sms warning using smssend and the totalise SMS service # # Based on sms.plugin, written by Paul van Tilburg # # Written as warning plugin for Checkservice, by Jeroen Latour # # Arguments are: -c confdir -h host -p port -s service -r result use strict; use Getopt::Std; use HTTP::Request::Common; use LWP::UserAgent; getopts("h:p:s:c:r:"); my ($host, $port, $service, $confdir) = ($main::opt_h, $main::opt_p, $main::opt_s, $main::opt_c); my $res; my %config = (); my $key; my $value; (! -d "$confdir") and die "$0: Can't find config dir ($confdir)\n"; # Parsing global conffile open (CONFIG, "$confdir/checkservice.conf") or die "$0: Can't open global configfile " . "'$confdir/checkservice.conf'\n"; while () { chomp; s/#.*//; if (($key, $value) = /^\s*(\S+)\s*=\s*(\S.*)/) { $config{$key} = $value; } } # Parsing sms plugin's conffile open (OCONFIG, "$confdir/plugins/smsnet.conf") or die "$0: Can't open plugins' configfile " . "'$confdir/plugins/smsnet.conf'\n"; while () { chomp; s/#.*//; if (($key, $value) = /^\s*(\S+)\s*=\s*(\S.*)/) { $config{$key} = $value; } } my $lockf = "$config{lockpath}/sms.$host.$service"; my @wmethods = split(":", $config{wmethod}); if (! -r $lockf) { unless ((defined $config{phonenr}) || ($config{phonenr})) { die "$0: No phone number specified\n"; } unless ((defined $config{country}) || ($config{country})) { die "$0: No country code specified\n"; } if ($service eq "-") { $res = &sendsms($config{country}, $config{phonenr}, "DOWN $host"); } else { $res = &sendsms($config{country}, $config{phonenr}, "DOWN $service/$host"); } open LOCKF, ">$lockf" or die "$0: Could not create lockfile $lockf: $!\n"; print LOCKF time, "\n"; } sub sendsms { my $country = shift; my $phone = shift; my $message = shift; $message = pack("A126", $message); $message = "$message [SW]"; my $ua = new LWP::UserAgent; $ua->agent("Mozilla/3.0 (CheckService)"); my $res = $ua->request(POST 'http://sms.totalise.net/send.asp', [ AREA => $country, tnumber => $phone, email => '', snumber => '', message => $message ] ); return $res->is_success; }