Skip to content

Commit

Permalink
Merge pull request #37 from pgstef/test-suite-simplify-supported-plat…
Browse files Browse the repository at this point in the history
…forms

Simplify supported platforms and enhance pgBackRest version detection.
  • Loading branch information
pgstef authored Jul 4, 2024
2 parents 0e98dfb + d9f4b80 commit 501e2d0
Show file tree
Hide file tree
Showing 89 changed files with 7,808 additions and 462 deletions.
32 changes: 14 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ on:
workflow_dispatch:

jobs:
use-case-1:
runs-on: ubuntu-20.04
shared-storage:
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
include:
- DOCKERI: rockylinux:8
- DOCKERI: rockylinux:9
DBTYPE: PG
DBVERSION: 16
CLNAME: ro8pg
EXTRA_VARS: "pgbackrest_excpected_release=2.47 check_pgbackrest_build=true"
CLNAME: ro9pg
EXTRA_VARS: "pgbackrest_excpected_release=2.52.1 check_pgbackrest_build=true"

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
path: check_pgbackrest
- uses: shogo82148/actions-setup-perl@v1
Expand All @@ -32,9 +32,7 @@ jobs:

- name: Run CI script
env:
EDB_REPO_USERNAME: ${{ secrets.EDB_REPO_USERNAME }}
EDB_REPO_PASSWORD: ${{ secrets.EDB_REPO_PASSWORD }}
ARCH: use-case-1
ARCH: shared-storage
CLPATH: /home/runner/clusters
CLNAME: ${{ matrix.CLNAME }}
DBTYPE: ${{ matrix.DBTYPE }}
Expand All @@ -45,21 +43,21 @@ jobs:
ACTIVITY: true
run: cd ${HOME?} && sh ${GITHUB_WORKSPACE?}/check_pgbackrest/tests/ci.sh

use-case-2:
runs-on: ubuntu-20.04
with-repo-host:
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
include:
- DOCKERI: ubuntu:20.04
- DOCKERI: ubuntu:22.04
DBTYPE: PG
DBVERSION: 16
CLNAME: u20pg
EXTRA_VARS: "pgbackrest_excpected_release=2.47 check_pgbackrest_build=true"
CLNAME: u22pg
EXTRA_VARS: "pgbackrest_excpected_release=2.52.1 check_pgbackrest_build=true"

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
path: check_pgbackrest
- uses: shogo82148/actions-setup-perl@v1
Expand All @@ -69,9 +67,7 @@ jobs:

- name: Run CI script
env:
EDB_REPO_USERNAME: ${{ secrets.EDB_REPO_USERNAME }}
EDB_REPO_PASSWORD: ${{ secrets.EDB_REPO_PASSWORD }}
ARCH: use-case-2
ARCH: with-repo-host
CLPATH: /home/runner/clusters
CLNAME: ${{ matrix.CLNAME }}
DBTYPE: ${{ matrix.DBTYPE }}
Expand Down
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Changelog
=========

2022-XX-XX v2.4:
2024-XX-XX v2.4:

- ...
- ...
- Only support pgBackRest **2.52** and above to fix issue with new pgBackRest
versioning policy since `2.52.1`. (Reported by netphantm)
- Add new `pgbackrest_version` service, in order to check for a specific
pgBackRest target version.

2022-05-31 v2.3:

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PostgreSQL License

Copyright (c) 2018-2020, DALIBO
Copyright (c) 2020-2022, Stefan Fercot
Copyright (c) 2020-2024, Stefan Fercot

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose, without fee, and without a written agreement is
Expand Down
9 changes: 7 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SYNOPSIS
check_pgbackrest [--help]

DESCRIPTION
check_pgbackrest is designed to monitor pgBackRest (2.33 and above)
check_pgbackrest is designed to monitor pgBackRest (2.52 and above)
backups from Nagios.

-s, --service SERVICE
Expand Down Expand Up @@ -140,6 +140,11 @@ DESCRIPTION

You must provide the expected version using "--target-version".

pgbackrest_version
Check if pgBackRest is running a given version.

You must provide the expected version using "--target-version".

CONTRIBUTING
check_pgbackrest is an open project. Any contribution to improve it is
welcome.
Expand All @@ -156,5 +161,5 @@ AUTHORS

Logo: Damien Cazeils (www.damiencazeils.com).

Copyright: (c) 2018-2020, Dalibo / 2020-2022, Stefan Fercot.
Copyright: (c) 2018-2020, Dalibo / 2020-2024, Stefan Fercot.

10 changes: 8 additions & 2 deletions README.pod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ check_pgbackrest - pgBackRest backup check plugin for Nagios

=head1 DESCRIPTION

check_pgbackrest is designed to monitor pgBackRest (2.33 and above) backups from Nagios.
check_pgbackrest is designed to monitor pgBackRest (2.52 and above) backups from Nagios.

=over

