Perl – Zabbix SMS Allert

Un netmonitor, non è un vero netmonitor se non fa squillare il telefono del sysadmin con un sms almeno 3 volte a notte, ecco qui uno script in perl per interfacciare zabbix con il servizio fornito da Mobyt tramite un POST http su un loro gateway, con qualche aggiustatina può essere usato anche con altri servizi analoghi.

#!/usr/bin/perl

# Leonardo Rizzi
# Version 0.3
# SMS sent throuth Mobyt gateway
# Designed for use without ip autentication only MD5 Hash
# Attention: there aren't any check but message limit is of 160 charaters.

use Digest::MD5 qw(md5_hex);
use strict;
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
my ($operation, $qty, $rcpt, $query, $out, $ua, $ok, $ko, $data, $from);
my ($code, $id, $password);

$id="username";
$password="password";
$ok='SMS Sent Correctly';
$ko='SMS Not Sent';
$from= $ARGV[1];
$operation="TEXT";
$qty = 'h';

#attention this fuking provider don't accept 00 for international area code only + if you use 00 you get sent error
$rcpt = $ARGV[0];
$data = $ARGV[2];
$code = join '', $id,$operation,$rcpt,$from,$data,$password;

my $ticket=md5_hex($code);

$ua = new LWP::UserAgent;
$ua->agent("SMS_MD5_Relay/0.2 " . $ua->agent);
my $req = POST 'http://smsweb.mobyt.it/sms-gw/sendsmart',
[
id => $id,
operation => 'TEXT',
rcpt => $rcpt,
from => $from,
data => $data,
qty => $qty,
ticket=> $ticket
];

my $res=$ua->request($req);

if ($res->content =~ /^OK/)
{
fine_ok (); }
else
{ fine_ko (); }

exit;
sub fine_ko () {
my $msg=shift;
print "$ko\n";
exit (1);

}

sub fine_ok () {
my $msg=shift;
print "$ok\n";
exit (1);

}

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.