From: Florian Forster Date: Fri, 31 Oct 2008 17:05:39 +0000 (+0100) Subject: contrib/collection3: Add the `format' parameter to the graph.cgi. X-Git-Tag: collectd-4.4.5~16 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6df04cbfbcf22db5e0550800b736f080182c43e0;p=collectd.git contrib/collection3: Add the `format' parameter to the graph.cgi. With this parameter one can specify the file format the graph is returned in, for example `format=SVG' for an SVG image. --- diff --git a/contrib/collection3/bin/graph.cgi b/contrib/collection3/bin/graph.cgi index 1524a660..7fe20871 100755 --- a/contrib/collection3/bin/graph.cgi +++ b/contrib/collection3/bin/graph.cgi @@ -20,6 +20,23 @@ our $Debug = param ('debug'); our $Begin = param ('begin'); our $End = param ('end'); our $GraphWidth = param ('width'); +our $OutputFormat = 'PNG'; +our $ContentType = 'image/png'; + +if (param ('format')) +{ + my $temp = param ('format') || ''; + $temp = uc ($temp); + + if ($temp =~ m/^(PNG|SVG|EPS|PDF)$/) + { + $OutputFormat = $temp; + + if ($OutputFormat eq 'SVG') { $ContentType = 'image/svg+xml'; } + elsif ($OutputFormat eq 'EPS') { $ContentType = 'image/eps'; } + elsif ($OutputFormat eq 'PDF') { $ContentType = 'application/pdf'; } + } +} if ($Debug) { @@ -141,7 +158,7 @@ flush_files ($files, addr => gc_get_scalar ('UnixSockAddr', undef), interval => gc_get_scalar ('Interval', 10)); -print STDOUT header (-Content_type => 'image/png', +print STDOUT header (-Content_type => $ContentType, -Last_Modified => epoch_to_rfc1123 ($obj->getLastModified ()), -Expires => epoch_to_rfc1123 ($expires)); @@ -173,7 +190,7 @@ else } $| = 1; - RRDs::graph ('-', '-a', 'PNG', '--width', $GraphWidth, @timesel, @$args); + RRDs::graph ('-', '-a', $OutputFormat, '--width', $GraphWidth, @timesel, @$args); if (my $err = RRDs::error ()) { print STDERR "RRDs::graph failed: $err\n";