Skip to content
Snippets Groups Projects
Commit 6507d7d3 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

remove special chars from systemd status

parent dde54092
No related branches found
No related tags found
1 merge request!191remove special chars from systemd status
...@@ -9,11 +9,12 @@ ...@@ -9,11 +9,12 @@
# 2020-09-06 v1.2 <axel.hahn@unibe.ch> add param -r to use a regex # 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.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-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 . $( dirname $0 )/inc_pluginfunctions
export self_APPVERSION=1.4 export self_APPVERSION=1.5
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# FUNCTIONS # FUNCTIONS
...@@ -127,13 +128,16 @@ fi ...@@ -127,13 +128,16 @@ fi
# --- check given unit # --- 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 ph.setStatus critical
fi fi
ph.status "${_status}" ph.status "${_status}"
echo "$_data" | sed -n "2,\$p" | tr -d '└├' | tr '─' '-'
ph.exit ph.exit
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -16,7 +16,7 @@ A unit is everything listed by systemctl command - services, timers, targets, .. ...@@ -16,7 +16,7 @@ A unit is everything listed by systemctl command - services, timers, targets, ..
______________________________________________________________________ ______________________________________________________________________
CHECK_SYSTEMDUNIT CHECK_SYSTEMDUNIT
v1.4 v1.5
(c) Institute for Medical Education - University of Bern (c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3 Licence: GNU GPL 3
...@@ -89,17 +89,17 @@ To check a single service you need to add the unit name in the 1st column. ...@@ -89,17 +89,17 @@ To check a single service you need to add the unit name in the 1st column.
``$ ./check_systemdunit nginx`` returns ``$ ./check_systemdunit nginx`` returns
```txt ```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) 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 Active: active (running) since Fri 2023-10-20 08:04:35 CEST; 3h 14min ago
Process: 577 ExecStart=/usr/bin/nginx -g pid /run/nginx.pid; error_log stderr; (code=exited, status=0/SUCCESS) Process: 783 ExecStart=/usr/bin/nginx (code=exited, status=0/SUCCESS)
Main PID: 612 (nginx) Main PID: 787 (nginx)
Tasks: 2 (limit: 18881) Tasks: 2 (limit: 18881)
Memory: 3.0M Memory: 3.8M
CPU: 38ms CPU: 39ms
CGroup: /system.slice/nginx.service CGroup: /system.slice/nginx.service
├─612 "nginx: master process /usr/bin/nginx -g pid /run/nginx.pid; error_log stderr;" -787 "nginx: master process /usr/bin/nginx"
└─613 "nginx: worker process" -788 "nginx: worker process"
... ...
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment