I also Tried this, same thing. import requests
import json
# Define your API key and base URL
api_key = 'YOUR_API_KEY'
base_url = 'https://api.meraki.com/api/v1'
org_id = 'YOUR_VERIFIED_ORG_ID'
email_to_add = 'user@company.com'
sms_number_to_add = '+15555555555'
http_server_id = 'aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20vd2ViaG9va3M='
# Define the headers
headers = {
'X-Cisco-Meraki-API-Key': api_key,
'Content-Type': 'application/json'
}
# Define the alert condition for WAN appliance offline
alert_settings = {
"defaultDestinations": {
"emails": [email_to_add],
"smsNumbers": [sms_number_to_add],
"allAdmins": False,
"snmp": False,
"httpServerIds": [http_server_id]
},
"alerts": [
{
"type": "applianceConnectivity",
"enabled": True,
"alertDestinations": {
"emails": [email_to_add],
"smsNumbers": [sms_number_to_add],
"allAdmins": False,
"snmp": False,
"httpServerIds": [http_server_id]
},
"alertCondition": {
"timeout": 30
}
}
]
}
# Fetch all networks in the organization
networks_response = requests.get(f'{base_url}/organizations/{org_id}/networks', headers=headers)
networks = networks_response.json()
# Loop through each network and update alert settings
for network in networks:
network_id = network['id']
alert_settings_endpoint = f'{base_url}/networks/{network_id}/alerts/settings'
# Fetch current alert settings for the network
current_settings_response = requests.get(alert_settings_endpoint, headers=headers)
current_settings = current_settings_response.json()
# Update with new alert settings
current_settings["defaultDestinations"] = alert_settings["defaultDestinations"]
# Ensure appliance connectivity alert is set correctly
appliance_alert_exists = False
for alert in current_settings["alerts"]:
if alert["type"] == "applianceConnectivity":
alert["enabled"] = True
alert["alertDestinations"] = alert_settings["alerts"][0]["alertDestinations"]
alert["alertCondition"]["timeout"] = alert_settings["alerts"][0]["alertCondition"]["timeout"]
appliance_alert_exists = True
break
if not appliance_alert_exists:
current_settings["alerts"].append(alert_settings["alerts"][0])
# Update the alert settings
update_response = requests.put(alert_settings_endpoint, headers=headers, data=json.dumps(current_settings))
if update_response.status_code == 200:
print(f'Successfully updated alerts for network {network["name"]}')
else:
print(f'Failed to update alerts for network {network["name"]}')
print(f'Status Code: {update_response.status_code}')
print(f'Response Text: {update_response.text}')
print(f'Request Data: {json.dumps(current_settings, indent=2)}')
print("Completed updating alerts for all networks.")
... View more