How to send SMS?

Support and queries relating to all previous versions of ZoneMinder
Locked
ziopippo
Posts: 18
Joined: Tue Sep 05, 2006 10:43 am
Location: Italy

How to send SMS?

Post by ziopippo »

Hi, i have also search on the forum without answer. :(

I have just installed on my distro Ubuntu Edgy this software: http://www.sideralis.org/sidesms

It work also by terminal.

Q: How can i tell to ZoneMinder to send an SMS with sidesms?


Is to welcome also Italian answer. :D

Thank's.

Regards

Ettore.
________
Amc rebel history
Last edited by ziopippo on Sun Feb 13, 2011 12:39 pm, edited 3 times in total.
ziopippo
Posts: 18
Joined: Tue Sep 05, 2006 10:43 am
Location: Italy

Post by ziopippo »

I've just read this post http://www.zoneminder.com/forums/viewto ... ght=filter

I think that my question is possible but i don't know how.

The command to insert in a filter is:

Code: Select all


user@ubuntu:~$ sidesms -uUSERNAME -pPASSWORD -sPROVIDER_SENDER -nNUMBER_OF_PHONE TEXT
How i can add it?

Thanks.
________
DISCUSS VAPORIZERS
Last edited by ziopippo on Sun Feb 13, 2011 12:39 pm, edited 1 time in total.
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

I think the easiest way for you is to configure the Message format to what you want to send, and test it by sending to an email address. Then change the Message email address to an address on your local machine and use procmail to pass it through to sendsms. You example of sendsms does not indicate where the text body comes from but assuming it's just piped into it, then it should not be too hard to do.
Phil
ziopippo
Posts: 18
Joined: Tue Sep 05, 2006 10:43 am
Location: Italy

Post by ziopippo »

It's too difficulty for me, have you an easy example?
________
M1
Last edited by ziopippo on Sun Feb 13, 2011 12:39 pm, edited 1 time in total.
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

I don't have an example because I've never actually done what you are trying to do. But setting up ZM to send you a short email (use the _MESSAGE_ settings rather than the _EMAIL_ ones) should be easy. Then once you are happy with the content you can use procmail to pipe it into sms.

The 'man procmail' page tells you about procmail and 'man procmailex' will give you lots of examples.
Phil
ziopippo
Posts: 18
Joined: Tue Sep 05, 2006 10:43 am
Location: Italy

Post by ziopippo »

Ok i try, but my problem is: how can i insert an execute command?

I have created a new filter, and i have checked "Automatically execute command on all matches" (and save all), but i don't know how can i inser my command.

In the terminal console the command is this: sidesms -uUSERNAME -pPASSWORD -sPROVIDER_SENDER -nNUMBER_OF_PHONE TEXT :wink:

Thank's a lot.

Regards.
________
Buy Vapormatic
Last edited by ziopippo on Sun Feb 13, 2011 12:40 pm, edited 1 time in total.
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

You do not need to execute a command, you should just check 'message details' and use the message event format. If you want to execute your own command then you will need to create a script that creates and formats your sms before passing it to sendsms. It will also need to retrieve the event details from the db if you want that included in your sms.
Phil
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

Or something like this:

Code: Select all

#!/bin/sh
MONITOR_EVENT=$1

#Insert REGEX here to break the input up into MONITOR and EVENT zm wil send  $m/$e

if [-x sidesms ]; then
               sidesms -uUSERNAME -pPASSWORD -sPROVIDER_SENDER -nNUMBER_OF_PHONE "Monitor $MONITOR has alarmed and produced event # $EVENT"
else
           echo "ERROR: sidesms not found."
           return 1
fi
anest
Posts: 24
Joined: Tue May 16, 2006 12:47 am

SMS

Post by anest »

One more example :)

Code: Select all

#!/usr/bin/perl

use Getopt::Std;
getopts ("s:g:h:t:l:u");

$summary=<STDIN>;
chomp $summary;

$rest="";
while (<STDIN>) {
  $rest .= $_;
}

