aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/monfront/main.go46
1 files changed, 28 insertions, 18 deletions
diff --git a/cmd/monfront/main.go b/cmd/monfront/main.go
index b8ba1de..57904a5 100644
--- a/cmd/monfront/main.go
+++ b/cmd/monfront/main.go
@@ -347,27 +347,37 @@ func showChecks(w http.ResponseWriter, r *http.Request) {
func showGroups(w http.ResponseWriter, r *http.Request) {
con := Context{}
- query := `select groupid, groupname, nodeid, nodename, mapping_id, state
- from (
- select g.id groupid, g.name groupname, n.id nodeid, n.name nodename, ac.mapping_id,
- ac.states[1] state, max(ac.states[1]) over (partition by c.node_id) maxstate
- from groups g
- join nodes_groups ng on g.id = ng.group_id
- join nodes n on ng.node_id = n.id
- join checks c on n.id = c.node_id
- join active_checks ac on c.id = ac.check_id
- join mapping_level ml on ac.mapping_id = ml.mapping_id and ac.states[1] = ml.target
- ) s
- where state = maxstate`
+ query := `select
+ group_id,
+ group_name,
+ node_id,
+ node_name,
+ mapping_id,
+ state
+from (
+ select
+ g.id group_id,
+ g.name group_name,
+ n.id node_id,
+ n.name node_name,
+ ac.states[1] state,
+ ac.mapping_id,
+ ac.acknowledged,
+ row_number() over (partition by c.node_id order by ac.states[1] desc) maxstate
+ from groups g
+ join nodes_groups ng on g.id = ng.group_id
+ join nodes n on ng.node_id = n.id
+ join checks c on n.id = c.node_id
+ join active_checks ac on c.id = ac.check_id
+ %s
+ order by g.name, n.name
+) groups
+where maxstate = 1`
if strings.HasPrefix(r.URL.Path, "/unhandled") {
- query += ` and state > 0`
+ query = fmt.Sprintf(query, `where ac.states[1] != 0 and acknowledged = false`)
con.Unhandled = true
- }
-
- if strings.HasPrefix(r.URL.Path, "/unhandled") {
- query += ` order by state desc, groupname, nodename`
} else {
- query += ` order by groupname, nodename`
+ query = fmt.Sprintf(query, "")
}
rows, err := DB.Query(query)