Change status type of particular check

Hi Icinga Forum!

I’d like to change the status type of a particular check. It is the check_running_kernel check:

##############################################################################
# Usage     : check_running_kernel( );
# Purpose   : checks if the loaded kernel is the latest available
# Returns   : n/a
# Arguments : n/a
# Throws    : n/a
# Comments  : n/a
# See also  : n/a
sub check_running_kernel {

# return if running in openvz client: /proc/vz is always present but
# /proc/bc only exists on node, but not inside container.
if ( -d '/proc/vz' && !( -d '/proc/bc' ) ) {
    return;
}

if ( !$bootcheck ) {
    return;
}

my $package = 'kernel';

################################################################################
# Running

my ( $sysname, $nodename, $release, $version, $machine ) = POSIX::uname();

$release = clean_kernel_version($release);

verbose "running a Linux kernel: $release\n";

################################################################################
# Installed

	my @versions;

for my $rpm (
    (
        "$package",         "$package-smp",
        "$package-PAE",     "$package-xen",
        "$package-uek",     'ovzkernel',
        'vzkernel',         "$package-PAE-core",
        "$package-ml-aufs", "$package-lt-aufs",
        "$package-core",
    )
  )

{

    my $output;

    #<<<
    my $pid = open $output, q{-|}, "rpm -q $rpm" ## no critic (RequireBriefOpen)
      or exit_with_error( $plugin_module->UNKNOWN,
        "Cannot list installed kernels: $OS_ERROR" );
    #>>>
    # there could be multiple versions of the same package installed
    my @rpm_versions;
    while (<$output>) {
        chomp;
        push @rpm_versions, $_;
    }

    if ( !( close $output ) && ( $OS_ERROR != 0 ) ) {

        # close to a piped open return false if the command with non-zero
        # status. In this case $! is set to 0
        exit_with_error( $plugin_module->UNKNOWN,
            "Error while closing pipe to rpm: $OS_ERROR\n" );

    }

    if ( $CHILD_ERROR == 0 ) {

        # rpm exits with 0 only it the RPM exists

        push @versions, @rpm_versions;

    }

}

for (@versions) {

# strip package name
    s/^$package-//mxs;
    $_ = clean_kernel_version($_);

}

@versions = sort versioncmp @versions;

my $installed = $versions[-1];

if ( !$installed ) {
    $plugin->nagios_exit( $plugin->UNKNOWN,
        'Unable to detect installed kernel' );
}

verbose "kernel: running = $release, installed = $installed\n";

if ( $installed ne $release ) {

    my $error =
"your machine is running kernel $release but a newer version ($installed) is installed: you should reboot";

    if ($exit_message) {
        $exit_message .= $error;
    }
    else {
        $exit_message = $error;
    }

    $wrong_kernel = 1;

}

return;

}

I don’t want that the status is CRITICAL but WARNING, whenever an installed kernel is newer than a running kernel.

Do you know what I have to change in the config?

Thank you very much!

Best regards,
Armin

I Dont see any exit here, you should search your script for $wrong_kernel and see what it does on exit.

Thank you @anon66228339 for the hint. I think this is the relevant section:

 if ( $bootcheck == 2 && $wrong_kernel ) {
            $status = $plugin_module->WARNING;
        }
        elsif ( $bootcheck && $wrong_kernel ) {
            $status = $plugin_module->CRITICAL;
        }

So I will change it to the following and see what happens when the next kernel update will have been installed:

 if ( $bootcheck == 2 && $wrong_kernel ) {
            $status = $plugin_module->WARNING;
        }
        elsif ( $bootcheck && $wrong_kernel ) {
            $status = $plugin_module->WARNING;
        }
1 Like

Found a system with installed new kernel prior to being rebooted, i.e. installed kernel > running kernel.
Changed section as outlined above, the nrestarted nrpe service.

Result: The event is listed below the WARNING events, not below the CRITICAL events anymore, i.e. just like desired!

1 Like