mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 23:42:37 -07:00
Move webserver notify to API
This commit is contained in:
parent
29ab470e42
commit
9b4536f132
4 changed files with 52 additions and 8 deletions
|
@ -35,6 +35,8 @@ import database
|
||||||
import libraries
|
import libraries
|
||||||
import logger
|
import logger
|
||||||
import mobile_app
|
import mobile_app
|
||||||
|
import notification_handler
|
||||||
|
import notifiers
|
||||||
import users
|
import users
|
||||||
|
|
||||||
|
|
||||||
|
@ -397,6 +399,50 @@ class API2:
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def notify(self, notifier_id='', subject='Tautulli', body='Test notification', **kwargs):
|
||||||
|
""" Send a notification using Tautulli.
|
||||||
|
|
||||||
|
```
|
||||||
|
Required parameters:
|
||||||
|
notifier_id (int): The ID number of the notification agent
|
||||||
|
subject (str): The subject of the message
|
||||||
|
body (str): The body of the message
|
||||||
|
|
||||||
|
Optional parameters:
|
||||||
|
None
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
if not notifier_id:
|
||||||
|
self._api_msg = 'Notification failed: no notifier id provided.'
|
||||||
|
self._api_result_type = 'error'
|
||||||
|
return
|
||||||
|
|
||||||
|
notifier = notifiers.get_notifier_config(notifier_id=notifier_id)
|
||||||
|
|
||||||
|
if not notifier:
|
||||||
|
self._api_msg = 'Notification failed: invalid notifier_id provided %s.' % notifier_id
|
||||||
|
self._api_result_type = 'error'
|
||||||
|
return
|
||||||
|
|
||||||
|
logger.api_debug(u'Tautulli APIv2 :: Sending notification.')
|
||||||
|
success = notification_handler.notify(notifier_id=notifier_id,
|
||||||
|
notify_action='api',
|
||||||
|
subject=subject,
|
||||||
|
body=body,
|
||||||
|
**kwargs)
|
||||||
|
|
||||||
|
if success:
|
||||||
|
self._api_msg = 'Notification sent.'
|
||||||
|
self._api_result_type = 'success'
|
||||||
|
else:
|
||||||
|
self._api_msg = 'Notification failed.'
|
||||||
|
self._api_result_type = 'error'
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
def _api_make_md(self):
|
def _api_make_md(self):
|
||||||
""" Tries to make a API.md to simplify the api docs. """
|
""" Tries to make a API.md to simplify the api docs. """
|
||||||
|
|
||||||
|
@ -581,8 +627,8 @@ General optional parameters:
|
||||||
if isinstance(result, (dict, list)):
|
if isinstance(result, (dict, list)):
|
||||||
ret = result
|
ret = result
|
||||||
else:
|
else:
|
||||||
raise
|
raise Exception
|
||||||
except:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
ret = json.loads(result)
|
ret = json.loads(result)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
|
|
|
@ -332,7 +332,7 @@ def notify(notifier_id=None, notify_action=None, stream_data=None, timeline_data
|
||||||
if not notifier_config:
|
if not notifier_config:
|
||||||
return
|
return
|
||||||
|
|
||||||
if notify_action == 'test':
|
if notify_action in ('test', 'api'):
|
||||||
subject = kwargs.pop('subject', 'Tautulli')
|
subject = kwargs.pop('subject', 'Tautulli')
|
||||||
body = kwargs.pop('body', 'Test Notification')
|
body = kwargs.pop('body', 'Test Notification')
|
||||||
script_args = kwargs.pop('script_args', [])
|
script_args = kwargs.pop('script_args', [])
|
||||||
|
@ -350,8 +350,8 @@ def notify(notifier_id=None, notify_action=None, stream_data=None, timeline_data
|
||||||
|
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
notification_id = set_notify_state(session=stream_data or timeline_data,
|
notification_id = set_notify_state(session=stream_data or timeline_data,
|
||||||
notify_action=notify_action,
|
|
||||||
notifier=notifier_config,
|
notifier=notifier_config,
|
||||||
|
notify_action=notify_action,
|
||||||
subject=subject,
|
subject=subject,
|
||||||
body=body,
|
body=body,
|
||||||
script_args=script_args)
|
script_args=script_args)
|
||||||
|
@ -390,9 +390,9 @@ def get_notify_state(session):
|
||||||
return notify_states
|
return notify_states
|
||||||
|
|
||||||
|
|
||||||
def set_notify_state(notify_action, notifier, subject, body, script_args, session=None):
|
def set_notify_state(notifier, notify_action, subject='', body='', script_args='', session=None):
|
||||||
|
|
||||||
if notify_action and notifier:
|
if notifier and notify_action:
|
||||||
monitor_db = database.MonitorDatabase()
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
||||||
session = session or {}
|
session = session or {}
|
||||||
|
|
|
@ -61,7 +61,6 @@ import mobile_app
|
||||||
import pmsconnect
|
import pmsconnect
|
||||||
import request
|
import request
|
||||||
from plexpy.config import _BLACKLIST_KEYS, _WHITELIST_KEYS
|
from plexpy.config import _BLACKLIST_KEYS, _WHITELIST_KEYS
|
||||||
from plexpy.helpers import checked
|
|
||||||
|
|
||||||
|
|
||||||
AGENT_IDS = {'growl': 0,
|
AGENT_IDS = {'growl': 0,
|
||||||
|
|
|
@ -3079,7 +3079,6 @@ class WebInterface(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@requireAuth(member_of("admin"))
|
@requireAuth(member_of("admin"))
|
||||||
@addtoapi("notify")
|
|
||||||
def send_notification(self, notifier_id=None, subject='Tautulli', body='Test notification', notify_action='', **kwargs):
|
def send_notification(self, notifier_id=None, subject='Tautulli', body='Test notification', notify_action='', **kwargs):
|
||||||
""" Send a notification using Tautulli.
|
""" Send a notification using Tautulli.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue