To change the SNMP version of a node in SolarWinds using the gosolar SDK, you must first retrieve the node's unique Uri via a SWQL query, and then perform an Update operation on that URI with a payload containing the new SNMP configuration.
When updating to SNMPv3, the request payload should include the following keys:
SNMPVersion: Set to 3.SNMPV3Username: The username for SNMPv3.SNMPV3Context: The SNMPv3 context.SNMPV3PrivMethod: The privacy method (e.g., None, DES56, AES128, AES 192, AES256).SNMPV3PrivKey: The privacy key.SNMPV3AuthMethod: The authentication method (e.g., None, MD5, SHA1).SNMPV3AuthKey: The authentication key.
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))
}
}