From 99b054e243c9ed5ee86ef2aa2cc97a7e72fbac79 Mon Sep 17 00:00:00 2001 From: Riccardo Bicelli Date: Sat, 11 Jul 2020 14:32:20 +0200 Subject: [PATCH] Removed preprocessing on Gateways, added default for numeric values in openvpn_server_uservalue --- pfsense_zbx.php | 31 +++- template_pfsense_active.xml | 29 +-- template_pfsense_active_ovpn_user.xml | 250 +++++++++++++------------- 3 files changed, 158 insertions(+), 152 deletions(-) diff --git a/pfsense_zbx.php b/pfsense_zbx.php index afdc73c..82b3dcd 100644 --- a/pfsense_zbx.php +++ b/pfsense_zbx.php @@ -191,7 +191,7 @@ function pfz_openvpn_server_userdiscovery(){ } // Get OpenVPN User Connected Value -function pfz_openvpn_server_uservalue($unique_id, $valuekey){ +function pfz_openvpn_server_uservalue($unique_id, $valuekey, $default=""){ $atpos=strpos($unique_id,'+'); $server_id = substr($unique_id,0,$atpos); @@ -202,12 +202,12 @@ function pfz_openvpn_server_uservalue($unique_id, $valuekey){ if($server['vpnid']==$server_id) { foreach($server['conns'] as $conn) { if ($conn['common_name']==$user_id){ - $value = $conn[$valuekey]; + $value = $conn[$valuekey]; } } } } - + if ($value=="") $value = $default; echo $value; } // OpenVPN Client Discovery @@ -230,7 +230,7 @@ function pfz_openvpn_clientdiscovery() { } -function pfz_openvpn_clientvalue($client_id, $valuekey){ +function pfz_openvpn_clientvalue($client_id, $valuekey, $default="none"){ $clients = openvpn_get_active_clients(); foreach($clients as $client) { if($client['vpnid']==$client_id) @@ -245,7 +245,7 @@ function pfz_openvpn_clientvalue($client_id, $valuekey){ } - if ($value=="") $value="none"; + if ($value=="") $value=$default; echo $value; } @@ -370,8 +370,12 @@ function pfz_gw_discovery() { function pfz_gw_value($gw, $valuekey) { $gws = return_gateways_status(true); - if(array_key_exists($gw,$gws)) - echo $gws[$gw][$valuekey]; + if(array_key_exists($gw,$gws)) { + $value = $gws[$gw][$valuekey]; + if ($valuekey=="status") + $value = pfz_valuemap("gateway.status", $value); + echo $value; + } } @@ -469,6 +473,16 @@ function pfz_valuemap($valuename, $value){ "server_tls" => "3", "server_user" => "4", "server_tls_user" => "5"); + break; + + case "gateway.status": + $valuemap = array( + "none" => "0", + "loss" => "1", + "highdelay" => "2", + "highloss" => "3", + "force_down" => "4", + "down" => "5"); break; } @@ -519,6 +533,9 @@ switch (strtolower($argv[1])){ case "openvpn_server_uservalue": pfz_openvpn_server_uservalue($argv[2],$argv[3]); break; + case "openvpn_server_uservalue_numeric": + pfz_openvpn_server_uservalue($argv[2],$argv[3],"0"); + break; case "openvpn_clientvalue": pfz_openvpn_clientvalue($argv[2],$argv[3]); break; diff --git a/template_pfsense_active.xml b/template_pfsense_active.xml index 6fa7822..0be60a2 100644 --- a/template_pfsense_active.xml +++ b/template_pfsense_active.xml @@ -1,10 +1,10 @@ 4.0 - 2020-04-28T07:21:17Z + 2020-07-11T12:27:03Z - Templates + Templates/Network Devices @@ -17,7 +17,7 @@ Version 1.0.1 https://github.com/rbicelli/pfsense-zabbix-template - Templates + Templates/Network Devices @@ -3240,18 +3240,7 @@ https://github.com/rbicelli/pfsense-zabbix-template pfSense Gateway Status - - - 5 - (.*) -\1:none=0:loss=1:highdelay=2:highloss=3:force_down=4:down=5 - - - 5 - (none|loss|highdelay|highloss|force_down|down)(?=.*:\1=(\d)) -\2 - - + 3s @@ -3425,8 +3414,8 @@ https://github.com/rbicelli/pfsense-zabbix-template Gateway {#GATEWAY} Availability - 640 - 480 + 900 + 200 0.0000 100.0000 1 @@ -3469,8 +3458,8 @@ https://github.com/rbicelli/pfsense-zabbix-template Gateway {#GATEWAY} Status - 640 - 480 + 900 + 200 0.0000 5.0000 1 @@ -5180,7 +5169,7 @@ or {Template pfSense Active:pfsense.value[system,new_version_available].last()}=1 0 - New verson of pfSense Available on {HOST.NAME} + New Version of pfSense Available on {HOST.NAME} 0 diff --git a/template_pfsense_active_ovpn_user.xml b/template_pfsense_active_ovpn_user.xml index ffe4052..81ace63 100644 --- a/template_pfsense_active_ovpn_user.xml +++ b/template_pfsense_active_ovpn_user.xml @@ -1,10 +1,10 @@ 4.0 - 2020-04-28T07:22:36Z + 2020-07-11T12:27:51Z - Templates + Templates/Network devices @@ -20,7 +20,7 @@ Version 1.0.1 https://github.com/rbicelli/pfsense-zabbix-template - Templates + Templates/Network devices @@ -182,66 +182,6 @@ https://github.com/rbicelli/pfsense-zabbix-template - - OpenVPN Server {#SERVERNAME}, Client {#USERID}: Client ID - 7 - - - pfsense.value[openvpn_server_uservalue,{#UNIQUEID},client_id] - 120s - 0 - 0 - 0 - 3 - - - - - 0 - 0 - - 0 - - - - 0 - - - - - - Client ID - 0 - - - OpenVPN Server Clients - - - - - - - 3s - - - - 200 - 1 - 0 - - - 0 - 0 - 0 - 0 - - - - 0 - 0 - - - OpenVPN Server {#SERVERNAME}, Client {#USERID}: Connection Time 7 @@ -302,66 +242,6 @@ https://github.com/rbicelli/pfsense-zabbix-template - - OpenVPN Server {#SERVERNAME}, Client {#USERID}: Peer ID - 7 - - - pfsense.value[openvpn_server_uservalue,{#UNIQUEID},peer_id] - 60s - 0 - 0 - 0 - 3 - - - - - 0 - 0 - - 0 - - - - 0 - - - - - - Peer ID - 0 - - - OpenVPN Server Clients - - - - - - - 3s - - - - 200 - 1 - 0 - - - 0 - 0 - 0 - 0 - - - - 0 - 0 - - - OpenVPN Server {#SERVERNAME}, Client {#USERID}: Remote Host 7 @@ -488,7 +368,7 @@ https://github.com/rbicelli/pfsense-zabbix-template pfsense.value[openvpn_server_uservalue,{#UNIQUEID},virtual_addr6] - 180s + 60s 90d 0 0 @@ -548,7 +428,7 @@ https://github.com/rbicelli/pfsense-zabbix-template pfsense.value[openvpn_server_uservalue,{#UNIQUEID},virtual_addr] - 30s + 60s 180d 0 0 @@ -602,6 +482,126 @@ https://github.com/rbicelli/pfsense-zabbix-template + + OpenVPN Server {#SERVERNAME}, Client {#USERID}: Client ID + 7 + + + pfsense.value[openvpn_server_uservalue_numeric,{#UNIQUEID},client_id] + 120s + 0 + 0 + 0 + 3 + + + + + 0 + 0 + + 0 + + + + 0 + + + + + + Client ID + 0 + + + OpenVPN Server Clients + + + + + + + 3s + + + + 200 + 1 + 0 + + + 0 + 0 + 0 + 0 + + + + 0 + 0 + + + + + OpenVPN Server {#SERVERNAME}, Client {#USERID}: Peer ID + 7 + + + pfsense.value[openvpn_server_uservalue_numeric,{#UNIQUEID},peer_id] + 60s + 0 + 0 + 0 + 3 + + + + + 0 + 0 + + 0 + + + + 0 + + + + + + Peer ID + 0 + + + OpenVPN Server Clients + + + + + + + 3s + + + + 200 + 1 + 0 + + + 0 + 0 + 0 + 0 + + + + 0 + 0 + + +