-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearches.go
72 lines (66 loc) · 1.59 KB
/
searches.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
package splunk
import (
"net/url"
"time"
"github.com/pkg/errors"
)
type searches struct {
}
var (
Searches = &searches{}
)
type SearchRsp struct {
Updated time.Time `json:"updated"`
Entry []struct {
Name string `json:"name"`
Updated time.Time `json:"updated"`
Author string `json:"author"`
Content struct {
SplunkHecTarget string `json:"action.forward_alert_to_splunk_hec.param.splunk_hec_target"`
ActionWebhookURL string `json:"action.webhook.param.url"`
Actions string `json:"actions"`
CronSchedule string `json:"cron_schedule"`
Disabled bool `json:"disabled"`
IsScheduled bool `json:"is_scheduled"`
Search string `json:"search"`
} `json:"content"`
} `json:"entry"`
Paging struct {
Total int `json:"total"`
} `json:"paging"`
}
func (s *searches) List() (*SearchRsp, error) {
if client == nil {
return nil, ErrClientNotInit
}
_rsp := &SearchRsp{}
rsp, err := client.R().
SetDebug(clientDebug).
SetResult(&_rsp).
SetQueryParamsFromValues(url.Values{
"f": []string{
"search",
"actions",
"action.webhook",
"action.webhook.param.url",
"action.forward_alert_to_splunk_hec",
"action.forward_alert_to_splunk_hec.param.splunk_hec_target",
"cron_schedule",
"is_scheduled",
"disabled",
},
}).
SetQueryParams(map[string]string{
"output_mode": "json",
"count": "500",
}).
Get("/services/saved/searches")
if err != nil {
return nil, err
}
if !rsp.IsSuccess() {
err = errors.Errorf("%s %s", rsp.Status(), rsp.String())
return nil, err
}
return _rsp, nil
}