Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: lib/bot: fix behavior for unconfigured bots #2054

Merged
1 commit merged into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ CHANGELOG
They now reside in `intelmq.lib.processmanager` which also contains an interface definition the processmanager implementations must adhere to.
Both the processmanagers and the `intelmqctl` script were cleaned up a bit.
The `LogLevel` and `ReturnType` Enums were added to `intelmq.lib.datatypes`.
- `intelmq.lib.bot`:
- Enhance behaviour if an unconfigured bot is started (PR#2054 by Sebastian Wagner).

### Development

Expand Down
23 changes: 18 additions & 5 deletions intelmq/lib/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
from intelmq.lib.datatypes import *

__all__ = ['Bot', 'CollectorBot', 'ParserBot', 'OutputBot', 'ExpertBot']
ALLOWED_SYSTEM_PARAMETERS = {'enabled', 'run_mode', 'group', 'description', 'module', 'name'}
# The first two keys are only used by the IntelMQ Manager and can be ignored, the last just contains the runtime parameters and is handled separately
IGNORED_SYSTEM_PARAMETERS = {'groupname', 'bot_id', 'parameters'}


class Bot(object):
Expand All @@ -53,6 +56,8 @@ class Bot(object):
# Bot is capable of SIGHUP delaying
_sighup_delay: bool = True
# From the runtime configuration
enabled: bool = True
run_mode: str = "continuous"
description: Optional[str] = None
group: Optional[str] = None
module = None
Expand Down Expand Up @@ -758,16 +763,21 @@ def __load_runtime_configuration(self):

if self.__bot_id in config:
params = config[self.__bot_id]
self.run_mode = params.get('run_mode', 'continuous')
self.name = params.get('name')
self.description = params.get('description')
self.group = params.get('group')
self.module = params.get('module')
for key, value in params.items():
if key in ALLOWED_SYSTEM_PARAMETERS and value:
self.__log_configuration_parameter("system", key, value)
setattr(self, key, value)
elif key not in IGNORED_SYSTEM_PARAMETERS:
self.logger.warning('Ignoring disallowed system parameter %r.',
key)
for option, value in params.get('parameters', {}).items():
setattr(self, option, value)
self.__log_configuration_parameter("runtime", option, value)
if option.startswith('logging_'):
reinitialize_logging = True
else:
self.logger.warning('Bot ID %r not found in runtime configuration - could not load any parameters.',
self.__bot_id)

intelmq_environment = [elem for elem in os.environ if elem.startswith('INTELMQ_')]
for elem in intelmq_environment:
Expand All @@ -784,6 +794,9 @@ def __load_runtime_configuration(self):
setattr(self, option, value)
self.__log_configuration_parameter("environment", option, value)

if option.startswith('logging_'):
reinitialize_logging = True

if reinitialize_logging:
self.logger.handlers = [] # remove all existing handlers
self.__init_logger()
Expand Down