Exemplo n.º 1
0
def getIPAddress(request, addr):
    data = LookupIP.instance().lookup(addr)

    if data:
        return HttpResponse(json.dumps(data))
    else:
        return Http404
Exemplo n.º 2
0
def getIPAddress(request, addr):
    data = LookupIP.instance().lookup(addr)

    if data:
        return HttpResponse(json.dumps(data))
    else:
        return Http404
Exemplo n.º 3
0
    def process(cls, widget, job, data):
        """Class method to generate list of circle objects.

        Subclass should manipulate this list into specific
        JSON structures as needed.
        """

        settings = SystemSettings.get_system_settings()
        maps_version = settings.maps_version
        post_process = POST_PROCESS_MAP[maps_version]

        columns = job.get_columns()

        ColInfo = namedtuple('ColInfo', ['col', 'dataindex'])

        keycol = None
        latcol = None
        longcol = None
        valuecol = None
        labelcol = None
        urlcol = None
        for i, c in enumerate(columns):
            if c.name == widget.options.key:
                keycol = ColInfo(c, i)
            elif c.name == widget.options.latitude:
                latcol = ColInfo(c, i)
            elif c.name == widget.options.longitude:
                longcol = ColInfo(c, i)
            elif c.name == widget.options.value:
                valuecol = ColInfo(c, i)
            elif c.name == widget.options.label:
                labelcol = ColInfo(c, i)
            elif c.name == widget.options.url:
                urlcol = ColInfo(c, i)

        # Array of circle objects for each data row
        Circle = namedtuple('Circle', [
            'title', 'lat', 'long', 'value', 'size', 'url', 'units',
            'formatter'
        ])
        circles = []

        if data:
            valmin = None
            valmax = None
            if valuecol.col.isnumeric():
                values = zip(*data)[valuecol.dataindex]
                filtered = filter(bool, values)
                if filtered:
                    valmin = min(filtered)
                    valmax = max(filtered)
                else:
                    valmin = 1
                    valmax = 1

            geolookup = None

            if valuecol.col.isnumeric():
                formatter = 'formatMetric'
            else:
                formatter = None

            for rawrow in data:
                val = rawrow[valuecol.dataindex]

                # skip empty result values which are not explicitly zero
                if val is None or val == '':
                    continue

                if valmax:
                    normalized = float(val - valmin) / float(valmax - valmin)
                    marker_size = 5 + normalized * 20
                else:
                    marker_size = 5

                if keycol:
                    key = rawrow[keycol.dataindex]

                    # XXXCJ - this is a hack for NetProfiler based host groups,
                    # need to generalize this, probably via options
                    if widget.table().options.get('groupby') == 'host_group':
                        try:
                            geo = Location.objects.get(name=key)
                        except ObjectDoesNotExist:
                            continue
                    else:
                        # Perform geolookup on the key
                        # (should be an IP address...)
                        if geolookup is None:
                            geolookup = LookupIP.instance()
                        geo = geolookup.lookup(key)

                    if geo:
                        # Found a match, create a Circle
                        url = rawrow[urlcol.dataindex] if urlcol else None

                        circle = Circle(title=geo.name,
                                        lat=geo.latitude,
                                        long=geo.longitude,
                                        value=val,
                                        size=marker_size,
                                        units=valuecol.col.units_str(),
                                        formatter=formatter,
                                        url=url)
                        circles.append(circle)
                else:
                    # use lat/long columns instead of lookups
                    lat = rawrow[latcol.dataindex]
                    long = rawrow[longcol.dataindex]
                    title = rawrow[labelcol.dataindex] if labelcol else val
                    url = rawrow[urlcol.dataindex] if urlcol else None

                    circle = Circle(title=title,
                                    lat=lat,
                                    long=long,
                                    value=val,
                                    size=marker_size,
                                    units=valuecol.col.units_str(),
                                    formatter=formatter,
                                    url=url)
                    circles.append(circle)

        else:
            # no data just return empty circles list
            pass

        data = {
            "chartTitle": widget.title.format(**job.actual_criteria),
            "circles": circles,
            "minbounds": widget.options.min_bounds
        }

        return post_process(data)
