This repository has been archived by the owner on Sep 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
poundctl.go
84 lines (64 loc) · 1.74 KB
/
poundctl.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
84
package poundctl
import (
"encoding/xml"
"os/exec"
)
type ListenerStatus string
const (
ListenerStatus_Active ListenerStatus = "active"
ListenerStatus_Disabled ListenerStatus = "DISABLED"
)
type ListenerProtocol string
const (
ListenerProtocol_HTTP ListenerProtocol = "http"
ListenerProtocol_HTTPS ListenerProtocol = "HTTPS"
)
type AliveStatus string
const (
AliveStatus_Alive AliveStatus = "yes"
AliveStatus_Dead AliveStatus = "DEAD"
)
type PoundStatus struct {
XMLName xml.Name `xml:"pound"`
Queue PoundQueue `xml:"queue"`
Listeners []PoundListener `xml:"listener"`
}
type PoundQueue struct {
Size int `xml:"size,attr"`
}
type PoundListener struct {
ID int `xml:"index,attr"`
Protocol ListenerProtocol `xml:"protocol,attr"`
Address string `xml:"address,attr"`
Status ListenerStatus `xml:"status,attr"`
Services []PoundService `xml:"service"`
}
type PoundService struct {
ID int `xml:"index,attr"`
Name string `xml:"name,attr"`
Status ListenerStatus `xml:"status,attr"`
Backends []PoundBackend `xml:"backend"`
}
type PoundBackend struct {
ID int `xml:"index,attr"`
Address string `xml:"address,attr"`
Avg float32 `xml:"avg,attr"`
Priority int `xml:"priority,attr"`
Alive AliveStatus `xml:"alive,attr"`
Status ListenerStatus `xml:"status,attr"`
}
func GetStatus(socketFile string) (*PoundStatus, error) {
x, err := exec.Command("poundctl", "-c", socketFile, "-X").Output()
if err != nil {
return nil, err
}
return ParseStatusXml(x)
}
func ParseStatusXml(resultXml []byte) (*PoundStatus, error) {
v := PoundStatus{}
err := xml.Unmarshal(resultXml, &v)
if err != nil {
return nil, err
}
return &v, nil
}