Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

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

August 14, 2023 Linux

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

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

Related Reading

How to Increase Size of Disk Partition in...

October 5, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

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

August 30, 2023

How to Install and Configure Ansible on Linux

August 27, 2023

Configure Remote SSH Connections in Visual Studio Code

July 12, 2023

1 comment

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

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

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
  • How to Access VMFS Datastore from Linux, Windows, or ESXi
  • Using iPerf to Test Network Speed and Bandwidth
  • Installing an Open Source KMS Server (Vlmcsd) on Linux
  • How to Enable Two-Factor Authentication (2FA) for SSH on Linux
  • How to Fix the ‘Too Many Open Files’ Error in Linux
Footer Logo

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


Back To Top