Ejemplo 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]))
Ejemplo n.º 2
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]))
Ejemplo n.º 3
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))
Ejemplo 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))
Ejemplo n.º 5
0
 def _get_timeinfo(self):
     """Return the timeinfo exactly as it comes from netshark
     """
     # check three times before giving up
     count = 0
     timeinfo = None
     while count < 3:
         res = self.shark.api.view.get_stats(
             self.handle, timestamp_format=self.timestamp_format)
         timeinfo = res.get('time_details')
         if timeinfo['start'] and timeinfo['end']:
             return DictObject(timeinfo)
         else:
             count += 1
             time.sleep(0.5)
     return DictObject(timeinfo)
Ejemplo n.º 6
0
 def __init__(self, data, servicedef=None, datarep=None):
     logger.debug('Initialized {} object with data {}'.format(
         self.__class__.__name__, data))
     self.data = DictObject.create_from_dict(data)
     if not datarep:
         self.datarep = servicedef.bind(self.resource, id=self.data.id)
     else:
         self.datarep = datarep
Ejemplo n.º 7
0
 def __init__(self, data, servicedef=None, datarep=None):
     # Override super class to use name instead of id
     logger.debug('Initialized {} object with data {}'.format(
         self.__class__.__name__, data))
     self.data = DictObject.create_from_dict(data)
     if not datarep:
         self.datarep = servicedef.bind(self.resource, name=self.data.name)
     else:
         self.datarep = datarep
Ejemplo n.º 8
0
    def update(self, obj):
        """Update the HostGroup on an appresponse appliance.

        :param obj: an HostGroupConfig object. Note that the Hostgroup
            on the appresponse will be totally overwritten by the
            HostGroup object.
        """

        resp = self.datarep.execute('set', _data=obj)
        self.data = DictObject.create_from_dict(resp.data)
Ejemplo n.º 9
0
    def lookup(self, addr):
        addrlong = ip2long(addr)

        data = DictObject()
        data.addr = addr

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

        if match:
            return data
        else:
            return None
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
    def __init__(self, host, port=None, auth=None):
        """Establishes a connection to a NetProfiler appliance.

        :param str host: name or IP address of the NetProfiler to
            connect to

        :param int port: TCP port on which the NetProfiler appliance
            listens.  If this parameter is not specified, the function will try
            to automatically determine the port.

        :param auth: defines the authentication method and credentials
            to use to access the NetProfiler.  It should be an instance of
            :py:class:`UserAuth<steelscript.common.service.UserAuth>` or
            :py:class:`OAuth<steelscript.common.service.OAuth>`

        :param str force_version: API version to use when communicating.
            if unspecified, this will use the latest version supported by both
            this implementation and the NetProfiler appliance.

        See the base :py:class:`Service<steelscript.common.service.Service>` class
        for more information about additional functionality supported.
        """
        super(NetProfiler, 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

        # checking if the profiler supports 1.2
        # if yes, then use column dsc
        # otherwise, use column qos
        if (self.supported_versions is None
                or APIVersion("1.2") in self.supported_versions):
            _key, _value = ('dsc', 'dsc')
        else:
            _key, _value = ('qos', 'qos')
        self.groupbys[_key] = _value

        self._load_file_caches()
        self.columns = ColumnContainer(self._unique_columns())
        self.colnames = set(c.key for c in self.columns)

        self.areas = AreaContainer(self._areas_dict.iteritems())
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
    def __init__(self, host, port=None, auth=None):
        """Establishes a connection to a NetProfiler appliance.

        :param str host: name or IP address of the NetProfiler to
            connect to

        :param int port: TCP port on which the NetProfiler appliance
            listens.  If this parameter is not specified, the function will try
            to automatically determine the port.

        :param auth: defines the authentication method and credentials
            to use to access the NetProfiler.  It should be an instance of
            :py:class:`UserAuth<steelscript.common.service.UserAuth>` or
            :py:class:`OAuth<steelscript.common.service.OAuth>`

        :param str force_version: API version to use when communicating.
            if unspecified, this will use the latest version supported by both
            this implementation and the NetProfiler appliance.

        See the base :py:class:`Service<steelscript.common.service.Service>` class
        for more information about additional functionality supported.
        """
        super(NetProfiler, 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

        # checking if the profiler supports 1.2
        # if yes, then use column dsc
        # otherwise, use column qos
        if (self.supported_versions is None or
           APIVersion("1.2") in self.supported_versions):
            _key, _value = ('dsc', 'dsc')
        else:
            _key, _value = ('qos', 'qos')
        self.groupbys[_key] = _value

        self._load_file_caches()
        self.columns = ColumnContainer(self._unique_columns())
        self.colnames = set(c.key for c in self.columns)

        self.areas = AreaContainer(self._areas_dict.iteritems())
Ejemplo n.º 14
0
    def lookup(self, addr):
        data = DictObject()
        data.addr = addr

        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 = addr

            return data
        else:
            return None
Ejemplo n.º 15
0
    def lookup(self, addr):
        addrlong = ip2long(addr)

        data = DictObject()
        data.addr = addr

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

        if match:
            return data
        else:
            return None
Ejemplo n.º 16
0
    def lookup(self, addr):
        data = DictObject()
        data.addr = addr

        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 = addr

            return data
        else:
            return None
Ejemplo n.º 17
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)
Ejemplo n.º 18
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)