Ticket #832: fix_munin832.patch

File fix_munin832.patch, 8.6 KB (added by Elbandi80, at 2010-11-30T15:43:10+01:00)

Backport to 1.4

  • master/_bin/munin-cgi-graph.in

    diff --git a/master/_bin/munin-cgi-graph.in b/master/_bin/munin-cgi-graph.in
    index 619ff4e..0584d90 100755
    a b my $IPC_KEY = 89340; 
    6262my $config = &munin_readconfig ($conffile); 
    6363 
    6464my $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 
    6966 
    7067&verify_parameters ($dom, $host, $serv, $scale); 
    7168 
    sem_setup(); 
    8178my $no_cache = defined($ENV{HTTP_CACHE_CONTROL}) && $ENV{HTTP_CACHE_CONTROL} =~ /no-cache/i; 
    8279 
    8380if ($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}); 
    8582    goto draw; 
    8683} 
    8784 
    if (defined $ENV{HTTP_IF_MODIFIED_SINCE} and 
    106103 
    107104draw: 
    108105 
    109     @stats = stat ($filename) unless @stats; 
     106    @stats = stat ($filename); # restat to be sure 
    110107 
    111108$last_modified = strftime ("%a, %d %b %Y %H:%M:%S %Z", localtime ($stats[9])) 
    112109    unless defined($last_modified);  
    $expires = strftime ("%a, %d %b %Y %H:%M:%S GMT", 
    115112                             gmtime($stats[9]+($period{$scale}-($stats[9]%$period{$scale})))) 
    116113    unless defined($expires); 
    117114 
     115print "Status: 200\n"; 
    118116print "Content-Type: image/png\n"; 
     117print "Content-Length: $stats[7]\n"; 
    119118print "Expires: ", strftime ("%a, %d %b %Y %H:%M:%S GMT", gmtime(time+($period{$scale}-($time%$period{$scale})))), "\n"; 
    120119print "Last-Modified: $last_modified\n"; 
    121120print "\n"; 
    sub graph { 
    167166    # This just serves the file, no file is made. 
    168167    my $filename = shift; 
    169168 
    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) 
    174172} 
    175173 
    176174 
    sub graph_usable { 
    288286 
    289287 
    290288sub draw_graph { 
     289    my $dom  = shift; 
    291290    my $host  = shift; 
    292291    my $serv  = shift; 
    293292    my $scale = shift; 
    sub draw_graph { 
    296295    # . needs to be legal in host names 
    297296    $host =~ s{[^\w_/"'\[\]\(\)\.+=-]}{_}g; $host =~ /^(.+)$/; $host = $1; #" 
    298297 
     298    my $fqn = "root/$dom/$host/$serv"; 
     299 
    299300    my @params = ($GRAPHER); 
    300301    push @params, @$scale; 
    301302    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 
    303305    push @params, "STDERR>&STDOUT"; 
    304306 
    305307    my $file = "/dev/null"; 
  • master/_bin/munin-fastcgi-graph.in

    diff --git a/master/_bin/munin-fastcgi-graph.in b/master/_bin/munin-fastcgi-graph.in
    index 979d641..6c6b3f2 100755
    a b sem_setup(); 
    7070# BEGIN FAST-CGI LOOP: 
    7171while (new CGI::Fast) { 
    7272    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 
    7774   
    7875    if (! &verify_parameters ($dom, $host, $serv, $scale)) { 
    7976        print "Status: 500\n"; 
    while (new CGI::Fast) { 
    9188    my $no_cache = defined($ENV{HTTP_CACHE_CONTROL}) && $ENV{HTTP_CACHE_CONTROL} =~ /no-cache/i; 
    9289  
    9390    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}); 
    9592        goto draw; 
    9693    } 
    9794 
    while (new CGI::Fast) { 
    115112    } 
    116113 
    117114  draw:   
    118     @stats           = stat ($filename) unless @stats; 
     115    @stats           = stat ($filename); # restat to be sure 
    119116    $last_modified   = strftime ("%a, %d %b %Y %H:%M:%S %Z", localtime ($stats[9])) unless defined($last_modified); 
    120117    # "Expires" has to use last modified time as base: 
    121118    $expires         = strftime ("%a, %d %b %Y %H:%M:%S GMT",  
    122119                                 gmtime($stats[9]+($period{$scale}-($stats[9]%$period{$scale})))) unless defined ($expires); 
    123120     
     121    print "Status: 200\n"; 
    124122    print "Content-Type: image/png\n"; 
     123    print "Content-Length: $stats[7]\n"; 
    125124    print "Expires: ", $expires, "\n"; 
    126125    print "Last-Modified: $last_modified\n"; 
    127126    print "\n"; 
    128      
     127 
    129128    &graph ($filename); 
    130129} 
    131130 
    sub graph { 
    169168    # Serve the graph contents.  This is not heavy, no semaphore. 
    170169    my $filename = shift; 
    171170 
    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) 
    176174} 
    177175 
    178176 
    sub graph_usable { 
    293291 
    294292sub draw_graph { 
    295293    # Draw a new graph - use semaphore to avoid too many concurrent munin-graph calls. 
     294    my $dom  = shift; 
    296295    my $host  = shift; 
    297296    my $serv  = shift; 
    298297    my $scale = shift; 
    sub draw_graph { 
    301300    # . needs to be legal in host names 
    302301    $host =~ s{[^\w_\/"'\[\]\(\)\.+=-]}{_}g; $host =~ /^(.+)$/; $host = $1; #" 
    303302 
     303    my $fqn = "root/$dom/$host/$serv"; 
     304 
    304305    my @params = ($GRAPHER); 
    305306    push @params, @$scale; 
    306307    push @params, "--skip-locking", "--skip-stats", "--nolazy"; 
    307308    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 
    309311    push @params, "STDERR>&STDOUT"; 
    310312 
    311313    my $file = "/dev/null"; 
  • master/lib/Munin/Master/GraphOld.pm

    diff --git a/master/lib/Munin/Master/GraphOld.pm b/master/lib/Munin/Master/GraphOld.pm
    index 201e567..4e5a2ee 100644
    a b my %sumtimes = ( # time => [ label, seconds-in-period ] 
    145145# Limit graphing to certain hosts and/or services 
    146146my @limit_hosts    = (); 
    147147my @limit_services = (); 
     148my $only_fqn; 
    148149 
    149150my $watermark = "Munin " . $Munin::Common::Defaults::MUNIN_VERSION; 
    150151 
    sub graph_startup { 
    175176                "lazy!"         => \$force_lazy, 
    176177                "host=s"        => \@limit_hosts, 
    177178                "service=s"     => \@limit_services, 
     179                "only-fqn=s"    => \$only_fqn, 
    178180                "config=s"      => \$conffile, 
    179181                "stdout!"       => \$stdout, 
    180182                "day!"          => \$draw{'day'}, 
    sub orig_to_cdef { 
    13391341    return $fieldname; 
    13401342} 
    13411343 
     1344sub 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 
    13421352 
    13431353sub skip_service { 
    13441354    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"; 
    13461360 
    13471361    # 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"; 
    13491364 
    13501365    # Always graph if --force is present 
    13511366    return 0 if $force_graphing; 
  • master/lib/Munin/Master/Utils.pm

    diff --git a/master/lib/Munin/Master/Utils.pm b/master/lib/Munin/Master/Utils.pm
    index efaf71e..54877f4 100644
    a b our (@ISA, @EXPORT); 
    5454           'munin_get_rrd_filename', 
    5555           'munin_get_node_name', 
    5656           'munin_get_parent_name', 
     57           'munin_get_node_fqn', 
    5758           'munin_get_node_loc', 
    5859           'munin_get_node', 
    5960           'munin_set_var_loc', 
    sub munin_get_node_name 
    517518    } 
    518519} 
    519520 
     521sub 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} 
    520539 
    521540sub munin_get_picture_loc { 
    522541    my $hash = shift;