Add Multiple SNMP Agents to Telegraf Config
I will add several more SNMP agents to the Telegraf config.
In order for Telegraf to connect to the external SNMP agents, those other SNMP agents will need to be configured to allow my Telegraf agent to connect remotely.
On my servers, that I'd like monitor using SNMP, I install SNMPD using
sudo apt install snmpd
I then configure snmpd.conf.
sudo nano /etc/snmp/snmpd.conf
I change below,
... agentAddress udp:127.0.0.1:161 ...
to allow remote connections,
... agentAddress udp:161 ...
and I change below
... view systemonly included .18.104.22.168.2.1.1 view systemonly included .22.214.171.124.126.96.36.199 ...
to return more data,
... view systemonly included .188.8.131.52.2.1 #view systemonly included .184.108.40.206.220.127.116.11 ...
and I change below,
... rocommunity public default -V systemonly rocommunity6 public default -V systemonly ...
to set the community, and restrict to ipv4 only(optional).
... rocommunity mycommunity default -V systemonly #rocommunity6 mycommunity default -V systemonly ...
The SNMPD can now be connected to remotely by anybody on the internet, so I use iptables to restrict UDP connections on port 161 to the localhost and my external Grafana server domain or ip only.
iptables -A INPUT -p udp -s [domain name or ip] --dport 161 -j ACCEPT iptables -A INPUT -p udp -s localhost --dport 161 -j ACCEPT iptables -A INPUT -p udp --dport 161 -j DROP iptables -L
I then start the SNMPD service
sudo service snmpd start
I then go back to my Grafana server, and test that I can query the new SNMPD on the other server using SNMPWALK.
snmpwalk -v 2c -c mycommunity [domain name or ip] .
I then reconfigure the Telegraf conf to add the information for my external SNMP agent.
I duplicate the existing [[inputs.snmp]] section from the last lecture, but change the SNMP agents address.
I also repeat the process for another server that I want to monitor SNMP for, so at the end of the lecture, I have 3 SNMP agents able to be queried using Grafana.
After I've added all my SNMP agent configs to the telegraf.conf, I then restart the Telegraf service on my Grafana server.
sudo systemctl restart telegraf