Changeset 1496
- Timestamp:
- 02/28/08 22:00:17 (4 years ago)
- Files:
-
- people/jo/multilevel-groups-2/server/Munin.pm.in (modified) (3 diffs)
- people/jo/multilevel-groups-2/server/munin-limits.in (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
people/jo/multilevel-groups-2/server/Munin.pm.in
r1495 r1496 581 581 my $loc = shift; 582 582 583 while (my $tmpvar = shift@$loc) {583 foreach my $tmpvar (@$loc) { 584 584 if ($tmpvar !~ /\S/) { 585 585 ::logger ("Error: munin_get_node: Cannot work on hash node \"$tmpvar\""); … … 587 587 } 588 588 return undef if !exists $hash->{$tmpvar}; 589 return $hash->{$tmpvar} if @$loc <= 0;590 589 $hash = $hash->{$tmpvar}; 591 590 } 591 return $hash; 592 592 } 593 593 … … 716 716 } elsif ($var =~ /^\s*([^;:\.]+)\s*$/) { 717 717 $result = munin_set_var_loc ($hash, [$1], $val); 718 } elsif ($var =~ /^\s*([^:;]+)$/) { 719 my @leftarr = split (/\./, $1); 720 $result = munin_set_var_loc ($hash, [@leftarr], $val); 718 721 } elsif ($var =~ /^\s*(.+)\.([^\.:;]+)$/) { 719 722 my ($leftstring, $rightstring) = ($1, $2); people/jo/multilevel-groups-2/server/munin-limits.in
r1495 r1496 24 24 use Time::HiRes; 25 25 use Text::Balanced qw (extract_multiple extract_delimited extract_quotelike extract_bracketed); 26 use Data::Dumper; 26 27 27 28 my $DEBUG=0; … … 96 97 97 98 if (!defined $config->{'contact'}->{'nagios'}->{'command'} and 98 defined $config->{'nsca'}) 99 { 99 defined $config->{'nsca'}) { 100 100 $config->{'contact'}->{'old-nagios'}->{'command'} = "$config->{nsca} $config->{nsca_server} -c $config->{nsca_config} -to 60"; 101 101 $config->{'contact'}->{'old-nagios'}->{'always_send'} = "critical warning"; 102 102 } 103 if (!defined $config->{'contact'}->{'nagios'}->{'always_send'}) 104 { 103 if (!defined $config->{'contact'}->{'nagios'}->{'always_send'}) { 105 104 $config->{'contact'}->{'nagios'}->{'always_send'} = "critical warning"; 106 105 } 106 107 my $defaultcontacts = munin_get ($config, "contacts", ""); 108 if (!length $defaultcontacts) { 109 my @tmpcontacts = (); 110 foreach my $cont (@{munin_get_children ($config->{"contact"})}) { 111 if (munin_get ($cont, "command")) { 112 push @tmpcontacts, munin_get_node_name ($cont); 113 } 114 } 115 $defaultcontacts = join (' ', @tmpcontacts); 116 } 117 munin_set_var_loc ($config, ["contacts"], $defaultcontacts); 118 logger ("Debug: Set default \"contacts\" to \"$defaultcontacts\"") if $DEBUG; 107 119 108 120 # Make array of what needs to be checked … … 128 140 logger("munin-limits finished ($update_time sec)"); 129 141 130 print Data::Dumper ($work_array);142 #logger ("Dumper: " . Dumper (%notes)); 131 143 132 144 exit 0; … … 155 167 my $warn = munin_get ($field, "warning", undef); 156 168 my $crit = munin_get ($field, "critical", undef); 157 my $ path= munin_get_node_loc ($field);158 my $onfield = munin_get_node ($oldnotes, $ path);169 my $fpath = munin_get_node_loc ($field); 170 my $onfield = munin_get_node ($oldnotes, $fpath); 159 171 160 172 # Skip fields without warning/critical definitions 161 173 next if (!defined $warn and !defined $crit); 162 174 163 logger ("processing field: $fname") if $DEBUG;175 logger ("processing field: ".join ('::', @$fpath)) if $DEBUG; 164 176 next if (@limit_services and !grep (/^$service$/, @limit_services)); 165 177 … … 180 192 $field->{'wrange'} = (defined $warn->[0]?$warn->[0]:"").":".(defined $warn->[1]?$warn->[1]:""); 181 193 182 logger ("value: ". join ('::', @{munin_get_node_loc ($hash)}) ) if $DEBUG;194 logger ("value: ". join ('::', @{munin_get_node_loc ($hash)}) .": $value (crit: $crit->[0]:$crit->[1]) (warn: $warn->[0]:$warn->[1])") if $DEBUG; 183 195 if ($value eq "unknown") { 184 196 $crit->[0] ||= ""; … … 186 198 $hash->{'worst'} = "UNKNOWN" if $hash->{"worst"} eq "OK"; 187 199 $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."));200 munin_set_var_loc (\%notes, [@$fpath, "state"], "unknown"); 201 munin_set_var_loc (\%notes, [@$fpath, "unknown"], (defined $field->{"extinfo"} ? "unknown: " . $field->{"extinfo"} : "Value is unknown.")); 190 202 191 203 if (!defined $onfield or !defined $onfield->{"state"} or $onfield->{"state"} ne "unknown") { 192 $ field->{'state_changed'} = 1;204 $hash->{'state_changed'} = 1; 193 205 } 194 206 } elsif ((defined ($crit->[0]) and $value < $crit->[0]) or … … 198 210 $hash->{'worst'} = "CRITICAL"; 199 211 $hash->{'worstid'} = 2; 200 munin_set_var_loc (\%notes, [ $path, "state"], "critical");201 munin_set_var_loc (\%notes, [ $path, "critical"],212 munin_set_var_loc (\%notes, [@$fpath, "state"], "critical"); 213 munin_set_var_loc (\%notes, [@$fpath, "critical"], 202 214 (defined $field->{"extinfo"}? 203 215 "$value (not in $crit->[0]:$crit->[1]): ". … … 206 218 207 219 if (!defined $onfield or !defined $onfield->{"state"} or $onfield->{"state"} ne "critical") { 208 $ field->{'state_changed'} = 1;220 $hash->{'state_changed'} = 1; 209 221 } 210 222 } elsif ((defined ($warn->[0]) and $value < $warn->[0]) or 211 (defined ($warn->[1]) and $value > $warn->[1])) 212 { 223 (defined ($warn->[1]) and $value > $warn->[1])) { 213 224 $warn->[0] ||= ""; 214 225 $warn->[1] ||= ""; 215 226 $hash->{'worst'} = "WARNING" if $hash->{"worst"} ne "CRITICAL"; 216 227 $hash->{'worstid'} = 1 if $hash->{"worstid"} != 2; 217 munin_set_var_loc (\%notes, [ $path, "state"], "warning");218 munin_set_var_loc (\%notes, [ $path, "warning"],228 munin_set_var_loc (\%notes, [@$fpath, "state"], "warning"); 229 munin_set_var_loc (\%notes, [@$fpath, "warning"], 219 230 (defined $field->{"extinfo"}? 220 231 "$value (not in $warn->[0]:$warn->[1]): ". … … 226 237 } 227 238 } elsif (defined $onfield and defined $onfield->{"state"} or $force) { 228 munin_set_var_loc (\%notes, [ $path, "state"], "ok");229 munin_set_var_loc (\%notes, [ $path, "warning"], "OK");239 munin_set_var_loc (\%notes, [@$fpath, "state"], "ok"); 240 munin_set_var_loc (\%notes, [@$fpath, "ok"], "OK"); 230 241 $hash->{'state_changed'} = 1; 231 242 } … … 273 284 my $worst = $hash->{"worst"}; 274 285 my %stats = ('critical' => [], 'warning' => [], 'unknown' => [], 'foks' => [], 'ok' => []); 275 my $contacts = munin_get_children (munin_get_node ($config, ["contact s"]));286 my $contacts = munin_get_children (munin_get_node ($config, ["contact"])); 276 287 277 288 logger ("generating service message: ". join ('::', @{munin_get_node_loc ($hash)})) if $DEBUG; … … 295 306 $hash->{'numofields'} = scalar @{$stats{'ok'}}; 296 307 297 my $defaultcontacts = join (' ', map { munin_get_node_name ($_) } @$contacts); 298 foreach my $c (split (/\s+/, munin_get ($hash, "contacts", $defaultcontacts))) { 308 my $contactlist = munin_get ($hash, "contacts", ""); 309 logger ("Contact list for ". join ('::', @{munin_get_node_loc ($hash)}) . ": $contactlist"); 310 foreach my $c (split (/\s+/, $contactlist)) { 299 311 next if $c eq "none"; 300 312 my $contactobj = munin_get_node ($config, ["contact", $c]); … … 309 321 $obsess = grep {scalar(@{$stats{$_}})} (split (/\s+/, lc $cas)); 310 322 } 323 logger ("checking if state has changed $c"); 311 324 if (!$hash->{'state_changed'} and !$obsess) { 312 325 next; # No need to send notification 313 326 } 327 logger ("state has changed, notifying $c"); 314 328 my $precmd = munin_get ($contactobj, "command"); 315 329 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, "");330 my $txt = message_expand ($hash, $pretxt, ""); 331 my $cmd = message_expand ($hash, $precmd, ""); 318 332 $txt =~ s/\\n/\n/g; 319 333 $txt =~ s/\\t/\t/g; … … 327 341 close ($pipe); 328 342 $pipe = undef; 329 munin_set_var ($contactobj, "pipe", undef); 343 munin_set_var_loc ($contactobj, ["pipe"], undef); 344 logger ("Debug: Closing \"$c\" -> command (max number of messages reached).") if $DEBUG; 330 345 } elsif ($curcmd and $curcmd ne $cmd) { 331 346 close ($pipe); 332 347 $pipe = undef; 333 munin_set_var ($contactobj, "pipe", undef); 348 munin_set_var_loc ($contactobj, ["pipe"], undef); 349 logger ("Debug: Closing \"$c\" -> command (command has changed).") if $DEBUG; 334 350 } 335 351 336 352 if (!defined $pipe) { 337 353 my @cmd = extract_multiple ( 338 message_expand ($ cmd),354 message_expand ($hash, $cmd), 339 355 [ sub { extract_delimited ($_[0], q{"'})}, 340 356 qr/\S+/ … … 342 358 undef, 1); 343 359 @cmd = map { s/['"]$//; s/^['"]//; $_ } @cmd; 344 munin_set_var ($contactobj, "num_messages", 0);360 $contactobj->{"num_messages"} = 0; 345 361 if ($cmd[0] eq "|") { 346 362 $cmd[0] = "|-"; … … 348 364 unshift (@cmd, "|-"); 349 365 } 350 logger ("Debug: opening for writing: \"" . join('" "',@cmd) . "\".") if $DEBUG;366 logger ("Debug: opening \"$c\" for writing: \"" . join('" "',@cmd) . "\".") if $DEBUG; 351 367 if ($cmd[0] eq ">") { 352 368 if (! open ($pipe, join (' ', @cmd))) { … … 396 412 } 397 413 } 398 munin_set_var ($contactobj, "pipe_command", $cmd); 399 munin_set_var ($contactobj, "pipe", $pipe); 414 logger ("baz?"); 415 munin_set_var_loc ($contactobj, ["pipe_command"], $cmd); 416 munin_set_var_loc ($contactobj, ["pipe"], $pipe); 400 417 } 401 418 logger ("sending message: \"$txt\"") if ($DEBUG); 419 logger ("bar?"); 402 420 print $pipe $txt, "\n" if (defined $pipe); 403 munin_set_var ($contactobj, "num_messages", 1 + munin_get ($contactobj, "num_messages", 0)); # $num_messages++421 $contactobj->{"num_messages"} = 1 + munin_get ($contactobj, "num_messages", 0); # $num_messages++ 404 422 } 405 423 }
