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

Function update_rdns

python3_cron_scripts/get_sonar_data_unified.py:159–207  ·  view source on GitHub ↗

Insert any matching Sonar RDNS records in the Marinus database.

(logger, rdns_file, zones, dns_mgr, mongo_connector)

Source from the content-addressed store, hash-verified

157
158
159def update_rdns(logger, rdns_file, zones, dns_mgr, mongo_connector):
160 """
161 Insert any matching Sonar RDNS records in the Marinus database.
162 """
163 rdns_collection = mongo_connector.get_sonar_reverse_dns_connection()
164 g_dns = GoogleDNS.GoogleDNS()
165
166 with open(rdns_file, "r") as read_f:
167 for line in read_f:
168 try:
169 data = json.loads(line)
170 except ValueError:
171 continue
172 except Exception as e:
173 logger.error("Error parsing file...")
174 logger.error("Exception: " + str(e))
175 raise
176
177 try:
178 domain = data["value"]
179 ip_addr = data["name"]
180 zone = find_zone(domain, zones)
181 except KeyError:
182 domain = ""
183 ip_addr = ""
184 zone = ""
185
186 timestamp = data["timestamp"]
187
188 if zone != "" and domain != "":
189 logger.debug("Domain matches! " + domain + " Zone: " + zone)
190 result = mongo_connector.perform_count(rdns_collection, {"ip": ip_addr})
191 if result == 0:
192 insert_json = {}
193 insert_json["ip"] = ip_addr
194 insert_json["zone"] = zone
195 insert_json["fqdn"] = domain
196 insert_json["status"] = "unknown"
197 insert_json["sonar_timestamp"] = int(timestamp)
198 insert_json["created"] = datetime.now()
199 insert_json["updated"] = datetime.now()
200 mongo_connector.perform_insert(rdns_collection, insert_json)
201 else:
202 rdns_collection.update_one(
203 {"ip": ip_addr},
204 {"$set": {"fqdn": domain}, "$currentDate": {"updated": True}},
205 )
206
207 check_for_ptr_record(ip_addr, g_dns, zones, dns_mgr)
208
209
210def download_remote_files(logger, s, file_reference, data_dir, jobs_manager):

Callers 1

mainFunction · 0.70

Calls 5

perform_countMethod · 0.80
perform_insertMethod · 0.80
find_zoneFunction · 0.70
check_for_ptr_recordFunction · 0.70

Tested by

no test coverage detected