Blame view

src/core/pyros_django/agent/AgentSST.py 17.7 KB
05316241   Alexis Koralewski   Adding AgentSST, ...
1
2
3
4
#!/usr/bin/env python3

from pathlib import Path
import subprocess
9cd82394   Alexis Koralewski   Add new option fo...
5
6
import sys, os, argparse

a04e004d   Alexis Koralewski   Fixing AgentCmd c...
7
from datetime import datetime, timezone, timedelta
05316241   Alexis Koralewski   Adding AgentSST, ...
8
9
10
11
12
13
14
##import utils.Logger as L
#import threading #, multiprocessing, os
import time

#from django.db import transaction
#from common.models import Command

0bcd6dd5   Etienne Pallier   renamed Agent met...
15
from Agent import Agent, build_agent, log, __extract_parameters
05316241   Alexis Koralewski   Adding AgentSST, ...
16
import socket
c86245ec   Alexis Koralewski   AgentSST not long...
17
from common.models import AgentCmd, AgentSurvey, Majordome
05316241   Alexis Koralewski   Adding AgentSST, ...
18

dd27c2bc   Alexis Koralewski   Updating agent co...
19
from src.core.pyros_django.obsconfig.obsconfig_class import OBSConfig
05316241   Alexis Koralewski   Adding AgentSST, ...
20
21

class AgentSST(Agent):
04b0b442   Alexis Koralewski   Changing computer...
22
    computer = "XCY1"
05316241   Alexis Koralewski   Adding AgentSST, ...
23
24
25
26
    _previous_dir = ""
    PROJECT_ROOT_PATH = ""
    VENV_PYTHON = ""
    subprocess_dict = {}
7fd15ce5   Alexis Koralewski   Adding test mode ...
27
    agent_in_mode_test = {}
9c844b4d   Alexis Koralewski   AgentSST change n...
28
    simulated_computer = None
05316241   Alexis Koralewski   Adding AgentSST, ...
29

baada9d5   Etienne Pallier   New PRIO CMD mana...
30
31
32
33
34
35
36
    _AGENT_SPECIFIC_COMMANDS = {
        # Format : “cmd_name” : (timeout, exec_mode)
        
        "do_stop_agent" : (10, Agent.EXEC_MODE.SEQUENTIAL),
        "do_restart_agent" : (20, Agent.EXEC_MODE.SEQUENTIAL),
        "do_start_agent" : (20, Agent.EXEC_MODE.SEQUENTIAL),
    }
0bcd6dd5   Etienne Pallier   renamed Agent met...
37
38
39
40

    _TEST_COMMANDS_LIST = [
        (True, "self get_mode", 200, "MODE = ATTENTIVE",  Agent.CMD_STATUS.CMD_EXECUTED),
        (True, "self set_mode ATTENTIVE", 200, "MODE = ATTENTIVE", Agent.CMD_STATUS.CMD_EXECUTED),
7fd15ce5   Alexis Koralewski   Adding test mode ...
41
    ]
05316241   Alexis Koralewski   Adding AgentSST, ...
42

30eeadc1   Etienne Pallier   cleanup
43
    # @Override
d6a94dfd   Alexis Koralewski   Updating AgentSST...
44
    def __init__(self, name:str=None, simulated_computer=None, agent=None):
05316241   Alexis Koralewski   Adding AgentSST, ...
45
        
dd27c2bc   Alexis Koralewski   Updating agent co...
46
        super().__init__()
05316241   Alexis Koralewski   Adding AgentSST, ...
47
48
49
        self.PROJECT_ROOT_PATH = os.environ["PROJECT_ROOT_PATH"]
        if name is None:
            name = self.__class__.__name__
6fa0909e   Alexis Koralewski   Add button to man...
50
            self.name = name
4a81e038   Alexis Koralewski   Add get_specifics...
51
        self.computer = socket.gethostname()    
d6a94dfd   Alexis Koralewski   Updating AgentSST...
52
53
        if simulated_computer != None:
            self.computer = simulated_computer
9c844b4d   Alexis Koralewski   AgentSST change n...
54
            self.simulated_computer = simulated_computer
