def save(self): """ _save_ Pack the data object into an IMProvNode """ output = None try: try: config = os.environ.get("PRODAGENT_CONFIG", None) if config == None: msg = "No ProdAgent Config file provided\n" raise RuntimeError, msg cfgObject = ProdAgentConfiguration() cfgObject.loadFromFile(config) alertHandlerConfig = cfgObject.get("AlertHandler") workingDir = alertHandlerConfig["ComponentDir"] dir = os.path.join(os.path.expandvars(workingDir), "Alerts") if not os.path.exists(dir): os.makedirs(dir) self.FileName = os.path.join(dir, "alert-%s.dat" % makeUUID()) output = open(self.FileName, "wb") pickle.dump(self, output) except Exception, ex: # to do: Exception handling print ex raise RuntimeError, str(ex) finally: if output: output.close() return
def __init__ (self, baseURL): """ _init_ Initization function """ self.args = {} self.args['ComponentURL'] = baseURL + "/alertmonitor" self.args['BaseURL'] = baseURL self.args['AlertMonitorRefreshTime'] = 2*60 # time in seconds self.args['MoveAlertTime'] = 5*60 # time in seconds self.args['component'] = 'ALL' try: config = os.environ.get("PRODAGENT_CONFIG", None) if config == None: msg = "No ProdAgent Config file provided\n" raise RuntimeError, msg cfgObject = ProdAgentConfiguration() cfgObject.loadFromFile(config) alertHandlerConfig = cfgObject.get("HTTPFrontend") self.args.update (**alertHandlerConfig) except Exception, ex: msg = 'AlertMonitor Initialization Failed' raise RuntimeError, msg
def save(self): """ _save_ Pack the data object into an IMProvNode """ output = None try: try: config = os.environ.get("PRODAGENT_CONFIG", None) if config == None: msg = "No ProdAgent Config file provided\n" raise RuntimeError, msg cfgObject = ProdAgentConfiguration() cfgObject.loadFromFile(config) alertHandlerConfig = cfgObject.get("AlertHandler") workingDir = alertHandlerConfig['ComponentDir'] dir = os.path.join(os.path.expandvars(workingDir), 'Alerts') if not os.path.exists(dir): os.makedirs(dir) self.FileName = os.path.join(dir, "alert-%s.dat" % makeUUID()) output = open(self.FileName, 'wb') pickle.dump(self, output) except Exception, ex: # to do: Exception handling print ex raise RuntimeError, str(ex) finally: if output: output.close() return
def getDAOFactory (): """ Initialize the DAOFactory and connection to the respective database. Return: DAOFactory instance """ # // # // Load ProdAgent Config block to get connection parameters #// config = os.environ.get("PRODAGENT_CONFIG", None) if config == None: msg = "No ProdAgent Config file provided\n" msg += "Set $PRODAGENT_CONFIG variable\n" cfgObject = ProdAgentConfiguration() cfgObject.loadFromFile(config) dbConfig = cfgObject.get("ProdAgentDB") param = {} try: #// connection parameters param['dialect'] = dbConfig['dbType'] param['user'] = dbConfig['user'] param['password'] = dbConfig['passwd'] param['database'] = dbConfig['dbName'] param['host'] = dbConfig['host'] if dbConfig['portNr']: param['port'] = dbConfig['portNr'] if dbConfig['socketFileLocation']: param['unix_socket'] = dbConfig['socketFileLocation'] #// otherwise use default socket location /tmp except Exception, ex: msg = "Parameter missing \n" msg += str(ex) raise RuntimeError, msg