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

Function update_dns

python3_cron_scripts/get_data_by_cidr_unified.py:107–153  ·  view source on GitHub ↗

Search DNS file and insert relevant records into the database.

(logger, dns_file, dns_manager, ip_manager, zones)

Source from the content-addressed store, hash-verified

105
106
107def update_dns(logger, dns_file, dns_manager, ip_manager, zones):
108 """
109 Search DNS file and insert relevant records into the database.
110 """
111 with open(dns_file, "r") as dns_f:
112 for line in dns_f:
113 try:
114 data = json.loads(line)
115 except ValueError:
116 continue
117 except Exception as e:
118 logger.error("Error parsing file...")
119 logger.error("Exception: " + str(e))
120 raise
121
122 try:
123 domain = data["name"]
124 except:
125 logger.warning("Error with line: " + line)
126 domain = ""
127
128 dtype = data["type"]
129
130 try:
131 value = data["value"]
132 except KeyError:
133 logger.warning("Error with line: " + line)
134 value = ""
135 timestamp = data["timestamp"]
136
137 if (
138 dtype == "a"
139 and value != ""
140 and domain != ""
141 and ip_manager.is_tracked_ip(value)
142 ):
143 logger.debug("Matched DNS " + value)
144 zone = find_zone(domain, zones)
145 insert_json = {}
146 insert_json["fqdn"] = domain
147 insert_json["zone"] = zone
148 insert_json["type"] = dtype
149 insert_json["status"] = "unknown"
150 insert_json["value"] = value
151 insert_json["sonar_timestamp"] = int(timestamp)
152 insert_json["created"] = datetime.now()
153 dns_manager.insert_record(insert_json, "sonar_dns")
154
155
156def check_for_ptr_record(ipaddr, dns_manager, g_dns, zones):

Callers 1

mainFunction · 0.70

Calls 3

is_tracked_ipMethod · 0.80
find_zoneFunction · 0.70
insert_recordMethod · 0.45

Tested by

no test coverage detected