Skip to content

Instantly share code, notes, and snippets.

@dynax60
Created September 6, 2011 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dynax60/1197089 to your computer and use it in GitHub Desktop.
Save dynax60/1197089 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use File::Temp;
use Data::Dumper;
my $phone = shift or die;
my $subject = shift;
exit 0 unless $subject =~ /Loss input voltage on UPS: PROBLEM/;
my $timeout = 10;
my $sshdst = 'root@x.x.x.x:/var/spool/asterisk/outgoing/';
my $tmpdir = '/tmp/';
sub scp($$);
undef $/;
my $tmp = File::Temp->new(
TEMPLATE => 'callmeXXXXXX',
DIR => $tmpdir,
SUFFIX => '.call',
);
my $body = <DATA>;
$body =~ s/%phone%/$phone/;
print $tmp $body;
close $tmp;
die "Error occured while do scp on $sshdst!\n" unless scp($tmp, $sshdst);
sub scp($$) {
my ($src, $dst) = @_;
my $errc;
local $SIG{ALRM} = sub { die "timeout" };
alarm $timeout;
eval {
qx{/usr/bin/scp -i /usr/local/etc/zabbix/id_dsa -B $src $dst 2>&1};
$errc = $? >> 8;
};
alarm 0;
my $ret = $errc || $@ ? 0 : 1;
return $ret;
}
__DATA__
Channel: SIP/Softswitch/%phone%
Context: alarm
Callerid: 4951112233
Extension: 205
MaxRetries: 3
RetryTime: 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment