Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mackerel-plugin-snmp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SNMP V2c custom metrics plugin for mackerel.io agent.
can specify multiple metric-definitions in the form of `OID:NAME[:DIFF?][:STACK?]` args.

```shell
mackerel-plugin-snmp [-name=<graph-name>] [-unit=<graph-unit>] [-host=<host>] [-community=<snmp-v2c-community>] [-tempfile=<tempfile>] 'OID:NAME[:DIFF?][:STACK?]' ['OID:NAME[:DIFF?][:STACK?][:COUNTER?]' ...]
mackerel-plugin-snmp [-name=<graph-name>] [-unit=<graph-unit>] [-host=<host>] [-port=<port>] [-community=<snmp-v2c-community>] [-tempfile=<tempfile>] 'OID:NAME[:DIFF?][:STACK?]' ['OID:NAME[:DIFF?][:STACK?][:COUNTER?]' ...]

```

Expand Down
4 changes: 4 additions & 0 deletions mackerel-plugin-snmp/lib/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type SNMPPlugin struct {
GraphName string
GraphUnit string
Host string
Port uint16
Community string
Tempfile string
SNMPMetricsSlice []SNMPMetrics
Expand All @@ -33,6 +34,7 @@ func (m SNMPPlugin) FetchMetrics() (map[string]interface{}, error) {
stat := make(map[string]interface{})

gosnmp.Default.Target = m.Host
gosnmp.Default.Port = m.Port
gosnmp.Default.Community = m.Community
gosnmp.Default.Version = gosnmp.Version2c
gosnmp.Default.Timeout = time.Duration(30) * time.Second
Expand Down Expand Up @@ -93,13 +95,15 @@ func Do() {
optGraphUnit := flag.String("unit", "float", "Graph unit")

optHost := flag.String("host", "localhost", "Hostname")
optPort := flag.Uint("port", 161, "Port")
optCommunity := flag.String("community", "public", "SNMP V2c Community")

optTempfile := flag.String("tempfile", "", "Temp file name")
flag.Parse()

var snmp SNMPPlugin
snmp.Host = *optHost
snmp.Port = uint16(*optPort)
snmp.Community = *optCommunity
snmp.GraphName = *optGraphName
snmp.GraphUnit = *optGraphUnit
Expand Down
5 changes: 2 additions & 3 deletions mackerel-plugin-snmp/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ then
fi

image=local/test-$plugin
# mackerel-plugin-snmp is disallowed --port option.
port=161
port=10161

docker build -t $image testdata/

docker run --name "test-$plugin" -v $(pwd)/testdata/snmpd.conf:/etc/snmp/snmpd.conf:ro -p $port:161/udp -d $image
trap 'docker stop test-$plugin; docker rm test-$plugin; exit 1' 1 2 3 15
sleep 10

$plugin '.1.3.6.1.2.1.25.1.5.0:hrSystemNumUsers:0:0' '.1.3.6.1.2.1.25.1.6.0:hrSystemProcesses:0:0' '.1.3.6.1.4.1.8072.1.3.2.3.1.2.4.101.99.104.111:echo:0:0' | graphite-metric-test -f rule.txt
$plugin -port $port '.1.3.6.1.2.1.25.1.5.0:hrSystemNumUsers:0:0' '.1.3.6.1.2.1.25.1.6.0:hrSystemProcesses:0:0' '.1.3.6.1.4.1.8072.1.3.2.3.1.2.4.101.99.104.111:echo:0:0' | graphite-metric-test -f rule.txt
status=$?

docker stop "test-$plugin"
Expand Down
Loading