Skip to content
Snippets Groups Projects
check_uptime 2.20 KiB
#!/bin/bash
# ======================================================================
#
# NAGIOS CLIENT CHECK :: show uptime and if automatic update is ON
#
# REQUIREMENTS
# - client uses a cronjob with cronwrapper (it creates parsable logs)
#
# It returns
# - OK in all cases
#
# ----------------------------------------------------------------------
#
# ah=axel.hahn@iml.unibe.ch
# ds=daniel.schueler@iml.unibe.ch
#
# 2018-12-17  v1.0  ah,ds
# 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.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"
self_APPVERSION=1.5


# ----------------------------------------------------------------------
# functions
# ----------------------------------------------------------------------

# 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

# ----------------------------------------------------------------------