Skip to content

Instantly share code, notes, and snippets.

@briglx
Created August 24, 2017 22:58
Show Gist options
  • Save briglx/d2ff66737195dd810d4a3b959358ed4f to your computer and use it in GitHub Desktop.
Save briglx/d2ff66737195dd810d4a3b959358ed4f to your computer and use it in GitHub Desktop.
Parse the output from a call to the azure deployment api. Usage: azure group deployment operation list --name deploymentname --resource-group rgname | python parse_azure_deployment.py
#!/usr/bin/python
import json
import sys
from pprint import pprint
import fileinput
data = json.load(sys.stdin)
for d in data:
resourceName = "Null"
resourceType = "Null"
message = ""
if d["properties"]["targetResource"] != None:
resourceName = d["properties"]["targetResource"]["resourceName"]
resourceType = d["properties"]["targetResource"]["resourceType"]
if d["properties"]["provisioningState"] == "Failed":
message = d["properties"]["statusMessage"]["message"]
print resourceName, ",", resourceType, ",", d["properties"]["provisioningState"], ",", message, ",", d["properties"]["timestamp"], ",", d["operationId"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment