diff --git a/check_pgactivity b/check_pgactivity index e3261a9..b7607f6 100755 --- a/check_pgactivity +++ b/check_pgactivity @@ -7670,9 +7670,12 @@ again with the argument C<--save>. No perfdata. -Critical and Warning thresholds are ignored. +The Critical thresholds is ignored. -A Critical is raised if at least one parameter changed. +Warning is raised when the time since configuration change is less than the +warning threshold. Obviously these alerts will disappear from themselves +once enough time has passed. This doesn't apply for configuration changes with +pending restart warnings. Required privileges: unprivileged role. @@ -7680,13 +7683,20 @@ Required privileges: unprivileged role. sub check_settings { my $me = 'POSTGRES_SETTINGS'; + my $this_msg; + my $now = gettimeofday(); + my $expected_result = 0; # Ok my @long_msg; my @hosts; my @rs; my %settings; + my %settings_laste; + my $settings_lastemsg; + my $settings_lastedate; my %new_settings; my $pending_count = 0; my %args = %{ $_[0] }; + my $w_limit; my %queries = ( $PG_VERSION_90 => q{ SELECT coalesce(r.rolname, '*'), coalesce(d.datname, '*'), @@ -7713,12 +7723,14 @@ sub check_settings { ); @hosts = @{ parse_hosts %args }; + $w_limit = get_time $args{'warning'} if (defined $args{'warning'}); is_compat $hosts[0], 'settings', $PG_VERSION_90 or exit 1; @rs = @{ query_ver( $hosts[0], %queries ) }; %settings = %{ load( $hosts[0], 'settings', $args{'status-file'} ) || {} }; + %settings_laste = %{ load( $hosts[0], 'settings_laste', $args{'status-file'} ) || {} }; # Save settings on the very first call $args{'save'} = 1 unless %settings; @@ -7756,16 +7768,37 @@ PARAM_LOOP: foreach my $row (@rs) { } } + $expected_result = 2 if scalar @long_msg; # Regular warning + $expected_result = 1 if $pending_count > 0; # Pending restart + $this_msg = join('\0', @long_msg); + $settings_lastemsg = $settings_laste{'msg'} // ""; + $settings_lastedate = $settings_laste{'date'} // $now; + + if ( $this_msg ne $settings_lastemsg ) { + $settings_laste{'msg'} = $this_msg; + $settings_laste{'date'} = $now; + save $hosts[0], 'settings_laste', \%settings_laste, $args{'status-file'}; + } else { + my $duration = $now - $settings_lastedate; + + if ( defined $w_limit && $expected_result eq 2 && $duration >= $w_limit ) { + # Should have been a warning but the warning treshold has expired. + # Pending restart changes are not subject to this expiration. + $expected_result = 0; + $args{'save'} = 1; + } + } + if ( $args{'save'} ) { save $hosts[0], 'settings', \%new_settings, $args{'status-file'}; return status_ok( $me, [ "Setting saved" ] ) } return status_warning( $me, [ 'Setting changed and pending restart!' ], undef, \@long_msg ) - if $pending_count > 0; + if $expected_result == 1; return status_warning( $me, [ 'Setting changed!' ], undef, \@long_msg ) - if scalar @long_msg; + if $expected_result == 2; return status_ok( $me, [ "Setting OK" ] ); } @@ -9763,7 +9796,7 @@ pod2usage( pod2usage( -message => 'FATAL: you must provide both warning and critical thresholds.', -exitval => 127 -) if $args{'service'} !~ m/^(pga_version|minor_version|uptime)$/ and ( +) if $args{'service'} !~ m/^(pga_version|minor_version|uptime|settings)$/ and ( ( defined $args{'critical'} and not defined $args{'warning'} ) or ( not defined $args{'critical'} and defined $args{'warning'} ));