Ejemplo n.º 1
0
 def xmlrpc_catalog(self, path=''):
     """Return a list of subdirectories within this stats path"""
     result = defer.Deferred()
     d = StatsTarget(path).catalog()
     d.addErrback(result.errback)
     d.addCallback(self._catalog, result)
     return result
Ejemplo n.º 2
0
 def xmlrpc_get(self, path, name, default=False):
     """Get a (value, type) tuple for the metadata key with the given
        name, returning 'default' if it isn't found
        """
     result = defer.Deferred()
     StatsTarget(path).metadata.get(name, default).addCallback(
         self._get, result).addErrback(result.errback)
     return result
Ejemplo n.º 3
0
 def xmlrpc_catalog(self, path=''):
     """Return a list of subdirectories within this stats path"""
     result = defer.Deferred()
     d = StatsTarget(path).catalog()
     d.addErrback(result.errback)
     d.addCallback(self._catalog, result)
     return result
Ejemplo n.º 4
0
    def message(self, uri, message, content):
        """Appends 'content' to the path represented by the given URI
           and delivers a message to its associated stats target.

           This includes a bit of a hack for tracking associations
           between stats targets. We assume that messages are delivered
           one at a time- if we get a duplicate message (presumably to a
           different stats target) we add that stats target to the list of
           targets this message has been delivered to, and reinforce the
           new relations this forms.
           """
        path = posixpath.join(self.parseURI(uri)['path'], content)
        target = StatsTarget(path)
        target.deliver(message)

        if message == self.lastMessage:
            for prevTarget in self.messageTargets:
                Relation(prevTarget, target).reinforce()
        else:
            self.messageTargets = []
        self.messageTargets.append(target)
        self.lastMessage = message
Ejemplo n.º 5
0
    def getTargetFromURL(self, url):
        """Given a URL that presumably refers to our HTTP server, extract a stats
           target from it. The URL should be to an RSS feed, but we won't be too
           picky. If we can't find a related stats target, return None.
           """
        # We ignore everything except the path, assuming the URL actually
        # refers to this host. There's no reason for someone to ask us to
        # notify them if another server's page changes, and it would take
        # more effort than it's worth to accurately determine if the given
        # host refers to this CIA server, with all the proxying and DNS
        # multiplicity that could be going on.
        path = urlparse.urlparse(url)[2]

        # FIXME: really cheesy hack!
        if not path.startswith("/stats/"):
            return None
        return StatsTarget(path[7:].split("/.", 1)[0])
Ejemplo n.º 6
0
 def protected_clearTarget(self, path):
     """Deletes any data stored at a given stats target or in any of its subtargets"""
     log.msg("Clearing stats path %r" % path)
     return StatsTarget(path).clear()
Ejemplo n.º 7
0
 def xmlrpc_getCounterValues(self, path, name):
     """Returns a dictionary with current values for the given counter.
        Note that times are returned as UNIX-style seconds since
        the epoch in UTC.
        """
     return StatsTarget(path).counters.getCounter(name)
Ejemplo n.º 8
0
 def xmlrpc_getLatestMessages(self, path, limit=None):
     """Return 'limit' latest messages delivered to this stats target,
        or all available recent messages if 'limit' isn't specified.
        """
     return [(id, XML.toString(doc))
             for id, doc in StatsTarget(path).messages.getLatest(limit)]
Ejemplo n.º 9
0
 def protected_remove(self, path, name):
     """Remove one metadata key for this target, if it exists"""
     return StatsTarget(path).metadata.remove(name)
Ejemplo n.º 10
0
 def protected_clear(self, path):
     """Remove all metadata for one target"""
     return StatsTarget(path).metadata.clear()
Ejemplo n.º 11
0
 def protected_set(self, path, name, value, mimeType='text/plain'):
     """Set a metadata key's value and MIME type"""
     return StatsTarget(path).metadata.set(name, str(value), mimeType)
Ejemplo n.º 12
0
 def xmlrpc_dict(self, path):
     """Return a mapping of names to (value, type) tuples for the given path"""
     result = defer.Deferred()
     StatsTarget(path).metadata.dict().addCallback(
         self._dict, result).addErrback(result.errback)
     return result