From f3078f328153d31e46790b76e7bd65fd3be4a93b Mon Sep 17 00:00:00 2001 From: Grant Emsley Date: Thu, 6 Feb 2020 11:52:10 -0500 Subject: [PATCH] Use interface descriptions instead of hardware names where possible. --- pfsense_zbx.php | 37 +++++++++++++++++++++++++++++++------ template_pfsense_active.xml | 8 ++++---- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/pfsense_zbx.php b/pfsense_zbx.php index fab6b47..dc996af 100644 --- a/pfsense_zbx.php +++ b/pfsense_zbx.php @@ -57,16 +57,38 @@ function pfz_test(){ function pfz_get_if_name($hwif){ - - $ifdescrs = get_configured_interface_with_descr(true); - foreach ($ifdescrs as $ifdescr => $ifname){ + + $ifdescrs = get_configured_interface_with_descr(true); + foreach ($ifdescrs as $ifdescr => $ifname){ $ifinfo = get_interface_info($ifdescr); if($ifinfo["hwif"]==$hwif){ - echo $ifname; - return true; + return $ifname; } } - + return null; + +} + +//Interface Discovery +function pfz_interface_discovery() { + $ifaces = get_interface_arr(); + + $json_string = '{"data":['; + + foreach ($ifaces as $iface) { + $json_string .= '{"{#IFNAME}":"' . $iface . '"'; + + $descr = pfz_get_if_name($iface); + if($descr === null){ $descr = $iface; } + + $json_string .= ',"{#IFDESCR}":"' . $descr . '"'; + $json_string .= '},'; + } + $json_string = rtrim($json_string,","); + $json_string .= "]}"; + + echo $json_string; + } @@ -324,6 +346,9 @@ function pfz_discovery($section){ case "services": pfz_services_discovery(); break; + case "interfaces": + pfz_interface_discovery(); + break; } } diff --git a/template_pfsense_active.xml b/template_pfsense_active.xml index 835eb23..c2c5df6 100644 --- a/template_pfsense_active.xml +++ b/template_pfsense_active.xml @@ -2980,7 +2980,7 @@ 7 - net.if.discovery + pfsense.discovery[interfaces] 3600 0 @@ -3015,7 +3015,7 @@ Discovery of network interfaces as defined in global regular expression "Network interfaces for discovery". - Incoming network traffic on $1 + Incoming network traffic on {#IFDESCR} 7 @@ -3084,7 +3084,7 @@ - Outgoing network traffic on $1 + Outgoing network traffic on {#IFDESCR} 7 @@ -3156,7 +3156,7 @@ - Network traffic on {#IFNAME} + Network traffic on {#IFDESCR} 900 200 0.0000