<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export><version>5.0</version><date>2021-11-21T21:42:32Z</date><groups><group><name>Templates</name></group></groups><templates><template><template>App WireGuard</template><name>App WireGuard</name><description>## Overview

Hi,


I tried to create a template to monitor WireGuard with Zabbix.  
WireGuard does not really provide any monitoring tool so I had to do with &quot;wg show&quot; commands.


It's probably not perfect so if you want to help I'm interested.


Template provides 2 discovery rules :


Interfaces Discovery (wg0, wg1...) :  
- Items to get active peers, total peers, port used and check firewall mark.  
- Triggers to check changes on port, fwmark and numbers of clients.  
- Graph to monitor active and total peers (even if connections are never released by WG once established).  



Peers Discovery (based on public key) :  
I had to truncate keys to 10 characters for easy reading. It should not be a problem because they're random.  
- Items to get for each endpoint : allowed IPs, IP address, port used, incoming/outgoing traffic, keepalive status and the last handshake.   
- Triggers to track changes on allowed IPs, connection port, IP address, keeaplive status and to monitor high traffic and unreachable endpoint.  
- Graph to monitor incoming/outgoing network traffic.  



This template may work with previous versions of Zabbix but it was tested for Zabbix 4.0 on a Debian 9.6 server.


Please follow the link for instructions and files.


Have fun !



## Author

Cryptage21

