import requests import json # Define your Deep Security Manager credentials and the endpoint DSM_HOST = "your_dsm_host" DSM_PORT = "4119" # Default port for Deep Security Manager DSM_USERNAME = "your_username" DSM_PASSWORD = "your_password" ACTIVATE_AGENT_ENDPOINT = f"https://{DSM_HOST}:{DSM_PORT}/rest" # Function to authenticate with Deep Security Manager def authenticate(): login_url = f"{ACTIVATE_AGENT_ENDPOINT}/session/login" headers = {'Content-Type': 'application/json'} payload = { "dsCredentials": { "userName": DSM_USERNAME, "password": DSM_PASSWORD } } response = requests.post(login_url, headers=headers, data=json.dumps(payload), verify=False) if response.status_code == 200: return response.json()["sessionID"] else: print(f"Failed to authenticate. Status code: {response.status_code}") return None # Function to activate an agent def activate_agent(session_id, agent_endpoint): activate_url = f"{ACTIVATE_AGENT_ENDPOINT}/agents/{agent_endpoint}/activate" headers = { 'Content-Type': 'application/json', 'Cookie': f"sID={session_id}" } response = requests.post(activate_url, headers=headers, verify=False) if response.status_code == 200: print(f"Agent {agent_endpoint} activation successful!") else: print(f"Failed to activate agent {agent_endpoint}. Status code: {response.status_code}") if __name__ == "__main__": session_id = authenticate() if session_id: agents_to_activate = [ "agent_id_to_activate_1", "agent_id_to_activate_2", "agent_id_to_activate_3", # Add more agent IDs as needed ] for agent in agents_to_activate: activate_agent(session_id, agent) else: print("Authentication failed. Please check your credentials and try again.")