Zabbix detect Public IP Change

If you do not have a fixed IP you may already also be using something like DynDns to access your own Home-Network.

If you are also using Zabbix for Monitoring you may want to include an additional Information Layer to be notfied, when your public IP changes.

Reason? I myself also have had the problem that the DynDns Update failed and i had no information what my new “public IP” was. If Zabbix sends an EMail (it has had new Internet-Access) than you may be able to “recover” and dial in again (VPN…) using the IP and not your Dynamic DNS Name.

Getting public IP

How can you get your public IP?

There are a lot of Services to get it. Just use google.

Eg. ipfy “https://api.ipify.org/?format=plain” will provide it.

You may also use a simple custom solution on your own VServer or Webhosting-Package/Domain like setting up a PHP-Script to send back your IP.

Example (myip.php):

 <?php
echo $_SERVER['REMOTE_ADDR'];
?>

Create Zabbix Host

If you have already created a Host (see Zabbix Internet Connectivity Check) you can use it. Or else create it.

Create Item to get public IP

The Web Scenarios do not work for this Use-Case.

But there is a HTTPAgent in Zabbix.

Go to items and Create a new one.

Name: GetPublicIP

Type: “HTTP agent”

Key: public_ip

Type of Information: Character

URL:

Custom: https://my.domain/myip.php

Or a public available Service URL

Update Interval: 5m

Press Add.

Create Trigger

Now go to Triggers and Create a new one.

Name: PublicIPChange {ITEM.VALUE}

Severity: Information

Description: Public IP has Changed {ITEM.VALUE}

Expression:

(last(/Network connectivity checks/public_ip,#1)<>last(/Network connectivity checks/public_ip,#2))>0

Press Add and that’s it. Now if you want to test it just disconnect and reconnect to the internet and Zabbix will send an Notification that your IP changed. (Also 5min later it will also be automatically resolved).

Zabbix Internet Connectivity Check

Simple HowTo create a Internet Connectivity Check for Zabbix.

Create new Host

Create a new Host named “Network connectivity checks”

You do not need to add any Interfaces.

Add Web Scenario to Host

On our newly created Host go to “Web Scenarios”.

Press “Create web Scenario”

You can use your own Server or check Google.

For our Example we are going to use google.

Name of new Scenario: “Check Google Connectivity”

Update-Interval: 5m

Agent: Zabbix

Go to the Steps Tab and press “Add”

Name: “Google”

URL: “https://www.google.com”

Required Status Code: 200

Press the Add-Button to add the Step and than Add to add the Scenario.

Create a Trigger

Now we go to the Triggers Tab and pres “Create trigger”.

Name: “Google Accessibility {ITEM.VALUE}”

Severity: High

Expression:

length(last(/Network connectivity checks/web.test.error[Check Google Connectivity]))>0 and last(/Network connectivity checks/web.test.fail[Check Google Connectivity])>0

Press Add and we are Finished.

Now if you want to test it, disconnect from the Internet and wait a moment.

A new Problem should be created. If you have In-House Mailing (no internet contection required) you should get a new Problem-Notification from Zabbix.