Esempio n. 1
0
    def get_iterdata(self, *args, **kwargs):
        """ Return a generator for the combined stream of outputs from each source object
        """
        threshold = timedelta(seconds=1)
        if 'time_thresh' in kwargs:
            threshold = kwargs['time_thresh']
            del kwargs['time_thresh']

        template = [None] * len(self._legend)
        iters = [s.output.get_iterdata(*args, **kwargs) for s in self._sources]
        inputs = [next(i, None) for i in iters]

        # XXX
        infinity = datetime(year=9999, month=12, day=31, tzinfo=tzutc())

        def get_sample_time(s):
            if s is None:
                return infinity
            return s.t

        def min_sample():
            return min(inputs, key=get_sample_time)

        ms = min_sample()
        sample_time = ms.t
        vals = list(template)
        while ms is not None:
            i = inputs.index(ms)
            inputs[i] = next(iters[i], None)

            delta = ms.t - sample_time
            if delta >= threshold:
                yield DictObject.create_from_dict(dict(t=sample_time,
                                                       vals=[vals],
                                                       processed_pkts=None,
                                                       unprocessed_pkts=None))
                
                sample_time = ms.t
                vals = list(template)

            assert len(ms.vals) == 1

            V = ms.vals[0]
            off = self._sources[i].offset
            for j in range(len(V)):
                vals[off + j] = V[j]
                
            ms = min_sample()

        yield DictObject.create_from_dict(dict(t=sample_time,
                                               processed_pkts=None,
                                               unprocessed_pkts=None,
                                               vals=[vals]))
Esempio n. 2
0
    def __init__(self, host, port=None, auth=None):
        """Establishes a connection to a Profiler appliance.

        `host` is the name or IP address of the Profiler to connect to

        `port` is the TCP port on which the Profiler appliance listens.
                 if this parameter is not specified, the function will
                 try to automatically determine the port.

        `auth` defines the authentication method and credentials to use
                 to access the Profiler.  It should be an instance of
                 rvbd.common.UserAuth or rvbd.common.OAuth.

        `force_version` is the API version to use when communicating.
                 if unspecified, this will use the latest version supported
                 by both this implementation and the Profiler appliance.

        See the base [Service](common.html#service) class for more information
        about additional functionality supported.
        """
        super(Profiler, self).__init__("profiler", host, port,
                                       auth=auth,
                                       versions=[APIVersion("1.0")])

        self.api = _api1.Handler(self)

        self.groupbys = DictObject.create_from_dict(_constants.groupbys)
        self.realms = _constants.realms
        self.centricities = _constants.centricities

        self._info = None

        self._load_file_caches()
        self.columns = ColumnContainer(self._unique_columns())
        self.areas = AreaContainer(self._areas_dict.iteritems())
Esempio n. 3
0
    def add_source(self, src, prefix=None):
        """ Add new source to mixer

            `src` is time-based view object
        """
        if prefix is None:
            prefix = 'o%d' % len(self._sources)

        obj = self.sourceobj(output=src, prefix=prefix, offset=len(self._legend))
        self._sources.append(obj)

        for field in src.get_legend():
            if field.dimension:
                raise NotImplementedError()
            
            # create a new record overriding some fields
            entry = DictObject(field)
            entry.id = 'x%d' % len(self._legend)
            entry.name = prefix + entry.name

            self._legend.append(entry)
Esempio n. 4
0
def getLocation(request, name):
    try:
        loc = Location.objects.get(name=name)
    except ObjectDoesNotExist:
        return Http404

    d = DictObject()
    d.name = loc.name
    d.address = loc.address
    d.mask = loc.mask
    d.latitude = loc.latitude
    d.longitude = loc.longitude

    return HttpResponse(json.dumps(d))
Esempio n. 5
0
def getLocation(request, name):
    try:
        loc = Location.objects.get(name=name);
    except ObjectDoesNotExist:
        return Http404

    d = DictObject()
    d.name = loc.name
    d.address = loc.address
    d.mask = loc.mask
    d.latitude = loc.latitude
    d.longitude = loc.longitude

    return HttpResponse(json.dumps(d))
Esempio n. 6
0
 def update(self, data):
     """Update the data of the current object
     with new data from the server
     """
     assert self.id == data['id']
     self.data = DictObject.create_from_dict(data)
Esempio n. 7
0
    def lookup(self, addr):
        data = DictObject()
        data.addr = addr
        data.internal = False

        with lookup_lock:
            r = self.geoip.record_by_addr(addr)

        match = False

        if r is not None:
            data.latitude = r['latitude']
            data.longitude = r['longitude']
            match = True
            try:
                (n, x, y) = socket.gethostbyaddr(addr)
                data.name = n
            except:
                data.name = None

        else:
            addrlong = ip2long(addr)
            
            for location in Location.objects.all():
                if ((addrlong & ip2long(location.mask)) == ip2long(location.address)):
                    data.latitude = location.latitude
                    data.longitude = location.longitude
                    data.name = location.name
                    data.internal = True
                    match = True
                    break

        if match:
            return data
        else:
            return None
Esempio n. 8
0
    def lookup(self, addr):
        data = DictObject()
        data.addr = addr
        data.internal = False

        with lookup_lock:
            r = self.geoip.record_by_addr(addr)

        match = False

        if r is not None:
            data.latitude = r['latitude']
            data.longitude = r['longitude']
            match = True
            try:
                (n, x, y) = socket.gethostbyaddr(addr)
                data.name = n
            except:
                data.name = None

        else:
            addrlong = ip2long(addr)

            for location in Location.objects.all():
                if ((addrlong & ip2long(location.mask)) == ip2long(
                        location.address)):
                    data.latitude = location.latitude
                    data.longitude = location.longitude
                    data.name = location.name
                    data.internal = True
                    match = True
                    break

        if match:
            return data
        else:
            return None
Esempio n. 9
0
 def __init__(self, shark, data):
     self.shark = shark
     self.id = data['id']
     self.data = DictObject.create_from_dict(data)