This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.go
154 lines (125 loc) · 3.46 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
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
package main
import (
"encoding/json"
"strconv"
)
func generateStatusCode(n int)(string) {
sn := strconv.Itoa(n)
for i := len(sn) + 4; i < 15; i++ {
sn = " " + sn
}
return "200 " + sn + "\n"
}
func addRoot(i []interface{})([]interface{}) {
var root[] interface{}
if i != nil {
root = append(root, i)
} else {
var empty[] interface{} = make([]interface{}, 0)
return empty
}
return root
}
func generateJson(ss[] interface{})(string) {
j, err := json.Marshal(ss)
if err != nil {
return `["error"]`
} else {
return string(j)
}
}
func processTableStatus()(string) {
var result[] interface{}
result = append(result, 1)
result = append(result, 1)
result = append(result, 1)
result = append(result, 0)
result = append(result, 1)
result = append(result, 1)
result = append(result, 0)
result = append(result, 1)
result = append(result, 1)
result = append(result, 1)
result = append(result, 1629390707)
result = append(result, -1)
result = append(result, "1.2.8p27")
result = append(result, 0)
result = append(result, 0)
result = append(result, 0)
result = append(result, 0)
result = append(result, 1629301880)
result = append(result, "18.10.0")
result = append(result, 50)
return generateJson(addRoot(result))
}
func processTableContacts()(string) {
return `[]`
}
func processTableContactGroups()(string) {
return `[]`
}
func processTableComments()(string) {
return `[]`
}
func processTableDowntimes()(string) {
return `[]`
}
func processTableCommands()(string) {
return `[]`
}
func processTableHosts(pa Parameters)(string) {
sql_filters := ""
var result[] interface{}
if len(pa.filters) > 0 {
sql_filters = filters_to_sql(pa.filters)
}
stats_filters := stats_to_sql(pa.stats)
sql_str := generate_hosts_sql(pa.columns, sql_filters, stats_filters, pa.limit)
result = exec_sql(sql_str, pa.table)
return generateJson(result)
}
func processTableServices(pa Parameters)(string) {
sql_filters := ""
var result[] interface{}
if len(pa.filters) > 0 {
sql_filters = filters_to_sql(pa.filters)
}
stats_filters := stats_to_sql(pa.stats)
sql_str := generate_services_sql(pa.columns, sql_filters, stats_filters, pa.limit)
result = exec_sql(sql_str, pa.table)
return generateJson(result)
}
func processCommand(pa Parameters)(string) {
result := ""
statusCode := ""
switch pa.table {
case "status":
result = processTableStatus()
break
case "hosts":
result = processTableHosts(pa)
break
case "services":
result = processTableServices(pa)
break
case "contacts":
result = processTableContacts()
break
case "contactgroups":
result = processTableContactGroups()
break
case "comments":
result = processTableComments()
break
case "downtimes":
result = processTableDowntimes()
break
case "commands":
result = processTableCommands()
break
default:
break
}
statusCode = generateStatusCode(len(result) + 1)
return statusCode + result + "\n"
}