certificatezabbix

Track the date in Zabbix



How can I track the date in Zabbix?
There is a need to track application certificates and personal user certificates.
Perhaps it is worth creating an Item and assigning a certain date to it, and then in the Trigger to track the occurrence of this date. But date() doesn't work exactly as I expected, and now() only works with Epoth.
Any ideas?

Solution

  • Use now() to know the difference between the certificate expiration date (as a Unix timestamp) and the time the item was last checked. This item can have a daily interval.

    See https://www.zabbix.com/documentation/6.0/en/manual/appendix/functions/time

    Update: sample script to get expiration date as Unix timestamp.

    #!/bin/bash
    
    url="$1" # example.com
    
    # Retrieve the certificate and extract the expiration date
    expiration_date=$(echo | openssl s_client -connect $url:443 -servername $url 2>/dev/null | openssl x509 -noout -enddate | cut -d "=" -f 2)
    
    # Convert the expiration date to Unix timestamp
    expiration_timestamp=$(date -d "$expiration_date" +"%s")
    
    # Print the results
    echo "$expiration_timestamp"
    

    Using timestamp as the Item unit in Zabbix, allows Zabbix to display the timestamp as human readable in Latest Data.