summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a5bd496)
raw | patch | inline | side by side (parent: a5bd496)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 26 Nov 2014 21:18:20 +0000 (22:18 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 26 Nov 2014 21:18:20 +0000 (22:18 +0100) |
A query may now be prefixed with <type>: to chose a different type. The
default is still hosts.
default is still hosts.
server/query.go | patch | blob | history | |
templates/main.tmpl | patch | blob | history |
diff --git a/server/query.go b/server/query.go
index a8a9501603ab0667d1c66b6240301d88909f4174..e303d93069a1d094e11489cb8677cef2aa634edc 100644 (file)
--- a/server/query.go
+++ b/server/query.go
return nil, errors.New("Empty query")
}
+ typ := "hosts"
var args string
for i, tok := range tokens {
- if i != 0 {
+ if len(args) > 0 {
args += " AND"
}
if fields := strings.SplitN(tok, ":", 2); len(fields) == 2 {
- args += fmt.Sprintf(" attribute[%s] = %s",
- proto.EscapeString(fields[0]), proto.EscapeString(fields[1]))
+ if i == 0 && fields[1] == "" {
+ typ = fields[0]
+ } else {
+ args += fmt.Sprintf(" attribute[%s] = %s",
+ proto.EscapeString(fields[0]), proto.EscapeString(fields[1]))
+ }
} else {
args += fmt.Sprintf(" name =~ %s", proto.EscapeString(tok))
}
}
- res, err := s.query("LOOKUP hosts MATCHING" + args)
+ res, err := s.query("LOOKUP %s MATCHING"+args, identifier(typ))
if err != nil {
return nil, err
}
- return tmpl(s.results["hosts"], res)
+ if t, ok := s.results[typ]; ok {
+ return tmpl(t, res)
+ }
+ return nil, fmt.Errorf("Unsupported type %s", typ)
}
func fetch(req request, s *Server) (*page, error) {
diff --git a/templates/main.tmpl b/templates/main.tmpl
index c48b2234c964d1808e391254d9a8bbf7cab7c6c8..254a22ab714cbeb97f0a13bae3197d09338a0d99 100644 (file)
--- a/templates/main.tmpl
+++ b/templates/main.tmpl
<div class="searchbox">
<form action="/lookup" method="POST">
- <input type="text" name="query" value="{{.Query}}" placeholder="Search hosts"
+ <input type="text" name="query" value="{{.Query}}" placeholder="Search objects"
required /><button type="submit">GO</button>
</form>
</div>