Example #1
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)
Example #2
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))
Example #3
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
Example #4
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
Example #5
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)