@@ -447,49 +447,49 @@ def check_licenses(self) -> Dict[str, Any]:
447447
448448 return response_dict
449449
450- def get_machine_sync_details (self ) -> List [Any ]:
450+ def get_machine_sync_details (self ) -> Dict [Any ]:
451451 """Checks CloudEndure Project inventory and returns register machine replication state.
452452 """
453- response_list : List [Any ] = []
454453 print (f"INFO: Retreiving sync status for all machines in Project: ({ self .project_name } )" )
455454 machines_response : Response = self .api .api_call (f"projects/{ self .project_id } /machines" )
456455 if not machines_response .ok :
457456 print (f"ERROR: API response did not return a 2XX status; Returned { machines_response .status_code } ..." )
458457 return {}
458+ response_dict : Dict [str , Any ] = {}
459459 ce_project_inventory = json .loads (machines_response .text ).get ("items" , [])
460460 for _query_value in ce_project_inventory :
461- machine_name : str = _query_value ["sourceProperties" ]["name" ]
462- sync_details : Dict [str , Any ] = {
463- "machine_name" : machine_name ,
461+ machine_id : str = _query_value ["id" ]
462+ replication_info : Dict [str , Any ] = _query_value .get ("replicationInfo" , {})
463+ response_dict [machine_id ] = {
464+ "machine_name" : _query_value .get ("sourceProperties" , {}).get ("name" , "" ),
464465 "in_inventory" : _query_value ["isAgentInstalled" ],
465466 "replication_status" : _query_value ["replicationStatus" ],
466- "last_seen_utc" : _query_value ["replicationInfo" ]["lastSeenDateTime" ],
467- "total_storage_bytes" : _query_value ["replicationInfo" ]["totalStorageBytes" ],
468- "replicated_storage_bytes" : _query_value ["replicationInfo" ]["replicatedStorageBytes" ],
469- "rescanned_storage_bytes" : 0 ,
470- "backlogged_storage_bytes" : _query_value ["replicationInfo" ]["backloggedStorageBytes" ],
467+ "total_storage_bytes" : replication_info .get ("totalStorageBytes" , - 1 ),
468+ "replicated_storage_bytes" : replication_info .get ("replicatedStorageBytes" , - 1 ),
469+ "rescanned_storage_bytes" : replication_info .get ("rescannedStorageBytes" , 0 ),
470+ "backlogged_storage_bytes" : replication_info .get ("backloggedStorageBytes" , - 1 ),
471471 }
472- if "rescannedStorageBytes" in _query_value ["replicationInfo" ]:
473- sync_details ["recanned_storage_bytes" ] = _query_value ["replicationInfo" ]["rescannedStorageBytes" ]
474- response_list .append (sync_details )
472+ if replication_info .get ("lastSeenDateTime" ):
473+ response_dict [machine_id ]["last_seen_utc" ] = replication_info .get ("lastSeenDateTime" )
475474 # Project is still printing to console as a convention; Emitting an
476475 # output to stdout for interactive usage
477- return response_list
476+ return response_dict
478477
479- def inspect_ce_project (self , check_type : str ) -> List [Any ]:
480- if not check_type :
478+ def inspect_ce_project (self , check_type : str ) -> Dict [str , Any ]:
479+ valid_check_types : List [str ] = ["not_synced" , "not_started" , "not_current" ]
480+ if check_type not in valid_check_types :
481481 print (
482- f" ERROR: Unknown check_type of ' { check_type } ' ; Please use 'not_synced', 'not_started', or 'not_current' ..."
482+ f' ERROR: Unknown check_type of " { check_type } " ; Please use a valid check_type: [ { ", " . join ( valid_check_types ) } ] ...'
483483 )
484484 return
485- result : List [ Any ] = []
486- sync_report : List [ Any ] = self .get_machine_sync_details ()
485+ result : Dict [ str , Any ] = {}
486+ sync_report : Dict [ str , Any ] = self .get_machine_sync_details ()
487487 print (f"INFO: Using check '{ check_type } ' on Project: ({ self .project_name } )" )
488488 inspector = getattr (self , check_type )
489- for item in sync_report :
490- mcheck = inspector (machine = item )
489+ for item in sync_report . keys () :
490+ mcheck = inspector (machine = sync_report [ item ] )
491491 if mcheck :
492- result . append ( item )
492+ result [ item ] = sync_report [ item ]
493493 print (f"INFO: Check '{ check_type } ' completed; { len (result )} machines matched in Project: ({ self .project_name } )" )
494494 return result
495495
@@ -506,12 +506,12 @@ def not_started(self, machine) -> bool:
506506 return True
507507
508508 def not_current (self , machine , delta_seconds : int = 86400 ) -> bool :
509- now : datetime = datetime . now ( timezone . utc )
510- machine_last_seen : datetime = datetime .fromisoformat ( machine [ "last_seen_utc" ] )
511- last_seen_delta : datetime = now - machine_last_seen
512- # If you're exceeding the size of int, you have bigger problems
513- if int (last_seen_delta .total_seconds ()) >= delta_seconds :
514- return True
509+ if machine . get ( "last_seen_utc" ):
510+ now : datetime = datetime .datetime . now ( datetime . timezone . utc )
511+ machine_last_seen : datetime = datetime . datetime . fromisoformat ( machine [ "last_seen_utc" ])
512+ last_seen_delta : datetime = now - machine_last_seen
513+ if int (last_seen_delta .total_seconds ()) >= delta_seconds :
514+ return True
515515 else :
516516 return False
517517
0 commit comments