I wanted to use a script that was already working on its own inside Zabbix
It returns when a certificate is about to expire.
Somehow it wasn't working for Zabbix. The first thing you check is permissions, but after some debugging it turned out it was receiving more parameters than I expected (or should???).
I'm feeding it with {HOST.CONN} and I expect this {MACRO} to resolve to the DNS or IP, whatever I set it to be primary.
The port was something I don't need now, so the key is "certexpire[ {HOST.CONN1} ]"
It turned out I was getting a repetition of HOSTS and the 2nd parameter ($2) with false info.
I assume this is a bug?
Can someone confirm/deny this?
The line "PORT=443" is my workaround......
The script is now working as it should.
This is the script:
It returns when a certificate is about to expire.
Somehow it wasn't working for Zabbix. The first thing you check is permissions, but after some debugging it turned out it was receiving more parameters than I expected (or should???).
I'm feeding it with {HOST.CONN} and I expect this {MACRO} to resolve to the DNS or IP, whatever I set it to be primary.
The port was something I don't need now, so the key is "certexpire[ {HOST.CONN1} ]"
It turned out I was getting a repetition of HOSTS and the 2nd parameter ($2) with false info.
I assume this is a bug?
Can someone confirm/deny this?
The line "PORT=443" is my workaround......
The script is now working as it should.
This is the script:
Code:
#!/bin/bash
export PATH=${PATH}:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin
HOST=$1
PORT=$2
[ -z "${HOST}" ] && exit 1
[ -z "${PORT}" ] && PORT=443
PORT=443
EXPIRE_DATE=`echo "" | openssl s_client -connect ${HOST}:${PORT} 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | openssl x509 -enddate -noout 2>/dev/null| sed 's/notAfter\=//'`
if [ -z "${EXPIRE_DATE}" ]; then
echo '-2'
else
EXPIRE_SECS=`date -d "${EXPIRE_DATE}" +%s`
EXPIRE_TIME=$(( ${EXPIRE_SECS} - `date +%s` ))
echo $(( ${EXPIRE_TIME} / 24 / 3600 ))
fi
Comment