gosolar

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2018 License: Apache-2.0 Imports: 8 Imported by: 30

README

gosolar

GoDoc Go Report Card

GoSolar is a SolarWinds client library written in Go. It allows you to submit queries to the SolarWinds Information Service (SWIS) and do various other things.

About

mrxinu/gosolar is a wrapper around REST calls to the SWIS and makes working with a SolarWinds install a little easier.

Overview

GoSolar has the following generic methods:

  • Read - read a SolarWinds object with all its properties.
  • Query - query information via SWQL.
  • Create - create new entities (nodes, pollers, etc.).
  • Delete - delete an entity using its URI.
  • Invoke - run verbs found in the SolarWinds API.

GoSolar has the following query wrappers for ease of use:

  • QueryOne - returns a single interface{} from the query.
  • QueryRow - returns a []byte representing the single row.
  • QueryColumn - returns a []interface{} from the query.

GoSolar has the following convenience methods:

  • Custom Properties
    • SetCustomProperty - set a custom property on a single entity.
    • SetCustomProperties - set custom properties on a single entity.
    • BulkSetCustomProperties - set a custom property on a series of entities.
    • CreateCustomProperty - create a custom property.
  • Network Configuration Manager (NCM)
    • RemoveNCMNodes - remove nodes from NCM monitoring.
  • Inventory Management
    • BulkDelete - delete multiple URIs in one request.
  • Universal Device Poller (UnDP)
    • GetAssignments - get all the current UnDP assignments.
    • AddNodePoller - add a UnDP poller to a node.
    • AddInterfacePoller - add a UnDP poller to an interface.

Installation

Install via go get:

go get -u github.com/mrxinu/gosolar

Documentation

See http://godoc.org/github.com/mrxinu/gosolar or your local go doc server for full documentation, as well as the examples.

cd $GOPATH
godoc -http=:6060 &
$preferred_browser http://localhost:6060/pkg &

Usage

Basic usage can be found below but more specific examples are in the examples folder:

package main

import (
	"encoding/json"
	"fmt"
	"log"

	"github.com/mrxinu/gosolar"
)

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)

	// run the query without any parameters by passing nil as the 2nd parameter
	res, err := client.Query("SELECT Caption, IPAddress FROM Orion.Nodes", nil)
	if err != nil {
		log.Fatal(err)
	}

	// build a structure to unmarshal the results into
	var nodes []struct {
		Caption   string `json:"caption"`
		IPAddress string `json:"ipaddress"`
	}

	// let unmarshal do the work of unpacking the JSON
	if err := json.Unmarshal(res, &nodes); err != nil {
		log.Fatal(err)
	}

	// iterate over the resulting slice of node structures
	for _, n := range nodes {
		fmt.Printf("Working with node [%s] on IP address [%s]...\n", n.Caption, n.IPAddress)
	}
}

Bugs

Please create an issue on GitHub with details about the bug and steps to reproduce it.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assignment

type Assignment struct {
	ID             string `json:"CustomPollerAssignmentID"`
	PollerID       string `json:"PollerID"`
	NodeID         int    `json:"NodeID"`
	InterfaceID    int    `json:"InterfaceID"`
	CustomPollerID string `json:"CustomPollerID"`
	InstanceType   string `json:"InstanceType"`
}

Assignment holds all the current UnDP configuration from SolarWinds.

type Client

type Client struct {
	// connection parameters
	URL      string
	Username string
	Password string
	// contains filtered or unexported fields
}

Client structure for the SolarWinds (SWIS) connection.

func NewClient

func NewClient(host, user, pass string, ignoreSSL bool) *Client

NewClient creates a new reference to the Client struct.

func (*Client) AddInterfacePoller

func (c *Client) AddInterfacePoller(customPollerID string, interfaceID int) error

AddInterfacePoller adds a Universal Device Poller (UnDP) to an interface.

func (*Client) AddNodePoller

func (c *Client) AddNodePoller(customPollerID string, nodeID int) error

AddNodePoller adds a Universal Device Poller (UnDP) to a node.

func (*Client) BulkDelete

func (c *Client) BulkDelete(uris []string) ([]byte, error)

BulkDelete wraps post and send a slice of URIs to delete.

func (*Client) BulkSetCustomProperty

func (c *Client) BulkSetCustomProperty(uris []string, name string, value interface{}) error

BulkSetCustomProperty sets a custom property on a series of URIs.

func (*Client) Create

func (c *Client) Create(entity, body interface{}) ([]byte, error)

Create calls the create endpoint and passes the entity and body.

func (*Client) CreateCustomProperty

func (c *Client) CreateCustomProperty(cpEntity, cpType, cpName, cpDesc string) error

CreateCustomProperty creates a new custom property of a specified type.

func (*Client) Delete

func (c *Client) Delete(uri string) ([]byte, error)

Delete wraps post and uses the DELETE method to delete an entity.

func (*Client) GetAssignments

func (c *Client) GetAssignments() ([]Assignment, error)

GetAssignments function returns all the current custom poller assignments in effect at the time.

func (*Client) Invoke

func (c *Client) Invoke(entity, verb string, body interface{}) ([]byte, error)

Invoke calls the invoke endpoint with the entity and verb along with a body.

func (*Client) Query

func (c *Client) Query(query string, parameters interface{}) ([]byte, error)

Query retrieves a result from the SolarWinds API.

func (*Client) QueryColumn

func (c *Client) QueryColumn(query string, parameters interface{}) ([]interface{}, error)

QueryColumn wraps Query and pulls a single column of values into a slice of maps.

func (*Client) QueryOne

func (c *Client) QueryOne(query string, parameters interface{}) (interface{}, error)

QueryOne wraps QueryRow which wraps post and extracts a single value.

func (*Client) QueryRow

func (c *Client) QueryRow(query string, parameters interface{}) ([]byte, error)

QueryRow wraps query and pulls a single row from the result.

func (*Client) Read

func (c *Client) Read(uri string) ([]byte, error)

func (*Client) RemoveNCMNodes

func (c *Client) RemoveNCMNodes(guids []string) error

RemoveNCMNodes deletes nodes from NCM handling in SolarWinds.

func (*Client) SetCustomProperties

func (c *Client) SetCustomProperties(uri string, properties map[string]interface{}) error

SetCustomProperties sets multiple properties on an entity.

func (*Client) SetCustomProperty

func (c *Client) SetCustomProperty(uri, name string, value interface{}) error

SetCustomProperty sets a custom property value on a specific URI.

func (*Client) Update

func (c *Client) Update(uri string, body map[string]interface{}) ([]byte, error)

Update wraps the post function passing the URI and body to update.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL