Changeset 1493
- Timestamp:
- 02/26/08 22:35:20 (4 years ago)
- Files:
-
- people/jo/multilevel-groups-2/server/Munin.pm.in (modified) (1 diff)
- people/jo/multilevel-groups-2/server/munin-html.in (modified) (2 diffs)
- people/jo/multilevel-groups-2/server/munin-limits.in (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
people/jo/multilevel-groups-2/server/Munin.pm.in
r1347 r1493 1152 1152 return undef unless (defined $hash and ref ($hash) eq "HASH"); 1153 1153 1154 foreach my $service ( munin_get_children ($hash)) {1154 foreach my $service (@{munin_get_children ($hash)}) { 1155 1155 next if (!defined $service or ref ($service) ne "HASH"); 1156 1156 next if (!defined $service->{'graph_title'}); people/jo/multilevel-groups-2/server/munin-html.in
r1353 r1493 339 339 340 340 foreach my $child (@{munin_get_children ($hash)}) { 341 next unless defined $child and ref ($child) eq "HASH" and $child;341 next unless defined $child and ref ($child) eq "HASH" and keys %$child; 342 342 if (defined $child->{"graph_title"}) { 343 343 my $childname = munin_get_node_name ($child); … … 455 455 456 456 sub generate_service_templates { 457 }458 459 sub generate_service_templates {460 457 461 458 my $service = shift || return undef; people/jo/multilevel-groups-2/server/munin-limits.in
r1341 r1493 1 1 #!@@PERL@@ 2 2 # -*- perl -*- 3 # Copyright (C) 2004 Jimmy Olsen3 # Copyright (C) 2004-2007 Jimmy Olsen 4 4 # 5 5 # This program is free software; you can redistribute it and/or … … 116 116 logger("munin-limits finished ($update_time sec)"); 117 117 118 119 sub process_domain { 120 my ($domain) = @_; 121 for my $node ( keys %{$config->{domain}->{$domain}->{node}}) { 122 if (@limit_hosts and !grep (/^$node$/, @limit_hosts)) 123 { 124 logger ("skipping node: $node"); 125 next; 126 } 127 logger ("processing node: $node"); 128 process_node($domain,$node ,$config->{domain}->{$domain}->{node}->{$node} ); 129 } 130 } 131 132 sub process_node { 133 my ($domain,$name,$node) = @_; 134 for my $client (keys %{$node->{client}}) { 135 logger ("processing service: $client") if $DEBUG; 136 process_service($domain,$name,$client,$node->{client}->{$client}); 137 } 118 sub process_group { 119 my $hash = shift || return undef; 120 my $name = munin_get_node_name ($hash); 121 122 if ($hash and ref ($hash) eq "HASH") { 123 if (defined $hash->{'graph_title'}) { # Graph, need to check limits 124 logger ("processing plugin: $name") if $DEBUG; 125 process_service ($hash); 126 } else { 127 foreach my $childobj (munin_get_children ($hash)) { 128 next unless ref ($childobj) eq "HASH"; 129 logger ("processing group: $name") if $DEBUG; 130 process_group ($childobj); 131 } 132 } 133 } 138 134 } 139 135 140 136 sub process_service { 141 my $critical= undef; 142 my ($domain, $name,$clientname,$client) = @_; 143 return unless $client; 144 for my $service (keys %$client) { 145 if ($service =~ /(^.*)\.label/) { 146 my $key = $1; 147 next unless ((exists $client->{"$key.warning"}) || ($client->{"$key.critical"})); 148 logger ("processing field: $key") if $DEBUG; 149 if (@limit_services and !grep (/^$service$/, @limit_services)) 150 { 151 next; 152 } 153 my $critical; 154 my $warning; 155 ($warning, $critical) = get_limits ($client, $domain, $name, $clientname, $key); 156 157 my $filename = "$config->{dbdir}/$domain/$name-$clientname-$key-". 158 lc substr (($client->{"$key.type"}||"GAUGE"),0,1) . ".rrd"; 159 my $value = &munin_fetch("$filename"); 160 # De-taint. 161 if (!defined $value) { 162 $value = "unknown"; 163 } else { 164 $value = sprintf "%.2f",$value; 165 } 166 167 # Some fields that are nice to have in the plugin output 168 $client->{$key.".value"} = $value; 169 $client->{'fields'} = join (' ', map { $_ =~ s/\.label$//; $_} grep (/\.label/, keys %$client)); 170 $client->{'plugin'} = $clientname; 171 $client->{'graph_title'} = $client->{'notify_alias'} if defined $client->{'notify_alias'}; 172 $client->{'host'} = $config->{'domain'}->{$domain}->{'node'}->{$name}->{'notify_alias'} || $name; 173 $client->{'group'} = $config->{'domain'}->{$domain}->{'notify_alias'} || $domain; 174 $client->{'worst'} = "OK"; 175 $client->{'worstid'} = 0 unless defined $client->{'worstid'}; 176 $client->{$key.".crange"} = (defined $critical->[0]?$critical->[0]:"").":".(defined $critical->[1]?$critical->[1]:""); 177 $client->{$key.".wrange"} = (defined $warning->[0]?$warning->[0]:"").":".(defined $warning->[1]?$warning->[1]:""); 178 179 logger ("value: $domain -> $name -> $clientname -> $key : $value") if $DEBUG; 137 my $hash = shift || return undef; 138 my $hostobj = munin_get_parent ($hash); 139 my $domainobj = munin_get_parent (munin_get_parent ($hash)); 140 my $service = munin_get_node_name ($hash); 141 my $host = munin_get_node_name ($hostobj); 142 my $domain = munin_get_node_name ($domainobj); 143 my $children = munin_get_children ($hash); 144 145 # Some fields that are nice to have in the plugin output 146 $hash->{'fields'} = join (' ', map { munin_get_node_name ($_) } @$children)); 147 $hash->{'plugin'} = $service; 148 $hash->{'graph_title'} = $hash->{'notify_alias'} if defined $hash->{'notify_alias'}; 149 $hash->{'host'} = munin_get ($hostobj, "notify_alias", $host); 150 $hash->{'group'} = munin_get ($domainobj, "notify_alias", $domain); 151 $hash->{'worst'} = "OK"; 152 $hash->{'worstid'} = 0 unless defined $hash->{'worstid'}; 153 154 foreach my $field (@$children) { 155 next if (!defined $field or ref ($field) ne "HASH"); 156 my $fname = munin_get_node_name ($field); 157 my $warn = munin_get ($field, "warning", undef); 158 my $crit = munin_get ($field, "critical", undef); 159 160 # Skip fields without warning/critical definitions 161 next if (!defined $warn and !defined $crit); 162 163 logger ("processing field: $fname") if $DEBUG; 164 next if (@limit_services and !grep (/^$service$/, @limit_services)); 165 166 ($warn, $crit) = get_limits ($field); 167 168 my $filename = munin_get_rrd_filename ($field); 169 my $value = munin_fetch("$filename"); 170 # De-taint. 171 if (!defined $value) { 172 $value = "unknown"; 173 } else { 174 $value = sprintf "%.2f",$value; 175 } 176 177 # Some fields that are nice to have in the plugin output 178 $field->{'value'} = $value; 179 $field->{'crange'} = (defined $critical->[0]?$critical->[0]:"").":".(defined $critical->[1]?$critical->[1]:""); 180 $field->{'wrange'} = (defined $warning->[0]?$warning->[0]:"").":".(defined $warning->[1]?$warning->[1]:""); 181 182 logger ("value: $domain -> $host -> $service -> $key : $value") if $DEBUG; 180 183 if ($value eq "unknown") { 181 184 $critical->[0] ||= ""; 182 185 $critical->[1] ||= ""; 183 $ client->{'worst'} = "UNKNOWN" if $client->{"worst"} eq "OK";184 $ client->{'worstid'} = 3 if $client->{"worstid"} == 0;186 $hash->{'worst'} = "UNKNOWN" if $hash->{"worst"} eq "OK"; 187 $hash->{'worstid'} = 3 if $hash->{"worstid"} == 0; 185 188 $notes{$domain}{$name}{$clientname}{"$key.state"} = "unknown"; 186 189 $notes{$domain}{$name}{$clientname}{"$key.unknown"} = … … 240 243 } 241 244 242 sub get_limits 243 { 244 my $client = shift; 245 my $domain = shift; 246 my $name = shift; 247 my $clientname = shift; 248 my $key = shift; 245 sub get_limits { 246 my $hash = shift || return undef; 249 247 my @critical = (undef, undef); 250 248 my @warning = (undef, undef); 251 if (defined $client->{"$key.critical"} and 252 $client->{"$key.critical"} =~ /^\s*([-+\d.]*):([-+\d.]*)\s*$/) 253 { 249 my $crit = munin_get ($hash, "critical", undef); 250 my $warn = munin_get ($hash, "warning", undef); 251 my $name = munin_get_node_name ($hash); 252 253 if (defined $critical and $critical =~ /^\s*([-+\d.]*):([-+\d.]*)\s*$/) { 254 254 $critical[0] = $1 if length $1; 255 255 $critical[1] = $2 if length $2; 256 logger ("processing critical: $domain -> $name -> $clientname -> $key -> $critical[0] : $critical[1]") if $DEBUG; 257 } 258 elsif (defined $client->{"$key.critical"} and 259 $client->{"$key.critical"} =~ /^\s*([-+\d.]+)\s*$/) 260 { 256 logger ("processing critical: $name -> $critical[0] : $critical[1]") if $DEBUG; 257 } elsif (defined $crit and $crit =~ /^\s*([-+\d.]+)\s*$/) { 261 258 $critical[1] = $1 if defined $1; 262 logger ("processing critical: $domain -> $name -> $clientname -> $key -> $critical[0] : $critical[1]") if $DEBUG; 263 } 264 elsif (defined $client->{"$key.critical"}) 265 { 259 logger ("processing critical: $name -> $critical[0] : $critical[1]") if $DEBUG; 260 } elsif (defined $crit) { 266 261 @critical = (0, 0); 267 logger ("processing critical: $domain -> $name -> $clientname -> $key -> $critical[0] : $critical[1]") if $DEBUG; 268 } 269 if (defined $client->{"$key.warning"} and 270 $client->{"$key.warning"} =~ /^\s*([-+\d.]*):([-+\d.]*)\s*$/) 271 { 262 logger ("processing critical: $name -> $critical[0] : $critical[1]") if $DEBUG; 263 } 264 265 if (defined $warn and $warn =~ /^\s*([-+\d.]*):([-+\d.]*)\s*$/) { 272 266 $warning[0] = $1 if length $1; 273 267 $warning[1] = $2 if length $2; 274 logger ("processing warning: $domain -> $name -> $clientname -> $key -> $warning[0] : $warning[1]") if $DEBUG; 275 } 276 elsif (defined $client->{"$key.warning"} and 277 $client->{"$key.warning"} =~ /^\s*([-+\d.]+)\s*$/) 278 { 268 logger ("processing warning: $name -> $warning[0] : $warning[1]") if $DEBUG; 269 } elsif (defined $warn and $warn =~ /^\s*([-+\d.]+)\s*$/) { 279 270 $warning[1] = $1 if defined $1; 280 logger ("processing warning: $domain -> $name -> $clientname -> $key -> $warning[0] : $warning[1]") if $DEBUG; 281 } 282 elsif (defined $client->{"$key.warning"}) 283 { 271 logger ("processing warning: $name -> $warning[0] : $warning[1]") if $DEBUG; 272 } elsif (defined $warn) { 284 273 @warning = (0, 0); 285 logger ("processing warning: $ domain -> $name -> $clientname -> $key-> $warning[0] : $warning[1]") if $DEBUG;274 logger ("processing warning: $name -> $warning[0] : $warning[1]") if $DEBUG; 286 275 } 287 276 return (\@warning, \@critical);
