| 123 | | my $hash = shift || return undef; |
|---|
| 124 | | my $hostobj = munin_get_parent ($hash); |
|---|
| 125 | | my $domainobj = munin_get_parent (munin_get_parent ($hash)); |
|---|
| 126 | | my $service = munin_get_node_name ($hash); |
|---|
| 127 | | my $host = munin_get_node_name ($hostobj); |
|---|
| 128 | | my $domain = munin_get_node_name ($domainobj); |
|---|
| 129 | | my $children = munin_get_children ($hash); |
|---|
| | 135 | my $hash = shift || return undef; |
|---|
| | 136 | my $parentobj = munin_get_parent ($hash); |
|---|
| | 137 | my $gparentobj = munin_get_parent (munin_get_parent ($hash)); |
|---|
| | 138 | my $service = munin_get_node_name ($hash); |
|---|
| | 139 | my $parent = munin_get_node_name ($parentobj); |
|---|
| | 140 | my $gparent = munin_get_node_name ($gparentobj); |
|---|
| | 141 | my $children = munin_get_children ($hash); |
|---|
| 165 | | $field->{'crange'} = (defined $critical->[0]?$critical->[0]:"").":".(defined $critical->[1]?$critical->[1]:""); |
|---|
| 166 | | $field->{'wrange'} = (defined $warning->[0]?$warning->[0]:"").":".(defined $warning->[1]?$warning->[1]:""); |
|---|
| 167 | | |
|---|
| 168 | | logger ("value: $domain -> $host -> $service -> $key : $value") if $DEBUG; |
|---|
| 169 | | if ($value eq "unknown") { |
|---|
| 170 | | $critical->[0] ||= ""; |
|---|
| 171 | | $critical->[1] ||= ""; |
|---|
| 172 | | $hash->{'worst'} = "UNKNOWN" if $hash->{"worst"} eq "OK"; |
|---|
| 173 | | $hash->{'worstid'} = 3 if $hash->{"worstid"} == 0; |
|---|
| 174 | | $notes{$domain}{$name}{$clientname}{"$key.state"} = "unknown"; |
|---|
| 175 | | $notes{$domain}{$name}{$clientname}{"$key.unknown"} = |
|---|
| 176 | | (defined $client->{"$key.extinfo"} ? "unknown: " . $client->{"$key.extinfo"} : "Value is unknown."); |
|---|
| 177 | | if (!defined ($oldnotes->{'domain'}->{$domain}->{'node'}->{$name}->{'client'}->{$clientname}->{"$key.state"}) or |
|---|
| 178 | | $oldnotes->{'domain'}->{$domain}->{'node'}->{$name}->{'client'}->{$clientname}->{"$key.state"} ne "unknown") |
|---|
| 179 | | { |
|---|
| 180 | | $client->{'state_changed'} = 1; |
|---|
| 181 | | } |
|---|
| | 179 | $field->{'crange'} = (defined $crit->[0]?$crit->[0]:"").":".(defined $crit->[1]?$crit->[1]:""); |
|---|
| | 180 | $field->{'wrange'} = (defined $warn->[0]?$warn->[0]:"").":".(defined $warn->[1]?$warn->[1]:""); |
|---|
| | 181 | |
|---|
| | 182 | logger ("value: ". join ('::', @{munin_get_node_loc ($hash)})) if $DEBUG; |
|---|
| | 183 | if ($value eq "unknown") { |
|---|
| | 184 | $crit->[0] ||= ""; |
|---|
| | 185 | $crit->[1] ||= ""; |
|---|
| | 186 | $hash->{'worst'} = "UNKNOWN" if $hash->{"worst"} eq "OK"; |
|---|
| | 187 | $hash->{'worstid'} = 3 if $hash->{"worstid"} == 0; |
|---|
| | 188 | munin_set_var_loc (\%notes, [$path, "state"], "unknown"); |
|---|
| | 189 | munin_set_var_loc (\%notes, [$path, "unknown"], (defined $field->{"extinfo"} ? "unknown: " . $field->{"extinfo"} : "Value is unknown.")); |
|---|
| | 190 | |
|---|
| | 191 | if (!defined $onfield or !defined $onfield->{"state"} or $onfield->{"state"} ne "unknown") { |
|---|
| | 192 | $field->{'state_changed'} = 1; |
|---|
| 183 | | elsif ((defined ($critical->[0]) and $value < $critical->[0]) or |
|---|
| 184 | | (defined ($critical->[1]) and $value > $critical->[1])) { |
|---|
| 185 | | $critical->[0] ||= ""; |
|---|
| 186 | | $critical->[1] ||= ""; |
|---|
| 187 | | $client->{'worst'} = "CRITICAL"; |
|---|
| 188 | | $client->{'worstid'} = 2; |
|---|
| 189 | | $notes{$domain}{$name}{$clientname}{"$key.state"} = "critical"; |
|---|
| 190 | | $notes{$domain}{$name}{$clientname}{"$key.critical"} = |
|---|
| 191 | | (defined $client->{"$key.extinfo"}? |
|---|
| 192 | | "$value (not in $critical->[0]:$critical->[1]): ". |
|---|
| 193 | | $client->{"$key.extinfo"}: |
|---|
| 194 | | "Value is $value. Critical range ($critical->[0]:$critical->[1]) exceeded"); |
|---|
| 195 | | if (!defined ($oldnotes->{'domain'}->{$domain}->{'node'}->{$name}->{'client'}->{$clientname}->{"$key.state"}) or |
|---|
| 196 | | $oldnotes->{'domain'}->{$domain}->{'node'}->{$name}->{'client'}->{$clientname}->{"$key.state"} ne "critical") |
|---|
| 197 | | { |
|---|
| 198 | | $client->{'state_changed'} = 1; |
|---|
| 199 | | } |
|---|
| | 194 | } elsif ((defined ($crit->[0]) and $value < $crit->[0]) or |
|---|
| | 195 | (defined ($crit->[1]) and $value > $crit->[1])) { |
|---|
| | 196 | $crit->[0] ||= ""; |
|---|
| | 197 | $crit->[1] ||= ""; |
|---|
| | 198 | $hash->{'worst'} = "CRITICAL"; |
|---|
| | 199 | $hash->{'worstid'} = 2; |
|---|
| | 200 | munin_set_var_loc (\%notes, [$path, "state"], "critical"); |
|---|
| | 201 | munin_set_var_loc (\%notes, [$path, "critical"], |
|---|
| | 202 | (defined $field->{"extinfo"}? |
|---|
| | 203 | "$value (not in $crit->[0]:$crit->[1]): ". |
|---|
| | 204 | $field->{"extinfo"}: |
|---|
| | 205 | "Value is $value. Critical range ($crit->[0]:$crit->[1]) exceeded")); |
|---|
| | 206 | |
|---|
| | 207 | if (!defined $onfield or !defined $onfield->{"state"} or $onfield->{"state"} ne "critical") { |
|---|
| | 208 | $field->{'state_changed'} = 1; |
|---|
| 201 | | elsif ((defined ($warning->[0]) and $value < $warning->[0]) or |
|---|
| 202 | | (defined ($warning->[1]) and $value > $warning->[1])) |
|---|
| 203 | | { |
|---|
| 204 | | $warning->[0] ||= ""; |
|---|
| 205 | | $warning->[1] ||= ""; |
|---|
| 206 | | $client->{'worst'} = "WARNING" if $client->{"worst"} ne "CRITICAL"; |
|---|
| 207 | | $client->{'worstid'} = 1 if $client->{"worstid"} != 2; |
|---|
| 208 | | $notes{$domain}{$name}{$clientname}{"$key.state"} = "warning"; |
|---|
| 209 | | $notes{$domain}{$name}{$clientname}{"$key.warning"} = |
|---|
| 210 | | (defined $client->{"$key.extinfo"}? |
|---|
| 211 | | "$value (not in $warning->[0]:$warning->[1]): ". |
|---|
| 212 | | $client->{"$key.extinfo"}: |
|---|
| 213 | | "Value is $value. Warning range ($warning->[0]:$warning->[1]) exceeded"); |
|---|
| 214 | | if (!defined ($oldnotes->{'domain'}->{$domain}->{'node'}->{$name}->{'client'}->{$clientname}->{"$key.state"}) or |
|---|
| 215 | | $oldnotes->{'domain'}->{$domain}->{'node'}->{$name}->{'client'}->{$clientname}->{"$key.state"} ne "warning") |
|---|
| 216 | | { |
|---|
| 217 | | $client->{'state_changed'} = 1; |
|---|
| 218 | | } |
|---|
| 219 | | } |
|---|
| 220 | | elsif (defined ($oldnotes->{'domain'}->{$domain}->{'node'}->{$name}->{'client'}->{$clientname}->{"$key.state"}) or |
|---|
| 221 | | $force) |
|---|
| 222 | | { |
|---|
| 223 | | $notes{$domain}{$name}{$clientname}{"$key.ok"} = "OK"; |
|---|
| 224 | | $client->{'state_changed'} = 1; |
|---|
| | 210 | } elsif ((defined ($warn->[0]) and $value < $warn->[0]) or |
|---|
| | 211 | (defined ($warn->[1]) and $value > $warn->[1])) |
|---|
| | 212 | { |
|---|
| | 213 | $warn->[0] ||= ""; |
|---|
| | 214 | $warn->[1] ||= ""; |
|---|
| | 215 | $hash->{'worst'} = "WARNING" if $hash->{"worst"} ne "CRITICAL"; |
|---|
| | 216 | $hash->{'worstid'} = 1 if $hash->{"worstid"} != 2; |
|---|
| | 217 | munin_set_var_loc (\%notes, [$path, "state"], "warning"); |
|---|
| | 218 | munin_set_var_loc (\%notes, [$path, "warning"], |
|---|
| | 219 | (defined $field->{"extinfo"}? |
|---|
| | 220 | "$value (not in $warn->[0]:$warn->[1]): ". |
|---|
| | 221 | $field->{"extinfo"}: |
|---|
| | 222 | "Value is $value. Warning range ($warn->[0]:$warn->[1]) exceeded")); |
|---|
| | 223 | |
|---|
| | 224 | if (!defined $onfield or !defined $onfield->{"state"} or $onfield->{"state"} ne "warning") { |
|---|
| | 225 | $hash->{'state_changed'} = 1; |
|---|
| 266 | | my $critical= undef; |
|---|
| 267 | | my ($domain, $name,$clientname,$client) = @_; |
|---|
| 268 | | return unless $client; |
|---|
| 269 | | my $worst = ""; |
|---|
| 270 | | my %stats = ('critical' => [], 'warning' => [], 'unknown' => [], 'foks' => [], 'ok' => []); |
|---|
| 271 | | |
|---|
| 272 | | logger ("generating service message: $domain -> $name -> $clientname") if $DEBUG; |
|---|
| 273 | | foreach my $key (keys %{$notes{$domain}{$name}{$clientname}}) |
|---|
| 274 | | { |
|---|
| 275 | | if ($key =~ /^([^\.]+)\.critical$/) |
|---|
| 276 | | { |
|---|
| 277 | | $worst = "critical"; |
|---|
| 278 | | push @{$stats{'critical'}}, $1; |
|---|
| 279 | | } |
|---|
| 280 | | elsif ($key =~ /^([^\.]+)\.warning$/) |
|---|
| 281 | | { |
|---|
| 282 | | $worst = "warning" if $worst ne "critical"; |
|---|
| 283 | | push @{$stats{'warning'}}, $1; |
|---|
| 284 | | } |
|---|
| 285 | | elsif ($key =~ /^([^\.]+)\.unknown$/) |
|---|
| 286 | | { |
|---|
| 287 | | $worst = "unknown" if (!$worst or $worst eq "ok"); |
|---|
| 288 | | push @{$stats{'unknown'}}, $1; |
|---|
| 289 | | } |
|---|
| 290 | | elsif ($key =~ /^([^\.]+)\.ok$/) |
|---|
| 291 | | { |
|---|
| 292 | | $worst = "ok" unless $worst; |
|---|
| 293 | | push @{$stats{'ok'}}, $1; |
|---|
| 294 | | push @{$stats{'foks'}}, $1; |
|---|
| 295 | | } |
|---|
| 296 | | else |
|---|
| 297 | | { |
|---|
| 298 | | push @{$stats{'ok'}}, $1; |
|---|
| 299 | | } |
|---|
| 300 | | } |
|---|
| 301 | | $client->{'cfields'} = join " ", @{$stats{'critical'}}; |
|---|
| 302 | | $client->{'wfields'} = join " ", @{$stats{'warning'}}; |
|---|
| 303 | | $client->{'ufields'} = join " ", @{$stats{'unknown'}}; |
|---|
| 304 | | $client->{'fofields'} = join " ", @{$stats{'foks'}}; |
|---|
| 305 | | $client->{'ofields'} = join " ", @{$stats{'ok'}}; |
|---|
| 306 | | $client->{'numcfields'} = scalar @{$stats{'critical'}}; |
|---|
| 307 | | $client->{'numwfields'} = scalar @{$stats{'warning'}}; |
|---|
| 308 | | $client->{'numufields'} = scalar @{$stats{'unknown'}}; |
|---|
| 309 | | $client->{'numfofields'} = scalar @{$stats{'foks'}}; |
|---|
| 310 | | $client->{'numofields'} = scalar @{$stats{'ok'}}; |
|---|
| 311 | | |
|---|
| 312 | | if ($worst) |
|---|
| 313 | | { |
|---|
| 314 | | foreach my $c (split (/\s+/, munin_get ($config, "contacts", join (' ', keys %{$config->{'contact'}}), $domain, $name, $clientname))) |
|---|
| 315 | | { |
|---|
| 316 | | next if $c eq "none"; |
|---|
| 317 | | next unless defined $config->{'contact'}->{$c}->{'command'}; |
|---|
| 318 | | if (@limit_contacts and !grep (/^$c$/, @limit_contacts)) |
|---|
| 319 | | { |
|---|
| 320 | | next; |
|---|
| | 271 | my $hash = shift || return undef; |
|---|
| | 272 | my $critical = undef; |
|---|
| | 273 | my $worst = $hash->{"worst"}; |
|---|
| | 274 | my %stats = ('critical' => [], 'warning' => [], 'unknown' => [], 'foks' => [], 'ok' => []); |
|---|
| | 275 | my $contacts = munin_get_children (munin_get_node ($config, ["contacts"])); |
|---|
| | 276 | |
|---|
| | 277 | logger ("generating service message: ". join ('::', @{munin_get_node_loc ($hash)})) if $DEBUG; |
|---|
| | 278 | foreach my $field (@{munin_get_children ($hash)}) { |
|---|
| | 279 | if (defined $field->{"state"}) { |
|---|
| | 280 | push @{$stats{$field->{"state"}}}, munin_get_node_name ($field); |
|---|
| | 281 | if ($field->{"state"} eq "ok") { |
|---|
| | 282 | push @{$stats{"foks"}}, munin_get_node_name ($field); |
|---|
| 322 | | my $obsess = 0; |
|---|
| 323 | | if (defined ($config->{'contact'}->{$c}->{'always_send'})) |
|---|
| 324 | | { |
|---|
| 325 | | $obsess = grep {scalar(@{$stats{$_}})} (split (/\s+/, lc $config->{'contact'}->{$c}->{'always_send'})); |
|---|
| | 284 | } |
|---|
| | 285 | } |
|---|
| | 286 | $hash->{'cfields'} = join " ", @{$stats{'critical'}}; |
|---|
| | 287 | $hash->{'wfields'} = join " ", @{$stats{'warning'}}; |
|---|
| | 288 | $hash->{'ufields'} = join " ", @{$stats{'unknown'}}; |
|---|
| | 289 | $hash->{'fofields'} = join " ", @{$stats{'foks'}}; |
|---|
| | 290 | $hash->{'ofields'} = join " ", @{$stats{'ok'}}; |
|---|
| | 291 | $hash->{'numcfields'} = scalar @{$stats{'critical'}}; |
|---|
| | 292 | $hash->{'numwfields'} = scalar @{$stats{'warning'}}; |
|---|
| | 293 | $hash->{'numufields'} = scalar @{$stats{'unknown'}}; |
|---|
| | 294 | $hash->{'numfofields'} = scalar @{$stats{'foks'}}; |
|---|
| | 295 | $hash->{'numofields'} = scalar @{$stats{'ok'}}; |
|---|
| | 296 | |
|---|
| | 297 | my $defaultcontacts = join (' ', map { munin_get_node_name ($_) } @$contacts); |
|---|
| | 298 | foreach my $c (split (/\s+/, munin_get ($hash, "contacts", $defaultcontacts))) { |
|---|
| | 299 | next if $c eq "none"; |
|---|
| | 300 | my $contactobj = munin_get_node ($config, ["contact", $c]); |
|---|
| | 301 | next unless defined $contactobj; |
|---|
| | 302 | next unless defined munin_get ($contactobj, "command", undef); |
|---|
| | 303 | if (@limit_contacts and !grep (/^$c$/, @limit_contacts)) { |
|---|
| | 304 | next; |
|---|
| | 305 | } |
|---|
| | 306 | my $obsess = 0; |
|---|
| | 307 | my $cas = munin_get ($contactobj, "always_send"); |
|---|
| | 308 | if (defined $cas) { |
|---|
| | 309 | $obsess = grep {scalar(@{$stats{$_}})} (split (/\s+/, lc $cas)); |
|---|
| | 310 | } |
|---|
| | 311 | if (!$hash->{'state_changed'} and !$obsess) { |
|---|
| | 312 | next; # No need to send notification |
|---|
| | 313 | } |
|---|
| | 314 | my $precmd = munin_get ($contactobj, "command"); |
|---|
| | 315 | my $pretxt = munin_get ($contactobj, "text", munin_get (munin_get_node ($config, ["contact", "default"]), "text", $default_text{$c} || $default_text{"default"})); |
|---|
| | 316 | my $txt = message_expand ($pretxt, $hash, ""); |
|---|
| | 317 | my $cmd = message_expand ($precmd, $hash, ""); |
|---|
| | 318 | $txt =~ s/\\n/\n/g; |
|---|
| | 319 | $txt =~ s/\\t/\t/g; |
|---|
| | 320 | |
|---|
| | 321 | # In some cases we want to reopen the command |
|---|
| | 322 | my $maxmess = munin_get ($contactobj, "max_messages", 0); |
|---|
| | 323 | my $curmess = munin_get ($contactobj, "num_messages", 0); |
|---|
| | 324 | my $curcmd = munin_get ($contactobj, "pipe_command", undef); |
|---|
| | 325 | my $pipe = munin_get ($contactobj, "pipe", undef); |
|---|
| | 326 | if ($maxmess and $curmess >= $maxmess ) { |
|---|
| | 327 | close ($pipe); |
|---|
| | 328 | $pipe = undef; |
|---|
| | 329 | munin_set_var ($contactobj, "pipe", undef); |
|---|
| | 330 | } elsif ($curcmd and $curcmd ne $cmd) { |
|---|
| | 331 | close ($pipe); |
|---|
| | 332 | $pipe = undef; |
|---|
| | 333 | munin_set_var ($contactobj, "pipe", undef); |
|---|
| | 334 | } |
|---|
| | 335 | |
|---|
| | 336 | if (!defined $pipe) { |
|---|
| | 337 | my @cmd = extract_multiple ( |
|---|
| | 338 | message_expand ($cmd), |
|---|
| | 339 | [ sub { extract_delimited ($_[0], q{"'})}, |
|---|
| | 340 | qr/\S+/ |
|---|
| | 341 | ], |
|---|
| | 342 | undef, 1); |
|---|
| | 343 | @cmd = map { s/['"]$//; s/^['"]//; $_ } @cmd; |
|---|
| | 344 | munin_set_var ($contactobj, "num_messages", 0); |
|---|
| | 345 | if ($cmd[0] eq "|") { |
|---|
| | 346 | $cmd[0] = "|-"; |
|---|
| | 347 | } elsif ($cmd[0] !~ /^[|>]/) { |
|---|
| | 348 | unshift (@cmd, "|-"); |
|---|
| 327 | | if (!$client->{'state_changed'} and !$obsess) |
|---|
| 328 | | { |
|---|
| 329 | | next; |
|---|
| 330 | | } |
|---|
| 331 | | my $precmd = $config->{'contact'}->{$c}->{'command'}; |
|---|
| 332 | | my $pretxt = ($config->{'contact'}->{$c}->{'text'} || $config->{'contact'}->{'default'}->{'text'} || $default_text{$c} || $default_text{'default'}); |
|---|
| 333 | | my $txt = message_expand ($pretxt, $client, ""); |
|---|
| 334 | | my $cmd = message_expand ($precmd, $client, ""); |
|---|
| 335 | | $txt =~ s/\\n/\n/g; |
|---|
| 336 | | $txt =~ s/\\t/\t/g; |
|---|
| 337 | | |
|---|
| 338 | | # In some cases we want to reopen the command |
|---|
| 339 | | if ($config->{'contact'}->{$c}->{'max_messages'} and defined ($config->{'contact'}->{$c}->{'num_messages'}) and |
|---|
| 340 | | $config->{'contact'}->{$c}->{'num_messages'} >= $config->{'contact'}->{$c}->{'max_messages'}) |
|---|
| 341 | | { |
|---|
| 342 | | close ($config->{'contact'}->{$c}->{'pipe'}); |
|---|
| 343 | | $config->{'contact'}->{$c}->{'pipe'} = undef; |
|---|
| 344 | | } |
|---|
| 345 | | elsif (defined ($config->{'contact'}->{$c}->{'pipe_command'}) and |
|---|
| 346 | | $config->{'contact'}->{$c}->{'pipe_command'} ne $cmd) |
|---|
| 347 | | { |
|---|
| 348 | | close ($config->{'contact'}->{$c}->{'pipe'}); |
|---|
| 349 | | $config->{'contact'}->{$c}->{'pipe'} = undef; |
|---|
| 350 | | } |
|---|
| 351 | | |
|---|
| 352 | | my $pipe; |
|---|
| 353 | | if (!defined $config->{'contact'}->{$c}->{'pipe'}) |
|---|
| 354 | | { |
|---|
| 355 | | my @cmd = extract_multiple ( |
|---|
| 356 | | message_expand ($cmd), |
|---|
| 357 | | [ sub { extract_delimited ($_[0], q{"'})}, |
|---|
| 358 | | qr/\S+/ |
|---|
| 359 | | ], |
|---|
| 360 | | undef, 1); |
|---|
| 361 | | @cmd = map { s/['"]$//; s/^['"]//; $_ } @cmd; |
|---|
| 362 | | $config->{'contact'}->{$c}->{'num_messages'} = 0; |
|---|
| 363 | | if ($cmd[0] eq "|") |
|---|
| 364 | | { |
|---|
| 365 | | $cmd[0] = "|-"; |
|---|
| 366 | | } |
|---|
| 367 | | elsif ($cmd[0] !~ /^[|>]/) |
|---|
| 368 | | { |
|---|
| 369 | | unshift (@cmd, "|-"); |
|---|
| | 350 | logger ("Debug: opening for writing: \"" . join('" "',@cmd) . "\".") if $DEBUG; |
|---|
| | 351 | if ($cmd[0] eq ">") { |
|---|
| | 352 | if (! open ($pipe, join (' ', @cmd))) { |
|---|
| | 353 | logger ("Fatal: Could not open " . join (' ', @cmd[1 .. $#cmd]) . " for writing: $!"); |
|---|
| | 354 | exit 3; |
|---|
| 432 | | } |
|---|
| 433 | | $config->{'contact'}->{$c}->{'pipe_command'} = $cmd; |
|---|
| 434 | | $config->{'contact'}->{$c}->{'pipe'} = $pipe; |
|---|
| 435 | | } |
|---|
| 436 | | $pipe = $config->{'contact'}->{$c}->{'pipe'}; |
|---|
| 437 | | logger ("sending message: \"$txt\"") if ($DEBUG); |
|---|
| 438 | | print $pipe $txt, "\n" if (defined $pipe); |
|---|
| 439 | | $config->{'contact'}->{$c}->{'num_messages'}++; |
|---|
| 440 | | } |
|---|
| | 390 | close (STDERR); |
|---|
| | 391 | *STDERR = \$logstderr; |
|---|
| | 392 | |
|---|
| | 393 | exec (@cmd[1 .. $#cmd]) or logger ("Warning: Could not run command \"" . join(' ',@cmd[1 .. $#cmd]) . "\": $!"); |
|---|
| | 394 | exit 5; |
|---|
| | 395 | # NOTREACHED |
|---|
| | 396 | } |
|---|
| | 397 | } |
|---|
| | 398 | munin_set_var ($contactobj, "pipe_command", $cmd); |
|---|
| | 399 | munin_set_var ($contactobj, "pipe", $pipe); |
|---|
| | 400 | } |
|---|
| | 401 | logger ("sending message: \"$txt\"") if ($DEBUG); |
|---|
| | 402 | print $pipe $txt, "\n" if (defined $pipe); |
|---|
| | 403 | munin_set_var ($contactobj, "num_messages", 1 + munin_get ($contactobj, "num_messages", 0)); # $num_messages++ |
|---|
| 546 | | if ($log->opened) |
|---|
| 547 | | { |
|---|
| 548 | | print $log "$now - $comment\n"; |
|---|
| 549 | | } |
|---|
| 550 | | else |
|---|
| 551 | | { |
|---|
| 552 | | if (defined $config->{logdir}) |
|---|
| 553 | | { |
|---|
| 554 | | if (open ($log, ">>$config->{logdir}/munin-graph.log")) |
|---|
| 555 | | { |
|---|
| 556 | | print $log "$now - $comment\n"; |
|---|
| 557 | | $log->flush; |
|---|
| 558 | | close (STDERR); |
|---|
| 559 | | open (STDERR, ">&", $log); |
|---|
| 560 | | } |
|---|
| 561 | | else |
|---|
| 562 | | { |
|---|
| 563 | | print STDERR "Warning: Could not open log file \"$config->{logdir}/munin-graph.log\" for writing: $!"; |
|---|
| 564 | | print STDERR "$now - $comment\n"; |
|---|
| 565 | | } |
|---|
| 566 | | } |
|---|
| 567 | | else |
|---|
| 568 | | { |
|---|
| 569 | | print STDERR "$now - $comment\n"; |
|---|
| 570 | | } |
|---|
| | 492 | if ($log->opened) { |
|---|
| | 493 | print $log "$now - $comment\n"; |
|---|
| | 494 | } else { |
|---|
| | 495 | if (defined $config->{logdir}) { |
|---|
| | 496 | if (open ($log, ">>$config->{logdir}/munin-graph.log")) { |
|---|
| | 497 | print $log "$now - $comment\n"; |
|---|
| | 498 | $log->flush; |
|---|
| | 499 | close (STDERR); |
|---|
| | 500 | open (STDERR, ">&", $log); |
|---|
| | 501 | } else { |
|---|
| | 502 | print STDERR "Warning: Could not open log file \"$config->{logdir}/munin-graph.log\" for writing: $!"; |
|---|
| | 503 | print STDERR "$now - $comment\n"; |
|---|
| | 504 | } |
|---|
| | 505 | } else { |
|---|
| | 506 | print STDERR "$now - $comment\n"; |
|---|
| | 507 | } |
|---|