An on-call engineer's small Flask service receives Meraki alert webhooks from a 300-device warehouse network. It must open a ticket only for warning and critical events, tolerate alerts that omit the device serial, and reject requests with an invalid shared secret. Which parsing and validation sequence should the handler apply to each webhook JSON body?
Select an answer to reveal the explanation.
Short Explanation
Treat each webhook like a guest at the door: decode the JSON, then reject it if the shared secret doesn’t match. Next, check the alert level so you open tickets only for warning or critical events, and use .get() with a default for optional fields like the device serial.
Full Explanation
The handler should decode the body so its fields can be examined, then check the shared secret and reject a mismatch before doing alert-specific work. It should branch on alert level to create tickets only for warning and critical events, and use .get() with suitable defaults for fields that may be absent, such as the device serial. Reading the serial with body indexing is conventional when a field is mandatory, but omission is explicitly allowed here; a missing key would raise KeyError and could prevent an otherwise valid alert from being handled. Assigning ticket priority by alert level and safely reading optional fields does not meet the filtering requirement: prioritizing is not the same as branching to exclude informational or other non-target alerts, so those alerts could still open tickets. Allowing requests from approved source IPs is a common additional perimeter control, but it does not verify the required shared secret; an invalid or absent secret would not itself cause rejection. Exam caveat: distinguish authentication from authorization and routing—passing a credential check does not mean every authenticated event should create a ticket. Practical check: test valid and invalid secrets, warning and critical levels, a non-target level, and a payload with no serial; confirm only the intended alerts create tickets and missing optional data causes no exception.