@@ -7670,23 +7670,33 @@ again with the argument C<--save>.
76707670
76717671No perfdata.
76727672
7673- Critical and Warning thresholds are ignored.
7673+ The Critical thresholds is ignored.
76747674
7675- A Critical is raised if at least one parameter changed.
7675+ Warning is raised when the time since configuration change is less than the
7676+ warning threshold. Obviously these alerts will disappear from themselves
7677+ once enough time has passed. This doesn't apply for configuration changes with
7678+ pending restart warnings.
76767679
76777680Required privileges: unprivileged role.
76787681
76797682=cut
76807683
76817684sub check_settings {
76827685 my $me = ' POSTGRES_SETTINGS' ;
7686+ my $this_msg ;
7687+ my $now = gettimeofday();
7688+ my $expected_result = 0; # Ok
76837689 my @long_msg ;
76847690 my @hosts ;
76857691 my @rs ;
76867692 my %settings ;
7693+ my %settings_laste ;
7694+ my $settings_lastemsg ;
7695+ my $settings_lastedate ;
76877696 my %new_settings ;
76887697 my $pending_count = 0;
76897698 my %args = %{ $_ [0] };
7699+ my $w_limit ;
76907700 my %queries = (
76917701 $PG_VERSION_90 => q{
76927702 SELECT coalesce(r.rolname, '*'), coalesce(d.datname, '*'),
@@ -7713,12 +7723,14 @@ sub check_settings {
77137723 );
77147724
77157725 @hosts = @{ parse_hosts %args };
7726+ $w_limit = get_time $args {' warning' } if (defined $args {' warning' });
77167727
77177728 is_compat $hosts [0], ' settings' , $PG_VERSION_90 or exit 1;
77187729
77197730 @rs = @{ query_ver( $hosts [0], %queries ) };
77207731
77217732 %settings = %{ load( $hosts [0], ' settings' , $args {' status-file' } ) || {} };
7733+ %settings_laste = %{ load( $hosts [0], ' settings_laste' , $args {' status-file' } ) || {} };
77227734
77237735 # Save settings on the very first call
77247736 $args {' save' } = 1 unless %settings ;
@@ -7756,16 +7768,37 @@ PARAM_LOOP: foreach my $row (@rs) {
77567768 }
77577769 }
77587770
7771+ $expected_result = 2 if scalar @long_msg ; # Regular warning
7772+ $expected_result = 1 if $pending_count > 0; # Pending restart
7773+ $this_msg = join (' \0' , @long_msg );
7774+ $settings_lastemsg = $settings_laste {' msg' } // " " ;
7775+ $settings_lastedate = $settings_laste {' date' } // $now ;
7776+
7777+ if ( $this_msg ne $settings_lastemsg ) {
7778+ $settings_laste {' msg' } = $this_msg ;
7779+ $settings_laste {' date' } = $now ;
7780+ save $hosts [0], ' settings_laste' , \%settings_laste , $args {' status-file' };
7781+ } else {
7782+ my $duration = $now - $settings_lastedate ;
7783+
7784+ if ( defined $w_limit && $expected_result eq 2 && $duration >= $w_limit ) {
7785+ # Should have been a warning but the warning treshold has expired.
7786+ # Pending restart changes are not subject to this expiration.
7787+ $expected_result = 0;
7788+ $args {' save' } = 1;
7789+ }
7790+ }
7791+
77597792 if ( $args {' save' } ) {
77607793 save $hosts [0], ' settings' , \%new_settings , $args {' status-file' };
77617794 return status_ok( $me , [ " Setting saved" ] )
77627795 }
77637796
77647797 return status_warning( $me , [ ' Setting changed and pending restart!' ], undef , \@long_msg )
7765- if $pending_count > 0 ;
7798+ if $expected_result == 1 ;
77667799
77677800 return status_warning( $me , [ ' Setting changed!' ], undef , \@long_msg )
7768- if scalar @long_msg ;
7801+ if $expected_result == 2 ;
77697802
77707803 return status_ok( $me , [ " Setting OK" ] );
77717804}
@@ -9763,7 +9796,7 @@ pod2usage(
97639796pod2usage(
97649797 -message => ' FATAL: you must provide both warning and critical thresholds.' ,
97659798 -exitval => 127
9766- ) if $args {' service' } !~ m / ^(pga_version|minor_version|uptime)$ / and (
9799+ ) if $args {' service' } !~ m / ^(pga_version|minor_version|uptime|settings )$ / and (
97679800 ( defined $args {' critical' } and not defined $args {' warning' } )
97689801 or ( not defined $args {' critical' } and defined $args {' warning' } ));
97699802
0 commit comments