300-435 · Question #119
Refer to the exhibit. A network engineer must create a script that provides alerts from their Cisco Meraki network. All alerts must be printed on the screen, and the critical alerts must also be…
The correct answer is B. alert_level = data["alertLevel"] alert_type = data["alertType"]. To extract alertLevel and alertType from the incoming JSON payload received by a Flask webhook, directly accessing data["alertLevel"] and data["alertType"] is the correct method, assuming these keys are at the top level of the JSON.
Question
from flask import Flask, request
import my_webex_module #custom made module for Cisco Webex functions
APP = Flask(__name__)
@APP.route("/", methods=["POST"])
def webhook():
data = request.json
print("() alert: {}".format(alert_level, alert_type))
if alert_level == "critical":
my_webex_module.send_alert(alert_type)
return "Alert sent"
else:
return "No alert sent"
# MISSING LINE HERE
Options
- Aalert_level = data["alertLevel"]json alert_type = data["alertType"]json
- Balert_level = data["alertLevel"] alert_type = data["alertType"]
- Calert_level = data["response"]["alertLevel"] alert_type = data["response"]["alertType"]
- Dalert_level = data["item"]["alertLevel"] alert_type = data["item"]["alertType"]
How the community answered
(38 responses)- A5% (2)
- B89% (34)
- C3% (1)
- D3% (1)
Why each option
To extract `alertLevel` and `alertType` from the incoming JSON payload received by a Flask webhook, directly accessing `data["alertLevel"]` and `data["alertType"]` is the correct method, assuming these keys are at the top level of the JSON.
Appending "json" after the dictionary indexing is a syntax error in Python and incorrectly assumes a special handling of JSON data.
The `request.json` object in Flask, after parsing an incoming JSON webhook payload, results in a Python dictionary. To access values from this dictionary where keys like "alertLevel" and "alertType" are at the root level of the JSON, one uses standard dictionary indexing, e.g., `data["alertLevel"]`.
This option assumes that "alertLevel" and "alertType" are nested under a key named "response" within the incoming JSON, which is not indicated by the problem description or typical Meraki webhook structures for direct alerts.
This option assumes that "alertLevel" and "alertType" are nested under a key named "item" within the incoming JSON, which is not indicated by the problem description or typical Meraki webhook structures for direct alerts.
Concept tested: Python Flask webhook JSON payload parsing
Source: https://flask.palletsprojects.com/en/latest/api/#flask.Request.json
Topics
Community Discussion
No community discussion yet for this question.