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

Function download_sonar_rdns

python3_cron_scripts/download_from_remote_database.py:253–285  ·  view source on GitHub ↗

The remote sonar_rdns_colllection is temporary storage for the remote Sonar scripts

(logger, mongo_connector, remote_mongo_connector)

Source from the content-addressed store, hash-verified

251
252
253def download_sonar_rdns(logger, mongo_connector, remote_mongo_connector):
254 """
255 The remote sonar_rdns_colllection is temporary storage for the remote Sonar scripts
256 """
257 logger.info("Beginning Sonar RDNS Download")
258
259 # Calculate jobs
260 scrub_date = datetime.now() - timedelta(days=2, hours=9)
261
262 remote_sonar_rdns_collection = (
263 remote_mongo_connector.get_sonar_reverse_dns_connection()
264 )
265 rdns_collection = mongo_connector.get_sonar_reverse_dns_connection()
266
267 # Get all dns records where
268 results = remote_mongo_connector.perform_find(
269 remote_sonar_rdns_collection, {"updated": {"$gt": scrub_date}}, {"_id": 0}
270 ).batch_size(50)
271
272 for result in results:
273 count = mongo_connector.perform_count(rdns_collection, {"ip": result["ip"]})
274
275 if count == 0:
276 mongo_connector.perform_insert(rdns_collection, result)
277 else:
278 rdns_collection.update_one(
279 {"ip": result["ip"]},
280 {"$set": {"fqdn": result["fqdn"]}, "$currentDate": {"updated": True}},
281 )
282
283 # Delete all DNS records not updated within 60 days?
284 scrub_date = datetime.now() - timedelta(days=60, hours=9)
285 remote_sonar_rdns_collection.delete_many({"updated": {"$lt": scrub_date}})
286
287
288def main(logger=None):

Callers

nothing calls this directly

Calls 4

perform_findMethod · 0.80
perform_countMethod · 0.80
perform_insertMethod · 0.80

Tested by

no test coverage detected