]> git.zerfleddert.de Git - upsgraph/blobdiff - upsgraph.pl
Fix creation of new rrd files: Trailing space seems to be harmful
[upsgraph] / upsgraph.pl
index 10f622b7f643dd04ec4c6f458ace8d6069457c5d..3077e2357abaa0c458b56e1428a4b783782335c8 100755 (executable)
@@ -11,6 +11,7 @@ if ((@ARGV != 1) && (@ARGV != 2)) {
 
 use Net::SNMP;
 use IO::Socket::INET;
+use IO::Select;
 use RRDs;
 use File::Copy;
 use Data::Dumper;
@@ -78,7 +79,7 @@ sub rrdcreate(@) {
 
        push @cmd, "DS:${field}:GAUGE:600:" .
                $vars->{$field}->{'min'} . ":" .
-               $vars->{$field}->{'max'} . " ";
+               $vars->{$field}->{'max'};
 
        push @cmd, "RRA:AVERAGE:0.5:1:${keep}";
 
@@ -124,7 +125,13 @@ sub fetch_tcp(@) {
 
        return undef if (!$sock);
 
-       chomp(my $value = <$sock>);
+       my $select = IO::Select->new($sock);
+
+       my $value = undef;
+
+       if ($select->can_read(1)) {
+               chomp($value) if (sysread($sock, $value, 4096) > 0);
+       }
 
        close($sock);
 
@@ -150,11 +157,19 @@ sub fetch_tcp_multi(@) {
 
        return undef if (!$sock);
 
-       while(<$sock>) {
-               chomp;
-               (my $key, my $value) = split(/${delimiter}/, $_);
-               $value=~ s/\s//g;
-               $values{$key} = $value;
+       my $select = IO::Select->new($sock);
+
+       while($select->can_read(1)) {
+               if (sysread($sock, my $buf, 16384) > 0) {
+                       $buf=~s/\r//g;
+                       foreach my $line (split(/\n/, $buf)) {
+                               (my $key, my $value) = split(/${delimiter}/, $line);
+                               $value=~ s/\s//g;
+                               $values{$key} = $value;
+                       }
+               } else {
+                       last;
+               }
        }
 
        close($sock);
@@ -428,7 +443,7 @@ while(1) {
                        print HTML "<a href=\"${hostname}.${var}.html\"><img src=\"${hostname}.${var}.png\" width=\"${width}\" height=\"${height}\" border=\"0\"></a><br>\n";
 
                        open (HTML2, ">${outdir}/${hostname}.${var}.html.new");
-                       print HTML2 '<html><head><meta http-equiv="refresh" content="60"/><meta http-equiv="cache-control" content="no-cache"/><meta http-equiv="pragma" content="no-cache"/><meta http_equiv="expires" content="Sat, 26 Jul 1997 05:00:00 GMT"/><title>' . $vars->{$var}->{'name'} . '</title></head>';
+                       print HTML2 '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="refresh" content="60"/><meta http-equiv="cache-control" content="no-cache"/><meta http-equiv="pragma" content="no-cache"/><meta http_equiv="expires" content="Sat, 26 Jul 1997 05:00:00 GMT"/><title>' . $vars->{$var}->{'name'} . '</title></head>';
                        print HTML2 '<body bgcolor="#ffffff">';
 
                        push @graphdef, "VDEF:min=${var},MINIMUM";
@@ -458,7 +473,7 @@ while(1) {
                                }
                        }
 
-                       print HTML2 "<img src=\"${hostname}.${var}.long.png\" width=\"${width}\" height=\"${height}\"><br>";
+                       print HTML2 "<img src=\"${hostname}.${var}.long.png\" width=\"${width}\" height=\"${height}\"><br>\n";
 
                        $mtime=(stat("${outdir}/${hostname}.${var}.week.png.work"))[9];
                        ($averages, $width, $height) =
@@ -475,7 +490,7 @@ while(1) {
                                }
                        }
 
-                       print HTML2 "<img src=\"${hostname}.${var}.week.png\" width=\"${width}\" height=\"${height}\"><br>";
+                       print HTML2 "<img src=\"${hostname}.${var}.week.png\" width=\"${width}\" height=\"${height}\"><br>\n";
 
                        $mtime=(stat("${outdir}/${hostname}.${var}.year.png.work"))[9];
                        ($averages, $width, $height) =
@@ -492,7 +507,7 @@ while(1) {
                                }
                        }
 
-                       print HTML2 "<img src=\"${hostname}.${var}.year.png\" width=\"${width}\" height=\"${height}\"><br>";
+                       print HTML2 "<img src=\"${hostname}.${var}.year.png\" width=\"${width}\" height=\"${height}\"><br>\n";
 
                        print HTML2 "</body></html>\n";
                        close(HTML2);
Impressum, Datenschutz