Changeset 1216

Show
Ignore:
Timestamp:
10/30/06 14:52:06 (5 years ago)
Author:
janl
Message:
  • muin-html: Do not generate height/width attributes when in cgi mode
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/server/munin-html.in

    r1215 r1216  
    11#!@@PERL@@ 
     2# -*- perl -*- 
    23# 
    34# Copyright (C) 2002-2006 Jimmy Olsen, Audun Ytterdal 
     
    4142 
    4243# Get options 
    43 $do_usage=1  unless  
     44$do_usage=1  unless 
    4445GetOptions ( "host=s"       => \(), 
    4546             "force-root!"  => \$force_root, 
     
    167168my $timestamp = strftime("%Y-%m-%d T %T", localtime); 
    168169for my $domain (@domainorder) { 
    169     logger("processing domain: $domain"); 
    170     my %domain; 
    171     $domain{domain}=$domain; 
    172     my @nodes; 
    173     my %comparisons; 
    174     my @nodeorder = (); 
    175     if ($config->{domain}->{$domain}->{node_order}) { 
    176         @nodeorder = split /\s+/, $config->{domain}->{$domain}->{node_order}; 
    177     }  
    178     foreach my $n (sort (keys %{$config->{domain}->{$domain}->{node}})) 
    179     { 
    180         unless (grep (/^$n$/, @nodeorder)) 
    181         { 
    182             push @nodeorder, $n; 
    183         } 
    184     } 
    185     for my $node (@nodeorder) { 
    186         logger("processing node: $node"); 
    187         my %node; 
    188         $node{node}=$node; 
    189         $node{url}="$domain/$node.html"; 
    190         my @services; 
    191         my @categories; 
    192         my %categories; 
    193         my %tmp_cats; 
    194         my @serviceorder; 
    195         if ($config->{domain}->{$domain}->{node}->{$node}->{service_order}) { 
    196             @serviceorder = split /\s+/, $config->{domain}->{$domain}->{node}->{$node}->{service_order}; 
     170  logger("processing domain: $domain"); 
     171  my %domain; 
     172  $domain{domain}=$domain; 
     173  my @nodes; 
     174  my %comparisons; 
     175  my @nodeorder = (); 
     176  if ($config->{domain}->{$domain}->{node_order}) { 
     177    @nodeorder = split /\s+/, $config->{domain}->{$domain}->{node_order}; 
     178  } 
     179  foreach my $n (sort (keys %{$config->{domain}->{$domain}->{node}})) { 
     180    unless (grep (/^$n$/, @nodeorder)) { 
     181      push @nodeorder, $n; 
     182    } 
     183  } 
     184  for my $node (@nodeorder) { 
     185    logger("processing node: $node"); 
     186    my %node; 
     187    $node{node}=$node; 
     188    $node{url}="$domain/$node.html"; 
     189    my @services; 
     190    my @categories; 
     191    my %categories; 
     192    my %tmp_cats; 
     193    my @serviceorder; 
     194    if ($config->{domain}->{$domain}->{node}->{$node}->{service_order}) { 
     195      @serviceorder = split /\s+/, 
     196        $config->{domain}->{$domain}->{node}->{$node}->{service_order}; 
     197    } else { 
     198      @serviceorder = sort 
     199        keys %{$config->{domain}->{$domain}->{node}->{$node}->{client}}; 
     200    } 
     201 
     202    for my $service (@serviceorder) { 
     203      logger("processing service: $service"); 
     204      next unless 
     205        defined($config->{domain}->{$domain}->{node}->{$node}->{client}->{$service} ) 
     206        &&  $config->{domain}->{$domain}->{node}->{$node}->{client}->{$service} ne ""; 
     207 
     208      next unless 
     209        munin_get_bool ($config, "graph", 1, $domain, $node, $service); 
     210 
     211      my @service; 
     212      my %service; 
     213      my $fieldnum = 0; 
     214      my @graph_info; 
     215      my @field_info; 
     216      $service{service}=$service; 
     217      $service{label}= 
     218        $config->{domain}->{$domain}->{node}->{$node}->{client}-> 
     219          {$service}->{graph_title}; 
     220 
     221      my $method = &munin_get ($config, "graph_strategy", "cron"); 
     222      if ($method eq "cgi") { 
     223        $service{imgday}=$config->{'cgiurl_graph'}. 
     224          "/$domain/$node/$service-day.png"; 
     225        $service{imgweek}=$config->{'cgiurl_graph'}. 
     226          "/$domain/$node/$service-week.png"; 
     227        $service{imgmonth}=$config->{'cgiurl_graph'}. 
     228          "/$domain/$node/$service-month.png"; 
     229        $service{imgyear}=$config->{'cgiurl_graph'}. 
     230          "/$domain/$node/$service-year.png"; 
     231 
     232        if (&munin_get_bool_val($config->{domain}->{$domain}-> 
     233                                {node}->{$node}-> 
     234                                {client}->{$service}->{"graph_sums"}, 0)) { 
     235          $service{imgweeksum} = 
     236            $config->{'cgiurl_graph'}."/$domain/$node/$service-week-sum.png"; 
     237          $service{imgyearsum} = 
     238            $config->{'cgiurl_graph'}."/$domain/$node/$service-year-sum.png"; 
     239        } 
     240 
     241# There is a disturbance in the force here, the sizes are off. 
     242#       if (my ($w, $h) = 
     243#           &calculate_png_size ($config, $domain, $node, $service)) { 
     244#         for my $scale (@times) { 
     245#           $service{"img".$scale."width"} = $w; 
     246#           $service{"img".$scale."height"} = $h; 
     247#         } 
     248#         if (&munin_get_bool_val($config->{domain}->{$domain}-> 
     249#                                 {node}->{$node}-> 
     250#                                 {client}->{$service}->{"graph_sums"}, 0)) { 
     251#           for my $scale (["week", "year"]) { 
     252#             $service{"img".$scale."sumwidth"} = $w; 
     253#             $service{"img".$scale."sumheight"} = $h; 
     254#           } 
     255#         } 
     256#       } 
     257      } else { 
     258        # graph strategy cron 
     259        $service{imgday}="$node-$service-day.png"; 
     260        $service{imgweek}="$node-$service-week.png"; 
     261        $service{imgmonth}="$node-$service-month.png"; 
     262        $service{imgyear}="$node-$service-year.png"; 
     263 
     264        for my $scale (@times) { 
     265          if (my ($w, $h) = 
     266              &get_png_size(&munin_get_picture_filename($config, $domain, 
     267                                                        $node, $service, 
     268                                                        $scale))) { 
     269            $service{"img".$scale."width"} = $w; 
     270            $service{"img".$scale."height"} = $h; 
     271          } 
     272        } 
     273 
     274        if (&munin_get_bool_val ($config->{domain}->{$domain}-> 
     275                                 {node}->{$node}->{client}-> 
     276                                 {$service}->{"graph_sums"}, 0)) { 
     277          $service{imgweeksum} = "$node-$service-week-sum.png"; 
     278          $service{imgyearsum} = "$node-$service-year-sum.png"; 
     279          for my $scale (["week", "year"]) { 
     280            if (my ($w, $h) = 
     281                &get_png_size (&munin_get_picture_filename($config,$domain, 
     282                                                           $node, $service, 
     283                                                           $scale, 1))) { 
     284              $service{"img".$scale."sumwidth"} = $w; 
     285              $service{"img".$scale."sumheight"} = $h; 
     286            } 
     287          } 
     288        } 
     289      } 
     290      $service{url}="$node-$service.html"; 
     291      $service{domain}="$domain"; 
     292      $service{node}=$node; 
     293      $service{category}= lc( $config->{domain}->{$domain}-> 
     294                              {node}->{$node}->{client}-> 
     295                              {$service}->{graph_category} || "other" ); 
     296 
     297      # Do "help" section 
     298      if (defined($config->{domain}->{$domain}-> 
     299                  {node}->{$node}-> 
     300                  {client}->{$service}->{graph_info})) { 
     301        my %graph_info; 
     302 
     303        $graph_info{info} = $config->{domain}->{$domain}-> 
     304          {node}->{$node}->{client}->{$service}->{graph_info}; 
     305 
     306        push @{$service{graphinfo}}, \%graph_info; 
     307      } 
     308 
     309      $service{fieldlist} .= "<tr><th align='left' valign='top'>Field</th><th align='left' valign='top'>Type</th><th align='left' valign='top'>Warn</th><th align='left' valign='top'>Crit</th><th></tr>"; 
     310      # foreach my $field (keys %{$config->{domain}->{$domain}->{node}->{$node}->{client}->{$service}}) 
     311      foreach my $f (@{&munin_get_field_order ($config->{domain}->{$domain}->{node}->{$node}, $config, $domain, $node, $service)}) { 
     312        $f =~ s/=(.*)$//; 
     313        my $path = $1; 
     314        next unless &munin_draw_field ($config->{domain}->{$domain}-> 
     315                                       {node}->{$node}, $service, $f); 
     316 
     317        print "DEBUG: single_value: Checking field \"$f\" ($path).\n" 
     318          if $DEBUG; 
     319 
     320        if (defined $path) { 
     321          # HUH? Get the filename and then forget? Some side effect here? 
     322          munin_get_rrd_filename ($config->{domain}->{$domain}-> 
     323                                  {node}->{$node}, $config, $domain, 
     324                                  $node, $service, $f, $path); 
     325        } 
     326 
     327        my %field_info; 
     328        $fieldnum++; 
     329 
     330        $field_info{'hr'}    = 1 unless ($fieldnum % 3); 
     331        $field_info{'field'} = $f; 
     332        $field_info{'label'} = $config->{domain}->{$domain}-> 
     333          {node}->{$node}->{client}->{$service}->{$f.".label"} || $f; 
     334 
     335        $field_info{'type'}  = lc( $config->{domain}->{$domain}-> 
     336                                   {node}->{$node}->{client}->{$service}-> 
     337                                   {$f.".type"} || "GAUGE" ); 
     338 
     339        $field_info{'warn'}  = $config->{domain}->{$domain}-> 
     340          {node}->{$node}->{client}->{$service}->{$f.".warning"} || "None"; 
     341        $field_info{'crit'}  = $config->{domain}->{$domain}-> 
     342          {node}->{$node}->{client}->{$service}->{$f.".critical"} || "None"; 
     343        $field_info{'info'}  = $config->{domain}->{$domain}-> 
     344          {node}->{$node}->{client}->{$service}->{$f.".info"} || ""; 
     345 
     346        my $state = &munin_field_status ($config, $limits, $domain, 
     347                                         $node, $service, $f, 1); 
     348 
     349        if (defined $state) { 
     350          $field_info{'state_warning'}  = 1 if $state eq "warning"; 
     351          $field_info{'state_critical'} = 1 if $state eq "critical"; 
     352          $field_info{'state_unknown'}  = 1 if $state eq "unknown"; 
     353        } 
     354        push @{$service{fieldinfo}}, \%field_info; 
     355      } 
     356 
     357      { 
     358        my $state = &munin_service_status ($config, $limits, $domain, 
     359                                           $node, $service, 1); 
     360        if (defined $state) { 
     361          $service{'state_warning'}  = 1 if $state eq "warning"; 
     362          $service{'state_critical'} = 1 if $state eq "critical"; 
     363          $service{'state_unknown'}  = 1 if $state eq "unknown"; 
     364        } 
     365      } 
     366 
     367      push @services, \%service; 
     368      push @service, \%service; 
     369      push @{$tmp_cats{$service{'category'}}}, \%service; 
     370      $servicetemplate->param(SERVICES => \@service, 
     371                              SERVICE => $service, 
     372                              NODE => $node, 
     373                              DOMAIN => $domain,  
     374                              DOMAINS => \@domainlist,  
     375                              TIMESTAMP => $timestamp); 
     376      open (FILE, ">$config->{htmldir}/$domain/$node-$service.html") or 
     377        die "Cannot open $config->{htmldir}/$domain/$node-$service.html"; 
     378      print FILE $servicetemplate->output; 
     379      close FILE; 
     380    } 
     381    foreach my $key (keys %tmp_cats) { 
     382      next if $key eq "other"; 
     383      my %tmp; 
     384      my $state = &munin_category_status ($config, $limits, $domain, 
     385                                          $node, $key, 1); 
     386      print "DEBUG: Pushing category \"$node\" -> \"$key\"...\n" if $DEBUG; 
     387      if (defined $state) { 
     388        $tmp{'state_warning'}  = 1 if $state eq "warning"; 
     389        $tmp{'state_critical'} = 1 if $state eq "critical"; 
     390        $tmp{'state_unknown'}  = 1 if $state eq "unknown"; 
     391      } 
     392      $tmp{name} = ucfirst $key; 
     393      $tmp{services} = \@{$tmp_cats{$key}}; 
     394      $tmp{node} = $node; 
     395      $tmp{domain} = $domain; 
     396      $categories{ucfirst $key} = \%tmp; 
     397      $comparisons{$key}{$node} = \%tmp; 
     398    } 
     399    if (defined $tmp_cats{'other'}) { 
     400      my $key = 'other'; 
     401      my %tmp; 
     402      my $state = &munin_category_status ($config, $limits, $domain, 
     403                                          $node, $key, 1); 
     404      print "DEBUG: Pushing category \"$node\" -> \"$key\"...\n" if $DEBUG; 
     405      if (defined $state) { 
     406        $tmp{'state_warning'}  = 1 if $state eq "warning"; 
     407        $tmp{'state_critical'} = 1 if $state eq "critical"; 
     408        $tmp{'state_unknown'}  = 1 if $state eq "unknown"; 
     409      } 
     410      $tmp{name} = ucfirst $key; 
     411      $tmp{services} = \@{$tmp_cats{$key}}; 
     412      $tmp{node} = $node; 
     413      $tmp{domain} = $domain; 
     414      $categories{ucfirst $key} = \%tmp; 
     415      $comparisons{'other'}{$node} = \%tmp; 
     416    } 
     417    # Handle category_order 
     418    @categories = (); 
     419    if ($config->{domain}->{$domain}->{node}->{$node}->{category_order}) { 
     420      foreach my $cat (split /\s+/, 
     421                       $config->{domain}->{$domain}-> 
     422                       {node}->{$node}->{category_order}) { 
     423        push @categories, $categories{ucfirst $cat}; 
     424      } 
     425      foreach my $cat (sort keys %categories) { 
     426        push @categories, $categories{$cat} 
     427          unless (grep { $_->{name} eq $cat } @categories); 
     428      } 
     429    } else { 
     430      @categories = map { $categories{$_} } sort keys %categories; 
     431    } 
     432    $nodetemplate->param(SERVICES => \@services, 
     433                         NODE => $node, 
     434                         DOMAIN => $domain, 
     435                         DOMAINS => \@domainlist, 
     436                         TIMESTAMP => $timestamp, 
     437                         CATEGORIES => \@categories); 
     438    open (FILE, ">$config->{htmldir}/$domain/$node.html") or 
     439      die "Cannot open $config->{htmldir}/$domain/$node.html"; 
     440    print FILE $nodetemplate->output; 
     441    close FILE; 
     442    $node{services} = \@services; 
     443    $node{categories} = \@categories; 
     444    $node{domain} = $domain; 
     445    push @nodes,\%node; 
     446 
     447  } 
     448  $domaintemplate->param(NODES => \@nodes, 
     449                         DOMAIN => $domain,  
     450                         DOMAINS => \@domainlist,  
     451                         COMPARE => (&munin_get_bool ($config, "compare", 1, 
     452                                                      $domain) 
     453                                     and @nodeorder > 1), 
     454                         TIMESTAMP => $timestamp); 
     455  open (FILE, ">$config->{htmldir}/$domain/index.html") or 
     456    die "Cannot open $config->{htmldir}/index.html"; 
     457  print FILE $domaintemplate->output; 
     458  close FILE; 
     459 
     460  $domain{nodes} = \@nodes; 
     461  $domain{domain} = $domain; 
     462  $domain{compare} = (&munin_get_bool ($config, "compare", 1, $domain)  
     463                      and @nodeorder > 1); 
     464 
     465  my @cats = (); 
     466  foreach my $key (sort keys %comparisons) { 
     467    my %cat; 
     468    my %servlist; 
     469    my $nodewidth = 0; 
     470 
     471    foreach my $node (sort keys %{$comparisons{$key}}) { 
     472      foreach my $serv (@{$comparisons{$key}{$node}->{services}}) { 
     473        $servlist{$serv->{service}}{$node} = $serv; 
     474        $nodewidth = $serv->{imgdaywidth} 
     475          if (defined $serv->{imgdaywidth} 
     476              and $serv->{imgdaywidth} > $nodewidth); 
     477      } 
     478    } 
     479    foreach my $sname (sort keys %servlist) { 
     480      my %s; 
     481      foreach my $node (@nodeorder) { 
     482        if (defined $servlist{$sname}{$node}) { 
     483          $servlist{$sname}{$node}->{width} = $nodewidth; 
     484          push (@{$s{nodes}}, $servlist{$sname}{$node}); 
    197485        } else { 
    198             @serviceorder = sort (keys %{$config->{domain}->{$domain}->{node}->{$node}->{client}}); 
    199         } 
    200          
    201         for my $service (@serviceorder) { 
    202             logger("processing service: $service"); 
    203             next unless defined( $config->{domain}->{$domain}->{node}->{$node}->{client}->{$service} ) 
    204                             &&  $config->{domain}->{$domain}->{node}->{$node}->{client}->{$service} ne ""; 
    205             next unless (munin_get_bool ($config, "graph", 1, $domain, $node, $service)); 
    206             my @service; 
    207             my %service; 
    208             my $fieldnum = 0; 
    209             my @graph_info; 
    210             my @field_info; 
    211             $service{service}=$service; 
    212             $service{label}=$config->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{graph_title}; 
    213                  
    214             my $method = &munin_get ($config, "graph_strategy", "cron"); 
    215             if ($method eq "cgi") 
    216             { 
    217                 $service{imgday}=$config->{'cgiurl_graph'}."/$domain/$node/$service-day.png"; 
    218                 $service{imgweek}=$config->{'cgiurl_graph'}."/$domain/$node/$service-week.png"; 
    219                 $service{imgmonth}=$config->{'cgiurl_graph'}."/$domain/$node/$service-month.png"; 
    220                 $service{imgyear}=$config->{'cgiurl_graph'}."/$domain/$node/$service-year.png"; 
    221  
    222                 if (&munin_get_bool_val ($config->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{"graph_sums"}, 0)) 
    223                 { 
    224                     $service{imgweeksum} = $config->{'cgiurl_graph'}."/$domain/$node/$service-week-sum.png"; 
    225                     $service{imgyearsum} = $config->{'cgiurl_graph'}."/$domain/$node/$service-year-sum.png"; 
    226                 } 
    227          
    228                 if (my ($w, $h) = &calculate_png_size ($config, $domain, $node, $service)) 
    229                 { 
    230                     for my $scale (@times) 
    231                     { 
    232                         $service{"img".$scale."width"} = $w; 
    233                         $service{"img".$scale."height"} = $h; 
    234                     } 
    235                     if (&munin_get_bool_val ($config->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{"graph_sums"}, 0)) 
    236                     { 
    237                         for my $scale (["week", "year"]) 
    238                         { 
    239                             $service{"img".$scale."sumwidth"} = $w; 
    240                             $service{"img".$scale."sumheight"} = $h; 
    241                         } 
    242                     } 
    243                 } 
    244             } 
    245             else 
    246             { 
    247                     $service{imgday}="$node-$service-day.png"; 
    248                     $service{imgweek}="$node-$service-week.png"; 
    249                     $service{imgmonth}="$node-$service-month.png"; 
    250                     $service{imgyear}="$node-$service-year.png"; 
    251  
    252                     for my $scale (@times) 
    253                     { 
    254                             if (my ($w, $h) = &get_png_size (&munin_get_picture_filename ($config, $domain, $node, $service, $scale))) 
    255                             { 
    256                                     $service{"img".$scale."width"} = $w; 
    257                                     $service{"img".$scale."height"} = $h; 
    258                             } 
    259                     } 
    260  
    261                     if (&munin_get_bool_val ($config->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{"graph_sums"}, 0)) 
    262                     { 
    263                         $service{imgweeksum} = "$node-$service-week-sum.png"; 
    264                         $service{imgyearsum} = "$node-$service-year-sum.png"; 
    265                         for my $scale (["week", "year"]) 
    266                         { 
    267                                 if (my ($w, $h) = &get_png_size (&munin_get_picture_filename ($config, $domain, $node, $service, $scale, 1))) 
    268                                 { 
    269                                         $service{"img".$scale."sumwidth"} = $w; 
    270                                         $service{"img".$scale."sumheight"} = $h; 
    271                                 } 
    272                         } 
    273                     } 
    274             } 
    275             $service{url}="$node-$service.html"; 
    276             $service{domain}="$domain"; 
    277             $service{node}=$node; 
    278             $service{category}= lc $config->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{graph_category} || "other"; 
    279  
    280         # Do "help" section 
    281                 if (defined $config->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{graph_info}) 
    282                 { 
    283                         my %graph_info; 
    284                         $graph_info{info} = $config->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{graph_info}; 
    285                         push @{$service{graphinfo}}, \%graph_info; 
    286                 } 
    287                 $service{fieldlist} .= "<tr><th align='left' valign='top'>Field</th><th align='left' valign='top'>Type</th><th align='left' valign='top'>Warn</th><th align='left' valign='top'>Crit</th><th></tr>"; 
    288 #               foreach my $field (keys %{$config->{domain}->{$domain}->{node}->{$node}->{client}->{$service}}) 
    289                 foreach my $f (@{&munin_get_field_order ($config->{domain}->{$domain}->{node}->{$node}, $config, $domain, $node, $service)}) 
    290                 { 
    291                         $f =~ s/=(.*)$//; 
    292                         my $path = $1; 
    293                         next unless (&munin_draw_field ($config->{domain}->{$domain}->{node}->{$node}, $service, $f)); 
    294                         print "DEBUG: single_value: Checking field \"$f\" ($path).\n" if $DEBUG; 
    295  
    296                         if (defined $path) 
    297                         { 
    298                             munin_get_rrd_filename ($config->{domain}->{$domain}->{node}->{$node}, $config, $domain, $node, $service, $f, $path); 
    299                         } 
    300  
    301                         my %field_info; 
    302                         $fieldnum++; 
    303  
    304                         $field_info{'hr'}      = 1 unless ($fieldnum % 3); 
    305                         $field_info{'field'}   = $f; 
    306                         $field_info{'label'}   = $config->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{$f.".label"} || $f; 
    307                         $field_info{'type'}    = lc ($config->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{$f.".type"} || "GAUGE"); 
    308                         $field_info{'warn'}    = $config->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{$f.".warning"} || "None"; 
    309                         $field_info{'crit'}    = $config->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{$f.".critical"} || "None"; 
    310                         $field_info{'info'}    = $config->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{$f.".info"} || ""; 
    311  
    312                         my $state = &munin_field_status ($config, $limits, $domain, $node, $service, $f, 1); 
    313                         if (defined $state) 
    314                         { 
    315                                 $field_info{'state_warning'}  = 1 if $state eq "warning"; 
    316                                 $field_info{'state_critical'} = 1 if $state eq "critical"; 
    317                                 $field_info{'state_unknown'}  = 1 if $state eq "unknown"; 
    318                         } 
    319                         push @{$service{fieldinfo}}, \%field_info; 
    320                 } 
    321  
    322                 { 
    323                         my $state = &munin_service_status ($config, $limits, $domain, $node, $service, 1); 
    324                         if (defined $state) 
    325                         { 
    326                                 $service{'state_warning'}  = 1 if $state eq "warning"; 
    327                                 $service{'state_critical'} = 1 if $state eq "critical"; 
    328                                 $service{'state_unknown'}  = 1 if $state eq "unknown"; 
    329                         } 
    330                 } 
    331  
    332             push @services, \%service; 
    333             push @service, \%service; 
    334             push @{$tmp_cats{$service{'category'}}}, \%service; 
    335             $servicetemplate->param(SERVICES => \@service, 
    336                                     SERVICE => $service, 
    337                                     NODE => $node, 
    338                                     DOMAIN => $domain,  
    339                                     DOMAINS => \@domainlist,  
    340                                     TIMESTAMP => $timestamp); 
    341             open (FILE, ">$config->{htmldir}/$domain/$node-$service.html") or die "Cannot open $config->{htmldir}/$domain/$node-$service.html"; 
    342             print FILE $servicetemplate->output; 
    343             close FILE; 
    344         } 
    345         foreach my $key (keys %tmp_cats) 
    346         { 
    347             next if $key eq "other"; 
    348             my %tmp; 
    349             my $state = &munin_category_status ($config, $limits, $domain, $node, $key, 1); 
    350             print "DEBUG: Pushing category \"$node\" -> \"$key\"...\n" if $DEBUG; 
    351             if (defined $state) 
    352             { 
    353                     $tmp{'state_warning'}  = 1 if $state eq "warning"; 
    354                     $tmp{'state_critical'} = 1 if $state eq "critical"; 
    355                     $tmp{'state_unknown'}  = 1 if $state eq "unknown"; 
    356             } 
    357             $tmp{name} = ucfirst $key; 
    358             $tmp{services} = \@{$tmp_cats{$key}}; 
    359             $tmp{node} = $node; 
    360             $tmp{domain} = $domain; 
    361             $categories{ucfirst $key} = \%tmp; 
    362             $comparisons{$key}{$node} = \%tmp; 
    363         } 
    364         if (defined $tmp_cats{'other'}) 
    365         { 
    366             my $key = 'other'; 
    367             my %tmp; 
    368             my $state = &munin_category_status ($config, $limits, $domain, $node, $key, 1); 
    369             print "DEBUG: Pushing category \"$node\" -> \"$key\"...\n" if $DEBUG; 
    370             if (defined $state) 
    371             { 
    372                     $tmp{'state_warning'}  = 1 if $state eq "warning"; 
    373                     $tmp{'state_critical'} = 1 if $state eq "critical"; 
    374                     $tmp{'state_unknown'}  = 1 if $state eq "unknown"; 
    375             } 
    376             $tmp{name} = ucfirst $key; 
    377             $tmp{services} = \@{$tmp_cats{$key}}; 
    378             $tmp{node} = $node; 
    379             $tmp{domain} = $domain; 
    380             $categories{ucfirst $key} = \%tmp; 
    381             $comparisons{'other'}{$node} = \%tmp; 
    382         } 
    383         # Handle category_order 
    384         @categories = (); 
    385         if ($config->{domain}->{$domain}->{node}->{$node}->{category_order}) { 
    386             foreach my $cat (split /\s+/, $config->{domain}->{$domain}->{node}->{$node}->{category_order}) 
    387             { 
    388                 push @categories, $categories{ucfirst $cat}; 
    389             } 
    390             foreach my $cat (sort keys %categories) 
    391             { 
    392                 push @categories, $categories{$cat} 
    393                         unless (grep { $_->{name} eq $cat } @categories); 
    394             } 
    395         } else { 
    396             @categories = map { $categories{$_} } sort keys %categories; 
    397         } 
    398         $nodetemplate->param(SERVICES => \@services, 
    399                              NODE => $node, 
    400                              DOMAIN => $domain, 
    401                              DOMAINS => \@domainlist,  
    402                              TIMESTAMP => $timestamp, 
    403                              CATEGORIES => \@categories); 
    404         open (FILE, ">$config->{htmldir}/$domain/$node.html") or die "Cannot open $config->{htmldir}/$domain/$node.html"; 
    405         print FILE $nodetemplate->output; 
    406         close FILE; 
    407         $node{services} = \@services; 
    408         $node{categories} = \@categories; 
    409         $node{domain} = $domain; 
    410         push @nodes,\%node; 
    411  
    412     } 
    413     $domaintemplate->param(NODES => \@nodes, 
    414                            DOMAIN => $domain,  
    415                            DOMAINS => \@domainlist,  
    416                            COMPARE => (&munin_get_bool ($config, "compare", 1, $domain) and @nodeorder > 1), 
    417                            TIMESTAMP => $timestamp); 
    418     open (FILE, ">$config->{htmldir}/$domain/index.html") or die "Cannot open $config->{htmldir}/index.html"; 
    419     print FILE $domaintemplate->output; 
    420     close FILE; 
    421      
    422     $domain{nodes} = \@nodes; 
    423     $domain{domain} = $domain; 
    424     $domain{compare} = (&munin_get_bool ($config, "compare", 1, $domain) and @nodeorder > 1); 
    425  
    426     my @cats = (); 
    427     foreach my $key (sort keys %comparisons) 
    428     { 
    429         my %cat; 
    430         my %servlist; 
    431         my $nodewidth = 0; 
    432  
    433         foreach my $node (sort keys %{$comparisons{$key}}) 
    434         { 
    435             foreach my $serv (@{$comparisons{$key}{$node}->{services}}) 
    436             { 
    437                 $servlist{$serv->{service}}{$node} = $serv; 
    438                 $nodewidth = $serv->{imgdaywidth} if (defined $serv->{imgdaywidth} and $serv->{imgdaywidth} > $nodewidth); 
    439             } 
    440         } 
    441         foreach my $sname (sort keys %servlist) 
    442         { 
    443             my %s; 
    444             foreach my $node (@nodeorder) 
    445             { 
    446                 if (defined $servlist{$sname}{$node}) 
    447                 { 
    448                     $servlist{$sname}{$node}->{width} = $nodewidth; 
    449                     push (@{$s{nodes}}, $servlist{$sname}{$node}); 
    450                 } 
    451                 else 
    452                 { 
    453                     my %ts; 
    454                     $ts{label} = "Not present"; 
    455                     $ts{service} = "$sname"; 
    456                     $ts{title} = "Not present"; 
    457                     $ts{node} = $node; 
    458                     $ts{width} = $nodewidth; 
    459                     push (@{$s{nodes}}, \%ts); 
    460                 } 
    461             } 
    462             push @{$cat{services}}, \%s; 
    463         } 
    464         $cat{name} = ucfirst $key; 
    465         $cat{numnodes} = @nodeorder; 
    466         $cat{numnodes} = @nodeorder; 
    467         push @cats, \%cat; 
    468     } 
    469  
    470     if (&munin_get_bool ($config, "compare", 1, $domain) and @nodeorder > 1) 
    471     { 
    472         foreach my $t (@times) 
    473         { 
    474             $comparisontemplates{$t}->param(DOMAIN => $domain, 
    475                                  DOMAINS => \@domainlist,  
    476                                  TIMESTAMP => $timestamp, 
    477                                  CATEGORIES => \@cats); 
    478             open (FILE, ">$config->{htmldir}/$domain/comparison-$t.html") or die "Cannot open $config->{htmldir}/$domain/comparison-$t.html"; 
    479             print FILE $comparisontemplates{$t}->output; 
    480             close FILE; 
    481         } 
    482     } 
    483  
    484     push @domains,\%domain; 
     486          my %ts; 
     487          $ts{label} = "Not present"; 
     488          $ts{service} = "$sname"; 
     489          $ts{title} = "Not present"; 
     490          $ts{node} = $node; 
     491          $ts{width} = $nodewidth; 
     492          push (@{$s{nodes}}, \%ts); 
     493        } 
     494      } 
     495      push @{$cat{services}}, \%s; 
     496    } 
     497    $cat{name} = ucfirst $key; 
     498    $cat{numnodes} = @nodeorder; 
     499    $cat{numnodes} = @nodeorder; 
     500    push @cats, \%cat; 
     501  } 
     502 
     503  if (&munin_get_bool ($config, "compare", 1, $domain) and @nodeorder > 1) { 
     504    foreach my $t (@times) { 
     505      $comparisontemplates{$t}->param(DOMAIN => $domain, 
     506                                      DOMAINS => \@domainlist, 
     507                                      TIMESTAMP => $timestamp, 
     508                                      CATEGORIES => \@cats); 
     509      open (FILE, ">$config->{htmldir}/$domain/comparison-$t.html") or 
     510        die "Cannot open $config->{htmldir}/$domain/comparison-$t.html"; 
     511      print FILE $comparisontemplates{$t}->output; 
     512      close FILE; 
     513    } 
     514  } 
     515  push @domains,\%domain; 
    485516} 
    486517