I have several sensors in the same SNMP host. What is the best way to avoid repeating the same lines of code? The best solution I could find so far is YAML anchors and aliases:
sensor:
- name: "Power usage peak Watts"
baseoid: 1.3.6.1.4.1.674.10892.5.4.600.60.1.9.1.1
<<: &ESXi-1_template
platform: snmp
host: 192.168.89.2
version: 2c
port: 4161
- name: "Temperature Probe Reading"
baseoid: 1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.4
<<: *ESXi-1_template
But maybe there is a better solution, using some kind of inheritance. I have tried this option:
snmp:
- name: ESXi-1
host: 192.168.89.2
version: 2c
port: 4161
sensors:
- name: "Power usage peak Watts"
baseoid: 1.3.6.1.4.1.674.10892.5.4.600.60.1.9.1.1
- name: "Temperature Probe Reading"
baseoid: 1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.4
But it gives this error in the system logs:
“Setup failed for snmp: No setup or config entry setup function defined”
Here’s another attempt:
sensor:
- name: ESXi-1
platform: snmp
host: 192.168.89.2
version: 2c
port: 4161
sensors:
- name: "Power usage peak Watts"
baseoid: 1.3.6.1.4.1.674.10892.5.4.600.60.1.9.1.1
- name: "Temperature Probe Reading"
baseoid: 1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.4
But it gives this error in the basic YAML validation:
“Invalid config for [sensor.snmp]: [sensors] is an invalid option for [sensor.snmp]. Check: sensor.snmp->sensors”