generated from sensu/check-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzun.go
50 lines (42 loc) · 1.36 KB
/
zun.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
package main
import (
"github.com/gophercloud/gophercloud/v2"
"github.com/gophercloud/gophercloud/v2/pagination"
)
type ZunService struct {
Binary string `json:"binary"`
AvailabilityZone string `json:"availability_zone"`
State string `json:"state"`
ReportCount int `json:"report_count"`
Disabled bool `json:"disabled"`
DisableReason string `json:"disable_reason"`
ForceDown bool `json:"force_down"`
Host string `json:"host"`
ID int `json:"id"`
LastSeenUp AnyTime `json:"last_seen_up"`
CreatedAt AnyTime `json:"created_at"`
UpdatedAt AnyTime `json:"updated_at"`
}
type ZunServicePage struct {
pagination.SinglePageBase
}
func (page ZunServicePage) IsEmpty() (bool, error) {
if page.StatusCode == 204 {
return true, nil
}
services, err := ExtractZunServices(page)
return len(services) == 0, err
}
func ExtractZunServices(r pagination.Page) ([]ZunService, error) {
var s struct {
Service []ZunService `json:"services"`
}
err := (r.(ZunServicePage)).ExtractInto(&s)
return s.Service, err
}
func ZunServiceList(client *gophercloud.ServiceClient) pagination.Pager {
url := client.ServiceURL("services")
return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
return ZunServicePage{pagination.SinglePageBase(r)}
})
}