Skip to content

pdavisfmnh/zabbix_letsencrypt_template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Zabbix Template for Let's Encrypt Certificate Monitoring

A comprehensive monitoring solution for Let's Encrypt SSL/TLS certificates managed by certbot, with automatic discovery and multi-level alerting.

Features

  • βœ… Automatic Discovery - Finds all certbot-managed certificates
  • βœ… Expiry Monitoring - Tracks days until certificate expiration
  • βœ… Multi-Level Alerts - INFO (30d), WARNING (14d), HIGH (7d)
  • βœ… Certificate Details - Monitors domains, serial numbers, key types
  • βœ… Historical Tracking - 90 days history, 365 days trends
  • βœ… Low Overhead - Minimal performance impact
  • βœ… Easy Setup - Simple installation with validation script

Quick Start

Automated Installation (Recommended)

# Run the automated installer
sudo bash quick_install.sh

The installer will:

  • Detect your Zabbix agent version (Agent or Agent 2)
  • Create /etc/zabbix/scripts/ directory
  • Install all files to the correct locations
  • Configure sudo access
  • Restart the agent
  • Run validation tests

Manual Installation

# Create scripts directory
sudo mkdir -p /etc/zabbix/scripts

# Copy script and config
sudo cp cert_monitor.sh /etc/zabbix/scripts/
sudo chmod +x /etc/zabbix/scripts/cert_monitor.sh

# For Zabbix Agent 2:
sudo cp letsencrypt.conf /etc/zabbix/zabbix_agent2.d/

# For Zabbix Agent (legacy):
sudo cp letsencrypt.conf /etc/zabbix/zabbix_agentd.d/

# Configure sudo access
echo "zabbix ALL=(ALL) NOPASSWD: /usr/bin/certbot, /etc/zabbix/scripts/cert_monitor.sh" | \
  sudo tee /etc/sudoers.d/zabbix-letsencrypt

# Restart agent
sudo systemctl restart zabbix-agent2  # or zabbix-agent

2. Validate Setup

sudo bash validate_setup.sh

3. Import Template

  1. Open Zabbix web interface
  2. Go to Data collection β†’ Templates
  3. Click Import
  4. Upload zbx_letsencrypt_template.yaml
  5. Click Import
  6. Assign template to your hosts with certbot

Files Included

File Size Purpose
cert_monitor.sh 3.8 KB Main monitoring script for discovery and metrics
letsencrypt.conf 2.9 KB Zabbix Agent configuration file
zbx_letsencrypt_template.yaml 7.5 KB Zabbix 7.4 template (YAML format)
README.md 10 KB This file - overview and quick start
quick_install.sh 5.2 KB Automated installation script
validate_setup.sh 7.7 KB Validation script to test installation

Monitored Metrics

For each discovered certificate:

  • Days until expiry - Integer value with trend tracking
  • Expiry date - Full timestamp of expiration
  • Domains - List of all domains covered
  • Serial number - Certificate serial number
  • Key type - RSA or ECDSA key type

Alert Levels

Alert Severity Threshold Action
Info πŸ”΅ Blue < 30 days Informational only
Warning 🟑 Yellow < 14 days Review renewal status
High πŸ”΄ Red < 7 days Immediate action required

Requirements

  • Zabbix Agent: Version 5.0+ (Agent or Agent 2)
  • Certbot: Any version with certbot certificates command
  • OS: Linux (Ubuntu, Debian, RHEL, AlmaLinux)
  • Sudo: Access for zabbix user to run certbot
  • Python: 3.x for JSON validation (optional)

Testing

Manual Test

# Test discovery (Agent 2)
sudo -u zabbix zabbix_agent2 -t letsencrypt.discovery

# Test discovery (Agent)
sudo -u zabbix zabbix_agentd -t letsencrypt.discovery

# Test specific certificate (replace CERTNAME)
sudo -u zabbix zabbix_agent2 -t "letsencrypt.cert.expiry_days[CERTNAME]"
# or
sudo -u zabbix zabbix_agentd -t "letsencrypt.cert.expiry_days[CERTNAME]"

From Zabbix Server

# Test from server
zabbix_get -s <HOST_IP> -k letsencrypt.discovery
zabbix_get -s <HOST_IP> -k "letsencrypt.cert.expiry_days[CERTNAME]"

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Zabbix Server                        β”‚
β”‚  - Stores metrics and history                           β”‚
β”‚  - Triggers alerts based on thresholds                  β”‚
β”‚  - Provides graphs and dashboards                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚
                      β”‚ Polls every hour
                      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 Monitored Host                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚         Zabbix Agent / Agent 2                 β”‚    β”‚
