From ab1f53c34612dc816a00055c283884bf316e5f1c Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sat, 25 Apr 2015 13:59:40 +0200 Subject: [PATCH] Add support for host. queries. --- server/query.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/query.go b/server/query.go index 6f9722c..cb74f22 100644 --- a/server/query.go +++ b/server/query.go @@ -72,8 +72,19 @@ func lookup(req request, s *Server) (*page, error) { } if fields := strings.SplitN(tok, ":", 2); len(fields) == 2 { + // Query: [:] [.]: ... 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])) -- 2.30.2