Skip to content
This repository was archived by the owner on May 27, 2024. It is now read-only.

Commit 1070e49

Browse files
committed
Merge branch 'master' into certat
Conflicts: docs/Harmonization-fields.md
2 parents a38d592 + a04d154 commit 1070e49

File tree

16 files changed

+209
-40
lines changed

16 files changed

+209
-40
lines changed

docs/Data-Harmonization.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
## Table of Contents
22

33
1. [Overview](#overview)
4-
2. [Sections](#sections)
5-
2. [Data types](#basicdatatypes)
6-
3. [List of known fields](#fields)
7-
4. [Type/Taxonomy Mapping](#mapping)
8-
5. [Minimum required fields](#requirements)
4+
2. [Rules for keys](#rules)
5+
3. [Sections](#sections)
6+
4. [Data types](#basicdatatypes)
7+
5. [List of known fields](#fields)
8+
6. [Type/Taxonomy Mapping](#mapping)
9+
7. [Minimum required fields](#requirements)
910

1011

1112
<a name="overview"></a>
@@ -19,6 +20,7 @@ Every event **MUST** contain a timestamp field.
1920

2021
[IOC](https://en.wikipedia.org/wiki/Indicator_of_compromise) (Indicator of compromise) is a single observation like a log line.
2122

23+
<a name="rules"></a>
2224

2325
## Rules for keys
2426

docs/Developers-Guide.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ Most existing bots are only tested with one message. For newly written test it i
324324
# -*- coding: utf-8 -*-
325325
from __future__ import unicode_literals
326326

327-
import json
328327
import unittest
329328

330329
import intelmq.lib.test as test

docs/Harmonization-fields.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ Sanitation accepts string 'true' and 'false' and integers 0 and 1.
108108

109109
### FQDN
110110

111+
Fully qualified domain name type.
112+
113+
All valid domains are accepted, no IP addresses or URLs. Trailing dot is
114+
not allowed.
115+
111116

112117

113118
### Float

docs/User-Guide.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ useradd -d /opt/intelmq -U -s /bin/bash intelmq
115115
echo 'export PATH="$PATH:$HOME/bin"' > /opt/intelmq/.profile
116116
chmod -R 0770 /opt/intelmq
117117
chown -R intelmq.intelmq /opt/intelmq
118+
echo 'export INTELMQ_PYTHON=/usr/bin/python3.4' >> /opt/intelmq/.profile
118119
```
119120

120121
<a name="install-python27"></a>
@@ -212,6 +213,13 @@ logged to /opt/intelmq/var/log/intelmqctl
212213
The botnet represents all currently configured bots. To get an overview which
213214
bots are running, use `intelmqctl -n status`.
214215
216+
### Start bots with non-default Python
217+
218+
The python version/path can be specified by the `INTELMQ_PYTHON` environment variable. By default it's the default python binary. This can be used to start the bots with current Python (version 3), while the default Python version for the operating system is still Legacy Python (version 2).
219+
220+
$ export INTELMQ_PYTHON=/usr/bin/python3.4
221+
$ intelmqctl -n start
222+
215223
## Utilities
216224

217225
### Inspecting dumped messages

intelmq/bin/intelmqctl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ERROR_MESSAGES = {
4646
'running': '{} is still running.',
4747
'stopped': '{} was NOT RUNNING.',
4848
'stopping': '{} failed to STOP.',
49-
'noid': 'No bot ID was given, use --bot-id',
49+
'noid': 'No or unconfigured ID was given, use --bot-id',
5050
'notfound': '{} not found.'
5151
}
5252

@@ -305,7 +305,14 @@ class IntelMQContoller():
305305
return self.bot_status(bot_id)
306306

307307
def __bot_start(self, bot_id, module):
308-
cmd = "python -m {} {}".format(module, bot_id)
308+
"""
309+
Start a bot by calling it as module.
310+
311+
The python version/path can be specified by the INTELMQ_PYTHON
312+
environment variable. By default it's the default python binary.
313+
"""
314+
cmd = "{} -m {} {}".format(os.getenv('INTELMQ_PYTHON', 'python'),
315+
module, bot_id)
309316
pid = start_process(bot_id, cmd)
310317
write_pidfile(bot_id, pid)
311318

intelmq/bin/intelmqdump

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import intelmq.lib.message as message
1717
import intelmq.lib.pipeline as pipeline
1818
import intelmq.lib.utils as utils
1919
from intelmq import DEFAULT_LOGGING_PATH, DEFAULTS_CONF_FILE, RUNTIME_CONF_FILE
20-
from termstyle import bold, inverted, red
20+
from termstyle import bold, green, inverted, red
2121

2222
if sys.version_info[0] == 2:
2323
input = raw_input
@@ -72,25 +72,28 @@ AVAILABLE_IDS = [key for key, value in ACTIONS.items() if value[1]]
7272

7373
def dump_info(fname):
7474
info = red('unknwon error')
75-
try:
76-
handle = io.open(fname, 'rt')
77-
except OSError as exc:
78-
info = red('unable to open file: {!s}'.format(exc))
75+
if not os.path.getsize(fname):
76+
info = 'empty file'
7977
else:
8078
try:
81-
content = json.load(handle)
82-
except ValueError as exc:
83-
info = red('unable to load JSON: {!s}'.format(exc))
79+
handle = io.open(fname, 'rt')
80+
except OSError as exc:
81+
info = red('unable to open file: {!s}'.format(exc))
8482
else:
8583
try:
86-
info = "{!s} dumps".format(len(content.keys()))
87-
except AttributeError as exc:
88-
info = red("unable to count dumps: {!s}".format(exc))
89-
finally:
90-
try:
91-
handle.close()
92-
except NameError:
93-
pass
84+
content = json.load(handle)
85+
except ValueError as exc:
86+
info = red('unable to load JSON: {!s}'.format(exc))
87+
else:
88+
try:
89+
info = "{!s} dumps".format(len(content.keys()))
90+
except AttributeError as exc:
91+
info = red("unable to count dumps: {!s}".format(exc))
92+
finally:
93+
try:
94+
handle.close()
95+
except NameError:
96+
pass
9497
return info
9598

9699

@@ -124,6 +127,9 @@ if __name__ == '__main__':
124127

125128
if args.botid is None:
126129
filenames = glob.glob(os.path.join(DEFAULT_LOGGING_PATH, '*.dump'))
130+
if not len(filenames):
131+
print(green('Nothing to recover from, no dump files found!'))
132+
exit(0)
127133
filenames = [(fname, fname[len(DEFAULT_LOGGING_PATH):-5])
128134
for fname in sorted(filenames)]
129135

intelmq/bots/experts/deduplicator/expert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from intelmq.lib.cache import Cache
88

99

10-
class DeduplicatorBot(Bot):
10+
class DeduplicatorExpertBot(Bot):
1111

1212
def init(self):
1313
self.cache = Cache(self.parameters.redis_cache_host,
@@ -42,5 +42,5 @@ def process(self):
4242

4343

4444
if __name__ == "__main__":
45-
bot = DeduplicatorBot(sys.argv[1])
45+
bot = DeduplicatorExpertBot(sys.argv[1])
4646
bot.start()

intelmq/lib/bot.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import datetime
88
import json
99
import re
10+
import sys
1011
import time
1112
import traceback
1213

@@ -33,10 +34,11 @@ def __init__(self, bot_id):
3334
self.logger = None
3435

3536
try:
36-
self.log_buffer.append(('debug',
37-
'{} initialized with id {}.'
37+
version_info = sys.version.splitlines()[0].strip()
38+
self.log_buffer.append(('info',
39+
'{} initialized with id {} and version {}.'
3840
''.format(self.__class__.__name__,
39-
bot_id)))
41+
bot_id, version_info)))
4042
self.check_bot_id(bot_id)
4143
self.bot_id = bot_id
4244

intelmq/lib/harmonization.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ def sanitize(value):
266266

267267

268268
class FQDN(GenericType):
269+
"""
270+
Fully qualified domain name type.
271+
272+
All valid domains are accepted, no IP addresses or URLs. Trailing dot is
273+
not allowed.
274+
"""
269275

270276
@staticmethod
271277
def is_valid(value, sanitize=False):
@@ -285,8 +291,15 @@ def is_valid(value, sanitize=False):
285291
if not len(value.split('.')) > 1:
286292
return False
287293

294+
if value[-1] == '.':
295+
return False
296+
288297
return True
289298

299+
@staticmethod
300+
def sanitize(value):
301+
return value.rstrip('.')
302+
290303
@staticmethod
291304
def to_ip(value):
292305
try:

intelmq/lib/message.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ class MessageFactory(object):
2525
serialize: object to JSON encoded object
2626
"""
2727

28+
@staticmethod
29+
def from_dict(message):
30+
"""
31+
Takes dictionary Message object, returns instance of correct class.
32+
33+
The class is determined by __type attribute.
34+
"""
35+
try:
36+
class_reference = getattr(intelmq.lib.message, message["__type"])
37+
except AttributeError:
38+
raise exceptions.InvalidArgument('__type',
39+
got=message["__type"],
40+
expected=list(harm_config.keys()),
41+
docs=HARMONIZATION_CONF_FILE)
42+
del message["__type"]
43+
return class_reference(message)
44+
2845
@staticmethod
2946
def unserialize(raw_message):
3047
"""

0 commit comments

Comments
 (0)