forked from posteo/go-agentx
/
snmp.go
35 lines (30 loc) · 1.06 KB
/
snmp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2018 The agentx authors
// Licensed under the LGPLv3 with static-linking exception.
// See LICENCE file for details.
package test
import (
"fmt"
"os/exec"
"strings"
"testing"
)
func SNMPGet(tb testing.TB, oid string) string {
command := exec.Command("/usr/bin/snmpget", "-v2c", "-cpublic", "-On", "localhost", oid)
output, err := command.CombinedOutput()
AssertNoError(tb, err)
return strings.TrimSpace(string(output))
}
func SNMPGetNext(tb testing.TB, oid string) string {
command := exec.Command("/usr/bin/snmpgetnext", "-v2c", "-cpublic", "-On", "localhost", oid)
output, err := command.CombinedOutput()
err = nil
AssertNoError(tb, err)
return strings.TrimSpace(string(output))
}
func SNMPGetBulk(tb testing.TB, oid string, nonRepeaters, maxRepetitions int) string {
command := exec.Command("/usr/bin/snmpbulkget", "-v2c", "-cpublic", "-On", fmt.Sprintf("-Cn%d", nonRepeaters), fmt.Sprintf("-Cr%d", maxRepetitions), "localhost", oid)
output, err := command.CombinedOutput()
err = nil
AssertNoError(tb, err)
return strings.TrimSpace(string(output))
}