Skip to content

Commit b775fcd

Browse files
committed
ENH: upgrade: replace url2fqn by url expert
the url2fqn expert is deprecated and will be removed in version 4 remove the bot from the default runtime config add an upgrade function that replaces the bot in installations by the url expert and parameters so that the behavior will stay the same fixes #2430
1 parent ed79116 commit b775fcd

File tree

4 files changed

+60
-6
lines changed

4 files changed

+60
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
which provides certain common STOMP-bot-specific operations, factored out from
3333
`intelmq.bots.collectors.stomp.collector` and `intelmq.bots.outputs.stomp.output`
3434
(PR#2408 and PR#2414 by Jan Kaliszewski).
35+
- `intelmq.lib.upgrades`: Replace deprecated instances of `url2fqdn` experts by the new `url` expert in runtime configuration (PR#2432 by Sebastian Wagner).
3536

3637
### Development
3738
- Makefile: Add codespell and test commands (PR#2425 by Sebastian Wagner).

intelmq/etc/runtime.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ taxonomy-expert:
156156
parameters:
157157
destination_queues:
158158
_default:
159-
- url2fqdn-expert-queue
159+
- url-expert-queue
160160
run_mode: continuous
161-
url2fqdn-expert:
162-
bot_id: url2fqdn-expert
163-
description: url2fqdn is the bot responsible to parsing the fqdn from the url.
161+
url-expert:
162+
bot_id: url-expert
163+
description: Extract additional information for the URL
164164
enabled: true
165165
group: Expert
166166
groupname: experts
167-
module: intelmq.bots.experts.url2fqdn.expert
168-
name: URL2FQDN
167+
module: intelmq.bots.experts.url.expert
168+
name: url
169169
parameters:
170170
destination_queues:
171171
_default:

intelmq/lib/upgrades.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
'v310_feed_changes',
4040
'v310_shadowserver_feednames',
4141
'v320_update_turris_greylist_url',
42+
'v322_url_replacement',
4243
]
4344

4445

@@ -879,6 +880,24 @@ def v320_update_turris_greylist_url(configuration, harmonization, dry_run, **kwa
879880
return ' '.join(messages) if messages else None, configuration, harmonization
880881

881882

883+
def v322_url_replacement(configuration, harmonization, dry_run, **kwargs):
884+
"""
885+
Replace deprecated url2fqdn expert with url expert.
886+
"""
887+
changed = False
888+
for bot_id, bot in configuration.items():
889+
if bot_id == 'global':
890+
continue
891+
if bot["module"] == "intelmq.bots.experts.url2fqdn.expert":
892+
configuration[bot_id]["module"] = "intelmq.bots.experts.url.expert"
893+
if "parameters" not in configuration[bot_id]:
894+
configuration[bot_id]["parameters"] = {}
895+
# skip all fields except the fqdn field for backwards compatibility
896+
configuration[bot_id]["parameters"]["skip_fields"] = ["source.ip", "source.port", "source.urlpath", "source.account", "destination.ip", "destination.port", "destination.urlpath", "destination.account", "protocol.application", "protocol.transport"]
897+
changed = True
898+
return changed, configuration, harmonization
899+
900+
882901
UPGRADES = OrderedDict([
883902
((1, 0, 0, 'dev7'), (v100_dev7_modify_syntax,)),
884903
((1, 1, 0), (v110_shadowserver_feednames, v110_deprecations)),
@@ -905,6 +924,7 @@ def v320_update_turris_greylist_url(configuration, harmonization, dry_run, **kwa
905924
((3, 0, 2), ()),
906925
((3, 1, 0), (v310_feed_changes, v310_shadowserver_feednames)),
907926
((3, 2, 0), (v320_update_turris_greylist_url,)),
927+
((3, 2, 2), (v322_url_replacement, )),
908928
])
909929

910930
ALWAYS = (harmonization,)

intelmq/tests/lib/test_upgrades.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,29 @@
550550
"parameters": {}
551551
}
552552
}
553+
V322_URL2FQN_IN = {
554+
"global": {},
555+
"url2fqdn-expert": {
556+
"module": "intelmq.bots.experts.url2fqdn.expert",
557+
"parameters": {
558+
}
559+
},
560+
}
561+
V322_URL2FQN_IN_1 = {
562+
"global": {},
563+
"url2fqdn-expert": {
564+
"module": "intelmq.bots.experts.url2fqdn.expert",
565+
},
566+
}
567+
V322_URL2FQN_OUT = {
568+
"global": {},
569+
"url2fqdn-expert": {
570+
"module": "intelmq.bots.experts.url.expert",
571+
"parameters": {
572+
"skip_fields": ["source.ip", "source.port", "source.urlpath", "source.account", "destination.ip", "destination.port", "destination.urlpath", "destination.account", "protocol.application", "protocol.transport"]
573+
},
574+
},
575+
}
553576

554577

555578
def generate_function(function):
@@ -762,6 +785,16 @@ def test_v310_feed_changes(self):
762785
result[0])
763786
self.assertEqual(V310_FEED_CHANGES, result[1])
764787

788+
def test_v322_url_replacement(self):
789+
""" Test v322_url_replacement """
790+
result = upgrades.v322_url_replacement(V322_URL2FQN_IN, {}, False)
791+
self.assertTrue(result[0])
792+
self.assertEqual(V322_URL2FQN_OUT, result[1])
793+
794+
result = upgrades.v322_url_replacement(V322_URL2FQN_IN_1, {}, False)
795+
self.assertTrue(result[0])
796+
self.assertEqual(V322_URL2FQN_OUT, result[1])
797+
765798

766799
for name in upgrades.__all__:
767800
setattr(TestUpgradeLib, 'test_function_%s' % name,

0 commit comments

Comments
 (0)