1
0
mirror of https://github.com/omni-lchen/zabbix-ssl synced 2024-10-06 04:31:36 +02: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
SSL certificates expiry date monitoring separated by groups, suitable for monitoring hundreds of websites.
Support port per domain.
**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
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.

View File

@ -1,12 +1,36 @@
{
"DomainGroup1": [
{"domain": "www.a.com"},
{"domain": "www.b.com"},
{"domain": "www.c.com"}
{"domain": {
"name": "www.a.com"
"port": "443"
}
},
{"domain": {
"name": "www.b.com"
"port": "443"
}
},
{"domain": {
"name": "www.c.com"
"port": "443"
}
}
],
"DomainGroup2": [
{"domain": "www.d.com"},
{"domain": "www.e.com"},
{"domain": "www.f.com"}
{"domain": {
"name": "www.d.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
DOMAIN_GROUP=$1
ZABBIX_HOST=$2
ZABBIX_HOST="$2"
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
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() {
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
expiry_date_unix=$(date '+%s' --date "$expiry_date")
else
expiry_date_unix=0
fi
echo $ZABBIX_HOST" ssl.cert.expirydate["$domain"] "$expiry_date_unix
echo "\"$ZABBIX_HOST\""" ssl.cert.expirydate["${NAME}-${PORT}"] "$expiry_date_unix
done
}
@ -36,4 +38,4 @@ if [ -n "$response" ]; then
echo "$response"
else
echo "$result"
fi
fi

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

@ -8,9 +8,9 @@
DOMAIN_GROUP=$1
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
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
domainlist="$domainlist,"'{"{#DOMAIN}":"'${domain# }'"}'
done
echo '{"data":['${domainlist#,}']}'
echo '{"data":['${domainlist#,}']}'