d6a94dfd   Alexis Koralewski   Updating AgentSST...
55
56
57
58
59
60
61
62
63
64
        name_from_config = self.get_config().get_agent_sst_of_computer(self.computer)
        if name_from_config != None:
            name = name_from_config
            self.name = name
        if AgentSurvey.objects.filter(name=self.name).exists():
            self._agent_survey = AgentSurvey.objects.get(name=self.name)
        else:
            self._agent_survey = AgentSurvey.objects.create(
                name=self.name, 
                validity_duration=60, 
9c844b4d   Alexis Koralewski   AgentSST change n...
65
66
                mode=self.__get_mode(), 
                status=self.get_status(), 
d6a94dfd   Alexis Koralewski   Updating AgentSST...
67
68
                iteration=-1
            )
05316241   Alexis Koralewski   Adding AgentSST, ...
69
70
71
        WITH_DOCKER = False
        if os.environ.get("WITH_DOCKER"):
            WITH_DOCKER = True
99502363   Alexis Koralewski   add message when ...
72
            # if WITH_DOCKER socket.gethostname() bizarre 
05316241   Alexis Koralewski   Adding AgentSST, ...
73
74
75
76
77
78
79
80
81
82
83
84
85
86
        if WITH_DOCKER:
            VENV_ROOT = ""
            VENV = ""
            VENV_BIN = ""
        else:
            VENV_ROOT = "venv"
            VENV = "venv_py3_pyros"
            VENV_BIN = (
                self.PROJECT_ROOT_PATH
                + os.sep + VENV_ROOT
                + os.sep + VENV
                + os.sep + "bin"
                + os.sep
            )
dd27c2bc   Alexis Koralewski   Updating agent co...
87
        self.VENV_PYTHON = VENV_BIN + "python3"
9cd82394   Alexis Koralewski   Add new option fo...
88
89
90
91
        if agent:
            self.init_agent = agent
        else:
            self.init_agent = None
c86245ec   Alexis Koralewski   AgentSST not long...
92
        self._no_restart = False
4a81e038   Alexis Koralewski   Add get_specifics...
93
        #log.info(f"PC hostname is {self.computer}")
7fd15ce5   Alexis Koralewski   Adding test mode ...
94
    
30eeadc1   Etienne Pallier   cleanup
95
    # @Override
0bcd6dd5   Etienne Pallier   renamed Agent met...
96
    def _init(self):
4a81e038   Alexis Koralewski   Add get_specifics...
97
        log.info(f"PC hostname is {self.computer}")
9cd82394   Alexis Koralewski   Add new option fo...
98
99
100
101
        if self.init_agent is None:
            self.start_agents()
        else:
            self.start_agents(self.init_agent)
c86245ec   Alexis Koralewski   AgentSST not long...
102
103
        if self.TEST_MODE:
            self._no_restart = True
7fd15ce5   Alexis Koralewski   Adding test mode ...
104
        self.TEST_MODE = False
ea1ca112   Alexis Koralewski   Fixing agentSST s...
105
106
        time.sleep(10)
        self.set_delay(3)
a3d0b4b0   Alexis Koralewski   AgentSST : adapti...
107

4a81e038   Alexis Koralewski   Add get_specifics...
108
109
    def set_computer(self,computer):
        self.computer = computer
05316241   Alexis Koralewski   Adding AgentSST, ...
110
111
112
113
114
115
116
117
    def start_agents(self,agent_name=None):
        """
        Start all agents or one agent of obs_config

        Args:
            agent_name (_type_, optional): Specific agent name to start. Defaults to None.
        """
        obs_config = self.get_config()
7fd15ce5   Alexis Koralewski   Adding test mode ...
118
119
        test_mode = " -t"

05316241   Alexis Koralewski   Adding AgentSST, ...
120
121
        if agent_name:
            agent = agent_name
9d8855ba   Alexis Koralewski   Add three agentss...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
            if "AgentSST" not in agent:
                agents = obs_config.get_agents_per_computer(obs_config.unit_name).get(self.computer)
                if agent not in agents:
                    log.info(f"{agent} isn't associated to this computer : {self.computer}")
                    log.info(f"Agents associated to this computer : {agents}")
                    exit(1)
                # Start a specific agent of obs_config (restart)
                agent_informations = obs_config.get_agent_information(obs_config.unit_name,agent)
                protocol = agent_informations.get("protocol")
                if protocol:
                    protocol_folder_abs_path = os.path.join(self.PROJECT_ROOT_PATH, os.path.dirname(protocol))
                    
                    protocol_script_name = protocol.split("/")[-1]
                    if os.path.exists(protocol_folder_abs_path + os.sep + protocol_script_name):
                        cmd = self.VENV_PYTHON +" "+ protocol_folder_abs_path + os.sep + protocol_script_name
                        if not agent in self.agent_in_mode_test:
                            self.agent_in_mode_test[agent] = self.TEST_MODE
                        if self.agent_in_mode_test[agent]:
                            cmd += test_mode
9c844b4d   Alexis Koralewski   AgentSST change n...
141
142
                        if self.simulated_computer:
                            cmd += f" --computer {self.simulated_computer}"
9d8855ba   Alexis Koralewski   Add three agentss...
143
144
145
146
147
148
149
150
151
                        process = subprocess.Popen(f"{cmd}",shell=True)
                        process.poll()
                        if agent not in self.subprocess_dict:
                            self.subprocess_dict[agent] = {}
                        self.subprocess_dict[agent]["process"] = process
                        nb_try_restart = self.subprocess_dict[agent].get("nb_try_restart",0)
                        nb_try_restart += 1
                        self.subprocess_dict[agent]["nb_try_restart"] = nb_try_restart
                        log.info(f"Start agent {agent} with cmd {cmd}")
05316241   Alexis Koralewski   Adding AgentSST, ...
152
153

        else:
027eaa78   Alexis Koralewski   Fixing AgentSST i...
154
155
156
157
158
159
160
161
162
            agents = obs_config.get_agents_per_computer(obs_config.unit_name).get(self.computer)
            if agents is None:
                available_hostnames = obs_config.get_agents_per_computer(obs_config.unit_name).keys()
                log.info("Computer not found in obs config")
                log.info(f"Available hostnames {available_hostnames}. Current hostname is {self.computer}")
                exit(1)
            #self.change_dir(self.PROJECT_ROOT_PATH)
            else:
                log.info(f"Agents associated to this computer : {agents}")
05316241   Alexis Koralewski   Adding AgentSST, ...
163
164
            # Start every agent of obs_config (initial start)
            for agent in agents:
9d8855ba   Alexis Koralewski   Add three agentss...
165
166
                if "AgentSST" in agent:
                    continue
05316241   Alexis Koralewski   Adding AgentSST, ...
167
168
169
170
171
172
173
                agent_informations = obs_config.get_agent_information(obs_config.unit_name,agent)
                protocol = agent_informations.get("protocol")
                if protocol:
                    protocol_folder_abs_path = os.path.join(self.PROJECT_ROOT_PATH, os.path.dirname(protocol))
                    
                    protocol_script_name = protocol.split("/")[-1]
                    if os.path.exists(protocol_folder_abs_path + os.sep + protocol_script_name):
05316241   Alexis Koralewski   Adding AgentSST, ...
174
                        
7fd15ce5   Alexis Koralewski   Adding test mode ...
175
176
177
178
179
                        cmd = self.VENV_PYTHON +" "+ protocol_folder_abs_path + os.sep + protocol_script_name
                        if not agent in self.agent_in_mode_test:
                            self.agent_in_mode_test[agent] = self.TEST_MODE
                        if self.agent_in_mode_test[agent]:
                            cmd += test_mode
9c844b4d   Alexis Koralewski   AgentSST change n...
180
181
                        if self.simulated_computer:
                            cmd += f" --computer {self.simulated_computer}"
a04e004d   Alexis Koralewski   Fixing AgentCmd c...
182
183
                        # process = subprocess.Popen(f"{cmd}", shell=True, stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT)
                        process = subprocess.Popen(f"{cmd}", shell=True)
9bd7ac9e   Alexis Koralewski   Adding timeout co...
184
185
                        self.subprocess_dict[agent] = {}
                        self.subprocess_dict[agent]["process"] = process
3449489e   Alexis Koralewski   Fixing current_nb...
186
187
                        # Reset to zero nb_try when AgentSST start (launch all agents)
                        self.subprocess_dict[agent]["nb_try_restart"] = 0
05316241   Alexis Koralewski   Adding AgentSST, ...
188
189
                        log.info(f"Start agent {agent} with cmd {cmd}")

2918ab51   Alexis Koralewski   Adding do_start_a...
190
    def do_start_agent(self, agent_name:str):
05316241   Alexis Koralewski   Adding AgentSST, ...
191
192
193
194
195
196
197
        """
        Start a specific agent of obs_config (Restart)

        Args:
            agent_name (str): Name of agent to start
        """
        self.start_agents(agent_name)
3449489e   Alexis Koralewski   Fixing current_nb...
198
199
200
201
202
        nb_try_restart_agent = self.subprocess_dict[agent_name]["nb_try_restart"]
        agent_survey = AgentSurvey.objects.get(name=agent_name)
        agent_survey.current_nb_restart = nb_try_restart_agent
        
        agent_survey.save()
05316241   Alexis Koralewski   Adding AgentSST, ...
203

dd27c2bc   Alexis Koralewski   Updating agent co...
204

e848fbef   Alexis Koralewski   Change import of ...
205
    def do_stop_agent(self, agent:str)->None:
afbc5c95   Alexis Koralewski   Renaming AgentSST...
206
        # agent = args[0]
6fa0909e   Alexis Koralewski   Add button to man...
207
        if agent in self.subprocess_dict.keys() or agent == self.name:
9fa0958e   Alexis Koralewski   Adding do_restart...
208
209
            #cmd = self.send_cmd_to(agent,"do_exit")
            cmd = self.send_cmd_to(agent,"do_stop","asap")
e848fbef   Alexis Koralewski   Change import of ...
210
            print(cmd)
4ad8724b   Alexis Koralewski   Add view to see a...
211
            return f"Sent do_stop asap to {agent}"
dd27c2bc   Alexis Koralewski   Updating agent co...
212

9fa0958e   Alexis Koralewski   Adding do_restart...
213
    def do_restart_agent(self, agent:str, mode:str)->None:
afbc5c95   Alexis Koralewski   Renaming AgentSST...
214
        # agent = args[0]
9bd7ac9e   Alexis Koralewski   Adding timeout co...
215
        nb_try_restart_agent = self.subprocess_dict[agent]["nb_try_restart"]
c957b9e1   Alexis Koralewski   fixing restart of...
216
        if nb_try_restart_agent < AgentSurvey.objects.get(name=agent).nb_restart_max:
9fa0958e   Alexis Koralewski   Adding do_restart...
217
            if mode == "soft":
e9e49c7a   Alexis Koralewski   AgentSST fix rest...
218
                cmd = self.send_cmd_to(agent,"do_restart","asap")
9fa0958e   Alexis Koralewski   Adding do_restart...
219
            else:
e848fbef   Alexis Koralewski   Change import of ...
220
                self.do_stop_agent(agent)
9fa0958e   Alexis Koralewski   Adding do_restart...
221
                self.do_start_agent(agent)
9bd7ac9e   Alexis Koralewski   Adding timeout co...
222
223
224
        else:
            #sendmail
            pass
a3d0b4b0   Alexis Koralewski   AgentSST : adapti...
225
226
227
        agent_survey = AgentSurvey.objects.get(name=agent)
        agent_survey.current_nb_restart = nb_try_restart_agent
        agent_survey.save()
9bd7ac9e   Alexis Koralewski   Adding timeout co...
228

a04e004d   Alexis Koralewski   Fixing AgentCmd c...
229
230
231
232
233
234
        # if agent in self.subprocess_dict.keys():
        #     cmd.set_result(f"Agent {agent} restarted")
        #     cmd.set_as_processed()
        # else:
        #     cmd.set_result(f"Agent {agent} failed to restart")
        #     log.debug(f"Agent {agent} failed to restart")
dd27c2bc   Alexis Koralewski   Updating agent co...
235

a04e004d   Alexis Koralewski   Fixing AgentCmd c...
236
    def force_kill_agent(self, *args)->None:
d4ebe565   Alexis Koralewski   Adding pyros stop...
237
238
239
        if args:
            agent = args[0]
            if self.subprocess_dict.get(agent) is not None:
9bd7ac9e   Alexis Koralewski   Adding timeout co...
240
                process = self.subprocess_dict.get(agent).get("process")
d4ebe565   Alexis Koralewski   Adding pyros stop...
241
242
243
244
245
246
                # process.terminate()
                # process.wait()
                # Kill is better when using Popen(shell=True) because it will remove the created child process
                process.kill()
            else:
                return None
a04e004d   Alexis Koralewski   Fixing AgentCmd c...
247

0bcd6dd5   Etienne Pallier   renamed Agent met...
248
    def _do_things_before_exit(self,abort_cmd_sender):
a04e004d   Alexis Koralewski   Fixing AgentCmd c...
249
250
        kill_agent_commands = {}
        for agent in self.subprocess_dict.keys():
e848fbef   Alexis Koralewski   Change import of ...
251
            print(agent)
4d953583   Alexis Koralewski   fixing agentsst d...
252
            if AgentSurvey.objects.get(name=agent).status != "EXITING":
e848fbef   Alexis Koralewski   Change import of ...
253
254
255
                self.do_stop_agent(agent)
                cmd = AgentCmd.objects.filter(full_name="do_stop asap",recipient=agent).latest("s_deposit_time")
                #cmd = self.do_stop_agent(agent)    
4d953583   Alexis Koralewski   fixing agentsst d...
256
257
258
259
260
261
262
263
264
265
266
267
                kill_agent_commands[agent] = cmd
                agent_survey = AgentSurvey.objects.get(name=agent)
                # Reset counter before exiting
                agent_survey.current_nb_restart = 0
                agent_survey.save()                             
        for agent in kill_agent_commands.keys():
            cmd = kill_agent_commands[agent]
            while AgentCmd.objects.get(id=cmd.id).state != "CMD_EXECUTED":
                if self.subprocess_dict[agent].get("process").poll() != None:
                    cmd = AgentCmd.objects.get(id=cmd.id)
                    cmd.state = "CMD_EXECUTED"
                    cmd.save()
ea1ca112   Alexis Koralewski   Fixing agentSST s...
268
                time.sleep(0.5)
4d953583   Alexis Koralewski   fixing agentsst d...
269
270
271
272
273
        # wait 10 seconds in order to agents to exit themselves properly 
        # time.sleep(20)
        # for agent in self.subprocess_dict.keys():
        #     while self.subprocess_dict[agent].get("process").poll() is None:
        #         time.sleep(0.5)
65c091a2   Alexis Koralewski   Update variable n...
274
275
276
        # agent_survey = AgentSurvey.objects.get(name=self.name)
        # agent_survey.status = AgentSurvey.STATUS_EXIT
        # agent_survey.save()
547df0ef   Etienne Pallier   routine_process_b...
277
    def _routine_process_iter_end_body(self):
a04e004d   Alexis Koralewski   Fixing AgentCmd c...
278
        now_time = datetime.now(timezone.utc) 
027eaa78   Alexis Koralewski   Fixing AgentSST i...
279
        last_running_commands = AgentCmd.get_commands_sent_by_agent("AgentSST").filter(state="CMD_RUNNING",recipient__in=list(self.subprocess_dict.keys()))
a04e004d   Alexis Koralewski   Fixing AgentCmd c...
280
        for cmd in last_running_commands:
fd880010   Alexis Koralewski   Fixing error in A...
281
            last_running_cmd = cmd.full_name
a04e004d   Alexis Koralewski   Fixing AgentCmd c...
282
            if last_running_cmd == "KILL_AGENT" and cmd.is_expired():
fd880010   Alexis Koralewski   Fixing error in A...
283
                agent = cmd.args[0]
2918ab51   Alexis Koralewski   Adding do_start_a...
284
                self.force_kill_agent(agent)
a04e004d   Alexis Koralewski   Fixing AgentCmd c...
285

9cd82394   Alexis Koralewski   Add new option fo...
286
        # checking status of agent if they are timeout if in auto mode
c86245ec   Alexis Koralewski   AgentSST not long...
287
288
289
290
        try:
            soft_mode = Majordome.objects.last().soft_mode
        except Majordome.DoesNotExist:
            soft_mode = None
47a1e5b7   Alexis Koralewski   Fixing restarting...
291
        if (soft_mode is not None and soft_mode == "AUTO") and not self._no_restart:
c86245ec   Alexis Koralewski   AgentSST not long...
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
            for agent in self.subprocess_dict.keys():
                try:
                    agent_survey = AgentSurvey.objects.get(name=agent)
                except AgentSurvey.DoesNotExist:
                    # If there is no entry in AgentSurvey for this agent go to next iteration (it surely means that the agentSST launched this agent for the first time, and it didn't had enough time to create an entry in AgentSurvey)
                    continue
                
                validity_duration = agent_survey.validity_duration
                last_update_from_agent = agent_survey.updated
                validity_duration_timedelta = timedelta(seconds=validity_duration)
                timeout_datetime = last_update_from_agent + validity_duration_timedelta
                timeout_datetime = timeout_datetime.replace(tzinfo=timezone.utc)
                # if agent latest state is timeout, restart it
                if timeout_datetime < now_time:
                    if self.subprocess_dict[agent].get("process").poll() != None:
                        last_executed_start_agent_cmd =  AgentCmd.objects.filter(state="CMD_EXECUTED",full_name=f"do_start_agent {agent}",recipient=self.name).order_by("-s_deposit_time")
                        if last_executed_start_agent_cmd.exists():
                            cmd_outdated_datetime_start = datetime.utcnow() - timedelta(seconds=30)
                            cmd_outdated_datetime_end = datetime.utcnow() - timedelta(seconds=25)
                            cmd_outdated_datetime_start = cmd_outdated_datetime_start.replace(tzinfo=timezone.utc)
                            cmd_outdated_datetime_end = cmd_outdated_datetime_end.replace(tzinfo=timezone.utc)
                            # cmd outdated if deposit time was between 25 and 30 seconds ago from now
                            # if last start cmd for this agent was executed and this agent isn't currently running, ask again a start.
                            if cmd_outdated_datetime_start >= last_executed_start_agent_cmd.first().s_deposit_time and cmd_outdated_datetime_end >= last_executed_start_agent_cmd.first().s_deposit_time:
652d479b   Alexis Koralewski   Adding titles, c...
316
                                self.send_cmd_to(self.name,"do_start_agent", agent)
c86245ec   Alexis Koralewski   AgentSST not long...
317
318
319
320
321
322
                        else:
                            try:
                                # Check if do_start_agent cmd already asked by agentSST in previous iterations and not exectuted. If the query success (no exception raised), we don't send again a cmd
                                AgentCmd.get_pending_and_running_commands_for_agent(self.name).get(full_name=f"do_start_agent {agent}")
                            except:
                                self.send_cmd_to(self.name,"do_start_agent", agent)
027eaa78   Alexis Koralewski   Fixing AgentSST i...
323
                    else:
c86245ec   Alexis Koralewski   AgentSST not long...
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
                        last_executed_start_or_restart_agent_cmd =  AgentCmd.objects.filter(state="CMD_EXECUTED",full_name__in=(f"do_start_agent {agent}",f"do_restart_agent {agent}"),recipient=self.name).order_by("-s_deposit_time")
                        if last_executed_start_or_restart_agent_cmd.exists():
                            cmd_outdated_datetime_start = datetime.utcnow() - timedelta(seconds=30)
                            cmd_outdated_datetime_end = datetime.utcnow() - timedelta(seconds=25)
                            cmd_outdated_datetime_start = cmd_outdated_datetime_start.replace(tzinfo=timezone.utc)
                            cmd_outdated_datetime_end = cmd_outdated_datetime_end.replace(tzinfo=timezone.utc)
                            # cmd outdated if deposit time was between 25 and 30 seconds ago from now
                            # if last start or restart cmd for this agent was executed and this agent isn't currently running, ask again a restart.
                            if cmd_outdated_datetime_start >= last_executed_start_or_restart_agent_cmd.first().s_deposit_time and cmd_outdated_datetime_end >=  last_executed_start_or_restart_agent_cmd.first().s_deposit_time:
                                self.send_cmd_to(self.name,"do_restart_agent", agent)    
                        else:
                            try:
                                # Check if do_restart_agent cmd already asked by agentSST in previous iterations and not exectuted. If the query success (no exception raised), we don't send again a cmd
                                AgentCmd.get_pending_and_running_commands_for_agent(self.name).get(full_name=f"do_restart_agent {agent}")
                            except:
                                self.send_cmd_to(self.name,"do_restart_agent", agent)
027eaa78   Alexis Koralewski   Fixing AgentSST i...
340

a04e004d   Alexis Koralewski   Fixing AgentCmd c...
341
342
        log.info("Check status of process")
        for agent in self.subprocess_dict:
9bd7ac9e   Alexis Koralewski   Adding timeout co...
343
            proc = self.subprocess_dict.get(agent).get("process")
dd27c2bc   Alexis Koralewski   Updating agent co...
344
            log.info(f"{agent} poll result is {proc.poll()}")
a04e004d   Alexis Koralewski   Fixing AgentCmd c...
345
     
dd27c2bc   Alexis Koralewski   Updating agent co...
346

05316241   Alexis Koralewski   Adding AgentSST, ...
347
348

if __name__ == "__main__":
9cd82394   Alexis Koralewski   Add new option fo...
349
350
351
352
353
354
355
    parser = argparse.ArgumentParser(description='Start a agentSST.')
    parser.add_argument("--computer",dest="computer",help='Launch agent with simulated computer hostname',action="store")
    parser.add_argument("--agent",dest="agent",help='Launch an specific agent ',action="store")
    parser.add_argument("-t", action="store_true" )
    args = vars(parser.parse_args())
    agent = build_agent(AgentSST,param_constr=args)
    # agent = build_agent(AgentSST)
05316241   Alexis Koralewski   Adding AgentSST, ...
356
    agent.run()