2 # Copyright (C) 2002 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: genreport.in,v 1.1 2010-12-27 00:04:01 ivan Exp $
19 # Stanislav Sinyagin <ssinyagin@yahoo.com>
21 # Collect the router information and create the XML file
23 BEGIN { require '@torrus_config_pl@'; }
29 use Torrus::ReportOutput::HTML;
30 use Torrus::SiteConfig;
43 'report=s' => \$report,
46 'genhtml' => \$genhtml,
48 'all2tree=s' => \$all2tree,
49 'verbose' => \$verbose,
53 if( $report and not defined($Torrus::ReportGenerator::modules{$report}) )
55 print STDERR "Unknown report name: ", $report, "\n\n";
59 if( not $ok or (not $report and not $genhtml) or
60 ($report and not $date) or
61 ($genhtml and scalar(@trees) > 0 and $all2tree) or
65 "Usage: $0 --report=ReportName --date=YYYY-MM-DD | ",
66 "--genhtml options...\n";
67 print STDERR "Options:\n",
68 " --report=ReportName Report name.\n",
69 " --date=YYYY-MM-DD Report start date. ",
70 "For monthly reports, 1st day in a month.\n",
71 " --time=hh:mm Report start time. Ignored for monthly reports\n",
72 " --genhtml Generate HTML output from the database\n",
73 " --tree=TREE Generate HTML for a given tree only\n",
74 " --all2tree=TREE Generate reports for all service IDs and place\n",
75 " into the given tree (excludes the option --tree)\n",
76 " --verbose print extra information\n",
77 " --debug print debugging information\n",
79 "Report names supported:\n";
81 foreach my $rep ( sort keys %Torrus::ReportGenerator::modules )
83 print STDERR " ", $rep, "\n";
92 Torrus::Log::setLevel('debug');
96 Torrus::Log::setLevel('verbose');
99 &Torrus::DB::setSafeSignalHandlers();
103 my $class = $Torrus::ReportGenerator::modules{$report};
104 eval( 'require ' . $class );
107 my $generator = $class->new({
112 if( defined( $generator ) )
114 $generator->generate();
126 push( @trees, $all2tree );
129 if( scalar( @trees ) == 0 )
131 @trees = Torrus::SiteConfig::listTreeNames();
135 foreach my $tree ( @trees )
137 if( not Torrus::SiteConfig::treeExists( $tree ) )
139 Error('Tree ' . $tree . ' does not exist');
147 foreach my $tree ( @trees )
149 &Torrus::DB::checkInterrupted();
151 Verbose('Generating HTML report for tree ' . $tree);
153 my $options = {'Tree' => $tree};
155 if( length( $all2tree ) > 0 )
157 $options->{'All_Service_IDs'} = 1;
160 my $out = new Torrus::ReportOutput::HTML( $options );
164 $ok = $out->generate() ? $ok:0;
179 # indent-tabs-mode: nil
180 # perl-indent-level: 4