Skip to content

Commit

Permalink
v1.6.1 Merge
Browse files Browse the repository at this point in the history
v1.6.1 Merge
  • Loading branch information
dirtycajunrice authored Jan 12, 2019
2 parents c9da4dc + 5985d90 commit 6fe6a84
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 163 deletions.
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Change Log

## [v1.6.1](https://github.com/Boerderij/Varken/tree/v1.6.1) (2019-01-11)
[Full Changelog](https://github.com/Boerderij/Varken/compare/v1.6...v1.6.1)

**Implemented enhancements:**

- \[Feature Request\] Unifi Integration [\#79](https://github.com/Boerderij/Varken/issues/79)

**Fixed bugs:**

- \[BUG\] Unexpected keyword argument 'langCode' while creating OmbiMovieRequest structure [\#88](https://github.com/Boerderij/Varken/issues/88)

**Closed issues:**

- Remove Cisco ASA since Telegraf + SNMP can do the same [\#86](https://github.com/Boerderij/Varken/issues/86)

**Merged pull requests:**

- v1.6 Merge [\#90](https://github.com/Boerderij/Varken/pull/85) ([DirtyCajunRice](https://github.com/DirtyCajunRice))

## [v1.6](https://github.com/Boerderij/Varken/tree/v1.6) (2019-01-04)
[Full Changelog](https://github.com/Boerderij/Varken/compare/v1.5...v1.6)

Expand All @@ -15,7 +34,7 @@

**Merged pull requests:**

- v1.6 Merge [\#75](https://github.com/Boerderij/Varken/pull/85) ([DirtyCajunRice](https://github.com/DirtyCajunRice))
- v1.6 Merge [\#85](https://github.com/Boerderij/Varken/pull/85) ([DirtyCajunRice](https://github.com/DirtyCajunRice))

## [v1.5](https://github.com/Boerderij/Varken/tree/v1.5) (2018-12-30)
[Full Changelog](https://github.com/Boerderij/Varken/compare/v1.4...v1.5)
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM lsiobase/alpine.python3

LABEL maintainer="dirtycajunrice"
LABEL maintainers="dirtycajunrice,samwiseg0"

ENV DEBUG="False"

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[![Docker-Layers](https://images.microbadger.com/badges/image/boerderij/varken.svg)](https://microbadger.com/images/boerderij/varken)
[![Docker-Version](https://images.microbadger.com/badges/version/boerderij/varken.svg)](https://microbadger.com/images/boerderij/varken)
[![Docker Pulls](https://img.shields.io/docker/pulls/boerderij/varken.svg)](https://hub.docker.com/r/boerderij/varken/)
[![Docker Stars](https://img.shields.io/docker/stars/boerderij/varken.svg)](https://hub.docker.com/r/boerderij/varken/)

Dutch for PIG. PIG is an Acronym for Plex/InfluxDB/Grafana

Expand All @@ -30,7 +29,7 @@ Supported Modules:
* [Radarr](https://radarr.video/) - A fork of Sonarr to work with movies à la Couchpotato.
* [Tautulli](https://tautulli.com/) - A Python based monitoring and tracking tool for Plex Media Server.
* [Ombi](https://ombi.io/) - Want a Movie or TV Show on Plex or Emby? Use Ombi!
* Cisco ASA
* [Unifi](https://unifi-sdn.ubnt.com/) - The Global Leader in Managed Wi-Fi Systems

Key features:
* Multiple server support for all modules
Expand Down
71 changes: 47 additions & 24 deletions Varken.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import platform
import schedule

from time import sleep
from queue import Queue
from sys import version
from threading import Thread
from os import access, R_OK, getenv
Expand All @@ -10,8 +10,9 @@
from argparse import ArgumentParser, RawTextHelpFormatter
from logging import getLogger, StreamHandler, Formatter, DEBUG

from varken import structures # Needed to check version of python
from varken.ombi import OmbiAPI
from varken.cisco import CiscoAPI
from varken.unifi import UniFiAPI
from varken import VERSION, BRANCH
from varken.sonarr import SonarrAPI
from varken.radarr import RadarrAPI
Expand All @@ -26,9 +27,14 @@
PLATFORM_LINUX_DISTRO = ' '.join(x for x in linux_distribution() if x)


def threaded(job):
thread = Thread(target=job)
thread.start()
def thread():
while schedule.jobs:
job = QUEUE.get()
a = job()
print(a)
if a is not None:
schedule.clear(a)
QUEUE.task_done()


if __name__ == "__main__":
Expand Down Expand Up @@ -85,64 +91,81 @@ def threaded(job):

CONFIG = INIParser(DATA_FOLDER)
DBMANAGER = DBManager(CONFIG.influx_server)
QUEUE = Queue()

if CONFIG.sonarr_enabled:
for server in CONFIG.sonarr_servers:
SONARR = SonarrAPI(server, DBMANAGER)
if server.queue:
schedule.every(server.queue_run_seconds).seconds.do(threaded, SONARR.get_queue)
at_time = schedule.every(server.queue_run_seconds).seconds
at_time.do(QUEUE.put, SONARR.get_queue).tag(f"sonarr-{server.id}-get_queue")
if server.missing_days > 0:
schedule.every(server.missing_days_run_seconds).seconds.do(threaded, SONARR.get_missing)
at_time = schedule.every(server.missing_days_run_seconds).seconds
at_time.do(QUEUE.put, SONARR.get_missing).tag(f"sonarr-{server.id}-get_missing")
if server.future_days > 0:
schedule.every(server.future_days_run_seconds).seconds.do(threaded, SONARR.get_future)
at_time = schedule.every(server.future_days_run_seconds).seconds
at_time.do(QUEUE.put, SONARR.get_future).tag(f"sonarr-{server.id}-get_future")

if CONFIG.tautulli_enabled:
GEOIPHANDLER = GeoIPHandler(DATA_FOLDER)
schedule.every(12).to(24).hours.do(threaded, GEOIPHANDLER.update)
schedule.every(12).to(24).hours.do(QUEUE.put, GEOIPHANDLER.update)
for server in CONFIG.tautulli_servers:
TAUTULLI = TautulliAPI(server, DBMANAGER, GEOIPHANDLER)
if server.get_activity:
schedule.every(server.get_activity_run_seconds).seconds.do(threaded, TAUTULLI.get_activity)
at_time = schedule.every(server.get_activity_run_seconds).seconds
at_time.do(QUEUE.put, TAUTULLI.get_activity).tag(f"tautulli-{server.id}-get_activity")
if server.get_stats:
schedule.every(server.get_stats_run_seconds).seconds.do(threaded, TAUTULLI.get_stats)
at_time = schedule.every(server.get_stats_run_seconds).seconds
at_time.do(QUEUE.put, TAUTULLI.get_stats).tag(f"tautulli-{server.id}-get_stats")

if CONFIG.radarr_enabled:
for server in CONFIG.radarr_servers:
RADARR = RadarrAPI(server, DBMANAGER)
if server.get_missing:
schedule.every(server.get_missing_run_seconds).seconds.do(threaded, RADARR.get_missing)
at_time = schedule.every(server.get_missing_run_seconds).seconds
at_time.do(QUEUE.put, RADARR.get_missing).tag(f"radarr-{server.id}-get_missing")
if server.queue:
schedule.every(server.queue_run_seconds).seconds.do(threaded, RADARR.get_queue)
at_time = schedule.every(server.queue_run_seconds).seconds
at_time.do(QUEUE.put, RADARR.get_queue).tag(f"radarr-{server.id}-get_queue")

if CONFIG.ombi_enabled:
for server in CONFIG.ombi_servers:
OMBI = OmbiAPI(server, DBMANAGER)
if server.request_type_counts:
schedule.every(server.request_type_run_seconds).seconds.do(threaded, OMBI.get_request_counts)
at_time = schedule.every(server.request_type_run_seconds).seconds
at_time.do(QUEUE.put, OMBI.get_request_counts).tag(f"ombi-{server.id}-get_request_counts")
if server.request_total_counts:
schedule.every(server.request_total_run_seconds).seconds.do(threaded, OMBI.get_all_requests)
at_time = schedule.every(server.request_total_run_seconds).seconds
at_time.do(QUEUE.put, OMBI.get_all_requests).tag(f"ombi-{server.id}-get_all_requests")
if server.issue_status_counts:
schedule.every(server.issue_status_run_seconds).seconds.do(threaded, OMBI.get_issue_counts)
at_time = schedule.every(server.issue_status_run_seconds).seconds
at_time.do(QUEUE.put, OMBI.get_issue_counts).tag(f"ombi-{server.id}-get_issue_counts")

if CONFIG.sickchill_enabled:
for server in CONFIG.sickchill_servers:
SICKCHILL = SickChillAPI(server, DBMANAGER)
if server.get_missing:
schedule.every(server.get_missing_run_seconds).seconds.do(threaded, SICKCHILL.get_missing)
at_time = schedule.every(server.get_missing_run_seconds).seconds
at_time.do(QUEUE.put, SICKCHILL.get_missing).tag(f"sickchill-{server.id}-get_missing")

if CONFIG.ciscoasa_enabled:
for firewall in CONFIG.ciscoasa_servers:
ASA = CiscoAPI(firewall, DBMANAGER)
schedule.every(firewall.get_bandwidth_run_seconds).seconds.do(threaded, ASA.get_bandwidth)
if CONFIG.unifi_enabled:
for server in CONFIG.unifi_servers:
UNIFI = UniFiAPI(server, DBMANAGER)
at_time = schedule.every(server.get_usg_stats_run_seconds).seconds
at_time.do(QUEUE.put, UNIFI.get_usg_stats).tag(f"unifi-{server.id}-get_usg_stats")

# Run all on startup
SERVICES_ENABLED = [CONFIG.ombi_enabled, CONFIG.radarr_enabled, CONFIG.tautulli_enabled,
CONFIG.sonarr_enabled, CONFIG.ciscoasa_enabled, CONFIG.sickchill_enabled]
SERVICES_ENABLED = [CONFIG.ombi_enabled, CONFIG.radarr_enabled, CONFIG.tautulli_enabled, CONFIG.unifi_enabled,
CONFIG.sonarr_enabled, CONFIG.sickchill_enabled]
if not [enabled for enabled in SERVICES_ENABLED if enabled]:
vl.logger.error("All services disabled. Exiting")
exit(1)

WORKER = Thread(target=thread)
WORKER.start()

schedule.run_all()

while True:
while schedule.jobs:
schedule.run_pending()
sleep(1)
17 changes: 10 additions & 7 deletions data/varken.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ sonarr_server_ids = 1,2
radarr_server_ids = 1,2
tautulli_server_ids = 1
ombi_server_ids = 1
ciscoasa_server_ids = false
sickchill_server_ids = false
unifi_server_ids = false

[influxdb]
url = influxdb.domain.tld
port = 8086
ssl = false
verify_ssl = false
username = root
password = root

Expand Down Expand Up @@ -87,11 +89,12 @@ verify_ssl = false
get_missing = true
get_missing_run_seconds = 300

[ciscoasa-1]
url = firewall.domain.tld
username = cisco
password = cisco
outside_interface = WAN
[unifi-1]
url = unifi.domain.tld:8443
username = ubnt
password = ubnt
site = default
usg_name = MyRouter
ssl = false
verify_ssl = false
get_bandwidth_run_seconds = 300
get_usg_stats_run_seconds = 300
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ services:
- GF_PATHS_DATA=/config/data
- GF_PATHS_LOGS=/config/logs
- GF_PATHS_PLUGINS=/config/plugins
- GF_PATHS_CONFIG=/config/grafana.ini
- GF_INSTALL_PLUGINS=grafana-piechart-panel,grafana-worldmap-panel
depends_on:
- influxdb
Expand Down
4 changes: 2 additions & 2 deletions varken/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION = 1.7
BRANCH = 'pre-nightly'
VERSION = "1.6.1"
BRANCH = 'master'
61 changes: 0 additions & 61 deletions varken/cisco.py

This file was deleted.

5 changes: 3 additions & 2 deletions varken/dbmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
class DBManager(object):
def __init__(self, server):
self.server = server
self.influx = InfluxDBClient(self.server.url, self.server.port, self.server.username, self.server.password,
'varken')
self.influx = InfluxDBClient(host=self.server.url, port=self.server.port, username=self.server.username,
password=self.server.password, ssl=self.server.ssl, database='varken',
verify_ssl=self.server.verify_ssl)
databases = [db['name'] for db in self.influx.get_list_database()]
self.logger = getLogger()

Expand Down
15 changes: 7 additions & 8 deletions varken/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from hashlib import md5
from datetime import date
from logging import getLogger
from ipaddress import IPv4Address
from calendar import monthcalendar
from geoip2.database import Reader
from tarfile import open as taropen
Expand All @@ -11,7 +12,6 @@
from os.path import abspath, join, basename, isdir
from urllib3.exceptions import InsecureRequestWarning
from requests.exceptions import InvalidSchema, SSLError, ConnectionError
from ipaddress import IPv4Address

logger = getLogger()

Expand All @@ -36,11 +36,11 @@ def update(self):
today = date.today()

try:
dbdate = date.fromtimestamp(stat(self.dbfile).st_ctime)
dbdate = date.fromtimestamp(stat(self.dbfile).st_mtime)
except FileNotFoundError:
self.logger.error("Could not find GeoLite2 DB as: %s", self.dbfile)
self.download()
dbdate = date.fromtimestamp(stat(self.dbfile).st_ctime)
dbdate = date.fromtimestamp(stat(self.dbfile).st_mtime)

first_wednesday_day = [week[2:3][0] for week in monthcalendar(today.year, today.month) if week[2:3][0] != 0][0]
first_wednesday_date = date(today.year, today.month, first_wednesday_day)
Expand Down Expand Up @@ -90,7 +90,8 @@ def rfc1918_ip_check(ip):
return rfc1918_ip


def connection_handler(session, request, verify):
def connection_handler(session, request, verify, as_is_reply=False):
air = as_is_reply
s = session
r = request
v = verify
Expand All @@ -109,11 +110,9 @@ def connection_handler(session, request, verify):
return_json = get.json()
except JSONDecodeError:
logger.error('No JSON response. Response is: %s', get.text)
# 204 No Content is for ASA only
elif get.status_code == 204:
if get.headers['X-Auth-Token']:
return get.headers['X-Auth-Token']

if air:
return get
except InvalidSchema:
logger.error("You added http(s):// in the config file. Don't do that.")

Expand Down
Loading

0 comments on commit 6fe6a84

Please sign in to comment.