-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from AnaCr/examples
Add examples for changing SNMP version
- Loading branch information
Showing
4 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |