Skip to content

Latest commit

 

History

History
45 lines (40 loc) · 3.05 KB

step-by-step.md

File metadata and controls

45 lines (40 loc) · 3.05 KB

Step by step instructions

Let's assume the following things:

  • You do this directly on your Zabbix server
  • You are running Ubuntu 20.04 LTS
  • The domains you want to monitor are example.com, example.org, and example.net
  • The host inside of Zabbix that you want the items and triggers to be displayed under is called server1.example.com

Preparation:

  • Install whois by typing sudo apt install whois. Then type whois example.com to check if it even is possible to automate this for the domain you want, as we concluded could be a problem in issue number #4
  • Install pip by typing sudo apt install python3-pip
  • Install the dependencies this script has by then typing sudo pip install py-zabbix python-whois

Instructions:

  • Import the file zabbix-whois-template.xml in the Zabbix GUI and then add the template on the server1.example.com host
  • Put the two .py-files from this repository anywhere on your server you want. For this example, let's just use your own users home directory ~/zabbix-whois-expiry/
  • Make the .py-files executable with chmod +x zabbix-whois-discovery.py and chmod +x zabbix-whois-check.py
  • Create the folder ~/zabbix-whois-expiry/whois and inside that folder create a file called server1.example.com.json
  • Put the following inside of that .json-file:
{
  "domains": [
    "example.com",
    "example.org",
    "example.net"
  ]
}

Testing:

  • You can now test all of this manually by first typing ./zabbix-whois-discovery.py server1.example.com to do the discovery, this will create the items and triggers in zabbix.
  • Then type ./zabbix-whois-check.py server1.example.com to actually run the whois check and add data to the zabbix items.

Scheduling:

  • Assuming the above tests worked we will now use cron to schedule your server to automatically check the domains once each day.
  • Type crontab -e to edit your users cron-file (this is often online just called your users crontab instead).
  • Insert the following at the bottom of the editor that will appear in your terminal:
20 12 * * * $HOME/zabbix-whois-expiry/zabbix-whois-discovery.py server1.example.com
30 12 * * * $HOME/zabbix-whois-expiry/zabbix-whois-check.py server1.example.com
  • This means that 20 minutes past 12 on every day the file ~/zabbix-whois-expiry/zabbix-whois-discovery.py with the argument server1.example.com will automatically run.
  • Then at 30 minutes past 12 on every day the file ~/zabbix-whois-expiry/zabbix-whois-check.py with the argument server1.example.com will automatically run.
  • (Look up "crontab syntax" on a search engine if you're curious what the three asterisk symbols mean)

If you want to do this again for other hosts in zabbix just create new appropriately named .json-files and lines in your crontab and wait. If you no longer want to monitor a domain just remove it from the .json-file and wait, it will disappear automatically after a day or two. "Discovered" items in zabbix have an expiry time on them so this is why we run the discovery every day to remind zabbix of them as long as the domains exist in the .json-files.