Exemplo n.º 4
0
    def process(cls, widget, job, data):
        """Class method to generate list of circle objects.

        Subclass should manipulate this list into specific
        JSON structures as needed.
        """

        settings = SystemSettings.get_system_settings()
        maps_version = settings.maps_version
        post_process = POST_PROCESS_MAP[maps_version]

        columns = job.get_columns()

        ColInfo = namedtuple('ColInfo', ['col', 'dataindex'])

        keycol = None
        latcol = None
        longcol = None
        valuecol = None
        labelcol = None
        urlcol = None
        for i, c in enumerate(columns):
            if c.name == widget.options.key:
                keycol = ColInfo(c, i)
            elif c.name == widget.options.latitude:
                latcol = ColInfo(c, i)
            elif c.name == widget.options.longitude:
                longcol = ColInfo(c, i)
            elif c.name == widget.options.value:
                valuecol = ColInfo(c, i)
            elif c.name == widget.options.label:
                labelcol = ColInfo(c, i)
            elif c.name == widget.options.url:
                urlcol = ColInfo(c, i)

        # Array of circle objects for each data row
        Circle = namedtuple('Circle',
                            ['title', 'lat', 'long', 'value', 'size', 'url',
                             'units', 'formatter'])
        circles = []

        if data:
            valmin = None
            valmax = None
            if valuecol.col.isnumeric():
                values = zip(*data)[valuecol.dataindex]
                filtered = filter(bool, values)
                if filtered:
                    valmin = min(filtered)
                    valmax = max(filtered)
                else:
                    valmin = 1
                    valmax = 1

            geolookup = None

            if valuecol.col.isnumeric():
                formatter = 'formatMetric'
            else:
                formatter = None

            for rawrow in data:
                val = rawrow[valuecol.dataindex]

                # skip empty result values which are not explicitly zero
                if val is None or val == '':
                    continue

                if valmax:
                    normalized = float(val - valmin) / float(valmax - valmin)
                    marker_size = 5 + normalized * 20
                else:
                    marker_size = 5

                if keycol:
                    key = rawrow[keycol.dataindex]

                    # XXXCJ - this is a hack for NetProfiler based host groups,
                    # need to generalize this, probably via options
                    if widget.table().options.get('groupby') == 'host_group':
                        try:
                            geo = Location.objects.get(name=key)
                        except ObjectDoesNotExist:
                            continue
                    else:
                        # Perform geolookup on the key
                        # (should be an IP address...)
                        if geolookup is None:
                            geolookup = LookupIP.instance()
                        geo = geolookup.lookup(key)

                    if geo:
                        # Found a match, create a Circle
                        url = rawrow[urlcol.dataindex] if urlcol else None

                        circle = Circle(title=geo.name,
                                        lat=geo.latitude,
                                        long=geo.longitude,
                                        value=val,
                                        size=marker_size,
                                        units=valuecol.col.units_str(),
                                        formatter=formatter,
                                        url=url)
                        circles.append(circle)
                else:
                    # use lat/long columns instead of lookups
                    lat = rawrow[latcol.dataindex]
                    long = rawrow[longcol.dataindex]
                    title = rawrow[labelcol.dataindex] if labelcol else val
                    url = rawrow[urlcol.dataindex] if urlcol else None

                    circle = Circle(title=title,
                                    lat=lat,
                                    long=long,
                                    value=val,
                                    size=marker_size,
                                    units=valuecol.col.units_str(),
                                    formatter=formatter,
                                    url=url)
                    circles.append(circle)

        else:
            # no data just return empty circles list
            pass

        data = {
            "chartTitle": widget.title.format(**job.actual_criteria),
            "circles": circles,
            "minbounds": widget.options.min_bounds
        }

        return post_process(data)