use CGI (':cgi');
use CGI::Carp ('fatalsToBrowser');
use URI::Escape ('uri_escape');
+use JSON ('objToJson');
use Data::Dumper;
use Collectd::Graph::Type ();
our $Debug = param ('debug') ? 1 : 0;
+our $ServerName = 'collect.noris.net';
gc_read_config ("$RealBin/../etc/collection.conf");
print "Content-Type: application/json; charset=utf-8\n\n";
}
-print "{\n";
-
+my $obj = {};
my @hosts = get_all_hosts ();
for (my $i = 0; $i < @hosts; $i++)
{
+ my $host_obj = {};
my $host = $hosts[$i];
my $files = get_files_for_host ($host);
my %graphs = ();
$graphs{$type}->addFiles ($file);
} # for (@$files)
- print qq( "$host":\n {\n);
+ #print qq( ") . objToJson ({ foo => 123 }) . qq(":\n {\n);
@graphs = keys %graphs;
for (my $j = 0; $j < @graphs; $j++)
{
my $type = $graphs[$j];
my $graphs_num = $graphs{$type}->getGraphsNum ();
- my @args = ();
- for (my $k = 0; $k < $graphs_num; $k++)
+ if (!defined ($host_obj->{$type}))
{
- my $args = $graphs{$type}->getGraphArgs ($k);
- my $url = 'http://' . $ENV{'SERVER_NAME'} . "/cgi-bin/graph.cgi?" . $args;
- push (@args, $url);
+ $host_obj->{$type} = [];
}
- print qq( "$type": [ )
- . join (', ', map { qq("$_") } (@args));
-
- if ($j == (@graphs - 1))
- {
- print qq( ]\n);
- }
- else
+ for (my $k = 0; $k < $graphs_num; $k++)
{
- print qq( ],\n);
+ my $args = $graphs{$type}->getGraphArgs ($k);
+ my $url = "http://$ServerName/cgi-bin/collection3/bin/graph.cgi?" . $args;
+ push (@{$host_obj->{$type}}, $url);
}
} # for (keys %graphs)
- if ($i == (@hosts - 1))
- {
- print qq( }\n);
- }
- else
- {
- print qq( },\n\n);
- }
+ $obj->{$host} = $host_obj;
} # for (my $i = 0; $i < @hosts; $i++)
-print "}\n";
+print STDOUT objToJson ($obj, { pretty => 1, indent => 2 });
exit (0);