Expand Down Expand Up @@ -162,6 +162,12 @@ Check if this script is running a given version.

You must provide the expected version using C<--target-version>.

=item B<pgbackrest_version>

Check if pgBackRest is running a given version.

You must provide the expected version using C<--target-version>.

=back

=head1 CONTRIBUTING
Expand All @@ -183,5 +189,5 @@ Author: Stefan Fercot.

Logo: Damien Cazeils (www.damiencazeils.com).

Copyright: (c) 2018-2020, Dalibo / 2020-2022, Stefan Fercot.
Copyright: (c) 2018-2020, Dalibo / 2020-2024, Stefan Fercot.

83 changes: 61 additions & 22 deletions check_pgbackrest
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# Author: Stefan Fercot
# Copyright: (c) 2018-2020, Dalibo.
# Copyright: (c) 2020-2022, Stefan Fercot.
# Copyright: (c) 2020-2024, Stefan Fercot.
#-----------------------------------------------------------------------------

=head1 NAME
Expand All @@ -20,7 +20,7 @@ check_pgbackrest - pgBackRest backup check plugin for Nagios
=head1 DESCRIPTION
check_pgbackrest is designed to monitor pgBackRest (2.33 and above) backups from Nagios.
check_pgbackrest is designed to monitor pgBackRest (2.52 and above) backups from Nagios.
=cut

Expand Down Expand Up @@ -63,7 +63,7 @@ my $output_fmt;

$VERSION = '2.4dev';
$PROGRAM = 'check_pgbackrest';
$PGBR_SUPPORT = '2.33';
$PGBR_SUPPORT = '2.52';
$INIT_TIME = time();

# Available services and descriptions.
Expand All @@ -81,9 +81,14 @@ my %services = (
'stanza-arg' => 1
},
'check_pgb_version' => {
'sub' => \&check_pgb_version,
'sub' => \&check_check_pgbackrest_version,
'desc' => 'Check the version of this check_pgbackrest script.',
'stanza-arg' => 0
},
'pgbackrest_version' => {
'sub' => \&check_pgbackrest_version,
'desc' => 'Check the version of pgBackRest.',
'stanza-arg' => 0
}
);

Expand Down Expand Up @@ -548,16 +553,14 @@ sub pgbackrest_info {
}

sub pgbackrest_get {
my $args_ref = shift;
my %args = %{ $args_ref };
my $directory = shift;
my $filename = shift;
my $repo_key = shift;

pod2usage(
-message => 'FATAL: Unsupported pgBackRest version.',
-exitval => 127
) if ( pgbackrest_version(\%args) < $PGBR_SUPPORT );
) if ( pgbackrest_version() lt $PGBR_SUPPORT );

my $getcmd = $args{'command'}." repo-get";
$getcmd .= " --stanza=".$args{'stanza'};
Expand All @@ -582,16 +585,14 @@ sub pgbackrest_get {
}

sub pgbackrest_ls {
my $args_ref = shift;
my %args = %{ $args_ref };
my $directory = shift;
my $repo_key = shift;
my $recurse = shift;

pod2usage(
-message => 'FATAL: Unsupported pgBackRest version.',
-exitval => 127
) if ( pgbackrest_version(\%args) < $PGBR_SUPPORT );
) if ( pgbackrest_version() lt $PGBR_SUPPORT );

my $lscmd = $args{'command'}." repo-ls";
$lscmd .= " --stanza=".$args{'stanza'};
Expand Down Expand Up @@ -622,8 +623,6 @@ sub pgbackrest_ls {
}

