This article gives a detailed overview of how to configure the monitoring of your domain names’ expiration dates in Zabbix. This will prevent you from missing the renewal and expiration dates (end of delegation) of your domain names.
If the previous owner does not pay for the domain name within 30 days of the end of the registration period, the domain will be expired (its status will change to NotDelegated). Let’s look at a simple bash script and Zabbix template which allow you to check and monitor the domain name expiration date.
We assume that you already have a Zabbix server installed. We will use a small bash script to get the domain delegation information from the registrar. For this script to work, you must have the whois utility installed on your Linux host.
- CentOS/RHEL/Rocky Linux:
$ sudo dnf install whois -y
- Ubuntu/Debian:
$ sudo apt install whois -y
Check zabbix-server.conf file for the directory path for external scripts. By default, the following path is used (uncomment this line):
ExternalScripts=/usr/lib/zabbix/externalscripts
In this directory, create the file /usr/lib/zabbix/externalscripts/domain_expiration.sh containing the following code:
#!/bin/bash DOMAIN="$1" exdate=`whois $DOMAIN | grep -E 'paid|Expire|Expiry' | grep -o -E '[0-9]{4}.[0-9]{2}.[0-9]{2}|[0-9]{2}/[0-9]{2}/[0-9]{4}'` expire=$((`date -d "$exdate" '+%s'`)) today=$((`date '+%s'`)) leftsec=$(($expire - $today)) leftdays=$(($leftsec/86400)) echo $leftdays
Make your .sh file executable:
$ sudo chmod +x /usr/lib/zabbix/externalscripts/domain_expiration.sh
Check that the script works correctly. As a parameter, specify the name of the domain for which you want to get the number of days the delegation expires.
$ /usr/lib/zabbix/externalscripts/domain_expiration.sh woshub.com
In my example, the script returned that there were 532 days until the domain’s expiration date.
Now we must allow the Zabbix agent to run this custom script using the UserParameter parameter.
$ sudo mcedit /etc/zabbix/zabbix_agentd.conf
Add the following line:
UserParameter=domainexpire[*],/usr/lib/zabbix/externalscripts/domain_expiration.sh $1
This option allows you to run a specific external script through the Zabbix Agent. You must use the domainexpire parameter to call this script from Zabbix.
Restart the agent:
$ sudo service zabbix-agent restart
Make sure that the zabbix agent is able to retrieve data via the new parameter. You use the zabbix-get tool to test the agent:
$ sudo apt install zabbix-get
$ zabbix_get -s 127.0.0.1 -p 10050 -k domainexpire[woshub.com]
If you have configured everything correctly, the command should return the number of days before the domain registration expires.
Now add a new CheckDomainExpiration template to monitor the domain expiration date in Zabbix.
On the items tab, add the parameter:
- Name: Domain expiration time{$DOMAINNAME}
- Type: Zabbix Agent
- Key:
domainexpire[{$DOMAINNAME}]
- Type of information: Numeric (unsigned)
- Update Interval: 1d
- History: 90d
- Trenfd: 365d
Now add a new trigger:
- Name: Domain name {$DOMAINNAME} will expire in
- Expression:
last(/CheckDomainExpiration/domainexpire[{$DOMAINNAME}])<39
- Severity: High
This will be activated if there are less than 39 days before the domain registration expires.
Optionally, you can also add a trigger for recovery:
Recovery expression: last(/CheckDomainExpiration/domainexpire[{$DOMAINNAME}])>=40
Add a new host to Zabbix for your domain name with the Agent interface type.
In the Macros tab, specify the name of the domain whose expiration date you want to monitor:
- Macro:
{$DOMAINNAME}
- Value:
woshub.com
Finally, assign the CheckDomainExpiration template you created earlier to the host.
This template checks the domain registration date once a day. To get the whois data immediately, find the required parameter in the host tab and click Execute Now.
Go to Monitoring -> Latest Data. Zabbix shows that the domain name will expire in 532 days.
You can set this trigger to send an alert to e-mail or your favorite messaging app (or display the problem on the Zabbix dashboard).
You can follow the steps above to add all the domain names (in the Hosts tab) whose expiration dates you want to monitor.
4 comments
This is a great guide, thanks, I have set it up, and it all works apart from on the Dashboard all I get is xxx.com will expire in
I dont get the actual day it expires io? if I run the scripts or see the latest data I see the number, any ideas?
Boa noite. Legal sua publicação. Segui ela por completo, mas não tive sucesso quando utilizo diversas outras url de domínios. Com o .com.br, nenhuma funcionou.
I can not check domain .vn or .com.vn with this guide, result always return 0
Other are working well, thank for sharing
ZBX_NOTSUPPORTED: Unknown metric domainexpire
Could you please help me with this error?