Facebook
From Trend, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 185
  1. import requests
  2. import json
  3.  
  4. # Define your Deep Security Manager credentials and the endpoint
  5. DSM_HOST = "your_dsm_host"
  6. DSM_PORT = "4119"  # Default port for Deep Security Manager
  7. DSM_USERNAME = "your_username"
  8. DSM_PASSWORD = "your_password"
  9. ACTIVATE_AGENT_ENDPOINT = f"https://{DSM_HOST}:{DSM_PORT}/rest"
  10.  
  11. # Function to authenticate with Deep Security Manager
  12. def authenticate():
  13.     login_url = f"{ACTIVATE_AGENT_ENDPOINT}/session/login"
  14.     headers = {'Content-Type': 'application/json'}
  15.     payload = {
  16.         "dsCredentials": {
  17.             "userName": DSM_USERNAME,
  18.             "password": DSM_PASSWORD
  19.         }
  20.     }
  21.     response = requests.post(login_url, headers=headers, data=json.dumps(payload), verify=False)
  22.     if response.status_code == 200:
  23.         return response.json()["sessionID"]
  24.     else:
  25.         print(f"Failed to authenticate. Status code: {response.status_code}")
  26.         return None
  27.  
  28. # Function to activate an agent
  29. def activate_agent(session_id, agent_endpoint):
  30.     activate_url = f"{ACTIVATE_AGENT_ENDPOINT}/agents/{agent_endpoint}/activate"
  31.     headers = {
  32.         'Content-Type': 'application/json',
  33.         'Cookie': f"sID={session_id}"
  34.     }
  35.     response = requests.post(activate_url, headers=headers, verify=False)
  36.     if response.status_code == 200:
  37.         print(f"Agent {agent_endpoint} activation successful!")
  38.     else:
  39.         print(f"Failed to activate agent {agent_endpoint}. Status code: {response.status_code}")
  40.  
  41. if __name__ == "__main__":
  42.     session_id = authenticate()
  43.     if session_id:
  44.         agents_to_activate = [
  45.             "agent_id_to_activate_1",
  46.             "agent_id_to_activate_2",
  47.             "agent_id_to_activate_3",
  48.             # Add more agent IDs as needed
  49.         ]
  50.         for agent in agents_to_activate:
  51.             activate_agent(session_id, agent)
  52.     else:
  53.         print("Authentication failed. Please check your credentials and try again.")
  54.