question 222 CLI & Automation · easy
An alert threshold that crashes on the server
A monitoring script decides whether to page someone. It works on a laptop, but on the server, where ALERT_AT=3 is set in the environment, it crashes with TypeError: '>=' not supported between instances of 'int' and 'str'. Fix should_alert so it works whether or not the variable is set.
Function
should_alert(failures, env)failuresthe number of failed jobs (an
int)Returns
True when failures is at least ALERT_AT (default 5), else Falseenva dictionary of text values, like
os.environ; ALERT_AT may have spaces around itExamples
callshould_alert(2, {'ALERT_AT': '3'})returnsFalse
callshould_alert(3, {'ALERT_AT': '3'})returnsTrue
callshould_alert(7, {})returnsTrue