nerdexam
Cisco

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.

Controller-Based Network Automation

Question

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 sent to a Cisco Webex room. Which code snippet must be added to the box in the code to perform this task?
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)
  • A
    5% (2)
  • B
    89% (34)
  • C
    3% (1)
  • D
    3% (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.

Aalert_level = data["alertLevel"]json alert_type = data["alertType"]json

Appending "json" after the dictionary indexing is a syntax error in Python and incorrectly assumes a special handling of JSON data.

Balert_level = data["alertLevel"] alert_type = data["alertType"]Correct

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"]`.

Calert_level = data["response"]["alertLevel"] alert_type = data["response"]["alertType"]

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.

Dalert_level = data["item"]["alertLevel"] alert_type = data["item"]["alertType"]

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

#Python#Flask#Webhooks#JSON parsing

Community Discussion

No community discussion yet for this question.

Full 300-435 Practice