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)
# Shutdown has to be done via another thread. Otherwise a # deadlock will occur. _thread.start_new_thread(shutdown_server, (server, )) _thread.start_new_thread(shutdown_server, (unixserver, )) if db_cleaner: db_cleaner.shutdown() if __name__ == "__main__": # Register sigterm handler to gracefully shutdown the server. signal.signal(signal.SIGTERM, sigterm_handler) # Generate object of the global needed data. global_data = GlobalData() file_name = os.path.basename(__file__) # Parse config file, get logfile configurations # and initialize logging try: configRoot = xml.etree.ElementTree.parse( global_data.config_file).getroot() global_data.logdir = make_path( str(configRoot.find("general").find("log").attrib["dir"])) # parse chosen log level temp_loglevel = str( configRoot.find("general").find("log").attrib["level"])
from lib import ServerCommunication, ConnectionWatchdog, Receiver from lib import SMTPAlert from lib import ScreenUpdater from lib import Console from lib import UpdateChecker from lib import GlobalData import logging import time import socket import random import xml.etree.ElementTree if __name__ == '__main__': # generate object of the global needed data globalData = GlobalData() fileName = os.path.basename(__file__) # parse config file, get logfile configurations # and initialize logging try: configRoot = xml.etree.ElementTree.parse( globalData.configFile).getroot() logfile = str(configRoot.find("general").find("log").attrib["file"]) # parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"]) tempLoglevel = tempLoglevel.upper()
"--force", dest="force", action="store_true", help="Do not check the version. Just update all files.", default=False) (options, args) = parser.parse_args() if options.update is False: print "Use --help to get all available options." sys.exit(0) protocolUpdate = False configUpdate = False # generate object of the global needed data globalData = GlobalData() fileName = os.path.basename(__file__) instanceLocation = os.path.dirname(os.path.abspath(__file__)) + "/" try: # parse config file configRoot = xml.etree.ElementTree.parse( instanceLocation + "/config/config.xml").getroot() # parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"]) tempLoglevel = tempLoglevel.upper() if tempLoglevel == "DEBUG": loglevel = logging.DEBUG
elif ruleElement.type == "second": logString = ("%s second " % spaceString + "(start=%d, " % ruleElement.element.start + "end=%d)") % ruleElement.element.end logging.info("[%s]: %s" % (fileName, logString)) else: raise ValueError("Rule has invalid type: '%s'." % ruleElement.type) if __name__ == '__main__': # generate object of the global needed data globalData = GlobalData() fileName = os.path.basename(__file__) # parse config file, get logfile configurations # and initialize logging try: configRoot = xml.etree.ElementTree.parse( globalData.configFile).getroot() logfile = str(configRoot.find("general").find("log").attrib["file"]) # parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"]) tempLoglevel = tempLoglevel.upper()
# Function creates a path location for the given user input. def makePath(inputLocation): # Do nothing if the given location is an absolute path. if inputLocation[0] == "/": return inputLocation # Replace ~ with the home directory. elif inputLocation[0] == "~": return os.environ["HOME"] + inputLocation[1:] # Assume we have a given relative path. return os.path.dirname(os.path.abspath(__file__)) + "/" + inputLocation if __name__ == '__main__': # generate object of the global needed data globalData = GlobalData() fileName = os.path.basename(__file__) # parse config file, get logfile configurations # and initialize logging try: configRoot = xml.etree.ElementTree.parse( globalData.configFile).getroot() logfile = makePath( str(configRoot.find("general").find("log").attrib["file"])) # parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"])
# twitter: https://twitter.com/sqall01 # blog: https://h4des.org # github: https://github.com/sqall01 # # Licensed under the GNU Affero General Public License, version 3. from lib import GlobalData import xml.etree.ElementTree import MySQLdb import bcrypt import sys new_username = "******" new_password = "******" global_data = GlobalData() try: configRoot = xml.etree.ElementTree.parse(global_data.config_file).getroot() global_data.mysql_host = str( configRoot.find("storage").find("mysql").attrib["server"]) global_data.mysql_port = int( configRoot.find("storage").find("mysql").attrib["port"]) global_data.mysql_database = str( configRoot.find("storage").find("mysql").attrib["database"]) global_data.mysql_username = str( configRoot.find("storage").find("mysql").attrib["username"]) global_data.mysql_password = str( configRoot.find("storage").find("mysql").attrib["password"])
elif ruleElement.type == "second": logString = ("%s second " % spaceString + "(start=%d, " % ruleElement.element.start + "end=%d)") % ruleElement.element.end logging.info("[%s]: %s" % (fileName, logString)) else: raise ValueError("Rule has invalid type: '%s'." % ruleElement.type) if __name__ == '__main__': # generate object of the global needed data globalData = GlobalData() fileName = os.path.basename(__file__) # parse config file, get logfile configurations # and initialize logging try: configRoot = xml.etree.ElementTree.parse( globalData.configFile).getroot() globalData.logdir = makePath(str(configRoot.find("general").find( "log").attrib["dir"])) # parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"])
+ "(Optional)", default=False) parser.add_option_group(optGroup) (options, args) = parser.parse_args() showHelp = (options.add or options.delete or options.modify or options.list) if showHelp is False: print("Use --help to get all available options.") sys.exit(0) # Generate object of the global needed data. globalData = GlobalData() fileName = os.path.basename(__file__) instanceLocation = os.path.dirname(os.path.abspath(__file__)) + "/" validNodeTypes = ["sensor", "manager", "alert"] # Parse config file. try: configRoot = xml.etree.ElementTree.parse(instanceLocation + "/config/config.xml").getroot() # Parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"]) tempLoglevel = tempLoglevel.upper()
action="store_true", help= "Do not ask me for confirmation. I know what I am doing. (Optional)", default=False) parser.add_option_group(optGroup) (options, args) = parser.parse_args() showHelp = (options.add or options.delete or options.modify or options.list) if showHelp is False: print("Use --help to get all available options.") sys.exit(0) # Generate object of the global needed data. globalData = GlobalData() fileName = os.path.basename(__file__) instanceLocation = os.path.dirname(os.path.abspath(__file__)) + "/" validNodeTypes = ["sensor", "manager", "alert"] # Parse config file. try: configRoot = xml.etree.ElementTree.parse( instanceLocation + "/config/config.xml").getroot() # Parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"]) tempLoglevel = tempLoglevel.upper()
from lib import Mysql from lib import SMTPAlert from lib import UpdateChecker from lib import GlobalData import logging import time import socket import random import threading import stat import xml.etree.ElementTree if __name__ == '__main__': # generate object of the global needed data globalData = GlobalData() fileName = os.path.basename(__file__) # parse config file, get logfile configurations # and initialize logging try: configRoot = xml.etree.ElementTree.parse( globalData.configFile).getroot() logfile = str(configRoot.find("general").find("log").attrib["file"]) # parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"]) tempLoglevel = tempLoglevel.upper()
default=False) parser.add_option("-f", "--force", dest="force", action="store_true", help="Do not check the version. Just update all files.", default=False) (options, args) = parser.parse_args() if options.update is False: print "Use --help to get all available options." sys.exit(0) protocolUpdate = False configUpdate = False # generate object of the global needed data globalData = GlobalData() fileName = os.path.basename(__file__) instanceLocation = os.path.dirname(os.path.abspath(__file__)) + "/" try: # parse config file configRoot = xml.etree.ElementTree.parse(instanceLocation + "/config/config.xml").getroot() # parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"]) tempLoglevel = tempLoglevel.upper() if tempLoglevel == "DEBUG": loglevel = logging.DEBUG
"--force", dest="force", action="store_true", help="Do not check the version or dependencies. Just update all files.", default=False) (options, args) = parser.parse_args() if options.update is False: print "Use --help to get all available options." sys.exit(0) protocolUpdate = False configUpdate = False # generate object of the global needed data globalData = GlobalData() fileName = os.path.basename(__file__) instanceLocation = os.path.dirname(os.path.abspath(__file__)) + "/" try: # parse config file configRoot = xml.etree.ElementTree.parse( instanceLocation + "/config/config.xml").getroot() # parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"]) tempLoglevel = tempLoglevel.upper() if tempLoglevel == "DEBUG": loglevel = logging.DEBUG
from lib import SMTPAlert from lib import ScreenUpdater from lib import Console from lib import UpdateChecker from lib import GlobalData import logging import time import socket import random import xml.etree.ElementTree if __name__ == '__main__': # generate object of the global needed data globalData = GlobalData() fileName = os.path.basename(__file__) # parse config file, get logfile configurations # and initialize logging try: configRoot = xml.etree.ElementTree.parse( globalData.configFile).getroot() logfile = str(configRoot.find("general").find("log").attrib["file"]) # parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"]) tempLoglevel = tempLoglevel.upper()
# Do nothing if the given location is an absolute path. if inputLocation[0] == "/": return inputLocation # Replace ~ with the home directory. elif inputLocation[0] == "~": return os.environ["HOME"] + inputLocation[1:] # Assume we have a given relative path. return os.path.dirname(os.path.abspath(__file__)) + "/" + inputLocation if __name__ == '__main__': print(asciiLogo) # generate object of the global needed data globalData = GlobalData() fileName = os.path.basename(__file__) # parse config file, get logfile configurations # and initialize logging try: configRoot = xml.etree.ElementTree.parse( globalData.configFile).getroot() logfile = makePath( str(configRoot.find("general").find("log").attrib["file"])) # parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"])
pos = i break if pos == -1: return os.environ["HOME"] return os.path.join(os.environ["HOME"], input_location[pos:]) # Assume we have a given relative path. return os.path.join(os.path.dirname(os.path.abspath(__file__)), input_location) if __name__ == '__main__': print(asciiLogo) # generate object of the global needed data globalData = GlobalData() fileName = os.path.basename(__file__) # parse config file, get logfile configurations # and initialize logging try: configRoot = xml.etree.ElementTree.parse( globalData.configFile).getroot() logfile = make_path( str(configRoot.find("general").find("log").attrib["file"])) # parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"])
if inputLocation[0] == "/": return inputLocation # Replace ~ with the home directory. elif inputLocation[0] == "~": return os.environ["HOME"] + inputLocation[1:] # Assume we have a given relative path. return os.path.dirname(os.path.abspath(__file__)) + "/" + inputLocation if __name__ == '__main__': fileName = os.path.basename(__file__) instanceLocation = os.path.dirname(os.path.abspath(__file__)) + "/" # generate object of the global needed data globalData = GlobalData() try: # parse config file configRoot = xml.etree.ElementTree.parse( instanceLocation + "/config/config.xml").getroot() # parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"]) tempLoglevel = tempLoglevel.upper() if tempLoglevel == "DEBUG": loglevel = logging.DEBUG elif tempLoglevel == "INFO": loglevel = logging.INFO elif tempLoglevel == "WARNING":
from lib import ServerSession, ThreadedTCPServer from lib import VersionInformerSensor from lib import SensorAlertExecuter from lib import ManagerUpdateExecuter from lib import OptionExecuter from lib import GlobalData from lib import SurveyExecuter from lib import parse_config import time import threading import random if __name__ == '__main__': # generate object of the global needed data globalData = GlobalData() fileName = os.path.basename(__file__) # Parse config. if not parse_config(globalData): sys.exit(1) globalData.logger.info("[%s]: Parsing configuration succeeded." % fileName) random.seed() # start the thread that handles all sensor alerts globalData.logger.info("[%s] Starting sensor alert manage thread." % fileName) globalData.sensorAlertExecuter = SensorAlertExecuter(globalData)
from lib import ServerCommunication, ConnectionWatchdog from lib import SMTPAlert from lib import LightningmapSensor, LightningmapDataCollector, SensorExecuter from lib import UpdateChecker from lib import GlobalData import logging import time import socket import random import xml.etree.ElementTree if __name__ == '__main__': # generate object of the global needed data globalData = GlobalData() fileName = os.path.basename(__file__) # parse config file, get logfile configurations # and initialize logging try: configRoot = xml.etree.ElementTree.parse( globalData.configFile).getroot() logfile = str(configRoot.find("general").find("log").attrib["file"]) # parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"]) tempLoglevel = tempLoglevel.upper()
target_format = "raw" if do_png: target_format = "png" if target_location[-4:] != ".png": target_location += ".png" else: if target_location[-4:] != ".dot": target_location += ".dot" try: 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)
import os from lib import ServerCommunication, ConnectionWatchdog from lib import SMTPAlert from lib import LightningmapSensor, LightningmapDataCollector, SensorExecuter from lib import UpdateChecker from lib import GlobalData import logging import time import socket import random import xml.etree.ElementTree if __name__ == '__main__': # generate object of the global needed data globalData = GlobalData() fileName = os.path.basename(__file__) # parse config file, get logfile configurations # and initialize logging try: configRoot = xml.etree.ElementTree.parse( globalData.configFile).getroot() logfile = str(configRoot.find("general").find("log").attrib["file"]) # parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"]) tempLoglevel = tempLoglevel.upper()
if inputLocation[0] == "/": return inputLocation # Replace ~ with the home directory. elif inputLocation[0] == "~": return os.environ["HOME"] + inputLocation[1:] # Assume we have a given relative path. return os.path.dirname(os.path.abspath(__file__)) + "/" + inputLocation if __name__ == '__main__': fileName = os.path.basename(__file__) instanceLocation = os.path.dirname(os.path.abspath(__file__)) + "/" # generate object of the global needed data globalData = GlobalData() try: # parse config file configRoot = xml.etree.ElementTree.parse(instanceLocation + "/config/config.xml").getroot() # parse chosen log level tempLoglevel = str( configRoot.find("general").find("log").attrib["level"]) tempLoglevel = tempLoglevel.upper() if tempLoglevel == "DEBUG": loglevel = logging.DEBUG elif tempLoglevel == "INFO": loglevel = logging.INFO elif tempLoglevel == "WARNING":