Add Bionic compatibility for the NRPE scripts via libmonitoring.

From Bionic onwards, libnagios is replaced by libmonitoring. Trusty only
contains the former, Bionic only the latter. Xenial contains both, but
we prefer libmonitoring where it exists, so that we can drop libnagios
support entirely once Trusty goes EOL.

Change-Id: I613fd0b29b797e8900581f939eda72a1ab72868b
Closes-Bug: 1796143
This commit is contained in:
Barry Price 2018-12-20 22:34:34 +07:00
parent 2ca245127e
commit 600ba322fa
No known key found for this signature in database
GPG Key ID: 2387DE5D0184DA32
3 changed files with 103 additions and 43 deletions

View File

@ -20,10 +20,11 @@
# Authors: Phil Garner - phil@sysnix.com & Peter Mottram peter@sysnix.com # Authors: Phil Garner - phil@sysnix.com & Peter Mottram peter@sysnix.com
# #
# v0.1 05/01/2011 # v0.1 05/01/2011
# v0.2 31/10/2011 - additional crit when closing the file handle and additional # v0.2 31/10/2011 - additional crit when closing the file handle and additional
# comments added # comments added
# #
# NOTE:- Requires Perl 5.8 or higher & the Perl Module Nagios::Plugin # NOTE:- Requires Perl 5.8 or higher & either the Perl Module Nagios::Plugin
# or Monitoring::Plugin, whichever is available for your system.
# Nagios user will need sudo acces - suggest adding line below to # Nagios user will need sudo acces - suggest adding line below to
# sudoers. # sudoers.
# nagios ALL=(ALL) NOPASSWD: /usr/sbin/corosync-cfgtool -s # nagios ALL=(ALL) NOPASSWD: /usr/sbin/corosync-cfgtool -s
@ -35,7 +36,23 @@
use warnings; use warnings;
use strict; use strict;
use Nagios::Plugin;
my $plugin_provider='';
my $rc = eval {
require Monitoring::Plugin;
Monitoring::Plugin->import();
1;
};
if ($rc)
{
$plugin_provider = 'Monitoring';
} else{
require Nagios::Plugin;
Nagios::Plugin->import();
$plugin_provider = 'Nagios';
}
# Lines below may need changing if corosync-cfgtool or sudo installed in a # Lines below may need changing if corosync-cfgtool or sudo installed in a
# diffrent location. # diffrent location.
@ -44,15 +61,28 @@ my $sudo = '/usr/bin/sudo';
my $cfgtool = '/usr/sbin/corosync-cfgtool -s'; my $cfgtool = '/usr/sbin/corosync-cfgtool -s';
# Now set up the plugin # Now set up the plugin
my $np = Nagios::Plugin->new( my $np;
shortname => 'check_cororings', if ($plugin_provider eq 'Monitoring') {
version => '0.2', $np = Monitoring::Plugin->new(
usage => "Usage: %s <ARGS>\n\t\t--help for help\n", shortname => 'check_cororings',
license => "License - GPL v3 see code for more details", version => '0.2',
url => "http://www.sysnix.com", usage => "Usage: %s <ARGS>\n\t\t--help for help\n",
blurb => license => "License - GPL v3 see code for more details",
"\tNagios plugin that checks the status of corosync rings, requires Perl \t5.8+ and CPAN modules Nagios::Plugin.", url => "http://www.sysnix.com",
); blurb =>
"\tMonitoring plugin that checks the status of corosync rings, requires Perl \t5.8+ and CPAN modules Monitoring::Plugin.",
);
} else {
$np = Nagios::Plugin->new(
shortname => 'check_cororings',
version => '0.2',
usage => "Usage: %s <ARGS>\n\t\t--help for help\n",
license => "License - GPL v3 see code for more details",
url => "http://www.sysnix.com",
blurb =>
"\tNagios plugin that checks the status of corosync rings, requires Perl \t5.8+ and CPAN modules Nagios::Plugin.",
);
}
#Args #Args
$np->add_arg( $np->add_arg(
@ -71,29 +101,29 @@ my $rings = $np->opts->rings;
# Run cfgtools spin through output and get info needed # Run cfgtools spin through output and get info needed
open( $fh, "$sudo $cfgtool |" ) open( $fh, "$sudo $cfgtool |" )
or $np->nagios_exit( CRITICAL, "Running corosync-cfgtool failed" ); or $np->nagios_exit("CRITICAL", "Running corosync-cfgtool failed" );
foreach my $line (<$fh>) { foreach my $line (<$fh>) {
if ( $line =~ m/status\s*=\s*(\S.+)/ ) { if ( $line =~ m/status\s*=\s*(\S.+)/ ) {
my $status = $1; my $status = $1;
if ( $status =~ m/^ring (\d+) active with no faults/ ) { if ( $status =~ m/^ring (\d+) active with no faults/ ) {
$np->add_message( OK, "ring $1 OK" ); $np->add_message("OK", "ring $1 OK" );
} }
else { else {
$np->add_message( CRITICAL, $status ); $np->add_message("CRITICAL", $status );
} }
$found++; $found++;
} }
} }
close($fh) or $np->nagios_exit( CRITICAL, "Running corosync-cfgtool failed" ); close($fh) or $np->nagios_exit("CRITICAL", "Running corosync-cfgtool failed" );
# Check we found some rings and apply -r arg if needed # Check we found some rings and apply -r arg if needed
if ( $found == 0 ) { if ( $found == 0 ) {
$np->nagios_exit( CRITICAL, "No Rings Found" ); $np->nagios_exit("CRITICAL", "No Rings Found" );
} }
elsif ( defined $rings && $rings != $found ) { elsif ( defined $rings && $rings != $found ) {
$np->nagios_exit( CRITICAL, "Expected $rings rings but found $found" ); $np->nagios_exit("CRITICAL", "Expected $rings rings but found $found" );
} }
$np->nagios_exit( $np->check_messages() ); $np->nagios_exit( $np->check_messages() );

View File

@ -28,11 +28,12 @@
# v0.6 14/03/2013 - Change from \w+ to \S+ in stopped check to cope with # v0.6 14/03/2013 - Change from \w+ to \S+ in stopped check to cope with
# Servers that have non word charachters in. Suggested by # Servers that have non word charachters in. Suggested by
# Igal Baevsky. # Igal Baevsky.
# v0.7 01/09/2013 - In testing as still not fully tested. Adds optional # v0.7 01/09/2013 - In testing as still not fully tested. Adds optional
# constraints check (Boris Wesslowski). Adds fail count # constraints check (Boris Wesslowski). Adds fail count
# threshold ( Zoran Bosnjak & Marko Hrastovec ) # threshold ( Zoran Bosnjak & Marko Hrastovec )
# #
# NOTES: Requires Perl 5.8 or higher & the Perl Module Nagios::Plugin # NOTE:- Requires Perl 5.8 or higher & either the Perl Module Nagios::Plugin
# or Monitoring::Plugin, whichever is available for your system.
# Nagios user will need sudo acces - suggest adding line below to # Nagios user will need sudo acces - suggest adding line below to
# sudoers # sudoers
# nagios ALL=(ALL) NOPASSWD: /usr/sbin/crm_mon -1 -r -f # nagios ALL=(ALL) NOPASSWD: /usr/sbin/crm_mon -1 -r -f
@ -47,7 +48,24 @@
use warnings; use warnings;
use strict; use strict;
use Nagios::Plugin;
my $plugin_provider='';
my $rc = eval {
require Monitoring::Plugin;
Monitoring::Plugin->import();
1;
};
if ($rc)
{
$plugin_provider = 'Monitoring';
} else{
require Nagios::Plugin;
Nagios::Plugin->import();
$plugin_provider = 'Nagios';
}
# Lines below may need changing if crm_mon or sudo installed in a # Lines below may need changing if crm_mon or sudo installed in a
# different location. # different location.
@ -56,11 +74,20 @@ my $sudo = '/usr/bin/sudo';
my $crm_mon = '/usr/sbin/crm_mon -1 -r -f'; my $crm_mon = '/usr/sbin/crm_mon -1 -r -f';
my $crm_configure_show = '/usr/sbin/crm configure show'; my $crm_configure_show = '/usr/sbin/crm configure show';
my $np = Nagios::Plugin->new( my $np;
shortname => 'check_crm', if ($plugin_provider eq 'Monitoring') {
version => '0.7', $np = Monitoring::Plugin->new(
usage => "Usage: %s <ARGS>\n\t\t--help for help\n", shortname => 'check_crm',
); version => '0.7',
usage => "Usage: %s <ARGS>\n\t\t--help for help\n",
);
} else {
$np = Nagios::Plugin->new(
shortname => 'check_crm',
version => '0.7',
usage => "Usage: %s <ARGS>\n\t\t--help for help\n",
);
}
$np->add_arg( $np->add_arg(
spec => 'warning|w', spec => 'warning|w',
@ -100,14 +127,14 @@ $warn_or_crit = 'WARNING' if $np->opts->warning;
my $fh; my $fh;
open( $fh, "$sudo $crm_mon |" ) open( $fh, "$sudo $crm_mon |" )
or $np->nagios_exit( CRITICAL, "Running $sudo $crm_mon has failed" ); or $np->nagios_exit("CRITICAL", "Running $sudo $crm_mon has failed" );
foreach my $line (<$fh>) { foreach my $line (<$fh>) {
if ( $line =~ m/Connection to cluster failed\:(.*)/i ) { if ( $line =~ m/Connection to cluster failed\:(.*)/i ) {
# Check Cluster connected # Check Cluster connected
$np->nagios_exit( CRITICAL, "Connection to cluster FAILED: $1" ); $np->nagios_exit("CRITICAL", "Connection to cluster FAILED: $1" );
} }
elsif ( $line =~ m/Current DC:/ ) { elsif ( $line =~ m/Current DC:/ ) {
@ -116,10 +143,10 @@ foreach my $line (<$fh>) {
# Assume cluster is OK - we only add warn/crit after here # Assume cluster is OK - we only add warn/crit after here
$np->add_message( OK, "Cluster OK" ); $np->add_message("OK", "Cluster OK" );
} }
else { else {
$np->add_message( CRITICAL, "No Quorum" ); $np->add_message("CRITICAL", "No Quorum" );
} }
} }
elsif ( $line =~ m/^offline:\s*\[\s*(\S.*?)\s*\]/i ) { elsif ( $line =~ m/^offline:\s*\[\s*(\S.*?)\s*\]/i ) {
@ -149,25 +176,25 @@ foreach my $line (<$fh>) {
elsif ( $line =~ m/^Failed actions\:/ ) { elsif ( $line =~ m/^Failed actions\:/ ) {
# Check Failed Actions # Check Failed Actions
$np->add_message( CRITICAL, $np->add_message("CRITICAL",
": FAILED actions detected or not cleaned up" ); ": FAILED actions detected or not cleaned up" );
} }
elsif ( $line =~ m/\s*(\S+?)\s+ \(.*\)\:\s+\w+\s+\w+\s+\(unmanaged\)\s+/i ) elsif ( $line =~ m/\s*(\S+?)\s+ \(.*\)\:\s+\w+\s+\w+\s+\(unmanaged\)\s+/i )
{ {
# Check Unmanaged # Check Unmanaged
$np->add_message( CRITICAL, ": $1 unmanaged FAILED" ); $np->add_message("CRITICAL", ": $1 unmanaged FAILED" );
} }
elsif ( $line =~ m/\s*(\S+?)\s+ \(.*\)\:\s+not installed/i ) { elsif ( $line =~ m/\s*(\S+?)\s+ \(.*\)\:\s+not installed/i ) {
# Check for errors # Check for errors
$np->add_message( CRITICAL, ": $1 not installed" ); $np->add_message("CRITICAL", ": $1 not installed" );
} }
elsif ( $line =~ m/\s*(\S+?):.*fail-count=(\d+)/i ) { elsif ( $line =~ m/\s*(\S+?):.*fail-count=(\d+)/i ) {
if ( $2 >= $np->opts->failcount ) { if ( $2 >= $np->opts->failcount ) {
# Check for resource Fail count (suggested by Vadym Chepkov) # Check for resource Fail count (suggested by Vadym Chepkov)
$np->add_message( WARNING, ": $1 failure detected, fail-count=$2" ); $np->add_message("WARNING", ": $1 failure detected, fail-count=$2" );
} }
} }
} }
@ -178,23 +205,23 @@ if ( scalar @standby > 0 && !$np->opts->standbyignore ) {
": " . join( ', ', @standby ) . " in Standby" ); ": " . join( ', ', @standby ) . " in Standby" );
} }
close($fh) or $np->nagios_exit( CRITICAL, "Running $crm_mon FAILED" ); close($fh) or $np->nagios_exit("CRITICAL", "Running $crm_mon FAILED" );
# if -c flag set check configuration for constraints # if -c flag set check configuration for constraints
if ($ConstraintsFlag) { if ($ConstraintsFlag) {
open( $fh, "$sudo $crm_configure_show|" ) open( $fh, "$sudo $crm_configure_show|" )
or $np->nagios_exit( CRITICAL, or $np->nagios_exit("CRITICAL",
"Running $sudo $crm_configure_show has failed" ); "Running $sudo $crm_configure_show has failed" );
foreach my $line (<$fh>) { foreach my $line (<$fh>) {
if ( $line =~ m/location cli-(prefer|standby)-\S+\s+(\S+)/ ) { if ( $line =~ m/location cli-(prefer|standby)-\S+\s+(\S+)/ ) {
$np->add_message( WARNING, $np->add_message("WARNING",
": $2 blocking location constraint detected" ); ": $2 blocking location constraint detected" );
} }
} }
close($fh) close($fh)
or $np->nagios_exit( CRITICAL, "Running $crm_configure_show FAILED" ); or $np->nagios_exit("CRITICAL", "Running $crm_configure_show FAILED" );
} }
$np->nagios_exit( $np->check_messages() ); $np->nagios_exit( $np->check_messages() );

View File

@ -105,7 +105,8 @@ COROSYNC_CONF_FILES = [
] ]
PACKAGES = ['crmsh', 'corosync', 'pacemaker', 'python-netaddr', 'ipmitool', PACKAGES = ['crmsh', 'corosync', 'pacemaker', 'python-netaddr', 'ipmitool',
'libnagios-plugin-perl', 'python3-requests-oauthlib'] 'libmonitoring-plugin-perl', 'python3-requests-oauthlib']
SUPPORTED_TRANSPORTS = ['udp', 'udpu', 'multicast', 'unicast'] SUPPORTED_TRANSPORTS = ['udp', 'udpu', 'multicast', 'unicast']
DEPRECATED_TRANSPORT_VALUES = {"multicast": "udp", "unicast": "udpu"} DEPRECATED_TRANSPORT_VALUES = {"multicast": "udp", "unicast": "udpu"}
@ -113,9 +114,10 @@ DEPRECATED_TRANSPORT_VALUES = {"multicast": "udp", "unicast": "udpu"}
@hooks.hook('install.real') @hooks.hook('install.real')
def install(): def install():
ubuntu_release = lsb_release()['DISTRIB_CODENAME'].lower() ubuntu_release = lsb_release()['DISTRIB_CODENAME'].lower()
if CompareHostReleases(ubuntu_release) >= 'zesty': # use libnagios on anything older than Xenial
PACKAGES.remove('libnagios-plugin-perl') if CompareHostReleases(ubuntu_release) < 'xenial':
PACKAGES.append('libnagios-object-perl') PACKAGES.remove('libmonitoring-plugin-perl')
PACKAGES.append('libnagios-plugin-perl')
# NOTE(dosaboy): we currently disallow upgrades due to bug #1382842. This # NOTE(dosaboy): we currently disallow upgrades due to bug #1382842. This
# should be removed once the pacemaker package is fixed. # should be removed once the pacemaker package is fixed.
status_set('maintenance', 'Installing apt packages') status_set('maintenance', 'Installing apt packages')
@ -447,6 +449,7 @@ def stop():
def update_nrpe_config(): def update_nrpe_config():
scripts_src = os.path.join(os.environ["CHARM_DIR"], "files", scripts_src = os.path.join(os.environ["CHARM_DIR"], "files",
"nrpe") "nrpe")
scripts_dst = "/usr/local/lib/nagios/plugins" scripts_dst = "/usr/local/lib/nagios/plugins"
if not os.path.exists(scripts_dst): if not os.path.exists(scripts_dst):
os.makedirs(scripts_dst) os.makedirs(scripts_dst)