1
0
mirror of https://github.com/omni-lchen/zabbix-ssl synced 2024-12-21 08:27:52 +01:00

Add support of port per domain.

This commit is contained in:
Wizard1024 2019-03-12 17:51:46 +09:00
parent 9ada52cb76
commit 9f12469bbb
4 changed files with 42 additions and 15 deletions

View File

@ -1,6 +1,7 @@
# Zabbix-SSL # Zabbix-SSL
SSL certificates expiry date monitoring separated by groups, suitable for monitoring hundreds of websites. SSL certificates expiry date monitoring separated by groups, suitable for monitoring hundreds of websites.
Support port per domain.
**Installation** **Installation**
@ -8,7 +9,7 @@ Pre-requisites: Zabbix Sender, Openssl Client, JQ - https://stedolan.github.io/j
1. Copy the scripts and SSL configuration to zabbix external scripts directory: /usr/lib/zabbix/externalscripts 1. Copy the scripts and SSL configuration to zabbix external scripts directory: /usr/lib/zabbix/externalscripts
2. Add domains to the configuration file: ssl/sslCertDomains.json 2. Add domains and ports to the configuration file: ssl/sslCertDomains.json
3. Create zabbix host and link with SSL template, add macro to the host: {$DOMAIN_GROUP}, macro value should match the group name in the SSL configuration file. 3. Create zabbix host and link with SSL template, add macro to the host: {$DOMAIN_GROUP}, macro value should match the group name in the SSL configuration file.

View File

@ -1,12 +1,36 @@
{ {
"DomainGroup1": [ "DomainGroup1": [
{"domain": "www.a.com"}, {"domain": {
{"domain": "www.b.com"}, "name": "www.a.com"
{"domain": "www.c.com"} "port": "443"
}
},
{"domain": {
"name": "www.b.com"
"port": "443"
}
},
{"domain": {
"name": "www.c.com"
"port": "443"
}
}
], ],
"DomainGroup2": [ "DomainGroup2": [
{"domain": "www.d.com"}, {"domain": {
{"domain": "www.e.com"}, "name": "www.d.com"
{"domain": "www.f.com"} "port": "443"
}
},
{"domain": {
"name": "www.e.com"
"port": "443"
}
},
{"domain": {
"name": "www.f.com"
"port": "443"
}
}
] ]
} }

12
zabbix-externalscripts/sslCertExpiryCheck.sh Normal file → Executable file
View File

@ -13,20 +13,22 @@
# Query domains in a group # Query domains in a group
DOMAIN_GROUP=$1 DOMAIN_GROUP=$1
ZABBIX_HOST=$2 ZABBIX_HOST="$2"
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
ALL_DOMAINS=$SCRIPT_DIR"/ssl/sslCertDomains.json" ALL_DOMAINS=$SCRIPT_DIR"/ssl/sslCertDomains.json"
QUERY_DOMAINS=$(cat $ALL_DOMAINS | jq --arg DOMAIN_GROUP $DOMAIN_GROUP -r '.[$DOMAIN_GROUP][] .domain' | xargs 2>/dev/null) QUERY_DOMAINS=$(cat $ALL_DOMAINS | jq --arg DOMAIN_GROUP $DOMAIN_GROUP -r '.[$DOMAIN_GROUP][] | .domain.name + "-" + .domain.port' | xargs 2>/dev/null)
get_SSL_Certs_Expirydate() { get_SSL_Certs_Expirydate() {
for domain in $QUERY_DOMAINS; do for domain in $QUERY_DOMAINS; do
expiry_date=$(timeout 3 openssl s_client -host "$domain" -port 443 -servername "$domain" -showcerts </dev/null 2>/dev/null | sed -n '/BEGIN CERTIFICATE/,/END CERT/p' | openssl x509 -text 2>/dev/null | sed -n 's/ *Not After : *//p') NAME=${domain%-*}
PORT=${domain##*-}
expiry_date=$(echo QUIT | timeout 3 openssl s_client -host "$NAME" -port "$PORT" -servername "$NAME" -showcerts </dev/null 2>/dev/null | sed -n '/BEGIN CERTIFICATE/,/END CERT/p' | openssl x509 -text 2>/dev/null | sed -n 's/ *Not After : *//p')
if [ -n "$expiry_date" ]; then if [ -n "$expiry_date" ]; then
expiry_date_unix=$(date '+%s' --date "$expiry_date") expiry_date_unix=$(date '+%s' --date "$expiry_date")
else else
expiry_date_unix=0 expiry_date_unix=0
fi fi
echo $ZABBIX_HOST" ssl.cert.expirydate["$domain"] "$expiry_date_unix echo "\"$ZABBIX_HOST\""" ssl.cert.expirydate["${NAME}-${PORT}"] "$expiry_date_unix
done done
} }
@ -36,4 +38,4 @@ if [ -n "$response" ]; then
echo "$response" echo "$response"
else else
echo "$result" echo "$result"
fi fi

4
zabbix-externalscripts/sslDomainsDiscovery.sh Normal file → Executable file
View File

@ -8,9 +8,9 @@
DOMAIN_GROUP=$1 DOMAIN_GROUP=$1
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
ALL_DOMAINS=$SCRIPT_DIR"/ssl/sslCertDomains.json" ALL_DOMAINS=$SCRIPT_DIR"/ssl/sslCertDomains.json"
QUERY_DOMAINS=$(cat $ALL_DOMAINS | jq --arg DOMAIN_GROUP $DOMAIN_GROUP -r '.[$DOMAIN_GROUP][].domain' | xargs 2>/dev/null) QUERY_DOMAINS=$(cat $ALL_DOMAINS | jq --arg DOMAIN_GROUP $DOMAIN_GROUP -r '.[$DOMAIN_GROUP][] | .domain.name + "-" + .domain.port' | xargs 2>/dev/null)
for domain in $QUERY_DOMAINS; do for domain in $QUERY_DOMAINS; do
domainlist="$domainlist,"'{"{#DOMAIN}":"'${domain# }'"}' domainlist="$domainlist,"'{"{#DOMAIN}":"'${domain# }'"}'
done done
echo '{"data":['${domainlist#,}']}' echo '{"data":['${domainlist#,}']}'