def eventpage(): username = request.get_cookie("loggedin", secret='sm2345-45634') if username: database = check_config("OUTPUT_SQLITE3_DB_PATH=") conn = sqlite3.connect(database) #Get Thresholds lmax = conn.cursor().execute( "SELECT max from thresholds WHERE tname = 'low'").fetchone() med = conn.cursor().execute( "SELECT min,max from thresholds WHERE tname = 'med'").fetchone( ) hmin = conn.cursor().execute( "SELECT min from thresholds WHERE tname = 'high'").fetchone() alows = conn.cursor().execute( "select count(id) from alerts where weight <= ?", (lmax[0], )).fetchone() amediums = conn.cursor().execute( "select count(id) from alerts where weight between ? and ?", (med[0], med[1])).fetchone() ahighs = conn.cursor().execute( "select count(id) from alerts where weight >= ?", (hmin[0], )).fetchone() conn.close() return template('alerts', total_alert_highs=ahighs[0], total_alert_mediums=amediums[0], total_alert_lows=alows[0]) else: redirect('/login')
def login(): action = request.query.action if action == "logout": my_notice = "Logged Out" response.delete_cookie("loggedin") elif action == "error": my_notice = "Username or Password Incorrect" else: my_notice = "" return template('login', notice=my_notice)
def login(): action = request.query.action if action == "logout": my_notice = "Logged Out" response.delete_cookie("loggedin") elif action == "error": my_notice = "Username or Password Incorrect" else: my_notice = "" return template('login', notice=my_notice)
def eventpage(): username = request.get_cookie("loggedin", secret='sm2345-45634') if username: database = check_config("OUTPUT_SQLITE3_DB_PATH=") conn = sqlite3.connect(database) #Get Thresholds lmax = conn.cursor().execute("SELECT max from thresholds WHERE tname = 'low'").fetchone() med = conn.cursor().execute("SELECT min,max from thresholds WHERE tname = 'med'").fetchone() hmin = conn.cursor().execute("SELECT min from thresholds WHERE tname = 'high'").fetchone() alows = conn.cursor().execute("select count(id) from alerts where weight <= ?", (lmax[0],)).fetchone() amediums = conn.cursor().execute("select count(id) from alerts where weight between ? and ?", (med[0],med[1])).fetchone() ahighs = conn.cursor().execute("select count(id) from alerts where weight >= ?", (hmin[0],)).fetchone() conn.close() return template('alerts', total_alert_highs=ahighs[0], total_alert_mediums=amediums[0], total_alert_lows=alows[0]) else: redirect('/login')
def keywordspage(): username = request.get_cookie("loggedin", secret='sm2345-45634') if username: database = check_config("OUTPUT_SQLITE3_DB_PATH=") conn = sqlite3.connect(database) lmax = conn.cursor().execute("select max from thresholds where tname = \'low\'").fetchone() hmin = conn.cursor().execute("select min from thresholds where tname = \'high\'").fetchone() sliderp = "[%s,%s]," % (lmax[0],hmin[0]) rows = conn.cursor().execute("select id, keyword, weight from keywords order by weight DESC").fetchall() conn.close() trRows = "" for row in rows: trRows = trRows + '<tr id=\'%s\'><td>%s</td><td>%s</td></tr>' % (row[0],row[1],row[2]) return template('set-keywords', dataRows=trRows, slider=sliderp) else: redirect('/login')
def keywordspage(): username = request.get_cookie("loggedin", secret='sm2345-45634') if username: database = check_config("OUTPUT_SQLITE3_DB_PATH=") conn = sqlite3.connect(database) lmax = conn.cursor().execute( "select max from thresholds where tname = \'low\'").fetchone() hmin = conn.cursor().execute( "select min from thresholds where tname = \'high\'").fetchone( ) sliderp = "[%s,%s]," % (lmax[0], hmin[0]) rows = conn.cursor().execute( "select id, keyword, weight from keywords order by weight DESC" ).fetchall() conn.close() trRows = "" for row in rows: trRows = trRows + '<tr id=\'%s\'><td>%s</td><td>%s</td></tr>' % ( row[0], row[1], row[2]) return template('set-keywords', dataRows=trRows, slider=sliderp) else: redirect('/login')
def mainview(): username = request.get_cookie("loggedin", secret='sm2345-45634') if username: database = check_config("OUTPUT_SQLITE3_DB_PATH=") conn = sqlite3.connect(database) #Get Thresholds lmax = conn.cursor().execute( "SELECT max from thresholds WHERE tname = 'low'").fetchone() med = conn.cursor().execute( "SELECT min,max from thresholds WHERE tname = 'med'").fetchone( ) hmin = conn.cursor().execute( "SELECT min from thresholds WHERE tname = 'high'").fetchone() events = conn.cursor().execute( 'select count(id) from spicymango').fetchone() high_events = conn.cursor().execute( 'select count(id) from alerts where weight >= ?', (hmin[0], )).fetchone() medium_events = conn.cursor().execute( 'select count(id) from alerts where weight between ? and ?', (med[0], med[1])).fetchone() low_events = conn.cursor().execute( 'select count(id) from alerts where weight <= ?', (lmax[0], )).fetchone() chart_highs = conn.cursor().execute( "select count(s.id), strftime('%H', s.timeStamp) from spicymango s join alerts a on s.id = a.id where a.weight >= ? and s.timeStamp >= datetime('now', 'localtime', '-12 hour') group by strftime('%H', s.timeStamp)", (hmin[0], )).fetchall() chart_mediums = conn.cursor().execute( "select count(s.id), strftime('%H', s.timeStamp) from spicymango s join alerts a on s.id = a.id where a.weight between ? and ? and s.timeStamp >= datetime('now', 'localtime', '-12 hour') group by strftime('%H', s.timeStamp)", (med[0], med[1])).fetchall() chart_lows = conn.cursor().execute( "select count(s.id), strftime('%H', s.timeStamp) from spicymango s join alerts a on s.id = a.id where a.weight <= ? and s.timeStamp >= datetime('now', 'localtime', '-12 hour') group by strftime('%H', s.timeStamp)", (lmax[0], )).fetchall() recent_alls = conn.cursor().execute( "select a.weight, s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id order by timeStamp DESC limit 7" ).fetchall() recent_highs = conn.cursor().execute( "select s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id where a.weight >= ? order by timeStamp DESC limit 7", (hmin[0], )).fetchall() recent_mediums = conn.cursor().execute( "select s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id where a.weight between ? and ? order by timeStamp DESC limit 7", (med[0], med[1])).fetchall() recent_lows = conn.cursor().execute( "select s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id where a.weight <= ? order by timeStamp DESC limit 7", (lmax[0], )).fetchall() top_users = conn.cursor().execute( "select s.username, count(s.username) from spicymango s join alerts a on s.id = a.id group by username order by count(username) DESC LIMIT 5" ).fetchall() top_alerts = conn.cursor().execute( "select s.msg, a.weight, s.id from spicymango s join alerts a on s.id = a.id order by a.weight DESC LIMIT 5" ).fetchall() top_keywords = conn.cursor().execute( "select keyword, count from keywords order by count DESC LIMIT 5" ).fetchall() conn.close() i = 0 last_12 = [] while i < 13: d = datetime.datetime.now() - datetime.timedelta(hours=i) hr = d.strftime("%H") last_12.append(hr) i += 1 last_12.reverse() c_hours = "" c_highs = "" c_mediums = "" c_lows = "" for hour in last_12: high_count = "0" medium_count = "0" low_count = "0" for chigh in chart_highs: if hour == chigh[1]: high_count = str(chigh[0]) for cmedium in chart_mediums: if hour == cmedium[1]: medium_count = str(cmedium[0]) for clow in chart_lows: if hour == clow[1]: low_count = str(clow[0]) c_hours = c_hours + "<th>" + hour + ":00</th>" c_highs = c_highs + "<td>" + high_count + "</td>" c_mediums = c_mediums + "<td>" + medium_count + "</td>" c_lows = c_lows + "<td>" + low_count + "</td>" r_all = "" r_high = "" r_medium = "" r_low = "" for rall in recent_alls: if rall[0] >= hmin[0]: priority = "high" priority_label = "High" if med[0] <= rall[0] <= med[1]: priority = "medium" priority_label = "Medium" if rall[0] <= lmax[0]: priority = "low" priority_label = "Low" r_all = r_all + "<tr><td><span class='ticket {!s}'>{!s}</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format( priority, priority_label, rall[3], rall[1], rall[2]) for rhigh in recent_highs: r_high = r_high + "<tr><td><span class='ticket high'>High</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format( rhigh[2], rhigh[0], rhigh[1]) for rmedium in recent_mediums: r_medium = r_medium + "<tr><td><span class='ticket medium'>Medium</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format( rmedium[2], rmedium[0], rmedium[1]) for rlow in recent_lows: r_low = r_low + "<tr><td><span class='ticket low'>Low</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format( rlow[2], rlow[0], rlow[1]) return template('webview', eventcount=events[0], highs=high_events[0], mediums=medium_events[0], lows=low_events[0], chart_hours=c_hours, chart_highs=c_highs, chart_mediums=c_mediums, chart_lows=c_lows, recent_all=r_all, recent_highs=r_high, recent_mediums=r_medium, recent_lows=r_low, topusers=top_users, topalerts=top_alerts, topkeywords=top_keywords) else: redirect('/login')
def set_pass(): username = request.get_cookie("loggedin", secret='sm2345-45634') if username: return template('set-password') else: redirect('/login')
def eventpage(): username = request.get_cookie("loggedin", secret='sm2345-45634') if username: return template('events') else: redirect('/login')
def mainview(): username = request.get_cookie("loggedin", secret='sm2345-45634') if username: database = check_config("OUTPUT_SQLITE3_DB_PATH=") conn = sqlite3.connect(database) #Get Thresholds lmax = conn.cursor().execute("SELECT max from thresholds WHERE tname = 'low'").fetchone() med = conn.cursor().execute("SELECT min,max from thresholds WHERE tname = 'med'").fetchone() hmin = conn.cursor().execute("SELECT min from thresholds WHERE tname = 'high'").fetchone() events = conn.cursor().execute('select count(id) from spicymango').fetchone() high_events = conn.cursor().execute('select count(id) from alerts where weight >= ?', (hmin[0],)).fetchone() medium_events = conn.cursor().execute('select count(id) from alerts where weight between ? and ?', (med[0],med[1])).fetchone() low_events = conn.cursor().execute('select count(id) from alerts where weight <= ?', (lmax[0],)).fetchone() chart_highs = conn.cursor().execute("select count(s.id), strftime('%H', s.timeStamp) from spicymango s join alerts a on s.id = a.id where a.weight >= ? and s.timeStamp >= datetime('now', 'localtime', '-12 hour') group by strftime('%H', s.timeStamp)", (hmin[0],)).fetchall() chart_mediums = conn.cursor().execute("select count(s.id), strftime('%H', s.timeStamp) from spicymango s join alerts a on s.id = a.id where a.weight between ? and ? and s.timeStamp >= datetime('now', 'localtime', '-12 hour') group by strftime('%H', s.timeStamp)", (med[0],med[1])).fetchall() chart_lows = conn.cursor().execute("select count(s.id), strftime('%H', s.timeStamp) from spicymango s join alerts a on s.id = a.id where a.weight <= ? and s.timeStamp >= datetime('now', 'localtime', '-12 hour') group by strftime('%H', s.timeStamp)", (lmax[0],)).fetchall() recent_alls = conn.cursor().execute("select a.weight, s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id order by timeStamp DESC limit 7").fetchall() recent_highs = conn.cursor().execute("select s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id where a.weight >= ? order by timeStamp DESC limit 7", (hmin[0],)).fetchall() recent_mediums = conn.cursor().execute("select s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id where a.weight between ? and ? order by timeStamp DESC limit 7", (med[0],med[1])).fetchall() recent_lows = conn.cursor().execute("select s.msg, s.timeStamp, s.id from spicymango s join alerts a on s.id=a.id where a.weight <= ? order by timeStamp DESC limit 7", (lmax[0],)).fetchall() top_users = conn.cursor().execute("select s.username, count(s.username) from spicymango s join alerts a on s.id = a.id group by username order by count(username) DESC LIMIT 5").fetchall() top_alerts = conn.cursor().execute("select s.msg, a.weight, s.id from spicymango s join alerts a on s.id = a.id order by a.weight DESC LIMIT 5").fetchall() top_keywords = conn.cursor().execute("select keyword, count from keywords order by count DESC LIMIT 5").fetchall() conn.close() i = 0 last_12 = [] while i < 13: d = datetime.datetime.now() - datetime.timedelta(hours=i) hr = d.strftime("%H") last_12.append(hr) i += 1 last_12.reverse() c_hours = "" c_highs = "" c_mediums = "" c_lows = "" for hour in last_12: high_count = "0" medium_count = "0" low_count = "0" for chigh in chart_highs: if hour == chigh[1]: high_count = str(chigh[0]) for cmedium in chart_mediums: if hour == cmedium[1]: medium_count = str(cmedium[0]) for clow in chart_lows: if hour == clow[1]: low_count = str(clow[0]) c_hours = c_hours + "<th>"+hour+":00</th>" c_highs = c_highs + "<td>"+high_count+"</td>" c_mediums = c_mediums + "<td>"+medium_count+"</td>" c_lows = c_lows + "<td>"+low_count+"</td>" r_all = "" r_high = "" r_medium = "" r_low = "" for rall in recent_alls: if rall[0] >= hmin[0]: priority = "high" priority_label = "High" if med[0] <= rall[0] <= med[1]: priority = "medium" priority_label = "Medium" if rall[0] <= lmax[0]: priority = "low" priority_label = "Low" r_all = r_all + "<tr><td><span class='ticket {!s}'>{!s}</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format(priority, priority_label, rall[3], rall[1], rall[2]) for rhigh in recent_highs: r_high = r_high + "<tr><td><span class='ticket high'>High</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format(rhigh[2],rhigh[0], rhigh[1]) for rmedium in recent_mediums: r_medium = r_medium + "<tr><td><span class='ticket medium'>Medium</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format(rmedium[2], rmedium[0], rmedium[1]) for rlow in recent_lows: r_low = r_low + "<tr><td><span class='ticket low'>Low</span></td><td class='full'><a id='{!s}' href='javascript:void(0)'>{!s}</a></td><td class='who'>{!s}</td></tr>".format(rlow[2], rlow[0], rlow[1]) return template('webview', eventcount=events[0], highs=high_events[0], mediums=medium_events[0], lows=low_events[0], chart_hours=c_hours, chart_highs=c_highs, chart_mediums=c_mediums, chart_lows=c_lows, recent_all=r_all, recent_highs=r_high, recent_mediums=r_medium, recent_lows=r_low, topusers=top_users, topalerts=top_alerts, topkeywords=top_keywords) else: redirect('/login')
def set_pass(): username = request.get_cookie("loggedin", secret='sm2345-45634') if username: return template('set-password') else: redirect('/login')
def eventpage(): username = request.get_cookie("loggedin", secret='sm2345-45634') if username: return template('events') else: redirect('/login')
def index(): return template('index', parsed_result=parsed_result, thead=thead)
parser.add_argument('--no_server', action="store_true", help='Do not start a server to serve the result') parser.add_argument('--server_port', action="store", type=int, default=8080, help='Change the port of the server [default 8080]') parser.add_argument('--server_address', action="store", default="127.0.0.1", help='Change the bind address of the server [default 127.0.0.1]') args = parser.parse_args() if not os.path.exists("reports"): os.mkdir("reports") if not os.path.exists("cache"): os.mkdir("cache") print("Starting pt-query-digest for {}".format(args.file_name)) parsed_result = run_pt_query.run(args.file_name) template_result = template('index', parsed_result=parsed_result, thead=thead) if args.report_path: print("Saving report to {}".format(args.report_path)) with codecs.open(args.report_path, 'w', encoding='utf8') as f: f.write(template_result) if not args.no_server: @route('/') def index(): return template('index', parsed_result=parsed_result, thead=thead) run(host=args.server_address, port=args.server_port)