ika108 / inventaire-patch-ssm

0 stars 0 forks source link

no ssm agent installed #10

Open ika108 opened 6 days ago

ika108 commented 6 days ago

We need a way to handle the case where an instance doesn't even have the ssm agent installed/configured. Without it, we can't even send command to these instances, so we need a way to handle this case.

ysatiss commented 3 days ago

When a machine is launched with an ssm agent, it communicates with the ssm patch management inventory. If the instance is not in the inventory we can consider that it does not have the ssm agent installed/configured. So, we can search for its existence in the inventory to know its status. On the other hand, this does not answer the problem where the agent will no longer respond for x or y reasons.

Python object oriented

def get_ssm_instance(self,instance_id): try: response = self.ssm_client.get_inventory( Filters=[ { "Key": "AWS:InstanceInformation.InstanceId", "Values": [instance_id] } ] ) print(response)
if 'Entities' in response and response['Entities']: print("Information trouvée dans l'inventory ssm.") ssm_status = "true" else: print("Aucune information trouvée pour l'instance spécifiée.") ssm_status = "false" return ssm_status except Exception as e: print("Une erreur s'est produite:", e) return None