Beispiel #1
0
 def __init__(self, pattern, startTime, endTime):
   self.pattern = pattern
   self.startTime = startTime
   self.endTime = endTime
   self.isExact = is_pattern(pattern)
   self.interval = Interval(float('-inf') if startTime is None else startTime,
                            float('inf') if endTime is None else endTime)
Beispiel #2
0
  def subtree_query(self, root, query_parts):
    if query_parts:
      my_query = query_parts[0]
      if is_pattern(my_query):
        matches = [root[1][node] for node in match_entries(root[1], my_query)]
      elif my_query in root[1]:
        matches = [ root[1][my_query] ]
      else:
        matches = []

    else:
      matches = root[1].values()

    for child_node in matches:
      result = {
        'path' : child_node[0],
        'is_leaf' : bool(child_node[0]),
      }
      if result['path'] is not None and not result['is_leaf']:
        result['path'] += '.'
      yield result

      if query_parts:
        for result in self.subtree_query(child_node, query_parts[1:]):
          yield result
Beispiel #3
0
  def subtree_query(self, root, query_parts):
    if query_parts:
      my_query = query_parts[0]
      if is_pattern(my_query):
        matches = [root[1][node] for node in match_entries(root[1], my_query)]
      elif my_query in root[1]:
        matches = [ root[1][my_query] ]
      else:
        matches = []

    else:
      matches = root[1].values()

    for child_node in matches:
      result = {
        'path' : child_node[0],
        'is_leaf' : bool(child_node[0]),
      }
      if result['path'] is not None and not result['is_leaf']:
        result['path'] += '.'
      yield result

      if query_parts:
        for result in self.subtree_query(child_node, query_parts[1:]):
          yield result
Beispiel #4
0
 def __init__(self, pattern, startTime, endTime,
              local=False, headers=None, leaves_only=None):
     self.pattern = pattern
     self.startTime = startTime
     self.endTime = endTime
     self.isExact = is_pattern(pattern)
     self.interval = Interval(
         float('-inf') if startTime is None else startTime,
         float('inf') if endTime is None else endTime)
     self.local = local
     self.headers = headers
     self.leaves_only = leaves_only
Beispiel #5
0
 def __init__(self, pattern, startTime, endTime,
              local=False, headers=None, leaves_only=None):
     self.pattern = pattern
     self.startTime = startTime
     self.endTime = endTime
     self.isExact = is_pattern(pattern)
     self.interval = Interval(
         float('-inf') if startTime is None else startTime,
         float('inf') if endTime is None else endTime)
     self.local = local
     self.headers = headers
     self.leaves_only = leaves_only
Beispiel #6
0
    def find_nodes(self, query, request=None):
        # XXX --- revisit this code
        #print query
        #print query.pattern
        pattern = remove_metachars(query.pattern)
        parts = pattern.split('.')
        if is_pattern(parts[-1]):
            path = '/'.join([p.replace('@', '.') for p in parts[:-1]])
            metric_path = '.'.join(parts[:-1])
            pattern = parts[-1]
        else:
            path = '/'.join([p.replace('@', '.') for p in parts])
            metric_path = '.'.join(parts)
            pattern = None

        if request.user and request.user.is_authenticated():
            print "WE GOT ONE!!!"
            client = self.auth_client
        else:
            client = self.client

        #print ">>> path", path
        r = client.get(path)

        if type(r) == list:
            # XXX hack -- if we get multiple results use the most recent
            r = r[-1]

        if r.has_key('children'):
            for child in r['children']:
                if path != '':
                    cpath = metric_path + '.'
                else:
                    cpath = ''

                label = None
                if child.has_key('name'):
                    if path.endswith('interface') and \
                            (not child.has_key('name')
                                    or child['name'] == ''):
                        if not 'dev-alu' in path:
                            continue
                    name = child['name']
                    if child.has_key('name'):
                        label = "%s %s" % (name, child['name'])
                        label = label.replace('"', '')
                else:
                    name = parts[-1]

                cpath += name.replace('.', '@')
                # XXX KLUDGE! need to revist various path translation crap
                if 'error/' in cpath:
                    cpath = cpath.replace('error/', 'error.')
                if 'discard/' in cpath:
                    cpath = cpath.replace('discard/', 'discard.')

                if child['leaf']:
                    #print "CHILD", child, cpath
                    reader = EsmondReader(self.uri,
                                          cpath,
                                          query.startTime,
                                          query.endTime,
                                          username=self.username,
                                          password=self.password,
                                          debug=self.debug)
                    yield EsmondLeaf(cpath,
                                     reader,
                                     client=client,
                                     name=name,
                                     label=label)
                else:
                    yield EsmondBranch(cpath, name=name, label=label)
        else:
            reader = EsmondReader(self.uri,
                                  path,
                                  query.startTime,
                                  query.endTime,
                                  username=self.username,
                                  password=self.password,
                                  debug=self.debug)

            yield EsmondLeaf(path, reader, client=client)
Beispiel #7
0
    def find_nodes(self, query, request=None):
        # XXX --- revisit this code
        #print query
        #print query.pattern
        pattern = remove_metachars(query.pattern)
        parts = pattern.split('.')
        if is_pattern(parts[-1]):
            path = '/'.join([p.replace('@', '.') for p in parts[:-1]])
            metric_path = '.'.join(parts[:-1])
            pattern = parts[-1]
        else:
            path = '/'.join([p.replace('@', '.') for p in parts])
            metric_path = '.'.join(parts)
            pattern = None

        if request.user and request.user.is_authenticated():
            print "WE GOT ONE!!!"
            client = self.auth_client
        else:
            client = self.client

        #print ">>> path", path
        r = client.get(path)

        if type(r) == list:
            # XXX hack -- if we get multiple results use the most recent
            r = r[-1]

        if r.has_key('children'):
            for child in r['children']:
                if path != '':
                    cpath = metric_path + '.'
                else:
                    cpath = ''

                label = None
                if child.has_key('name'):
                    if path.endswith('interface') and \
                            (not child.has_key('name')
                                    or child['name'] == ''):
                        if not 'dev-alu' in path:
                            continue
                    name = child['name']
                    if child.has_key('name'):
                        label = "%s %s" % (name, child['name'])
                        label = label.replace('"','')
                else:
                    name = parts[-1]

                cpath += name.replace('.','@')
                # XXX KLUDGE! need to revist various path translation crap
                if 'error/' in cpath:
                    cpath = cpath.replace('error/', 'error.')
                if 'discard/' in cpath:
                    cpath = cpath.replace('discard/', 'discard.')

                if child['leaf']:
                    #print "CHILD", child, cpath
                    reader = EsmondReader(self.uri, cpath, query.startTime,
                            query.endTime, username=self.username,
                            password=self.password, debug=self.debug)
                    yield EsmondLeaf(cpath, reader, client=client,
                            name=name, label=label)
                else:
                    yield EsmondBranch(cpath, name=name, label=label)
        else:
            reader = EsmondReader(self.uri, path, query.startTime,
                    query.endTime, username=self.username, 
                    password=self.password, debug=self.debug)

            yield EsmondLeaf(path, reader, client=client)