1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
#!@@PERL@@ @@PERLOPTS@@
# datapage-alert-writer - write datapages showing alert statuses
# $Id: datapage-alert-writer.pl,v 1.4 2003/05/15 11:58:05 remstats Exp $
# from remstats @@VERSION@@
# Copyright 2001, 2002 (c) Thomas Erskine <@@AUTHOR@@>
# See the COPYRIGHT file with the distribution.
# - - - Configuration - - -
use strict;
# What is this program called, for error-messages and file-names
$main::prog = 'datapage-alert-writer';
# Where is the default configuration dir
$main::config_dir = '@@CONFIGDIR@@';
# - - - Version History - - -
$main::version = (split(' ', '$Revision: 1.4 $'))[1];
# - - - Setup - - -
use lib '.', '@@LIBDIR@@', '@@RRDLIBDIR@@';
use Getopt::Std;
use RRDs;
require "remstats.pl";
require "htmlstuff.pl";
# Parse the command-line
my %opt = ();
getopts('d:f:h', \%opt);
if (defined $opt{'h'}) { &usage; } # no return
if (defined $opt{'d'}) { $main::debug = $opt{'d'}; } else { $main::debug = 0; }
if (defined $opt{'f'}) { $main::config_dir = $opt{'f'}; }
# No buffering when debugging
if ($main::debug) { $| = 1; }
&read_config_dir( $main::config_dir, 'general', 'links', 'colors',
'tools', 'times', 'html', 'oids', 'rrds', 'groups', 'host-templates',
'hosts');
# Collect the hosts in Group order
my %hosts = ();
my @hosts = ();
my ($group, $host, $status);
foreach $group (@{$main::config{GROUPS}}) {
# In case there is a group with no hosts
next unless (@{$main::config{GROUP}{$group}});
push @hosts, @{$main::config{GROUP}{$group}};
}
undef %hosts;
# Get the indices
%main::indices = &init_indices;
%main::upindices = %main::indices;
# - - - Mainline - - -
my( $last_group, $ip, $fixed_group, $group_file, $header_bar, $html, $top,
$realrrd, $wildpart, $wildrrd, $fixedrrd, $var, $varname,
$rrdhtml, $found_var, $desc);
my $alert_index = $main::config{DATAPAGEDIR} .'/alert-index.page';
open( ALERT_INDEX, ">$alert_index") or
&abort("can't open $alert_index");
my $alert_html = "<DATAPAGE::HEADER Alert Index>\n\n";
$last_group = '';
my $group_bar = '';
foreach $host( @hosts) {
$ip = &get_ip( $host);
next unless( defined $ip);
$group = $main::config{HOST}{$host}{GROUP};
if( $group ne $last_group) {
$last_group = $group;
$fixed_group = &to_filename( $group) . '.html';
$group_file= $main::config{HTMLDIR} .'/'. $fixed_group;
if( -f $group_file) {
$group = "<NOBR><A HREF=\"$fixed_group\">$group</A></NOBR>";
$main::upindices{$main::config{HTML}{GROUPINDEX}} = '../' .
$fixed_group;
}
else { undef $main::upindices{$main::config{HTML}{GROUPINDEX}}; }
$header_bar = &header_bar( $group);
$alert_html .= $group_bar . "\n<H2>$group</H2>\n";
$group_bar = "<HR>\n";
}
if( defined $main::config{HOST}{$host}{DESC}) {
$desc = ' - ' . $main::config{HOST}{$host}{DESC};
}
else { $desc = ''; }
$html = '<TABLE BORDER=0 WIDTH="100%"><TR>' .
'<TD BGCOLOR="#CCCCCC"><FONT SIZE="+1"><A HREF="' .
&make_host_index_url( $host) . '"><B>' . $host .
'</B></A></FONT>' . $desc . "</TD></TR></TABLE>\n";
# Write the index entry for a host
my $rrdsep = '';
foreach $realrrd (@{$main::config{HOST}{$host}{RRDS}}) {
($wildrrd, $wildpart, $fixedrrd) =
&get_rrd($realrrd);
next unless (defined $wildrrd);
&debug(" for rrd $realrrd($wildrrd)") if ($main::debug);
$rrdhtml = $rrdsep . "<NOBR><SPAN STYLE=\"background-color: #DDDDDD\"><B>$realrrd</B></SPAN>:\n";
$rrdsep = "<SPAN WIDTH=\"5%\"></SPAN>\n";
$found_var = 0;
foreach $var (@{$main::config{RRD}{$wildrrd}{DATANAMES}}) {
# Sometimes we just don't want it on this host
if (defined $main::config{HOST}{$host}{ALERT}{$realrrd}{$var}{NOALERT}) {
&debug(" noalert for $realrrd $var; skipped") if ($main::debug);
next;
}
# Alerts defined on the host override those on the rrd
elsif (defined $main::config{HOST}{$host}{ALERT}{$realrrd}{$var}{RELATION}) {
&debug(" host alert for $realrrd $var") if ($main::debug);
}
# But we'll use alerts on the rrd if the host doesn't define one
elsif (defined $main::config{RRD}{$wildrrd}{ALERT}{$var}{RELATION}) {
&debug(" rrd alert for $realrrd $var") if ($main::debug);
}
else {
&debug(" no alert possible for $realrrd $var") if ($main::debug);
next;
}
$varname = $host .'_'. $fixedrrd .'_'. $var;
$top .= 'alertstatus ' . $varname .' '. $host .' '. $realrrd .' '. $var . "\n";
$top .= 'alertvalue ' . $varname .'_value '. $host .' '. $realrrd .' '. $var . "\n";
$top .= 'eval ' . $varname .'_value &siunits(${'. $varname .'_value'. "})\n";
# $rrdhtml .= "$var(<DATAPAGE::VAR ${varname}_value>)<DATAPAGE::VAR $varname>\n";
# $rrdhtml .= "<DATAPAGE::VAR $varname>[$var(<DATAPAGE::VAR ${varname}_value>)]\n";
$rrdhtml .= "[$var <DATAPAGE::VAR $varname>=<DATAPAGE::VAR ${varname}_value>]\n";
$found_var = 1;
}
$rrdhtml .= "</NOBR>\n";
if( $found_var) { $html .= $rrdhtml; }
}
$alert_html .= "\n" . $html;
}
$alert_html .= "\n<BR>\n<DATAPAGE::FOOTER>\n";
print ALERT_INDEX $top, "BEGIN-PAGE\nContent-type: text/html\n\n", $alert_html;
close (ALERT_INDEX);
#----------------------------------------------------------------- usage ---
sub usage {
print STDERR <<"EOD_USAGE";
$main::prog version $main::version from remstats @@VERSION@@
usage: $0 [options]
where options are:
-d nnn enable debugging output at level 'nnn'
-h show this help
EOD_USAGE
exit 0;
}
#----------------------------------------------------------------- debug ---
sub debug {
print STDERR 'DEBUG: ', @_, "\n";
}
#------------------------------------------------------------------ abort ---
sub abort {
print STDERR 'ABORT: ', @_, "\n";
exit 6;
}
#------------------------------------------------------------------ error ---
sub error {
print STDERR 'ERROR: ', @_, "\n";
}
|