From 18a5fdacbaaacda02a65999de3a58958996c0801 Mon Sep 17 00:00:00 2001
From: "Nicholas St. Germain"
Date: Tue, 4 Dec 2018 21:17:33 -0600
Subject: [PATCH] fixed clean_check of server_ids, fixed under-indented radarr
get_movie, and added __repr__ for cleaner logging
---
README.md | 10 +++++-----
varken/dbmanager.py | 7 ++++---
varken/helpers.py | 5 +++--
varken/iniparser.py | 29 ++++++++++++++++++++++++-----
varken/ombi.py | 3 +++
varken/radarr.py | 7 +++++--
varken/sonarr.py | 3 +++
varken/tautulli.py | 3 +++
8 files changed, 50 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
index 9b8370d..f4967ee 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# Varken
Dutch for PIG. PIG is an Acronym for Plex/InfluxDB/Grafana
-Varken is a standalone command-line utility to aggregate data
+varken is a standalone command-line utility to aggregate data
from the Plex ecosystem into InfluxDB. Examples use Grafana for a
frontend
@@ -12,14 +12,14 @@ Requirements /w install links: [Grafana](http://docs.grafana.org/installation/),
## Quick Setup (Varken Alpha)
-1. Clone the repository `sudo git clone https://github.com/DirtyCajunRice/grafana-scripts.git /opt/Varken`
+1. Clone the repository `sudo git clone https://github.com/DirtyCajunRice/grafana-scripts.git /opt/varken`
1. Follow the systemd install instructions located in `varken.systemd`
1. Create venv in project `/usr/bin/python3 -m venv varken-venv`
-1. Install requirements `/opt/Varken/varken-venv/bin/python -m pip install -r requirements.txt`
+1. Install requirements `/opt/varken/varken-venv/bin/python -m pip install -r requirements.txt`
1. Make a copy of `varken.example.ini` to `varken.ini` in the `data` folder
- `cp /opt/Varken/data/varken.example.ini /opt/Varken/data/varken.ini`
+ `cp /opt/varken/data/varken.example.ini /opt/varken/data/varken.ini`
1. Make the appropriate changes to `varken.ini`
- ie.`nano /opt/Varken/data/varken.ini`
+ ie.`nano /opt/varken/data/varken.ini`
1. After completing the [getting started](http://docs.grafana.org/guides/getting_started/) portion of grafana, create your datasource for influxdb.
1. Install `grafana-cli plugins install grafana-worldmap-panel`
1. TODO:: Click the + on your menu and click import. Using the .json provided in this repo, paste it in and customize as you like.
diff --git a/varken/dbmanager.py b/varken/dbmanager.py
index 581cb0f..4eee803 100644
--- a/varken/dbmanager.py
+++ b/varken/dbmanager.py
@@ -2,7 +2,7 @@ import logging
from influxdb import InfluxDBClient
-logger = logging.getLogger('Varken')
+logger = logging.getLogger('varken')
class DBManager(object):
def __init__(self, server):
@@ -16,5 +16,6 @@ class DBManager(object):
self.influx.create_retention_policy('varken 30d/1h', '30d', '1', 'varken', False, '1h')
def write_points(self, data):
- logger.debug('Writing Data to InfluxDB {}'.format(data))
- self.influx.write_points(data)
+ d = data
+ logger.debug('Writing Data to InfluxDB {}'.format(d))
+ self.influx.write_points(d)
diff --git a/varken/helpers.py b/varken/helpers.py
index 6643fd1..8806f5b 100644
--- a/varken/helpers.py
+++ b/varken/helpers.py
@@ -4,13 +4,14 @@ import tarfile
import hashlib
import geoip2.database
import logging
-
+from functools import update_wrapper
from json.decoder import JSONDecodeError
from os.path import abspath, join
from requests.exceptions import InvalidSchema, SSLError
from urllib.request import urlretrieve
-logger = logging.getLogger('Varken')
+logger = logging.getLogger('varken')
+
def geoip_download():
tar_dbfile = abspath(join('.', 'data', 'GeoLite2-City.tar.gz'))
diff --git a/varken/iniparser.py b/varken/iniparser.py
index d234fd2..daadac0 100644
--- a/varken/iniparser.py
+++ b/varken/iniparser.py
@@ -32,14 +32,33 @@ class INIParser(object):
self.parse_opts()
- def enable_check(self, type=None):
- global_server_ids = self.config.get('global', type)
+ def enable_check(self, server_type=None):
+ t = server_type
+ global_server_ids = self.config.get('global', t)
if global_server_ids.lower() in ['false', 'no', '0']:
- logger.info('{} disabled.'.format(type.upper()))
+ logger.info('{} disabled.'.format(t.upper()))
return False
else:
- logger.info('{} : ({})'.format(type.upper(), global_server_ids))
- return global_server_ids
+ sids = self.clean_check(global_server_ids, t)
+ return sids
+
+ def clean_check(self, server_id_list, server_type=None):
+ t = server_type
+ sid_list = server_id_list
+ cleaned_list = sid_list.replace(' ', '').split(',')
+ valid_sids = []
+ for sid in cleaned_list:
+ try:
+ valid_sids.append(int(sid))
+ except ValueError:
+ logger.error("{} is not a valid server id number".format(sid))
+
+ if valid_sids:
+ logger.info('{} : {}'.format(t.upper(), valid_sids))
+ return valid_sids
+ else:
+ logger.error("No valid {}".format(t.upper()))
+ return False
def read_file(self):
file_path = join(self.data_folder, 'varken.ini')
diff --git a/varken/ombi.py b/varken/ombi.py
index 6c71fe0..6e0fc6e 100644
--- a/varken/ombi.py
+++ b/varken/ombi.py
@@ -14,6 +14,9 @@ class OmbiAPI(object):
self.session = Session()
self.session.headers = {'Apikey': self.server.api_key}
+ def __repr__(self):
+ return "".format(self.server.id)
+
def get_total_requests(self):
self.now = datetime.now(timezone.utc).astimezone().isoformat()
tv_endpoint = '/api/v1/Request/tv'
diff --git a/varken/radarr.py b/varken/radarr.py
index 2dddacb..62ad2bf 100644
--- a/varken/radarr.py
+++ b/varken/radarr.py
@@ -14,6 +14,9 @@ class RadarrAPI(object):
self.session = Session()
self.session.headers = {'X-Api-Key': self.server.api_key}
+ def __repr__(self):
+ return "".format(self.server.id)
+
def get_missing(self):
endpoint = '/api/movie'
self.now = datetime.now(timezone.utc).astimezone().isoformat()
@@ -29,8 +32,8 @@ class RadarrAPI(object):
movies = [Movie(**movie) for movie in get]
for movie in movies:
- if self.server.get_missing:
- if not movie.downloaded and movie.isAvailable:
+ if not movie.downloaded:
+ if movie.isAvailable:
ma = True
else:
ma = False
diff --git a/varken/sonarr.py b/varken/sonarr.py
index 81a4d38..335ea84 100644
--- a/varken/sonarr.py
+++ b/varken/sonarr.py
@@ -16,6 +16,9 @@ class SonarrAPI(object):
self.session.headers = {'X-Api-Key': self.server.api_key}
self.session.params = {'pageSize': 1000}
+ def __repr__(self):
+ return "".format(self.server.id)
+
def get_missing(self):
endpoint = '/api/calendar'
last_days = str(date.today() + timedelta(days=-self.server.missing_days))
diff --git a/varken/tautulli.py b/varken/tautulli.py
index e5779f5..b3f4be7 100644
--- a/varken/tautulli.py
+++ b/varken/tautulli.py
@@ -19,6 +19,9 @@ class TautulliAPI(object):
self.session.params['apikey'] = self.server.api_key
self.endpoint = '/api/v2'
+ def __repr__(self):
+ return "".format(self.server.id)
+
def get_activity(self):
self.now = datetime.now(timezone.utc).astimezone().isoformat()
params = {'cmd': 'get_activity'}