per-agent configuration of batch processors, #71837
[freeside.git] / torrus / bin / action_printemail.in
1 #!@PERL@
2 #  Copyright (C) 2002  Stanislav Sinyagin
3 #
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.
8 #
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.
13 #
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.
17
18 # $Id: action_printemail.in,v 1.1 2010-12-27 00:04:03 ivan Exp $
19 # Stanislav Sinyagin <ssinyagin@yahoo.com>
20
21 # We need this for $Torrus::Global::templateDirs
22 BEGIN { require '@torrus_config_pl@'; }
23
24 use strict;
25 use Template;
26 use Getopt::Long;
27
28 require '@email_siteconfig_pl@';
29
30 if( not $ENV{'TORRUS_TREE'} )
31 {
32     print STDERR ("Torrus environment variables missing. This program ",
33                   "must be run from Torrus Monitor\n");
34     exit 1;
35 }
36
37
38 my $ok = GetOptions( 'url=s' => \$Torrus::Email::url,
39                      'template=s' => \$Torrus::Email::template );
40
41 if( not $ok )
42 {
43     print STDERR ("Error parsing options\n");
44     exit 1;
45 }
46
47 my $tt = new Template(INCLUDE_PATH => $Torrus::Global::templateDirs);
48
49 my $vars =
50 {
51     'tree'       => $ENV{'TORRUS_TREE'},
52     'token'      => $ENV{'TORRUS_TOKEN'},
53     'path'       => $ENV{'TORRUS_NODEPATH'},
54     'nickname'   => $ENV{'TORRUS_NICKNAME'},
55     'url'        => $Torrus::Email::url . '/' .
56         $ENV{'TORRUS_TREE'} . '?token='.$ENV{'TORRUS_TOKEN'},
57     'ncomment'   => $ENV{'TORRUS_NCOMMENT'},
58     'npcomment'  => $ENV{'TORRUS_NPCOMMENT'},
59     'event'      => $ENV{'TORRUS_EVENT'},
60     'monitor'    => $ENV{'TORRUS_MONITOR'},
61     'mcomment'   => $ENV{'TORRUS_MCOMMENT'},
62     'severity'   => $ENV{'TORRUS_SEVERITY'},
63     'timestamp'  => scalar(localtime($ENV{'TORRUS_TSTAMP'})),
64     'value'      => $ENV{'TORRUS_VALUE'},
65     'dispvalue'  => $ENV{'TORRUS_DISPLAY_VALUE'},
66     'env'        => sub  { return $ENV{$_[0]} }
67 };
68
69 my $result = $tt->process($Torrus::Email::template, $vars);
70
71 if( not $result )
72 {
73     print STDERR "Error while processing template: ".$tt->error()."\n";
74 }
75
76 exit( $result ? 0:1 );
77
78
79 # Local Variables:
80 # mode: perl
81 # indent-tabs-mode: nil
82 # perl-indent-level: 4
83 # End: