/
main.go
55 lines (45 loc) · 1.04 KB
/
main.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
package main
import (
"encoding/json"
"fmt"
"log"
"github.com/mrxinu/gosolar"
)
// Node struct holds query results
type Node struct {
URI string `json:"uri"`
}
func main() {
// SolarWinds connection details
hostname := "localhost"
username := "admin"
password := ""
// connect to SolarWinds
client := gosolar.NewClient(hostname, username, password, true)
// query for node uri
query := `SELECT Uri
FROM Orion.Nodes
WHERE IPAddress = '192.0.2.0'`
res, err := client.Query(query, nil)
if err != nil {
log.Fatal(err)
}
var nodes []*Node
if err := json.Unmarshal(res, &nodes); err != nil {
log.Fatal(err)
}
// change to snmp v3
req := map[string]interface{}{
"SNMPVersion": 3,
"SNMPV3Username": "",
"SNMPV3Context": "",
"SNMPV3PrivMethod": "", // None, DES56, AES128, AES 192, AES256
"SNMPV3PrivKey": "",
"SNMPV3AuthMethod": "", // None, MD5, SHA1
"SNMPV3AuthKey": "",
}
_, err = client.Update(nodes[0].URI, req)
if err != nil {
fmt.Println(fmt.Sprintf("failed to update node: %v", err))
}
}