Guest User

Untitled

a guest
Jan 22nd, 2018
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use File::Temp;
  7. use Data::Dumper;
  8.  
  9. my $phone = shift or die;
  10. my $subject = shift;
  11.  
  12. exit 0 unless $subject =~ /Loss input voltage on UPS: PROBLEM/;
  13.  
  14. my $timeout = 10;
  15. my $sshdst = 'root@x.x.x.x:/var/spool/asterisk/outgoing/';
  16. my $tmpdir = '/tmp/';
  17.  
  18. sub scp($$);
  19.  
  20. undef $/;
  21. my $tmp = File::Temp->new(
  22. TEMPLATE => 'callmeXXXXXX',
  23. DIR => $tmpdir,
  24. SUFFIX => '.call',
  25. );
  26.  
  27. my $body = <DATA>;
  28. $body =~ s/%phone%/$phone/;
  29. print $tmp $body;
  30. close $tmp;
  31. die "Error occured while do scp on $sshdst!\n" unless scp($tmp, $sshdst);
  32.  
  33. sub scp($$) {
  34. my ($src, $dst) = @_;
  35. my $errc;
  36. local $SIG{ALRM} = sub { die "timeout" };
  37. alarm $timeout;
  38. eval {
  39. qx{/usr/bin/scp -i /usr/local/etc/zabbix/id_dsa -B $src $dst 2>&1};
  40. $errc = $? >> 8;
  41. };
  42. alarm 0;
  43. my $ret = $errc || $@ ? 0 : 1;
  44. return $ret;
  45. }
  46.  
  47. __DATA__
  48. Channel: SIP/Softswitch/%phone%
  49. Context: alarm
  50. Callerid: 4951112233
  51. Extension: 205
  52. MaxRetries: 3
  53. RetryTime: 2
Add Comment
Please, Sign In to add comment