Hi,

while evaluating collectd we use the collection.cgi script to display our rrd values. We encountered two problems I've made some simple patches for:

collection.cgi.generic_rrd.patch: when no type definition exists we generate a generic list for @rrd_args

collection.cgi.IE.patch: IE always wants to download content of type application/xhmtl+xml. We now check first if the browser accepts this type, else we fall back to text/html.

Hope you can use it.

--
Mayr Stefan
--- collection.cgi.orig 2010-04-06 20:58:50.000000000 +0200
+++ collection.cgi      2010-04-06 21:07:07.000000000 +0200
@@ -763,8 +763,10 @@ sub action_show_graph
     return $MetaGraphDefs->{$type}->($host, $plugin, $plugin_instance, $type, 
$types{$type});
   }
 
-  return if (!defined ($GraphDefs->{$type}));
-  @rrd_args = @{$GraphDefs->{$type}};
+  if (defined ($GraphDefs->{$type}))
+  {
+    @rrd_args = @{$GraphDefs->{$type}};
+  }
 
   $title = "$host/$plugin" . (defined ($plugin_instance) ? "-$plugin_instance" 
: '')
   . "/$type" . (defined ($type_instance) ? "-$type_instance" : '');
@@ -774,6 +776,38 @@ sub action_show_graph
     my $file = $DataDirs[$i] . "/$title.rrd";
     next if (!-f $file);
 
+    # generate generic rrdargs if no known definition exists (needs to be done 
per file)
+    if (not defined ($GraphDefs->{$type}))
+    {
+      my $Canvas = 'FFFFFF';
+      my @FullColors = ('0000FF', '00E000', 'FF0000',  'F0A000', '00A0FF', 
'A000FF');
+      my @HalfColors = ('B7B7F7', 'B7EFB7', 'F7B7B7', 'F3DFB7', 'B7DFF7', 
'DFB7F7');
+      my $ColorCount = 0;
+
+      my $rrd_info = RRDs::info($file); 
+      foreach my $info (keys %$rrd_info) {
+        if ($info =~ m/^ds\[(.*)\].type$/) 
+        {
+          my $value = $1;
+          push (@rrd_args, (
+            "DEF:avg$ColorCount={file}:$value:AVERAGE",
+            "DEF:min$ColorCount={file}:$value:MIN",
+            "DEF:max$ColorCount={file}:$value:MAX",
+            "AREA:max$ColorCount#".($HalfColors[$ColorCount % 6]),
+            "AREA:min$ColorCount#$Canvas",
+            "LINE1:avg$ColorCount#".($FullColors[$ColorCount % 6]).":".
+              ($value eq "value" ? "$type".(defined ($type_instance) ? 
"-$type_instance" : '') : "$value"),
+            "GPRINT:min$ColorCount:MIN:\%5.1lf\%s Min,",
+            "GPRINT:avg$ColorCount:AVERAGE:\%5.1lf\%s Avg,",
+            "GPRINT:max$ColorCount:MAX:\%5.1lf\%s Max,",
+            "GPRINT:avg$ColorCount:LAST:\%5.1lf\%s Last\\n"
+            )
+          );
+          $ColorCount++;
+        }
+      }
+    }
+
     $file =~ s/:/\\:/g;
     s/{file}/$file/ for (@rrd_args);
 
--- collection.cgi.orig 2010-04-06 21:07:57.000000000 +0200
+++ collection.cgi      2010-04-06 21:08:18.000000000 +0200
@@ -877,8 +877,16 @@ HTML
 
 sub print_header
 {
+  # hack for IE to accept XHTML with text/html MIME-Type
+  if ($ENV{'HTTP_ACCEPT'} !~ m/application\/xhtml+xml/)
+  {
+    print "Content-Type: text/html; charset=utf-8\r\n";
+  }
+  else
+  {
+    print "Content-Type: application/xhtml+xml; charset=utf-8\r\n";
+  }
   print <<HEAD;
-Content-Type: application/xhtml+xml; charset=utf-8
 Cache-Control: no-cache
 
 <?xml version="1.0" encoding="utf-8"?>
_______________________________________________
collectd mailing list
[email protected]
http://mailman.verplant.org/listinfo/collectd

Reply via email to