pfsense-zabbix/README.md

128 lines
4.5 KiB
Markdown
Raw Permalink Normal View History

2020-04-26 18:24:37 +02:00
# pfSense Zabbix Template
2019-12-12 16:51:13 +01:00
This is a pfSense active template for Zabbix, based on Standard Agent and a php script using pfSense functions library for monitoring specific data.
2021-01-18 16:15:22 +01:00
This is forked from https://github.com/rbicelli/pfsense-zabbix-template for FWS needs
2019-12-12 16:51:13 +01:00
2020-04-28 00:12:32 +02:00
2023-02-26 13:21:25 +01:00
Tested with pfSense 2.5.x, Zabbix 4.0, Zabbix 5.0, Zabbix 6.0
2019-12-12 16:51:13 +01:00
## What it does
2020-04-28 00:12:32 +02:00
**Template pfSense Active**
2019-12-12 16:51:13 +01:00
- Network interface Discovery and Monitoring with User Assigned Names
2021-07-07 23:04:45 +02:00
- Gateway Discovery and Monitoring (Gateway Status/RTT)
- OpenVPN Server Discovery and Monitoring (Server Status/Tunnel Status)
- OpenVPN Clients Discovery and Monitoring (Client Status/Tunnel Status)
- CARP Monitoring (Global CARP State)
- Basic Service Discovery and Monitoring (Service Status)
- pfSense Version/Update Available
- Packages Update Available
2020-04-28 00:12:32 +02:00
**Template pfSense Active: OpenVPN Server User Auth**
- Discovery of OpenVPN Clients connected to OpenVPN Servers in user auth mode
- Monitoring of Client Parameters (Bytes sent/received, Connection Time...)
2019-12-12 16:51:13 +01:00
**Template pfSense Active: IPsec**
- Discovery of IPsec Site-to-Site tunnels
- Monitoring tunnel status (Phase 1 and Phase 2)
2021-07-05 19:31:48 +02:00
**Template pfSense Active: Speedtest**
- Discovery of WAN Interfaces
- Perform speed tests and collect metrics
2019-12-12 16:51:13 +01:00
## Configuration
First copy the file pfsense_zbx.php to your pfsense box (e.g. to /root/scripts).
2021-07-07 23:04:45 +02:00
From **Diagnostics/Command Prompt** input this one-liner:
```bash
2021-01-18 16:15:22 +01:00
mkdir /root/zabbix
2023-02-26 13:21:25 +01:00
curl --create-dirs -o /root/scripts/pfsense_zbx.php https://raw.githubusercontent.com/rbicelli/pfsense-zabbix-template/master/pfsense_zbx.php
```
Then, setup the system version cronjob with:
```bash
/usr/local/bin/php /root/scripts/pfsense_zbx.php sysversion_cron
```
2019-12-12 16:51:13 +01:00
2023-02-26 13:11:06 +01:00
Then install package "Zabbix Agent 5" (or "Zabbix Agent 6") on your pfSense Box
2019-12-12 16:51:13 +01:00
In Advanced Features-> User Parameters
```bash
UserParameter=pfsense.states.max,grep "limit states" /tmp/rules.limits | cut -f4 -d ' '
UserParameter=pfsense.states.current,grep "current entries" /tmp/pfctl_si_out | tr -s ' ' | cut -f4 -d ' '
UserParameter=pfsense.mbuf.current,netstat -m | grep "mbuf clusters" | cut -f1 -d ' ' | cut -d '/' -f1
UserParameter=pfsense.mbuf.cache,netstat -m | grep "mbuf clusters" | cut -f1 -d ' ' | cut -d '/' -f2
UserParameter=pfsense.mbuf.max,netstat -m | grep "mbuf clusters" | cut -f1 -d ' ' | cut -d '/' -f4
2021-01-18 16:15:22 +01:00
UserParameter=pfsense.discovery[*],/usr/local/bin/sudo /usr/local/bin/php /root/zabbix/pfsense_zbx.php discovery $1
UserParameter=pfsense.value[*],/usr/local/bin/sudo /usr/local/bin/php /root/zabbix/pfsense_zbx.php $1 $2 $3
2019-12-12 16:51:13 +01:00
```
2021-01-18 16:15:22 +01:00
_You need to allow zabbix user to exec /usr/local/bin/sudo /usr/local/bin/php /root/zabbix* without password with sudo_
2019-12-12 16:51:13 +01:00
Also increase the **Timeout** value at least to **5**, otherwise some checks will fail.
2020-04-28 00:12:32 +02:00
Then import xml templates in Zabbix and add your pfSense hosts.
2019-12-12 16:51:13 +01:00
If you are running a redundant CARP setup you should adjust the macro {$EXPECTED_CARP_STATUS} to a value representing what is CARP expected status on monitored box.
2019-12-12 16:51:13 +01:00
Possible values are:
- 0: Disabled
- 1: Master
- 2: Backup
This is useful when monitoring services which could stay stopped on CARP Backup Member.
2021-07-05 17:56:27 +02:00
## Setup Speedtest
2021-07-07 23:04:45 +02:00
For running speedtests on WAN interfaces you have to install the speedtest package.
2021-07-05 17:56:27 +02:00
From **Diagnostics/Command Prompt** input this commands:
2021-07-05 17:58:34 +02:00
```bash
2021-11-09 22:58:18 +01:00
pkg update && pkg install -y py38-speedtest-cli
2021-07-05 17:56:27 +02:00
```
2021-11-09 22:58:18 +01:00
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.
2021-07-05 17:56:27 +02:00
2021-07-05 17:58:34 +02:00
```bash
2021-11-09 22:58:18 +01:00
curl -Lo /usr/local/lib/python3.8/site-packages/speedtest.py https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
2021-07-05 17:56:27 +02:00
```
For testing if speedtest is installed properly you can try it:
2021-07-05 17:58:34 +02:00
```bash
2021-07-07 23:04:45 +02:00
/usr/local/bin/speedtest
2021-07-05 17:56:27 +02:00
```
Then, setup the cronjob with:
```bash
/url/local/bin/php /root/scripts/pfsense_zbx.php speedtest_cron
```
2021-07-05 17:56:27 +02:00
Remember that you will need to install the package on *every* pfSense upgrade.
2023-02-26 12:16:21 +01:00
Speedtest template creates a cron job and check for entry everytime Zabbix requests its items. If you want to uninstall the cron jobs simply run, from **Diagnostics/Command Prompt**:
2021-07-05 17:56:27 +02:00
2021-07-07 23:04:45 +02:00
```bash
/url/local/bin/php /root/scripts/pfsense_zbx.php cron_cleanup
```
2021-07-05 17:56:27 +02:00
2023-02-26 14:29:43 +01:00
**NOTE**: When used in multiple gateways scenario, speedtest results are OK only with default gateway. This is a known behavior that must be fixed upstream.
2023-02-26 13:11:06 +01:00
2023-02-26 16:11:38 +01:00
## Credits
[Keenton Zabbix Template](https://github.com/keentonsas/zabbix-template-pfsense) for Zabbix Agent freeBSD part.