diff options
author | Gibheer <gibheer+git@zero-knowledge.org> | 2019-03-08 16:45:28 +0100 |
---|---|---|
committer | Gibheer <gibheer+git@zero-knowledge.org> | 2019-03-08 16:45:28 +0100 |
commit | 361ca94ca3ffc60f5f633bd2071b1b598c1c42ff (patch) | |
tree | cdc556e72edcbbe39e36a686822c59acb2b1c1a2 /cmd/monfront | |
parent | bef2cfa349615d2dd61c6426df9a7587a8b519e4 (diff) |
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.
Diffstat (limited to 'cmd/monfront')
-rw-r--r-- | cmd/monfront/main.go | 46 |
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) |