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, config): cfgObject = ProdAgentConfiguration() cfgObject.loadFromFile(config) notifCfg = cfgObject.getConfig("Notification") senderName = notifCfg.get("Notification_SenderName") senderPwd = notifCfg.get("Notification_SenderPwd") if senderName == None : raise RuntimeError, "missing Notification_SenderName property in " + config + " configuration file" if senderPwd == None: raise RuntimeError, "missing Notification_SenderPwd property in " + config + " configuration file" self.senderName = senderName self.senderPwd = senderPwd self.smtpServer = notifCfg.get("Notification_SMTPServer") if self.smtpServer == None : raise RuntimeError, "missing Notification_SMTPServer property in " + config + " configuration file" self.smtpDbgLvl = notifCfg.get("Notification_SMTPServerDBGLVL") if self.smtpDbgLvl == None: self.smtpDbgLvl = 0 msg = "Notification.Mailer: mail Sender is [" + self.senderName + "]" logging.info( msg ) msg = "Notification.Mailer: SMTP server is [" + self.smtpServer + "]" logging.info( msg ) msg = "Notification.Mailer: SMTP server debug level [" + self.smtpDbgLvl + "]" logging.info( 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 __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 __init__(self, servername): Thread.__init__(self) config = os.environ.get("PRODAGENT_CONFIG", None) self.serverName = servername if config == None: msg = "No ProdAgent Config file provided\n" msg += "set $PRODAGENT_CONFIG variable\n" logging.error(msg) raise Exception(msg) okmsg = "Notification.Consumer.__init__: Configuration file is [" okmsg += config okmsg += "]" logging.info(okmsg) cfgObject = ProdAgentConfiguration() cfgObject.loadFromFile(config) notifCfg = cfgObject.getConfig("Notification") self.notif_delay = notifCfg.get("NotificationDelay") if self.notif_delay == None: self.notif_delay = 1800 try: self.mailer = Mailer.Mailer(config) except RuntimeError, mex: logging.error( mex ) import traceback logging.error(str(traceback.format_exc())) raise Exception(mex)
def CompDIR(comp_name): config = os.environ.get("PRODAGENT_CONFIG", None) cfgObject = ProdAgentConfiguration() cfgObject.loadFromFile(config) compCfg = cfgObject.getConfig(comp_name) return compCfg['ComponentDir']
def status(compList=False): """ _status_ Print status of all components in config file """ config = os.environ.get("PRODAGENT_CONFIG", None) cfgObject = ProdAgentConfiguration() cfgObject.loadFromFile(config) components = cfgObject.listComponents() if compList: return components else: component_run = [] component_down = [] for component in components: compCfg = cfgObject.getConfig(component) compDir = compCfg['ComponentDir'] compDir = os.path.expandvars(compDir) daemonXml = os.path.join(compDir, "Daemon.xml") if not os.path.exists(daemonXml): continue daemon = DaemonDetails(daemonXml) if not daemon.isAlive(): component_down.append(component) else: tmp=[component, daemon['ProcessID']] component_run.append(tmp) return component_run, component_down
def isDrained(): """ _isDrained_ true returned if the server is in drain mode """ config = os.environ.get("PRODAGENT_CONFIG", None) cfgObject = ProdAgentConfiguration() cfgObject.loadFromFile(config) cmconf = cfgObject.getConfig("CommandManager") try: if int(cmconf['acceptableThroughput']) == 0: return True except: return False return False
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
def generateHTML(self): """ Method to generate HTML CODE for main page """ config = os.environ.get("PRODAGENT_CONFIG", None) if config == None: msg = "No ProdAgent Config file provided\n" msg += "either set $PRODAGENT_CONFIG variable\n" msg += "or provide the --config option" raise RuntimeError,msg cfgObject = ProdAgentConfiguration() cfgObject.loadFromFile(config) components = cfgObject.listComponents() html = """ <html><head><title>ALERT MONITORING TOOL</title> <script type=text/javascript> function formsubmit() { alert('form submit') } function reload() { var t = setTimeout ('refresh()',""" + str(int(self.args['AlertMonitorRefreshTime'])*1000) + """) } function refresh() { window.location.href = \'""" + self.args['ComponentURL'] +"""\' } </script> </head> <body onload=reload()> <a href="""+ self.args['BaseURL']+""">Home</a> <h4>Select Component: <form name="components" action='""" +self.args['ComponentURL']+"""' target='_self' > <select name="component" size="1" onChange=components.submit()>""" components.append('ALL') for component in components: html+= "<option value=" +component if self.args['component'] == component: html+=" selected" html+= ">"+ component+" </option>" html += """ </select></h4> </form> <center><h4>Component: """ +self.args['component']+ """</h4></center> <table border=5 width = 90% align = center> <tr ><td colspan=11 bgcolor=#8888CC align=center><font color=black>AlertMonitor</font></td></tr> <tr><td bgcolor='white' align=center colspan=5>CurrentAlerts</td> <td bgcolor=#EEEEFF> </td> <td bgcolor=white colspan=5 align=center>Alert History</td> </tr> <tr> <td colspan=5><div><object style="overflow-x:hidden; width:100%; height:400;" type=text/html data='"""+self.args['ComponentURL']+"""/currentalert?component="""+self.args['component']+"""'></object></div></td> <td bgcolor=#EEEEFF> <td colspan=5></div><object style="overflow-x:hidden; width:100%; height:400;" type=text/html data='"""+self.args['ComponentURL']+"""/historyalert?component="""+self.args['component']+"""'></object></div></td> </tr> </table> """ return html