runtime
222 / 500
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.

Functionshould_alert(failures, env)
failuresthe number of failed jobs (an int)
ReturnsTrue when failures is at least ALERT_AT (default 5), else False
enva dictionary of text values, like os.environ; ALERT_AT may have spaces around it
Examples
callshould_alert(2, {'ALERT_AT': '3'})returnsFalse
callshould_alert(3, {'ALERT_AT': '3'})returnsTrue
callshould_alert(7, {})returnsTrue

Loading your progress…

An alert threshold that crashes on the server — Python practice · Runtime