Esempio n. 1
0
def send_login_info_func():
    if current_env != "Production" and current_env != "Development":
        return
    result, info = control.register_login_task()
    if result is False:
        print("register login task fail")
        return
    print("start run login task %s" % info["task_no"])
    result, info = control.get_login_info()
    table_content = ""
    if len(info["login_records"]) <= 0:
        print("No Login Records")
        return
    for item in info["login_records"]:
        tr_content = '<tr>'
        tr_content += '<td>%s</td>\n' % ip_str(item["server_ip"]) # unix_timestamp(item["run_begin"])
        tr_content += '<td>%s</td>\n' % item["server_name"]
        tr_content += '<td>%s</td>' % ip_str(item["user_ip"])
        tr_content += '<td>%s</td>\n' % item["user_name"]
        tr_content += '<td>%s</td>\n' % unix_timestamp(item["login_time"], style="datetime")
        tr_content += '</tr>\n'
        table_content += tr_content
    with open("../Web/templates/LOG/Login_Log.html") as rt:
        content = rt.read()
        content = content.replace("{{ TR }}", table_content.encode("utf-8"))
        subject = u"有用户登录到服务器"
        my_email.send_mail("*****@*****.**", subject, content)
    print("send success")
Esempio n. 2
0
def send_log_func():
    if current_env != "Production" and current_env != "Development":
        return
    result, info = control.register_log_task()
    if result is False:
        print("register log task fail")
        return
    print("start run log task %s" % info["task_no"])
    result, info = control.get_daily_log()
    table_content = ""
    for item in info["log_records"]:
        tr_content = '<tr title="info: %s&#10;host: %s">' % (item["info"].replace(">", "&gt;").replace('"', "&quot;"), item["host"])
        tr_content += '<td name="run_begin" class="status_move">%s</td>\n' % unix_timestamp(item["run_begin"])
        tr_content += '<td name="request_url">%s</td>\n' % item["url"]
        tr_content += '<td>%s</td>' % item["method"]
        tr_content += '<td name="request_account">%s</td>\n' % item["account"]
        if item["level"] == "error":
            level_class = "redBg"
        elif item["level"] == "base_error":
            level_class = "orgBg"
        elif item["level"] == "bad_req":
            level_class = "yellowBg"
        elif item["level"] == "http_error":
            level_class = "greenBg"
        else:
            level_class = ""
        tr_content += '<td name="log_level" class="%s">%s</td>\n' % (level_class, item["level"])

        if item["run_time"] >= 1:
            tr_content += '<td class="redBg">%s</td>' % item["run_time"]
        elif item["run_time"] >= 0.5:
            tr_content += '<td class="orgBg">%s</td>' % item["run_time"]
        else:
            tr_content += '<td>%s</td>' % item["run_time"]
        tr_content += "\n"
        tr_content += '<td name="request_ip">%s</td>' % ip_str(item["ip"])
        tr_content += "\n"
        tr_content += '</tr>\n'
        table_content += tr_content
    with open("../Web/templates/LOG/Daily_Log.html") as rt:
        content = rt.read()
        content = content.replace("{{ TR }}", table_content.encode("utf-8"))
        control.send_daily_log(content)