vdcloudcraft / fail2ban-geo-exporter

A Prometheus.io exporter that geotags your jailed IPs
MIT License
18 stars 7 forks source link

Crashes on "AddressNotFoundError #8

Closed Madic- closed 4 years ago

Madic- commented 4 years ago

The exporter crashes when it gets an ip address which is not in the database:

Jun 02 19:38:21 vps07 python3[34060]: 127.0.0.1 - - [02/Jun/2020 19:38:06] "GET /metrics HTTP/1.1" 500 59 Jun 02 19:38:21 vps07 python3[34060]: Traceback (most recent call last): Jun 02 19:38:21 vps07 python3[34060]: File "/usr/lib/python3.5/wsgiref/handlers.py", line 137, in run Jun 02 19:38:21 vps07 python3[34060]: self.result = application(self.environ, self.start_response) Jun 02 19:38:21 vps07 python3[34060]: File "/opt/fail2ban-geo-exporter/lib/python3.5/site-packages/prometheus_client/exposition.py", line 45, in prometheus_app Jun 02 19:38:21 vps07 python3[34060]: output = encoder(r) Jun 02 19:38:21 vps07 python3[34060]: File "/opt/fail2ban-geo-exporter/lib/python3.5/site-packages/prometheus_client/openmetrics/exposition.py", line 14, in generate_latest Jun 02 19:38:21 vps07 python3[34060]: for metric in registry.collect(): Jun 02 19:38:21 vps07 python3[34060]: File "/opt/fail2ban-geo-exporter/lib/python3.5/site-packages/prometheus_client/registry.py", line 75, in collect Jun 02 19:38:21 vps07 python3[34060]: for metric in collector.collect(): Jun 02 19:38:21 vps07 python3[34060]: File "/opt/fail2ban-geo-exporter/fail2ban-exporter.py", line 65, in collect Jun 02 19:38:21 vps07 python3[34060]: self.assign_location() Jun 02 19:38:21 vps07 python3[34060]: File "/opt/fail2ban-geo-exporter/fail2ban-exporter.py", line 61, in assign_location Jun 02 19:38:21 vps07 python3[34060]: entry.update(self.geo_provider.annotate(entry['ip'])) Jun 02 19:38:21 vps07 python3[34060]: File "/opt/fail2ban-geo-exporter/geoip_provider/maxminddb.py", line 10, in annotate Jun 02 19:38:21 vps07 python3[34060]: lookup = reader.city(ip) Jun 02 19:38:21 vps07 python3[34060]: File "/opt/fail2ban-geo-exporter/lib/python3.5/site-packages/geoip2/database.py", line 114, in city Jun 02 19:38:21 vps07 python3[34060]: return self._model_for(geoip2.models.City, 'City', ip_address) Jun 02 19:38:21 vps07 python3[34060]: File "/opt/fail2ban-geo-exporter/lib/python3.5/site-packages/geoip2/database.py", line 194, in _model_for Jun 02 19:38:21 vps07 python3[34060]: (record, prefix_len) = self._get(types, ip_address) Jun 02 19:38:21 vps07 python3[34060]: File "/opt/fail2ban-geo-exporter/lib/python3.5/site-packages/geoip2/database.py", line 190, in _get Jun 02 19:38:21 vps07 python3[34060]: "The address %s is not in the database." % ip_address) Jun 02 19:38:21 vps07 python3[34060]: geoip2.errors.AddressNotFoundError: The address 10.255.30.162 is not in the database.

vdcloudcraft commented 4 years ago

Yep, oversight on my part. I already have a fix in mind. I'll start working on it.

vdcloudcraft commented 4 years ago

Missing IPs are now caught. You can skip them or if you want to keep track of them, you can assign them default values. It's documented in the README under 'Configuration'