aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorGibheer <gibheer+git@zero-knowledge.org>2018-11-29 10:56:20 +0100
committerGibheer <gibheer+git@zero-knowledge.org>2018-11-29 10:56:20 +0100
commit3400167c98c78a2cf104cd4be3907450e01c56ff (patch)
tree6eef544b947804c86c2eed4a910f910e20c98c4b /cmd
parent0456e8e407d792d419124c287e325ea2a196b383 (diff)
monfront - add initial work for unhandled links
This will return the unhandled groups/checks/whatever but is still work in progress.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/monfront/main.go103
1 files changed, 93 insertions, 10 deletions
diff --git a/cmd/monfront/main.go b/cmd/monfront/main.go
index 544d4f3..ec3eeb1 100644
--- a/cmd/monfront/main.go
+++ b/cmd/monfront/main.go
@@ -10,6 +10,7 @@ import (
"io/ioutil"
"log"
"net/http"
+ "strings"
"time"
"github.com/lib/pq"
@@ -47,6 +48,9 @@ func main() {
http.HandleFunc("/", showChecks)
http.HandleFunc("/action", checkAction)
+ http.HandleFunc("/unhandled/checks", showChecks)
+ http.HandleFunc("/unhandled/hosts", showUnhandledHosts)
+ http.HandleFunc("/unhandled/groups", showUnhandledGroups)
http.ListenAndServe(config.Listen, nil)
}
@@ -122,13 +126,22 @@ func checkAction(w http.ResponseWriter, r *http.Request) {
log.Printf("could not adjust checks %#v: %s", checks, err)
return
}
- w.Header()["Location"] = []string{"/"}
+ ref, found := r.Header["Referrer"]
+ if found {
+ w.Header()["Location"] = ref
+ } else {
+ w.Header()["Location"] = []string{"/"}
+ }
w.WriteHeader(http.StatusSeeOther)
return
}
func showChecks(w http.ResponseWriter, r *http.Request) {
- rows, err := DB.Query(SQLShowChecks)
+ query := SQLShowChecks
+ if strings.HasPrefix(r.URL.Path, "/unhandled") {
+ query = SQLShowUnhandledChecks
+ }
+ rows, err := DB.Query(query)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("problems with the database"))
@@ -137,7 +150,7 @@ func showChecks(w http.ResponseWriter, r *http.Request) {
}
type check struct {
- Name string
+ NodeName string
CommandName string
CheckID int64
State int
@@ -150,7 +163,7 @@ func showChecks(w http.ResponseWriter, r *http.Request) {
checks := []check{}
for rows.Next() {
c := check{}
- err := rows.Scan(&c.CheckID, &c.Name, &c.CommandName, &c.State, &c.Notify, &c.Enabled, &c.Notice, &c.NextTime, &c.Msg)
+ err := rows.Scan(&c.CheckID, &c.NodeName, &c.CommandName, &c.State, &c.Notify, &c.Enabled, &c.Notice, &c.NextTime, &c.Msg)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("problems with the database"))
@@ -176,6 +189,51 @@ func showChecks(w http.ResponseWriter, r *http.Request) {
return
}
+func showUnhandledHosts(w http.ResponseWriter, r *http.Request) {
+}
+func showUnhandledGroups(w http.ResponseWriter, r *http.Request) {
+ rows, err := DB.Query(SQLShowUnhandledGroups)
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ w.Write([]byte("problems with the database"))
+ log.Printf("could not get check list: %s", err)
+ return
+ }
+
+ type check struct {
+ GroupName string
+ NodeName string
+ State int
+ }
+ checks := []check{}
+ for rows.Next() {
+ c := check{}
+ err := rows.Scan(&c.GroupName, &c.NodeName, &c.State)
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ w.Write([]byte("problems with the database"))
+ log.Printf("could not get check list: %s", err)
+ return
+ }
+ checks = append(checks, c)
+ }
+ tmpl, err := template.New("checklist").Parse(TmplUnhandledGroups)
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ w.Write([]byte("problems with a template"))
+ log.Printf("could not parse template: %s", err)
+ return
+ }
+ w.Header()["Content-Type"] = []string{"text/html"}
+ if err := tmpl.Execute(w, checks); err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ w.Write([]byte("problem with a template"))
+ log.Printf("could not execute template: %s", err)
+ return
+ }
+ return
+}
+
var (
SQLShowChecks = `select c.id, n.name, co.name, ac.states[1] as state, ac.notify,
ac.enabled, ac.notice, ac.next_time, ac.msg
@@ -184,6 +242,22 @@ var (
join nodes n on c.node_id = n.id
join commands co on c.command_id = co.id
order by n.name, co.name;`
+ SQLShowUnhandledChecks = `select c.id, n.name, co.name, ac.states[1] as state, ac.notify,
+ ac.enabled, ac.notice, ac.next_time, ac.msg
+ from active_checks ac
+ join checks c on ac.check_id = c.id
+ join nodes n on c.node_id = n.id
+ join commands co on c.command_id = co.id
+ where ac.states[1] > 0
+ order by n.name, co.name;`
+ SQLShowUnhandledGroups = `select g.name, n.name, max(ac.state[1])
+ 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
+ where ac.states[1] > 0
+ group by g.name, n.name;`
)
var (
@@ -199,10 +273,10 @@ var (
justify-content: center;
align-items: flex-start;
}
- form menu { order: 1; }
+ form nav { order: 1; }
form content { order: 2; flex-grow: 1; }
- form menu { display: flex; flex-direction: column; }
- form menu > * { margin: 0.5em; }
+ form nav { display: flex; flex-direction: column; }
+ form nav > * { margin: 0.5em; }
table td, table th { padding: 0.5em; }
td.state-0 { background: green; }
td.state-1 { background: orange; }
@@ -211,9 +285,17 @@ var (
</style>
</head>
<body>
+ <nav id="mainmenu">
+ <ul>
+ <li><a href="/">home</a></li>
+ <li><a href="/unhandled/checks">unhandled checks</a></li>
+ <li><a href="/unhandled/hosts">unhandled hosts</a></li>
+ <li><a href="/unhandled/groups">unhandled groups</a></li>
+ </ul>
+ </nav>
<form method="post" action="/action">
<section>
- <menu>
+ <nav>
<div class="option">
<label for="action">Action</label>
<select name="action">
@@ -231,7 +313,7 @@ var (
<input name="comment" />
</div>
<button type="submit">submit</button>
- </menu>
+ </nav>
<content>
<table>
<thead><tr><th></th><th>host</th><th>status</th><th>next check</th><th>message</th></tr></thead>
@@ -239,7 +321,7 @@ var (
{{ range . }}
<tr>
<td><input type="checkbox" name="checks" value="{{ .CheckID }}" /></td>
- <td>{{ .Name }}</td>
+ <td>{{ .NodeName }}</td>
<td class="state-{{ .State }}">{{ .CommandName }} - {{ .State }}</td>
<td>{{ .NextTime.Format "2006.01.02 15:04:05" }}</td>
<td><pre>{{ .Msg }}</pre></td>
@@ -251,4 +333,5 @@ var (
</form>
</body>
</html>`
+ TmplUnhandledGroups = `TODO`
)