Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Linux / Monitoring Domain Name Expiration Date with Zabbix

August 14, 2023

Monitoring Domain Name Expiration Date with Zabbix

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

zabbix enable 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.

check domain expiry date using bash script Linux

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.

zabbix_get checks for domain expiration

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

Zabbix - monitoring domainexpire item

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 zabbix triggers for domain expiration date

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

Add a domainexpiration macros to zabbix template

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.

How to monitor domain expire date with Zabbix

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.

check domain expiration date for multiple domain names

4 comments
4
Facebook Twitter Google + Pinterest
Linux
previous post
Extending a Disk Volume (Partition) in Windows
next post
How to Completely Remove/Uninstall a Driver in Windows

Related Reading

Fixing ‘The Network Path Was Not Found’ 0x80070035...

August 31, 2023

How to Fix the ‘Too Many Open Files’...

March 13, 2024

How to Use Ansible to Manage Windows Machines

March 12, 2024

Recovering Files from BitLocker Encrypted Drive

March 13, 2024

Turn Linux Computer into Wi-Fi Access Point (Hotspot)

March 11, 2024

Using iPerf to Test Network Speed and Bandwidth

March 12, 2024

How to Increase Size of Disk Partition in...

March 11, 2024

Printing from Linux to a Windows Shared Printer

May 29, 2024

4 comments

Jamie October 20, 2023 - 2:24 pm

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?

Reply
Gleison Mours November 2, 2023 - 9:55 pm

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.

Reply
Alvis January 3, 2024 - 7:12 am

I can not check domain .vn or .com.vn with this guide, result always return 0
Other are working well, thank for sharing

Reply
GeorgeM October 24, 2024 - 3:05 pm

ZBX_NOTSUPPORTED: Unknown metric domainexpire

Could you please help me with this error?

Reply

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025
  • Configure NTP Time Source for Active Directory Domain

    May 6, 2025
  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Fixing ‘The Network Path Was Not Found’ 0x80070035 Error Code on Windows
  • Recovering Files from BitLocker Encrypted Drive
  • Installing an Open Source KMS Server (Vlmcsd) on Linux
  • How to Access VMFS Datastore from Linux, Windows, or ESXi
  • Using iPerf to Test Network Speed and Bandwidth
  • Install Any OS from ISO Image over Network with iVentoy
  • Moving WSL to Another Drive in Windows
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top