This commit is contained in:
Riccardo Bicelli 2021-11-09 22:58:18 +01:00
parent cacc28be80
commit 12358a0584
3 changed files with 101 additions and 20 deletions

View File

@ -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:

View File

@ -1,7 +1,7 @@
<?php
/***
pfsense_zbx.php - pfSense Zabbix Interface
Version 1.0.5 - 2021-07-05
Version 1.1.1 - 2021-10-24
Written by Riccardo Bicelli <r.bicelli@gmail.com>
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();
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>5.0</version>
<date>2021-07-12T10:35:24Z</date>
<date>2021-11-09T21:44:28Z</date>
<groups>
<group>
<name>Templates/Network Devices</name>
@ -313,6 +313,29 @@ https://github.com/rbicelli/pfsense-zabbix-template</description>
</trigger>
</triggers>
</item>
<item>
<name>SMART Status</name>
<type>ZABBIX_ACTIVE</type>
<key>pfsense.value[smart_status]</key>
<delay>1800s</delay>
<description>pfSense SMART Status</description>
<applications>
<application>
<name>System</name>
</application>
</applications>
<valuemap>
<name>pfSense SMART Status</name>
</valuemap>
<triggers>
<trigger>
<expression>{last()}=1</expression>
<name>SMART Errors on {HOST.NAME}</name>
<priority>HIGH</priority>
<description>pfSense has detected SMART Problems on one or more drives.</description>
</trigger>
</triggers>
</item>
<item>
<name>pfSense Installed Version</name>
<type>ZABBIX_ACTIVE</type>
@ -2133,6 +2156,23 @@ or&#13;
</mapping>
</mappings>
</value_map>
<value_map>
<name>pfSense SMART Status</name>
<mappings>
<mapping>
<value>0</value>
<newvalue>OK</newvalue>
</mapping>
<mapping>
<value>1</value>
<newvalue>Error</newvalue>
</mapping>
<mapping>
<value>2</value>
<newvalue>Unknown</newvalue>
</mapping>
</mappings>
</value_map>
<value_map>
<name>Service state</name>
<mappings>