MCPcopy Create free account
hub / github.com/adobe/Marinus / update_dns

Function update_dns

python3_cron_scripts/get_sonar_data_unified.py:82–134  ·  view source on GitHub ↗

Insert any matching Sonar DNS records in the Marinus database.

(logger, dns_file, zones, dns_mgr)

Source from the content-addressed store, hash-verified

80
81
82def update_dns(logger, dns_file, zones, dns_mgr):
83 """
84 Insert any matching Sonar DNS records in the Marinus database.
85 """
86 with open(dns_file, "r") as dns_f:
87 for line in dns_f:
88 try:
89 data = json.loads(line)
90 except ValueError:
91 continue
92 except Exception as e:
93 logger.error("Error parsing file...")
94 logger.error("Exception: " + str(e))
95 raise
96
97 dtype = data["type"]
98 try:
99 value = data["value"]
100 domain = data["name"]
101 zone = find_zone(domain, zones)
102 except KeyError:
103 logger.warning("Error with line: " + line)
104 value = ""
105 zone = ""
106 domain = ""
107
108 timestamp = data["timestamp"]
109
110 if zone != "" and value != "":
111 logger.debug("Domain matches! " + domain + " Zone: " + zone)
112
113 if dtype.startswith("unk_in_"):
114 # Sonar didn't recognize the response
115 type_num = int(dtype[7:])
116 g_dns = GoogleDNS.GoogleDNS()
117 for key, value in g_dns.DNS_TYPES.items():
118 if value == type_num:
119 dtype = key
120 break
121
122 if dtype.startswith("unk_in_"):
123 # Marinus didn't recognize it either.
124 logger.warning("Unknown type: " + dtype)
125
126 insert_json = {}
127 insert_json["fqdn"] = domain
128 insert_json["zone"] = zone
129 insert_json["type"] = dtype
130 insert_json["status"] = "unknown"
131 insert_json["value"] = value
132 insert_json["sonar_timestamp"] = int(timestamp)
133 insert_json["created"] = datetime.now()
134 dns_mgr.insert_record(insert_json, "sonar_dns")
135
136
137def check_for_ptr_record(ipaddr, g_dns, zones, dns_manager):

Callers 1

mainFunction · 0.70

Calls 2

find_zoneFunction · 0.70
insert_recordMethod · 0.45

Tested by

no test coverage detected