2012-10-22 15:26:37 +01:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
#
|
|
|
|
# Monitorix - A lightweight system monitoring tool.
|
|
|
|
#
|
2015-03-03 15:50:54 +00:00
|
|
|
# Copyright (C) 2005-2015 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.
|
|
|
|
#
|
|
|
|
|
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";
|
2012-10-22 15:26:37 +01:00
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
use Monitorix;
|
|
|
|
use CGI qw(:standard);
|
|
|
|
use Config::General;
|
|
|
|
use POSIX;
|
|
|
|
use RRDs;
|
2012-10-22 15:26:37 +01:00
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
my %config;
|
|
|
|
my %cgi;
|
|
|
|
my %colors;
|
|
|
|
my %tf;
|
|
|
|
my @version12;
|
|
|
|
my @version12_small;
|
2012-10-22 15:26:37 +01:00
|
|
|
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
sub multihost {
|
|
|
|
my ($config, $colors, $cgi) = @_;
|
2012-10-22 15:26:37 +01:00
|
|
|
|
|
|
|
my $n;
|
|
|
|
my $n2;
|
2013-01-04 08:27:05 +00:00
|
|
|
my @host;
|
|
|
|
my @url;
|
2013-07-09 09:10:26 +01:00
|
|
|
my @foot_url;
|
2013-01-04 08:27:05 +00:00
|
|
|
my $multihost = $config->{multihost};
|
2012-10-22 15:26:37 +01:00
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
if($cgi->{val} =~ m/group(\d*)/) {
|
|
|
|
my @remotegroup_desc;
|
2012-10-22 15:26:37 +01:00
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
# all groups
|
|
|
|
if($cgi->{val} eq "group") {
|
|
|
|
my @remotegroup_list = split(',', $multihost->{remotegroup_list});
|
|
|
|
for($n = 0; $n < scalar(@remotegroup_list); $n++) {
|
|
|
|
scalar(my @tmp = split(',', $multihost->{remotegroup_desc}->{$n}));
|
|
|
|
for($n2 = 0; $n2 < scalar(@tmp); $n2++) {
|
|
|
|
push(@remotegroup_desc, trim($tmp[$n2]));
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
# specific group
|
|
|
|
if($cgi->{val} =~ m/group(\d+)/) {
|
|
|
|
my $gnum = int($1);
|
|
|
|
@remotegroup_desc = split(',', $multihost->{remotegroup_desc}->{$gnum});
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
my @remotehost_list = split(',', $multihost->{remotehost_list});
|
|
|
|
for($n = 0; $n < scalar(@remotegroup_desc); $n++) {
|
|
|
|
my $h = trim($remotegroup_desc[$n]);
|
|
|
|
for($n2 = 0; $n2 < scalar(@remotehost_list); $n2++) {
|
|
|
|
my $h2 = trim($remotehost_list[$n2]);
|
|
|
|
if($h eq $h2) {
|
|
|
|
push(@host, $h);
|
2013-07-09 09:10:26 +01:00
|
|
|
push(@url, (split(',', $multihost->{remotehost_desc}->{$n2}))[0] . (split(',', $multihost->{remotehost_desc}->{$n2}))[2]);
|
|
|
|
push(@foot_url, (split(',', $multihost->{remotehost_desc}->{$n2}))[0] . (split(',', $multihost->{remotehost_desc}->{$n2}))[1]);
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-20 08:26:48 +00:00
|
|
|
} else {
|
2013-01-04 08:27:05 +00:00
|
|
|
my @remotehost_list = split(',', $multihost->{remotehost_list});
|
|
|
|
for($n = 0; $n < scalar(@remotehost_list); $n++) {
|
|
|
|
push(@host, trim($remotehost_list[$n]));
|
2013-07-09 09:10:26 +01:00
|
|
|
push(@url, (split(',', $multihost->{remotehost_desc}->{$n}))[0] . (split(',', $multihost->{remotehost_desc}->{$n}))[2]);
|
|
|
|
push(@foot_url, (split(',', $multihost->{remotehost_desc}->{$n}))[0] . (split(',', $multihost->{remotehost_desc}->{$n}))[1]);
|
2012-11-20 08:26:48 +00:00
|
|
|
}
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
|
2013-01-07 11:58:56 +00:00
|
|
|
$multihost->{graphs_per_row} = 1 unless $multihost->{graphs_per_row} > 1;
|
2013-01-04 08:27:05 +00:00
|
|
|
my $graph = ($cgi->{graph} eq "all" || $cgi->{graph} =~ m/group\[0-9]*/) ? "_system1" : $cgi->{graph};
|
2012-10-22 15:26:37 +01:00
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
if($cgi->{val} eq "all" || $cgi->{val} =~ m/group[0-9]*/) {
|
2013-01-07 11:58:56 +00:00
|
|
|
for($n = 0; $n < scalar(@host); $n += $multihost->{graphs_per_row}) {
|
2013-01-04 08:27:05 +00:00
|
|
|
print "<table cellspacing='5' cellpadding='0' width='1' bgcolor='$colors->{graph_bg_color}' border='1'>\n";
|
2012-10-22 15:26:37 +01:00
|
|
|
print " <tr>\n";
|
2013-01-07 11:58:56 +00:00
|
|
|
for($n2 = 0; $n2 < $multihost->{graphs_per_row}; $n2++) {
|
2013-01-04 08:27:05 +00:00
|
|
|
if($n < scalar(@host)) {
|
|
|
|
print " <td bgcolor='$colors->{title_bg_color}'>\n";
|
|
|
|
print " <font face='Verdana, sans-serif' color='$colors->{fg_color}'>\n";
|
2014-01-27 09:33:19 +00:00
|
|
|
print " <b> " . $host[$n] . "</b>\n";
|
2012-10-22 15:26:37 +01:00
|
|
|
print " </font>\n";
|
|
|
|
print " </td>\n";
|
|
|
|
}
|
|
|
|
$n++;
|
|
|
|
}
|
|
|
|
print " </tr>\n";
|
|
|
|
print " <tr>\n";
|
2013-01-07 11:58:56 +00:00
|
|
|
for($n2 = 0, $n = $n - $multihost->{graphs_per_row}; $n2 < $multihost->{graphs_per_row}; $n2++) {
|
2013-01-04 08:27:05 +00:00
|
|
|
if($n < scalar(@host)) {
|
|
|
|
print " <td bgcolor='$colors->{title_bg_color}' style='vertical-align: top; height: 10%; width: 10%;'>\n";
|
2014-01-15 14:00:46 +00:00
|
|
|
print " <iframe src='" . $url[$n] . "/monitorix.cgi?mode=localhost&when=$cgi->{when}&graph=$graph&color=$cgi->{color}&silent=imagetag' height=201 width=397 frameborder=0 marginwidth=0 marginheight=0 scrolling=no></iframe>\n";
|
2012-10-22 15:26:37 +01:00
|
|
|
print " </td>\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
$n++;
|
|
|
|
}
|
|
|
|
print " </tr>\n";
|
|
|
|
print " <tr>\n";
|
2013-01-07 11:58:56 +00:00
|
|
|
for($n2 = 0, $n = $n - $multihost->{graphs_per_row}; $n2 < $multihost->{graphs_per_row}; $n2++) {
|
2013-01-04 08:27:05 +00:00
|
|
|
if($n < scalar(@host)) {
|
|
|
|
if(lc($multihost->{footer_url}) eq "y") {
|
|
|
|
print " <td bgcolor='$colors->{title_bg_color}'>\n";
|
|
|
|
print " <font face='Verdana, sans-serif' color='$colors->{title_fg_color}'>\n";
|
2012-10-22 15:26:37 +01:00
|
|
|
print " <font size='-1'>\n";
|
2014-09-19 09:40:10 +01:00
|
|
|
print " <b> <a href='" . $foot_url[$n] . "' style='color: " . $colors->{title_fg_color} . ";'>$foot_url[$n]</a></b>\n";
|
2012-10-22 15:26:37 +01:00
|
|
|
print " </font></font>\n";
|
|
|
|
print " </td>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$n++;
|
|
|
|
}
|
2013-01-07 11:58:56 +00:00
|
|
|
$n = $n - $multihost->{graphs_per_row};
|
2012-10-22 15:26:37 +01:00
|
|
|
print " </tr>\n";
|
|
|
|
print "</table>\n";
|
|
|
|
print "<br>\n";
|
|
|
|
}
|
|
|
|
} else {
|
2013-01-04 08:27:05 +00:00
|
|
|
print " <table cellspacing='5' cellpadding='0' width='1' bgcolor='$colors->{graph_bg_color}' border='1'>\n";
|
2012-10-22 15:26:37 +01:00
|
|
|
print " <tr>\n";
|
2013-01-04 08:27:05 +00:00
|
|
|
print " <td bgcolor='$colors->{title_bg_color}'>\n";
|
|
|
|
print " <font face='Verdana, sans-serif' color='$colors->{fg_color}'>\n";
|
2014-01-27 09:33:19 +00:00
|
|
|
print " <b> " . $host[$cgi->{val}] . "</b>\n";
|
2012-10-22 15:26:37 +01:00
|
|
|
print " </font>\n";
|
|
|
|
print " </td>\n";
|
|
|
|
print " </tr>\n";
|
|
|
|
print " <tr>\n";
|
2013-01-04 08:27:05 +00:00
|
|
|
print " <td bgcolor='$colors->{title_bg_color}' style='vertical-align: top; height: 10%; width: 10%;'>\n";
|
2014-01-15 14:00:46 +00:00
|
|
|
print " <iframe src='" . (split(',', $multihost->{remotehost_desc}->{$cgi->{val}}))[0] . (split(',', $multihost->{remotehost_desc}->{$cgi->{val}}))[2] . "/monitorix.cgi?mode=localhost&when=$cgi->{when}&graph=$graph&color=$cgi->{color}&silent=imagetagbig' height=249 width=545 frameborder=0 marginwidth=0 marginheight=0 scrolling=no></iframe>\n";
|
2012-10-22 15:26:37 +01:00
|
|
|
print " </td>\n";
|
|
|
|
print " </tr>\n";
|
|
|
|
print " <tr>\n";
|
2013-01-04 08:27:05 +00:00
|
|
|
if(lc($multihost->{footer_url}) eq "y") {
|
|
|
|
print " <td bgcolor='$colors->{title_bg_color}'>\n";
|
|
|
|
print " <font face='Verdana, sans-serif' color='$colors->{title_fg_color}'>\n";
|
2012-10-22 15:26:37 +01:00
|
|
|
print " <font size='-1'>\n";
|
2014-09-19 09:40:10 +01:00
|
|
|
print " <b> <a href='" . $foot_url[$cgi->{val}] . "' style='color: " . $colors->{title_fg_color} . ";'>$foot_url[$cgi->{val}]</a></b>\n";
|
2012-10-22 15:26:37 +01:00
|
|
|
print " </font></font>\n";
|
|
|
|
print " </td>\n";
|
|
|
|
}
|
|
|
|
print " </tr>\n";
|
|
|
|
print " </table>\n";
|
|
|
|
print " <br>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub graph_header {
|
|
|
|
my ($title, $colspan) = @_;
|
|
|
|
print("\n");
|
2013-07-10 17:46:45 +01:00
|
|
|
print("<!-- graph table begins -->\n");
|
2013-01-04 08:27:05 +00:00
|
|
|
print(" <table cellspacing='5' cellpadding='0' width='1' bgcolor='$colors{graph_bg_color}' border='1'>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
print(" <tr>\n");
|
2013-01-04 08:27:05 +00:00
|
|
|
print(" <td bgcolor='$colors{title_bg_color}' colspan='$colspan'>\n");
|
|
|
|
print(" <font face='Verdana, sans-serif' color='$colors{title_fg_color}'>\n");
|
2014-01-27 09:33:19 +00:00
|
|
|
print(" <b> $title</b>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
print(" </font>\n");
|
|
|
|
print(" </td>\n");
|
|
|
|
print(" </tr>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub graph_footer {
|
|
|
|
print(" </table>\n");
|
2013-07-10 17:46:45 +01:00
|
|
|
print("<!-- graph table ends -->\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# MAIN
|
|
|
|
# ----------------------------------------------------------------------------
|
2013-01-04 08:27:05 +00:00
|
|
|
open(IN, "< monitorix.conf.path");
|
|
|
|
my $config_path = <IN>;
|
|
|
|
chomp($config_path);
|
|
|
|
close(IN);
|
|
|
|
|
|
|
|
if(! -f $config_path) {
|
|
|
|
print(<< "EOF");
|
|
|
|
Content-Type: text/plain
|
2015-02-25 12:12:24 +00:00
|
|
|
<pre>
|
2013-01-04 08:27:05 +00:00
|
|
|
FATAL: Monitorix is unable to continue!
|
|
|
|
=======================================
|
|
|
|
|
2013-07-10 09:33:46 +01:00
|
|
|
File 'monitorix.conf.path' was not found.
|
2013-01-04 08:27:05 +00:00
|
|
|
|
2013-07-10 09:33:46 +01:00
|
|
|
Please make sure that 'base_dir' option is correctly configured and this
|
|
|
|
CGI (monitorix.cgi) is located in the 'base_dir'/cgi/ directory.
|
2013-01-04 08:27:05 +00:00
|
|
|
|
2013-07-10 09:33:46 +01:00
|
|
|
And don't forget to restart Monitorix for the changes to take effect!
|
2013-01-04 08:27:05 +00:00
|
|
|
EOF
|
2013-07-10 09:33:46 +01:00
|
|
|
die "FATAL: File 'monitorix.conf.path' was not found!";
|
2013-01-04 08:27:05 +00:00
|
|
|
}
|
|
|
|
|
2014-03-11 08:47:43 +00:00
|
|
|
# load main configuration file
|
2013-01-04 08:27:05 +00:00
|
|
|
my $conf = new Config::General(
|
|
|
|
-ConfigFile => $config_path,
|
|
|
|
);
|
|
|
|
%config = $conf->getall;
|
|
|
|
|
2014-03-11 08:47:43 +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:47:43 +00:00
|
|
|
my @files = grep { !/^[.]/ } readdir(DIR);
|
2014-06-02 16:26:27 +01:00
|
|
|
closedir(DIR);
|
2014-03-11 08:47:43 +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-03-11 08:47:43 +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:47:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-20 08:27:10 +01:00
|
|
|
$config{url} = ($config{url_prefix_proxy} || "");
|
|
|
|
if(!$config{url}) {
|
|
|
|
$config{url} = ($ENV{HTTPS} || ($config{httpd_builtin}->{https_url} || "n") eq "y") ? "https://" . $ENV{HTTP_HOST} : "http://" . $ENV{HTTP_HOST};
|
|
|
|
$config{hostname} = $config{hostname} || $ENV{SERVER_NAME};
|
|
|
|
if(!($config{hostname})) { # called from the command line
|
|
|
|
$config{hostname} = "127.0.0.1";
|
|
|
|
$config{url} = "http://127.0.0.1";
|
|
|
|
}
|
2013-01-04 08:27:05 +00:00
|
|
|
}
|
2013-01-31 17:48:29 +00:00
|
|
|
$config{url} .= $config{base_url};
|
2013-01-04 08:27:05 +00:00
|
|
|
|
|
|
|
our $mode = defined(param('mode')) ? param('mode') : '';
|
|
|
|
our $graph = param('graph');
|
|
|
|
our $when = param('when');
|
|
|
|
our $color = param('color');
|
|
|
|
our $val = defined(param('val')) ? param('val') : '';
|
|
|
|
our $silent = defined(param('silent')) ? param('silent') : '';
|
|
|
|
if($mode ne "localhost") {
|
|
|
|
($mode, $val) = split(/\./, $mode);
|
|
|
|
}
|
|
|
|
|
2013-06-18 15:00:28 +01:00
|
|
|
|
2014-07-29 09:56:35 +01:00
|
|
|
if(lc($config{httpd_builtin}->{enabled}) ne "y") {
|
2013-01-31 17:48:29 +00:00
|
|
|
print("Content-Type: text/html\n");
|
|
|
|
print("\n");
|
|
|
|
}
|
2013-01-04 08:27:05 +00:00
|
|
|
|
2014-01-22 15:07:16 +00:00
|
|
|
# get the current OS and kernel version
|
|
|
|
my $release;
|
|
|
|
($config{os}, undef, $release) = uname();
|
|
|
|
if(!($release =~ m/^(\d+)\.(\d+)/)) {
|
|
|
|
die "FATAL: unable to get the kernel version.";
|
|
|
|
}
|
|
|
|
$config{kernel} = "$1.$2";
|
2013-06-18 15:00:28 +01:00
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
$colors{graph_colors} = ();
|
|
|
|
$colors{warning_color} = "--color=CANVAS#880000";
|
2013-06-18 15:00:28 +01:00
|
|
|
|
2013-07-10 09:38:22 +01:00
|
|
|
# keep backwards compatibility for v3.2.1 and less
|
|
|
|
if(ref($config{theme}) ne "HASH") {
|
|
|
|
delete($config{theme});
|
|
|
|
}
|
|
|
|
|
2013-06-18 15:00:28 +01:00
|
|
|
if(!$config{theme}->{$color}) {
|
|
|
|
$color = "white";
|
|
|
|
|
|
|
|
$config{theme}->{$color}->{main_bg} = "FFFFFF";
|
|
|
|
$config{theme}->{$color}->{main_fg} = "000000";
|
|
|
|
$config{theme}->{$color}->{title_bg} = "777777";
|
|
|
|
$config{theme}->{$color}->{title_fg} = "CCCC00";
|
|
|
|
$config{theme}->{$color}->{graph_bg} = "CCCCCC";
|
2013-07-04 14:46:38 +01:00
|
|
|
$config{theme}->{$color}->{gap} = "000000";
|
2013-06-18 15:00:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if($color eq "black") {
|
|
|
|
push(@{$colors{graph_colors}}, "--color=CANVAS#" . $config{theme}->{$color}->{canvas});
|
|
|
|
push(@{$colors{graph_colors}}, "--color=BACK#" . $config{theme}->{$color}->{back});
|
|
|
|
push(@{$colors{graph_colors}}, "--color=FONT#" . $config{theme}->{$color}->{font});
|
|
|
|
push(@{$colors{graph_colors}}, "--color=MGRID#" . $config{theme}->{$color}->{mgrid});
|
|
|
|
push(@{$colors{graph_colors}}, "--color=GRID#" . $config{theme}->{$color}->{grid});
|
|
|
|
push(@{$colors{graph_colors}}, "--color=FRAME#" . $config{theme}->{$color}->{frame});
|
|
|
|
push(@{$colors{graph_colors}}, "--color=ARROW#" . $config{theme}->{$color}->{arrow});
|
|
|
|
push(@{$colors{graph_colors}}, "--color=SHADEA#" . $config{theme}->{$color}->{shadea});
|
|
|
|
push(@{$colors{graph_colors}}, "--color=SHADEB#" . $config{theme}->{$color}->{shadeb});
|
|
|
|
push(@{$colors{graph_colors}}, "--color=AXIS#" . $config{theme}->{$color}->{axis})
|
|
|
|
if defined($config{theme}->{$color}->{axis});
|
2013-01-04 08:27:05 +00:00
|
|
|
}
|
2013-06-18 15:00:28 +01:00
|
|
|
$colors{bg_color} = $config{theme}->{$color}->{main_bg};
|
|
|
|
$colors{fg_color} = $config{theme}->{$color}->{main_fg};
|
|
|
|
$colors{title_bg_color} = $config{theme}->{$color}->{title_bg};
|
|
|
|
$colors{title_fg_color} = $config{theme}->{$color}->{title_fg};
|
|
|
|
$colors{graph_bg_color} = $config{theme}->{$color}->{graph_bg};
|
2013-06-28 11:38:53 +01:00
|
|
|
$colors{gap} = $config{theme}->{$color}->{gap};
|
2013-06-18 15:00:28 +01:00
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
|
|
|
|
($tf{twhen}) = ($when =~ m/(hour|day|week|month|year)$/);
|
|
|
|
($tf{nwhen} = $when) =~ s/$tf{twhen}// unless !$tf{twhen};
|
|
|
|
$tf{nwhen} = 1 unless $tf{nwhen};
|
|
|
|
$tf{twhen} = "day" unless $tf{twhen};
|
|
|
|
$tf{when} = $tf{nwhen} . $tf{twhen};
|
|
|
|
|
|
|
|
# toggle this to 1 if you want to maintain old (2.3-) Monitorix with Multihost
|
|
|
|
if($config{backwards_compat_old_multihost}) {
|
|
|
|
$tf{when} = $tf{twhen};
|
|
|
|
}
|
|
|
|
|
|
|
|
our ($res, $tc, $tb, $ts);
|
|
|
|
if($tf{twhen} eq "day") {
|
|
|
|
($tf{res}, $tf{tc}, $tf{tb}, $tf{ts}) = (3600, 'h', 24, 1);
|
|
|
|
}
|
|
|
|
if($tf{twhen} eq "week") {
|
|
|
|
($tf{res}, $tf{tc}, $tf{tb}, $tf{ts}) = (108000, 'd', 7, 1);
|
|
|
|
}
|
|
|
|
if($tf{twhen} eq "month") {
|
|
|
|
($tf{res}, $tf{tc}, $tf{tb}, $tf{ts}) = (216000, 'd', 30, 1);
|
|
|
|
}
|
|
|
|
if($tf{twhen} eq "year") {
|
|
|
|
($tf{res}, $tf{tc}, $tf{tb}, $tf{ts}) = (5184000, 'd', 365, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if($RRDs::VERSION > 1.2) {
|
|
|
|
push(@version12, "--slope-mode");
|
|
|
|
push(@version12, "--font=LEGEND:7:");
|
|
|
|
push(@version12, "--font=TITLE:9:");
|
|
|
|
push(@version12, "--font=UNIT:8:");
|
|
|
|
if($RRDs::VERSION >= 1.3) {
|
|
|
|
push(@version12, "--font=DEFAULT:0:Mono");
|
|
|
|
}
|
|
|
|
if($tf{twhen} eq "day") {
|
|
|
|
push(@version12, "--x-grid=HOUR:1:HOUR:6:HOUR:6:0:%R");
|
|
|
|
}
|
|
|
|
push(@version12_small, "--font=TITLE:8:");
|
|
|
|
push(@version12_small, "--font=UNIT:7:");
|
|
|
|
if($RRDs::VERSION >= 1.3) {
|
|
|
|
push(@version12_small, "--font=DEFAULT:0:Mono");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-22 15:26:37 +01:00
|
|
|
if(!$silent) {
|
|
|
|
my $title;
|
|
|
|
my $str;
|
|
|
|
|
2014-06-02 16:11:02 +01:00
|
|
|
my $piwik_code = "";
|
|
|
|
my ($piwik_url, $piwik_sid, $piwik_img);
|
|
|
|
|
|
|
|
# Piwik tracking code
|
2014-07-29 09:56:35 +01: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
|
|
|
|
}
|
|
|
|
|
2014-01-27 10:46:17 +00:00
|
|
|
print("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2 Final//EN'>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
print("<html>\n");
|
|
|
|
print(" <head>\n");
|
2013-01-04 08:27:05 +00:00
|
|
|
print(" <title>$config{title}</title>\n");
|
2013-02-11 12:06:01 +00:00
|
|
|
print(" <link rel='shortcut icon' href='" . $config{url} . "/" . $config{favicon} . "'>\n");
|
2013-01-04 08:27:05 +00:00
|
|
|
if($config{refresh_rate}) {
|
|
|
|
print(" <meta http-equiv='Refresh' content='" . $config{refresh_rate} . "'>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
print(" </head>\n");
|
2013-01-04 08:27:05 +00:00
|
|
|
print(" <body bgcolor='" . $colors{bg_color} . "' vlink='#888888' link='#888888'>\n");
|
2014-06-02 16:11:02 +01:00
|
|
|
print(" $piwik_code\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
print(" <center>\n");
|
2013-01-04 08:27:05 +00:00
|
|
|
print(" <table cellspacing='5' cellpadding='0' bgcolor='" . $colors{graph_bg_color} . "' border='1'>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
print(" <tr>\n");
|
2013-01-04 08:27:05 +00:00
|
|
|
|
2012-10-22 15:26:37 +01:00
|
|
|
if(($val ne "all" || $val ne "group") && $mode ne "multihost") {
|
2013-01-04 08:27:05 +00:00
|
|
|
print(" <td bgcolor='" . $colors{title_bg_color} . "'>\n");
|
|
|
|
print(" <font face='Verdana, sans-serif' color='" . $colors{title_fg_color} . "'>\n");
|
2014-01-27 09:33:19 +00:00
|
|
|
print(" <font size='5'><b> Host: </b></font>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
print(" </font>\n");
|
|
|
|
print(" </td>\n");
|
|
|
|
}
|
2013-01-04 08:27:05 +00:00
|
|
|
|
|
|
|
if($val =~ m/group(\d+)/) {
|
|
|
|
my $gnum = $1;
|
|
|
|
my $gname = (split(',', $config{multihost}->{remotegroup_list}))[$gnum];
|
|
|
|
$gname = trim($gname);
|
|
|
|
print(" <td bgcolor='" . $colors{title_bg_color} . "'>\n");
|
|
|
|
print(" <font face='Verdana, sans-serif' color='" . $colors{title_fg_color} . "'>\n");
|
2014-01-27 09:33:19 +00:00
|
|
|
print(" <font size='5'><b> $gname </b></font>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
print(" </font>\n");
|
|
|
|
print(" </td>\n");
|
|
|
|
}
|
2013-01-04 08:27:05 +00:00
|
|
|
|
|
|
|
print(" <td bgcolor='" . $colors{bg_color} . "'>\n");
|
|
|
|
print(" <font face='Verdana, sans-serif' color='" . $colors{fg_color} . "'>\n");
|
2013-01-08 16:22:05 +00:00
|
|
|
if($mode eq "localhost" || $mode eq "traffacct") {
|
2013-01-04 08:27:05 +00:00
|
|
|
$title = $config{hostname};
|
2012-10-22 15:26:37 +01:00
|
|
|
} elsif($mode eq "multihost") {
|
|
|
|
$graph = $graph eq "all" ? "_system1" : $graph;
|
2014-03-03 15:10:33 +00:00
|
|
|
my ($g1, $g2) = ($graph =~ /(_\D+).*?(\d)$/);
|
|
|
|
if($g1 eq "_port") {
|
|
|
|
$title = $config{graphs}->{$g1};
|
|
|
|
$g2 = trim((split(',', $config{port}->{list}))[$g2]);
|
|
|
|
$title .= " " . $g2;
|
|
|
|
$g2 = (split(',', $config{port}->{desc}->{$g2}))[0];
|
|
|
|
$title .= " (" . trim($g2) . ")";
|
2012-10-22 15:26:37 +01:00
|
|
|
} else {
|
2014-03-03 13:50:36 +00:00
|
|
|
$g2 = "" if $g1 eq "_proc"; # '_procn' must be converted to '_proc'
|
|
|
|
$title = $config{graphs}->{$g1 . $g2};
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$title =~ s/ / /g;
|
|
|
|
print(" <font size='5'><b> $title </b></font>\n");
|
|
|
|
print(" </font>\n");
|
|
|
|
print(" </td>\n");
|
2013-01-04 08:27:05 +00:00
|
|
|
print(" <td bgcolor='" . $colors{title_bg_color} . "'>\n");
|
|
|
|
print(" <font face='Verdana, sans-serif' color='" . $colors{title_fg_color} . "'>\n");
|
2014-01-27 09:33:19 +00:00
|
|
|
print(" <font size='5'><b> last $tf{twhen} </b></font>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
print(" </font>\n");
|
|
|
|
print(" </td>\n");
|
|
|
|
print(" </tr>\n");
|
|
|
|
print(" </table>\n");
|
2013-01-04 08:27:05 +00:00
|
|
|
print(" <font face='Verdana, sans-serif' color='" . $colors{fg_color} . "'>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
print(" <h4><font color='#888888'>" . strftime("%a %b %e %H:%M:%S %Z %Y", localtime) . "</font></h4>\n");
|
|
|
|
}
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
|
|
|
|
$cgi{colors} = \%colors;
|
|
|
|
$cgi{tf} = \%tf;
|
|
|
|
$cgi{version12} = \@version12;
|
|
|
|
$cgi{version12_small} = \@version12_small;
|
|
|
|
$cgi{graph} = $graph;
|
|
|
|
$cgi{when} = $when;
|
|
|
|
$cgi{color} = $color;
|
|
|
|
$cgi{val} = $val;
|
|
|
|
$cgi{silent} = $silent;
|
|
|
|
|
2012-10-22 15:26:37 +01:00
|
|
|
if($mode eq "localhost") {
|
2013-01-04 08:27:05 +00:00
|
|
|
foreach (split(',', $config{graph_name})) {
|
2014-05-06 08:56:24 +01:00
|
|
|
my $gn = trim($_);
|
|
|
|
my $g = "";
|
|
|
|
if($graph ne "all") {
|
|
|
|
($g) = ($graph =~ m/^_*($gn)\d*$/);
|
|
|
|
next unless $g;
|
|
|
|
}
|
|
|
|
if(lc($config{graph_enable}->{$gn}) eq "y") {
|
|
|
|
my $cgi = $gn . "_cgi";
|
2013-01-04 08:27:05 +00:00
|
|
|
|
2014-05-06 08:56:24 +01:00
|
|
|
eval "use $gn qw(" . $cgi . ")";
|
2013-01-04 08:27:05 +00:00
|
|
|
if($@) {
|
2014-05-06 08:56:24 +01:00
|
|
|
print(STDERR "WARNING: unable to load module '$gn. $@'\n");
|
2013-01-04 08:27:05 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2014-05-06 08:56:24 +01:00
|
|
|
if($graph eq "all" || $gn eq $g) {
|
2013-01-04 08:27:05 +00:00
|
|
|
no strict "refs";
|
2014-05-06 08:56:24 +01:00
|
|
|
&$cgi($gn, \%config, \%cgi);
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elsif($mode eq "multihost") {
|
2013-01-04 08:27:05 +00:00
|
|
|
multihost(\%config, \%colors, \%cgi);
|
2013-01-08 16:22:05 +00:00
|
|
|
} elsif($mode eq "traffacct") {
|
|
|
|
eval "use $mode qw(traffacct_cgi)";
|
|
|
|
if($@) {
|
2014-04-08 12:10:04 +01:00
|
|
|
print(STDERR "WARNING: unable to load module '$mode'. $@\n");
|
2013-01-08 16:22:05 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
traffacct_cgi($mode, \%config, \%cgi);
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!$silent) {
|
|
|
|
print("\n");
|
|
|
|
print(" </font>\n");
|
|
|
|
print(" </center>\n");
|
2013-07-11 14:00:19 +01:00
|
|
|
print("<!-- footer begins -->\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
print(" <p>\n");
|
2013-02-07 17:37:09 +00:00
|
|
|
print(" <a href='http://www.monitorix.org'><img src='" . $config{url} . "/" . $config{logo_bottom} . "' border='0'></a>\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
print(" <br>\n");
|
2013-01-04 08:27:05 +00:00
|
|
|
print(" <font face='Verdana, sans-serif' color='" . $colors{fg_color} . "' size='-2'>\n");
|
2015-03-03 15:50:54 +00:00
|
|
|
print("Copyright © 2005-2015 Jordi Sanfeliu\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
print(" </font>\n");
|
|
|
|
print(" </body>\n");
|
|
|
|
print("</html>\n");
|
2013-07-11 14:00:19 +01:00
|
|
|
print("<!-- footer ends -->\n");
|
2012-10-22 15:26:37 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
0;
|