The remote sonar_rdns_colllection is temporary storage for the remote Sonar scripts
(logger, mongo_connector, remote_mongo_connector)
| 251 | |
| 252 | |
| 253 | def 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 | |
| 288 | def main(logger=None): |
nothing calls this directly
no test coverage detected