@@ -459,22 +459,18 @@ def get_machine_sync_details(self) -> Dict[Any]:
459459 ce_project_inventory = json .loads (machines_response .text ).get ("items" , [])
460460 for _query_value in ce_project_inventory :
461461 machine_id : str = _query_value ["id" ]
462+ replication_info : Dict [str , Any ] = _query_value .get ("replicationInfo" , {})
462463 response_dict [machine_id ] = {
463- "machine_name" : _query_value [ "sourceProperties" ][ "name" ] ,
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" : "N/A" ,
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 "lastSeenDateTime" in _query_value ["replicationInfo" ].keys ():
473- response_dict [machine_id ]["last_seen_utc" ] = _query_value ["replicationInfo" ]["lastSeenDateTime" ]
474- if "rescannedStorageBytes" in _query_value ["replicationInfo" ].keys ():
475- response_dict [machine_id ]["rescanned_storage_bytes" ] = _query_value ["replicationInfo" ][
476- "rescannedStorageBytes"
477- ]
472+ if replication_info .get ("lastSeenDateTime" ):
473+ response_dict [machine_id ]["last_seen_utc" ] = replication_info .get ("lastSeenDateTime" )
478474 # Project is still printing to console as a convention; Emitting an
479475 # output to stdout for interactive usage
480476 return response_dict
@@ -509,12 +505,12 @@ def not_started(self, machine) -> bool:
509505 return True
510506
511507 def not_current (self , machine , delta_seconds : int = 86400 ) -> bool :
512- now : datetime = datetime . now ( timezone . utc )
513- machine_last_seen : datetime = datetime .fromisoformat ( machine [ "last_seen_utc" ] )
514- last_seen_delta : datetime = now - machine_last_seen
515- # If you're exceeding the size of int, you have bigger problems
516- if int (last_seen_delta .total_seconds ()) >= delta_seconds :
517- return True
508+ if machine . get ( "last_seen_utc" ):
509+ now : datetime = datetime .now ( datetime . timezone . utc )
510+ machine_last_seen : datetime = datetime . datetime . fromisoformat ( machine [ "last_seen_utc" ])
511+ last_seen_delta : datetime = now - machine_last_seen
512+ if int (last_seen_delta .total_seconds ()) >= delta_seconds :
513+ return True
518514 else :
519515 return False
520516
0 commit comments