コード例 #1
0
def device_day_stats(date, host, sent_recv=True, metric=Metric.PROTOCOLS):
    if not check_ip(host):
        raise ValueError("host is not a valid IP address")

    if metric not in Metric:
        raise ValueError("not a supported metric")

    res = {}
    byte = 8.0  # bits
    time_factor = 300 * 12  # seconds of one rrd interval (1 h) for intervals older than 24 hours
    if datetime.date.today() == date:
        time_factor = 300  # seconds of one rrd interval (5 min) for values of the last 24 hours

    data = _device_day_data(date, host, metric)

    for proto in data:
        if sent_recv and metric == Metric.PROTOCOLS:
            # separate values for sent and received of one protocol
            key = " ".join(proto['target'].split(" ")[:2])
        else:
            # sum up values for send and received of one protocol
            key = proto['target'].split(" ")[0]

        res.setdefault(key, 0)
        # calculates bytes from given bps values
        res[key] += sum(
            (point[0] / byte) * time_factor for point in proto['datapoints'])

    final_result = {
        protocol: convert_to_megabytes(byte_count)
        for protocol, byte_count in res.items()
    }

    return final_result
コード例 #2
0
ファイル: views.py プロジェクト: guesslin/dn_tracer
def index(request):

    if request.method == "POST":
        dn_ip = request.POST.get("dn_ip")
        date = datetime.date.today()
        port = force_int(request.POST.get("port"))
        source = request.POST.get("source")
        note = source_parse(request.POST.get("note"))

        db = Database()
        msg = ""

        if dn_ip and source:
            if check_ip(dn_ip):
                if not port and note:
                    msg = db.insert_malicious_ip_record(ip=dn_ip,
                                                        date=date,
                                                        source=source,
                                                        note=note)
                elif port and not note:
                    msg = db.insert_malicious_ip_record(ip=dn_ip,
                                                        date=date,
                                                        source=source,
                                                        port=port)
                else:
                    msg = db.insert_malicious_ip_record(ip=dn_ip,
                                                        date=date,
                                                        source=source)
            else:
                if not port and note:
                    msg = db.insert_malicious_dn_record(dn=dn_ip,
                                                        date=date,
                                                        source=source,
                                                        note=note)
                elif port and not note:
                    msg = db.insert_malicious_dn_record(dn=dn_ip,
                                                        date=date,
                                                        source=source,
                                                        port=port)
                else:
                    msg = db.insert_malicious_dn_record(dn=dn_ip,
                                                        date=date,
                                                        source=source)
        else:
            return render_to_response("add/index.html",
                                      context_instance=RequestContext(request))
    else:
        return render_to_response("add/index.html",
                                  context_instance=RequestContext(request))
    if msg:
        return render_to_response("error.html",
                                  {"error": str(msg)},
                                  context_instance=RequestContext(request))
    else:
        return render_to_response("sucess.html",
                                  {"message": "Add {} to DB sucessfully".format(
                                      dn_ip)},
                                  context_instance=RequestContext(request))
コード例 #3
0
def index(request):

    if request.method == "POST":
        dn_ip = request.POST.get("dn_ip")
        date = datetime.date.today()
        port = force_int(request.POST.get("port"))
        source = request.POST.get("source")
        note = source_parse(request.POST.get("note"))

        db = Database()
        msg = ""

        if dn_ip and source:
            if check_ip(dn_ip):
                if not port and note:
                    msg = db.insert_malicious_ip_record(ip=dn_ip,
                                                        date=date,
                                                        source=source,
                                                        note=note)
                elif port and not note:
                    msg = db.insert_malicious_ip_record(ip=dn_ip,
                                                        date=date,
                                                        source=source,
                                                        port=port)
                else:
                    msg = db.insert_malicious_ip_record(ip=dn_ip,
                                                        date=date,
                                                        source=source)
            else:
                if not port and note:
                    msg = db.insert_malicious_dn_record(dn=dn_ip,
                                                        date=date,
                                                        source=source,
                                                        note=note)
                elif port and not note:
                    msg = db.insert_malicious_dn_record(dn=dn_ip,
                                                        date=date,
                                                        source=source,
                                                        port=port)
                else:
                    msg = db.insert_malicious_dn_record(dn=dn_ip,
                                                        date=date,
                                                        source=source)
        else:
            return render_to_response("add/index.html",
                                      context_instance=RequestContext(request))
    else:
        return render_to_response("add/index.html",
                                  context_instance=RequestContext(request))
    if msg:
        return render_to_response("error.html", {"error": str(msg)},
                                  context_instance=RequestContext(request))
    else:
        return render_to_response(
            "sucess.html",
            {"message": "Add {} to DB sucessfully".format(dn_ip)},
            context_instance=RequestContext(request))
