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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Commits
2b92af61
Commit
2b92af61
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
check_systemdunit add -r REGEX
parent
c6edcac7
Branches
Branches containing commit
No related tags found
1 merge request
!170
check_systemdunit add -r REGEX
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
check_systemdunit
+44
-6
44 additions, 6 deletions
check_systemdunit
docs/20_Checks/check_systemdunit.md
+11
-2
11 additions, 2 deletions
docs/20_Checks/check_systemdunit.md
with
55 additions
and
8 deletions
check_systemdunit
+
44
−
6
View file @
2b92af61
...
...
@@ -5,12 +5,13 @@
#
# -------------------------------------------------------------------------------
# 2023-09-05 v1.0 <axel.hahn@unibe.ch>
# 2020-09-08 v1.1 <axel.hahn@unibe.ch> add params -s, -l
# 2020-09-06 v1.1 <axel.hahn@unibe.ch> add params -s, -l
# 2020-09-06 v1.2 <axel.hahn@unibe.ch> add param -r to use a regex
# ================================================================================
.
$(
dirname
$0
)
/inc_pluginfunctions
export
self_APPVERSION
=
1.
1
export
self_APPVERSION
=
1.
2
# ----------------------------------------------------------------------
# FUNCTIONS
...
...
@@ -28,13 +29,18 @@ 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|-l|-s] UNIT
$_self
[-h|-l|-s
|-r
] UNIT
OPTIONS:
-h this help
-l list all units
-s list service units
-r handle UNIT as a regex and search for a single unit. A uniq regex
is needed to match a single unit. The initial idea was to match a
servie that has different service names on differen os eg.
- apache2 vs httpd
- mysld vs mariadb
UNIT Name of a unit - see output of 'systemctl'
...
...
@@ -47,9 +53,18 @@ EXAMPLES:
$_self
nginx.service
show status of nginx webservice
$_self
-r "(apache2|httpd)
\.
service"
Detect name of Apache httpd service by given regex and show status
of the found service name
EOF
}
# get the list of units
function
_getUnits
(){
systemctl
--no-legend
--no-pager
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
...
...
@@ -67,8 +82,8 @@ ph.require "systemctl"
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
)
_list
=
$(
_getUnits
)
for
mytype
in
$(
awk
'{ print $1 }'
<<<
"
$_list
"
| rev|
cut
-f
1
-d
'.'
| rev |
grep
-v
'[^a-z]'
|
sort
-u
)
do
echo
"----------
$mytype
"
grep
"
\.
${
mytype
}
"
<<<
"
$_list
"
...
...
@@ -85,8 +100,31 @@ if ph.hasParamoption "s" "$@" ; then
exit
0
fi
# --- find a service by regex
if
ph.hasParamoption
"r"
"
$@
"
;
then
_regex
=
"
${
2
}
"
_list
=
$(
_getUnits |
awk
'{ print $1 }'
|
grep
-v
'[^a-z\.\-]'
|
sort
)
_unit
=
$(
grep
-E
"
$_regex
"
<<<
"
$_list
"
)
if
[
-z
"
$_unit
"
]
;
then
ph.setStatus critical
ph.status
"REGEX '
$_regex
' does not match any existing unit"
ph.exit
fi
if
[
$(
wc
-l
<<<
"
$_unit
"
)
!=
"1"
]
;
then
ph.setStatus critical
ph.status
"REGEX '
$_regex
' matches on multiple units on this system:"
echo
"
$_unit
"
|
nl
echo
"You need to use a uniq regex."
ph.exit
fi
else
_unit
=
"
${
1
}
"
fi
# --- check given unit
_unit
=
"
${
1
}
"
_status
=
$(
systemctl
--no-pager
-l
status
"
${
_unit
}
"
2>&1
)
if
!
grep
"Active: active (running) "
<<<
"
${
_status
}
"
>
/dev/null
;
then
...
...
This diff is collapsed.
Click to expand it.
docs/20_Checks/check_systemdunit.md
+
11
−
2
View file @
2b92af61
...
...
@@ -16,7 +16,7 @@ A unit is everything listed by systemctl command - services, timers, targets, ..
______________________________________________________________________
CHECK_SYSTEMDUNIT
v1.
1
v1.
2
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
...
...
@@ -30,13 +30,18 @@ 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|-l|-s] UNIT
check_systemdunit [-h|-l|-s
|-r
] UNIT
OPTIONS:
-h this help
-l list all units
-s list service units
-r handle UNIT as a regex and search for a single unit. A uniq regex
is needed to match a single unit. The initial idea was to match a
servie that has different service names on differen os eg.
- apache2 vs httpd
- mysld vs mariadb
UNIT Name of a unit - see output of 'systemctl'
...
...
@@ -49,6 +54,10 @@ EXAMPLES:
check_systemdunit nginx.service
show status of nginx webservice
check_systemdunit -r "(apache2|httpd)\.service"
Detect name of Apache httpd service by given regex and show status
of the found service name
```
## Examples
...
...
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