snmpfetch is a simple command-line program that uses the SNMP protocol to retrieve system information.
It sends GET requests to a host where the SNMP daemon is running, parses the data, and prints them.
- Install Rust
apt-get install snmp snmpd snmp-mibs-downloader libssl-dev
sed -i 's/mibs :/# mibs :/g' /etc/snmp/snmp.conf
- Add to
/etc/snmp/snmpd.conf
:
view systemonly included .1.3.6.1.4.1.2021
view systemonly included .1.3.6.1.2.1.25
- Run
service snmpd restart
- Clone this repository
cd snmpfetch/
cargo build --release
cd target/release/
./snmpfetch 127.0.0.1
- sysName and sysDescr can be retrieved using commands
uname -n
anduname -a
- hrSystemUptime using command
uptime -p
- hrSystremProcesses by
ps aux
- cpuUsage by
iostat
- memTotal and memUsed by
free
- Loads by
top
. (top
shows values divided by 100)
To check if notifications are correctly sent, stress
can be used, but it might be necessary to reduce thresholds.
The tool can be installed using apt-get install stress
Edit the following snmpfetch_config.toml
fields
[contacts]
# If notifications are needed, set an URL
webhook = "<URL>"
[timings]
# Seconds to wait before sending webhook
webhook_pause = 120 # 2 minutes
# Seconds between snmpfetch executions
interval = 1
[thresholds]
# Percentage of used memory
used_mem = 20
# Load 1 minute value
load_1m = 300
[database]
influxdb_url = "http://localhost:8086"
influxdb_name = "test"
grafana_url = "http://localhost:3000"
- Run the command
stress --cpu 4 --vm 2 --vm-bytes 512M &
- Run
./snmpfetch 127.0.0.1 -t 2.5 -L
- Check notifications in your webhook channel and stop
snmpfetch
- Terminate
stress
- Download Grafana and InfluxDB 1.8
- Start Influxd:
service influxdb start
- Start Grafana Server:
service grafana-server start
- run
influx
and executeCREATE DATABASE test
- Visit 127.0.0.1:3000 and enter
admin
in both fields - Continue the configuration then go to 127.0.0.1:3000/datasources and click on
Add data source
- Search
InfluxDB
and set the following parameters:- Name:
test
- URL:
http://localhost:8086
- DATABASE:
test
- HTTP Method:
GET
- Name:
- Click
Save & Test
A sample can be generated by executing the program (ex. ./snmpfetch 127.0.0.1
)