β”‚  β”‚  - Receives key requests                       β”‚    β”‚
β”‚  β”‚  - Executes UserParameter commands             β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                 β”‚                                        β”‚
β”‚                 β”‚ Calls via sudo                        β”‚
β”‚                 β–Ό                                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚    /etc/zabbix/scripts/cert_monitor.sh         β”‚    β”‚
β”‚  β”‚  - Discovery: Returns JSON of all certs        β”‚    β”‚
β”‚  β”‚  - Monitor: Returns all cert metrics           β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                 β”‚                                        β”‚
β”‚                 β”‚ Executes                              β”‚
β”‚                 β–Ό                                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚           Certbot                              β”‚    β”‚
β”‚  β”‚  - Manages Let's Encrypt certificates          β”‚    β”‚
β”‚  β”‚  - Provides certificate information            β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Customization

Adjust Alert Thresholds

Edit trigger prototypes in the template:

  1. Configuration β†’ Templates
  2. Select template
  3. Discovery rules β†’ Trigger prototypes
  4. Modify expressions (e.g., change <7 to <3)

Change Discovery Interval

Edit discovery rule interval:

  1. Configuration β†’ Templates
  2. Select template
  3. Discovery rules β†’ Edit
  4. Change update interval (default: 1h)

Add Custom Metrics

Add new UserParameters to letsencrypt.conf:

# Example: Monitor certificate file modification time
UserParameter=letsencrypt.cert.modified[*],stat -c %Y /etc/letsencrypt/live/$1/cert.pem

Troubleshooting

Common Issues

Discovery returns no data

  • Check: sudo -u zabbix sudo certbot certificates
  • Verify sudo permissions in /etc/sudoers.d/zabbix-letsencrypt

Timeout errors

  • Increase Timeout= in /etc/zabbix/zabbix_agent2.conf (or zabbix_agentd.conf) to 10
  • Restart agent: sudo systemctl restart zabbix-agent2 (or zabbix-agent)

Items show "Not supported"

  • Check agent logs: tail -f /var/log/zabbix/zabbix_agent2.log (or zabbix_agentd.log)
  • Test manually: sudo -u zabbix zabbix_agent2 -t letsencrypt.discovery (or zabbix_agentd)

Debug Commands

# Check agent status
sudo systemctl status zabbix-agent2  # or zabbix-agent

# View agent logs
sudo tail -100 /var/log/zabbix/zabbix_agent2.log  # or zabbix_agentd.log

# Test script directly
sudo -u zabbix /etc/zabbix/scripts/cert_monitor.sh discovery

# Verify JSON output
sudo -u zabbix /etc/zabbix/scripts/cert_monitor.sh discovery | python3 -m json.tool

# Check certbot
sudo certbot certificates

Best Practices

  1. Regular Testing: Run validate_setup.sh after system updates
  2. Monitor Renewals: Check certbot timer status weekly
  3. Review Alerts: Investigate any certificate <14 days from expiry
  4. Historical Analysis: Use trend graphs to identify renewal patterns
  5. Documentation: Keep track of certificate-to-domain mappings

Performance

  • Discovery: Runs once per hour (configurable)
  • Item Updates: Every hour (configurable)
  • Certbot Execution Time: 1-2 seconds typically
  • CPU Impact: Negligible (<0.1% during checks)
  • Memory: <10MB for script execution
  • Network: Zero (all local checks)

Security

  • βœ… Read-only operations only
  • βœ… Sudo limited to specific commands
  • βœ… No passwords in configuration
  • βœ… No network exposure
  • βœ… Standard file permissions

Compatibility

Component Versions
Zabbix Agent 5.0, 6.0, 6.4, 7.0, 7.4+
Zabbix Server 5.0, 6.0, 6.4, 7.0, 7.4+
Certbot All versions
Ubuntu 20.04, 22.04, 24.04
Debian 10, 11, 12
RHEL/AlmaLinux 8, 9

Contributing

Improvements welcome! Areas for enhancement:

  • Support for other ACME clients (acme.sh, etc.)
  • Integration with external certificate monitoring
  • Additional certificate properties
  • Multi-language support

License

This template and associated scripts are provided as-is for use with Zabbix monitoring.

Support

For issues:

  1. Run validate_setup.sh to diagnose problems
  2. Check SETUP_GUIDE.md for detailed troubleshooting
  3. Review Zabbix agent logs
  4. Verify certbot functionality independently

Version

  • Version: 1.0
  • Date: 2025-11-13
  • Author: Field Museum IT Infrastructure
  • Zabbix Version: 6.0+

Acknowledgments

Built for enterprise SSL/TLS certificate lifecycle management with integration into existing Zabbix infrastructure.

About

A comprehensive monitoring solution for Let's Encrypt SSL/TLS certificates managed by certbot, with automatic discovery and multi-level alerting.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages