From 267283edf656c7bde9d074071e56b6ef70ccae1d Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Wed, 19 Feb 2025 17:09:19 +0100 Subject: [PATCH] add help: remove IML specific check for auto updates; add idletime; add markdown help page --- check_uptime | 70 +++++++++++++++++++++++++--------- docs/20_Checks/_index.md | 2 +- docs/20_Checks/check_uptime.md | 62 ++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 20 deletions(-) create mode 100644 docs/20_Checks/check_uptime.md diff --git a/check_uptime b/check_uptime index 2310c95..d160254 100755 --- a/check_uptime +++ b/check_uptime @@ -18,36 +18,68 @@ # 2020-03-05 v1.1 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions # 2020-03-10 v1.2 <axel.hahn@iml.unibe.ch> add performance data # 2020-07-02 v1.3 <axel.hahn@iml.unibe.ch> use sec for performance data -# 2022-10-21 v1.3 <axel.hahn@unibe.ch> remove grep: warning: stray \ before white space +# 2022-10-21 v1.4 <axel.hahn@unibe.ch> remove grep: warning: stray \ before white space +# 2025-02-19 v1.5 <axel.hahn@unibe.ch> add help: remove IML specific check for auto updates; add idletime # ====================================================================== -. `dirname $0`/inc_pluginfunctions -cronfile=/etc/cron.d/system-updater +. "$( dirname "$0" )/inc_pluginfunctions" +self_APPVERSION=1.5 + # ---------------------------------------------------------------------- -# MAIN +# functions # ---------------------------------------------------------------------- -iSecUp=`cat /proc/uptime | awk '{print $1}'` -echo "Uptime: `uptime | awk '{ print $3 " days " $5 " h"}' | tr -d ","` ... $iSecUp sec" - -# --- status of auto update (IML specific) -ls ${cronfile} >/dev/null 2>&1 -if [ $? -eq 0 ]; then - echo Autoupdate ON - grep -- " -r" ${cronfile} >/dev/null 2>&1 - if [ $? -eq 0 ]; then - echo Autoreboot ON - else - echo Autoreboot OFF - fi -else - echo Autoupdate OFF +# show help text +function showHelp(){ + local _self; _self=$(basename $0) +cat <<EOF +$( ph.showImlHelpHeader ) + +Show uptime and idle time. +The script sends performance data withvalues in seconds. + +SYNTAX: + + $_self [-h] + +OPTIONS: + + -h or --help show this help. + +PARAMETERS: + + None. + +EOF +} + +# ---------------------------------------------------------------------- +# check params +# ---------------------------------------------------------------------- + +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + showHelp + exit 0; +fi + +if [ -n "$*" ]; then + echo "ERROR: no parameter expected." + exit 1 fi +# ---------------------------------------------------------------------- +# MAIN +# ---------------------------------------------------------------------- + +iSecUp=$( cat /proc/uptime | awk '{print $1}' ) +iSecIdle=$( cat /proc/uptime | awk '{print $2}' ) +echo "Uptime: $( uptime ) ... up: $iSecUp sec ... idle: $iSecIdle sec" + # --- add performance data ph.perfadd uptime $iSecUp +ph.perfadd idletime $iSecIdle ph.exit diff --git a/docs/20_Checks/_index.md b/docs/20_Checks/_index.md index f79f96c..e1ba906 100644 --- a/docs/20_Checks/_index.md +++ b/docs/20_Checks/_index.md @@ -52,5 +52,5 @@ * check_systemdservices * [check_systemdunit](check_systemdunit.md) * [check_timesync](check_timesync.md) -* check_uptime +* [check_uptime](check_uptime.md) * hello diff --git a/docs/20_Checks/check_uptime.md b/docs/20_Checks/check_uptime.md new file mode 100644 index 0000000..b4277ec --- /dev/null +++ b/docs/20_Checks/check_uptime.md @@ -0,0 +1,62 @@ +## Check uptime + +Script: `check_uptime` + +**check_uptime** is a plugin to show uptime and idle time of a system. +It reads the counters from `/proc/uptime` and show the output of `upime` command. + +## Requirements + +Nothing special. + +## Standalone installation + +From this repository ypu need next to this script: + +* `inc_pluginfunctions` shared function for all IML checks written in bash + +## Syntax + +Start the script with `-h` or `--help` to get the help. + +```txt +______________________________________________________________________ + +CHECK_UPTIME +v1.5 + +(c) Institute for Medical Education - University of Bern +Licence: GNU GPL 3 + +https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_uptime.html +______________________________________________________________________ + +Show uptime and idle time. +The script sends performance data withvalues in seconds. + +SYNTAX: + + check_uptime [-h] + +OPTIONS: + + -h or --help show this help. + +PARAMETERS: + + None. + +``` + +## Examples + +No parameter is needed. + +`./check_uptime` + +returns + +```txt +Uptime: 17:03:41 up 8:23, 1 user, load average: 2.40, 1.92, 1.61 ... up: 30203.20 sec ... idle: 447821.43 sec + |uptime=30203.20;; idletime=447821.43;; + ``` -- GitLab