Мониторинг сертификатов java для JMX с отправкой данных в Zabbix
Содержимое скрипта.
#!/bin/sh #https://gist.github.com/zatarra/5570733 KEYSTORE="/home/.certstore" PASSWORD="stR0nGPa((word" keytool -list -v -keystore "$KEYSTORE" -storepass $PASSWORD | grep Alias | awk '{print $3}' | while read ALIAS do echo $ALIAS".on_cert_alias_name" #EXPIRACY=`keytool -list -v -keystore "$KEYSTORE" -storepass $PASSWORD -alias $ALIAS | grep Valid` UNTIL=`keytool -list -v -keystore "$KEYSTORE" -storepass $PASSWORD -alias $ALIAS | grep Valid | perl -ne 'if(/until: (.*?)\n/) { print "$1\n"; }'` echo "1 - $UNTIL" UNTIL_SECONDS=`date -d "$UNTIL" +%s` echo "2 - $UNTIL_SECONDS" REMAINING_DAYS=$(( ($UNTIL_SECONDS - $(date +%s)) / 60 / 60 / 24 )) echo "3 - $REMAINING_DAYS" zabbix_sender -z zabbix-server.com -p 10051 -s zabbix-server.com -k $ALIAS".on_cert_alias_name" -o $REMAINING_DAYS done KEYSTORE="/home/.keystore" keytool -list -v -keystore "$KEYSTORE" -storepass $PASSWORD | grep Alias | awk '{print $3}' | while read ALIAS do echo $ALIAS".on_client" #EXPIRACY=`keytool -list -v -keystore "$KEYSTORE" -storepass $PASSWORD -alias $ALIAS | grep Valid` UNTIL=`keytool -list -v -keystore "$KEYSTORE" -storepass $PASSWORD -alias $ALIAS | grep Valid | perl -ne 'if(/until: (.*?)\n/) { print "$1\n"; }'` echo "1 - $UNTIL" UNTIL_SECONDS=`date -d "$UNTIL" +%s` echo "2 - $UNTIL_SECONDS" REMAINING_DAYS=$(( ($UNTIL_SECONDS - $(date +%s)) / 60 / 60 / 24 )) echo "3 - $REMAINING_DAYS" zabbix_sender -z zabbix-server.com -p 10051 -s zabbix-server.com -k $ALIAS".on_client" -o $REMAINING_DAYS done
В крон добавляется задание:
* * * * * /home/./check_cert_date.sh
Item в Zabbix (в скрипте key для Item это $ALIAS».on_client»):