added logging conf and now checking recording status with simple script ; notifications are missing

This commit is contained in:
Tobias Kurze
2019-11-13 08:19:39 +01:00
parent 4563e16137
commit 872e531ef5
7 changed files with 436 additions and 265 deletions

View File

@@ -48,6 +48,7 @@ for r in recorders:
'type': 'SMP 351' if 'SMP 351' in r['Rekorder-Typ'] else r['Rekorder-Typ'],
'additional_camera': r['Zus. Kamera'] == 'Ja',
'firmware_version': r['FW Vers.'],
'network_name': r['DNS'],
'description': json.dumps(
{'comment': r['Bemerkung'], 'network_port': r['Dosennummer'], 'rsync_name': r['Rsync-Name']})}
nicely_formatted_recorders.append(rec)

View File

@@ -1,3 +1,8 @@
import json
import os
import logging
from multiprocessing.pool import ThreadPool
from pprint import pprint
import requests
@@ -5,6 +10,14 @@ from requests.auth import HTTPBasicAuth
from ics import Calendar
from backend.config import Config
from backend.recorder_adapters.epiphan_base import EpiphanV1
from backend.recorder_adapters.extron_smp import SMP
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.DEBUG)
logger.addHandler(stream_handler)
base_url = "https://opencast.bibliothek.kit.edu"
@@ -13,6 +26,8 @@ session.auth = HTTPBasicAuth(Config.OPENCAST_USER, Config.OPENCAST_PW)
config = {'service_urls': {}}
recorders = None
def get_service_url(service_type: str):
if service_type in config['service_urls']:
@@ -24,7 +39,7 @@ def get_service_url(service_type: str):
service = res.json()["services"]["service"]
config["service_urls"][service_type] = service["host"] + \
service["path"]
return service["host"] +service["path"]
return service["host"] + service["path"]
return None
@@ -43,13 +58,71 @@ def get_capture_agents():
if res.ok:
return res.json()["agents"]["agent"]
def get_recorder_details():
"""Temporary implementation using initial_recorders.json. Should be replaced by DB layer later!"""
global recorders
if recorders is None:
f = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, 'models', 'initial_recorders.json'))
with open(f, 'r') as json_file:
recorders = json.load(json_file)['recorders']
return recorders
def get_recorder_by_name(name: str):
for r in get_recorder_details():
if r["name"] == name:
return r
return None
def notify_users_of_problem(msg: str):
pass
def check_capture_agent_state(a: dict):
logger.debug("Checking Agent {}".format(a['name']))
c = get_calender(a['name'])
is_recording_in_calendar = len(list(c.timeline.now())) >= 1
if is_recording_in_calendar:
if a['state'] == "capturing":
print(
"{} is in capturing state, so there should be an entry in the calendar of the recorder, right? -> {}".format(
a['name'], is_recording_in_calendar
))
rec = get_recorder_by_name(a['name'])
print(rec)
if "SMP" in rec["type"]:
print("using SMP adapter")
rec = SMP(rec['ip'], rec['password'])
else:
rec = EpiphanV1(rec['ip'], rec["username"], rec["password"])
if rec.is_recording():
print("OK recorder is recording :)")
else:
logger.info(rec.get_recording_status())
logger.error("FATAL - recorder {} must be recording!!!!".format(a['name']))
else:
print("FATAL: {} is not in capturing state...but should be!!".format(a['name']))
else:
rec = get_recorder_by_name(a['name'])
if "SMP" in rec["type"]:
logger.debug("using SMP adapter")
rec = SMP(rec['ip'], rec['password'])
else:
rec = EpiphanV1(rec['ip'], rec["username"], rec["password"])
if rec.is_recording():
logger.error("FATAL - recorder must not be recording!!!!")
else:
logger.info("OK recorder is not recording :)")
agents = get_capture_agents()
for a in agents:
print(a['name'])
print(a['state'])
if a['state'] == "capturing":
c = get_calender(a['name'])
print(list(c.timeline.now()))
logger.info("Got {} capture agents that will be checked...".format(len(agents)))
pool = ThreadPool(5)
pool.map(check_capture_agent_state, agents)
exit()
c = get_calender('CS 30.46 Chemie Neuer Hoersaal')