Part I (Asuswrt): Advanced SNMP monitoring, part one: Asuswrt routers (Merlin build)
Part III (pfSense): TBC
Note 1: in the current firmware versions only extend directive works (exec directive is no longer supported) and this creates a different structure for OID. Use snmpwalk to get the values for all of the OIDs below if Home Assistant doesn’t get the values for the sensors, for example: snmpwalk -c public -v2c 192.168.0.36 1.3.6.1.2.1.25.1.8
which would result in 1.3.6.1.2.1.25.1.8.4.1.2.7.47.98.105.110.47.115.104.1
as the desired value.
iso.3.6.1.2.1.25.1.8.1.0 = INTEGER: 1
iso.3.6.1.2.1.25.1.8.2.1.2.7.47.98.105.110.47.115.104 = STRING: "/mnt/Data/files/SNMP/snmp-cpu-0-temp.sh"
iso.3.6.1.2.1.25.1.8.2.1.3.7.47.98.105.110.47.115.104 = ""
iso.3.6.1.2.1.25.1.8.2.1.4.7.47.98.105.110.47.115.104 = ""
iso.3.6.1.2.1.25.1.8.2.1.5.7.47.98.105.110.47.115.104 = INTEGER: 5
iso.3.6.1.2.1.25.1.8.2.1.6.7.47.98.105.110.47.115.104 = INTEGER: 1
iso.3.6.1.2.1.25.1.8.2.1.7.7.47.98.105.110.47.115.104 = INTEGER: 1
iso.3.6.1.2.1.25.1.8.2.1.20.7.47.98.105.110.47.115.104 = INTEGER: 4
iso.3.6.1.2.1.25.1.8.2.1.21.7.47.98.105.110.47.115.104 = INTEGER: 1
iso.3.6.1.2.1.25.1.8.3.1.1.7.47.98.105.110.47.115.104 = STRING: "54.0"
iso.3.6.1.2.1.25.1.8.3.1.2.7.47.98.105.110.47.115.104 = STRING: "54.0"
iso.3.6.1.2.1.25.1.8.3.1.3.7.47.98.105.110.47.115.104 = INTEGER: 1
iso.3.6.1.2.1.25.1.8.3.1.4.7.47.98.105.110.47.115.104 = INTEGER: 0
iso.3.6.1.2.1.25.1.8.4.1.2.7.47.98.105.110.47.115.104.1 = STRING: "54.0"
A. FreeNAS setup (IP of the FreeNAS machine is 192.168.0.36)
I. Find a suitable place for storing the SNMP scripts (I’ve used /mnt/Data/files/SNMP/) and create script files:
root@freenas[~]# nano /mnt/Data/files/SNMP/name_of_the_script.sh
- snmp-cpu-0-temp
#!/bin/sh
sysctl -a | egrep -E "cpu\.0+\.temp" | awk '{print $2}' | cut -c 1,2,3,4
- snmp-cpu-idle
#!/bin/sh
vmstat 2 2 | awk 'FNR==4{print $19}'
- snmp-diskx-temp (copy for each additional drive)
#!/bin/sh
/usr/local/sbin/smartctl -A /dev/ada0 | grep -i Temperature_Celsius | awk '{print $10}'
- snmp-space-free
#!/bin/sh
zfs list | head -2| awk '/Data/ {print $1}' | rev | cut -c2,3,4,5 | rev
II. Enable SNMP in FreeNAS -> Services - > SNMP
III. In Action for SNMP service include the following auxiliary parameters:
extend .1.3.6.1.2.1.25.1.8 /bin/sh /mnt/Data/files/SNMP/snmp-cpu-0-temp.sh
extend .1.3.6.1.2.1.25.1.10 /bin/sh /mnt/Data/files/SNMP/snmp-cpu-idle.sh
extend .1.3.6.1.2.1.25.1.11 /bin/sh /mnt/Data/files/SNMP/snmp-disk0-temp.sh
extend .1.3.6.1.2.1.25.1.12 /bin/sh /mnt/Data/files/SNMP/snmp-disk1-temp.sh
extend .1.3.6.1.2.1.25.1.13 /bin/sh /mnt/Data/files/SNMP/snmp-disk2-temp.sh
extend .1.3.6.1.2.1.25.1.14 /bin/sh /mnt/Data/files/SNMP/snmp-disk3-temp.sh
extend .1.3.6.1.2.1.25.1.15 /bin/sh /mnt/Data/files/SNMP/snmp-space-free.sh
B. Home Assistant
Make sure you add the packages in configuration.yaml (if starting recently with Home Assistant you would not have the homeassistant:
line in configuration.yaml)
homeassistant:
packages: !include_dir_named packages
#Package SNMP monitoring for FreeNAS
homeassistant:
customize:
#Some cosmetics (not really necessary)
switch.freenaswol:
friendly_name: FreeNAS WOL
icon: mdi:desktop-classic
assumed_state: true
sensor.freenas_cpu_temperature:
friendly_name: CPU Temp
sensor.freenas_cpu_used:
friendly_name: CPU Used
icon: mdi:cpu-64-bit
sensor.freenas_space_free:
friendly_name: Space Free
icon: mdi:harddisk
sensor.freenas_disk0_temperature:
friendly_name: Disk0 Temp
sensor.freenas_disk1_temperature:
friendly_name: Disk1 Temp
sensor.freenas_disk2_temperature:
friendly_name: Disk2 Temp
sensor.freenas_disk3_temperature:
friendly_name: Disk3 Temp
switch:
- platform: wake_on_lan
mac_address: "11-11-11-11-11-11"
name: freenaswol
host: 192.168.0.36
broadcast_address: 255.255.255.255
turn_off:
service: shell_command.turn_off_freenas
shell_command:
- turn_off_freenas: 'bash ssh -tt [email protected] /sbin/shutdown -p now'
#Note: Login without password is covered in https://community.home-assistant.io/t/internet-kill-switch-for-both-wireless-wired-devices/135785
# At least a successful connection from Home Assistant to FreeNAS machine is needed.
sensor:
#Standard
- platform: snmp
host: 192.168.0.36
baseoid: 1.3.6.1.4.1.2021.10.1.3.1
name: freenas_1min_load
accept_errors: true
default_value: 0
value_template: '{{value | float | round (2) }}'
unit_of_measurement: ' '
scan_interval: 35
- platform: snmp
host: 192.168.0.36
baseoid: 1.3.6.1.4.1.2021.10.1.3.2
name: freenas_5min_load
accept_errors: true
default_value: 0
value_template: '{{value | float | round (2) }}'
unit_of_measurement: ' '
scan_interval: 35
- platform: snmp
host: 192.168.0.36
baseoid: 1.3.6.1.4.1.2021.10.1.3.3
name: freenas_15min_load
accept_errors: true
default_value: 0
value_template: '{{value | float | round (2) }}'
unit_of_measurement: ' '
scan_interval: 35
- platform: snmp
host: 192.168.0.36
baseoid: 1.3.6.1.2.1.25.1.1.0
name: freenas_uptime
accept_errors: true
default_value: 0
scan_interval: 35
value_template: >-
{% set time = (value | int) | int %}
{% set minutes = ((time % 360000) / 6000) | int%}
{% set hours = ((time % 8640000) / 360000) | int %}
{% set days = (time / 8640000) | int %}
{%- if time < 60 -%}
Less then 1 min
{%- else -%}
{%- if days > 0 -%}
{{ days }}d
{%- endif -%}
{%- if hours > 0 -%}
{%- if days > 0 -%}
{{ ' ' }}
{%- endif -%}
{{ hours }}hr
{%- endif -%}
{%- if minutes > 0 -%}
{%- if days > 0 or hours > 0 -%}
{{ ' ' }}
{%- endif -%}
{{ minutes }}min
{%- endif -%}
{%- endif -%}
#Non-sttandard
- platform: snmp
host: 192.168.0.36
baseoid: 1.3.6.1.2.1.25.1.8.4.1.2.7.47.98.105.110.47.115.104.1
name: freenas_cpu_temperature
accept_errors: true
default_value: 0
value_template: '{{value | float | round (2) }}'
unit_of_measurement: '°C'
scan_interval: 35
- platform: snmp
host: 192.168.0.36
baseoid: 1.3.6.1.2.1.25.1.10.4.1.2.7.47.98.105.110.47.115.104.1
name: freenas_cpu_used
accept_errors: true
default_value: 0
value_template: '{{100-(value | float | round (2)) }}'
unit_of_measurement: '%'
scan_interval: 35
- platform: snmp
host: 192.168.0.36
baseoid: 1.3.6.1.2.1.25.1.11.4.1.2.7.47.98.105.110.47.115.104.1
name: freenas_disk0_temperature
accept_errors: true
default_value: 0
value_template: '{{value | float | round (2) }}'
unit_of_measurement: '°C'
scan_interval: 35
- platform: snmp
host: 192.168.0.36
baseoid: 1.3.6.1.2.1.25.1.12.4.1.2.7.47.98.105.110.47.115.104.1
name: freenas_disk1_temperature
accept_errors: true
default_value: 0
value_template: '{{value | float | round (2) }}'
unit_of_measurement: '°C'
scan_interval: 35
- platform: snmp
host: 192.168.0.36
baseoid: 1.3.6.1.2.1.25.1.13.4.1.2.7.47.98.105.110.47.115.104.1
name: freenas_disk2_temperature
accept_errors: true
default_value: 0
value_template: '{{value | float | round (2) }}'
unit_of_measurement: '°C'
scan_interval: 35
- platform: snmp
host: 192.168.0.36
baseoid: 1.3.6.1.2.1.25.1.14.4.1.2.7.47.98.105.110.47.115.104.1
name: freenas_disk3_temperature
accept_errors: true
default_value: 0
value_template: '{{value | float | round (2) }}'
unit_of_measurement: '°C'
scan_interval: 35
- platform: snmp
host: 192.168.0.36
baseoid: 1.3.6.1.2.1.25.1.15.4.1.2.7.47.98.105.110.47.115.104.1
name: freenas_space_free
accept_errors: true
default_value: 0
value_template: '{{value | float | round (2) }}'
unit_of_measurement: 'GB'
scan_interval: 35
Content for the Lovelace card; this includes modifications such as weblink, switch behaves differently when machine is on (in order to prevent accidentally turning it off):
cards:
- card:
content: >
[Web access FreeNAS](http://192.168.0.36) Uptime:
{{states.sensor.freenas_uptime.state}}
type: markdown
conditions:
- entity: switch.freenaswol
state: 'on'
type: conditional
- card:
entities:
- entity: switch.freenaswol
type: entities
conditions:
- entity: switch.freenaswol
state: 'off'
type: conditional
- card:
entities:
- entity: sensor.freenas_1min_load
- entity: sensor.freenas_5min_load
- entity: sensor.freenas_15min_load
- entity: sensor.freenas_cpu_temperature
- entity: switch.freenaswol
- entity: sensor.freenas_cpu_used
- entity: sensor.freenas_space_free
- entity: sensor.freenas_disk0_temperature
- entity: sensor.freenas_disk1_temperature
- entity: sensor.freenas_disk2_temperature
- entity: sensor.freenas_disk3_temperature
type: glance
conditions:
- entity: switch.freenaswol
state: 'on'
type: conditional
title: FreeNAS Machine
type: 'custom:vertical-stack-in-card'
This is the card when machine is off:
And when on: