Skip to content

Commit

Permalink
ENH: ctl handle enabled flag
Browse files Browse the repository at this point in the history
fixes #704

Signed-off-by: Sebastian Wagner <[email protected]>
  • Loading branch information
sebix committed Nov 16, 2016
1 parent 8eba275 commit 06cde54
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions intelmq/bin/intelmqctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Parameters(object):
}

MESSAGES = {
'disabled': '{} is disabled.',
'starting': 'Starting {}...',
'running': '{} is running.',
'stopped': '{} is stopped.',
Expand Down Expand Up @@ -382,8 +383,12 @@ def bot_start(self, bot_id):
def bot_stop(self, bot_id):
pid = read_pidfile(bot_id)
if not pid:
log_bot_error('stopped', bot_id)
return 'stopped'
if self.runtime_configuration[bot_id].get('enabled', True):
log_bot_error('stopped', bot_id)
return 'stopped'
else:
log_bot_message('disabled', bot_id)
return 'disabled'
if not status_process(pid):
remove_pidfile(bot_id)
log_bot_error('stopped', bot_id)
Expand All @@ -402,8 +407,12 @@ def bot_stop(self, bot_id):
def bot_reload(self, bot_id):
pid = read_pidfile(bot_id)
if not pid:
log_bot_error('stopped', bot_id)
return 'stopped'
if self.runtime_configuration[bot_id].get('enabled', True):
log_bot_error('stopped', bot_id)
return 'stopped'
else:
log_bot_message('disabled', bot_id)
return 'disabled'
if not status_process(pid):
remove_pidfile(bot_id)
log_bot_error('stopped', bot_id)
Expand Down Expand Up @@ -432,14 +441,21 @@ def bot_status(self, bot_id):
log_bot_error('notfound', bot_id)
return 'error'

log_bot_message('stopped', bot_id)
return 'stopped'
if self.runtime_configuration[bot_id].get('enabled', True):
log_bot_message('stopped', bot_id)
return 'stopped'
else:
log_bot_message('disabled', bot_id)
return 'disabled'

def botnet_start(self):
botnet_status = {}
log_botnet_message('starting')
for bot_id in sorted(self.runtime_configuration.keys()):
botnet_status[bot_id] = self.bot_start(bot_id)
if self.runtime_configuration[bot_id].get('enabled', True):
botnet_status[bot_id] = self.bot_start(bot_id)
else:
log_bot_message('disabled', bot_id)
botnet_status[bot_id] = 'disabled'
log_botnet_message('running')
return botnet_status

Expand All @@ -460,17 +476,8 @@ def botnet_reload(self):
return botnet_status

def botnet_restart(self):
botnet_status = {}
log_botnet_message('stopping')
for bot_id in sorted(self.runtime_configuration.keys()):
botnet_status[bot_id] = tuple(self.bot_stop(bot_id))
time.sleep(3)
log_botnet_message('stopped')
log_botnet_message('starting')
for bot_id in sorted(self.runtime_configuration.keys()):
botnet_status[bot_id] += tuple(self.bot_start(bot_id))
log_botnet_message('running')
return botnet_status
self.botnet_stop()
return self.botnet_start()

def botnet_status(self):
botnet_status = {}
Expand Down

0 comments on commit 06cde54

Please sign in to comment.