Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Add Comment
Please, Sign In to add comment