foreach $number (@ARGV) {

    # system("echo `date` `id` $number $summary >> /var/log/sms.alert.log");

    open (SMS, "| /usr/bin/gnokii --sendsms $number") || die "could not open pipe to sms: $!\n";

    print SMS $summary;
    print SMS "\n";
    print SMS $rest;

    close (SMS);

}
anest
Posts: 24
Joined: Tue May 16, 2006 12:47 am

Post by anest »

Example also for pager:

Code: Select all

#!/usr/local/bin/perl5 -w

# send pages to people via paging company Web interfaces or SNPP

# 

# released to mon list on 7/18/00
# alpha version - please send fixes, improvements, or suggestions to
# Ed Ravin <eravin@panix.com>

use strict;

use Getopt::Long;
use Socket;
use Net::SNPP;

my $myname="pageomat";
my %opt;
GetOptions (\%opt, "debug", "pin=s", "company=s", "timeout=i", "message=s");

my %pageinfo= (
	'skytel'=>
	{ 'url' => 'snpp://snpp.skytel.com:7777' }, 

	'skytel-http' =>
	{ 'url' => 'http://www.skytel.com/servlet/SendMessage',
	  'format' => 'recipients=%s&message=%s',
	  'match' => '(Your Message Status Number is: \d+)|(Skytel Messaging Center Has Received Your Message)' } ,

	'bellsouthips' =>
	{ 'url' => 'http://www.bellsouthips.com/scripts/rampage.dll?ProcessSendMail',
	  'format' => 'pin=%s&media=None&retaddr=&data=%s',
	  'match' => 'Your message has been sent to destination address' },

	'omnipoint' =>
	{ 'url' => 'http://www.omnipoint.com/cgi-bin/message.cgi',
	  'format' => 'load=%s&phone=%s&message=%s',
	  'match' => 'message_sent.html',
	  'referer' => 'Referer: http://www.omnipoint.com/common/center/main.html',
	  'arg1' =>  url_encode('http://www.omnipoint.com/common/center/message_sent.html') },

	'bam' =>
	{ 'url' => 'http://www3.bam.com/cgi-bin/sms/sms.cgi',
	  'format' => 'msg_type=messaging&area_code=%s&exchange=%s&extension=%s&message=%s&tCharacterCount=0',
	  'cut_pin_3' => 'true',
	  'match' => 'Your Message Has Been Accepted For Delivery' },

# att not tested yet
	'att' =>
	{ 'url' => 'http://www.mobile.att.net/mc/pager_show.cgi',
	 'format' => 'category=personal&pin=%s&sizebox=%s' },

	);

my $usage="Usage: $myname --pin=pagerid --company={" . join('|', keys %pageinfo) . "}\n";

my $debug= $opt{'debug'} || undef;

my $pin= $opt{'pin'} || die "$usage";
my $company= $opt{'company'} || die "$usage";
my $timeout= $opt{'timeout'} || 30;
my $message= $opt{'message'} || join (' ', <STDIN>);

$message =~ s/\n/ /g;



