Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icinga-checks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Commits
af1c1137
Commit
af1c1137
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
updatte check_systemdunit
parent
84b4fb05
No related branches found
No related tags found
1 merge request
!162
check_http first lines
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
check_systemdunit
+39
-17
39 additions, 17 deletions
check_systemdunit
docs/20_Checks/check_systemdunit.md
+40
-4
40 additions, 4 deletions
docs/20_Checks/check_systemdunit.md
with
79 additions
and
21 deletions
check_systemdunit
+
39
−
17
View file @
af1c1137
...
...
@@ -3,23 +3,14 @@
#
# CHECK A SINGLE SYSTEMD SERVICE
#
# (1)
# shows overview of important services - edit check_systemdservices.cfg to define
# them
#
# (2)
# resturns
# - OK if all systemd servises are running
# - UNKNOWN if systemctl command is not available
# - ERROR if any systemd service is not running
#
# -------------------------------------------------------------------------------
# 2023-09-05 v01.0 <axel.hahn@unibe.ch>
# 2023-09-05 v1.0 <axel.hahn@unibe.ch>
# 2020-09-08 v1.1 <axel.hahn@unibe.ch> add params -s, -l
# ================================================================================
.
$(
dirname
$0
)
/inc_pluginfunctions
export
self_APPVERSION
=
1.
0
export
self_APPVERSION
=
1.
1
# ----------------------------------------------------------------------
# FUNCTIONS
...
...
@@ -37,16 +28,24 @@ The status is unknown if the command systemctl is not found.
The status is critical if the service does not exist or is not running.
SYNTAX:
$_self
[-h] UNIT
$_self
[-h
|-l|-s
] UNIT
OPTIONS:
-h this help
-l list all units
-s list service units
UNIT Name of a unit - see output of 'systemctl'
EXAMPLES:
$_self
mysql.service
show status of service mysql
$_self
-s
list all existing services. For a unit check you need to add the name
in the 1st column.
$_self
nginx.service
show status of nginx webservice
EOF
}
...
...
@@ -64,8 +63,31 @@ fi
ph.require
"systemctl"
_service
=
"
${
1
}
"
_status
=
$(
systemctl
--no-pager
-l
status
"
${
_service
}
"
2>&1
)
# --- list all units
if
ph.hasParamoption
"l"
"
$@
"
;
then
echo
"List of all systemd units:"
echo
_list
=
$(
systemctl
--no-legend
--no-pager
)
for
mytype
in
$(
awk
'{ print $1 }'
<<<
"
$_list
"
|
grep
'\.'
| rev|
cut
-f
1
-d
'.'
| rev |
grep
-v
'[^a-z]'
|
sort
-u
)
do
echo
"----------
$mytype
"
grep
"
\.
${
mytype
}
"
<<<
"
$_list
"
echo
done
exit
0
fi
# --- list service units
if
ph.hasParamoption
"s"
"
$@
"
;
then
echo
"List of service units:"
echo
systemctl
--no-legend
--no-pager
--type
service
exit
0
fi
# --- check given unit
_unit
=
"
${
1
}
"
_status
=
$(
systemctl
--no-pager
-l
status
"
${
_unit
}
"
2>&1
)
if
!
grep
"Active: active (running) "
<<<
"
${
_status
}
"
>
/dev/null
;
then
ph.setStatus critical
...
...
This diff is collapsed.
Click to expand it.
docs/20_Checks/check_systemdunit.md
+
40
−
4
View file @
af1c1137
...
...
@@ -16,7 +16,7 @@ A unit is everything listed by systemctl command - services, timers, targets, ..
______________________________________________________________________
CHECK_SYSTEMDUNIT
v1.
0
v1.
1
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
...
...
@@ -30,21 +30,53 @@ The status is unknown if the command systemctl is not found.
The status is critical if the service does not exist or is not running.
SYNTAX:
check_systemdunit [-h] UNIT
check_systemdunit [-h
|-l|-s
] UNIT
OPTIONS:
-h this help
-l list all units
-s list service units
UNIT Name of a unit - see output of 'systemctl'
EXAMPLES:
check_systemdunit mysql.service
show status of service mysql
check_systemdunit -s
list all existing services. For a unit check you need to add the name
in the 1st column.
check_systemdunit nginx.service
show status of nginx webservice
```
## Examples
### List services
You maybe want to start to get a list of services to pick an existing one that you wanna check periodically.
You can use
``systemctl --no-legend --no-pager --type service``
or
``$ ./check_systemdunit -s``
```
txt
List of service units:
alsa-restore.service loaded active exited Save/Restore Sound Card State
apparmor.service loaded active exited Load AppArmor profiles
avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack
bluetooth.service loaded active running Bluetooth service
clamav-daemon.service loaded active running Clam AntiVirus userspace daemon
clamav-freshclam.service loaded active running ClamAV virus database updater
colord.service loaded active running Manage, Install and Generate Color Profiles
cronie.service loaded active running Periodic Command Scheduler
...
```
### Check a service
To check a single service you need to add the unit name in the 1st column.
``$ ./check_systemdunit nginx``
returns
```
txt
...
...
@@ -67,3 +99,7 @@ If a service does not exist: ``./check_systemdunit justadummy`` returns
```
txt
CRITICAL: Unit justadummy.service could not be found.
```
### Other units
With
``$ ./check_systemdunit -l``
you get a grouped list of all unit types. check_systemdunit handles all types - not only services.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment