diff --git a/Samples/Go/ChangeSNMPVersion/main.go b/Samples/Go/ChangeSNMPVersion/main.go new file mode 100644 index 000000000..9982bc65b --- /dev/null +++ b/Samples/Go/ChangeSNMPVersion/main.go @@ -0,0 +1,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)) + } +} diff --git a/Samples/Go/NCMProfile/main.go b/Samples/Go/NCMProfile/main.go new file mode 100644 index 000000000..742535266 --- /dev/null +++ b/Samples/Go/NCMProfile/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "encoding/json" + "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 Cirrus.Nodes + WHERE AgentIP = '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) + } + + // properties + req := map[string]interface{}{ + "ConnectionProfile": 1, + } + + _, err = client.Update(nodes[0].URI, req) + if err != nil { + log.Fatal(err) + } +} diff --git a/Samples/PowerShell/ChangeSNMPVersion.ps1 b/Samples/PowerShell/ChangeSNMPVersion.ps1 new file mode 100644 index 000000000..f2416a2bb --- /dev/null +++ b/Samples/PowerShell/ChangeSNMPVersion.ps1 @@ -0,0 +1,30 @@ +Import-Module SwisPowerShell + +# SolarWinds connection details +$hostname = 'localhost' +$username = 'admin' +$password = '' + +$swis = Connect-Swis -Hostname $hostname -Username $username -Password $password + +# get the node uri +$query = " + SELECT Uri + FROM Orion.Nodes + WHERE IPAddress = '192.0.2.0' +" +$uri = Get-SwisData $swis $query + +# SNMPv3 Properties +$properties = @{ + SNMPVersion = '3' ; + SNMPV3Context = ''; + SNMPV3Username = ''; + SNMPV3PrivMethod = ''; # None, DES56, AES128, AES192, AES256 + SNMPV3PrivKey = '' + SNMPV3AuthMethod = '' #None, MD5, SHA1 + SNMPV3AuthKey = '' +} + +# change SNMP version +Set-SwisObject $swis $uri $properties diff --git a/Samples/PowerShell/NCMProfile.ps1 b/Samples/PowerShell/NCMProfile.ps1 new file mode 100644 index 000000000..1749de456 --- /dev/null +++ b/Samples/PowerShell/NCMProfile.ps1 @@ -0,0 +1,21 @@ +Import-Module SwisPowerShell + +# SolarWinds connection details +$hostname = 'localhost' +$username = 'admin' +$password = '' + +$swis = Connect-Swis -Hostname $hostname -Username $username -Password $password + +$query = " + SELECT Uri + FROM Cirrus.Nodes + WHERE AgentIP = '192.0.2.0' +" +$uri = Get-SwisData $swis $query + +$properties = @{ + ConnectionProfile = 1 +} + +Set-SwisObject $swis $uri $properties