sub pgbackrest_version {
my $args_ref = shift;
my %args = %{ $args_ref };
my $version_cmd = $args{'command'}." version";

if(defined $args{'config'}) {
Expand All @@ -635,10 +634,11 @@ sub pgbackrest_version {
}

dprint("pgBackRest version command was : '$version_cmd'\n");
my $pgbackrest_version = `$version_cmd | sed -e s/pgBackRest\\ // | sed -e s/dev//`;
my $pgbackrest_version = `$version_cmd | sed -e s/pgBackRest\\ //`;

die("Can't get pgBackRest version.\nCommand was '$version_cmd'.\n") unless ($? eq 0);

chomp($pgbackrest_version);
return $pgbackrest_version;
}

Expand Down Expand Up @@ -698,7 +698,7 @@ sub check_retention {
foreach my $repo (@{$backups_info->{'repo'}}) {
my $backups_dir = "backup/".$args{'stanza'}; # Relative path inside repository
dprint("repo".$repo->{'key'}.", backups_dir: $backups_dir\n");
$backups_dir_content[$repo->{'key'}] = pgbackrest_ls(\%args, $backups_dir, $repo->{'key'}, 0);
$backups_dir_content[$repo->{'key'}] = pgbackrest_ls($backups_dir, $repo->{'key'}, 0);
}

# List backups per type and check consistency between backup info and real repository content
Expand Down Expand Up @@ -864,7 +864,7 @@ sub get_archived_wal_list {

foreach my $repo_key (keys %{$archives_dir}) {
dprint("repo$repo_key, archives_dir: ".$archives_dir->{$repo_key}."\n");
my $list = pgbackrest_ls(\%args, $archives_dir->{$repo_key}, $repo_key, 1);
my $list = pgbackrest_ls($archives_dir->{$repo_key}, $repo_key, 1);

foreach my $key (keys %{$list}) {
next unless $list->{$key}->{'type'} eq 'file';
Expand Down Expand Up @@ -907,7 +907,7 @@ sub get_archived_wal_list {
# Look for the last history file if needed
dprint("history file to open : ".$archives_dir->{$repo_key}."/$key\n");

my $history_content = pgbackrest_get(\%args, $archives_dir->{$repo_key}, $filename, $repo_key);
my $history_content = pgbackrest_get($archives_dir->{$repo_key}, $filename, $repo_key);
my @history_lines = split /\n/, $history_content;
foreach my $line ( @history_lines ){

Expand Down Expand Up @@ -1222,7 +1222,7 @@ You must provide the expected version using C<--target-version>.
=cut

sub check_pgb_version {
sub check_check_pgbackrest_version {
my $me = 'CHECK_PGBACKREST_VERSION';
my %args = %{ $_[0] };
my @msg;
Expand All @@ -1238,7 +1238,7 @@ sub check_pgb_version {
pod2usage(
-message => "FATAL: given version does not look like a $PROGRAM version!",
-exitval => 127
) if ( defined $args{'target-version'} and $args{'target-version'} !~ m/^\d\.\d+(?:_?(?:dev|beta|rc)\d*)?$/ );
) if ( defined $args{'target-version'} and $args{'target-version'} !~ m/^\d\.\d+(dev)?$/ );

if (defined $args{'target-version'} and $VERSION ne $args{'target-version'}){
push @crit_msg, sprintf("%s version should be %s", $PROGRAM, $args{'target-version'});
Expand All @@ -1252,6 +1252,45 @@ sub check_pgb_version {
return ok( $me, \@msg, \@longmsg );
}

=item B<pgbackrest_version>
Check if pgBackRest is running a given version.
You must provide the expected version using C<--target-version>.
=cut

sub check_pgbackrest_version {
my $me = 'PGBACKREST_VERSION';
my %args = %{ $_[0] };
my @msg;
my @warn_msg;
my @crit_msg;
my @longmsg;

pod2usage(
-message => 'FATAL: you must provide --target-version.',
-exitval => 127
) if not defined $args{'target-version'};

pod2usage(
-message => "FATAL: given version does not look like a pgBackRest version!",
-exitval => 127
) if ( defined $args{'target-version'} and $args{'target-version'} !~ m/^\d\.\d+(\.\d+)?(dev)?$/ );

my $pgbr_version = pgbackrest_version();
if (defined $args{'target-version'} and $pgbr_version ne $args{'target-version'}){
push @crit_msg, sprintf("pgBackRest version should be %s", $args{'target-version'});
push @longmsg, sprintf("pgBackRest version %s, Perl %vd", $pgbr_version, $^V);
}

return critical($me, \@crit_msg, \@longmsg) if @crit_msg;
return warning($me, \@warn_msg, \@longmsg) if @warn_msg;

push @msg, sprintf("pgBackRest version %s, Perl %vd", $pgbr_version, $^V);
return ok( $me, \@msg, \@longmsg );
}

# End of SERVICE section in pod doc
=pod
Expand Down Expand Up @@ -1336,11 +1375,11 @@ foreach( @specific_args ){
) if ( $args{$_} and ( $args{'service'} ne 'archives' or ! $args{'debug'} ));
}

# Check "check_pgb_version" specific arg --target-version
# Check "check_pgb_version" and "pgbackrest_version" specific arg --target-version
pod2usage(
-message => 'FATAL: "target-version" is only allowed with "check_pgb_version" service.',
-message => 'FATAL: "target-version" is only allowed with "check_pgb_version" and "pgbackrest_version" service.',
-exitval => 127
) if $args{'target-version'} and $args{'service'} ne 'check_pgb_version';
) if ( $args{'target-version'} and ( $args{'service'} ne 'check_pgb_version' and $args{'service'} ne 'pgbackrest_version'));

# Output format
for ( $args{'output'} ) {
Expand Down Expand Up @@ -1380,6 +1419,6 @@ Author: Stefan Fercot.
Logo: Damien Cazeils (www.damiencazeils.com).
Copyright: (c) 2018-2020, Dalibo / 2020-2022, Stefan Fercot.
Copyright: (c) 2018-2020, Dalibo / 2020-2024, Stefan Fercot.
=cut
Loading

0 comments on commit 501e2d0

Please sign in to comment.