return store_result if __name__ == '__main__': from datetime import datetime from dbm import DBManager from datadriver import SyslogDriver from random import random DB_NAME = 'icsmonitor' dbconfig = { 'user': '******', 'password': '******', 'host': '127.0.0.1', 'raise_on_warnings': True, } db = DBManager() db.connect(**dbconfig) db.set_db(DB_NAME) syslogdriver = SyslogDriver() syslogdriver.set_db(db) s_cisco1 = '<23>Mar 23 10:21:03 %ASA-4-106023 Deny ICMP reverse path check from 192.168.150.60 to 192.168.2.1 on interface outside' s_cisco2 = '''<187>Mar 23 10:21:03 %PIX-4-106023 Deny tcp src outside:192.168.208.63/5535 dst inside:192.168.150.77/256 by access-group "OUTSIDE" [0x5063b82f, 0x0]''' s_huacon = '''<13>Apr 1 14:34:23 SystemMgr: [2015-04-01 14:34:23.48][Emerg][User][ISG-A002G][ID!][change]system error, code:1762''' recog = SyslogRecog() recog.set_driver(syslogdriver) recog.set_recog_info() recog_info = recog.get_recog_info() #print(recog_info) #dev_file_name, = recog.recognize(s, recog_info)
from flask import Flask, render_template, request import json import data_logger # from kafka import Producer #enables streaming from dbm import DBManager app = Flask(__name__) DBM = DBManager('demo.db') #DB manager class w/ connection object init # producer = Producer() @app.route('/') def index(): return render_template('index.html') @app.route('/db/read') #returns location data def db_read(): result = DBM.read_locs() return json.dumps(result) @app.route('/db/routes') #returns route data def db_read_routes(): all_routes = DBM.read_routes() return json.dumps(all_routes) @app.route('/stream/collect', methods=['POST']) #route for AJAX post from Trip.js def stream_collect_data(): if request.method == 'POST': json_data = request.get_json(force=True) data_logger.write_data(json_data) #log all stream data as JSON in data_log.txt producer.stream_out(request.data) #send data to Kafka client return render_template('error.html') #have to return something small to avoid error, this return does nothing
import json import time from dbm import DBManager import sqlite3 as db from mapbox import Directions import mapbox_token DBM = DBManager('demo.db') service = Directions( access_token=mapbox_token.MAPBOX_ACCESS_TOKEN) #Mapbox API result = DBM.read_locs() #Get Location List to generate routes b/w them #Builds list of possible destinations and origins in memory. pairs = [] for loc_one in result: for loc_two in result: if (loc_one != loc_two): #Reformat raw db data into Mapbox Points point_one = { 'type': 'Feature', 'properties': { 'name': loc_one[0] }, 'geometry': { 'type': 'Point', 'coordinates': [loc_one[1], loc_one[2]] } } point_two = {
for child in obj_root: if child.tag == "name": primary_key_list.append(child.text) if primary_key_list: primary_key = ", ".join(primary_key_list) attr_str = attr_str + " , PRIMARY KEY ({0})".format(primary_key) newtable = newtable.format(attr_str) return newtable if __name__ == "__main__": from dbm import DBManager DB_NAME = "icsmonitor" dbconfig = {"user": "******", "password": "******", "host": "127.0.0.1", "raise_on_warnings": True} db = DBManager() db.connect(**dbconfig) db.set_db(DB_NAME) import dbtables db.add_tables(dbtables.TABLES_NAME, dbtables.TABLES) db.drop_tables() db.create_tables() conf = Config() conf.set_db(db) print("1.Read conf.xml file and insert to deive_file table:") conf.load_conf("conf.xml") print("2.Create tables for each device:") # conf.create_log_tables() print(" ignored") print("3.Insert every attribute to syslog_attr or snmp_attr:")