|
Packit |
667938 |
#! /usr/bin/perl
|
|
Packit |
667938 |
# -*- mode: Perl -*-
|
|
Packit |
667938 |
BEGIN{
|
|
Packit |
667938 |
#$main::OS = 'UNIX';
|
|
Packit |
667938 |
$main::OS = 'NT';
|
|
Packit |
667938 |
#$main::OS = 'VMS';
|
|
Packit |
667938 |
##################################################################
|
|
Packit |
667938 |
# MRTG-NSI 1.0 Network Status Imager for MRTG
|
|
Packit |
667938 |
##################################################################
|
|
Packit |
667938 |
# Created by: Mac Kloberg <mac@nacs.net><mac.kloberg@lam.liebherr.com>
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# WARNING: This thing was developed 'quick and dirty' on WinNT...
|
|
Packit |
667938 |
# I've never actually tried this on Unix or VMS, so I
|
|
Packit |
667938 |
# don't know if it will work. Guess you'll find out...
|
|
Packit |
667938 |
# Send me mail...
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# Built and based on: MRTG by Tobias Oetiker <oetiker@ee.ethz.ch>
|
|
Packit |
667938 |
# and Dave Rand <dlr@bungi.com>
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# Credits: THANKS, TOBI AND DAVE!!! K.U.T.G.W.
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
#################################################################
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# Distributed under the GNU copyleft
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
###################################################################
|
|
Packit |
667938 |
# The path separator is a slash, backslash or semicolon, depending
|
|
Packit |
667938 |
# on the platform.
|
|
Packit |
667938 |
$main::SL = {
|
|
Packit |
667938 |
UNIX=>'/',
|
|
Packit |
667938 |
WINDOWS=>'\\',
|
|
Packit |
667938 |
NT=>'\\',
|
|
Packit |
667938 |
VMS=>''
|
|
Packit |
667938 |
}->{$main::OS};
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# The search path separator is a colon or semicolon depending on the
|
|
Packit |
667938 |
# operating system.
|
|
Packit |
667938 |
$main::PS = {
|
|
Packit |
667938 |
UNIX=>':',
|
|
Packit |
667938 |
WINDOWS=>';',
|
|
Packit |
667938 |
NT=>';',
|
|
Packit |
667938 |
VMS=>':'
|
|
Packit |
667938 |
}->{$main::OS};
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# We need to find the place where mrtg is installed, and
|
|
Packit |
667938 |
# then take it from there...
|
|
Packit |
667938 |
$main::binpath ="";
|
|
Packit |
667938 |
if ($0 =~ /^(.+\Q${main::SL}\E)/) {
|
|
Packit |
667938 |
$main::binpath="$1";
|
|
Packit |
667938 |
} else {
|
|
Packit |
667938 |
foreach $pathname ( split ${main::PS}, $ENV{'PATH'}) {
|
|
Packit |
667938 |
if ((($main::OS eq 'NT') &&
|
|
Packit |
667938 |
(-e "$pathname${main::SL}$0")) ||
|
|
Packit |
667938 |
(-x "$pathname${main::SL}$0")) {
|
|
Packit |
667938 |
$main::binpath=$pathname;
|
|
Packit |
667938 |
last;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
die "ERROR: Can\'t find location of mrtg executable\n"
|
|
Packit |
667938 |
unless $main::binpath;
|
|
Packit |
667938 |
unshift (@INC,$main::binpath);
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# There older perls tend to behave peculiar with
|
|
Packit |
667938 |
# large integers ...
|
|
Packit |
667938 |
require 5.003;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if ($main::OS eq 'UNIX' || $main::OS eq 'NT') {
|
|
Packit |
667938 |
use GD;
|
|
Packit |
667938 |
use Net::SMTP; #requires libnet package to be installed
|
|
Packit |
667938 |
#use SNMP_Session "0.71";
|
|
Packit |
667938 |
#use BER "0.66";
|
|
Packit |
667938 |
#use SNMP_util "0.71";
|
|
Packit |
667938 |
use locales_mrtg "0.01";
|
|
Packit |
667938 |
use Config;
|
|
Packit |
667938 |
#$main::SNMPDEBUG =0;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Doesn't seem to work very well with the win32 port of GD
|
|
Packit |
667938 |
#use strict;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if($main::OS eq 'UNIX')
|
|
Packit |
667938 |
{
|
|
Packit |
667938 |
my($i) = 0;
|
|
Packit |
667938 |
my($name);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
foreach $name (split(/ /, $Config{sig_name}))
|
|
Packit |
667938 |
{
|
|
Packit |
667938 |
$main::signo{$name} = $i;
|
|
Packit |
667938 |
$main::signame[$i++] = $name;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
$main::DEBUG=1;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub END {
|
|
Packit |
667938 |
local($?, $!);
|
|
Packit |
667938 |
unlink ${main::Cleanfile} if($main::Cleanfile);
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub main {
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my ($router, $target ,$gdstyles, $neweventcounter, $eventcounter, $newevents, $neweventstype);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# unbuffer stdout to see everything immediately
|
|
Packit |
667938 |
$|=1 if $main::DEBUG;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
print "\nMRTG - Network Status Imager loading & initializing...\n\n" if $main::DEBUG;
|
|
Packit |
667938 |
my ($routers, $cfg, $rcfg, $cfgfile) = readcfg();
|
|
Packit |
667938 |
$target = cfgcheck($routers, $cfg, $rcfg);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
print "Locking Config Files...\n";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# Check the config and create the target object
|
|
Packit |
667938 |
# lets make sure that there are not two mrtg-nsi's running in parallel.
|
|
Packit |
667938 |
# so we lock on the cfg file. Nothing fancy, just a lockfile
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
my $lockfile = $cfgfile."_l";
|
|
Packit |
667938 |
my $templock = $cfgfile."_l_" . $$ ;
|
|
Packit |
667938 |
if ($main::OS eq 'VMS' || $main::OS eq 'NT') {
|
|
Packit |
667938 |
# too sad NT and VMS can't do links we'll do the diletants lock
|
|
Packit |
667938 |
if (-e $lockfile && not unlink $lockfile){
|
|
Packit |
667938 |
my($lockage) = time()-(stat($lockfile))[9];
|
|
Packit |
667938 |
die ("ERROR: I guess another mrtg-nsi is running. A lockfile ($lockfile)
|
|
Packit |
667938 |
aged $lockage seconds is hanging around and I can't remove
|
|
Packit |
667938 |
it because another process is still using it.");
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
open (LOCK, ">$lockfile") or die "ERROR: Can't create lockfile $lockfile\n";
|
|
Packit |
667938 |
print LOCK "$$\n";
|
|
Packit |
667938 |
close LOCK;
|
|
Packit |
667938 |
open (LOCK, "<$lockfile") or die "ERROR: Can't open lockfile $lockfile for owner check\n";
|
|
Packit |
667938 |
my($read)=<LOCK>;
|
|
Packit |
667938 |
chomp($read);
|
|
Packit |
667938 |
die "ERROR: Someone else just got the lockfile $lockfile\n"
|
|
Packit |
667938 |
unless $$ == $read;
|
|
Packit |
667938 |
} else {
|
|
Packit |
667938 |
# now, lets do it the UNIX way ... Daves work ...
|
|
Packit |
667938 |
open(LOCK,">$templock") || die "Can't create templock $templock";
|
|
Packit |
667938 |
$main::Cleanfile = $templock;
|
|
Packit |
667938 |
if (!link($templock,$lockfile)) { # Lock file exists - deal with it.
|
|
Packit |
667938 |
my($nlink,$lockage) = (stat($lockfile))[3,9];
|
|
Packit |
667938 |
$lockage = time() - $lockage;
|
|
Packit |
667938 |
if ($nlink < 2 || $lockage > 30*60) { #lockfile is alone and old
|
|
Packit |
667938 |
unlink($lockfile)
|
|
Packit |
667938 |
|| do{ unlink $templock;
|
|
Packit |
667938 |
die "ERROR: Can't unlink stale lockfile ($lockfile). Permissions?\n"};
|
|
Packit |
667938 |
|
|
Packit |
667938 |
link($templock,$lockfile)
|
|
Packit |
667938 |
|| do{ unlink $templock;
|
|
Packit |
667938 |
die "ERROR: Can't create lockfile ($lockfile).\n".
|
|
Packit |
667938 |
"Permission problem or another mrtg locking succesfully?\n"};
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
else {
|
|
Packit |
667938 |
unlink $templock;
|
|
Packit |
667938 |
die ("ERROR: I guess another mrtg is running. A lockfile ($lockfile) aged\n".
|
|
Packit |
667938 |
"$lockage seconds is hanging around. If you are sure that no other mrtg\n".
|
|
Packit |
667938 |
"is running you can remove the lockfile\n");
|
|
Packit |
667938 |
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Read the messages
|
|
Packit |
667938 |
my($msg) = readmsgfile($$cfg{'msgfile'});
|
|
Packit |
667938 |
open (BACKGROUNDIMG,"<$$cfg{'statusmapbackground'}") || die "ERROR: Can't open StatusMapBackGround\n";
|
|
Packit |
667938 |
my($ImageData) = newFromGif GD::Image(BACKGROUNDIMG) || die "ERROR: GD::newFromGif\n";
|
|
Packit |
667938 |
close BACKGROUNDIMG;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Allocate colors for this image...
|
|
Packit |
667938 |
my %defcolors =
|
|
Packit |
667938 |
(#Color allocation table
|
|
Packit |
667938 |
'black', "0,0,0",
|
|
Packit |
667938 |
'red', "255,0,0",
|
|
Packit |
667938 |
'green', "0,255,0",
|
|
Packit |
667938 |
'blue', "0,0,255",
|
|
Packit |
667938 |
'yellow', "255,250,205",
|
|
Packit |
667938 |
'white', "255,0,0"
|
|
Packit |
667938 |
);
|
|
Packit |
667938 |
%colors = ();
|
|
Packit |
667938 |
while(($color, $cvalue) = each(%defcolors)){
|
|
Packit |
667938 |
#Try to allocate our color
|
|
Packit |
667938 |
if($ImageData->colorAllocate(split(/,/,$cvalue)) ne "-1"){
|
|
Packit |
667938 |
$colors{$color} = $ImageData->colorAllocate(split(/,/,$cvalue));
|
|
Packit |
667938 |
}else{
|
|
Packit |
667938 |
#Didn't work, we'll have to match the closest then
|
|
Packit |
667938 |
$colors{$color} = $ImageData->colorClosest(split(/,/,$cvalue));
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Define our linestyles
|
|
Packit |
667938 |
$$gdstyles{'linestylec1'}{'style'} = "$colors{'yellow'},$colors{'yellow'},$colors{'yellow'},$colors{'yellow'},$colors{'blue'},$colors{'blue'},$colors{'blue'},$colors{'blue'},gdTransparent,gdTransparent";
|
|
Packit |
667938 |
$$gdstyles{'linestylew1'}{'style'} = "$colors{'red'},$colors{'red'},$colors{'red'},$colors{'red'},$colors{'blue'},$colors{'blue'},$colors{'blue'},$colors{'blue'},gdTransparent,gdTransparent";
|
|
Packit |
667938 |
$$gdstyles{'linestylea1'}{'style'} = "$colors{'red'},$colors{'red'},$colors{'blue'},$colors{'red'},$colors{'red'},$colors{'red'},$colors{'blue'},$colors{'blue'},gdTransparent,gdTransparent,gdTransparent,gdTransparent,gdTransparent,gdTransparent,gdTransparent,gdTransparent,gdTransparent";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
drawtext($ImageData, $gdstyles, $cfg, $rcfg, $routers, $router, "cool", "cool", "", "always", "1", "baxter.x", "baxter.y", "baxtersprings", "black",);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
$neweventcounter = 0;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
foreach $router (@$routers) {
|
|
Packit |
667938 |
my($savetz) = $ENV{'TZ'};
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if ($$rcfg{'timezone'}{$router} ne '') {
|
|
Packit |
667938 |
$ENV{'TZ'} = $$rcfg{'timezone'}{$router}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
print "Imaging node: $router\n";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# set the locale
|
|
Packit |
667938 |
my($LOC);
|
|
Packit |
667938 |
if( $$cfg{'language'} && defined($lang2tran::LOCALE{"\L$$cfg{'language'}\E"}))
|
|
Packit |
667938 |
{
|
|
Packit |
667938 |
$LOC=$lang2tran::LOCALE{"\L$$cfg{'language'}\E"};
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
else
|
|
Packit |
667938 |
{
|
|
Packit |
667938 |
$LOC=$lang2tran::LOCALE{'default'};
|
|
Packit |
667938 |
};
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Node test...
|
|
Packit |
667938 |
if($$cfg{'testnodelocations'} =~ /y/i){
|
|
Packit |
667938 |
action_draw_crosshair($ImageData, $cfg, $rcfg, $routers, $router, $$rcfg{'nodecenterx'}{$router},$$rcfg{'nodecentery'}{$router},$black);
|
|
Packit |
667938 |
next;
|
|
Packit |
667938 |
#Normal node processing
|
|
Packit |
667938 |
}else{
|
|
Packit |
667938 |
my ($incurrent, $outcurrent, $inlast, $outlast) = getnodevalues($$rcfg{'node'}{$router}, $router, $rcfg, $cfg);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#DEBUG --- DEBUG --- DEBUG --- DEBUG --- DEBUG --- DEBUG --- DEBUG ---
|
|
Packit |
667938 |
#if ($router =~ /NewportNewsEmailX400Kirchdorf/i){
|
|
Packit |
667938 |
#$inlast = 0;$incurrent = 50;
|
|
Packit |
667938 |
#$inlast = 5000;$incurrent = 100;
|
|
Packit |
667938 |
#}
|
|
Packit |
667938 |
#DEBUG --- DEBUG --- DEBUG --- DEBUG --- DEBUG --- DEBUG --- DEBUG ---
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my ($nodeinstatus,$nodeoutstatus) = getnodestatus($incurrent,$outcurrent,$$rcfg{'node'}{$router}, $router, $rcfg, $cfg);
|
|
Packit |
667938 |
my ($nodeinlaststatus,$nodeoutlaststatus) = getnodestatus($inlast,$outlast,$$rcfg{'node'}{$router}, $router, $rcfg, $cfg);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
print "NodeStatus-Old: $nodeinlaststatus($inlast)/$nodeoutlaststatus($outlast)\n";
|
|
Packit |
667938 |
print "NodeStatus-New: $nodeinstatus($incurrent)/$nodeoutstatus($outcurrent)\n";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Generate events for the log and status-email
|
|
Packit |
667938 |
my $ineventid = "";
|
|
Packit |
667938 |
my $outeventid = "";
|
|
Packit |
667938 |
my $ineventtype = "";
|
|
Packit |
667938 |
my $outeventtype = "";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Cool event (in)
|
|
Packit |
667938 |
if($nodeinstatus eq "cool" && $nodeinlaststatus eq "alarm" && defined $$rcfg{'nodeincoolmsgid'}{$router}){$ineventid = lc($$rcfg{'nodeincoolmsgid'}{$router});$ineventtype = "Cool";};
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Cool event (in)
|
|
Packit |
667938 |
if($nodeinstatus eq "warning" && $nodeinlaststatus eq "alarm" && defined $$rcfg{'nodeincoolmsgid'}{$router}){$ineventid = lc($$rcfg{'nodeincoolmsgid'}{$router});$ineventtype = "Cool";};
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Warning event (in)
|
|
Packit |
667938 |
if($nodeinstatus eq "warning" && $nodeinlaststatus eq "cool" && defined $$rcfg{'nodeinwarningmsgid'}{$router}){$ineventid = lc($$rcfg{'nodeinwarningmsgid'}{$router});$ineventtype = "Warn";};
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Alarm event (in)
|
|
Packit |
667938 |
if($nodeinstatus eq "alarm" && ($nodeinlaststatus eq "cool" || $nodeinlaststatus eq "warning") && defined $$rcfg{'nodeinalarmmsgid'}{$router}){$ineventid = lc($$rcfg{'nodeinalarmmsgid'}{$router});$ineventtype = "Alarm";};
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Cool event (out)
|
|
Packit |
667938 |
if($nodeoutstatus eq "cool" && $nodeoutlaststatus eq "alarm" && defined $$rcfg{'nodeoutcoolmsgid'}{$router}){$outeventid = lc($$rcfg{'nodeoutcoolmsgid'}{$router});$outeventtype = "Cool";};
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Cool event (out)
|
|
Packit |
667938 |
if($nodeoutstatus eq "warning" && $nodeoutlaststatus eq "alarm" && defined $$rcfg{'nodeoutcoolmsgid'}{$router}){$outeventid = lc($$rcfg{'nodeoutcoolmsgid'}{$router});$outeventtype = "Cool";};
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Warning event (out)
|
|
Packit |
667938 |
if($nodeoutstatus eq "warning" && $nodeoutlaststatus eq "cool" && defined $$rcfg{'nodeoutwarningmsgid'}{$router}){$outeventid = lc($$rcfg{'nodeoutwarningmsgid'}{$router});$outeventtype = "Warn";};
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Alarm event (out)
|
|
Packit |
667938 |
if($nodeoutstatus eq "alarm" && ($nodeoutlaststatus eq "cool" || $nodeoutlaststatus eq "warning") && defined $$rcfg{'nodeoutalarmmsgid'}{$router}){$outeventid = lc($$rcfg{'nodeoutalarmmsgid'}{$router});$outeventtype = "Cool";};
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Log events (in)
|
|
Packit |
667938 |
if($ineventid ne ""){
|
|
Packit |
667938 |
$newevents[$neweventcounter] = $$msg{$ineventid};
|
|
Packit |
667938 |
#Translate variables in the event message
|
|
Packit |
667938 |
$newevents[$neweventcounter] = transeventvar($cfg, $rcfg, $routers, $router, $incurrent, $outcurrent, $newevents[$neweventcounter]);
|
|
Packit |
667938 |
#Anybody needs to know about this?
|
|
Packit |
667938 |
if($$rcfg{'email'}{lc($ineventtype)}{$router}){
|
|
Packit |
667938 |
$neweventstype[$neweventcounter] = "$ineventtype/e";
|
|
Packit |
667938 |
sendmail($cfg, $rcfg, $routers, $router, $incurrent, $outcurrent, $newevents[$neweventcounter],$neweventstype[$neweventcounter],$$rcfg{'nodestatusemailtarget'}{$router});
|
|
Packit |
667938 |
}else{
|
|
Packit |
667938 |
$neweventstype[$neweventcounter] = $ineventtype;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
$neweventcounter++;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Log events (out)
|
|
Packit |
667938 |
if($outeventid ne ""){
|
|
Packit |
667938 |
$newevents[$neweventcounter] = $$msg{$outeventid};
|
|
Packit |
667938 |
$neweventstype[$neweventcounter] = $outeventtype;
|
|
Packit |
667938 |
#Translate variables in the event message
|
|
Packit |
667938 |
$newevents[$neweventcounter] = transeventvar($cfg, $rcfg, $routers, $router, $incurrent, $outcurrent, $newevents[$neweventcounter]);
|
|
Packit |
667938 |
#Anybody needs to know about this?
|
|
Packit |
667938 |
if($$rcfg{'email'}{lc($outeventtype)}{$router}){
|
|
Packit |
667938 |
$neweventstype[$neweventcounter] = "$outeventtype/e";
|
|
Packit |
667938 |
sendmail($cfg, $rcfg, $routers, $router, $incurrent, $outcurrent, $newevents[$neweventcounter],$neweventstype[$neweventcounter],$$rcfg{'nodestatusemailtarget'}{$router});
|
|
Packit |
667938 |
}else{
|
|
Packit |
667938 |
$neweventstype[$neweventcounter] = $outeventtype;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
$neweventcounter++;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Main action loop, the right sequencing is important because of overlappling graphics in the status map
|
|
Packit |
667938 |
for ($actioncounter = 0; $actioncounter <= $$rcfg{maxaction}{$router}; $actioncounter++){
|
|
Packit |
667938 |
if (exists $$rcfg{"action.$actioncounter"}{$router}) {
|
|
Packit |
667938 |
my $action = $$rcfg{"action.$actioncounter"}{$router};
|
|
Packit |
667938 |
my @acfunctelements = split(/\(/,$action);
|
|
Packit |
667938 |
my $acfunc = $acfunctelements[0];
|
|
Packit |
667938 |
#Cleanup the function name
|
|
Packit |
667938 |
$acfunc=~s/\s/ /g;
|
|
Packit |
667938 |
$acfunc=~s/^ *//g;
|
|
Packit |
667938 |
$acfunc=~s/ *$//g;
|
|
Packit |
667938 |
$acfunc=lc($acfunc);
|
|
Packit |
667938 |
my @acfunctelements = split(/[\(\)]/,$action);
|
|
Packit |
667938 |
my @acargs = split(/,/,$acfunctelements[1]);
|
|
Packit |
667938 |
#Cleanup the functions arguments and put them in parethesis...
|
|
Packit |
667938 |
foreach $acarg (@acargs){
|
|
Packit |
667938 |
$acarg=~s/\s/ /g;
|
|
Packit |
667938 |
$acarg=~s/^ *//g;
|
|
Packit |
667938 |
$acarg=~s/ *$//g;
|
|
Packit |
667938 |
$acarg=lc($acarg);
|
|
Packit |
667938 |
$acarg="\"$acarg\",";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Execute Action
|
|
Packit |
667938 |
eval("$acfunc(\$ImageData, \$gdstyles, \$cfg, \$rcfg, \$routers, \$router, \$msg, \"$nodeinstatus\", \"$nodeoutstatus\", \"$incurrent\" , \"$outcurrent\", @acargs);");
|
|
Packit |
667938 |
die "* Problem with action statement: $acfunc(\$ImageData, \$gdstyles, \$cfg, \$rcfg, \$routers, \$router, \$msg, \"$nodeinstatus\", \"$nodeoutstatus\", \"$incurrent\" , \"$outcurrent\", @acargs);\n" if $@;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#put TZ things back in shape ...
|
|
Packit |
667938 |
if ($savetz) {$ENV{'TZ'} = $savetz;} else
|
|
Packit |
667938 |
{delete $ENV{'TZ'}};
|
|
Packit |
667938 |
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#If there are no events, don't do anything
|
|
Packit |
667938 |
if ($neweventcounter > 0){
|
|
Packit |
667938 |
#Open current log file and get the old log entries
|
|
Packit |
667938 |
open (LOGFILE,"<$$cfg{'workdir'}\\mrtg-nsi.log") || print "WARNING: Couldn't open eventlog file for reading: $$cfg{'workdir'}//mrtg-nsi.log\n";
|
|
Packit |
667938 |
my @oldeventloglines = <LOGFILE>;
|
|
Packit |
667938 |
close LOGFILE;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Open eventlog again and add new events
|
|
Packit |
667938 |
open (LOGFILE,">$$cfg{'workdir'}\\mrtg-nsi.log") || die "ERROR: Couldn't open eventlog file for writing: $$cfg{'workdir'}//mrtg-nsi.log\n";
|
|
Packit |
667938 |
open (HTMLLOG,">$$cfg{'eventlog'}") || die "ERROR: Couldn't open eventlog file for writing: $$cfg{'eventlog'}\n";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Add header to the html-log
|
|
Packit |
667938 |
print HTMLLOG "<html>\n";
|
|
Packit |
667938 |
print HTMLLOG "\n";
|
|
Packit |
667938 |
print HTMLLOG "<head>\n";
|
|
Packit |
667938 |
print HTMLLOG "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n";
|
|
Packit |
667938 |
print HTMLLOG "<meta http-equiv=\"Refresh\" CONTENT=\"60\">\n";
|
|
Packit |
667938 |
print HTMLLOG "<title>Home Page</title>\n";
|
|
Packit |
667938 |
print HTMLLOG "</head>\n";
|
|
Packit |
667938 |
print HTMLLOG "\n";
|
|
Packit |
667938 |
print HTMLLOG "<body topmargin=\"1\" leftmargin=\"1\" bordercolor=\"#FFFFFF\" bgcolor=\"#FFFFFF\">\n";
|
|
Packit |
667938 |
print HTMLLOG "\n";
|
|
Packit |
667938 |
print HTMLLOG "<font face=\"Arial\" size=\"5\">Network Status Imager: Event Log</font>
|
|
Packit |
667938 |
print HTMLLOG "face=\"Arial\"> \n";
|
|
Packit |
667938 |
print HTMLLOG "</font><font face=\"Arial\" size=\"1\">NSI v1.0 for MRTG, Created by Mac\n";
|
|
Packit |
667938 |
print HTMLLOG "Kloberg <mac.kloberg\@lam.liebherr.com>
|
|
Packit |
667938 |
print HTMLLOG "href=\"mailto:mac\@nacs.net\"><mac\@nacs.net>) \n";
|
|
Packit |
667938 |
print HTMLLOG "Credits to Tobias Oetiker <oetiker\@ee.ethz.ch> and Dave Rand
|
|
Packit |
667938 |
print HTMLLOG "href=\"mailto:dlr\@bungi.com\"><dlr\@bungi.com>. \n";
|
|
Packit |
667938 |
print HTMLLOG "Sofware distributed under the GNU copyleft.";
|
|
Packit |
667938 |
print HTMLLOG " \n";
|
|
Packit |
667938 |
print HTMLLOG "</font>\n";
|
|
Packit |
667938 |
print HTMLLOG "\n";
|
|
Packit |
667938 |
print HTMLLOG "\n";
|
|
Packit |
667938 |
print HTMLLOG " \n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">Date</font>\n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">Time</font>\n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">Type</font>\n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">Event</font>\n";
|
|
Packit |
667938 |
print HTMLLOG " \n";
|
|
Packit |
667938 |
print HTMLLOG "\n";
|
|
Packit |
667938 |
print HTMLLOG "\n";
|
|
Packit |
667938 |
print HTMLLOG " \n";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
for ($logfileeventcounter = 0; $logfileeventcounter <= $$cfg{'eventlogmax'}; $logfileeventcounter++){
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Add new events
|
|
Packit |
667938 |
if($logfileeventcounter eq 0){
|
|
Packit |
667938 |
for ($neweventlogcounter = 0; $neweventlogcounter < $neweventcounter; $neweventlogcounter++){
|
|
Packit |
667938 |
my $shortdatestr = &shortdatestr(time);
|
|
Packit |
667938 |
print LOGFILE "$shortdatestr - $neweventstype[$neweventlogcounter] - $newevents[$neweventlogcounter]\n";
|
|
Packit |
667938 |
my($htmldate,,$htmltime) = split(/ - /,$shortdatestr);
|
|
Packit |
667938 |
print HTMLLOG " \n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">$htmldate</font>\n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">-</font>\n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">$htmltime</font>\n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">$neweventstype[$neweventlogcounter]</font>\n";
|
|
Packit |
667938 |
if($neweventstype[$neweventlogcounter] =~ /cool.*/i){
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\"></font>\n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">$newevents[$neweventlogcounter]\n";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if($neweventstype[$neweventlogcounter] =~ /warn.*/i){
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\"></font>\n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">$newevents[$neweventlogcounter]\n";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if($neweventstype[$neweventlogcounter] =~ /alarm.*/i){
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\"></font>\n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">$newevents[$neweventlogcounter]\n";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
print HTMLLOG " </font>\n";
|
|
Packit |
667938 |
print HTMLLOG " \n";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Add old events
|
|
Packit |
667938 |
if($logfileeventcounter > 0 && $oldeventloglines[$logfileeventcounter-1] ne ""){
|
|
Packit |
667938 |
print LOGFILE "$oldeventloglines[$logfileeventcounter-1]";
|
|
Packit |
667938 |
#print "Writing oldevent ($logfileeventcounter): $oldeventloglines[$logfileeventcounter-1] ";
|
|
Packit |
667938 |
my($htmldate,$htmltime,$htmleventtype,$htmlevent) = split(/ - /,$oldeventloglines[$logfileeventcounter-1]);
|
|
Packit |
667938 |
print HTMLLOG " \n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">$htmldate</font>\n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">-</font>\n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">$htmltime</font>\n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">$htmleventtype</font>\n";
|
|
Packit |
667938 |
if($htmleventtype =~ /cool.*/i){
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\"></font>\n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">$htmlevent\n";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if($htmleventtype =~ /warn.*/i){
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\"></font>\n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">$htmlevent\n";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if($htmleventtype =~ /alarm.*/i){
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\"></font>\n";
|
|
Packit |
667938 |
print HTMLLOG " <font size=\"2\">$htmlevent\n";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
print HTMLLOG " </font>\n";
|
|
Packit |
667938 |
print HTMLLOG " \n";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
print HTMLLOG "\n";
|
|
Packit |
667938 |
print HTMLLOG "</body>\n";
|
|
Packit |
667938 |
print HTMLLOG "</html>\n";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
close HTMLLOG;
|
|
Packit |
667938 |
close LOGFILE;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Finally, timestamp the image
|
|
Packit |
667938 |
my($ImgSizeX,$ImgSizeY) = $ImageData->getBounds;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
$Today=&datestr(time);
|
|
Packit |
667938 |
my $stampstring = "Network Status Imager for MRTG - $Today";
|
|
Packit |
667938 |
my $stringwidth = GD::Font::width(gdSmallFont) * length($stampstring);
|
|
Packit |
667938 |
$ImageData->string(gdSmallFont,$ImgSizeX - $stringwidth - 3,$ImgSizeY - 13,"$stampstring",$colors{'black'});
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Write the whole thing to the status map
|
|
Packit |
667938 |
open (STATUSMAP,">$$cfg{'workdir'}\\\\$$cfg{statusmapimagename}") || die "ERROR: Couldn't write to status map image $$cfg{'workdir'}\\\\$$cfg{statusmapimagename}";
|
|
Packit |
667938 |
binmode STATUSMAP;
|
|
Packit |
667938 |
print STATUSMAP $ImageData->gif;
|
|
Packit |
667938 |
close STATUSMAP;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# OK we are done, remove the lock files ...
|
|
Packit |
667938 |
print "Removing Lockfiles\n";
|
|
Packit |
667938 |
close LOCK; unlink ($templock, $lockfile);
|
|
Packit |
667938 |
print "\nMRTG - Network Status Imager unloading, gone and done...\n\n" if $main::DEBUG;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
main;
|
|
Packit |
667938 |
exit(0);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub readcfg {
|
|
Packit |
667938 |
my ($first,$second,$key);
|
|
Packit |
667938 |
my (%seen);
|
|
Packit |
667938 |
my (@routers);
|
|
Packit |
667938 |
my (%rcfg,%cfg,%pre,%post,%deflt,%defaulted);
|
|
Packit |
667938 |
my ($cfgfile) = pop(@ARGV);
|
|
Packit |
667938 |
open (CFG, $cfgfile) || do { print "ERROR: unable to open config file: $cfgfile\n\n"; &printusage };
|
|
Packit |
667938 |
while (<CFG>) {
|
|
Packit |
667938 |
s/\s+$//g; #remove whitespace at the end of the line
|
|
Packit |
667938 |
s/\s/ /g; #replace whitespace by space
|
|
Packit |
667938 |
next if /^\s*\#/; #ignore comment lines
|
|
Packit |
667938 |
next if /^\s*$/; #ignore empty lines
|
|
Packit |
667938 |
# oops spelling error
|
|
Packit |
667938 |
s/^supress/suppress/gi;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Trashcan leading zeros in action statements
|
|
Packit |
667938 |
s/^action\.0+/action\./gi;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Also lets record the number of the highest action given for later
|
|
Packit |
667938 |
if ($first =~ /^action.+/){
|
|
Packit |
667938 |
$actionnumber = $first;
|
|
Packit |
667938 |
$actionnumber =~ s/action\.//gi;
|
|
Packit |
667938 |
if($actionnumber > $rcfg{'maxaction'}{$second}){
|
|
Packit |
667938 |
$rcfg{'maxaction'}{$second} = $actionnumber;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# append mode
|
|
Packit |
667938 |
if ($first && /^\s+(.*\S)\s*$/) {
|
|
Packit |
667938 |
if ($second eq '^') {
|
|
Packit |
667938 |
$pre{$first} .= " $1";
|
|
Packit |
667938 |
next;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if ($second eq '$' ) {
|
|
Packit |
667938 |
$post{$first} .= " $1";
|
|
Packit |
667938 |
next;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if ($second eq '_') {
|
|
Packit |
667938 |
$deflt{$first} .= " $1";
|
|
Packit |
667938 |
next;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if ($second) {
|
|
Packit |
667938 |
$rcfg{$first}{$second} .= " $1";
|
|
Packit |
667938 |
} else {
|
|
Packit |
667938 |
$cfg{$first} .= " $1";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
next;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if ($first && $second && $post{$first} && ($second !~ /^[\$^_]$/)) {
|
|
Packit |
667938 |
if ($defaulted{$first}{$second}) {
|
|
Packit |
667938 |
$rcfg{$first}{$second} = $post{$first};
|
|
Packit |
667938 |
delete $defaulted{$first}{$second};
|
|
Packit |
667938 |
} else {
|
|
Packit |
667938 |
$rcfg{$first}{$second} .= " $post{$first}"
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if ($first && exists $deflt{$first} && ($second eq '_')) {
|
|
Packit |
667938 |
&quickcheck($first,$second,$deflt{$first},$.)
|
|
Packit |
667938 |
} elsif ($first && $second && ($second !~ /^[\$^_]$/)) {
|
|
Packit |
667938 |
&quickcheck($first,$second,$rcfg{$first}{$second},$.)
|
|
Packit |
667938 |
} elsif ($first && ($second !~ /^[\$^_]$/)) {
|
|
Packit |
667938 |
&quickcheck($first,0,$cfg{$first},$.)
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if (/^([A-Za-z0-9\.]+)\[(\S+)\]\s*:\s*(.*\S?)\s*$/) {
|
|
Packit |
667938 |
print "readcfg: rcfg $1 $2 = $3\n" if $main::DEBUG > 1;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
$first = lc($1);
|
|
Packit |
667938 |
$second = lc($2);
|
|
Packit |
667938 |
if ($second eq '^')
|
|
Packit |
667938 |
{ if ($3 ne '') {$pre{$first}=$3} else {delete $pre{$first}}; next; }
|
|
Packit |
667938 |
if ($second eq '$')
|
|
Packit |
667938 |
{ if ($3 ne '') {$post{$first}=$3} else {delete $post{$first}}; next; }
|
|
Packit |
667938 |
if ($second eq '_')
|
|
Packit |
667938 |
{ if ($3 ne '') {$deflt{$first}=$3} else {delete $deflt{$first}}; next; }
|
|
Packit |
667938 |
|
|
Packit |
667938 |
push (@routers, $second) unless grep (/^$second$/, @routers);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# make sure that default tags spring into existance upon first
|
|
Packit |
667938 |
# call of a router
|
|
Packit |
667938 |
|
|
Packit |
667938 |
foreach $key (keys %deflt) {
|
|
Packit |
667938 |
if (! exists $rcfg{$key}{$second}) {
|
|
Packit |
667938 |
$rcfg{$key}{$second} = $deflt{$key};
|
|
Packit |
667938 |
$defaulted{$key}{$second} = 1;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# make sure that prefix-only tags spring into existance upon first
|
|
Packit |
667938 |
# call of a router
|
|
Packit |
667938 |
|
|
Packit |
667938 |
foreach $key (keys %pre) {
|
|
Packit |
667938 |
if (! exists $rcfg{$key}{$second}) {
|
|
Packit |
667938 |
delete $defaulted{$key}{$second} if $defaulted{$key}{$second};
|
|
Packit |
667938 |
$rcfg{$key}{$second} = "$pre{$key} ";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if ($seen{$first}{$second}) {
|
|
Packit |
667938 |
die ("\nLine $. in CFG file contains a duplicate definition for\n".
|
|
Packit |
667938 |
"$first\[$second]. First definition is on line $seen{$first}{$second}\n")
|
|
Packit |
667938 |
} else {
|
|
Packit |
667938 |
$seen{$first}{$second} = $.;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if ($defaulted{$first}{$second}) {
|
|
Packit |
667938 |
$rcfg{$first}{$second} = '';
|
|
Packit |
667938 |
delete $defaulted{$first}{$second};
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
$rcfg{$first}{$second} .= $3;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
next;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if (/^(\S+):\s*(.*\S)\s*$/) {
|
|
Packit |
667938 |
$first = lc($1);
|
|
Packit |
667938 |
$cfg{$first} = $2;
|
|
Packit |
667938 |
$second = '';
|
|
Packit |
667938 |
next;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
die ( "\nLine $. in CFG file does not make sense\n" );
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# append $ stuff to the very last tag in cfg file if necessary
|
|
Packit |
667938 |
if ($first && $second && $post{$first} && ($second !~ /^[\$^_]$/)) {
|
|
Packit |
667938 |
if ($defaulted{$first}{$second}) {
|
|
Packit |
667938 |
$rcfg{$first}{$second} = $post{$first};
|
|
Packit |
667938 |
delete $defaulted{$first}{$second};
|
|
Packit |
667938 |
} else {
|
|
Packit |
667938 |
$rcfg{$first}{$second} .= " $post{$first}"
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Tobi, I don't know how you did this, but this is something else:
|
|
Packit |
667938 |
#Get highest action number for the last line in the config file...
|
|
Packit |
667938 |
if ($first =~ /^action.+/){
|
|
Packit |
667938 |
$actionnumber = $first;
|
|
Packit |
667938 |
$actionnumber =~ s/action\.//gi;
|
|
Packit |
667938 |
if($actionnumber > $rcfg{'maxaction'}{$second}){
|
|
Packit |
667938 |
$rcfg{'maxaction'}{$second} = $actionnumber;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#check the last input line
|
|
Packit |
667938 |
if ($first && exists $deflt{$first} && ($second eq '_')) {
|
|
Packit |
667938 |
&quickcheck($first,$second,$deflt{$first},$.)
|
|
Packit |
667938 |
} elsif ($first && $second) {
|
|
Packit |
667938 |
&quickcheck($first,$second,$rcfg{$first}{$second},$.)
|
|
Packit |
667938 |
} elsif ($first) {
|
|
Packit |
667938 |
&quickcheck($first,0,$cfg{$first},$.)
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
close (CFG);
|
|
Packit |
667938 |
(\@routers, \%cfg, \%rcfg, $cfgfile);
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub cfgcheck {
|
|
Packit |
667938 |
my ($routers, $cfg, $rcfg) = @_;
|
|
Packit |
667938 |
my ($rou, $confname, $one_option);
|
|
Packit |
667938 |
my %node;
|
|
Packit |
667938 |
my $error="no";
|
|
Packit |
667938 |
my(@known_options) = qw(alarmifnull);
|
|
Packit |
667938 |
if (! $$cfg{workdir}) {
|
|
Packit |
667938 |
warn ("\nERROR: \"WorkDir\" not specified\n");
|
|
Packit |
667938 |
$error = "yes";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
foreach $rou (@$routers) {
|
|
Packit |
667938 |
if ($$rcfg{'directory'}{$rou})
|
|
Packit |
667938 |
{
|
|
Packit |
667938 |
# They specified a directory for this router. Append the
|
|
Packit |
667938 |
# pathname seperator to it (so that it can either be present or
|
|
Packit |
667938 |
# absent, and the rules for including it are the same).
|
|
Packit |
667938 |
$$rcfg{'directory'}{$rou} .= ${main::SL};
|
|
Packit |
667938 |
# remove any stray spaces ...
|
|
Packit |
667938 |
$$rcfg{'directory'}{$rou} =~ s/\s//g;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# Configure e-mail notification for this node
|
|
Packit |
667938 |
if (defined($$rcfg{'nodestatusemail'}{$rou})){
|
|
Packit |
667938 |
if($$rcfg{'nodestatusemailtarget'}{$rou} ne ""){
|
|
Packit |
667938 |
if($$rcfg{'nodestatusemail'}{$rou} =~ /[^cwa *]/i ){
|
|
Packit |
667938 |
warn ("\nERROR: NodeStatusEmail[$rou]: \"$$rcfg{'nodestatusemail'}{$rou}\" contains invalid options [cwa].\n");
|
|
Packit |
667938 |
$error="yes";
|
|
Packit |
667938 |
}else{
|
|
Packit |
667938 |
if($$rcfg{'nodestatusemail'}{$rou} =~ /c/i ){
|
|
Packit |
667938 |
$$rcfg{'email'}{'cool'}{$rou} = 1;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if($$rcfg{'nodestatusemail'}{$rou} =~ /w/i ){
|
|
Packit |
667938 |
$$rcfg{'email'}{'warn'}{$rou} = 1;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if($$rcfg{'nodestatusemail'}{$rou} =~ /a/i ){
|
|
Packit |
667938 |
$$rcfg{'email'}{'alarm'}{$rou} = 1;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}else{
|
|
Packit |
667938 |
warn ("\nERROR: NodeStatusEmail[$rou]: \"$$rcfg{'nodestatusemail'}{$rou}\" is given but no NodeStatusEmailTarget[$rou] was found.\n");
|
|
Packit |
667938 |
$error="yes";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if (exists $$rcfg{"options"}{$rou}) {
|
|
Packit |
667938 |
foreach $one_option (split /[,\s]+/, lc($$rcfg{"options"}{$rou})) {
|
|
Packit |
667938 |
if (grep {$one_option eq $_} @known_options) {
|
|
Packit |
667938 |
$$rcfg{'options'}{$one_option}{$rou} = 1;
|
|
Packit |
667938 |
} else {
|
|
Packit |
667938 |
warn ("\nERROR: Option[$rou]: \"$one_option\" is unknown\n");
|
|
Packit |
667938 |
$error="yes";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if ($error eq "yes") {
|
|
Packit |
667938 |
die ("\n\nABORT: Please fix the error(s) in your config file\n\n");
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
\%node;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub quickcheck {
|
|
Packit |
667938 |
my ($first,$second,$arg,$line) = @_;
|
|
Packit |
667938 |
my %rules =
|
|
Packit |
667938 |
(# General CFG
|
|
Packit |
667938 |
'workdir' =>
|
|
Packit |
667938 |
['$arg && (-d $arg)','"Directory $arg does not exist"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'eventlog' =>
|
|
Packit |
667938 |
['$arg','"Eventlog path is missing"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'eventlogmax' =>
|
|
Packit |
667938 |
['$arg =~ /\d+/','"You must specify a value"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'icondir' =>
|
|
Packit |
667938 |
['$arg && (-d $arg)','"Directory $arg does not exist"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'statusmapbackground' =>
|
|
Packit |
667938 |
['$arg && (-f $arg)','"Image file $arg does not exist"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'statusmapimagename' =>
|
|
Packit |
667938 |
['$arg','"Target image name is missing"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'imgsourcedir' =>
|
|
Packit |
667938 |
['$arg && (-d $arg)','"Directory $arg does not exist"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'msgfile' =>
|
|
Packit |
667938 |
['$arg && (-f $arg)','"Message file $arg does not exist"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'statusemailorigin' =>
|
|
Packit |
667938 |
['$arg =~ /\w+/','"You must specify something for this option"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'refresh' =>
|
|
Packit |
667938 |
['int($arg) >= 300', '"$arg should be 300 seconds or more"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'interval' =>
|
|
Packit |
667938 |
['int($arg) >= 5','"$arg should be more than 5 Minutes"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'testnodelocations' =>
|
|
Packit |
667938 |
['$arg =~ /[ynYN]/','"This option is either y or n"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Nodes CFG
|
|
Packit |
667938 |
'node[]' =>
|
|
Packit |
667938 |
['$arg =~ /\w+/','"You must specify something for this option"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'nodecenterx[]' =>
|
|
Packit |
667938 |
['int($arg) >= 0', '"$arg <-- Value cannot be negative"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'nodecentery[]' =>
|
|
Packit |
667938 |
['int($arg) >= 0', '"$arg <-- Value cannot be negative"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'nodealarmthreshhold[]' =>
|
|
Packit |
667938 |
['$arg =~ /\d+/','"You must specify a value"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'nodewarningthreshhold[]' =>
|
|
Packit |
667938 |
['$arg =~ /\d+/','"You must specify a value"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'nodeincoolmsgid[]' =>
|
|
Packit |
667938 |
['$arg =~ /\w+/','"You must specify something for this option"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'nodeinwarningmsgid[]' =>
|
|
Packit |
667938 |
['$arg =~ /\w+/','"You must specify something for this option"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'nodeinalarmmsgid[]' =>
|
|
Packit |
667938 |
['$arg =~ /\w+/','"You must specify something for this option"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'nodeoutcoolmsgid[]' =>
|
|
Packit |
667938 |
['$arg =~ /\w+/','"You must specify something for this option"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'nodeoutwarningmsgid[]' =>
|
|
Packit |
667938 |
['$arg =~ /\w+/','"You must specify something for this option"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'nodeoutalarmmsgid[]' =>
|
|
Packit |
667938 |
['$arg =~ /\w+/','"You must specify something for this option"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'nodestatusemail[]' =>
|
|
Packit |
667938 |
['$arg =~ /\w+/','"You must specify something for this option"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'nodestatusemailtarget[]' =>
|
|
Packit |
667938 |
['$arg =~ /\w+/','"You must specify something for this option"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'options[]' =>
|
|
Packit |
667938 |
['1','"Internal Error"'],
|
|
Packit |
667938 |
|
|
Packit |
667938 |
'action[]' =>
|
|
Packit |
667938 |
['$arg =~ /\w+/','"You must specify something for this option"'],
|
|
Packit |
667938 |
);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my $braces = $second ? '[]':'';
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#The actions are different from the other options
|
|
Packit |
667938 |
if ($first =~ /^action.+/){
|
|
Packit |
667938 |
if ($first =~ /action.\d*/) {
|
|
Packit |
667938 |
return 1;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}elsif (exists $rules{$first.$braces}) {
|
|
Packit |
667938 |
if (eval($rules{$first.$braces}[0])) {
|
|
Packit |
667938 |
return 1;
|
|
Packit |
667938 |
} else {
|
|
Packit |
667938 |
if ($second) {
|
|
Packit |
667938 |
die "\nCFG Error in \"$first\[$second\]\", line $line: ".
|
|
Packit |
667938 |
eval($rules{$first.$braces}[1])."\n\n";
|
|
Packit |
667938 |
} else {
|
|
Packit |
667938 |
die "\nCFG Error in \"$first\", line $line: ".
|
|
Packit |
667938 |
eval($rules{$first.$braces}[1])."\n\n";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
die "\nCFG Error: Unknown Option \"$first\" on line $line or above.\n".
|
|
Packit |
667938 |
" Check readme.html for Help\n\n";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub readmsgfile {
|
|
Packit |
667938 |
my ($msgfile) = @_;
|
|
Packit |
667938 |
my ($first,$second,$key);
|
|
Packit |
667938 |
my (%seen);
|
|
Packit |
667938 |
my (%rmsg,%msg,%pre,%post);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
open (MSGFILE, $msgfile) || do { print "ERROR: unable to open message file: $msgfile\n\n"};
|
|
Packit |
667938 |
while (<MSGFILE>) {
|
|
Packit |
667938 |
s/\s+$//g; #remove whitespace at the end of the line
|
|
Packit |
667938 |
s/\s/ /g; #replace whitespace by space
|
|
Packit |
667938 |
next if /^\s*\#/; #ignore comment lines
|
|
Packit |
667938 |
next if /^\s*$/; #ignore empty lines
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# append mode
|
|
Packit |
667938 |
if ($first && /^\s+(.*\S)\s*$/) {
|
|
Packit |
667938 |
if ($second eq '^') {
|
|
Packit |
667938 |
$pre{$first} .= " $1";
|
|
Packit |
667938 |
next;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if ($second eq '$' ) {
|
|
Packit |
667938 |
$post{$first} .= " $1";
|
|
Packit |
667938 |
next;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if ($second) {
|
|
Packit |
667938 |
$rmsg{$first}{$second} .= " $1";
|
|
Packit |
667938 |
} else {
|
|
Packit |
667938 |
$msg{$first} .= " $1";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
next;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if (/^(\S+):\s*(.*\S)\s*$/) {
|
|
Packit |
667938 |
$first = lc($1);
|
|
Packit |
667938 |
$msg{$first} = $2;
|
|
Packit |
667938 |
$second = '';
|
|
Packit |
667938 |
next;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
die ( "\nLine $. in MSGFILE file does not make sense\n" );
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
close (MSGFILE);
|
|
Packit |
667938 |
(\%msg);
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub action_draw_crosshair {
|
|
Packit |
667938 |
#This one draws a crosshair symbol
|
|
Packit |
667938 |
my($ImageData, $cfg, $rcfg, $routers, $router, $cox, $coy,$color) = @_;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
$cox = nsi_eval($ImageData, $cfg, $rcfg, $routers, $router, $cox);
|
|
Packit |
667938 |
$cox = $cox + nsi_eval($ImageData, $cfg, $rcfg, $routers, $router, $$rcfg{'nodelabeloffsetx'}{$router});
|
|
Packit |
667938 |
|
|
Packit |
667938 |
$coy = nsi_eval($ImageData, $cfg, $rcfg, $routers, $router, $coy);
|
|
Packit |
667938 |
$coy = $coy + nsi_eval($ImageData, $cfg, $rcfg, $routers, $router, $$rcfg{'nodelabeloffsety'}{$router});
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Draw the crosshair...
|
|
Packit |
667938 |
$ImageData->arc($cox,$coy,30,30,0,360,$color);
|
|
Packit |
667938 |
$ImageData->arc($cox,$coy,20,20,0,360,$color);
|
|
Packit |
667938 |
$ImageData->arc($cox,$coy,10,10,0,360,$color);
|
|
Packit |
667938 |
$ImageData->line($cox-17,$coy,$cox+17,$coy,$color);
|
|
Packit |
667938 |
$ImageData->line($cox,$coy-17,$cox,$coy+17,$color);
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub datestr {
|
|
Packit |
667938 |
my ($time) = shift(@_) || return 0;
|
|
Packit |
667938 |
my ($wday) = ('Sunday','Monday','Tuesday','Wednesday',
|
|
Packit |
667938 |
'Thursday','Friday','Saturday')[(localtime($time))[6]];
|
|
Packit |
667938 |
my ($month) = ('January','February' ,'March' ,'April' ,
|
|
Packit |
667938 |
'May' , 'June' , 'July' , 'August' , 'September' ,
|
|
Packit |
667938 |
'October' ,
|
|
Packit |
667938 |
'November' , 'December' )[(localtime($time))[4]];
|
|
Packit |
667938 |
my ($mday,$year,$hour,$min,$sec) = (localtime($time))[3,5,2,1,0];
|
|
Packit |
667938 |
if ($min<10) {$min = "0$min";}
|
|
Packit |
667938 |
if ($sec<10) {$sec = "0$sec";}
|
|
Packit |
667938 |
return "$wday, $month $mday, ".($year+1900)." - $hour:$min:$sec";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub shortdatestr {
|
|
Packit |
667938 |
my ($time) = shift(@_) || return 0;
|
|
Packit |
667938 |
my ($mday,$month,$year,$hour,$min,$sec) = (localtime($time))[3,4,5,2,1,0];
|
|
Packit |
667938 |
$month++;
|
|
Packit |
667938 |
if ($min<10) {$min = "0$min";}
|
|
Packit |
667938 |
if ($sec<10) {$sec = "0$sec";}
|
|
Packit |
667938 |
return "$month/$mday/".($year+1900)." - $hour:$min:$sec";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub nsi_eval {
|
|
Packit |
667938 |
#Replace references to other nodes and evaluate expressions
|
|
Packit |
667938 |
my($ImageData, $cfg, $rcfg, $routers, $router, $evali) = @_;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Replace .xy-references to other nodes
|
|
Packit |
667938 |
foreach $eval_node (@$routers) {
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my $lceval_node = lc($eval_node);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Replace "node.x"
|
|
Packit |
667938 |
$evali =~ s/[\W]$lceval_node\.x/$$rcfg{'nodecenterx'}{$eval_node}/gie;
|
|
Packit |
667938 |
$evali =~ s/^$lceval_node\.x/$$rcfg{'nodecenterx'}{$eval_node}/gie;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Replace "node.y"
|
|
Packit |
667938 |
$evali =~ s/[\W]$lceval_node\.y/$$rcfg{'nodecentery'}{$eval_node}/gie;
|
|
Packit |
667938 |
$evali =~ s/^$lceval_node\.y/$$rcfg{'nodecentery'}{$eval_node}/gie;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#If something else expanded from the nodecenter, evaluate that too...
|
|
Packit |
667938 |
$evali = lc($evali);
|
|
Packit |
667938 |
foreach $eval_node (@$routers) {
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my $lceval_node = lc($eval_node);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Replace "node.x"
|
|
Packit |
667938 |
$evali =~ s/[\W]$lceval_node\.x/$$rcfg{'nodecenterx'}{$eval_node}/gie;
|
|
Packit |
667938 |
$evali =~ s/^$lceval_node\.x/$$rcfg{'nodecenterx'}{$eval_node}/gie;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Replace "node.y"
|
|
Packit |
667938 |
$evali =~ s/[\W]$lceval_node\.y/$$rcfg{'nodecentery'}{$eval_node}/gie;
|
|
Packit |
667938 |
$evali =~ s/^$lceval_node\.y/$$rcfg{'nodecentery'}{$eval_node}/gie;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Evaluate and format the expression
|
|
Packit |
667938 |
$evali = sprintf("%.0f",eval($evali));
|
|
Packit |
667938 |
return $evali;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub getnodevalues {
|
|
Packit |
667938 |
my ($target, $rou, $rcfg, $cfg) = @_;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my $period = 0;
|
|
Packit |
667938 |
my $lastperiod = 0;
|
|
Packit |
667938 |
my $incurrent=0;
|
|
Packit |
667938 |
my $outcurrent=0;
|
|
Packit |
667938 |
my $inlast = 0;
|
|
Packit |
667938 |
my $outlast = 0;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
open (LOG, "<$$cfg{'workdir'}\\\\$target.log") or die "ERROR: Can't open .log file for this node: $target\n";
|
|
Packit |
667938 |
my($counterline,$line,$lastline) = <LOG>;
|
|
Packit |
667938 |
($period,$incurrent,$outcurrent)=split(/\D/,$line);
|
|
Packit |
667938 |
($lastperiod,$inlast,$outlast)=split(/\D/,$lastline);
|
|
Packit |
667938 |
close LOG;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Check the period (if we're too far out, we've probably lost contact with the node)
|
|
Packit |
667938 |
$time = time unless defined $time;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my($timediff)=$time - $period;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Give it 2 more minutes, then report the node as down
|
|
Packit |
667938 |
if($timediff > $$cfg{'interval'} * 60 + 120){
|
|
Packit |
667938 |
$incurrent = -1;
|
|
Packit |
667938 |
$outcurrent = -1;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
($incurrent, $outcurrent, $inlast, $outlast);
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub getnodestatus{
|
|
Packit |
667938 |
my ($incurrent,$outcurrent,$target, $router, $rcfg, $cfg) = @_;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my $nodeinstatus = "cool";
|
|
Packit |
667938 |
my $nodeoutstatus = "cool";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Node down?
|
|
Packit |
667938 |
if($incurrent eq -1){
|
|
Packit |
667938 |
$nodeinstatus = "alarm";
|
|
Packit |
667938 |
$nodeoutstatus = "alarm";
|
|
Packit |
667938 |
}else{
|
|
Packit |
667938 |
#Which direction are we looking?
|
|
Packit |
667938 |
if($$rcfg{'nodealarmthreshhold'}{$router} >= $$rcfg{'nodewarningthreshhold'}{$router}){
|
|
Packit |
667938 |
#Straight forward
|
|
Packit |
667938 |
if($incurrent > $$rcfg{'nodewarningthreshhold'}{$router}){
|
|
Packit |
667938 |
$nodeinstatus = "warning";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if($outcurrent > $$rcfg{'nodewarningthreshhold'}{$router}){
|
|
Packit |
667938 |
$nodeoutstatus = "warning";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if($incurrent > $$rcfg{'nodealarmthreshhold'}{$router}){
|
|
Packit |
667938 |
$nodeinstatus = "alarm";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if($outcurrent > $$rcfg{'nodealarmthreshhold'}{$router}){
|
|
Packit |
667938 |
$nodeoutstatus = "alarm";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}else{
|
|
Packit |
667938 |
#Backwards
|
|
Packit |
667938 |
if($incurrent < $$rcfg{'nodewarningthreshhold'}{$router}){
|
|
Packit |
667938 |
$nodeinstatus = "warning";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if($outcurrent < $$rcfg{'nodewarningthreshhold'}{$router}){
|
|
Packit |
667938 |
$nodeoutstatus = "warning";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if($incurrent < $$rcfg{'nodealarmthreshhold'}{$router}){
|
|
Packit |
667938 |
$nodeinstatus = "alarm";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if($outcurrent < $$rcfg{'nodealarmthreshhold'}{$router}){
|
|
Packit |
667938 |
$nodeoutstatus = "alarm";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Check for nulls
|
|
Packit |
667938 |
if($$rcfg{'options'}{'alarmifnull'}{$router}){
|
|
Packit |
667938 |
if($incurrent eq "0"){
|
|
Packit |
667938 |
$nodeinstatus = "alarm";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if($outcurrent eq "0"){
|
|
Packit |
667938 |
$nodeoutstatus = "alarm";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
($nodeinstatus,$nodeoutstatus);
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub drawnodeline{
|
|
Packit |
667938 |
my ($ImageData, $gdstyles, $cfg, $rcfg, $routers, $router, $msg, $nodeinstatus, $nodeoutstatus, $incurrent, $outcurrent, $direction, $cond, $source, $destination, $style) = @_;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Expand our numeric arguments
|
|
Packit |
667938 |
my $sourcex = nsi_eval($ImageData, $cfg, $rcfg, $routers, $router, "$source.x");
|
|
Packit |
667938 |
my $sourcey = nsi_eval($ImageData, $cfg, $rcfg, $routers, $router, "$source.y");
|
|
Packit |
667938 |
my $destinationx = nsi_eval($ImageData, $cfg, $rcfg, $routers, $router, "$destination.x");
|
|
Packit |
667938 |
my $destinationy = nsi_eval($ImageData, $cfg, $rcfg, $routers, $router, "$destination.y");
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my $absnodestatus = "$direction$cond";
|
|
Packit |
667938 |
my $absnodeinstatus = "in$nodeinstatus";
|
|
Packit |
667938 |
my $absnodeoutstatus = "out$nodeoutstatus";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Draw something depending on the node's status
|
|
Packit |
667938 |
if ($absnodestatus eq $absnodeinstatus || $absnodestatus =~ /always/i){
|
|
Packit |
667938 |
$ImageData->setStyle(split(/,/,$$gdstyles{$style}{'style'}));
|
|
Packit |
667938 |
#$ImageData->setStyle($$gdstyles{$style}{'style'});
|
|
Packit |
667938 |
$ImageData->line($sourcex,$sourcey,$destinationx,$destinationy,gdStyled);
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub copyimage{
|
|
Packit |
667938 |
my ($ImageData, $gdstyles, $cfg, $rcfg, $routers, $router, $msg, $nodeinstatus, $nodeoutstatus, $incurrent, $outcurrent, $direction, $cond, $image, $coordx, $coordy) = @_;
|
|
Packit |
667938 |
#Expand our numeric arguments
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my $coordx = nsi_eval($ImageData, $cfg, $rcfg, $routers, $router, "$coordx");
|
|
Packit |
667938 |
my $coordy = nsi_eval($ImageData, $cfg, $rcfg, $routers, $router, "$coordy");
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my $absnodestatus = "$direction$cond";
|
|
Packit |
667938 |
my $absnodeinstatus = "in$nodeinstatus";
|
|
Packit |
667938 |
my $absnodeoutstatus = "out$nodeoutstatus";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Draw something depending on the node's status
|
|
Packit |
667938 |
if ($absnodestatus eq $absnodeinstatus || $absnodestatus =~ /always/i){
|
|
Packit |
667938 |
open (SRCIMG,"<$$cfg{'icondir'}\\\\$image") || die "ERROR: Can't open source image for copy: $$cfg{'icondir'}\\\\$image\n";
|
|
Packit |
667938 |
my($srcImageData) = newFromGif GD::Image(SRCIMG) || die "ERROR: GD::newFromGif\n";
|
|
Packit |
667938 |
close SRCIMG;
|
|
Packit |
667938 |
my($srcImgDataSizeX,$srcImgDataSizeY) = $srcImageData->getBounds;
|
|
Packit |
667938 |
$ImageData->copy($srcImageData,$coordx,$coordy,0,0,$srcImgDataSizeX,$srcImgDataSizeY);
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub multicopyimage{
|
|
Packit |
667938 |
my ($ImageData, $gdstyles, $cfg, $rcfg, $routers, $router, $msg, $nodeinstatus, $nodeoutstatus, $incurrent, $outcurrent, $direction, $cond, $image, $coordx, $coordy, $howoften, $minoften, $maxoften, $stepsize, $angle) = @_;
|
|
Packit |
667938 |
#Expand our numeric arguments
|
|
Packit |
667938 |
|
|
Packit |
667938 |
print "Coordinates: $coordx/$coordy\n";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my $coordx = nsi_eval($ImageData, $cfg, $rcfg, $routers, $router, "$coordx");
|
|
Packit |
667938 |
my $coordy = nsi_eval($ImageData, $cfg, $rcfg, $routers, $router, "$coordy");
|
|
Packit |
667938 |
my $howoften = nsi_eval($ImageData, $cfg, $rcfg, $routers, $router, "$howoften");
|
|
Packit |
667938 |
|
|
Packit |
667938 |
print "Coordinates: $coordx/$coordy\n";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if ($howoften < $minoften){
|
|
Packit |
667938 |
$howoften = $minoften;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if ($howoften > $maxoften){
|
|
Packit |
667938 |
$howoften = $maxoften;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my $absnodestatus = "$direction$cond";
|
|
Packit |
667938 |
my $absnodeinstatus = "in$nodeinstatus";
|
|
Packit |
667938 |
my $absnodeoutstatus = "out$nodeoutstatus";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Draw something depending on the node's status
|
|
Packit |
667938 |
if ($absnodestatus eq $absnodeinstatus || $absnodestatus =~ /always/i){
|
|
Packit |
667938 |
open (SRCIMG,"<$$cfg{'icondir'}\\\\$image") || die "ERROR: Can't open source image for copy: $$cfg{'icondir'}\\\\$image\n";
|
|
Packit |
667938 |
my($srcImageData) = newFromGif GD::Image(SRCIMG) || die "ERROR: GD::newFromGif\n";
|
|
Packit |
667938 |
close SRCIMG;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my($srcImgDataSizeX,$srcImgDataSizeY) = $srcImageData->getBounds;
|
|
Packit |
667938 |
my $rad = ($angle * 3.141592654) / 180;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if ($stepsize >= 0){
|
|
Packit |
667938 |
for($multicounter = 0; $multicounter < $howoften; $multicounter++){
|
|
Packit |
667938 |
my $hyp = $multicounter * $stepsize;
|
|
Packit |
667938 |
my $a = sprintf("%.0f",sin($rad) * $hyp);
|
|
Packit |
667938 |
my $b = sprintf("%.0f",cos($rad) * $hyp);
|
|
Packit |
667938 |
#print "Angle: $angle, Rad: $rad, a: $a, b: $b\n";
|
|
Packit |
667938 |
$ImageData->copy($srcImageData,$coordx + $b,$coordy - $a,0,0,$srcImgDataSizeX,$srcImgDataSizeY);
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}else{
|
|
Packit |
667938 |
$stepsize = abs($stepsize);
|
|
Packit |
667938 |
for($multicounter = $howoften - 1; $multicounter >= 0; $multicounter--){
|
|
Packit |
667938 |
my $hyp = $multicounter * $stepsize;
|
|
Packit |
667938 |
my $a = sprintf("%.0f",sin($rad) * $hyp);
|
|
Packit |
667938 |
my $b = sprintf("%.0f",cos($rad) * $hyp);
|
|
Packit |
667938 |
#print "Angle: $angle, Rad: $rad, a: $a, b: $b\n";
|
|
Packit |
667938 |
$ImageData->copy($srcImageData,$coordx + $b,$coordy - $a,0,0,$srcImgDataSizeX,$srcImgDataSizeY);
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub drawtext{
|
|
Packit |
667938 |
my ($ImageData, $gdstyles, $cfg, $rcfg, $routers, $router, $msg, $nodeinstatus, $nodeoutstatus, $incurrent, $outcurrent, $direction, $cond, $font, $coordx, $coordy, $textid, $color) = @_;
|
|
Packit |
667938 |
#Expand our numeric arguments
|
|
Packit |
667938 |
my $coordx = nsi_eval($ImageData, $cfg, $rcfg, $routers, $router, "$coordx");
|
|
Packit |
667938 |
my $coordy = nsi_eval($ImageData, $cfg, $rcfg, $routers, $router, "$coordy");
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my $absnodestatus = "$direction$cond";
|
|
Packit |
667938 |
my $absnodeinstatus = "in$nodeinstatus";
|
|
Packit |
667938 |
my $absnodeoutstatus = "out$nodeoutstatus";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Draw something depending on the node's status
|
|
Packit |
667938 |
if ($absnodestatus eq $absnodeinstatus || $absnodestatus =~ /always/i){
|
|
Packit |
667938 |
if(!defined($$msg{$textid})){
|
|
Packit |
667938 |
$$msg{$textid} = "MSG not defined!";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
if($font eq 1){$ImageData->string(gdTinyFont,$coordx,$coordy,$$msg{$textid},$colors{$color});}
|
|
Packit |
667938 |
if($font eq 2){$ImageData->string(gdSmallFont,$coordx,$coordy,$$msg{$textid},$colors{$color});}
|
|
Packit |
667938 |
if($font eq 3){$ImageData->string(gdMediumBoldFont,$coordx,$coordy,$$msg{$textid},$colors{$color});}
|
|
Packit |
667938 |
if($font eq 4){$ImageData->string(gdLargeFont,$coordx,$coordy,$$msg{$textid},$colors{$color});}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub transeventvar{
|
|
Packit |
667938 |
my ($cfg, $rcfg, $routers, $router, $incurrent, $outcurrent, $transstring) = @_;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my @transsplit = split(/\$/,$transstring);
|
|
Packit |
667938 |
my $maxelements = $transsplit;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
print "MAXELEMNTS: $transstring\n";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
for ($transcounter = 0; $transcounter <= $maxelements; $transcounter++){
|
|
Packit |
667938 |
$transstring =~ s/\$NodeWarningThreshhold/$$rcfg{nodewarningthreshhold}{$router}/i;
|
|
Packit |
667938 |
$transstring =~ s/\$NodeAlarmThreshhold/$$rcfg{nodealarmthreshhold}{$router}/i;
|
|
Packit |
667938 |
$transstring =~ s/\$NodeIn/$incurrent/i;
|
|
Packit |
667938 |
$transstring =~ s/\$NodeOut/$outcurrent/i;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
return $transstring;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
sub sendmail{
|
|
Packit |
667938 |
my ($cfg, $rcfg, $routers, $router, $incurrent, $outcurrent, $event, $eventtype, $address) = @_;
|
|
Packit |
667938 |
print "Sending e-mail to: $address from $$cfg{'statusemailorigin'}\n";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
my $smtp = Net::SMTP->new('hampton.lam.liebherr.com'); # connect to an SMTP server
|
|
Packit |
667938 |
|
|
Packit |
667938 |
foreach $target (split(/;/,$address)){
|
|
Packit |
667938 |
$smtp->mail( $$cfg{'statusemailorigin'} ); # use the sender's address here
|
|
Packit |
667938 |
$smtp->to($target); # recipient's address
|
|
Packit |
667938 |
$smtp->data(); # Start the mail
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# Send the header.
|
|
Packit |
667938 |
$smtp->datasend("To: $address\n");
|
|
Packit |
667938 |
$smtp->datasend("From: $$cfg{'statusemailorigin'}\n");
|
|
Packit |
667938 |
$smtp->datasend("Subject: $eventtype on Node \"$router\"\n");
|
|
Packit |
667938 |
$smtp->datasend("\n");
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# Send the body.
|
|
Packit |
667938 |
$smtp->datasend("$event\n");
|
|
Packit |
667938 |
$smtp->datasend("\n");
|
|
Packit |
667938 |
$smtp->datasend("\n");
|
|
Packit |
667938 |
$smtp->datasend("*******************************************************\n");
|
|
Packit |
667938 |
$smtp->datasend("*** This was an automated network status update ***\n");
|
|
Packit |
667938 |
$smtp->datasend("*** message generated by: ***\n");
|
|
Packit |
667938 |
$smtp->datasend("*** NSI v1.0 for MRTG, Created by Mac Kloberg ***\n");
|
|
Packit |
667938 |
$smtp->datasend("*** <mac.kloberg\@lam.liebherr.com> <mac\@nacs.net> ***\n");
|
|
Packit |
667938 |
$smtp->datasend("*******************************************************\n");
|
|
Packit |
667938 |
$smtp->dataend(); # Finish sending the mail
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
$smtp->quit; # Close the SMTP connection
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|