Ticket #832: fix_munin832.patch
| File fix_munin832.patch, 8.6 kB (added by Elbandi80, 1 year ago) |
|---|
-
a/master/_bin/munin-cgi-graph.in
old new 62 62 my $config = &munin_readconfig ($conffile); 63 63 64 64 my $path = $ENV{PATH_INFO} || ""; 65 $path =~ s/^\///; 66 ($dom, $host, $serv) = split /\//, $path; 67 ($serv, $scale) = split /-/, $serv, 2; 68 $scale =~ s/\.png$//; 65 ($dom, $host, $serv, $scale) = $path =~ m#^/(.*)/([^/]+)/(\w+)-(\w+)\.png#; ## avoid bug in vim 69 66 70 67 &verify_parameters ($dom, $host, $serv, $scale); 71 68 … … 81 78 my $no_cache = defined($ENV{HTTP_CACHE_CONTROL}) && $ENV{HTTP_CACHE_CONTROL} =~ /no-cache/i; 82 79 83 80 if ($no_cache or (! &graph_usable($filename,$time) )) { 84 exit 0 unless draw_graph_or_complain($ host, $serv, $TIMES{$scale});81 exit 0 unless draw_graph_or_complain($dom, $host, $serv, $TIMES{$scale}); 85 82 goto draw; 86 83 } 87 84 … … 106 103 107 104 draw: 108 105 109 @stats = stat ($filename) unless @stats;106 @stats = stat ($filename); # restat to be sure 110 107 111 108 $last_modified = strftime ("%a, %d %b %Y %H:%M:%S %Z", localtime ($stats[9])) 112 109 unless defined($last_modified); … … 115 112 gmtime($stats[9]+($period{$scale}-($stats[9]%$period{$scale})))) 116 113 unless defined($expires); 117 114 115 print "Status: 200\n"; 118 116 print "Content-Type: image/png\n"; 117 print "Content-Length: $stats[7]\n"; 119 118 print "Expires: ", strftime ("%a, %d %b %Y %H:%M:%S GMT", gmtime(time+($period{$scale}-($time%$period{$scale})))), "\n"; 120 119 print "Last-Modified: $last_modified\n"; 121 120 print "\n"; … … 167 166 # This just serves the file, no file is made. 168 167 my $filename = shift; 169 168 170 open (my $GRAPH, '<', $filename) 171 or die "Warning: Could not open picture file \"$filename\" for reading: $!\n"; 172 print while (<$GRAPH>); 173 close ($GRAPH); 169 open (GRAPH_PNG_FILE, '<', $filename) or die "Warning: Could not open picture file \"$filename\" for reading: $!\n"; 170 print while (<GRAPH_PNG_FILE>); 171 close (GRAPH_PNG_FILE) 174 172 } 175 173 176 174 … … 288 286 289 287 290 288 sub draw_graph { 289 my $dom = shift; 291 290 my $host = shift; 292 291 my $serv = shift; 293 292 my $scale = shift; … … 296 295 # . needs to be legal in host names 297 296 $host =~ s{[^\w_/"'\[\]\(\)\.+=-]}{_}g; $host =~ /^(.+)$/; $host = $1; #" 298 297 298 my $fqn = "root/$dom/$host/$serv"; 299 299 300 my @params = ($GRAPHER); 300 301 push @params, @$scale; 301 302 push @params, "--skip-locking", "--skip-stats", "--nolazy", "--list-images"; 302 push @params, "--host", $host, "--service", $serv; 303 push @params, "--host", $host, "--only-fqn", $fqn; 304 push @params, "--no-fork"; # FastCgi forks for us 303 305 push @params, "STDERR>&STDOUT"; 304 306 305 307 my $file = "/dev/null"; -
a/master/_bin/munin-fastcgi-graph.in
old new 70 70 # BEGIN FAST-CGI LOOP: 71 71 while (new CGI::Fast) { 72 72 my $path = $ENV{PATH_INFO} || ""; 73 $path =~ s/^\///; 74 ($dom, $host, $serv) = split /\//, $path; 75 ($serv, $scale) = split /-/, $serv, 2; 76 $scale =~ s/\.png$//; 73 ($dom, $host, $serv, $scale) = $path =~ m#^/(.*)/([^/]+)/(\w+)-(\w+)\.png#; ## avoid bug in vim 77 74 78 75 if (! &verify_parameters ($dom, $host, $serv, $scale)) { 79 76 print "Status: 500\n"; … … 91 88 my $no_cache = defined($ENV{HTTP_CACHE_CONTROL}) && $ENV{HTTP_CACHE_CONTROL} =~ /no-cache/i; 92 89 93 90 if ($no_cache or (! &graph_usable ($filename, $time) )) { 94 next unless draw_graph_or_complain($ host, $serv, $TIMES{$scale});91 next unless draw_graph_or_complain($dom, $host, $serv, $TIMES{$scale}); 95 92 goto draw; 96 93 } 97 94 … … 115 112 } 116 113 117 114 draw: 118 @stats = stat ($filename) unless @stats;115 @stats = stat ($filename); # restat to be sure 119 116 $last_modified = strftime ("%a, %d %b %Y %H:%M:%S %Z", localtime ($stats[9])) unless defined($last_modified); 120 117 # "Expires" has to use last modified time as base: 121 118 $expires = strftime ("%a, %d %b %Y %H:%M:%S GMT", 122 119 gmtime($stats[9]+($period{$scale}-($stats[9]%$period{$scale})))) unless defined ($expires); 123 120 121 print "Status: 200\n"; 124 122 print "Content-Type: image/png\n"; 123 print "Content-Length: $stats[7]\n"; 125 124 print "Expires: ", $expires, "\n"; 126 125 print "Last-Modified: $last_modified\n"; 127 126 print "\n"; 128 127 129 128 &graph ($filename); 130 129 } 131 130 … … 169 168 # Serve the graph contents. This is not heavy, no semaphore. 170 169 my $filename = shift; 171 170 172 open (my $GRAPH, '<', $filename) 173 or die "Warning: Could not open picture file \"$filename\" for reading: $!\n"; 174 print while (<$GRAPH>); 175 close ($GRAPH); 171 open (GRAPH_PNG_FILE, '<', $filename) or die "Warning: Could not open picture file \"$filename\" for reading: $!\n"; 172 print while (<GRAPH_PNG_FILE>); 173 close (GRAPH_PNG_FILE) 176 174 } 177 175 178 176 … … 293 291 294 292 sub draw_graph { 295 293 # Draw a new graph - use semaphore to avoid too many concurrent munin-graph calls. 294 my $dom = shift; 296 295 my $host = shift; 297 296 my $serv = shift; 298 297 my $scale = shift; … … 301 300 # . needs to be legal in host names 302 301 $host =~ s{[^\w_\/"'\[\]\(\)\.+=-]}{_}g; $host =~ /^(.+)$/; $host = $1; #" 303 302 303 my $fqn = "root/$dom/$host/$serv"; 304 304 305 my @params = ($GRAPHER); 305 306 push @params, @$scale; 306 307 push @params, "--skip-locking", "--skip-stats", "--nolazy"; 307 308 push @params, "--list-images"; 308 push @params, "--host", $host, "--service", $serv; 309 push @params, "--host", $host, "--only-fqn", $fqn; 310 push @params, "--no-fork"; # FastCgi forks for us 309 311 push @params, "STDERR>&STDOUT"; 310 312 311 313 my $file = "/dev/null"; -
a/master/lib/Munin/Master/GraphOld.pm
old new 145 145 # Limit graphing to certain hosts and/or services 146 146 my @limit_hosts = (); 147 147 my @limit_services = (); 148 my $only_fqn; 148 149 149 150 my $watermark = "Munin " . $Munin::Common::Defaults::MUNIN_VERSION; 150 151 … … 175 176 "lazy!" => \$force_lazy, 176 177 "host=s" => \@limit_hosts, 177 178 "service=s" => \@limit_services, 179 "only-fqn=s" => \$only_fqn, 178 180 "config=s" => \$conffile, 179 181 "stdout!" => \$stdout, 180 182 "day!" => \$draw{'day'}, … … 1339 1341 return $fieldname; 1340 1342 } 1341 1343 1344 sub ends_with { 1345 my ($src, $searched) = @_; 1346 DEBUG "[DEBUG] ends_with($src, $searched)\n"; 1347 1348 my $is_ending = (substr($src, - length($searched)) eq $searched); 1349 return $is_ending; 1350 } 1351 1342 1352 1343 1353 sub skip_service { 1344 1354 my $service = shift; 1345 my $sname = munin_get_node_name($service); 1355 my $fqn = munin_get_node_fqn($service); 1356 1357 # Skip if we've limited services with the omnipotent cli option only-fqn 1358 return 1 if ($only_fqn and ! ends_with($fqn, $only_fqn)); 1359 DEBUG "[DEBUG] $fqn is in ($only_fqn)\n"; 1346 1360 1347 1361 # Skip if we've limited services with cli options 1348 return 1 if (@limit_services and !grep /^$sname$/, @limit_services); 1362 return 1 if (@limit_services and ! (grep { ends_with($fqn, $_) } @limit_services)); 1363 DEBUG "[DEBUG] $fqn is in (" . join(",", @limit_services) . ")\n"; 1349 1364 1350 1365 # Always graph if --force is present 1351 1366 return 0 if $force_graphing; -
a/master/lib/Munin/Master/Utils.pm
old new 54 54 'munin_get_rrd_filename', 55 55 'munin_get_node_name', 56 56 'munin_get_parent_name', 57 'munin_get_node_fqn', 57 58 'munin_get_node_loc', 58 59 'munin_get_node', 59 60 'munin_set_var_loc', … … 517 518 } 518 519 } 519 520 521 sub munin_get_node_fqn 522 { 523 my $hash = shift; 524 525 if (ref ($hash) eq "HASH") { 526 my $fqn = ""; 527 if (defined $hash->{'#%#name'}) { 528 $fqn = $hash->{'#%#name'}; 529 } 530 if (defined $hash->{'#%#parent'}) { 531 # Recursively prepend the parent, concatenation with / 532 $fqn = munin_get_node_fqn ($hash->{'#%#parent'}) . "/" . $fqn; 533 } 534 return $fqn; 535 } else { 536 return; 537 } 538 } 520 539 521 540 sub munin_get_picture_loc { 522 541 my $hash = shift;
