2012-10-22 15:26:37 +01:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
#
|
|
|
|
# Monitorix - A lightweight system monitoring tool.
|
|
|
|
#
|
2018-10-04 11:51:33 +01:00
|
|
|
# Copyright (C) 2005-2018 by Jordi Sanfeliu <jordi@fibranet.cat>
|
2012-10-22 15:26:37 +01:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
|
|
|
|
require 5.006;
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use FindBin qw($Bin);
|
2013-01-17 16:56:38 +00:00
|
|
|
use lib $Bin . "/lib", "/usr/lib/monitorix";
|
2013-01-04 08:27:05 +00:00
|
|
|
|
|
|
|
use Monitorix;
|
2013-01-10 11:18:28 +00:00
|
|
|
use POSIX qw(WNOHANG LC_TIME setlocale uname pause setsid);
|
2013-01-04 08:27:05 +00:00
|
|
|
use Config::General;
|
2012-10-22 15:26:37 +01:00
|
|
|
use Getopt::Std;
|
2013-01-17 16:56:38 +00:00
|
|
|
use Cwd qw(abs_path);
|
2013-01-04 08:27:05 +00:00
|
|
|
|
2012-10-22 15:26:37 +01:00
|
|
|
# Force a standard locale
|
|
|
|
$ENV{LANG} = "";
|
|
|
|
setlocale(LC_TIME, "C");
|
|
|
|
|
|
|
|
$SIG{'INT' } = 'INT_handler';
|
|
|
|
$SIG{'ABRT'} = 'INT_handler';
|
|
|
|
$SIG{'QUIT'} = 'INT_handler';
|
|
|
|
$SIG{'TRAP'} = 'INT_handler';
|
|
|
|
$SIG{'STOP'} = 'INT_handler';
|
|
|
|
$SIG{'TERM'} = 'INT_handler';
|
|
|
|
$SIG{'CHLD'} = 'CHLD_handler';
|
|
|
|
$SIG{'HUP' } = 'HUP_handler';
|
|
|
|
|
2017-09-25 19:58:48 +01:00
|
|
|
use constant VERSION => "3.10.0";
|
|
|
|
use constant RELDATE => "25-Sep-2017";
|
2012-10-22 15:26:37 +01:00
|
|
|
|
|
|
|
my @suppsys = ("Linux", "FreeBSD", "OpenBSD", "NetBSD");
|
2013-02-07 14:54:31 +00:00
|
|
|
our %config;
|
2013-01-04 08:27:05 +00:00
|
|
|
our %options;
|
2012-10-22 15:26:37 +01:00
|
|
|
|
|
|
|
sub INT_handler {
|
|
|
|
my ($signal) = @_;
|
|
|
|
|
|
|
|
logger("SIG$signal caught.");
|
2013-01-04 08:27:05 +00:00
|
|
|
flush_accounting_rules(\%config, $options{d});
|
2014-07-29 09:55:48 +01:00
|
|
|
if(lc($config{httpd_builtin}->{enabled}) eq "y") {
|
2013-01-31 17:48:29 +00:00
|
|
|
kill(15, $config{httpd_pid});
|
|
|
|
}
|
2012-10-22 15:26:37 +01:00
|
|
|
logger("Exiting.");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub CHLD_handler {
|
|
|
|
my $pid = waitpid(-1, WNOHANG);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub HUP_handler {
|
|
|
|
my ($signal) = @_;
|
|
|
|
my $myself = (caller(0))[3];
|
|
|
|
|
2018-10-17 10:54:05 +01:00
|
|
|
return if $options{n}; # only continue if it's a daemon
|
|
|
|
|
2013-02-15 10:54:38 +00:00
|
|
|
my (undef, undef, $uid) = getpwnam($config{httpd_builtin}->{user});
|
|
|
|
my (undef, undef, $gid) = getgrnam($config{httpd_builtin}->{group});
|
|
|
|
|
2012-10-22 15:26:37 +01:00
|
|
|
logger("SIG$signal caught.");
|
2013-01-04 08:27:05 +00:00
|
|
|
|
2018-03-19 11:31:35 +00:00
|
|
|
# upon receiving SIGHUP a new logfile is opened
|
2012-10-22 15:26:37 +01:00
|
|
|
close(STDOUT);
|
|
|
|
close(STDERR);
|
2013-01-10 11:18:28 +00:00
|
|
|
open(STDOUT, ">> $config{log_file}") || logger("Can't write to LOG: $!");
|
|
|
|
open(STDERR, ">> $config{log_file}") || logger("Can't write to LOG: $!");
|
2018-03-05 15:54:36 +00:00
|
|
|
chmod(0600, $config{log_file});
|
2013-07-15 10:46:09 +01:00
|
|
|
logger("$myself: opening a new log file.");
|
2013-02-15 10:54:38 +00:00
|
|
|
|
2018-10-17 10:54:05 +01:00
|
|
|
# restart HTTP built-in
|
|
|
|
if(lc($config{httpd_builtin}->{enabled}) eq "y") {
|
|
|
|
if(defined($config{httpd_pid})) {
|
|
|
|
require HTTPServer;
|
|
|
|
kill(15, $config{httpd_pid});
|
|
|
|
kill(9, $config{httpd_pid});
|
|
|
|
httpd_setup(\%config, $options{d});
|
|
|
|
logger("Restarted built-in HTTP server (pid $config{httpd_pid}).") if (defined($config{httpd_pid}));
|
|
|
|
}
|
|
|
|
}
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub daemonize {
|
2013-01-10 11:18:28 +00:00
|
|
|
open(STDIN, "< /dev/null") || die "Can't read /dev/null: $!";
|
|
|
|
open(STDOUT, ">> $config{log_file}") || die "Can't write to LOG: $!";
|
|
|
|
umask(022) || die "Unable to umask 022: $!";
|
|
|
|
exit if fork(); # parent exits
|
|
|
|
(setsid() != -1) || die "Can't start a new session: $!";
|
|
|
|
open(STDERR, ">> $config{log_file}") || die "Can't write to LOG: $!";
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub usage {
|
|
|
|
print(STDERR << "EOF");
|
2014-04-08 11:54:32 +01:00
|
|
|
Usage: monitorix -c configfile [-p pidfile] [-d none | graph[,graph] | all ] [-v] [-n]
|
2012-10-22 15:26:37 +01:00
|
|
|
|
|
|
|
EOF
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub create_index {
|
|
|
|
my $myself = (caller(0))[3];
|
|
|
|
|
|
|
|
my $n;
|
|
|
|
my $gname;
|
2013-01-04 08:27:05 +00:00
|
|
|
my $bgcolor;
|
|
|
|
my $table_back_color;
|
|
|
|
my $title_back_color;
|
|
|
|
my $title_fore_color;
|
2014-06-02 16:11:02 +01:00
|
|
|
my $piwik_code = "";
|
|
|
|
my ($piwik_url, $piwik_sid, $piwik_img);
|
2013-01-04 08:27:05 +00:00
|
|
|
|
2013-06-18 15:00:28 +01:00
|
|
|
# keep backwards compatibility for v3.2.1 and less
|
|
|
|
if(ref($config{theme}) ne "HASH") {
|
|
|
|
logger("$myself: WARNING: the <theme> option is not valid. Please consider upgrading your configuration file. Defaulting to white theme.");
|
|
|
|
delete($config{theme});
|
|
|
|
$config{theme}->{white}->{main_bg} = "FFFFFF";
|
|
|
|
$config{theme}->{white}->{main_fg} = "000000";
|
|
|
|
$config{theme}->{white}->{title_bg} = "777777";
|
|
|
|
$config{theme}->{white}->{title_fg} = "CCCC00";
|
|
|
|
$config{theme}->{white}->{graph_bg} = "CCCCCC";
|
|
|
|
$config{theme_color} = "white";
|
|
|
|
}
|
2013-02-11 14:28:20 +00:00
|
|
|
|
2014-03-31 14:30:30 +01:00
|
|
|
my $theme = $config{theme_color} || "white";
|
|
|
|
if(!$config{theme}->{$theme}) {
|
|
|
|
logger("$myself: ERROR: invalid value in 'theme_color' option. Defaulting to white theme.");
|
|
|
|
$theme = $config{theme_color} = "white";
|
|
|
|
}
|
|
|
|
|
2013-06-18 15:00:28 +01:00
|
|
|
if($config{theme}->{$theme}) {
|
|
|
|
$bgcolor = $config{theme}->{$theme}->{main_bg};
|
|
|
|
$table_back_color = $config{theme}->{$theme}->{graph_bg};
|
|
|
|
$title_back_color = $config{theme}->{$theme}->{title_bg};
|
|
|
|
$title_fore_color = $config{theme}->{$theme}->{title_fg};
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
|
2014-06-02 16:11:02 +01:00
|
|
|
# Piwik tracking code
|
2018-03-06 08:57:50 +00:00
|
|
|
if(lc($config{piwik_tracking}->{enabled} || "") eq "y") {
|
2014-06-02 16:11:02 +01:00
|
|
|
$piwik_url = $config{piwik_tracking}->{url} || "";
|
|
|
|
$piwik_sid = $config{piwik_tracking}->{sid} || "";
|
|
|
|
$piwik_img = $config{piwik_tracking}->{img} || "";
|
|
|
|
$piwik_code = <<"EOF";
|
|
|
|
|
|
|
|
<!-- Piwik -->
|
|
|
|
<script type="text/javascript">
|
|
|
|
var _paq = _paq || [];
|
|
|
|
_paq.push(['trackPageView']);
|
|
|
|
_paq.push(['enableLinkTracking']);
|
|
|
|
(function() {
|
|
|
|
var u=(("https:" == document.location.protocol) ? "https" : "http") + "$piwik_url";
|
|
|
|
_paq.push(['setTrackerUrl', u+'piwik.php']);
|
|
|
|
_paq.push(['setSiteId', $piwik_sid]);
|
|
|
|
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
|
|
|
|
g.defer=true; g.async=true; g.src=u+'piwik.js';
|
|
|
|
s.parentNode.insertBefore(g,s);
|
|
|
|
})();
|
|
|
|
</script>
|
|
|
|
<noscript>
|
|
|
|
<p><img src="$piwik_img" style="border:0;" alt=""/></p>
|
|
|
|
</noscript>
|
|
|
|
<!-- End Piwik Code -->
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2013-06-18 15:00:28 +01:00
|
|
|
# force to only one trailing slash
|
|
|
|
(my $base_url = $config{base_url}) =~ s/\/*$/\//;
|
|
|
|
(my $base_cgi = $config{base_cgi}) =~ s/\/*$/\//;
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
if(!open(OUT, "> $config{base_dir}/index.html")) {
|
2013-01-10 11:18:28 +00:00
|
|
|
die "unable to create '${config{base_dir}}index.html': $!";
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
print(OUT <<EOF);
|
2017-06-26 09:39:49 +01:00
|
|
|
<!DOCTYPE html "-//W3C//DTD HTML 4.01 Final//EN">
|
2012-10-22 15:26:37 +01:00
|
|
|
<html>
|
|
|
|
<head>
|
2013-01-04 08:27:05 +00:00
|
|
|
<title>$config{title}</title>
|
2013-02-11 14:28:20 +00:00
|
|
|
<link rel="shortcut icon" href="$base_url$config{favicon}">
|
2012-10-22 15:26:37 +01:00
|
|
|
</head>
|
|
|
|
<body bgcolor="$bgcolor" text="#888888" vlink="#888888" link="#888888">
|
2014-06-02 16:11:02 +01:00
|
|
|
$piwik_code
|
2012-10-22 15:26:37 +01:00
|
|
|
<center>
|
|
|
|
<p>
|
|
|
|
<br>
|
|
|
|
<font face="Verdana, sans-serif">
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2015-04-09 00:03:10 +01:00
|
|
|
<a href="$config{logo_top_url}"><img src="$base_url$config{logo_top}" border="0"></a>
|
2012-10-22 15:26:37 +01:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<h2 align="right">v@{[VERSION]}</h2>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<p>
|
2013-02-11 14:28:20 +00:00
|
|
|
<form action="${base_cgi}monitorix.cgi" method="get">
|
2012-10-22 15:26:37 +01:00
|
|
|
<table cellspacing="5" cellpadding="0" bgcolor="$table_back_color" border="1">
|
|
|
|
<tr>
|
|
|
|
<td bgcolor="$title_back_color">
|
|
|
|
<font color="$title_fore_color">
|
|
|
|
<b> Hostname </b>
|
|
|
|
</font>
|
|
|
|
</td>
|
|
|
|
<td bgcolor="$title_back_color">
|
|
|
|
<font color="$title_fore_color">
|
|
|
|
<b> Graph </b>
|
|
|
|
</font>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
print(OUT " <td bgcolor='$bgcolor'>\n");
|
|
|
|
print(OUT " <select name='mode' size='1'>\n");
|
2013-01-07 17:11:17 +00:00
|
|
|
print(OUT " <optgroup label='Local Host'>\n");
|
|
|
|
print(OUT " <option value='localhost'>localhost</option>\n");
|
|
|
|
print(OUT " </optgroup>\n");
|
2013-01-04 08:27:05 +00:00
|
|
|
|
2018-03-06 08:57:50 +00:00
|
|
|
if(scalar(my @remotehost_list = split(',', $config{multihost}->{remotehost_list})) && lc($config{multihost}->{enabled} || "") eq "y") {
|
2012-10-22 15:26:37 +01:00
|
|
|
print(OUT " <optgroup label='Multihost'>\n");
|
2013-01-07 17:11:17 +00:00
|
|
|
print(OUT " <option value='multihost.all'>All</option>\n");
|
2013-01-04 08:27:05 +00:00
|
|
|
for($n = 0; $n < scalar(@remotehost_list); $n++) {
|
|
|
|
print(OUT " <option value='multihost.$n'>" . trim($remotehost_list[$n]) . "</option>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
print(OUT " </optgroup>\n");
|
|
|
|
|
2013-01-07 17:11:17 +00:00
|
|
|
if(lc($config{multihost}->{groups}) eq "y" ) {
|
|
|
|
my @remotegroup_list = split(',', $config{multihost}->{remotegroup_list});
|
2013-01-04 08:27:05 +00:00
|
|
|
print(OUT " <optgroup label='Multihost-Groups'>\n");
|
|
|
|
print(OUT " <option value='multihost.group'>All Groups</option>\n");
|
|
|
|
for($n = 0; $n < scalar(@remotegroup_list); $n++) {
|
|
|
|
print(OUT " <option value='multihost.group$n'>" . trim($remotegroup_list[$n]) . "</option>\n");
|
|
|
|
}
|
|
|
|
print(OUT " </optgroup>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-06 08:57:50 +00:00
|
|
|
if(scalar(my @tal = split(',', $config{traffacct}->{list})) && lc($config{traffacct}->{enabled} || "") eq "y") {
|
2013-01-07 17:11:17 +00:00
|
|
|
print(OUT " <optgroup label='Traffic Accounting'>\n");
|
|
|
|
print(OUT " <option value='traffacct.all'>All</option>\n");
|
2013-01-08 16:22:05 +00:00
|
|
|
for($n = 0; $n < scalar(@tal); $n++) {
|
|
|
|
print(OUT " <option value='traffacct.$n'>" . trim($tal[$n]) . "</option>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
print(OUT " </optgroup>\n");
|
|
|
|
}
|
|
|
|
print(OUT " </select>\n");
|
|
|
|
print(OUT " </td>\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(OUT " <td bgcolor='$bgcolor'>\n");
|
|
|
|
print(OUT " <select name='graph' size='1'>\n");
|
|
|
|
print(OUT " <option value='all'>All graphs</option>\n");
|
2013-01-04 08:27:05 +00:00
|
|
|
foreach (split(',', $config{graph_name})) {
|
|
|
|
my $g = trim($_);
|
|
|
|
if(lc($config{graph_enable}->{$g}) eq "y") {
|
|
|
|
print(OUT " <optgroup label='" . $config{graph_title}->{$g} . "'>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
if($g eq "proc") {
|
2013-01-04 08:27:05 +00:00
|
|
|
for($n = 0; $n < $config{proc}->{max}; $n++) {
|
2012-10-22 15:26:37 +01:00
|
|
|
$gname = "_" . $g;
|
2013-01-04 08:27:05 +00:00
|
|
|
print(OUT " <option value='" . $gname . $n . "'>" . $config{graphs}->{$gname} . " " . $n . "</option>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2016-12-20 09:13:57 +00:00
|
|
|
if($g eq "ipmi") {
|
|
|
|
for($n = 0; $n < scalar(my @ipmi_list = split(',', $config{ipmi}->{list})); $n++) {
|
|
|
|
my $name = trim($ipmi_list[$n]);
|
|
|
|
$gname = "_" . $g;
|
|
|
|
print(OUT " <option value='" . $gname . $n . "'>" . $name . "</option>\n");
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2017-11-24 08:06:40 +00:00
|
|
|
if($g eq "ambsens") {
|
|
|
|
for($n = 0; $n < scalar(my @ambsens_list = split(',', $config{ambsens}->{list})); $n++) {
|
|
|
|
my $name = trim($ambsens_list[$n]);
|
|
|
|
$gname = "_" . $g;
|
|
|
|
print(OUT " <option value='" . $gname . $n . "'>" . $name . "</option>\n");
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2015-02-25 12:19:11 +00:00
|
|
|
if($g eq "fs" || $g eq "process") {
|
2013-05-10 11:04:38 +01:00
|
|
|
$n = 0;
|
|
|
|
foreach my $k (sort keys %{$config{graphs}}) {
|
|
|
|
if($k =~ m/$g/) {
|
|
|
|
$gname = "_" . $g . ++$n;
|
|
|
|
my $gname2 = "_" . $g . "0" . $n;
|
|
|
|
if($config{graphs}->{$gname}) {
|
|
|
|
print(OUT " <option value='" . $gname2 ."'>" . $config{graphs}->{$gname} . "</option>\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2015-05-06 11:56:54 +01:00
|
|
|
if($g eq "du") {
|
|
|
|
for($n = 0; $n < scalar(my @du_list = split(',', $config{du}->{list})); $n++) {
|
|
|
|
my $name = trim($du_list[$n]);
|
|
|
|
$gname = "_" . $g;
|
|
|
|
print(OUT " <option value='" . $gname . $n . "'>" . $name . "</option>\n");
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2012-10-22 15:26:37 +01:00
|
|
|
if($g eq "net") {
|
|
|
|
my $n2;
|
2013-01-04 08:27:05 +00:00
|
|
|
for($n = 0; $n < scalar(my @nl = split(',', $config{net}->{list})); $n++) {
|
2012-10-22 15:26:37 +01:00
|
|
|
$gname = "_" . $g;
|
|
|
|
for($n2 = 1; $n2 <= 3; $n2++) {
|
2013-01-04 08:27:05 +00:00
|
|
|
my $str = trim($nl[$n]) . " " . $config{graphs}->{$gname . $n2};
|
2012-10-22 15:26:37 +01:00
|
|
|
print(OUT " <option value='" . $gname . $n . $n2 . "'>" . $str . "</option>\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if($g eq "port") {
|
2013-01-04 08:27:05 +00:00
|
|
|
for($n = 0; $n < $config{port}->{max} && $n < scalar(my @port_list = split(',', $config{port}->{list})); $n++) {
|
|
|
|
my $num = trim($port_list[$n]);
|
2014-02-20 11:54:27 +00:00
|
|
|
if(!$config{port}->{desc}->{$num}) {
|
|
|
|
logger("$myself: port number '$num' listed but not defined.");
|
|
|
|
next;
|
|
|
|
}
|
2013-01-29 11:46:25 +00:00
|
|
|
my $name = trim((split(',', $config{port}->{desc}->{$num}))[0]);
|
|
|
|
my $pcon = trim((split(',', $config{port}->{desc}->{$num}))[2]);
|
2012-10-22 15:26:37 +01:00
|
|
|
$gname = "_" . $g;
|
2013-01-29 11:46:25 +00:00
|
|
|
foreach my $c (split('/', $pcon)) {
|
|
|
|
$c = uc(trim($c));
|
|
|
|
print(OUT " <option value='" . $gname . $n . "'>" . $config{graphs}->{$gname} . " " . $num . " (" . $c . "-" . $name . ")" . "</option>\n");
|
|
|
|
}
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if($g eq "fail2ban") {
|
2013-01-04 08:27:05 +00:00
|
|
|
for($n = 0; $n < scalar(my @fail2ban_list = split(',', $config{fail2ban}->{list})); $n++) {
|
|
|
|
my $name = trim($fail2ban_list[$n]);
|
2012-10-22 15:26:37 +01:00
|
|
|
$gname = "_" . $g;
|
2013-01-04 08:27:05 +00:00
|
|
|
print(OUT " <option value='" . $gname . $n . "'>" . $name . "</option>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
$n = 0;
|
2013-01-04 08:27:05 +00:00
|
|
|
foreach my $k (sort keys %{$config{graphs}}) {
|
2012-10-22 15:26:37 +01:00
|
|
|
if($k =~ m/$g/) {
|
|
|
|
$gname = "_" . $g . ++$n;
|
2013-01-04 08:27:05 +00:00
|
|
|
if($config{graphs}->{$gname}) {
|
|
|
|
print(OUT " <option value='" . $gname ."'>" . $config{graphs}->{$gname} . "</option>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print(OUT " </optgroup>\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print(OUT " </select>\n");
|
|
|
|
print(OUT " </td>\n");
|
|
|
|
|
|
|
|
|
|
|
|
print(OUT <<EOF);
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<p>
|
|
|
|
<table cellspacing="5" cellpadding="0" bgcolor="$table_back_color" border="1">
|
|
|
|
<tr>
|
2016-03-01 10:08:31 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
if(lc($config{enable_hourly_view} || "") eq "y" ) {
|
|
|
|
print(OUT <<EOF);
|
|
|
|
<td bgcolor="$title_back_color">
|
2017-06-15 14:11:03 +01:00
|
|
|
<label>
|
|
|
|
<input type="radio" name="when" value="1hour">
|
|
|
|
<font color="$title_fore_color"><b>Hourly </b></font>
|
|
|
|
</label>
|
2016-03-01 10:08:31 +00:00
|
|
|
</td>
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
print(OUT <<EOF);
|
2012-10-22 15:26:37 +01:00
|
|
|
<td bgcolor="$title_back_color">
|
2017-06-15 14:11:03 +01:00
|
|
|
<label>
|
|
|
|
<input type="radio" checked name="when" value="1day">
|
|
|
|
<font color="$title_fore_color"><b>Daily </b></font>
|
|
|
|
</label>
|
2012-10-22 15:26:37 +01:00
|
|
|
</td>
|
|
|
|
<td bgcolor="$title_back_color">
|
2017-06-15 14:11:03 +01:00
|
|
|
<label>
|
|
|
|
<input type="radio" name="when" value="1week">
|
|
|
|
<font color="$title_fore_color"><b>Weekly </b></font>
|
|
|
|
</label>
|
2012-10-22 15:26:37 +01:00
|
|
|
</td>
|
|
|
|
<td bgcolor="$title_back_color">
|
2017-06-15 14:11:03 +01:00
|
|
|
<label>
|
|
|
|
<input type="radio" name="when" value="1month">
|
|
|
|
<font color="$title_fore_color"><b>Monthly </b></font>
|
|
|
|
</label>
|
2012-10-22 15:26:37 +01:00
|
|
|
</td>
|
|
|
|
<td bgcolor="$title_back_color">
|
2017-06-15 14:11:03 +01:00
|
|
|
<label>
|
|
|
|
<input type="radio" name="when" value="1year">
|
|
|
|
<font color="$title_fore_color"><b>Yearly </b></font>
|
|
|
|
</label>
|
2012-10-22 15:26:37 +01:00
|
|
|
</td>
|
|
|
|
</tr>
|
2013-11-06 14:14:45 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
if($config{max_historic_years} > 1) {
|
|
|
|
print(OUT " <tr>\n");
|
|
|
|
}
|
|
|
|
for($n = 2; $n <= $config{max_historic_years}; $n++) {
|
2016-04-11 20:41:59 +01:00
|
|
|
if($n > 2 && (($n - 2) % 4) == 0) {
|
|
|
|
print(OUT " </tr>\n");
|
|
|
|
print(OUT " <tr>\n");
|
|
|
|
}
|
2013-11-06 14:14:45 +00:00
|
|
|
print(OUT <<EOF);
|
|
|
|
<td bgcolor="$title_back_color">
|
2017-06-15 14:11:03 +01:00
|
|
|
<label>
|
|
|
|
<input type="radio" name="when" value="${n}year">
|
|
|
|
<font color="$title_fore_color"><b>$n Years </b></font>
|
|
|
|
</label>
|
2013-11-06 14:14:45 +00:00
|
|
|
</td>
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
if($config{max_historic_years} > 1) {
|
|
|
|
print(OUT " </tr>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
print(OUT <<EOF);
|
2012-10-22 15:26:37 +01:00
|
|
|
</table>
|
|
|
|
<p>
|
2013-01-04 08:27:05 +00:00
|
|
|
<input type="hidden" name="color" value="$theme">
|
2012-10-22 15:26:37 +01:00
|
|
|
<input type="submit" value=" Ok ">
|
|
|
|
</form>
|
|
|
|
</font>
|
|
|
|
</center>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
EOF
|
|
|
|
close(OUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
# Main
|
2012-10-22 15:26:37 +01:00
|
|
|
# ----------------------------------------------------------------------------
|
2014-04-08 11:54:32 +01:00
|
|
|
getopts("c:p:d:vn", \%options) || usage();
|
2012-10-22 15:26:37 +01:00
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
if($options{v}) {
|
|
|
|
print("Monitorix version " . VERSION . " (" . RELDATE . ")\n");
|
|
|
|
print("by Jordi Sanfeliu <jordi\@fibranet.cat>\n");
|
|
|
|
print("http://www.monitorix.org/\n\n");
|
|
|
|
exit(0);
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
2013-01-04 08:27:05 +00:00
|
|
|
if(!$options{c}) {
|
|
|
|
usage();
|
|
|
|
exit(1);
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
2018-07-06 08:06:59 +01:00
|
|
|
$options{c} = (abs_path($options{c}) || $options{c}) unless $^V lt 5.6.2;
|
2013-01-04 08:27:05 +00:00
|
|
|
if(!stat($options{c})) {
|
2013-01-10 11:18:28 +00:00
|
|
|
die "can't open file '$options{c}': $!";
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
|
2014-03-11 08:26:28 +00:00
|
|
|
# load main configuration file
|
2013-01-04 08:27:05 +00:00
|
|
|
my $conf = new Config::General(
|
|
|
|
-ConfigFile => $options{c},
|
|
|
|
);
|
|
|
|
%config = $conf->getall;
|
|
|
|
$config{debug} = ();
|
|
|
|
$config{func_update} = ();
|
2012-10-22 15:26:37 +01:00
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
# get the current OS and kernel version and check its support
|
|
|
|
my $release;
|
|
|
|
($config{os}, undef, $release) = uname();
|
2014-01-22 12:08:49 +00:00
|
|
|
if(!($release =~ m/^(\d+)\.(\d+)/)) {
|
|
|
|
die "FATAL: unable to get the kernel version.";
|
|
|
|
}
|
|
|
|
$config{kernel} = "$1.$2";
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
if(!grep {$_ eq $config{os}} @suppsys) {
|
2013-01-10 11:18:28 +00:00
|
|
|
die "FATAL: your operating system ($config{os}) is not supported.";
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
if(grep {$_ eq $config{os}} ("FreeBSD", "OpenBSD", "NetBSD")) {
|
|
|
|
$SIG{'CHLD'} = 'DEFAULT';
|
|
|
|
}
|
2012-10-22 15:26:37 +01:00
|
|
|
|
2015-09-17 14:34:48 +01:00
|
|
|
$0 = sprintf("%s %s%s%s%s%s",
|
2013-01-04 08:27:05 +00:00
|
|
|
$^V lt 5.6.2 ? "monitorix" : abs_path($0),
|
|
|
|
$options{c} ? "-c $options{c}" : "",
|
|
|
|
$options{p} ? " -p $options{p}" : "",
|
|
|
|
$options{d} ? " -d $options{d}" : "",
|
2014-04-08 11:54:32 +01:00
|
|
|
$options{v} ? " -v" : "",
|
|
|
|
$options{n} ? " -n" : "");
|
2012-10-22 15:26:37 +01:00
|
|
|
|
2014-04-08 11:54:32 +01:00
|
|
|
daemonize() unless $options{n};
|
2013-01-04 08:27:05 +00:00
|
|
|
logger("Starting Monitorix version " . VERSION . " (pid $$).");
|
2014-05-21 14:32:07 +01:00
|
|
|
logger("Loaded main configuration file '$options{c}'.");
|
2012-10-22 15:26:37 +01:00
|
|
|
|
2014-02-20 08:08:05 +00:00
|
|
|
# save the pidfile
|
2013-01-04 08:27:05 +00:00
|
|
|
if($options{p}) {
|
|
|
|
$options{p} = abs_path($options{p});
|
|
|
|
open(OUT, "> $options{p}")
|
2013-01-10 11:18:28 +00:00
|
|
|
|| die "could not open '$options{p}' for writing: $!";
|
2013-01-04 08:27:05 +00:00
|
|
|
print(OUT "$$");
|
|
|
|
close(OUT);
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
# change to a safety directory
|
|
|
|
unless(chdir("/tmp")) {
|
2013-03-15 06:57:21 +00:00
|
|
|
die "can't chdir to /tmp: $!";
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
if($options{d}) {
|
|
|
|
if($options{d} ne "none" && $options{d} ne "all") {
|
|
|
|
@{$config{debug}} = split(',', $options{d});
|
|
|
|
foreach my $t (@{$config{debug}}) {
|
2013-07-10 17:53:59 +01:00
|
|
|
if(!grep {trim($_) eq $t} (split(',', $config{graph_name} . ", traffacct, emailreports"))) {
|
2013-01-10 11:18:28 +00:00
|
|
|
die "Invalid debug key '$t'";
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-04 08:27:05 +00:00
|
|
|
logger("Entering in debug mode.");
|
|
|
|
logger("Changed process name to '$0'.");
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
|
2014-03-11 08:26:28 +00:00
|
|
|
# load additional configuration files
|
2014-03-18 08:03:02 +00:00
|
|
|
if($config{include_dir} && opendir(DIR, $config{include_dir})) {
|
2014-03-11 08:26:28 +00:00
|
|
|
my @files = grep { !/^[.]/ } readdir(DIR);
|
2014-06-02 16:26:27 +01:00
|
|
|
closedir(DIR);
|
2014-03-11 08:26:28 +00:00
|
|
|
foreach my $c (sort @files) {
|
2014-03-11 10:18:58 +00:00
|
|
|
next unless -f $config{include_dir} . "/$c";
|
|
|
|
next unless $c =~ m/\.conf$/;
|
2014-05-21 14:32:07 +01:00
|
|
|
logger("Loading extra configuration file '$config{include_dir}/$c'.");
|
2014-03-11 08:26:28 +00:00
|
|
|
my $conf_inc = new Config::General(
|
|
|
|
-ConfigFile => $config{include_dir} . "/$c",
|
|
|
|
);
|
|
|
|
my %config_inc = $conf_inc->getall;
|
2014-04-08 10:27:49 +01:00
|
|
|
while(my ($key, $val) = each(%config_inc)) {
|
|
|
|
if(ref($val) eq "HASH") {
|
|
|
|
# two level options
|
|
|
|
while(my ($key2, $val2) = each(%{$val})) {
|
|
|
|
if(ref($val2) eq "HASH") {
|
|
|
|
# three level options
|
|
|
|
while(my ($key3, $val3) = each(%{$val2})) {
|
|
|
|
$config{$key}->{$key2}->{$key3} = $val3;
|
|
|
|
delete $config_inc{$key}->{$key2}->{$key3};
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
$config{$key}->{$key2} = $val2;
|
|
|
|
delete $config_inc{$key}->{$key2};
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
# graph_name option is special
|
|
|
|
if($key eq "graph_name") {
|
|
|
|
$config{graph_name} .= ", $val";
|
|
|
|
delete $config_inc{graph_name};
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
# one level options
|
|
|
|
$config{$key} = $val;
|
|
|
|
delete $config_inc{$key};
|
2014-03-11 08:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-03-18 08:03:02 +00:00
|
|
|
logger("Can't read directory '$config{include_dir}'. $!")
|
|
|
|
if $config{include_dir};
|
2014-03-11 08:26:28 +00:00
|
|
|
}
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
# save the path of the configuration file
|
2013-01-31 17:48:29 +00:00
|
|
|
if(open(OUT, "> " . $config{base_dir} . "/cgi/monitorix.conf.path")) {
|
2013-01-04 08:27:05 +00:00
|
|
|
print(OUT "$options{c}\n");
|
|
|
|
close(OUT);
|
|
|
|
} else {
|
2015-09-24 09:18:15 +01:00
|
|
|
logger("WARNING: unable to create the file '$config{base_dir}/cgi/monitorix.conf.path'. $!");
|
2013-01-31 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
2015-07-20 12:02:58 +01:00
|
|
|
if($config{os} eq "Linux") {
|
|
|
|
# make sure that 'ip_default_table' option has a consistent value
|
|
|
|
$config{ip_default_table} = "filter" if !$config{ip_default_table};
|
|
|
|
|
|
|
|
# check 'iptables' version to include the new wait lock option '--wait'
|
|
|
|
my $ipv = `iptables --version`;
|
|
|
|
chomp($ipv);
|
|
|
|
$ipv =~ s/^iptables v//;
|
|
|
|
$ipv = sprintf("%03s.%03s.%03s", split('\.', $ipv));
|
|
|
|
if($ipv gt "001.004.020") { # 1.4.20
|
|
|
|
$config{iptables_wait_lock} = " --wait ";
|
|
|
|
} else {
|
|
|
|
$config{iptables_wait_lock} = "";
|
|
|
|
}
|
2015-02-17 14:36:42 +00:00
|
|
|
}
|
|
|
|
|
2017-08-31 15:15:36 +01:00
|
|
|
# make sure that some options are correctly defined
|
|
|
|
if(!$config{max_historic_years}) {
|
|
|
|
logger("WARNING: the 'max_historic_years' option doesn't exist. Please consider upgrading your configuration file.");
|
|
|
|
$config{max_historic_years} = 1;
|
|
|
|
}
|
|
|
|
if(!$config{net}->{max}) {
|
|
|
|
logger("WARNING: the 'max' option in 'net.pm' doesn't exist. Please consider upgrading your configuration file.");
|
|
|
|
$config{net}->{max} = 10;
|
|
|
|
}
|
|
|
|
|
2014-09-03 16:02:28 +01:00
|
|
|
# make sure that there aren't residual Monitorix iptables rules
|
2013-01-04 08:27:05 +00:00
|
|
|
flush_accounting_rules(\%config, $options{d});
|
2012-10-22 15:26:37 +01:00
|
|
|
|
2014-05-21 14:32:07 +01:00
|
|
|
logger("Initializing graphs.");
|
2014-07-29 09:51:34 +01:00
|
|
|
|
|
|
|
# check for inconsistencies between enabled graphs and defined graphs
|
|
|
|
foreach my $g (sort keys %{$config{graph_enable}}) {
|
2018-03-06 08:57:50 +00:00
|
|
|
if(lc($config{graph_enable}->{$g} || "") eq "y") {
|
2014-07-29 09:51:34 +01:00
|
|
|
if(!grep {trim($_) eq $g} (split(',', $config{graph_name}))) {
|
|
|
|
logger("WARNING: inconsitency between '<graph_enable>' and 'graph_name' options; '$g' doesn't exist.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-03 16:02:28 +01:00
|
|
|
# initialize all enabled graphs
|
2013-07-16 15:56:26 +01:00
|
|
|
foreach (split(',', $config{graph_name} . ", traffacct")) {
|
2013-01-04 08:27:05 +00:00
|
|
|
my $g = trim($_);
|
2013-01-07 18:09:17 +00:00
|
|
|
my $e = "n";
|
|
|
|
|
2013-07-16 15:56:26 +01:00
|
|
|
if($g eq "traffacct") {
|
2018-03-06 08:57:50 +00:00
|
|
|
$e = lc($config{$g}->{enabled} || "");
|
2013-01-07 18:09:17 +00:00
|
|
|
} else {
|
2018-03-06 08:57:50 +00:00
|
|
|
$e = lc($config{graph_enable}->{$g} || "");
|
2013-01-07 18:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if($e eq "y") {
|
2013-01-04 08:27:05 +00:00
|
|
|
my $init = $g . "_init";
|
|
|
|
my $d = $g;
|
2012-10-22 15:26:37 +01:00
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
undef($d) if(!grep {trim($_) eq $d} (@{$config{debug}}));
|
|
|
|
if(defined($options{d}) && $options{d} eq "all") {
|
|
|
|
$d = $g;
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
eval "use $g qw(" . $init . " " . $g . "_update)";
|
|
|
|
if($@) {
|
2014-04-08 10:52:42 +01:00
|
|
|
logger("WARNING: unable to load module '$g'. $@");
|
2012-10-22 15:26:37 +01:00
|
|
|
next;
|
|
|
|
}
|
2013-01-04 08:27:05 +00:00
|
|
|
{
|
|
|
|
no strict "refs";
|
|
|
|
eval { &$init($g, \%config, $d); };
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
2014-03-11 08:26:28 +00:00
|
|
|
logger("WARNING: unexpected errors in function $init().") if($@);
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
if(!scalar($config{func_update})) {
|
2013-06-28 12:13:22 +01:00
|
|
|
logger("Nothing to do, exiting.");
|
2012-10-22 15:26:37 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2014-05-21 14:32:07 +01:00
|
|
|
logger("Generating the 'index.html' file.");
|
2015-04-09 08:04:25 +01:00
|
|
|
if(!defined($config{logo_top_url})) {
|
|
|
|
logger("WARNING: the 'logo_top_url' option doesn't exist. Please consider upgrading your configuration file.");
|
|
|
|
$config{logo_top_url} = "http://www.monitorix.org/";
|
|
|
|
}
|
2012-10-22 15:26:37 +01:00
|
|
|
create_index();
|
2013-03-01 11:19:00 +00:00
|
|
|
|
2014-09-03 16:02:28 +01:00
|
|
|
# start the HTTP built-in (if enabled)
|
2014-07-29 09:55:48 +01:00
|
|
|
if(lc($config{httpd_builtin}->{enabled}) eq "y") {
|
2018-10-04 11:51:33 +01:00
|
|
|
logger("Setting owner/group and permission bits for the imgs/ directory.") if defined($options{d});
|
|
|
|
my (undef, undef, $uid) = getpwnam($config{httpd_builtin}->{user});
|
|
|
|
my (undef, undef, $gid) = getgrnam($config{httpd_builtin}->{group});
|
|
|
|
chown($uid, $gid, $config{base_dir} . "/" . $config{imgs_dir});
|
|
|
|
chmod(0755, $config{base_dir} . "/" . $config{imgs_dir});
|
|
|
|
|
2017-01-13 09:14:47 +00:00
|
|
|
require HTTPServer;
|
2013-03-01 11:19:00 +00:00
|
|
|
httpd_setup(\%config, $options{d});
|
2014-06-19 08:44:02 +01:00
|
|
|
logger("Started built-in HTTP server (pid $config{httpd_pid}).") if (defined($config{httpd_pid}));
|
2013-03-01 11:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-09-03 16:02:28 +01:00
|
|
|
# make sure that some options are correctly defined
|
2013-07-29 17:03:13 +01:00
|
|
|
if(!$config{global_zoom}) {
|
|
|
|
logger("WARNING: the 'global_zoom' option is not valid or doesn't exist. Please consider upgrading your configuration file.");
|
2016-01-25 17:18:21 +00:00
|
|
|
# it's set in 'monitorix.cgi'
|
2013-07-29 17:03:13 +01:00
|
|
|
}
|
2016-01-25 17:18:21 +00:00
|
|
|
if(!$config{image_format}) {
|
|
|
|
logger("WARNING: the 'image_format' option is not valid or doesn't exist. Please consider upgrading your configuration file.");
|
|
|
|
# it's set in 'monitorix.cgi'
|
|
|
|
}
|
2013-07-29 17:03:13 +01:00
|
|
|
|
2015-02-17 14:36:42 +00:00
|
|
|
|
2015-12-28 14:59:05 +00:00
|
|
|
setpriority(0, 0, $config{priority} || 0);
|
2014-06-17 09:04:26 +01:00
|
|
|
logger("Ok, ready.");
|
2012-10-22 15:26:37 +01:00
|
|
|
|
2014-09-03 16:02:28 +01:00
|
|
|
# main loop
|
2012-10-22 15:26:37 +01:00
|
|
|
while(1) {
|
2013-07-11 11:17:12 +01:00
|
|
|
local $SIG{'ALRM'} = sub { };
|
2013-06-07 07:59:57 +01:00
|
|
|
alarm(1);
|
|
|
|
pause();
|
|
|
|
|
2013-07-10 17:53:59 +01:00
|
|
|
my ($sec, $min, $hour, $mday, $mon, undef, $wday) = localtime(time);
|
2013-06-07 07:59:57 +01:00
|
|
|
|
|
|
|
# call to all enabled graphs on every minute
|
|
|
|
if($sec == 0) {
|
|
|
|
foreach my $f (@{$config{func_update}}) {
|
|
|
|
my $update = $f . "_update";
|
|
|
|
my $d = $f;
|
|
|
|
logger("Calling $update()") unless !$options{d};
|
|
|
|
|
|
|
|
undef($d) if(!grep {trim($_) eq $d} (@{$config{debug}}));
|
|
|
|
if(defined($options{d}) && $options{d} eq "all") {
|
|
|
|
$d = $f;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
no strict "refs";
|
|
|
|
eval { &$update($f, \%config, $d); };
|
|
|
|
if($@) {
|
|
|
|
logger("$update(): $@");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-10 17:53:59 +01:00
|
|
|
|
|
|
|
# TRAFFACCT graph daily reports
|
2016-06-03 09:49:10 +01:00
|
|
|
if(lc($config{traffacct}->{enabled}) eq "y") {
|
2013-06-07 07:59:57 +01:00
|
|
|
my $d = "traffacct";
|
|
|
|
undef($d) if(!grep {trim($_) eq $d} (@{$config{debug}}));
|
|
|
|
|
|
|
|
# at 00:00h
|
|
|
|
if($min == 0 && $hour == 0) {
|
|
|
|
|
|
|
|
# collect traffic accounting every day
|
|
|
|
eval { traffacct::traffacct_getcounters(\%config, $d); };
|
|
|
|
if($@) {
|
|
|
|
logger("traffacct::traffacct_getcounters(): $@");
|
|
|
|
}
|
|
|
|
|
|
|
|
# send reports every first day of a month
|
2016-05-20 09:15:12 +01:00
|
|
|
if(lc($config{traffacct}->{reports}->{enabled}) eq "y") {
|
|
|
|
if($mday == 1) {
|
|
|
|
eval { traffacct::traffacct_sendreports(\%config, $d); };
|
|
|
|
if($@) {
|
|
|
|
logger("traffacct::traffacct_sendreports(): $@");
|
|
|
|
}
|
2013-06-07 07:59:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-10 17:53:59 +01:00
|
|
|
|
|
|
|
# Email Reports
|
|
|
|
if(lc($config{emailreports}->{enabled}) eq "y") {
|
|
|
|
my $emailreports = $config{emailreports};
|
2014-01-30 16:01:20 +00:00
|
|
|
my $m = $emailreports->{minute} || 0;
|
|
|
|
my $h = $emailreports->{hour} || 0;
|
2013-07-10 17:53:59 +01:00
|
|
|
my $d = "emailreports";
|
|
|
|
undef($d) if(!grep {trim($_) eq $d} (@{$config{debug}}));
|
|
|
|
|
2014-01-29 17:00:56 +00:00
|
|
|
if($min == $m && $hour == $h) {
|
2013-07-10 17:53:59 +01:00
|
|
|
|
2013-07-18 11:54:34 +01:00
|
|
|
eval "use emailreports qw(emailreports_send)";
|
|
|
|
if($@) {
|
2014-04-08 12:10:04 +01:00
|
|
|
logger("WARNING: unable to load module 'emailreports'. $@");
|
2013-07-18 11:54:34 +01:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2013-07-10 17:53:59 +01:00
|
|
|
# daily
|
|
|
|
if(lc($emailreports->{daily}->{enabled}) eq "y") {
|
|
|
|
eval { emailreports::emailreports_send(\%config, "daily", "1day", $d); };
|
|
|
|
if($@) {
|
|
|
|
logger("emailreports::emailreports_send(): $@");
|
|
|
|
}
|
|
|
|
}
|
2013-07-11 15:35:43 +01:00
|
|
|
|
|
|
|
# weekly (send reports on every Monday)
|
|
|
|
if($wday == 1) {
|
|
|
|
if(lc($emailreports->{weekly}->{enabled}) eq "y") {
|
|
|
|
eval { emailreports::emailreports_send(\%config, "weekly", "1week", $d); };
|
|
|
|
if($@) {
|
|
|
|
logger("emailreports::emailreports_send(): $@");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# monthly (send reports every first day of each month)
|
|
|
|
if($mday == 1) {
|
|
|
|
if(lc($emailreports->{monthly}->{enabled}) eq "y") {
|
|
|
|
eval { emailreports::emailreports_send(\%config, "monthly", "1month", $d); };
|
|
|
|
if($@) {
|
|
|
|
logger("emailreports::emailreports_send(): $@");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# yearly (send reports every first day of each year)
|
|
|
|
if($mon == 0 && $mday == 1) {
|
|
|
|
if(lc($emailreports->{yearly}->{enabled}) eq "y") {
|
|
|
|
eval { emailreports::emailreports_send(\%config, "yearly", "1year", $d); };
|
|
|
|
if($@) {
|
|
|
|
logger("emailreports::emailreports_send(): $@");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-10 17:53:59 +01:00
|
|
|
}
|
|
|
|
}
|
2013-06-07 07:59:57 +01:00
|
|
|
}
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|