Revision ec551d65
Added by Hamish Coleman over 15 years ago
- ID ec551d658026090abeb8f9f7bc183cf50ff27317
indexmrtg.cgi | ||
---|---|---|
}
|
||
}
|
||
|
||
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;
|
||
}
|
||
|
||
# a valid hosttype both:
|
||
# defined($db->{graph}->{$name}->{hosttype}) &&
|
||
# defined($db->{hosttype}->{$hosttype})
|
||
my $hosttype = $db->{graph}{$name}{tag}{hosttype};
|
||
if (defined($hosttype) && !defined($db->{hosttype}->{$hosttype})) {
|
||
$hosttype=undef;
|
||
}
|
||
|
||
# TODO - determine a better description for this tree leaf
|
||
my $testtreename = 'Graph Type';
|
||
|
||
if (defined $hosttype) {
|
||
$db->{tree}->{group}->{$group}->{$hosttype}->{$host}->{$test}->{$name} = $sequence;
|
||
$db->{tree}->{group}->{$group}->{$hosttype}->{$testtreename}->{$test}->{$name} = $sequence;
|
||
$db->{tree}->{group}->{ALL}->{$hosttype}->{$host}->{$test}->{$name} = $sequence;
|
||
$db->{tree}->{group}->{ALL}->{$testtreename}->{$test}->{$hosttype}->{$host}->{$name} = $sequence;
|
||
$db->{tree}->{group}->{$group}->{$testtreename}->{$test}->{$hosttype}->{$host}->{$name} = $sequence;
|
||
} else {
|
||
$db->{tree}->{group}->{$group}->{$host}->{$test}->{$name} = $sequence;
|
||
$db->{tree}->{group}->{ALL}->{$host}->{$test}->{$name} = $sequence;
|
||
$db->{tree}->{group}->{ALL}->{$testtreename}->{$test}->{$host}->{$name} = $sequence;
|
||
$db->{tree}->{group}->{$group}->{$testtreename}->{$test}->{$host}->{$name} = $sequence;
|
||
}
|
||
}
|
||
|
||
sub maketree_definedby($$) {
|
||
my ($name,$sequence) = @_;
|
||
|
||
# config files
|
||
my $definedby = $db->{graph}->{$name}->{definedby};
|
||
|
||
my @srcpath = split /\//,$definedby;
|
||
|
||
shift @srcpath; # remove initial slash
|
||
|
||
unshift @srcpath,"config"; # ensure that the config node exists
|
||
my $node = $db->{tree};
|
||
|
||
while (@srcpath ) {
|
||
if (!defined $node->{$srcpath[0]}) {
|
||
$node->{$srcpath[0]} = {};
|
||
}
|
||
$node = $node->{$srcpath[0]};
|
||
shift @srcpath;
|
||
}
|
||
|
||
# assign a name name and sequence to the final node
|
||
$node->{$name} = $sequence;
|
||
}
|
||
|
||
# Look through the name database and create tree entries for each cfgfile
|
||
#
|
||
sub maketree() {
|
||
|
||
for my $name (keys %{$db->{graph}}) {
|
||
my $sequence = $db->{graph}->{$name}->{sequence};
|
||
maketree_definedby($name,$sequence);
|
||
maketree_grouphosttest($name,$sequence);
|
||
# TODO - parse the Target setting and create trees
|
||
# TODO - parse magic comments and create trees here
|
||
}
|
||
|
||
# TODO - look for nodes that have only one child and that child is
|
||
# childless and prune the child
|
||
}
|
||
|
||
sub maketags() {
|
||
maketree_find_hosttypes();
|
||
|
||
... | ... | |
|
||
my $this_host = hostname;
|
||
|
||
print header,
|
||
start_html(-TITLE=>"$this_host indexmrtg (V$VERSION)"),
|
||
"\n";
|
||
print "Content-Type: text/json; charset=ISO-8859-1\n";
|
||
|
||
config_load_file(@config_files);
|
||
config_read_filesystem();
|
||
maketags();
|
||
#maketree();
|
||
|
||
# Time the next update to occur a little while after the next interval completes
|
||
my $interval = 300; # 5 min update interval
|
||
... | ... | |
$refresh = $interval if $refresh <= $guardband;
|
||
my $expires = gmtime (time + $interval * 2 + $guardband);
|
||
|
||
print
|
||
"<meta http-equiv=\"expires\" content=\"$expires GMT\">\n",
|
||
"<meta http-equiv=\"refresh\" content=$refresh>\n";
|
||
|
||
print end_html;
|
||
$db->{global}{expires} = "$expires GMT";
|
||
$db->{global}{refresh} = $refresh;
|
||
|
||
print "\n",JSON->new->utf8(1)->pretty(1)->canonical(1)->encode($db),"\n";
|
||
|
||
if (param('debug')) {
|
||
print "\n",Dumper(\$db),"\n";
|
||
}
|
||
|
||
print "\n",JSON->new->utf8(1)->pretty(1)->canonical(1)->encode($db),"\n";
|
||
|
Also available in: Unified diff
Remove unused code, update output to be purely json