Code

Add support for host.<attribute> queries.
authorSebastian Harl <sh@tokkee.org>
Sat, 25 Apr 2015 11:59:40 +0000 (13:59 +0200)
committerSebastian Harl <sh@tokkee.org>
Sat, 25 Apr 2015 11:59:40 +0000 (13:59 +0200)
server/query.go

index 6f9722c64a6c37130311bf3e15b9586039964764..cb74f22f479dcd4bbec5dcd787b82f0fdb992c5c 100644 (file)
@@ -72,8 +72,19 @@ func lookup(req request, s *Server) (*page, error) {
                }
 
                if fields := strings.SplitN(tok, ":", 2); len(fields) == 2 {
+                       // Query: [<type>:] [<sibling-type>.]<attribute>:<value> ...
                        if i == 0 && fields[1] == "" {
                                typ = fields[0]
+                       } else if elems := strings.Split(fields[0], "."); len(elems) > 1 {
+                               objs := elems[:len(elems)-1]
+                               for _, o := range objs {
+                                       if o != "host" && o != "service" && o != "metric" {
+                                               return nil, fmt.Errorf("Invalid object type %q", o)
+                                       }
+                               }
+                               args += fmt.Sprintf(" %s.attribute[%s] = %s",
+                                       strings.Join(objs, "."), proto.EscapeString(elems[len(elems)-1]),
+                                       proto.EscapeString(fields[1]))
                        } else {
                                args += fmt.Sprintf(" attribute[%s] = %s",
                                        proto.EscapeString(fields[0]), proto.EscapeString(fields[1]))