Project

General

Profile

« Previous | Next » 

Revision af3a7f97

Added by Hamish Coleman almost 17 years ago

  • ID af3a7f973a6b9c0db8191ccb61c855faf9f494cd

Make debug text a param, rename "test" again, start extracting hosttype functions

View differences:

mrtg.cgi
}
}
sub maketree_grouphosttest($$) {
my ($name,$sequence) = @_;
sub extract_grouphosttest($) {
my ($name) = @_;
# Do not classify any test with no separators in it
# Do not classify a test with no separators in it
if ($name !~ /,/) {
$db->{tree}->{other}->{$name} = $sequence;
return;
return undef;
}
my ($group,$host,$test) = split ',', $name;
# TODO cope with missing group/host/test parts.
# for now, just assume it is not a group/host/test
if (!defined $group || !defined $host || !defined $test) {
return undef;
}
return ($group,$host,$test);
}
# Read through the list of targets and find common hostname prefixes,
# so that we can group these hosts together
# (a hosttype entry)
#
sub maketree_find_hosttypes() {
for my $name (keys %{$db->{target}}) {
my ($group,$host,$test) = extract_grouphosttest($name);
if (!defined($group)) {
next;
}
my $hosttype;
# TODO - this needs to have a better way...
# hosttype is the non digit hostname prefix - thus
# "proxy-1" and "proxy-2" would both end up in the
# "proxy-" hosttype
if ($host =~ m/^(.*[^0-9])(\d+)$/) {
$hosttype = $1.'*';
} else {
next;
}
$db->{target}->{$name}->{_hosttype} = $hosttype;
$db->{hosttype}->{$hosttype}->{$name}++;
}
#for my $hosttype (keys %{$db->{hosttype}}) {
# if ((keys %{$db->{hosttype}->{$hosttype}})<2) {
# delete $db->{hosttype}->{$hosttype};
# }
#}
# a valid hosttype is:
# defined($db->{target}->{$name}->{hosttype}) &&
# defined($db->{hosttype}->{$hosttype})
}
sub maketree_grouphosttest($$) {
my ($name,$sequence) = @_;
my ($group,$host,$test) = extract_grouphosttest($name);
if (!defined($group)) {
# TODO cope with missing group/host/test parts.
# for now, just assume it is not a group/host/test
$db->{tree}->{other}->{$name} = $sequence;
return;
}
#my $hosttype = $db->{target}->{$name}->{_hosttype};
#if (!defined($db->{hosttype}->{$hosttype})) {
# $hosttype=undef;
#}
my $hosttype;
# TODO - this needs to have a better way...
# hosttype is the non digit hostname prefix - thus
......
}
# TODO - determine a better description for this tree leaf
my $testtreename = 'Gorganzola';
my $testtreename = 'Graph Type';
if (defined $hosttype) {
$db->{tree}->{group}->{$group}->{$hosttype}->{$host}->{$test}->{$name} = $sequence;
......
$db->{tree}->{group}->{ALL}->{$testtreename}->{$test}->{$host}->{$name} = $sequence;
$db->{tree}->{group}->{$group}->{$testtreename}->{$test}->{$host}->{$name} = $sequence;
}
}
sub maketree_cfgfile($$) {
......
# Look through the target database and create tree entries for each cfgfile
#
sub maketree() {
maketree_find_hosttypes();
for my $name (keys %{$db->{target}}) {
my $sequence = $db->{target}->{$name}->{_sequence};
maketree_cfgfile($name,$sequence);
......
sub emit_tree_one($$$) {
my ($parentnode,$path,$dir) = @_;
my $debug;
if (defined(param('debug'))) {
$debug = 'debug=1&';
} else {
$debug = '';
}
if (!ref($dir)) {
#print "FIXME !REF $dir\n";
print "insDoc($parentnode, gLnk(\"S\", \"FIXME !REF $dir\", \"?\"))\n";
......
}
my $node = 'n'.$node_next++;
print "$node = insFld($parentnode, gFld(\"$i\", \"?path=$path/$i\"))\n";
print "$node = insFld($parentnode, gFld(\"$i\", \"?".$debug."path=$path/$i\"))\n";
emit_tree_one("$node","$path/$i",$val);
}
}
......
}
if ($warnings && param('debug')) {
print "<pre>\n", "$warnings", "</pre>\n";
if (param('debug')) {
#print "<pre>\n", "$warnings", "</pre>\n";
print "<pre>\n";
print Dumper(\$db),"\n";
print "</pre>";
}
#print "<pre>\n";
#print Dumper(\$db),"\n";
#print "</pre>";

Also available in: Unified diff