Skip to content
This repository has been archived by the owner on Jun 14, 2022. It is now read-only.

Node creation sample #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions examples/create-node/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
"fmt"
"regexp"
"strconv"
"strings"

"github.com/mrxinu/gosolar"
)

type Node struct {
IPAddress string
EngineID int
ObjectSubType string
SNMPVersion int
Community string
DNS string
NodeName string
SysName string
}

func main() {
hostname := "localhost"
username := "admin"
password := ""

// NewClient creates a client that will handle the connection to SolarWinds
// along with the timeout and HTTP conversation.
client := gosolar.NewClient(hostname, username, password, true)

node := Node{
IPAddress: "10.10.10.10",
EngineID: 1,
ObjectSubType: "SNMP",
Community: "SNMP community string here",
SNMPVersion: 2,
DNS: "device.name.here",
NodeName: "device.name.here",
SysName: "device.name.here",
}

// Node creation
res, err := client.Create("Orion.Nodes", node)

if err != nil {
fmt.Println(err)
}

// In case you want to get the NodeID
re := regexp.MustCompile(`NodeID=\d+`)
match := re.FindAllString(string(res), -1)
if len(match) == 0 {
fmt.Println("No NodeID found in create Node response")
}

fmt.Println(strconv.Atoi(strings.Replace(match[0], "NodeID=", "", -1)))
}