-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_domain_expiry_synthetics.py
47 lines (33 loc) · 1.17 KB
/
create_domain_expiry_synthetics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""_summary_
"""
import os
from dotenv import load_dotenv
import synthetics_functions
def main():
load_dotenv()
api_key = os.environ.get("NEW_RELIC_API_KEY")
account_id = os.environ.get("NEW_RELIC_ACCOUNT_ID")
headers = {"X-Api-Key": api_key, "Content-Type": "application/json"}
graph_url = "https://api.newrelic.com/graphql"
url_file = "test_urls.txt"
c = 0
urls = synthetics_functions.get_urls(url_file)
for url in urls:
clean_url = url.strip()
if clean_url:
create_mutation = synthetics_functions.get_create_script_monitor_mutation(
clean_url, account_id
)
response = synthetics_functions.make_graph_post_request(
graph_url, headers, create_mutation
)
if '{"errors":[]}' in response.text and response.status_code == 200:
c += 1
print(f"{c}/{len(urls)} : {response.status_code}/Ok : `{clean_url}` monitor created")
else:
raise Exception(f"Query failed: {response.text}")
print("All URLs have been processed.")
if __name__ == "__main__":
main()