Skip to content

Commit

Permalink
Merge pull request #200 from AnaCr/examples
Browse files Browse the repository at this point in the history
Add examples for changing SNMP version
  • Loading branch information
danjagnow committed Nov 6, 2019
2 parents 5ea2029 + 57c32d8 commit 31596c8
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 0 deletions.
55 changes: 55 additions & 0 deletions 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))
}
}
48 changes: 48 additions & 0 deletions 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)
}
}
30 changes: 30 additions & 0 deletions 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
21 changes: 21 additions & 0 deletions 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

0 comments on commit 31596c8

Please sign in to comment.