-
Notifications
You must be signed in to change notification settings - Fork 3
/
apirt-device.go
177 lines (156 loc) · 3.94 KB
/
apirt-device.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package webui
import (
//"github.com/go-macaron/binding"
"github.com/adejoux/pSeriesCollector/pkg/agent"
"gopkg.in/macaron.v1"
// "time"
)
// NewAPIRtDevice Runtime Device REST API creator
func NewAPIRtDevice(m *macaron.Macaron) error {
//bind := binding.Bind
m.Group("/api/rt/device", func() {
m.Get("/info/", reqSignedIn, RTGetInfo)
m.Get("/info/:id", reqSignedIn, RTGetInfo)
m.Put("/status/activate/:id", reqSignedIn, RTActivateDev)
m.Put("/status/deactivate/:id", reqSignedIn, RTDeactivateDev)
m.Put("/debug/activate/:id", reqSignedIn, RTActHMCAPIDebugDev)
m.Put("/debug/deactivate/:id", reqSignedIn, RTDeactHMCAPIDebugDev)
//m.Get("/reset/:id/:mode", reqSignedIn, RTSnmpReset)
m.Get("/forcegather/:id", reqSignedIn, RTForceGather)
m.Put("/log/setloglevel/:id/:level", reqSignedIn, RTSetLogLevelDev)
m.Get("/log/getdevicelog/:id", reqSignedIn, RTGetLogFileDev)
m.Get("/forcedevscan/:id", reqSignedIn, RTForceHMCScan)
})
return nil
}
/****************/
/*Runtime Info
/****************/
// RTForceHMCScan force scan for HMC devices
func RTForceHMCScan(ctx *Context) {
id := ctx.Params(":id")
d, err := agent.GetDevice(id)
if err != nil {
ctx.JSON(404, err.Error())
return
}
log.Infof("trying to force filter for device %s", id)
d.ForceDevScan()
ctx.JSON(200, "OK")
}
// RTGetLogFileDev get file dev
func RTGetLogFileDev(ctx *Context) {
id := ctx.Params(":id")
d, err := agent.GetDevice(id)
if err != nil {
ctx.JSON(404, err.Error())
return
}
ctx.ServeFile(d.GetLogFilePath())
}
//RTSetLogLevelDev xx
func RTSetLogLevelDev(ctx *Context) {
id := ctx.Params(":id")
level := ctx.Params(":level")
dev, err := agent.GetDevice(id)
if err != nil {
ctx.JSON(404, err.Error())
return
}
log.Infof("set runtime log level from device id %s : %s", id, level)
dev.RTSetLogLevel(level)
ctx.JSON(200, "OK")
}
/*// RTSnmpReset runtime send reset
func RTSnmpReset(ctx *Context) {
id := ctx.Params(":id")
mode := ctx.Params(":mode")
log.Infof("activating runtime on device %s", id)
dev, err := agent.GetDevice(id)
if err != nil {
ctx.JSON(404, err.Error())
return
}
log.Infof("activating runtime on device %s", id)
dev.SnmpReset(mode)
ctx.JSON(200, "OK")
}*/
// RTForceGather force gather
func RTForceGather(ctx *Context) {
id := ctx.Params(":id")
log.Infof("activating runtime on device %s", id)
dev, err := agent.GetDevice(id)
if err != nil {
ctx.JSON(404, err.Error())
return
}
log.Infof("activating runtime on device %s", id)
dev.ForceGather()
ctx.JSON(200, "OK")
}
//RTActivateDev xx
func RTActivateDev(ctx *Context) {
id := ctx.Params(":id")
dev, err := agent.GetDevice(id)
if err != nil {
ctx.JSON(404, err.Error())
return
}
log.Infof("activating runtime on device %s", id)
dev.RTActivate(true)
ctx.JSON(200, "OK")
}
//RTDeactivateDev xx
func RTDeactivateDev(ctx *Context) {
id := ctx.Params(":id")
dev, err := agent.GetDevice(id)
if err != nil {
ctx.JSON(404, err.Error())
return
}
log.Infof("deactivating runtime on device %s", id)
dev.RTActivate(false)
ctx.JSON(200, "OK")
}
//RTActHMCAPIDebugDev xx
func RTActHMCAPIDebugDev(ctx *Context) {
id := ctx.Params(":id")
dev, err := agent.GetDevice(id)
if err != nil {
ctx.JSON(404, err.Error())
return
}
log.Infof("activating snmpdebug %s", id)
dev.RTProtocolDebug(true)
ctx.JSON(200, "OK")
}
//RTDeactHMCAPIDebugDev xx
func RTDeactHMCAPIDebugDev(ctx *Context) {
id := ctx.Params(":id")
dev, err := agent.GetDevice(id)
if err != nil {
ctx.JSON(404, err.Error())
return
}
log.Infof("deactivating snmpdebug %s", id)
dev.RTProtocolDebug(false)
ctx.JSON(200, "OK")
}
//RTGetInfo xx
func RTGetInfo(ctx *Context) {
id := ctx.Params(":id")
if len(id) > 0 {
json, err := agent.GetDeviceJSONInfo(id)
if err != nil {
ctx.JSON(404, err.Error())
return
}
log.Infof("get runtime data from id %s", id)
ctx.RawAsJSON(200, json)
//get only one device info
} else {
devstats := agent.GetDevStats()
ctx.JSON(200, &devstats)
}
return
}