From 12358a05848eaf4defec03d697161db7c252b229 Mon Sep 17 00:00:00 2001 From: Riccardo Bicelli Date: Tue, 9 Nov 2021 22:58:18 +0100 Subject: [PATCH] Issues #70, #81, #87 --- README.md | 8 ++--- pfsense_zbx.php | 71 +++++++++++++++++++++++++++++-------- template_pfsense_active.xml | 42 +++++++++++++++++++++- 3 files changed, 101 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 210c699..3faab65 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This is a pfSense active template for Zabbix, based on Standard Agent and a php script using pfSense functions library for monitoring specific data. -Tested with pfSense 2.4.x, Zabbix 4.0, Zabbix 5.0 +Tested with pfSense 2.5.x, Zabbix 4.0, Zabbix 5.0 ## What it does @@ -87,13 +87,13 @@ For running speedtests on WAN interfaces you have to install the speedtest packa From **Diagnostics/Command Prompt** input this commands: ```bash -pkg update && pkg install -y py37-speedtest-cli +pkg update && pkg install -y py38-speedtest-cli ``` -Speedtest python package could be broken at the moment, so you could need an extra step: download the latest version from package author's github repo. +Speedtest python package could be broken at the moment, so you could need an extra step, *only if manually executing speedtest results in an error*: download the latest version from package author's github repo. ```bash -curl -Lo /usr/local/lib/python3.7/site-packages/speedtest.py https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py +curl -Lo /usr/local/lib/python3.8/site-packages/speedtest.py https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py ``` For testing if speedtest is installed properly you can try it: diff --git a/pfsense_zbx.php b/pfsense_zbx.php index c002ec0..108968b 100644 --- a/pfsense_zbx.php +++ b/pfsense_zbx.php @@ -1,7 +1,7 @@ This program is licensed under Apache 2.0 License @@ -112,17 +112,20 @@ function pfz_interface_discovery($is_wan=false,$is_cron=false) { $ifdescr = $hwif; $has_gw = false; $is_vpn = false; + $has_public_ip = false; foreach($ifcs as $ifc=>$ifinfo){ if ($ifinfo["hwif"] == $hwif){ $ifdescr = $ifinfo["description"]; if (array_key_exists("gateway",$ifinfo)) $has_gw=true; + // Issue #81 - https://stackoverflow.com/a/13818647/15093007 + if (filter_var($ifinfo["ipaddr"], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) $has_public_ip=true; if (strpos($ifinfo["if"],"ovpn")!==false) $is_vpn=true; break; } } - if ( ($is_wan==false) || (($is_wan==true) && ($has_gw==true) && ($is_vpn==false)) ) { + if ( ($is_wan==false) || (($is_wan==true) && (($has_gw==true) || ($has_public_ip==true)) && ($is_vpn==false)) ) { $if_ret[]=$hwif; $json_string .= '{"{#IFNAME}":"' . $hwif . '"'; $json_string .= ',"{#IFDESCR}":"' . $ifdescr . '"'; @@ -164,7 +167,7 @@ function pfz_interface_speedtest_value($ifname, $value){ } - +// This is supposed to run via cron job function pfz_speedtest_cron(){ require_once("services.inc"); $ifdescrs = get_configured_interface_with_descr(true); @@ -183,13 +186,9 @@ function pfz_speedtest_cron(){ break; } } - - //If the interface has a gateway is considered WAN, so let's do the speedtest - if (array_key_exists("gateway", $ifinfo)) { - $ipaddr = $ifinfo['ipaddr']; - pfz_speedtest_exec($ifname, $ipaddr); - } - + + pfz_speedtest_exec($ifname, $ifinfo['ipaddr']); + } } @@ -446,7 +445,7 @@ function pfz_service_value($name,$value){ //List of service which are stopped on CARP Slave. //For now this is the best way i found for filtering out the triggers //Waiting for a way in Zabbix to use Global Regexp in triggers with items discovery - $stopped_on_carp_slave = array("haproxy","radvd","openvpn.","openvpn"); + $stopped_on_carp_slave = array("haproxy","radvd","openvpn.","openvpn","avahi"); foreach ($services as $service){ $namecfr = $service["name"]; @@ -530,8 +529,13 @@ function pfz_gw_value($gw, $valuekey) { $gws = return_gateways_status(true); if(array_key_exists($gw,$gws)) { $value = $gws[$gw][$valuekey]; - if ($valuekey=="status") - $value = pfz_valuemap("gateway.status", $value); + if ($valuekey=="status") { + //Issue #70: Gateway Forced Down + if ($gws[$gw]["substatus"]<>"none") + $value = $gws[$gw]["substatus"]; + + $value = pfz_valuemap("gateway.status", $value); + } echo $value; } } @@ -1018,10 +1022,44 @@ function pfz_get_system_value($section){ break; case "packages_update": echo pfz_packages_uptodate(); - break; + break; } } +//S.M.A.R.T Status +// Taken from /usr/local/www/widgets/widgets/smart_status.widget.php +function pfz_get_smart_status(){ + + $devs = get_smart_drive_list(); + $status = 0; + foreach ($devs as $dev) { ## for each found drive do + $smartdrive_is_displayed = true; + $dev_ident = exec("diskinfo -v /dev/$dev | grep ident | awk '{print $1}'"); ## get identifier from drive + $dev_state = trim(exec("smartctl -H /dev/$dev | awk -F: '/^SMART overall-health self-assessment test result/ {print $2;exit} +/^SMART Health Status/ {print $2;exit}'")); ## get SMART state from drive + switch ($dev_state) { + case "PASSED": + case "OK": + //OK + $status=0; + break; + case "": + //Unknown + $status=2; + return $status; + break; + default: + //Error + $status=1; + return $status; + break; + } + } + + echo $status; +} + + // File is present function pfz_file_exists($filename) { if (file_exists($filename)) @@ -1217,7 +1255,10 @@ switch (strtolower($argv[1])){ break; case "cron_cleanup": pfz_speedtest_cron_install(false); - break; + break; + case "smart_status": + pfz_get_smart_status(); + break; default: pfz_test(); } diff --git a/template_pfsense_active.xml b/template_pfsense_active.xml index 3568b05..00f0c47 100644 --- a/template_pfsense_active.xml +++ b/template_pfsense_active.xml @@ -1,7 +1,7 @@ 5.0 - 2021-07-12T10:35:24Z + 2021-11-09T21:44:28Z Templates/Network Devices @@ -313,6 +313,29 @@ https://github.com/rbicelli/pfsense-zabbix-template + + SMART Status + ZABBIX_ACTIVE + pfsense.value[smart_status] + 1800s + pfSense SMART Status + + + System + + + + pfSense SMART Status + + + + {last()}=1 + SMART Errors on {HOST.NAME} + HIGH + pfSense has detected SMART Problems on one or more drives. + + + pfSense Installed Version ZABBIX_ACTIVE @@ -2133,6 +2156,23 @@ or + + pfSense SMART Status + + + 0 + OK + + + 1 + Error + + + 2 + Unknown + + + Service state