Skip to content

Commit dea15b1

Browse files
committed
Added news entry and upgrade function
1 parent 62f944e commit dea15b1

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
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 severity varchar(10);
25+
```
2126

2227
### Configuration
2328

intelmq/lib/upgrades.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,18 @@ def v340_deprecations(configuration, harmonization, dry_run, **kwargs):
973973
message = f"Found discontinued Twitter collector bot: {', '.join(found_twitter_collector)}"
974974
return message or changed, configuration, harmonization
975975

976+
def v341_new_fields(configuration, harmonization, dry_run, **kwargs):
977+
changed = False
978+
if "severity" not in harmonization["event"]:
979+
harmonization["event"]["severity"] = {
980+
"description": "Severity of the event, based on the information from the source, and eventually modified by IntelMQ during processing. Meaning of the levels may differ based on the event source.",
981+
"length": 10,
982+
"regex": "^(critical|high|medium|low|info|undefined)$",
983+
"type": "LowercaseString",
984+
}
985+
changed = True
986+
return changed, configuration, harmonization
987+
976988

977989
UPGRADES = OrderedDict([
978990
((1, 0, 0, 'dev7'), (v100_dev7_modify_syntax,)),
@@ -1004,7 +1016,7 @@ def v340_deprecations(configuration, harmonization, dry_run, **kwargs):
10041016
((3, 3, 0), ()),
10051017
((3, 3, 1), ()),
10061018
((3, 4, 0), (v340_deprecations, )),
1007-
((3, 4, 1), ()),
1019+
((3, 4, 1), (v341_new_fields, )),
10081020
])
10091021

10101022
ALWAYS = (harmonization,)

intelmq/tests/bin/initdb.sql

Lines changed: 1 addition & 1 deletion
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");

intelmq/tests/lib/test_upgrades.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,13 @@ 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[1]["event"])
864+
self.assertIn("severity", result[1]["event"])
865+
859866

860867
for name in upgrades.__all__:
861868
setattr(TestUpgradeLib, 'test_function_%s' % name,

0 commit comments

Comments
 (0)