Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cert-autorefresh
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NOCpublic
cert-autorefresh
Commits
c7881c34
Commit
c7881c34
authored
3 months ago
by
Thomas Boettcher
Browse files
Options
Downloads
Patches
Plain Diff
adding check-certs
parent
ef37ebca
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
usr/local/sbin/check-certs
+79
-0
79 additions, 0 deletions
usr/local/sbin/check-certs
with
79 additions
and
0 deletions
usr/local/sbin/check-certs
0 → 100644
+
79
−
0
View file @
c7881c34
#!/bin/bash
# DEFAULTS
WarnDays
=
60
CritDays
=
30
workdir
=
/usr/local/cert
searchfile
=
cert.pem
ec
=
0
tmpfile
=
$(
mktemp
)
function
usage
{
echo
>
&2
echo
"
$0
[-w <days>] [-c <days>] [-d <dir>] [-f <filename>]"
>
&2
echo
>
&2
echo
"checks if enddate of certificates in location are critical."
>
&2
echo
>
&2
echo
"Usage:"
>
&2
echo
" -w <days> day threshold for status WARNING (exitcode=1)"
>
&2
echo
" DEFAULT:
$WarnDays
"
>
&2
echo
" -c <days> day threshold for status CRITICAL (exitcode=2)"
>
&2
echo
" DEFAULT:
$CritDays
"
>
&2
echo
" -d <dir> working directory with subdirs"
>
&2
echo
" DEFAULT:
$workdir
"
>
&2
echo
" -f <filename> filename to find"
>
&2
echo
" DEFAULT:
$searchfile
"
>
&2
echo
>
&2
exit
3
}
# OPTIONS
while
getopts
"?w:c:d:n:"
opt
do
case
$opt
in
w
)
WarnDays
=
$OPTARG
;;
c
)
CritDays
=
$OPTARG
;;
d
)
workdir
=
$OPTARG
;;
f
)
searchfile
=
$OPTARG
;;
\?
)
usage
;;
esac
done
# TABLE HEADER OUTPUT
echo
-e
"enddate
\t\t
days
\t
status
\t
file"
# WORKING CHECKS
(
for
cert
in
$(
find
$workdir
-name
$searchfile
)
do
enddate
=
$(
date
-d
"
$(
openssl x509
-in
$cert
-enddate
-nocert
|
sed
's/notAfter=//g'
)
"
+%F
)
let
datediff
=(
$(
date
-d
$enddate
+%s
)
-
$(
date
+%s
)
)
/86400
if
[
$datediff
-gt
$WarnDays
]
then
status
=
"[OK]"
elif
[
$datediff
-gt
$CritDays
]
then
status
=
"[WARN]"
[
$ec
-lt
1
]
&&
ec
=
1
else
status
=
"[CRIT]"
[
$ec
-lt
2
]
&&
ec
=
2
fi
echo
-e
"
$enddate
\t
$datediff
\t
$status
\t
$cert
"
done
echo
$ec
>
$tmpfile
)
|
sort
ec
=
$(
cat
$tmpfile
)
rm
$tmpfile
exit
$ec
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