Skip to content

Commit b3b1876

Browse files
authored
v1.7.6 (#165)
v1.7.6
2 parents 7b71a8a + c3b0a7a commit b3b1876

File tree

8 files changed

+61
-26
lines changed

8 files changed

+61
-26
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Change Log
22

3+
## [v1.7.6](https://github.com/Boerderij/Varken/tree/v1.7.6) (2020-01-01)
4+
[Full Changelog](https://github.com/Boerderij/Varken/compare/1.7.5...v1.7.6)
5+
6+
**Merged pull requests:**
7+
8+
- v1.7.6 Merge [\#163](https://github.com/Boerderij/Varken/pull/163) ([samwiseg0](https://github.com/samwiseg0))
9+
10+
**Fixed bugs:**
11+
12+
- \[BUG\] Geolite database download failing [\#164](https://github.com/Boerderij/Varken/issues/164)
13+
14+
**Notes:**
15+
- A MaxMind license key will be required in order to download the GeoLite2 DB. Please see the [wiki](https://wiki.cajun.pro/link/5#bkmrk-maxmind) for more details.
16+
317
## [v1.7.5](https://github.com/Boerderij/Varken/tree/v1.7.5) (2019-12-11)
418
[Full Changelog](https://github.com/Boerderij/Varken/compare/1.7.4...v1.7.5)
519

Varken.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def thread(job, **kwargs):
107107
at_time.do(thread, SONARR.get_calendar, query="Future").tag("sonarr-{}-get_future".format(server.id))
108108

109109
if CONFIG.tautulli_enabled:
110-
GEOIPHANDLER = GeoIPHandler(DATA_FOLDER)
110+
GEOIPHANDLER = GeoIPHandler(DATA_FOLDER, CONFIG.tautulli_servers[0].maxmind_license_key)
111111
schedule.every(12).to(24).hours.do(thread, GEOIPHANDLER.update)
112112
for server in CONFIG.tautulli_servers:
113113
TAUTULLI = TautulliAPI(server, DBMANAGER, GEOIPHANDLER)

data/varken.example.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ tautulli_server_ids = 1
66
ombi_server_ids = 1
77
sickchill_server_ids = false
88
unifi_server_ids = false
9+
maxmind_license_key = xxxxxxxxxxxxxxxx
910

1011
[influxdb]
1112
url = influxdb.domain.tld

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ services:
2929
- VRKN_GLOBAL_OMBI_SERVER_IDS=1
3030
- VRKN_GLOBAL_SICKCHILL_SERVER_IDS=false
3131
- VRKN_GLOBAL_UNIFI_SERVER_IDS=false
32+
- VRKN_GLOBAL_MAXMIND_LICENSE_KEY=xxxxxxxxxxxxxxxx
3233
- VRKN_INFLUXDB_URL=influxdb.domain.tld
3334
- VRKN_INFLUXDB_PORT=8086
3435
- VRKN_INFLUXDB_SSL=false

varken/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
VERSION = "1.7.5"
1+
VERSION = "1.7.6"
22
BRANCH = 'master'

varken/helpers.py

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from time import sleep
44
from logging import getLogger
55
from ipaddress import IPv4Address
6-
from urllib.error import HTTPError
6+
from urllib.error import HTTPError, URLError
77
from geoip2.database import Reader
88
from tarfile import open as taropen
99
from urllib3 import disable_warnings
@@ -18,24 +18,25 @@
1818

1919

2020
class GeoIPHandler(object):
21-
def __init__(self, data_folder):
21+
def __init__(self, data_folder, maxmind_license_key):
2222
self.data_folder = data_folder
23+
self.maxmind_license_key = maxmind_license_key
2324
self.dbfile = abspath(join(self.data_folder, 'GeoLite2-City.mmdb'))
2425
self.logger = getLogger()
2526
self.reader = None
2627
self.reader_manager(action='open')
2728

28-
self.logger.info('Opening persistent connection to GeoLite2 DB...')
29+
self.logger.info('Opening persistent connection to the MaxMind DB...')
2930

3031
def reader_manager(self, action=None):
3132
if action == 'open':
3233
try:
3334
self.reader = Reader(self.dbfile)
3435
except FileNotFoundError:
35-
self.logger.error("Could not find GeoLite2 DB! Downloading!")
36+
self.logger.error("Could not find MaxMind DB! Downloading!")
3637
result_status = self.download()
3738
if result_status:
38-
self.logger.error("Could not download GeoLite2 DB!!!, You may need to manually install it.")
39+
self.logger.error("Could not download MaxMind DB! You may need to manually install it.")
3940
exit(1)
4041
else:
4142
self.reader = Reader(self.dbfile)
@@ -53,54 +54,64 @@ def update(self):
5354

5455
try:
5556
dbdate = date.fromtimestamp(stat(self.dbfile).st_mtime)
56-
db_next_update = date.fromtimestamp(stat(self.dbfile).st_mtime) + timedelta(days=60)
57+
db_next_update = date.fromtimestamp(stat(self.dbfile).st_mtime) + timedelta(days=30)
5758

5859
except FileNotFoundError:
59-
self.logger.error("Could not find GeoLite2 DB as: %s", self.dbfile)
60+
self.logger.error("Could not find MaxMind DB as: %s", self.dbfile)
6061
self.download()
6162
dbdate = date.fromtimestamp(stat(self.dbfile).st_mtime)
62-
db_next_update = date.fromtimestamp(stat(self.dbfile).st_mtime) + timedelta(days=60)
63+
db_next_update = date.fromtimestamp(stat(self.dbfile).st_mtime) + timedelta(days=30)
6364

6465
if db_next_update < today:
65-
self.logger.info("Newer GeoLite2 DB available, Updating...")
66-
self.logger.debug("GeoLite2 DB date %s, DB updates after: %s, Today: %s",
66+
self.logger.info("Newer MaxMind DB available, Updating...")
67+
self.logger.debug("MaxMind DB date %s, DB updates after: %s, Today: %s",
6768
dbdate, db_next_update, today)
6869
self.reader_manager(action='close')
6970
self.download()
7071
self.reader_manager(action='open')
7172
else:
7273
db_days_update = db_next_update - today
73-
self.logger.debug("Geolite2 DB will update in %s days", abs(db_days_update.days))
74-
self.logger.debug("GeoLite2 DB date %s, DB updates after: %s, Today: %s",
74+
self.logger.debug("MaxMind DB will update in %s days", abs(db_days_update.days))
75+
self.logger.debug("MaxMind DB date %s, DB updates after: %s, Today: %s",
7576
dbdate, db_next_update, today)
7677

7778
def download(self):
7879
tar_dbfile = abspath(join(self.data_folder, 'GeoLite2-City.tar.gz'))
79-
url = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz'
80+
maxmind_url = ('https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City'
81+
f'&suffix=tar.gz&license_key={self.maxmind_license_key}')
8082
downloaded = False
8183

8284
retry_counter = 0
8385

8486
while not downloaded:
85-
self.logger.info('Downloading GeoLite2 from %s', url)
87+
self.logger.info('Downloading GeoLite2 DB from MaxMind...')
8688
try:
87-
urlretrieve(url, tar_dbfile)
89+
urlretrieve(maxmind_url, tar_dbfile)
8890
downloaded = True
91+
except URLError as e:
92+
self.logger.error("Problem downloading new MaxMind DB: %s", e)
93+
result_status = 1
94+
return result_status
8995
except HTTPError as e:
90-
self.logger.error("Problem downloading new GeoLite2 DB... Trying again. Error: %s", e)
91-
sleep(2)
92-
retry_counter = (retry_counter + 1)
96+
if e.code == 401:
97+
self.logger.error("Your MaxMind license key is incorect! Check your config: %s", e)
98+
result_status = 1
99+
return result_status
100+
else:
101+
self.logger.error("Problem downloading new MaxMind DB... Trying again: %s", e)
102+
sleep(2)
103+
retry_counter = (retry_counter + 1)
93104

94105
if retry_counter >= 3:
95-
self.logger.error("Retried downloading the new GeoLite2 DB 3 times and failed... Aborting!")
106+
self.logger.error("Retried downloading the new MaxMind DB 3 times and failed... Aborting!")
96107
result_status = 1
97108
return result_status
98109
try:
99110
remove(self.dbfile)
100111
except FileNotFoundError:
101-
self.logger.warning("Cannot remove GeoLite2 DB as it does not exist!")
112+
self.logger.warning("Cannot remove MaxMind DB as it does not exist!")
102113

103-
self.logger.debug("Opening GeoLite2 tar file : %s", tar_dbfile)
114+
self.logger.debug("Opening MaxMind tar file : %s", tar_dbfile)
104115

105116
tar = taropen(tar_dbfile, 'r:gz')
106117

@@ -113,9 +124,9 @@ def download(self):
113124
tar.close()
114125
try:
115126
remove(tar_dbfile)
116-
self.logger.debug('Removed the GeoLite2 DB TAR file.')
127+
self.logger.debug('Removed the MaxMind DB tar file.')
117128
except FileNotFoundError:
118-
self.logger.warning("Cannot remove GeoLite2 DB TAR file as it does not exist!")
129+
self.logger.warning("Cannot remove MaxMind DB TAR file as it does not exist!")
119130

120131

121132
def hashit(string):

varken/iniparser.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ def parse_opts(self, read_file=False):
207207
missing_days_run_seconds = int(env.get(
208208
f'VRKN_{envsection}_MISSING_DAYS_RUN_SECONDS',
209209
self.config.getint(section, 'missing_days_run_seconds')))
210+
210211
future_days_run_seconds = int(env.get(
211212
f'VRKN_{envsection}_FUTURE_DAYS_RUN_SECONDS',
212213
self.config.getint(section, 'future_days_run_seconds')))
@@ -234,12 +235,14 @@ def parse_opts(self, read_file=False):
234235

235236
get_stats = boolcheck(env.get(f'VRKN_{envsection}_GET_STATS',
236237
self.config.get(section, 'get_stats')))
238+
237239
get_activity = boolcheck(env.get(f'VRKN_{envsection}_GET_ACTIVITY',
238240
self.config.get(section, 'get_activity')))
239241

240242
get_activity_run_seconds = int(env.get(
241243
f'VRKN_{envsection}_GET_ACTIVITY_RUN_SECONDS',
242244
self.config.getint(section, 'get_activity_run_seconds')))
245+
243246
get_stats_run_seconds = int(env.get(
244247
f'VRKN_{envsection}_GET_STATS_RUN_SECONDS',
245248
self.config.getint(section, 'get_stats_run_seconds')))
@@ -251,11 +254,15 @@ def parse_opts(self, read_file=False):
251254
server_id)
252255
exit(1)
253256

257+
maxmind_license_key = env.get(f'VRKN_GLOBAL_MAXMIND_LICENSE_KEY',
258+
self.config.get('global', 'maxmind_license_key'))
259+
254260
server = TautulliServer(id=server_id, url=scheme + url, api_key=apikey,
255261
verify_ssl=verify_ssl, get_activity=get_activity,
256262
fallback_ip=fallback_ip, get_stats=get_stats,
257263
get_activity_run_seconds=get_activity_run_seconds,
258-
get_stats_run_seconds=get_stats_run_seconds)
264+
get_stats_run_seconds=get_stats_run_seconds,
265+
maxmind_license_key=maxmind_license_key)
259266

260267
if service == 'ombi':
261268
issue_status_counts = boolcheck(env.get(

varken/structures.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class TautulliServer(NamedTuple):
6767
id: int = None
6868
url: str = None
6969
verify_ssl: bool = None
70+
maxmind_license_key: str = None
7071

7172

7273
class SickChillServer(NamedTuple):

0 commit comments

Comments
 (0)