</description><groups><group><name>Templates</name></group></groups><applications><application><name>Wireguard</name></application></applications><discovery_rules><discovery_rule><name>WireGuard Interfaces Discovery</name><key>wg.list.discovery[INTERFACES]</key><delay>3600s</delay><item_prototypes><item_prototype><name>Firewall mark enabled on {#WGINTERFACE}</name><key>wg.fw.mark[{#WGINTERFACE}]</key><delay>60m</delay><history>7d</history><trends>7d</trends><applications><application><name>Wireguard</name></application></applications><preprocessing><step><type>BOOL_TO_DECIMAL</type><params/></step></preprocessing><trigger_prototypes><trigger_prototype><expression>{diff()}=1</expression><name>Firewall mark changed on {#WGINTERFACE} {HOST.NAME} VPN</name><priority>WARNING</priority></trigger_prototype></trigger_prototypes></item_prototype><item_prototype><name>Active peers on {#WGINTERFACE}</name><key>wg.peers.connected[{#WGINTERFACE}]</key><delay>15m</delay><history>30d</history><applications><application><name>Wireguard</name></application></applications><trigger_prototypes><trigger_prototype><expression>{change()}&lt;=-1</expression><name>Less clients connected on {#WGINTERFACE} {HOST.NAME} VPN</name><priority>INFO</priority></trigger_prototype><trigger_prototype><expression>{change()}&gt;=1</expression><name>More clients connected on {#WGINTERFACE} {HOST.NAME} VPN</name><priority>INFO</priority></trigger_prototype></trigger_prototypes></item_prototype><item_prototype><name>Total peers on {#WGINTERFACE}</name><key>wg.peers.count[{#WGINTERFACE}]</key><delay>30m</delay><history>7d</history><trends>30d</trends><applications><application><name>Wireguard</name></application></applications><trigger_prototypes><trigger_prototype><expression>{change()}&gt;=1</expression><name>Peers added on {#WGINTERFACE} {HOST.NAME} VPN</name><priority>INFO</priority></trigger_prototype><trigger_prototype><expression>{change()}&lt;=-1</expression><name>Peers removed on {#WGINTERFACE} {HOST.NAME} VPN</name><priority>INFO</priority></trigger_prototype></trigger_prototypes></item_prototype><item_prototype><name>Port used on {#WGINTERFACE}</name><key>wg.port.used[{#WGINTERFACE}]</key><delay>60m</delay><history>7d</history><trends>7d</trends><value_type>FLOAT</value_type><applications><application><name>Wireguard</name></application></applications><preprocessing><step><type>TRIM</type><params>8</params></step></preprocessing><trigger_prototypes><trigger_prototype><expression>{diff()}=1</expression><name>Connection port changed on {#WGINTERFACE} {HOST.NAME} VPN</name><priority>WARNING</priority></trigger_prototype></trigger_prototypes></item_prototype></item_prototypes><graph_prototypes><graph_prototype><name>Peers on [{#WGINTERFACE}] VPN</name><graph_items><graph_item><color>199C0D</color><item><host>App WireGuard</host><key>wg.peers.connected[{#WGINTERFACE}]</key></item></graph_item><graph_item><sortorder>1</sortorder><color>F63100</color><item><host>App WireGuard</host><key>wg.peers.count[{#WGINTERFACE}]</key></item></graph_item></graph_items></graph_prototype></graph_prototypes></discovery_rule><discovery_rule><name>WireGuard Peers Discovery</name><key>wg.list.discovery[PEERS]</key><delay>3600s</delay><item_prototypes><item_prototype><name>Endpoint IP address for peer {#PEER}... on {#INTERFACE}</name><key>wg.endpoint.address[{#PEER}]</key><delay>15m</delay><history>30d</history><trends>0</trends><value_type>TEXT</value_type><applications><application><name>Wireguard</name></application></applications><trigger_prototypes><trigger_prototype><expression>{diff()}=1</expression><name>IP address changed for {#PEER}... peer on {HOST.NAME}</name><priority>INFO</priority></trigger_prototype></trigger_prototypes></item_prototype><item_prototype><name>Allowed IPs for peer {#PEER}... on {#INTERFACE}</name><key>wg.endpoint.allowedips[{#PEER}]</key><delay>30m</delay><history>7d</history><trends>0</trends><value_type>TEXT</value_type><applications><application><name>Wireguard</name></application></applications><trigger_prototypes><trigger_prototype><expression>{diff()}=1</expression><name>Allowed IPs list altered for {#PEER}... peer on {HOST.NAME}</name><priority>HIGH</priority></trigger_prototype></trigger_prototypes></item_prototype><item_prototype><name>Last handshake for peer {#PEER}... on {#INTERFACE}</name><key>wg.endpoint.handshake[{#PEER}]</key><delay>10m</delay><history>7d</history><trends>7d</trends><units>unixtime</units><applications><application><name>Wireguard</name></application></applications><trigger_prototypes><trigger_prototype><expression>{fuzzytime(1800)}=0</expression><name>Unreachable {#PEER}... peer on {HOST.NAME} for 30 minutes</name><priority>HIGH</priority></trigger_prototype></trigger_prototypes></item_prototype><item_prototype><name>Keepalive enabled for peer {#PEER}... on {#INTERFACE}</name><key>wg.endpoint.keepalive[{#PEER}]</key><delay>30m</delay><history>7d</history><trends>30d</trends><applications><application><name>Wireguard</name></application></applications><preprocessing><step><type>BOOL_TO_DECIMAL</type><params/></step></preprocessing><trigger_prototypes><trigger_prototype><expression>{diff()}=1</expression><name>Keepalived changed for {#PEER}... peer on {HOST.NAME}</name><priority>WARNING</priority></trigger_prototype></trigger_prototypes></item_prototype><item_prototype><name>Endpoint port for peer {#PEER}... on {#INTERFACE}</name><key>wg.endpoint.port[{#PEER}]</key><delay>15m</delay><history>7d</history><trends>7d</trends><applications><application><name>Wireguard</name></application></applications><trigger_prototypes><trigger_prototype><expression>{diff()}=1</expression><name>Connection port changed for {#PEER}... peer on {HOST.NAME}</name><priority>INFO</priority></trigger_prototype></trigger_prototypes></item_prototype><item_prototype><name>Incoming traffic for peer {#PEER}... on {#INTERFACE}</name><key>wg.endpoint.transferdown[{#PEER}]</key><delay>5m</delay><history>30d</history><units>bps</units><applications><application><name>Wireguard</name></application></applications><preprocessing><step><type>SIMPLE_CHANGE</type><params/></step></preprocessing><trigger_prototypes><trigger_prototype><expression>{change()}&gt;52428800</expression><name>High incoming traffic for {#PEER}... peer on {HOST.NAME}</name><priority>AVERAGE</priority></trigger_prototype></trigger_prototypes></item_prototype><item_prototype><name>Outgoing traffic for peer {#PEER}... on {#INTERFACE}</name><key>wg.endpoint.transferup[{#PEER}]</key><delay>5m</delay><history>30d</history><units>bps</units><applications><application><name>Wireguard</name></application></applications><preprocessing><step><type>SIMPLE_CHANGE</type><params/></step></preprocessing><trigger_prototypes><trigger_prototype><expression>{change()}&gt;52428800</expression><name>High outgoing traffic for {#PEER}... peer on {HOST.NAME}</name><priority>AVERAGE</priority></trigger_prototype></trigger_prototypes></item_prototype></item_prototypes><graph_prototypes><graph_prototype><name>Network traffic for {#INTERFACE}-{#PEER} peer</name><graph_items><graph_item><color>199C0D</color><item><host>App WireGuard</host><key>wg.endpoint.transferdown[{#PEER}]</key></item></graph_item><graph_item><sortorder>1</sortorder><color>F63100</color><item><host>App WireGuard</host><key>wg.endpoint.transferup[{#PEER}]</key></item></graph_item></graph_items></graph_prototype></graph_prototypes></discovery_rule></discovery_rules></template></templates></zabbix_export>
