How to use build_alert_hooks method in autotest

Best Python code snippet using autotest_python

monitors_util.py

Source:monitors_util.py Github

copy

Full Screen

...81 if not line.startswith('#')]82 overrides_pairs = zip(overrides_lines[0::3], overrides_lines[1::3])83 _assert_is_all_blank_lines(overrides_lines[2::3], overrides_file)84 return dict(overrides_pairs)85def build_alert_hooks(patterns_file, warnfile, overrides_file=None):86 """Parse data in patterns file and transform into alert_hook list.87 Args:88 patterns_file: file; File to read alert pattern definitions from.89 warnfile: file; File to configure alert function to write warning to.90 Returns:91 list; Regex to alert function mapping.92 [(regex, alert_function), ...]93 """94 pattern_lines = patterns_file.readlines()95 # expected pattern format:96 # <msgtype> <newline> <regex> <newline> <alert> <newline> <newline>97 # msgtype = a string categorizing the type of the message - used for98 # enabling/disabling specific categories of warnings99 # regex = a python regular expression100 # alert = a string describing the alert message101 # if the regex matches the line, this displayed warning will102 # be the result of (alert % match.groups())103 patterns = zip(pattern_lines[0::4], pattern_lines[1::4],104 pattern_lines[2::4])105 _assert_is_all_blank_lines(pattern_lines[3::4], patterns_file)106 overrides_map = _read_overrides(overrides_file)107 hooks = []108 for msgtype, regex, alert in patterns:109 regex = overrides_map.get(regex, regex)110 regex = re.compile(regex.rstrip('\n'))111 alert_function = make_alert(warnfile, msgtype.rstrip('\n'),112 alert.rstrip('\n'))113 hooks.append((regex, alert_function))114 return hooks115def build_alert_hooks_from_path(patterns_path, warnfile):116 """117 Same as build_alert_hooks, but accepts a path to a patterns file and118 automatically finds the corresponding site overrides file if one exists.119 """120 dirname, basename = os.path.split(patterns_path)121 site_overrides_basename = 'site_' + basename + '_overrides'122 site_overrides_path = os.path.join(dirname, site_overrides_basename)123 site_overrides_file = None124 patterns_file = open(patterns_path)125 try:126 if os.path.exists(site_overrides_path):127 site_overrides_file = open(site_overrides_path)128 try:129 return build_alert_hooks(patterns_file, warnfile,130 overrides_file=site_overrides_file)131 finally:132 if site_overrides_file:133 site_overrides_file.close()134 finally:135 patterns_file.close()136def process_input(137 input, logfile, log_timestamp_format=None, alert_hooks=()):138 """Continuously read lines from input stream and:139 - Write them to log, possibly prefixed by timestamp.140 - Watch for alert patterns.141 Args:142 input: file; Stream to read from.143 logfile: file; Log file to write to...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful