diff --git a/README.md b/README.md index a67e747..87e6a42 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/zabbix-externalscripts/ssl/sslCertDomains.json b/zabbix-externalscripts/ssl/sslCertDomains.json index 9266585..4251282 100644 --- a/zabbix-externalscripts/ssl/sslCertDomains.json +++ b/zabbix-externalscripts/ssl/sslCertDomains.json @@ -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" + } + } ] -} \ No newline at end of file +} diff --git a/zabbix-externalscripts/sslCertExpiryCheck.sh b/zabbix-externalscripts/sslCertExpiryCheck.sh old mode 100644 new mode 100755 index d5e4f90..790e660 --- a/zabbix-externalscripts/sslCertExpiryCheck.sh +++ b/zabbix-externalscripts/sslCertExpiryCheck.sh @@ -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 | 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 | 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 \ No newline at end of file +fi diff --git a/zabbix-externalscripts/sslDomainsDiscovery.sh b/zabbix-externalscripts/sslDomainsDiscovery.sh old mode 100644 new mode 100755 index ae4fa4e..dcc09f6 --- a/zabbix-externalscripts/sslDomainsDiscovery.sh +++ b/zabbix-externalscripts/sslDomainsDiscovery.sh @@ -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#,}']}' \ No newline at end of file +echo '{"data":['${domainlist#,}']}'