Skip to content

Instantly share code, notes, and snippets.

@matt-FFFFFF
Last active December 18, 2025 11:48
Show Gist options
  • Select an option

  • Save matt-FFFFFF/7a635f4a0b96f88ccbe9d861a63bab7a to your computer and use it in GitHub Desktop.

Select an option

Save matt-FFFFFF/7a635f4a0b96f88ccbe9d861a63bab7a to your computer and use it in GitHub Desktop.
A log parser for the azuread Terraform provider.
import re
import sys
def parse_log(filename):
with open(filename, 'r') as f:
lines = f.readlines()
requests = []
current_request = {}
in_response = False
for line in lines:
if "Begin AzureAD Response" in line:
in_response = True
current_request = {'method': None, 'uri': None, 'status': None, 'request_id': None}
continue
if "End AzureAD Response" in line:
if in_response and current_request['method']:
requests.append(current_request)
in_response = False
continue
if in_response:
# Try to match Method and URI
# The line usually looks like "GET https://..."
# It might be the first line after Begin Response, but let's be flexible
if not current_request['method']:
match = re.match(r'^\s*(GET|POST|PUT|PATCH|DELETE)\s+(https?://\S+)', line)
if match:
current_request['method'] = match.group(1)
current_request['uri'] = match.group(2)
continue
# Try to match Status Code
# HTTP/2.0 200 OK
if not current_request['status']:
match = re.match(r'^\s*HTTP/\d+\.\d+\s+(\d+)', line)
if match:
current_request['status'] = match.group(1)
continue
# Try to match Request-Id
# Request-Id: ...
if not current_request['request_id']:
match = re.match(r'^\s*Request-Id:\s*([a-f0-9-]+)', line, re.IGNORECASE)
if match:
current_request['request_id'] = match.group(1)
continue
# Print table
print(f"{'Method':<8} | {'Response Code':<15} | {'Request ID':<38} | {'URI'}")
print("-" * 120)
for req in requests:
method = req.get('method', 'N/A')
status = req.get('status', 'N/A')
req_id = req.get('request_id', 'N/A')
uri = req.get('uri', 'N/A')
print(f"{method:<8} | {status:<15} | {req_id:<38} | {uri}")
if __name__ == "__main__":
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <logfile>")
sys.exit(1)
parse_log(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment