Skip to content

Commit bc941c6

Browse files
authored
Merge pull request certtools#2495 from certtools/2493-shadowserver-api-bot
Handle type parameter as a string and match by type instead of filena…
2 parents de4b093 + 5c4d101 commit bc941c6

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
### Bots
2121
#### Collectors
22+
- `intelmq.bots.collectors.shadowserver.collector_reports_api.py`:
23+
- Added support for the types parameter to be either a string or a list.
24+
- Refactored to utilize the type field returned by the API to match the requested types instead of a sub-string match on the filename.
2225
- `intelmq.bots.collectors.shodan.collector_stream` (PR#2492 by Mikk Margus Möll):
2326
- Add `alert` parameter to Shodan stream collector to allow fetching streams by configured alert ID
2427

intelmq/bots/collectors/shadowserver/collector_reports_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def init(self):
5959
self._report_list = self.reports.split(',')
6060
elif isinstance(self.reports, list):
6161
self._report_list = self.reports
62-
62+
if isinstance(self.types, str):
63+
self.types = self.types.split(',')
6364
if self.country and self.country not in self._report_list:
6465
self.logger.warn("Deprecated parameter 'country' found. Please use 'reports' instead. The backwards-compatibility will be removed in IntelMQ version 4.0.0.")
6566
self._report_list.append(self.country)
@@ -110,8 +111,7 @@ def _reports_list(self, date=None):
110111
return None
111112

112113
if self.types:
113-
reports = [report for report in reports if any(rtype in report['file'] for rtype in self.types)]
114-
114+
reports = [report for report in reports if any(report['type'] == rtype for rtype in self.types)]
115115
return reports
116116

117117
def _report_download(self, reportid: str):

intelmq/tests/bots/collectors/shadowserver/reports-list.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,36 @@
22
{
33
"report": "[email protected]",
44
"file": "2020-08-02-scan_smb-anarres-geo.csv",
5+
"type": "scan_smb",
56
"id": "xNDSuwXrKnrLrDopU926rR75CAESMWesVCKsuyI8b8ncTv7GCX",
67
"timestamp": "2020-08-02"
78
},
89
{
910
"report": "[email protected]",
1011
"id": "unnzVtn92tS9459rKIEz2J8qb7oJDv0Fa2feGUOiJLCDLqBXnN",
1112
"file": "2020-08-02-cisco_smart_install-anarres-geo.csv",
13+
"type": "cisco_smart_install",
1214
"timestamp": "2020-08-02"
1315
},
1416
{
1517
"timestamp": "2020-08-02",
1618
"id": "EhngMTvBT7tD4ehUpVJNqW8TRZRI9N6ozsarxuick4ritIIxOG",
1719
"file": "2020-08-02-scan_adb-anarres-geo.csv",
20+
"type": "scan_adb",
1821
"report": "[email protected]"
1922
},
2023
{
2124
"id": "GYb7n9SbR5jM2PMsfvo78r3G7tYF4v37koXEB8Kngs3ewCvHF4",
2225
"file": "2020-08-02-scan_rsync-anarres-geo.csv",
26+
"type": "scan_rsync",
2327
"report": "[email protected]",
2428
"timestamp": "2020-08-02"
2529
},
2630
{
2731
"timestamp": "2020-08-02",
2832
"report": "[email protected]",
2933
"file": "2020-08-02-scan_ldap_tcp-anarres-geo.csv",
34+
"type": "scan_ldap_tcp",
3035
"id": "qxe9EGItMY7eyDQwPBwGgEP2VOpvZqnqSDRIJGkXy3UWVUC06B"
3136
}
3237
]

0 commit comments

Comments
 (0)