diff --git a/check_systemdunit b/check_systemdunit index f2fe97f192d75ed78cae54c83acd836799baf993..5ccb9773aafb48fbf09acc4efc95386d361e7f45 100755 --- a/check_systemdunit +++ b/check_systemdunit @@ -9,11 +9,12 @@ # 2020-09-06 v1.2 <axel.hahn@unibe.ch> add param -r to use a regex # 2020-09-18 v1.3 <axel.hahn@unibe.ch> fix: list units --all to show all stopped units # 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 # ================================================================================ . $( dirname $0 )/inc_pluginfunctions -export self_APPVERSION=1.4 +export self_APPVERSION=1.5 # ---------------------------------------------------------------------- # FUNCTIONS @@ -127,13 +128,16 @@ fi # --- check given unit -_status=$( systemctl --no-pager -l status "${_unit}" 2>&1 | tr '|' ':' ) +_data=$( systemctl --no-pager -l status "${_unit}" 2>&1 | tr '|' ':' ) -if ! grep "Active: active (running) " <<< "${_status}" >/dev/null; then +_status=$( echo "$_data" | head -1 | sed "s#^[^a-zA-Z]*##g" ) +if ! grep "Active: active (running) " <<< "${_data}" >/dev/null; then ph.setStatus critical fi ph.status "${_status}" +echo "$_data" | sed -n "2,\$p" | tr -d '└├' | tr '─' '-' + ph.exit # ---------------------------------------------------------------------- diff --git a/docs/20_Checks/check_systemdunit.md b/docs/20_Checks/check_systemdunit.md index da6c2996f779d1dfbb99d41e70544aed30815b88..414b562549fe5b9d5e25a804c3f3e5b393d64970 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.4 +v1.5 (c) Institute for Medical Education - University of Bern Licence: GNU GPL 3 @@ -89,17 +89,17 @@ To check a single service you need to add the unit name in the 1st column. ``$ ./check_systemdunit nginx`` returns ```txt -OK: ● nginx.service - A high performance web server and a reverse proxy server +OK: nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: disabled) - Active: active (running) since Tue 2023-09-05 08:04:45 CEST; 8h ago - Process: 577 ExecStart=/usr/bin/nginx -g pid /run/nginx.pid; error_log stderr; (code=exited, status=0/SUCCESS) - Main PID: 612 (nginx) + Active: active (running) since Fri 2023-10-20 08:04:35 CEST; 3h 14min ago + Process: 783 ExecStart=/usr/bin/nginx (code=exited, status=0/SUCCESS) + Main PID: 787 (nginx) Tasks: 2 (limit: 18881) - Memory: 3.0M - CPU: 38ms + Memory: 3.8M + CPU: 39ms CGroup: /system.slice/nginx.service - ├─612 "nginx: master process /usr/bin/nginx -g pid /run/nginx.pid; error_log stderr;" - └─613 "nginx: worker process" + -787 "nginx: master process /usr/bin/nginx" + -788 "nginx: worker process" ... ```