Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions check_pgactivity
Original file line number Diff line number Diff line change
Expand Up @@ -7670,23 +7670,33 @@ 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: since configuration change or since the 1st time a change was detected?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the first time this particular change was detected.

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.

=cut

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, '*'),
Expand All @@ -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;
Expand Down Expand Up @@ -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" ] );
}
Expand Down Expand Up @@ -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'} ));

Expand Down