-
Notifications
You must be signed in to change notification settings - Fork 27
/
sw_test.go
163 lines (143 loc) · 3.64 KB
/
sw_test.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package sw
import (
"fmt"
"strconv"
"testing"
"time"
"github.com/ulricqin/gosnmp"
)
const (
ip = "10.200.43.1"
community = "test"
oid = "1.3.6.1.4.1.2021.10.1.3.1"
timeout = 1000
method = "get"
retry = 3
iprange = "10.10.50.1-10.10.50.25"
pingIp = "10.10.10.1"
pingtimeout = 1000
fastPingMode = true
limitConn = 1
)
func Test_CpuUtilization(t *testing.T) {
if np, err := CpuUtilization(ip, community, timeout, retry); err != nil {
t.Error(err)
} else {
t.Log("CpuUtilization :", np)
}
}
func Test_MemUtilization(t *testing.T) {
if np, err := MemUtilization(ip, community, timeout, retry); err != nil {
t.Error(err)
} else {
fmt.Println("MemUtilization :", np)
}
}
func Test_RunSnmp(t *testing.T) {
var np []gosnmp.SnmpPDU
var err error
for i := 0; i < retry; i++ {
np, err = RunSnmp(ip, community, oid, method, timeout)
if len(np) > 0 {
break
}
time.Sleep(100 * time.Millisecond)
}
if err != nil {
t.Error(err)
} else {
fmt.Println("Test_RunSnmp :", &np)
fmt.Println(np[0].Value.(string))
}
}
func Test_RunSnmpswalk(t *testing.T) {
var np []gosnmp.SnmpPDU
var err error
np, err = RunSnmpwalk(ip, community, oid, retry, timeout)
if err != nil {
t.Error(err)
} else {
fmt.Println("Test_RunSnmp :", &np)
}
}
func Test_SysDescr(t *testing.T) {
np, err := SysDescr(ip, community, retry, timeout)
t.Error(err)
version_number, err := strconv.ParseFloat(getVersionNumber(np), 32)
t.Error(err)
fmt.Println("Test_SysDescr :", np)
fmt.Println("Version_number:", version_number)
}
func Test_SysVendor(t *testing.T) {
if np, err := SysVendor(ip, community, retry, timeout); err != nil {
t.Error(err)
} else {
fmt.Println("Test_SysVendor :", np)
}
}
func Test_ListIfStats(t *testing.T) {
ignoreIface := []string{"Vl"}
ignorePkt := true
ignoreOperStatus := true
ignoreMulticastPkt := true
ignoreBroadcastPkt := true
ignoreDiscards := true
ignoreErrors := true
ignoreUnknownProtos := true
ignoreOutQLen := true
if np, err := ListIfStats(ip, community, timeout, ignoreIface, retry, limitConn, ignorePkt, ignoreOperStatus, ignoreBroadcastPkt, ignoreMulticastPkt, ignoreDiscards, ignoreErrors, ignoreUnknownProtos, ignoreOutQLen); err != nil {
t.Error(err)
} else {
fmt.Println("value:", np)
}
}
func Test_ListIfStatsSnmpWalk(t *testing.T) {
ignoreIface := []string{"VLAN", "VL", "Vl"}
ignorePkt := true
ignoreOperStatus := false
ignoreMulticastPkt := false
ignoreBroadcastPkt := false
ignoreDiscards := false
ignoreErrors := false
ignoreUnknownProtos := false
ignoreOutQLen := true
if np, err := ListIfStatsSnmpWalk(ip, community, timeout, ignoreIface, retry, ignorePkt, ignoreOperStatus, ignoreBroadcastPkt, ignoreMulticastPkt, ignoreDiscards, ignoreErrors, ignoreUnknownProtos, ignoreOutQLen); err != nil {
t.Error(err)
} else {
fmt.Println("value:", np)
}
}
func Test_SysModel(t *testing.T) {
if np, err := SysModel(ip, community, retry, timeout); err != nil {
t.Error(err)
} else {
fmt.Println("Test_SysModel :", np)
}
}
func Test_SysName(t *testing.T) {
if np, err := SysName(ip, community, timeout); err != nil {
t.Error(err)
} else {
fmt.Println("Test_SysName :", np)
}
}
func Test_SysUpTime(t *testing.T) {
if np, err := SysUpTime(ip, community, timeout); err != nil {
t.Error(err)
} else {
fmt.Println("Test_SysUpTime :", np)
}
}
func Test_ParseIp(t *testing.T) {
np := ParseIp(iprange)
t.Log("aliveip:", np)
}
func Test_PingRtt(t *testing.T) {
rtt, err := PingRtt(pingIp, pingtimeout, fastPingMode)
t.Log("rtt:", rtt)
t.Log("err:", err)
}
func Test_Ping(t *testing.T) {
r := Ping(pingIp, pingtimeout, fastPingMode)
t.Log(r)
}