#!/usr/bin/perl # # Alerts via Clickatell's HTTP/S - SMS API # # Copyright (C) 2006, Stuart Yarrow # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # use Getopt::Std; use LWP; getopts ("s:g:h:t:l:u"); # Set your login details here. See Clickatell API spec for details. my $apiID = ""; my $userName = ""; my $password = ""; # # Example usage in mon.cf: # # alert clickatell.alert 447123123456 447891456789 # # will send sms to both numbers (add as many numbers as required) # $summary=; chomp $summary; $t = localtime($opt_t); ($wday,$mon,$day,$tm) = split (/\s+/, $t); my $message = "Alert for ".$opt_g.", service ".$opt_s."\n"; $message .= $wday." ".$mon." ".$day." ".$tm."\n"; if($opt_u) { $message .= "SERVICE RESTORED\n"; } else { $message .= "SERVICE DOWN\n".$summary; } $authURL = "https://api.clickatell.com/http/auth?api_id=".$apiID."&user=".$userName."&password=".$password; my $browser = LWP::UserAgent->new; my $authResponse = $browser->get($authURL); die "Moo! Failed to GET session ID." unless $authResponse->is_success; die "Moo! Authentication failure." unless substr($authResponse->content, 0, 1) == "OK"; my $authToken = substr($authResponse->content, 4); @telNos = @ARGV; for my $telNumber (@telNos) { $url = "http://api.clickatell.com/http/sendmsg?session_id=".$authToken."&to=".$telNumber."&text=".$message; my $response = $browser->get($url); }