#!/usr/bin/perl -w # SCM: @(#): $Id$ # # SYNTAX: my $usage = qq{ submit_sms_aql Copyright (C) 2007 Altinity Limited Usage: submit_sms_aql -u aql_username -p aql_password [-m max] {-c | -n [,] -t } Options: -u,-p AQL's username and password. Sign up at http://www.aql.com/site/order2.php?contract=prepay&referral=altinity -c Credit check. Returns number of credits available in account -n Telephone number to send to -t Message text to send. Will truncate and convert linefeeds to spaces -m num Maximum number of texts of 160 chars to send. Will truncate to (160*num) }; # # DESCRIPTION: # Sends text message via AQL # You need to have an account with AQL. Sign up at http://www.aql.com/site/order2.php?contract=prepay&referral=altinity # # LICENCE: # Copyright (C) 2007 Altinity Limited # # This file is part of Opsview # # Opsview 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. # # Opsview 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 Opsview; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # sub usage { if ($_ = shift) { print "Error: $_\n" } print $usage; exit 1; } use strict; use Getopt::Std; use SMS::AQL 0.04; my $opts = {}; getopts("hcu:p:n:t:m:", $opts); if ($opts->{h}){ usage(); exit(0); } my $username = $opts->{u} || usage "Must specify AQL username"; my $password = $opts->{p} || usage "Must specify AQL password"; my $sms = SMS::AQL->new( { username => $username, password => $password, options => { sender => "Opsview" } } ); if ($opts->{c}) { my $credit = $sms->credit || ""; if ($credit =~ /^\d+$/) { print "Number of credits: $credit",$/; } else { print "Error: ".$sms->last_error,$/; } exit 0; } usage "Must specify smsnumber with -n" unless $opts->{n}; usage "Must specify message with -t 'message'" unless $opts->{t}; my $t = $opts->{t}; my @numbers = split(",",$opts->{n}); # Cleanup text $t =~ s/\n/ /g; my $maxchars = ($opts->{m} || 1) * 160; $t = substr($t, 0, $maxchars); # Cleanup numbers # From Opsview, will definitely get a + at beginning. Spaces shouldn't appear # but worthwhile to remove here @numbers = map { s/\+//; s/ //g; $_ } @numbers; my $n; foreach $n (@numbers) { my $ok = $sms->send_sms($n, $t); if (! $ok) { print "Error: ".$sms->last_error.$/; } } print "Submitted to AQL",$/; exit;