def setUp(self): global_data = GlobalData() # Initialize logging. logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', datefmt='%m/%d/%Y %H:%M:%S', level=logging.WARNING) global_data.logger = logging.getLogger("graph") # Open database. db_location = os.path.join(os.path.dirname(os.path.abspath(__file__)), "database.db") global_data.storage = Sqlite(db_location, global_data, read_only=True) # Read necessary configurations. config_location = os.path.join( os.path.dirname(os.path.abspath(__file__)), "config.xml") configRoot = xml.etree.ElementTree.parse(config_location).getroot() configure_profiles(configRoot, global_data) configure_alert_levels(configRoot, global_data) self.alert_levels = {} for alert_level in global_data.alertLevels: self.alert_levels[alert_level.level] = alert_level self.nodes, self.alerts, self.sensors = get_objects_from_db( global_data)
# configure user credentials backend userBackendMethod = str( configRoot.find("storage").find("userBackend").attrib[ "method"]).upper() if userBackendMethod == "CSV": globalData.userBackend = CSVBackend(globalData.userBackendCsvFile) else: raise ValueError("No valid user backend method in config file.") # configure storage backend (check which backend is configured) userBackendMethod = str( configRoot.find("storage").find("storageBackend").attrib[ "method"]).upper() if userBackendMethod == "SQLITE": globalData.storage = Sqlite(globalData.storageBackendSqliteFile, globalData.version) elif userBackendMethod == "MYSQL": backendUsername = str(configRoot.find("storage").find( "storageBackend").attrib["username"]) backendPassword = str(configRoot.find("storage").find( "storageBackend").attrib["password"]) backendServer = str(configRoot.find("storage").find( "storageBackend").attrib["server"]) backendPort = int(configRoot.find("storage").find( "storageBackend").attrib["port"]) backendDatabase = str(configRoot.find("storage").find( "storageBackend").attrib["database"]) globalData.storage = Mysql(backendServer, backendPort,
loggedWindow_active = loginWindow_active = False # When event and values are startWindow then they show that window. while True: ev1, vals1 = startWindow.Read() # If the 'close' button is pushed the program is going to stop with running if ev1 is None: break # If the 'No' button is pushed the program is going to stop with running if ev1 == 'No': break # If the 'Yes' button is pushed the program is going to save the database in the location you've chose if ev1 == 'Yes': if path != vals1[0]: path = vals1[0] db = Sqlite.Sqlite(path, name) exists = os.path.isfile(path + '/' + name + ".db") if not exists: # Store configuration file values db.setup_database() # If the 'Yes' button is pushed the program is going to activate the 2nd window and hide the previous window. if not loginWindow_active and ev1 == 'Yes': loginWindow_active = True startWindow.Hide() # The layout of the window is created with the 'layout' variable layout2 = [[ Sg.Text('Login as a TUF user or create a new user account.') ], [Sg.Text('Username'), Sg.Input()], [Sg.Text('Password'), Sg.Input(password_char='*')], [Sg.Button('Login'),
with open(target_location, 'w') as fp: pass except Exception: print("Not able to write '%s'." % target_location) sys.exit(1) global_data = GlobalData() # Initialize logging. logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', datefmt='%m/%d/%Y %H:%M:%S', level=logging.WARNING) global_data.logger = logging.getLogger("graph") global_data.storage = Sqlite(global_data.storageBackendSqliteFile, global_data, read_only=True) # Read necessary configurations. configRoot = xml.etree.ElementTree.parse(global_data.configFile).getroot() configure_alert_levels(configRoot, global_data) # Get Alert, Alert Level, ans Sensor objects. alert_level_objs_dict = dict() for alert_level in global_data.alertLevels: alert_level_objs_dict[alert_level.level] = alert_level node_objs, alert_objs, sensor_objs = get_objects_from_db(global_data) # Filter Alert Level, Alert, and Sensor. try: alert_level_objs_dict = filter_obj.filter_alert_levels(
smtpFromAddr = config.get("smtp", "fromAddr") smtpToAddr = config.get("smtp", "toAddr") globalData.smtpAlert = SMTPAlert(smtpServer, smtpPort, smtpFromAddr, smtpToAddr) # configure user credentials backend userBackendMethod = config.get("userBackend", "method") if userBackendMethod.upper() == "CSV": globalData.userBackend = CSVBackend(globalData.userBackendCsvFile) else: raise ValueError("No valid user backend method in config file.") # configure storage backend (check which backend is configured) userBackendMethod = config.get("storage", "method") if userBackendMethod.upper() == "SQLITE": globalData.storage = Sqlite(globalData.storageBackendSqliteFile) elif userBackendMethod.upper() == "MYSQL": backendUsername = config.get("storage", "username") backendPassword = config.get("storage", "password") backendServer = config.get("storage", "server") backendPort = config.getint("storage", "port") backendDatabase = config.get("storage", "database") globalData.storage = Mysql(backendServer, backendPort, backendDatabase, backendUsername, backendPassword) else: raise ValueError("No valid storage backend method in config file.") # get server configurations