Skip to content

Commit d62540b

Browse files
committed
Tests, upgrade function, news
1 parent dca0f55 commit d62540b

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

Diff for: NEWS.md

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ Please refer to the change log for a full list of changes.
1818
### Tools
1919

2020
### Data Format
21+
To save new fields from IntelMQ Data Format in existing PostgreSQL instances, the following schema
22+
update is necessary:
23+
```sql
24+
ALTER TABLE events ADD "constituency" text;
25+
```
2126

2227
### Configuration
2328

Diff for: intelmq/lib/upgrades.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
'v320_update_turris_greylist_url',
4242
'v322_url_replacement',
4343
'v322_removed_feeds_and_bots',
44-
'v340_deprecations'
44+
'v340_deprecations',
45+
'v341_new_fields'
4546
]
4647

4748

@@ -974,6 +975,29 @@ def v340_deprecations(configuration, harmonization, dry_run, **kwargs):
974975
return message or changed, configuration, harmonization
975976

976977

978+
def v341_new_fields(configuration, harmonization, dry_run, **kwargs):
979+
"""
980+
Add new fields to IntelMQ Data Format
981+
"""
982+
changed = None
983+
if "event" not in harmonization:
984+
return changed, configuration, harmonization
985+
986+
builtin_harmonisation = load_configuration(
987+
resource_filename("intelmq", "etc/harmonization.conf")
988+
)
989+
for field in [
990+
"constituency",
991+
]:
992+
if field not in harmonization["event"]:
993+
if field not in builtin_harmonisation["event"]:
994+
# ensure forward-compatibility if we ever remove something from harmonisation
995+
continue
996+
harmonization["event"][field] = builtin_harmonisation["event"][field]
997+
changed = True
998+
return changed, configuration, harmonization
999+
1000+
9771001
UPGRADES = OrderedDict([
9781002
((1, 0, 0, 'dev7'), (v100_dev7_modify_syntax,)),
9791003
((1, 1, 0), (v110_shadowserver_feednames, v110_deprecations)),
@@ -1004,7 +1028,7 @@ def v340_deprecations(configuration, harmonization, dry_run, **kwargs):
10041028
((3, 3, 0), ()),
10051029
((3, 3, 1), ()),
10061030
((3, 4, 0), (v340_deprecations, )),
1007-
((3, 4, 1), ()),
1031+
((3, 4, 1), (v341_new_fields, )),
10081032
])
10091033

10101034
ALWAYS = (harmonization,)

Diff for: intelmq/tests/bin/initdb.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ CREATE INDEX "idx_events_source.asn" ON events USING btree ("source.asn");
9494
CREATE INDEX "idx_events_source.ip" ON events USING btree ("source.ip");
9595
CREATE INDEX "idx_events_source.fqdn" ON events USING btree ("source.fqdn");
9696
CREATE INDEX "idx_events_time.observation" ON events USING btree ("time.observation");
97-
CREATE INDEX "idx_events_time.source" ON events USING btree ("time.source");
97+
CREATE INDEX "idx_events_time.source" ON events USING btree ("time.source");

Diff for: intelmq/tests/lib/test_upgrades.py

+6
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,12 @@ def test_v340_twitter_collector(self):
856856
self.assertIn('twitter-collector', result[0])
857857
self.assertEqual(V340_TWITTER_COLLECTOR_IN, result[1])
858858

859+
def test_v341_new_fields(self):
860+
""" Test adding new harmonisation fields """
861+
result = upgrades.v341_new_fields({}, {"event": {"old-field": "must stay"}}, False)
862+
self.assertTrue(result[0])
863+
self.assertIn("old-field", result[2]["event"])
864+
self.assertIn("constituency", result[2]["event"])
859865

860866
for name in upgrades.__all__:
861867
setattr(TestUpgradeLib, 'test_function_%s' % name,

0 commit comments

Comments
 (0)