-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure-fleet.py
123 lines (102 loc) · 5.47 KB
/
configure-fleet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import os
import sys
import time
import subprocess
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
IP_ADDR = str(sys.argv[1])
PASS = str(sys.argv[2])
options = Options()
options.add_argument('--window-size=1920,1080')
options.add_argument('--start-maximized')
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('ignore-certificate-errors')
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get(f"https://{IP_ADDR}:5601/")
userNameField = WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.XPATH, '//*[@data-test-subj="loginUsername"]')))
time.sleep(0.2)
userNameField.send_keys("elastic")
driver.find_element("xpath", '//*[@data-test-subj="loginPassword"]').send_keys(PASS)
driver.find_element("xpath", '//*[@data-test-subj="loginSubmit"]').click()
skipWelcomeScreenElement = WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '//*[@data-test-subj="skipWelcomeScreen"]')))
time.sleep(0.2)
skipWelcomeScreenElement.click() #Explore own
toggleNavButtonElement = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@data-test-subj="toggleNavButton"]')))
time.sleep(0.2)
toggleNavButtonElement.click() #Navbar
fleetElement = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//span[@title="Fleet"]')))
time.sleep(0.2)
fleetElement.click() #Fleet
fleetSettingsTabElement = WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.XPATH, '//*[@data-test-subj="fleet-settings-tab"]')))
time.sleep(0.2)
fleetSettingsTabElement.click() #Settings
editOutputBtnElement = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@data-test-subj="editOutputBtn"]')))
time.sleep(0.2)
editOutputBtnElement.click() #edit icon
specifyHostURLElement = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//input[@placeholder="Specify host URL"]')))
time.sleep(0.2)
specifyHostURLElement.clear() #Hosts
time.sleep(1)
specifyHostURLElement.send_keys(f"https://{IP_ADDR}:9200") #Hosts
SSL_FINGERPRINT = subprocess.getoutput('cat SSL_FINGERPRINT')
SSL_KEY= f"""ssl:
certificate authorities:
- |
{SSL_FINGERPRINT}
"""
time.sleep(5)
yamlElement = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//*[@aria-label="YAML Code Editor"]')))
time.sleep(0.2)
yamlElement.send_keys(SSL_KEY) #YAML
saveApplySettingsElement = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//*[@data-test-subj="saveApplySettingsBtn"]')))
time.sleep(0.2)
saveApplySettingsElement.click() #save
confirmModalElement = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//*[@data-test-subj="confirmModalConfirmButton"]')))
time.sleep(0.2)
confirmModalElement.click() #confirm
addFleetServerHostBtn = WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.XPATH, '//*[@data-test-subj="settings.fleetServerHosts.addFleetServerHostBtn"]')))
time.sleep(0.2)
addFleetServerHostBtn.click() #Fleet
fleetServerSetupElement = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@data-test-subj="fleetServerSetup.nameInput"]')))
time.sleep(0.2)
fleetServerSetupElement.send_keys("Fleet Server") #fleet name
specifyHostURLElement = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//input[@placeholder="Specify host URL"]')))
time.sleep(0.2)
specifyHostURLElement.clear() #Hosts
time.sleep(1)
specifyHostURLElement.send_keys(f"https://{IP_ADDR}:8220") #fleet ip
generateFleetServerPolicyElement = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@data-test-subj="generateFleetServerPolicyButton"]')))
time.sleep(0.2)
generateFleetServerPolicyElement.click()
time.sleep(60)
euiFlyoutCloseElement = WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, '//*[@data-test-subj="euiFlyoutCloseButton"]')))
time.sleep(0.2)
euiFlyoutCloseElement.click()
fleetAgentsTabElement = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//*[@data-test-subj="fleet-agents-tab"]')))
time.sleep(0.2)
fleetAgentsTabElement.click()
fleetServerLandingElement = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//*[@data-test-subj="fleetServerLanding.addFleetServerButton"]')))
time.sleep(0.2)
fleetServerLandingElement.click()
generateFleetServerPolicyElement = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@data-test-subj="generateFleetServerPolicyButton"]')))
time.sleep(0.2)
generateFleetServerPolicyElement.click()
time.sleep(30)
FLEET = driver.find_element("css selector", "pre[class^='CommandCode']").text
time.sleep(5)
cmd = f'echo -n "{FLEET}" > fleet-install.sh'
os.system(cmd)
IP = os.environ["IP_ADDR"]
CD = os.environ["CURR_PATH"]
cmd = f'echo " --url=https://{IP}:8220 --fleet-server-es-ca=/usr/local/share/ca-certificates/http_ca.crt --certificate-authorities={CD}/ca/ca.crt --fleet-server-cert={CD}/fleet-server/fleet-server.crt --fleet-server-cert-key={CD}/fleet-server/fleet-server.key --force" >> fleet-install.sh'
os.system(cmd)
time.sleep(10)
driver.find_element("xpath", '//*[@data-test-subj="euiFlyoutCloseButton"]').click()
driver.close()