From 44a9132de46ecc2ea32e80d0cb5fefe5585bc610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germain=20Carr=C3=A9?= Date: Tue, 8 Aug 2023 20:59:04 +0200 Subject: [PATCH] Adding needrestart probe --- README.md | 3 ++- VERSION | 2 +- build/deb/DEBIAN/postinst | 2 +- build/rpm/wigo.spec | 2 +- etc/conf.d/needrestart.conf | 4 +++ probes/examples/needrestart | 53 +++++++++++++++++++++++++++++++++++++ 6 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 etc/conf.d/needrestart.conf create mode 100755 probes/examples/needrestart diff --git a/README.md b/README.md index 048c90e..131c075 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,8 @@ The directory name is the interval of check in seconds ├── hardware_load_average -> ../../probes-examples/hardware_load_average ├── hardware_memory -> ../../probes-examples/hardware_memory ├── ifstat -> ../../probes-examples/ifstat - └── supervisord + ├── supervisord + └── needrestart ``` diff --git a/VERSION b/VERSION index 2d163e5..e266056 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.73.27 +0.73.28 diff --git a/build/deb/DEBIAN/postinst b/build/deb/DEBIAN/postinst index f7bdf31..bbb1587 100755 --- a/build/deb/DEBIAN/postinst +++ b/build/deb/DEBIAN/postinst @@ -3,7 +3,7 @@ echo "Installing WiGO on your system" WIGOPATH="/usr/local/wigo" -EXAMPLEPROBES60=( hardware_load_average hardware_disks hardware_memory ifstat supervisord check_mdadm check_process haproxy lm-sensors iostat check_uptime ) +EXAMPLEPROBES60=( hardware_load_average hardware_disks hardware_memory ifstat supervisord needrestart check_mdadm check_process haproxy lm-sensors iostat check_uptime ) EXAMPLEPROBES300=( smart check_ntp packages-apt ) # Fixing logrotate permissions diff --git a/build/rpm/wigo.spec b/build/rpm/wigo.spec index 94bb7df..05a9557 100644 --- a/build/rpm/wigo.spec +++ b/build/rpm/wigo.spec @@ -95,7 +95,7 @@ rm -rf %{buildroot} %post WIGOPATH="/usr/local/wigo" -EXAMPLEPROBES60=( hardware_load_average hardware_disks hardware_memory ifstat supervisord check_mdadm check_process haproxy lm-sensors iostat check_uptime) +EXAMPLEPROBES60=( hardware_load_average hardware_disks hardware_memory ifstat supervisord needrestart check_mdadm check_process haproxy lm-sensors iostat check_uptime) EXAMPLEPROBES300=( smart check_ntp packages-yum ) # Enabling default probes on 60 directory diff --git a/etc/conf.d/needrestart.conf b/etc/conf.d/needrestart.conf new file mode 100644 index 0000000..3fffe89 --- /dev/null +++ b/etc/conf.d/needrestart.conf @@ -0,0 +1,4 @@ +{ + "enabled" : true, + "needrestart" : "/usr/sbin/needrestart" +} diff --git a/probes/examples/needrestart b/probes/examples/needrestart new file mode 100755 index 0000000..7141306 --- /dev/null +++ b/probes/examples/needrestart @@ -0,0 +1,53 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/../../lib"; +use Wigo::Probe qw/:all/; + +### +# DEFAULT CONFIG +### + +my $conf = { + 'needrestart' => '/usr/sbin/needrestart', +}; + +init( config => $conf ); + +my $needrestart = config->{'needrestart'}; +unless ( -x $needrestart ) +{ + status 403; + message "needrestart $needrestart is not executable"; + output 13; +} + +### +# GET STATUS LIST +### + +my $outNeedRestart = `$needrestart -k -p -l`; +my $returnCode = $?; +if($returnCode == 512) +{ + status 200; + message "Restart needed"; +} +elsif($returnCode) +{ + status 500; + message "Error while getting restart status"; + output 1; +} +else +{ + message "Restart not needed"; +} + +my @lines = split("\n", $outNeedRestart); +detail->{'output'} = $lines[0]; + +output 0;