Skip to content

Commit 272ae20

Browse files
author
Sebastian Wagner
committed
Merge remote-tracking branch 'upstream/pr/1751' into develop
2 parents ebae301 + d3f8c10 commit 272ae20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+395
-384
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ CHANGELOG
1111
- New class `ClassificationTaxonomy` with fixed list of taxonomies and sanitiation
1212
- `intelmq.lib.bot`:
1313
- Handle `InvalidValue` exceptions upon message retrieval by dumping the message instead of repeating endlessly (#1765, PR#1766 by Filip Pokorný).
14+
- Rewrite of the parameter loading and handling, getting rid of the `parameters` member (PR#1729 by Birger Schacht).
1415
- `intelmq.lib.exceptions`:
1516
- `InvalidValue`: Add optional parameter `object` (PR#1766 by Filip Pokorný).
17+
- `intelmq.lib.utils`:
18+
- New function `list_all_bots` to list all available/installed bots as replacement for the BOTS file (#368, #552, #644, #757, #1069, #1750, PR#1751 by Sebastian Waldbauer).
1619

1720
### Development
1821

@@ -36,6 +39,8 @@ Update allowed classification fields to 2020-01-28 version (#1409, #1476). Old n
3639
- The type `vulnerable service` has been renamed to `vulnerable-system`.
3740

3841
### Bots
42+
- The parameters handling of numerous bots has been refactored (PR#1751, PR#1729, by Birger Schacht, Sebastian Wagner, Sebastian Waldbauer).
43+
3944
#### Collectors
4045
- Remove `intelmq.bots.collectors.xmpp`: one of the dependencies of the bot was deprecated and according to a short survey on the IntelMQ
4146
users mailinglist, the bot is not used by anyone. (https://lists.cert.at/pipermail/intelmq-users/2020-October/000177.html, PR#1761, closes #1614)

intelmq/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@
2828
HARMONIZATION_CONF_FILE = os.path.join(CONFIG_DIR, "harmonization.conf")
2929
PIPELINE_CONF_FILE = os.path.join(CONFIG_DIR, "pipeline.conf")
3030
RUNTIME_CONF_FILE = os.path.join(CONFIG_DIR, "runtime.conf")
31-
BOTS_FILE = os.path.join(CONFIG_DIR, "BOTS")
3231
STATE_FILE_PATH = path = os.path.abspath(os.path.join(VAR_STATE_PATH,
3332
'../state.json'))

intelmq/bin/intelmqctl.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import pkg_resources
2323
from termstyle import green
2424

25-
from intelmq import (BOTS_FILE, DEFAULT_LOGGING_LEVEL, DEFAULTS_CONF_FILE, # noqa: F401
25+
from intelmq import (DEFAULT_LOGGING_LEVEL, DEFAULTS_CONF_FILE, # noqa: F401
2626
HARMONIZATION_CONF_FILE, PIPELINE_CONF_FILE,
2727
RUNTIME_CONF_FILE, VAR_RUN_PATH, STATE_FILE_PATH,
2828
DEFAULT_LOGGING_PATH, __version_info__,
@@ -865,6 +865,8 @@ def __init__(self, interactive: bool = False, return_type: str = "python", quiet
865865
help='Only show the total '
866866
'number of messages in queues. '
867867
'Only valid for listing queues.')
868+
parser_list.add_argument('--configured', '-c', action='store_true',
869+
help='Only show configured bots')
868870
parser_list.set_defaults(func=self.list)
869871

870872
parser_clear = subparsers.add_parser('clear', help='Clear a queue')
@@ -1220,11 +1222,11 @@ def botnet_status(self, group=None):
12201222
retval = 1
12211223
return retval, botnet_status
12221224

1223-
def list(self, kind=None, non_zero=False, count=False):
1225+
def list(self, kind=None, non_zero=False, count=False, configured=False):
12241226
if kind == 'queues':
12251227
return self.list_queues(non_zero=non_zero, count=count)
12261228
elif kind == 'bots':
1227-
return self.list_bots(non_zero=non_zero)
1229+
return self.list_bots(non_zero=non_zero, configured=configured)
12281230
elif kind == 'queues-and-status':
12291231
q = self.list_queues()
12301232
b = self.botnet_status()
@@ -1243,25 +1245,29 @@ def write_updated_runtime_config(self, filename=RUNTIME_CONF_FILE):
12431245
self.abort('Can\'t update runtime configuration: Permission denied.')
12441246
return True
12451247

1246-
def list_bots(self, non_zero=False):
1248+
def list_bots(self, non_zero=False, configured=False):
12471249
"""
1248-
Lists all configured bots from runtime.conf with bot id and
1249-
description.
1250+
Lists all (configured) bots from runtime.conf or generated on demand
1251+
with bot id/module and description and parameters.
12501252
12511253
If description is not set, None is used instead.
12521254
"""
1253-
if RETURN_TYPE == 'text':
1254-
for bot_id in sorted(self.runtime_configuration.keys(), key=str.lower):
1255-
if non_zero and not self.runtime_configuration[bot_id].get('enabled'):
1256-
continue
1257-
if QUIET:
1258-
print(bot_id)
1259-
else:
1260-
print("Bot ID: {}\nDescription: {}"
1261-
"".format(bot_id, self.runtime_configuration[bot_id].get('description')))
1262-
return 0, [{'id': bot_id,
1263-
'description': self.runtime_configuration[bot_id].get('description')}
1264-
for bot_id in sorted(self.runtime_configuration.keys())]
1255+
if configured:
1256+
if RETURN_TYPE == 'text':
1257+
for bot_id in sorted(self.runtime_configuration.keys(), key=str.lower):
1258+
if non_zero and not self.runtime_configuration[bot_id].get('enabled'):
1259+
continue
1260+
if QUIET:
1261+
print(bot_id)
1262+
else:
1263+
print("Bot ID: {}\nDescription: {}"
1264+
"".format(bot_id, self.runtime_configuration[bot_id].get('description')))
1265+
return 0, [{'id': bot_id,
1266+
'description': self.runtime_configuration[bot_id].get('description')}
1267+
for bot_id in sorted(self.runtime_configuration.keys())]
1268+
else:
1269+
val = utils.list_all_bots()
1270+
return 0, val
12651271

12661272
def get_queues(self, with_internal_queues=False):
12671273
"""
@@ -1421,8 +1427,7 @@ def check(self, no_connections=False):
14211427

14221428
# loading files and syntax check
14231429
files = {DEFAULTS_CONF_FILE: None, PIPELINE_CONF_FILE: None,
1424-
RUNTIME_CONF_FILE: None, BOTS_FILE: None,
1425-
HARMONIZATION_CONF_FILE: None}
1430+
RUNTIME_CONF_FILE: None, HARMONIZATION_CONF_FILE: None}
14261431
check_logger.info('Reading configuration files.')
14271432
for filename in files:
14281433
try:
@@ -1555,7 +1560,7 @@ def check(self, no_connections=False):
15551560
if bot_check:
15561561
for log_line in bot_check:
15571562
getattr(check_logger, log_line[0])("Bot %r: %s" % (bot_id, log_line[1]))
1558-
for group in files[BOTS_FILE].values():
1563+
for group in utils.list_all_bots():
15591564
for bot_id, bot in group.items():
15601565
if subprocess.call(['which', bot['module']], stdout=subprocess.DEVNULL,
15611566
stderr=subprocess.DEVNULL):
@@ -1874,7 +1879,7 @@ def debug(self, sections=None):
18741879
variables = globals()
18751880
if RETURN_TYPE == 'text':
18761881
print('Paths:')
1877-
for path in ('BOTS_FILE', 'DEFAULTS_CONF_FILE',
1882+
for path in ('DEFAULTS_CONF_FILE',
18781883
'HARMONIZATION_CONF_FILE', 'PIPELINE_CONF_FILE',
18791884
'RUNTIME_CONF_FILE', 'VAR_RUN_PATH', 'STATE_FILE_PATH',
18801885
'DEFAULT_LOGGING_PATH', '__file__',

intelmq/bin/intelmqsetup.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
from termstyle import red
4646
from intelmq import (CONFIG_DIR, DEFAULT_LOGGING_PATH, ROOT_DIR, VAR_RUN_PATH,
47-
VAR_STATE_PATH, BOTS_FILE, STATE_FILE_PATH)
47+
VAR_STATE_PATH, STATE_FILE_PATH)
4848
from intelmq.bin.intelmqctl import IntelMQController
4949

5050

@@ -161,13 +161,6 @@ def intelmqsetup_core(ownership=True, state_file=STATE_FILE_PATH):
161161
if ownership:
162162
change_owner(destination_file, owner='intelmq', group='intelmq', log=log_ownership_change)
163163

164-
if Path(BOTS_FILE).is_symlink():
165-
print('Skip writing BOTS file as it is a link.')
166-
else:
167-
print('Writing BOTS file.')
168-
shutil.copy(pkg_resources.resource_filename('intelmq', 'bots/BOTS'),
169-
BOTS_FILE)
170-
171164
if ownership:
172165
print('Setting intelmq as owner for it\'s directories.')
173166
for obj in (CONFIG_DIR, DEFAULT_LOGGING_PATH, ROOT_DIR, VAR_RUN_PATH,

intelmq/bots/collectors/amqp/collector_amqp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class AMQPCollectorBot(AMQPTopicOutputBot, CollectorBot):
2020
Collect data from an AMQP Server and fetch either intelmq or any other messages. Requires the pika python library.
2121
Inheriting from AMQPTopicOutputBot for connect_server method
2222
"""
23-
exchange: bool = False
2423
connection_attempts: int = 3
2524
connection_heartbeat: int = 3600
2625
connection_host: str = "127.0.0.1" # TODO should be ipaddress

intelmq/bots/collectors/api/collector_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class APICollectorBot(CollectorBot):
2828
"""Collect data by exposing a HTTP API interface"""
2929
name: str = "API"
3030
port: int = 5000
31+
__collector_empty_process: bool = True
3132
provider: str = "APICollector"
32-
collector_empty_process: bool = True
33-
is_multithreadable: bool = False
33+
__is_multithreadable: bool = False
3434

3535
def init(self):
3636
if IOLoop is None:

intelmq/bots/collectors/github_api/collector_github_contents_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import re
1313

1414
from intelmq.lib.exceptions import InvalidArgument
15-
from intelmq.bots.collectors.github_api.collector_github_api import GithubAPICollectorBot
15+
from intelmq.bots.collectors.github_api._collector_github_api import GithubAPICollectorBot
1616

1717
try:
1818
import requests

intelmq/bots/collectors/http/collector_http_stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
class HTTPStreamCollectorBot(CollectorBot):
3131
"Open a streaming connection to the URL and process data per line"
32-
sighup_delay = False
32+
_sighup_delay: bool = False
3333
http_password: str = None
3434
http_url: str = "<insert url of feed>"
3535
http_username: str = None
File renamed without changes.

0 commit comments

Comments
 (0)