From 361ca94ca3ffc60f5f633bd2071b1b598c1c42ff Mon Sep 17 00:00:00 2001 From: Gibheer Date: Fri, 8 Mar 2019 16:45:28 +0100 Subject: monfront - fix group list It was possible that a node was showing multiple times when it had more than one check. That wasn't the purpose of that list. Now each node only comes up once and its worst state is shown. --- cmd/monfront/main.go | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'cmd/monfront') 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) -- cgit v1.2.3-70-g09d2