def __call__(self, events, skip_ok=False, skip_warning=False, skip_error=False, skip_trivial=True, skip_start=False, squash_start=False): """Performs filtering, and returns the altered event list.""" output = [] squash = set() self.errors = 0 self.warnings = 0 for (i, e) in enumerate(events): if i in squash: continue e = e.copy() if e['type'] == CrabEvent.START: if skip_start: continue else: if (skip_trivial and CrabStatus.is_trivial(e['status']) or skip_ok and CrabStatus.is_ok(e['status']) or skip_warning and CrabStatus.is_warning(e['status']) or skip_error and CrabStatus.is_error(e['status'])): continue if CrabStatus.is_error(e['status']): self.errors += 1 if CrabStatus.is_warning(e['status']): self.warnings += 1 if squash_start and e['type'] == CrabEvent.FINISH: start = _find_previous_start(events, i) if start is not None: squash.add(start) delta = ( self.store.parse_datetime(e['datetime']) - self.store.parse_datetime(events[start]['datetime'])) e['duration'] = str(delta) e['datetime'] = self.in_timezone(e['datetime']) output.append(e) return output
def __call__(self, events, skip_ok=False, skip_warning=False, skip_error=False, skip_trivial=True, skip_start=False, squash_start=False): """Performs filtering, and returns the altered event list.""" output = [] squash = set() self.errors = 0 self.warnings = 0 for (i, e) in enumerate(events): if i in squash: continue e = e.copy() if e['type'] == CrabEvent.START: if skip_start: continue else: if (skip_trivial and CrabStatus.is_trivial(e['status']) or skip_ok and CrabStatus.is_ok(e['status']) or skip_warning and CrabStatus.is_warning(e['status']) or skip_error and CrabStatus.is_error(e['status'])): continue if CrabStatus.is_error(e['status']): self.errors += 1 if CrabStatus.is_warning(e['status']): self.warnings += 1 if squash_start and e['type'] == CrabEvent.FINISH: start = _find_previous_start(events, i) if start is not None: squash.add(start) delta = (self.store.parse_datetime(e['datetime']) - self.store.parse_datetime(events[start]['datetime'])) e['duration'] = str(delta) e['datetime'] = self.in_timezone(e['datetime']) output.append(e) return output
def _process_event(self, id_, event): """Processes the given event, updating the instance data structures accordingly.""" datetime_ = event['datetime'] if event['status'] is not None: status = event['status'] prevstatus = self.status[id_]['status'] # Avoid overwriting a status with a less important one. if status == CrabStatus.CLEARED: self.status[id_]['status'] = status elif CrabStatus.is_trivial(status): if prevstatus is None or CrabStatus.is_ok(prevstatus): self.status[id_]['status'] = status elif CrabStatus.is_warning(status): if prevstatus is None or not CrabStatus.is_error(prevstatus): self.status[id_]['status'] = status # Always set success / failure status (the remaining options). else: self.status[id_]['status'] = status if not CrabStatus.is_trivial(status): history = self.status[id_]['history'] if len(history) >= HISTORY_COUNT: del history[0] history.append(status) # Handle ALREADYRUNNING as a 'start' type event, so that # the MISSED alarm is not raised and the timeout period # is extended. if (event['type'] == CrabEvent.START or event['status'] == CrabStatus.ALREADYRUNNING): self.status[id_]['running'] = True if not self.passive: self.last_start[id_] = datetime_ self.timeout[id_] = datetime_ + self.config[id_]['timeout'] if id_ in self.late_timeout: del self.late_timeout[id_] if id_ in self.miss_timeout: del self.miss_timeout[id_] elif (event['type'] == CrabEvent.FINISH or event['status'] == CrabStatus.TIMEOUT): self.status[id_]['running'] = False if not self.passive: if id_ in self.timeout: del self.timeout[id_]
def _process_event(self, id_, event): """Processes the given event, updating the instance data structures accordingly.""" datetime_ = event['datetime'] if event['status'] is not None: status = event['status'] prevstatus = self.status[id_]['status'] # Avoid overwriting a status with a less important one. if status == CrabStatus.CLEARED: self.status[id_]['status'] = status elif CrabStatus.is_trivial(status): if prevstatus is None or CrabStatus.is_ok(prevstatus): self.status[id_]['status'] = status elif CrabStatus.is_warning(status): if prevstatus is None or not CrabStatus.is_error(prevstatus): self.status[id_]['status'] = status # Always set success / failure status (the remaining options). else: self.status[id_]['status'] = status if not CrabStatus.is_trivial(status): history = self.status[id_]['history'] if len(history) >= HISTORY_COUNT: del history[0] history.append(status) # Handle ALREADYRUNNING as a 'start' type event, so that # the MISSED alarm is not raised and the timeout period # is extended. if (event['type'] == CrabEvent.START or event['status'] == CrabStatus.ALREADYRUNNING): self.status[id_]['running'] = True if not self.passive: self.last_start[id_] = datetime_ self.timeout[id_] = datetime_ + self.config[id_]['timeout'] if id_ in self.late_timeout: del self.late_timeout[id_] if id_ in self.miss_timeout: del self.miss_timeout[id_] elif (event['type'] == CrabEvent.FINISH or event['status'] == CrabStatus.TIMEOUT): self.status[id_]['running'] = False if not self.passive: if id_ in self.timeout: del self.timeout[id_]
def check_status_patterns(status, config, output): """Function to update a job status based on the patterns. Compares the given output with the patterns in the job configuration, and returns the updated status.""" # Is this a special status which doesn't indicate job completion? # If so we should not attempt to look at the patterns. if status == CrabStatus.ALREADYRUNNING: return status # Check for error status. if CrabStatus.is_error(status): return status fail_pattern = config['fail_pattern'] if fail_pattern is not None and re.search(fail_pattern, output): return CrabStatus.FAIL # Check for warning status. if CrabStatus.is_warning(status): return status warning_pattern = config['warning_pattern'] if warning_pattern is not None and re.search(warning_pattern, output): return CrabStatus.WARNING # Check for good status. success_pattern = config['success_pattern'] if success_pattern is not None and re.search(success_pattern, output): return CrabStatus.SUCCESS # No match -- decide what to do based on which patterns were defined. if success_pattern is not None: if fail_pattern is not None: # There were success and fail patterns but we matched neither # of them, so the status is UNKNOWN. return CrabStatus.UNKNOWN else: # There was a success pattern which we did not match, so # assume this was a failure as there was no explicit success # match. return CrabStatus.FAIL # Otherwise return the original status. If there was a failure # pattern, then we already know we didn't match it. return status
def check_status_patterns(status, config, output): """Function to update a job status based on the patterns. Compares the given output with the patterns in the job configuration, and returns the updated status.""" # Is this a special status which doesn't indicate job completion? # If so we should not attempt to look at the patterns. if status == CrabStatus.ALREADYRUNNING: return status # Check for error status. if CrabStatus.is_error(status): return status fail_pattern = config['fail_pattern'] if fail_pattern is not None and re.search(fail_pattern, output): return CrabStatus.FAIL # Check for warning status. if CrabStatus.is_warning(status): return status warning_pattern = config['warning_pattern'] if warning_pattern is not None and re.search(warning_pattern, output): return CrabStatus.WARNING # Check for good status. success_pattern = config['success_pattern'] if success_pattern is not None and re.search(success_pattern, output): return CrabStatus.SUCCESS # No match -- decide what to do based on which patterns were defined. if success_pattern is not None: if fail_pattern is not None: # There were success and fail patterns but we matched neither # of them, so the status is UNKNOWN. return CrabStatus.UNKNOWN else: # There was a success pattern which we did not match, so # assume this was a failure as there was no explicit success # match. return CrabStatus.FAIL # Otherwise return the original status. If there was a failure # pattern, then we already know we didn't match it. return status