diff --git a/check_systemdunit b/check_systemdunit index c54b275cb87e07b297935aa24ec8b9a9b1e826c7..aeb35b1b79e65487bb433a88e4a6be1bc881bfd8 100755 --- a/check_systemdunit +++ b/check_systemdunit @@ -11,11 +11,12 @@ # 2020-09-18 v1.4 <axel.hahn@unibe.ch> replace pipes in systemctl status output # 2020-10-20 v1.5 <axel.hahn@unibe.ch> remove special chars from systemd status # 2020-10-23 v1.6 <axel.hahn@unibe.ch> handle units with multiple instrances +# 2020-11-03 v1.7 <axel.hahn@unibe.ch> autodetect multiple instances without @ char in unit name # ================================================================================ . $( dirname $0 )/inc_pluginfunctions -export self_APPVERSION=1.6 +export self_APPVERSION=1.7 # ---------------------------------------------------------------------- # FUNCTIONS @@ -151,9 +152,8 @@ typeset -i _iActive; _iActive=$( grep -c "Active: active (running) " <<< "${_ if [ $_iActive -eq 0 ]; then ph.setStatus critical else - # when unit contains a @ char and * then check multiple instances of a service - if grep "@\*" <<< "$_unit" >/dev/null; then - typeset -i _iInstances; _iInstances=$( grep -c "Loaded: .*@" <<< "${_data}" ) + typeset -i _iInstances; _iInstances=$( grep -c "Loaded: " <<< "${_data}" ) + if [ $_iInstances -gt 0 ]; then _status="$_iActive of $_iInstances ${_unit} units are active" _out="$_data" diff --git a/docs/20_Checks/check_systemdunit.md b/docs/20_Checks/check_systemdunit.md index 884ccf92fa44f7f1fe5443fee82b15aee96a9c86..3148753531f6734b18421942c6490b3158655cf6 100644 --- a/docs/20_Checks/check_systemdunit.md +++ b/docs/20_Checks/check_systemdunit.md @@ -16,7 +16,7 @@ A unit is everything listed by systemctl command - services, timers, targets, .. ______________________________________________________________________ CHECK_SYSTEMDUNIT -v1.6 +v1.7 (c) Institute for Medical Education - University of Bern Licence: GNU GPL 3 @@ -139,14 +139,14 @@ Here are a few examples for services with regex: ### Check a service with multiple instances -Systemd services with multiple instances contain an @ char. -In the list of the systemctl command the @ char is followed by a number of the instance. +Systemd services with multiple instances can be detected automatically. +In the list of the systemctl command the an instance by a number of the instance in the unit name. #### All instances -To check if all instances are running use ``@*`` at the end of the servicename (like you would do with ``systemctl status myservice@*``). +To check if all instances are running use ``*`` at the end of the servicename (like you would do with ``systemctl status myservice*``). -The command ``check_systemdunit myservice@*`` will return a status line how many active and existing instanecs were found: +The command ``check_systemdunit myservice*`` will return a status line how many active and existing instanecs were found: ```txt OK: 4 of 4 myservice@* units are active @@ -155,6 +155,6 @@ OK: 4 of 4 myservice@* units are active #### A single instance -To check if all instances are running use ``@[number]`` at the end of the servicename. +To check if all instances are running use ``myservice[number]`` at the end of the servicename. -The command ``check_systemdunit myservice@2`` checks the 2nd instance. It is handled like single service check. +The command ``check_systemdunit myservice2`` checks the 2nd instance. It is handled like single service check. diff --git a/inc_pluginfunctions b/inc_pluginfunctions index d21ca196822a00f688de9ef09aa18fab94a8f002..3f64983a8793b37c0a1f954a0b70b99706323170 100644 --- a/inc_pluginfunctions +++ b/inc_pluginfunctions @@ -330,7 +330,7 @@ function ph.toUnit(){ test $_digits -gt 0 && _dots=$( yes "." 2>/dev/null | head -$_digits | tr -d "\n" ) test $_digits -gt 0 && _bc+=" -l | grep -o '.*\\.${_dots}'" - echo "$(echo "$_value" | tr -d "[:alpha:]" )*${_multiply}/$_divisor" | eval "$_bc" | sed "s#^\.#0.#" + echo "$(echo "$_value" | tr -d "[:alpha:]" )*( ${_multiply}/$_divisor )" | eval "$_bc" | sed "s#^\.#0.#" }