Ejemplo n.º 1
0
def api_vuln_global_time(request, **kwargs):
    http = HttpClient(api_settings.SERVER, timeout=20)
    vuln_type = request.GET.get('type')
    url = http.murl('{url}?type={type}'.format(url=api_settings.GLOBAL_TIME,
                                               type=vuln_type))
    try:
        res = http.mget(url)
    except Exception as e:
        logger.error('get vuln global risk error: %s --server[%s]', e.message,
                     url)
        # return default_views.Http404Page(request, e)
        raise exceptions.NotFound(ResError.VULN_CONNECTED_FAILED)
    res_data = http.result(res, True)
    if res.status_code == 200:
        time = res_data['time']
        data = res_data['content']

    else:
        logger.error('get vuln global risk error: %s --server[%s]',
                     res_data.get('message'), url)
        # return default_views.Http404Page(request, Exception())
        raise exceptions.NotFound(ResError.VULN_CONNECTED_FAILED)

    return response.Response(OrderedDict([('time', time), ('content', data)]),
                             status=status.HTTP_200_OK)
Ejemplo n.º 2
0
def api_vuln_global_risk(request, **kwargs):
    http = HttpClient(api_settings.SERVER, timeout=20)
    vuln_type = request.GET.get('type')
    url = http.murl('{url}?type={type}'.format(url=api_settings.GLOBAL_RISK,
                                               type=vuln_type))
    try:
        res = http.mget(url)
    except Exception as e:
        logger.error('get vuln global risk error: %s -- server[%s]', e.message,
                     url)
        # return default_views.Http404Page(request, e)
        raise exceptions.NotFound(ResError.VULN_CONNECTED_FAILED)
    res_data = http.result(res, True)
    if res.status_code == 200:

        if len(res_data) > 0:
            data = res_data
        else:
            # return default_views.Http404Page(request, Exception())
            raise exceptions.NotFound(ResError.VULN_CONNECTED_FAILED)
    else:
        logger.error('get vuln global risk error: %s --server[%s]',
                     res_data.get('message'), url)
        # return default_views.Http404Page(request, Exception())
        raise exceptions.NotFound(ResError.VULN_CONNECTED_FAILED)
    en_name = ['High Risk', 'Medium Risk', 'Low Risk', 'Unknown']
    if getattr(request, 'LANGUAGE_CODE', settings.LANGUAGE_CODE) == 'en':
        for index, type_data in enumerate(data):
            type_data['name'] = en_name[index]

    return response.Response(data, status=status.HTTP_200_OK)