Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples for changing SNMP version #200

Merged
merged 3 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 55 additions & 0 deletions Samples/Go/ChangeSNMPVersion/main.go
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))
}
}
48 changes: 48 additions & 0 deletions Samples/Go/NCMProfile/main.go
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)
}
}
30 changes: 30 additions & 0 deletions Samples/PowerShell/ChangeSNMPVersion.ps1
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
21 changes: 21 additions & 0 deletions Samples/PowerShell/NCMProfile.ps1
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