Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
checkmk-formula
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
salt
checkmk-formula
Commits
2adc0d81
Commit
2adc0d81
authored
4 years ago
by
Jan Philipp Timme
Browse files
Options
Downloads
Patches
Plain Diff
Add basic plugin to monitor certs in /etc/hsh-certs
parent
2128f40f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
checkmk/custom-files/local/monitor-certificates
+55
-0
55 additions, 0 deletions
checkmk/custom-files/local/monitor-certificates
checkmk/debian/monitor-certificates.sls
+7
-0
7 additions, 0 deletions
checkmk/debian/monitor-certificates.sls
with
62 additions
and
0 deletions
checkmk/custom-files/local/monitor-certificates
0 → 100644
+
55
−
0
View file @
2adc0d81
#!/bin/bash
# We need current time+date to check for remaining time on certificates
NOW
=
$(
date
+%s
)
# WARN if less than this amount of days is left on the certificate
CONFIG_WARN_DAYS_LEFT
=
30
# CRIT if less than this amount of days is left on the certificate
CONFIG_CRIT_DAYS_LEFT
=
14
# List of folders to process *.pem files in
# Example: CONFIG_CHECK_FOLDERS=( "/a/b/c" "/d/e/f" "/foo/bar/baz" )
CONFIG_CHECK_FOLDERS
=(
"/etc/hsh-certs"
)
function
process_folder
{
folder
=
"
$1
"
if
[[
""
==
"
$folder
"
||
!
-d
"
$folder
"
]]
;
then
return
fi
echo
"
$folder
"
pemfiles
=
$(
find
"
$folder
"
-type
f
-name
'*.pem'
)
for
pemfile
in
$pemfiles
;
do
if
[[
"
$pemfile
"
=
~
\.
(
dhparam|chain|cacert
)
\.
pem
$
]]
;
then
continue
;
fi
pem_subject
=
$(
openssl x509
-in
"
$pemfile
"
-noout
-text
2>&1 |
grep
'Subject:'
|
tr
-s
' '
|
cut
-d
' '
-f
3-
)
pem_cn
=
$(
echo
$pem_subject
| rev |
cut
-d
' '
-f
1 | rev
)
pem_expire_date
=
$(
openssl x509
-in
"
$pemfile
"
-noout
-text
2>&1 |
grep
'Not After'
|
tr
-s
' '
|
cut
-d
' '
-f
5-
)
pem_expire_timestamp
=
$(
date
-d
"
$pem_expire_date
"
+%s
)
pem_remaining_seconds
=
$((
$pem_expire_timestamp
-
$NOW
))
pem_remaining_days
=
$((
$pem_remaining_seconds
/
86400
))
pem_status
=
""
checkmk_status
=
"3"
if
[[
$pem_remaining_days
-lt
1
]]
;
then
pem_status
=
"EXPIRED"
checkmk_status
=
"2"
else
pem_status
=
"
$pem_remaining_days
days remaining"
# Default is OK, gets overridden by WARN, then by CRIT
checkmk_status
=
"0"
if
[[
$pem_remaining_days
-le
CONFIG_WARN_DAYS_LEFT
]]
;
then
checkmk_status
=
"1"
fi
if
[[
$pem_remaining_days
-le
CONFIG_CRIT_DAYS_LEFT
]]
;
then
checkmk_status
=
"2"
fi
fi
echo
"
$checkmk_status
Certificate
$pem_cn
-
$pem_status
(
$pemfile
)"
done
}
for
folder
in
${
CONFIG_CHECK_FOLDERS
[@]
}
;
do
process_folder
$folder
done
This diff is collapsed.
Click to expand it.
checkmk/debian/monitor-certificates.sls
0 → 100644
+
7
−
0
View file @
2adc0d81
hsh_checkmk_monitor_certificates_plugin:
file.managed:
- name: /usr/lib/check_mk_agent/local/monitor-certificates
- source: salt://checkmk/custom-files/local/monitor-certificates
- mode: 755
- user: root
- group: root
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