X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=monitor%2Fdatabase%2Finfo%2Finterface.py;h=8e3b1fb1639da85635923f510416b1c2523debe0;hb=4bf13ed6dd1e71c3f065b7a1957cd3d76c121217;hp=c0ffbf36d16a46c044b6fdfb24aa4ca6a4938dac;hpb=37c768dbd516a39bd56bc43f9b73b51acdfd9563;p=monitor.git diff --git a/monitor/database/info/interface.py b/monitor/database/info/interface.py index c0ffbf3..8e3b1fb 100644 --- a/monitor/database/info/interface.py +++ b/monitor/database/info/interface.py @@ -1,11 +1,13 @@ -from monitor import reboot from monitor.common import * from monitor.model import * from monitor.wrapper import plc from monitor.wrapper import plccache from monitor.wrapper.emailTxt import mailtxt from monitor.database.info.model import * +# NOTE: must import this after monitor.database.info.model b/c that imports +# pcucontro.reboot and blocks this version, if it comes last. +from monitor import reboot class SiteInterface(HistorySiteRecord): @classmethod @@ -60,7 +62,9 @@ class SiteInterface(HistorySiteRecord): return - def pausePenalty(self): + def setPenaltyPause(self): + self.db.penalty_pause = True + self.db.penalty_pause_time = datetime.now() act = ActionRecord(loginbase=self.db.loginbase, action='penalty', action_type='pause_penalty',) @@ -69,6 +73,11 @@ class SiteInterface(HistorySiteRecord): #act = ActionRecord(loginbase=self.db.loginbase, action='penalty', action_type='clear_penalty',) self.db.penalty_level = 0 self.db.penalty_applied = False + self.clearPenaltyPause() + + def clearPenaltyPause(self): + self.db.penalty_pause = False + self.db.penalty_pause_time = None def getTicketStatus(self): if self.db.message_id != 0: @@ -76,6 +85,7 @@ class SiteInterface(HistorySiteRecord): self.db.message_status = rtstatus['Status'] self.db.message_queue = rtstatus['Queue'] self.db.message_created = datetime.fromtimestamp(rtstatus['Created']) + #self.db.message_last_reply = datetime.fromtimestamp(rtstatus['Told']) def setTicketStatus(self, status): print 'SETTING status %s' % status @@ -111,7 +121,12 @@ class SiteInterface(HistorySiteRecord): # TODO: catch any errors here, and add an ActionRecord that contains # those errors. - args = {'loginbase' : self.db.loginbase, 'penalty_level' : self.db.penalty_level} + args = {'loginbase' : self.db.loginbase, + 'penalty_level' : -self.db.penalty_level, + 'monitor_hostname' : config.MONITOR_HOSTNAME, + 'support_email' : config.support_email, + 'plc_name' : config.PLC_NAME, + 'plc_hostname' : config.PLC_WWW_HOSTNAME} args.update(kwargs) hostname = None @@ -121,16 +136,31 @@ class SiteInterface(HistorySiteRecord): if hasattr(mailtxt, type): message = getattr(mailtxt, type) + + ccemail = False + saveact = True viart = True - if 'viart' in kwargs: + if 'viart' in kwargs: + saveact = kwargs['viart'] viart = kwargs['viart'] + if 'saveact' in kwargs: + saveact = kwargs['saveact'] + + if 'ccemail' in kwargs: + ccemail = kwargs['ccemail'] + if viart: self.getTicketStatus() # get current message status + if self.db.message_status not in ['open', 'new']: + self.closeTicket() m = Message(message[0] % args, message[1] % args, viart, self.db.message_id) - contacts = self.getContacts() + if ccemail: + contacts = [config.exception_email] + else: + contacts = self.getContacts() print "sending message: %s to site %s for host %s" % (type, self.db.loginbase, hostname) @@ -140,6 +170,7 @@ class SiteInterface(HistorySiteRecord): # reset to previous status, since a new subject 'opens' RT tickets. self.setTicketStatus(self.db.message_status) + if saveact: # NOTE: only make a record of it if it's in RT. act = ActionRecord(loginbase=self.db.loginbase, hostname=hostname, action='notice', action_type=type, message_id=self.db.message_id) @@ -152,17 +183,17 @@ class SiteInterface(HistorySiteRecord): return def closeTicket(self): - # TODO: close the rt ticket before overwriting the message_id - mailer.closeTicketViaRT(self.db.message_id, "Ticket Closed by Monitor") - act = ActionRecord(loginbase=self.db.loginbase, action='notice', - action_type='close_ticket', message_id=self.db.message_id) - self.db.message_id = 0 - self.db.message_status = "new" + if self.db.message_id: + mailer.closeTicketViaRT(self.db.message_id, "Ticket Closed by Monitor") + act = ActionRecord(loginbase=self.db.loginbase, action='notice', + action_type='close_ticket', message_id=self.db.message_id) + self.db.message_id = 0 + self.db.message_status = "new" def runBootManager(self, hostname): from monitor import bootman print "attempting BM reboot of %s" % hostname - ret = "" + ret = "error" try: ret = bootman.restore(self, hostname) err = "" @@ -170,10 +201,19 @@ class SiteInterface(HistorySiteRecord): err = traceback.format_exc() print err + # TODO: keep this record so that the policy.py can identify all + # bootmanager_* actions without explicitly listing every kind. act = ActionRecord(loginbase=self.db.loginbase, hostname=hostname, action='reboot', action_type='bootmanager_restore', + error_string="") + + if ret: + act = ActionRecord(loginbase=self.db.loginbase, + hostname=hostname, + action='reboot', + action_type='bootmanager_' + ret, error_string=err) return ret