# chop up url
my ($protocol, $hostname, $path)= ($pageinfo{$company}{'url'} =~ m!([^:]+)://([^/]+)(.*)!);
my $port;

if ($hostname =~ m!([^:]+)(:\d+)!)
{
	$hostname= $1; $port= $2;
}

$port=80 unless defined($port);
$port=~ s/://;

if ($debug) {
	print "Message to $pin at $company via $pageinfo{$company}{'url'}\n";
	print "Protocol is $protocol, server is $hostname, port is $port, path is $path\n";
}

if ($protocol eq "snpp")
{
	send_snpp($hostname, $port, $pin, $message);
	exit 0;
}


if ($debug) {
	open COMMAND, ">&STDOUT" || die "$0: can't dup fd for debugging: $!";
} else {
    my $pro = getprotobyname ('tcp');
    if (!defined $pro) {
        die "$myname: could not getprotobyname tcp: is there a network here?\n";
    }
    if (!defined socket (COMMAND, PF_INET, SOCK_STREAM, $pro)) {
        die "$myname: could not create socket: $!\n";
    }
    my $address = inet_aton ($hostname);
    if (!defined $address) {
        die "$myname: $hostname could not inet_aton";
    }
    my $sin = sockaddr_in (80, $address);
	if (!defined $sin) {
		die "$0: $hostname/$address could not sockaddr_in";
	}

    my $r;

    die "$0: cannot setsockopt: $!"
        unless setsockopt(COMMAND, SOL_SOCKET, SO_LINGER, pack "i i", 1, 10);

    eval {
        local $SIG{"ALRM"} = sub { die "alarm\n" };

        alarm $timeout;

        $r = connect (COMMAND, $sin);

        alarm 0;
    };

    if ($@) {
                if ($@ eq "alarm\n") {
                        die "$0: $hostname/$address timeout";
                } else {
                        die "$0: $hostname/$address interrupted syscall: $!";
                }
    }

    if (!defined $r) {
        die "$0: $hostname/$address could not connect: $!";
    }

}


if ($company eq "skytel-http")
{
    # Skytel's form chokes on or eats up these characters - so substitute them
    $message =~ s/[&]/{and}/g;
    $message =~ s/[+]/{plus}/g;
    $message =~ s/[%]/{percent}/g;
} elsif ($company eq "bam")
{
    # bam doesn't like carrots.  Silly rabbit...
    $message =~ s/</(/g;
    $message =~ s/>/)/g;
}

$message= url_encode($message);  # format for POST'ing

my $data;

if (defined($pageinfo{$company}{'arg1'}))
{
	$data= sprintf $pageinfo{$company}{'format'},
		$pageinfo{$company}{'arg1'}, $pin, $message;
} elsif (defined($pageinfo{$company}{'cut_pin_3'}))
{
	die "PIN must be 10-digit number for this company"
		unless $pin =~ /^\d{10}$/;
	my ($areacode, $exchange, $suffix)=
		(substr($pin,0,3), substr($pin,3,3), substr($pin,6,4));
	$data= sprintf $pageinfo{$company}{'format'},
		$areacode, $exchange, $suffix, $message;
}
else
{
	$data= sprintf $pageinfo{$company}{'format'}, $pin, $message;
}

select COMMAND; $|=1; select STDOUT;

print COMMAND "POST $path HTTP/1.0\r\n" .
              "Host: $hostname\r\n" .
              "Accept: text/html, text/plain\r\n" .
              "User-Agent: $myname\r\n" .
	( defined($pageinfo{$company}{'referer'}) ?
		"$pageinfo{$company}{'referer'}\r\n" : "" ) .
              "Content-type: application/x-www-form-urlencoded\r\n" .
              "Content-length: " . length($data) . "\r\n\r\n" .
              $data;

print COMMAND "\r\n" if $debug;

$SIG{"PIPE"} = 'IGNORE';
shutdown COMMAND, 1; # SHUT_WR - disallow further writes


my $response= "";
my @response;

alarm $timeout; # just die if we get stuck somehow listening on the socket

@response= <COMMAND>; $response= join('', @response);

print length($response), " bytes received.\n";

if ( $response =~ $pageinfo{$company}{'match'} )
{
	print "Message delivery confirmed to $pin at $hostname:\n";
	exit 0;
} else {
	print "No match - cannot confirm message delivery.\n";
	open TRACE, ">/tmp/pageomat.response.$$" ||
		die "$0: cannot create tracefile /tmp/pageomat.$$: $!";
	print TRACE $response;
	close TRACE;
	exit 1;
}


sub send_snpp
{
	my ($host, $port, $pagerid, $text) = @_;
	my $rc;
	my $snpp = Net::SNPP->new ($host, Port => $port, Timeout => 60)
	   or die "SNPP->new fails: $!";

	$rc= $snpp->send ( Pager => [ $pagerid ], Message => "$text" );
	
	die "SNPP send fails." unless $rc;

	$snpp->quit;
}




sub url_encode {

    my $text = shift;

    $text =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;

    return $text;
}

anest
Posts: 24
Joined: Tue May 16, 2006 12:47 am

Post by anest »

Alerts on your AIM messanger:

Code: Select all

#!/usr/bin/perl
#

# aim.alert - AIM alert for mon
#
# The first line from STDIN is summary information
#
# Don Harper, duck@duckland.org
#
# $Id: aim.alert,v 1.1.1.1 2002/11/02 17:19:10 duck Exp $
#
#    Copyright (C) 2002, Don Harper
#
#    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 AOL::TOC;
use Getopt::Std;
use Text::Wrap;

$screen_name = "A SCREEN NAME HERE";
$password = "$screen_name's PASSWORD HERE";
$master = "WHO TO ALERT?";
$toc_server = "toc.oscar.aol.com";
$login_server = "login.oscar.aol.com";
$port = "9993";

getopts ("S:s:g:h:t:l:u");
$summary=<STDIN>;
chomp $summary;

$summary = $opt_S if (defined $opt_S);
$mailaddrs = join (',', @ARGV);
$ALERT = $opt_u ? "UPALERT" : "ALERT";
$t = localtime($opt_t);
($wday,$mon,$day,$tm) = split (/\s+/, $t);


# Create the TOC object
$toc = AOL::TOC::new($toc_server, $login_server, $port, 
                     $screen_name, $password);
# register callbacks
$toc->register_callback("SIGN_ON", \&client_signon);
$toc->register_callback("ERROR", \&client_error);

# Informs our master we are operational
sub client_signon
{
    $toc->add_buddy($screen_name);
    print "We are online and ready!\n";
    sleep 1;
    $toc->send_im($master, " Warning: $screen_name now operation!");
}

# connect to aim server
if (! ( $toc->connect() ) )
{
     abort();
}

$toc->dispatch();
sleep 1;
$str  = "Subject: $ALERT $opt_g/$opt_s: $summary ($wday $mon $day $tm)\n";
$str .= wrap ("", "", "Summary output        : $summary"), "\n";
$str .= "\nGroup                 : $opt_g\n";
$str .= "Service               : $opt_s\n";
$str .= "Time noticed          : $t\n";
$str .= "Secs until next alert : $opt_l\n";
$str .= wrap ("", "", "Members               : $opt_h"), "\n";
$str .= "\nDetailed text (if any) follows:\n";
$str .= "-------------------------------\n";
while (<STDIN>) { $str .= $_; }

print "sending: $str to $master\n";
$toc->send_im($master,$str);
sleep 1;
exit;

sub client_error
{
    my ($self, $code) = @_;
    
    print "ERROR: " . aim_errstr($code, $previous_target) . "\n";
}

sub aim_errstr() {
    my ($code, $target, %_error_name);

    ($code, $target) = @_;

    %_error_name = (
                    # AIM Errors
                    901   => "$target not currently available",
                    902   => "Warning of $target not currently available",
                    903   => 'A message has been dropped, you are exceeding the server speed limit',
                    #   * Chat Errors  *',
                    950   => 'Chat in $target is unavailable.',

                    #   * IM & Info Errors *',
                    960   => 'You are sending message too fast to $target',
                    961   => 'You missed an im from $target because it was too big.',
                    962   => 'You missed an im from $target because it was sent too fast.',

                    #   * Dir Errors *',
                    970   => 'Failure',
                    971   => 'Too many matches',
                    972   => 'Need more qualifiers',
                    973   => 'Dir service temporarily unavailable',
                    974   => 'Email lookup restricted',
                    975   => 'Keyword Ignored',
                    976   => 'No Keywords',
                    977   => 'Language not supported',
                    978   => 'Country not supported',
                    979   => 'Failure unknown $target',

                    #  * Auth errors *',
                    980   => 'Incorrect nickname or password.',
                    981   => 'The service is temporarily unavailable.',
                    982   => 'Your warning level is currently too high to sign on.',
                    983   => 'You have been connecting and disconnecting too fre quently.  Wait 10 minutes and try again.  If you continue to try, you will need to wait even longer.',
                    989   => 'An unknown signon error has occurred $target'
                    );

    # fatal signon errors, we should abort!
    if ($code eq '980' ||
        $code eq '981' ||
        $code eq '982' ||
        $code eq '983' ||
        $code eq '989')
        {
             print "Aborting...\n$_error_name{$code}\n";
             abort();
        }
    return $_error_name{$code};
}
Locked