def check_and_log_activation_change(self): """ Will look for active/un-active change of timeperiod. In case it change, we log it like: [1327392000] TIMEPERIOD TRANSITION: <name>;<from>;<to> States of is_active: -1: default value when start 0: when timeperiod end 1: when timeperiod start :return: None """ now = int(time.time()) was_active = self.is_active self.is_active = self.is_time_valid(now) # If we got a change, log it! if self.is_active != was_active: _from = 0 _to = 0 # If it's the start, get a special value for was if was_active is None: _from = -1 if was_active: _from = 1 if self.is_active: _to = 1 # Now raise the log naglog_result( 'info', 'TIMEPERIOD TRANSITION: %s;%d;%d' % (self.get_name(), _from, _to))
def check_and_log_activation_change(self): """ Will look for active/un-active change of timeperiod. In case it change, we log it like: [1327392000] TIMEPERIOD TRANSITION: <name>;<from>;<to> States of is_active: -1: default value when start 0: when timeperiod end 1: when timeperiod start :return: None """ now = int(time.time()) was_active = self.is_active self.is_active = self.is_time_valid(now) # If we got a change, log it! if self.is_active != was_active: _from = 0 _to = 0 # If it's the start, get a special value for was if was_active is None: _from = -1 if was_active: _from = 1 if self.is_active: _to = 1 # Now raise the log naglog_result( 'info', 'TIMEPERIOD TRANSITION: %s;%d;%d' % (self.get_name(), _from, _to) )
def raise_cancel_downtime_log_entry(self): """Raise CONTACT DOWNTIME ALERT entry (info level) Format is : "CONTACT DOWNTIME ALERT: *get_name()*;CANCELLED; Contact has entered a period of scheduled downtime" Example : "CONTACT DOWNTIME ALERT: test_contact;CANCELLED; Contact has entered a period of scheduled downtime" :return: None """ naglog_result('info', "CONTACT DOWNTIME ALERT: %s;CANCELLED; Scheduled " "downtime for contact has been cancelled." % self.get_name())
def raise_exit_downtime_log_entry(self): """Raise CONTACT DOWNTIME ALERT entry (info level) Format is : "CONTACT DOWNTIME ALERT: *get_name()*;STOPPED; Contact has entered a period of scheduled downtime" Example : "CONTACT DOWNTIME ALERT: test_contact;STOPPED; Contact has entered a period of scheduled downtime" :return: None """ naglog_result('info', "CONTACT DOWNTIME ALERT: %s;STOPPED; Contact has " "exited from a period of scheduled downtime" % self.get_name())
def test_basic_logging_log(self): sys.stdout = StringIO() self._collector = Collector() sh = StreamHandler(sys.stdout) sh.setFormatter(DEFAULT_FORMATTER) alignak_logger.handlers = [] alignak_logger.addHandler(sh) alignak_logger.load_obj(self._collector) alignak_logger.log_set = True alignak_logger.setLevel(DEBUG) self.generic_tst(lambda x: naglog_result('info', x), 'Some log-message', [1, 1], [r'^\[\d+\] Some log-message\n$', r'^\[\d+\] Some log-message$'])
def test_basic_logging_log(self): sys.stdout = StringIO() self._collector = Collector() sh = StreamHandler(sys.stdout) sh.setFormatter(DEFAULT_FORMATTER) alignak_logger.handlers = [] alignak_logger.addHandler(sh) alignak_logger.load_obj(self._collector) alignak_logger.log_set = True alignak_logger.setLevel(DEBUG) self.generic_tst( lambda x: naglog_result('info', x), 'Some log-message', [1, 1], [r'^\[\d+\] Some log-message\n$', r'^\[\d+\] Some log-message$'])
def test_basic_logging_log(self): sys.stdout = StringIO() self._collector = Collector() sh = StreamHandler(sys.stdout) sh.setFormatter(DEFAULT_FORMATTER) alignak_logger.handlers = [] alignak_logger.addHandler(sh) alignak_logger.load_obj(self._collector) alignak_logger.log_set = True logfile = NamedTemporaryFile("w", delete=False) logfile.close() self.logfile_name = logfile.name alignak_logger.register_local_log(logfile.name, purge_buffer=False) alignak_logger.setLevel(DEBUG) self.generic_tst(lambda x: naglog_result('info', x), 'Some log-message', [1, 1, 1], ['', r'^\[\d+\] Some log-message$', r'^\[\d+\] Some log-message$'])
def test_basic_logging_log(self): sys.stdout = StringIO() self._collector = Collector() sh = StreamHandler(sys.stdout) sh.setFormatter(DEFAULT_FORMATTER) alignak_logger.handlers = [] alignak_logger.addHandler(sh) alignak_logger.load_obj(self._collector) alignak_logger.log_set = True logfile = NamedTemporaryFile("w", delete=False) logfile.close() self.logfile_name = logfile.name alignak_logger.register_local_log(logfile.name, purge_buffer=False) alignak_logger.setLevel(DEBUG) self.generic_tst( lambda x: naglog_result('info', x), 'Some log-message', [1, 1, 1], ['', r'^\[\d+\] Some log-message$', r'^\[\d+\] Some log-message$'])