This repository has been archived by the owner on Jun 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
custompollers.go
83 lines (69 loc) · 2.09 KB
/
custompollers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package gosolar
import (
"encoding/json"
"fmt"
)
// Assignment holds all the current UnDP configuration from SolarWinds.
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"`
}
// GetAssignments function returns all the current custom poller assignments
// in effect at the time.
func (c *Client) GetAssignments() ([]Assignment, error) {
query := `
SELECT
CustomPollerAssignmentID
,CustomPollerID
,NodeID
,InterfaceID
,CustomPollerID
,InstanceType
FROM Orion.NPM.CustomPollerAssignment
`
res, err := c.Query(query, nil)
if err != nil {
return []Assignment{}, fmt.Errorf("failed to query for assignments: %v", err)
}
var assignments []Assignment
if err := json.Unmarshal(res, &assignments); err != nil {
return []Assignment{}, fmt.Errorf("failed to unmarshal assignments: %v", err)
}
return assignments, nil
}
// AddNodePoller adds a Universal Device Poller (UnDP) to a node.
func (c *Client) AddNodePoller(customPollerID string, nodeID int) error {
entity := "Orion.NPM.CustomPollerAssignmentOnNode"
request := struct {
NodeID int `json:"NodeID"`
CustomPollerID string `json:"CustomPollerID"`
}{
NodeID: nodeID,
CustomPollerID: customPollerID,
}
_, err := c.post("Create/"+entity, request)
if err != nil {
return fmt.Errorf("failed to add poller: %v", err)
}
return nil
}
// AddInterfacePoller adds a Universal Device Poller (UnDP) to an interface.
func (c *Client) AddInterfacePoller(customPollerID string, interfaceID int) error {
entity := "Orion.NPM.CustomPollerAssignmentOnInterface"
request := struct {
InterfaceID int `json:"InterfaceID"`
CustomPollerID string `json:"CustomPollerID"`
}{
InterfaceID: interfaceID,
CustomPollerID: customPollerID,
}
_, err := c.post("Create/"+entity, request)
if err != nil {
return fmt.Errorf("failed to add poller: %v", err)
}
return nil
}