Christian Joergensen skrev:
> Per Jørgensen <pbj@mobilepeople.com> writes:
> Foerste skridt er at kunne sende SMS fra command line. Det skriver du,
> du ikke kan. Hvilken fejl faar du? Hvad for noget programmel bruger du?
>
Jamen har hentet flere af de forskellige plugins der ligger på
nagiosexchange til dette formål.
Generelt har jeg fundet den der hedder notify_sms!
Efter jeg har tilrettet denne til mine egne behov :
./notify_sms
Bareword "utils" not allowed while "strict subs" in use at ./notify_sms
line 7.
Bareword "pm" not allowed while "strict subs" in use at ./notify_sms line 7.
BEGIN not safe after errors--compilation aborted at ./notify_sms line 8.
Og generelt ligger utils.pm i samme mapper under /usr/local/nagios/libexec
Dog er dette script ikke modificeret efter mine behov endnu - da det
fejler allerede inden
Selve scriptet ser således ud:
#!/usr/bin/perl -wT
use strict;
use HTTP::Lite;
use Getopt::Long;
use vars qw($opt_version $opt_help $opt_username $opt_password
$opt_api_id $opt_baseurl $opt_text $opt_to $PROGNAME);
use lib utils.pm;
use utils qw(%ERRORS &print_revision &support &usage);
$PROGNAME = "notify_sms";
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("v" => \$opt_version, "version" => \$opt_version,
"h" => \$opt_help, "help" => \$opt_help,
"a=s" => \$opt_api_id, "apiid=s" => \$opt_api_id,
"b=s" => \$opt_baseurl, "baseurl=s" => \$opt_baseurl,
"m=s" => \$opt_text, "message=s" => \$opt_text,
"p=s" => \$opt_password, "password=s" => \$opt_password,
"t=s" => \$opt_to, "to=s" => \$opt_to,
"u=s" => \$opt_username, "username=s" => \$opt_username);
if ($opt_version) {
print_revision($PROGNAME,'$Revision: 1.1 $');
exit $ERRORS{'OK'};
}
if ($opt_help) {print_help(); exit $ERRORS{'OK'};}
($opt_api_id) || usage("Gateway api ID must be specified\n");
($opt_text) || usage("Message body must be specified\n");
($opt_password) || usage("Gateway login password must be specified\n");
($opt_to) || usage("Phone to number must be specified\n");
($opt_username) || usage("Gateway login username must be specified\n");
if (!$opt_baseurl) {
$opt_baseurl = "
http://mps1.dk:8040/smsgate/";
}
my $login_url =
$opt_baseurl."/http/auth?user=".$opt_username."&password=".$opt_password."&api_id=".$opt_api_id;
my $send_url =
$opt_baseurl."/http/auth?user=".$opt_username."&password=".$opt_password."&api_id=".$opt_api_id;
#print $text."\n";
my $http = new HTTP::Lite;
my $req = $http->request($login_url);
my $res = $http->body();
my @sres = split(":", $res);
if ($sres[0] eq "OK") {
my $sess = $sres[1];
chomp($sess);
$sess = substr($sess,1);
my $rhttp = new HTTP::Lite;
my $ret = $rhttp->request($send_url);
my $nres = $rhttp->body();
my @sent = split(":", $nres);
if ($sent[0] eq "ID") {
print "Message sent\n";
exit $ERRORS{'OK'};
} else {
print "Gateway authentication failed\n";
exit $ERRORS{'CRITICAL'};
}
} else {
print "Authentication failed\n";
}
sub urlencode {
my $ask = shift @_;
my @a2 = unpack "C*", $ask;
my $s2 = "";
while (@a2) {
$s2 .= sprintf "%%%X", shift @a2;
}
return $s2;
}
sub print_usage () {
print "Usage: $PROGNAME -u <gw_username> -p <gw_password> -a
<gw_api_id> -b <gw_baseurl> -m <message_text> -t <to_msisdn>\n";
}
sub print_help () {
print_revision($PROGNAME,'$Revision: 1.1 $');
print "
Copyright (c) 2005 Serhan D. KIYMAZ <skiymaz\@netpia.com>
Netpia Internet Hizmetleri Pazarlama A.S. - TURKEY
This plugin sends SMS notification messages to contacts from a SMS Gateway.
It has been tested with Clickatell <
www.clickatell.com>
";
print_usage();
print "
-a, --apiid=API_ID
Api ID for gateway login. It is specified by gateway company.
-b, --baseurl=BASE_URL
Base URL for login and send SMS actions of gateway. Default:
http://api.clickatell.com.
-m, --message=MESSAGE_TEXT
Message text that will be sent to TO number. Max: 160 chars.
-p, --password=PASSWORD
Login password for gateway login.
-t, --to=TO_NUMBER
GSM phone number that the message will be delivered to.
-u, --username=USERNAME
Login username for gateway login.
";
support();
}
> Naar foerst det virker, er det en smal sag at sende en sms (eksempel):
>
> define command{
> command_name notify-by-sms
> command_line /usr/bin/printf "%b" "Type: $NOTIFICATIONTYPE$\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nAdditional Info:\n$OUTPUT$" | /usr/bin/sendsms $CONTACTPAGER$
> }
>
Det er nu ikke kommandoerne jeg har problemer med - Det er mere det at
fåp det til at virke.
Vi(firmaet) har vores egen SMSgateway - via alm. http - men har også
prøvet med sms_client og et siemens GSM-modem på COMporten
--
Med Venlig Hilsen
Pe® Jørgense/\/
Operations
www.mobilepeople.,com