-
Notifications
You must be signed in to change notification settings - Fork 2
/
perf_Imports.py
163 lines (116 loc) · 3.52 KB
/
perf_Imports.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
from selenium import webdriver
from config import CONFIG
import time
import paramiko
import os
from selenium.webdriver.chrome.options import Options
from login import login
if CONFIG.WEBDRIVER == "Chrome":
_chrome_options = Options()
_chrome_options.add_argument('--disable-infobars')
driver = webdriver.Chrome(chrome_options=_chrome_options)
elif CONFIG.WEBDRIVER == "Firefox":
driver = webdriver.Firefox()
else:
print('No valid Webdrive was provided. ')
driver.set_window_size(1440, 1200)
driver.implicitly_wait(CONFIG.waittime)
# sleep(2)
host = CONFIG.HOST
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(CONFIG.server, username=CONFIG.username)
sftp = ssh.open_sftp()
# use shell for running the script to make-object-set
channel = ssh.invoke_shell()
# define current working dir
cwd = os.getcwd()
def setup_memscrape():
# Copy all the files needed to setup an Investigations server
ftp_client = ssh.open_sftp()
# use 1 second performance collector
localfile = cwd + os.sep + "files" + os.sep + "tqmemscrape.sh"
remotepath = "/tmp/tqmemscrape.sh"
ftp_client.put(localfile, remotepath)
ftp_client.close()
ftp_client = ssh.open_sftp()
localfile = "./tqmemscrape.service"
remotepath = "/tmp/tqmemscrape.service"
ftp_client.put(localfile, remotepath)
ftp_client.close()
# Move the files to their appropriate location:
cmd = 'sudo cp /tmp/tqmemscrape.sh /root'
print (' ')
ssh.exec_command(cmd)
print (cmd)
print (' ')
cmd = 'sudo chmod +x /root/tqmemscrape.sh'
ssh.exec_command(cmd)
print (cmd)
print (' ')
cmd = 'sudo cp /tmp/tqmemscrape.service /etc/systemd/system'
ssh.exec_command(cmd)
print (cmd)
print (' ')
cmd = 'sudo chmod +x /etc/systemd/system/tqmemscrape.service'
ssh.exec_command(cmd)
print (cmd)
print (' ')
# Load the service file
cmd = 'sudo systemctl daemon-reload'
ssh.exec_command(cmd)
print (cmd)
print (' ')
cmd = 'sudo systemctl enable tqmemscrape.service'
ssh.exec_command(cmd)
print (cmd)
print (' ')
def clear_logs():
logfile = '/var/log/threatq-memory-%s.log' % CONFIG.hostname
cmd = r'sudo rm -rf %s' % logfile
channel.send(cmd + '\n')
buff = ''
resp = channel.recv(9999)
buff += resp
print(resp)
def strt_stp_service(runstop):
cmd = r'sudo systemctl %s tqmemscrape.service' % runstop
channel.send(cmd + '\n')
buff = ''
resp = channel.recv(9999)
buff += resp
print(resp)
def main():
# Login to server
login(host, driver, usr=CONFIG.USER[0], pssword=CONFIG.USER[1])
# Stop the running tqmemscrape service
strt_stp_service('stop')
# upload 1 second tqmemscrap.sh
setup_memscrape()
# Remove any existing log file
clear_logs()
# Start the tqmemscrape service
strt_stp_service('start')
# Allow the server to normalize the data for 60 seconds before running test
time.sleep(60)
comptime = 0
# Run Import tests
# comment out the test you want to run.
# import Signatures
import Indicators
# import Events_Relationships
# allow processes and memory to normalize
time.sleep(60)
# Stop the tqmemscrape service
strt_stp_service('stop')
# Collect performance data from server
# CSVcreate
print(comptime)
if __name__ == "__main__":
main()
driver.quit()
# Collect stats
import CSVcreate
sftp.close()
ssh.close()