Notes before starting:
This script example should be performed with the new Cloud DDoS Portal API.
Before proceeding, make sure you have obtained the CDDoS account ID.
# Function to get the settings of an asset
def AssetSettings(ACCOUNT_ID, AssetName):
HEADERS = {"X-API-KEY": APIKEY}
AssetsSettingsURL = f"{BASE_URL}/api/assets?type=account&id=" + ACCOUNT_ID
r = requests.get(AssetsSettingsURL, headers=HEADERS)
if not r.ok:
raise Exception("Error occured while getting asset settings")
r = r.json()
r = r["reply"]
for i in r:
check = i["name"].replace(" ", "")
if check == AssetName: # Name of the asset in the portal
print(i) # Prints only the settings of the asset mentioned
return
def Get_Security_Alerts(ACCOUNT_ID):
HEADERS = {"X-API-KEY": APIKEY}
# Get current epoch time and interval
current_epoch_time = int(time.time()) * 1000 # current epoch time in milliseconds
interval_epoch_time = str(current_epoch_time - 259200000) # Last 72 hours
current_epoch_time = str(current_epoch_time)
NetworkSecurityAlertsURL = f"{BASE_URL}/api/alerts/events/?from={interval_epoch_time}&to={current_epoch_time}&id={ACCOUNT_ID}&severity=INFO,LOW,MEDIUM,HIGH&type=account"
r = requests.get(NetworkSecurityAlertsURL, headers=HEADERS)
if not r.ok:
print(r.reason)
else:
text = json.dumps(r.json(), indent=2)
print(text)
def Get_Operational_Alerts(ACCOUNT_ID):
HEADERS = {"X-API-KEY": APIKEY}
# Get current epoch time and interval
current_epoch_time = int(time.time()) * 1000 # current epoch time in milliseconds
interval_epoch_time = str(current_epoch_time - 259200000) # Last 72 hours
current_epoch_time = str(current_epoch_time)
NetworkSecurityAlertsURL = f"{BASE_URL}/api/alerts/operational/?from={interval_epoch_time}&to={current_epoch_time}&id={ACCOUNT_ID}&severity=INFO,LOW,MEDIUM,HIGH&type=account"
r = requests.get(NetworkSecurityAlertsURL, headers=HEADERS)
if not r.ok:
print(r.reason)
else:
text = json.dumps(r.json(), indent=2)
print(text)