2 # Copyright (C) 2006 Stanislav Sinyagin
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18 # $Id: action_notify.in,v 1.1 2010-12-27 00:04:01 ivan Exp $
19 # Stanislav Sinyagin <ssinyagin@yahoo.com>
21 # We need this for $Torrus::Global::templateDirs
22 BEGIN { require '@torrus_config_pl@'; }
29 require '@notify_siteconfig_pl@';
31 if( not $ENV{'TORRUS_TREE'} )
33 print STDERR ("Torrus environment variables missing. This program ",
34 "must be run from Torrus Monitor\n");
39 our $nowHour = time2str('%H', $now);
40 our $nowWeekday = time2str('%w', $now);
42 my $severity = $ENV{'TORRUS_SEVERITY'};
45 foreach my $policy ( keys %Torrus::Notify::policies )
47 if( &{$Torrus::Notify::policies{$policy}{'match'}} )
49 Debug('Notification policy matched: ' . $policy);
52 my $levels = $Torrus::Notify::policies{$policy}{'severity'};
54 foreach my $level ( sort {$a <=>$b} keys %{$levels} )
56 if( $severity >= $level )
58 push( @targets, @{$levels->{$level}} );
64 Debug('Selected notification targets: ' . join(' ', @targets));
67 foreach my $target ( @targets )
69 my($protocol, $arg) = split(':', $target);
70 if( defined( $Torrus::Notify::programs{$protocol} ) )
73 my $status = system( $Torrus::Notify::programs{$protocol} );
78 Error('The command "' .
79 $Torrus::Notify::programs{$protocol} .
80 '" returned error code ' . $status);
94 # indent-tabs-mode: nil
95 # perl-indent-level: 4