/
query.go
97 lines (80 loc) · 2.89 KB
/
query.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
package nqm
import (
commonDb "github.com/Cepave/open-falcon-backend/common/db"
)
// The query conditions of agent
type AgentQuery struct {
Name string `mvc:"query[name]" conform:"trim"`
ConnectionId string `mvc:"query[connection_id]" conform:"trim"`
Hostname string `mvc:"query[hostname]" conform:"trim"`
IpAddress string `mvc:"query[ip_address]" conform:"trim"`
IspId int16 `mvc:"query[isp_id]"`
HasIspIdParam bool `mvc:"query[?isp_id]"`
Status bool `mvc:"query[status]"`
HasStatusParam bool `mvc:"query[?status]"`
}
// Gets the []byte used to perform like in MySql
func (query *AgentQuery) GetIpForLikeCondition() []byte {
bytes, err := commonDb.IpV4ToBytesForLike(query.IpAddress)
if err != nil {
panic(err)
}
return bytes
}
type AgentQueryWithPingTask struct {
AgentQuery
PingTaskId int32 `mvc:"param[pingtask_id]"`
Applied bool `mvc:"query[applied]"`
HasApplied string `mvc:"query[applied] default[!N!]"`
}
func (query *AgentQueryWithPingTask) HasAppliedCondition() bool {
return query.HasApplied != "!N!"
}
type TargetsOfAgentQuery struct {
AgentID int32 `mvc:"param[agent_id]"`
TargetQuery *TargetQuery
}
// The query conditions of target
type TargetQuery struct {
Name string `mvc:"query[name]"`
Host string `mvc:"query[host]"`
IspId int16 `mvc:"query[isp_id]"`
HasIspIdParam bool `mvc:"query[?isp_id]"`
Status bool `mvc:"query[status]"`
HasStatusParam bool `mvc:"query[?status]"`
}
type AgentFilter struct {
Name []string `json:"name" digest:"1"`
Hostname []string `json:"hostname" digest:"2"`
IpAddress []string `json:"ip_address" digest:"3"`
ConnectionId []string `json:"connection_id" digest:"4"`
IspIds []int16 `json:"isp_ids" digest:"21"`
ProvinceIds []int16 `json:"province_ids" digest:"22"`
CityIds []int16 `json:"city_ids" digest:"23"`
NameTagIds []int16 `json:"name_tag_ids" digest:"24"`
GroupTagIds []int32 `json:"group_tag_ids" digest:"25"`
}
func (f *AgentFilter) HasAgentDescriptive() bool {
return len(f.Name)+len(f.Hostname)+
len(f.IpAddress)+len(f.ConnectionId) > 0
}
type TargetFilter struct {
Name []string `json:"name" digest:"1"`
Host []string `json:"host" digest:"2"`
IspIds []int16 `json:"isp_ids" digest:"21"`
ProvinceIds []int16 `json:"province_ids" digest:"22"`
CityIds []int16 `json:"city_ids" digest:"23"`
NameTagIds []int16 `json:"name_tag_ids" digest:"24"`
GroupTagIds []int32 `json:"group_tag_ids" digest:"25"`
}
func (f *TargetFilter) HasTargetDescriptive() bool {
return len(f.Name)+len(f.Host) > 0
}
// The query parameters filtering pingtasks
type PingtaskQuery struct {
Period string `mvc:"query[period]"`
Name string `mvc:"query[name]"`
Enable string `mvc:"query[enable]"`
Comment string `mvc:"query[comment]"`
NumOfEnabledAgents string `mvc:"query[num_of_enabled_agents]"`
}