Hoi, ik heb een script gevonden waarmee ik via clickatell smsjes kan versturen vanuit nagios, maar het werkt van geen kanten.. het originele script zat vol met perl errors.. Ik heb ze kunnen fixen maar ik ben zelf geen perl programmer en nu zit ik echt vast.
Wanneer ik een bericht verstuurd gaat dat als volgt (via terminal):
./check_sms -a 12345 -u username -p password -m 'this is a test' -t 12345
Echter nu krijg ik enkel het bericht "this" aan.
Hoe zorg ik dat ik de hele lijn aan krijg?
Het script:
Bij voorbaat dank
Wanneer ik een bericht verstuurd gaat dat als volgt (via terminal):
./check_sms -a 12345 -u username -p password -m 'this is a test' -t 12345
Echter nu krijg ik enkel het bericht "this" aan.
Hoe zorg ik dat ik de hele lijn aan krijg?
Het script:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
| #!/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 "/usr/lib/nagios/plugins" ;
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://api.clickatell.com";
}
my $login_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 $send_url = $opt_baseurl."/http/sendmsg?session_id=".$sess."&to=".$opt_to."&text=".$opt_text;
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();
} |
Bij voorbaat dank
Naatan.com - Blog & Wordpress Plugins | Divia-CMS.com (OpenSource) - Currently Recruiting!