SolarWinds Orion SDK

repository·master·Indexed 19 days ago

https://github.com/solarwinds/orionsdk

Tools for interacting with the SolarWinds Orion platform API, including a PowerShell module, the SWQL Studio graphical query tool, and code samples. Provides documentation for the Orion schema and API, installation guides via Chocolatey or manual download, and Go implementation examples using the gosolar library for tasks such as updating custom properties, managing SNMP versions, and creating dependencies.

Tokens
10.3K
Snippets
24
Records
33
Agent score
54%

What's inside Orion SDK

  1. Use ScintillaNET-FindReplaceDialog for ScintillaNET v3

    master

    ScintillaNET-FindReplaceDialog provides a Find & Replace Dialog, a Goto Dialog, and Incremental Search functionality for applications using ScintillaNET v3.

    Note: This component is not available via NuGet. It must be included in your project by copying the source code directly from the original repository (https://github.com/Stumpii/ScintillaNET-FindReplaceDialog).

  2. Install the Orion SDK tools

    master

    You can install the Orion SDK tools (which include samples, the SWQL Studio graphical query tool, and the PowerShell module) using one of the following methods:

    1. Manual Download: Download pre-compiled installers from the GitHub releases page.
    2. Chocolatey: If you use Chocolatey, run the following command in your terminal:
      choco install orionsdk
    choco install orionsdk
  3. Change SNMP version for a node using gosolar

    master

    To change the SNMP version of a node in SolarWinds using the gosolar SDK, you must first retrieve the node's unique Uri via a SWQL query, and then perform an Update operation on that URI with a payload containing the new SNMP configuration.

    When updating to SNMPv3, the request payload should include the following keys:

    • SNMPVersion: Set to 3.
    • SNMPV3Username: The username for SNMPv3.
    • SNMPV3Context: The SNMPv3 context.
    • SNMPV3PrivMethod: The privacy method (e.g., None, DES56, AES128, AES 192, AES256).
    • SNMPV3PrivKey: The privacy key.
    • SNMPV3AuthMethod: The authentication method (e.g., None, MD5, SHA1).
    • SNMPV3AuthKey: The authentication key.
    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))
    	}
    }
  4. Manage NCM profiles using gosolar in Go

    master

    To manage NCM (Network Configuration Manager) profiles, you can use the gosolar client to query for specific nodes and then update their properties.

    1. Connect: Initialize a client using gosolar.NewClient(hostname, username, password, useSsl).
    2. Query: Execute a SWQL (SolarWinds Query Language) query using client.Query(query, params) to retrieve the Uri of the target node.
    3. Update: Use client.Update(uri, properties) where properties is a map[string]interface{} containing the fields you wish to change (e.g., ConnectionProfile).
    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)
    	}
    }
  5. Update a custom property using gosolar

    master

    To update a custom property for a specific entity (like a Node), you must first retrieve the entity's Uri via a SWQL query. Once you have the Uri, use the SetCustomProperty method on the gosolar.Client instance. This method takes the entity's Uri, the name of the custom property (as a string), and the new value.

    // 1. Initialize the client
    c := gosolar.NewClient(hostname, username, password, true)
    
    // 2. Retrieve the URI of the target entity via SWQL
    parameters := map[string]interface{}{
        "id": 1,
    }
    res, err := c.Query(`SELECT Uri FROM Orion.Nodes WHERE NodeID = @id`, parameters)
    
    // ... unmarshal res into a struct containing the 'Uri' field ...
    
    // 3. Update the custom property
    err = c.SetCustomProperty(nodes[0].URI, "City", "Los Angeles")
  6. Retrieve Container details via SWQL query

    master

    You can fetch specific container properties using the QueryRow method on the gosolar.Client. This is useful for obtaining the current state of a container before performing an update.

    When querying the Orion.Container entity, ensure your SELECT statement matches the fields expected by your local data structures (e.g., ContainerID, Name, Owner, Frequency, statusCalculator, Description, and pollingEnabled).

    query := `
    	SELECT
    		Container.ContainerID AS ID
    		, Container.Name AS Name
    		, Container.Owner AS Owner
    		, Container.Frequency AS Frequency
    		, Container.statusCalculator AS StatusCalculator
    		, Container.Description AS Description
    		, Container.pollingEnabled AS PollingEnabled
    	FROM Orion.Container AS Container
    	WHERE Container.Name = @containerName
    `
    
    parameters := map[string]interface{}{
    	"containerName": "Serenity Group",
    }
    
    // Execute query and unmarshal result
    row, err := client.QueryRow(query, parameters)
    if err != nil {
    	return nil, err
    }
    
    var container Group
    if err := json.Unmarshal(row, &container); err != nil {
    	return nil, err
    }
  7. Unmanage a node using the Orion SDK in Go

    master

    To unmanage a node in Orion, you must use the Invoke method on a gosolar.Client instance. This requires calling the Unmanage verb on the Orion.Nodes entity.

    The Invoke method for unmanaging nodes expects a slice of interface values ([]interface{}) containing the following parameters in order:

    1. Node Identifier: A string formatted as N:<NodeID> (e.g., N:123).
    2. Start Time: A time.Time object representing the beginning of the unmanaged period (UTC recommended).
    3. End Time: A time.Time object representing the end of the unmanaged period (UTC recommended).
    4. Unmanaged Flag: A boolean value (typically false to indicate the node should be unmanaged/not monitored).

    Before invoking the unmanage command, you typically use c.Query with a SWQL (SolarWinds Query Language) statement to retrieve the NodeID and other necessary metadata.

    // 1. Initialize client
    c := gosolar.NewClient(hostname, username, password, true)
    
    // 2. Prepare parameters for Unmanage
    nowUTC := time.Now().UTC()
    laterUTC := nowUTC.Add(time.Hour * 48)
    
    // The properties slice must follow the exact order required by the Orion.Nodes.Unmanage verb:
    // ["N:<ID>", startTime, endTime, unmanagedFlag]
    properties := []interface{}{
        fmt.Sprintf("N:%d", n.NodeID),
        nowUTC,
        laterUTC,
        false,
    }
    
    // 3. Invoke the verb
    _, err := c.Invoke("Orion.Nodes", "Unmanage", properties)
    if err != nil {
        log.Fatal(err)
    }