コード例 #4
0
ファイル: server_manage.py プロジェクト: zhouyinghou/mega
 def data_check(self):
     if not self.server_ip or not check_ip(self.server_ip):
         self.msg += MSG_ERR_IP
         return False
     if not self.server_name:
         self.server_name = self.server_ip
     if not self.server_online:
         self.server_online = datetime.datetime.now()
     if not self.server_os:
         self.server_os = DEFAULT_OS
     if not self.server_owner:
         self.server_owner = DEFAULT_OWNER
     return True
コード例 #5
0
ファイル: server_manage.py プロジェクト: sixizi/mega
 def data_check(self):
     if not self.server_ip or not check_ip(self.server_ip):
         self.msg+=MSG_ERR_IP
         return False
     if not self.server_name:
         self.server_name=self.server_ip
     if not self.server_online:
         self.server_online=datetime.datetime.now()
     if not self.server_os:
         self.server_os=DEFAULT_OS
     if not self.server_owner:
         self.server_owner=DEFAULT_OWNER
     return True
コード例 #6
0
ファイル: views.py プロジェクト: guesslin/dn_tracer
def index(request):

    db = Database()
    query_result = []
    if request.method == "POST":
        query = request.POST.get("query").strip()
        start_date = request.POST.get("Start_Date")
        end_date = request.POST.get("End_Date")
        if not start_date:
            start_date = '2016-01-01'
        if not end_date:
            end_date = datetime.date.today()
        if query:
            if check_ip(query):
                query_result = db.get_pdns_record(ip=query,
                                                  start=start_date,
                                                  end=end_date)
                record = db.get_malicious_ip_record(query)
                dn_ip = "ip"
            else:
                query_result = db.get_pdns_record(dn=query,
                                                  start=start_date,
                                                  end=end_date)
                record = db.get_malicious_dn_record(query)
                dn_ip = "domain"
            return render_to_response("search/result.html",
                                      {"results": query_result,
                                       "record": record,
                                       "type": dn_ip},
                                      context_instance=RequestContext(request))
        else:
            form = ToDoForm(request.POST)
            return render_to_response("search/index.html",
                                      {'form': form},
                                      context_instance=RequestContext(request))
    else:
        form = ToDoForm()
        return render_to_response("search/index.html",
                                  {'form': form},
                                  context_instance=RequestContext(request))
コード例 #7
0
ファイル: instance_manage.py プロジェクト: zhouyinghou/mega
 def data_check(self):
     if not self.inst_ip or not check_ip(self.inst_ip):
         self.msg += MSG_ERR_IP
         return False
     if is_int(self.inst_port):
         self.msg += MSG_ERR_PORT
         return False
     if not self.inst_level:
         self.inst_level = DEFAULT_LEVEL
     if not self.inst_name:
         self.inst_name = self.inst_ip
     if not self.inst_owner:
         self.inst_owner = DEFAULT_OWNER
     if not self.inst_online_date:
         self.inst_online_date = datetime.datetime.now()
     if not self.inst_dbtype:
         self.inst_dbtype = DEFAULT_DBTYPE
     if not self.inst_hatype:
         self.inst_hatype = DEFAULT_HATYPE
     if not self.inst_bussiness:
         self.inst_bussiness = DEFAULT_BUSINESS
     return True
コード例 #8
0
ファイル: instance_manage.py プロジェクト: sixizi/mega
 def data_check(self):
     if not self.inst_ip or not check_ip(self.inst_ip):
         self.msg+=MSG_ERR_IP
         return False
     if is_int(self.inst_port):
         self.msg+=MSG_ERR_PORT
         return False
     if not self.inst_level:
         self.inst_level=DEFAULT_LEVEL
     if not self.inst_name:
         self.inst_name=self.inst_ip
     if not self.inst_owner:
         self.inst_owner=DEFAULT_OWNER
     if not self.inst_online_date:
         self.inst_online_date=datetime.datetime.now()
     if not self.inst_dbtype:
         self.inst_dbtype=DEFAULT_DBTYPE
     if not self.inst_hatype:
         self.inst_hatype=DEFAULT_HATYPE
     if not self.inst_bussiness:
         self.inst_bussiness=DEFAULT_BUSINESS
     return True