mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 07:46:07 -07:00
Fixes for testing script notifications
This commit is contained in:
parent
0988b68c8c
commit
1de3c0d559
3 changed files with 76 additions and 70 deletions
|
@ -75,6 +75,22 @@ from plexpy import helpers
|
||||||
<div class="col-md-12" style="margin-top: 10px; padding-top: 10px; border-top: 1px solid #444;">
|
<div class="col-md-12" style="margin-top: 10px; padding-top: 10px; border-top: 1px solid #444;">
|
||||||
<h4>Test ${agent['name']}</h4>
|
<h4>Test ${agent['name']}</h4>
|
||||||
<p class="help-block">Test if ${agent['name']} notifications are working. See <a href="/logs">logs</a> for troubleshooting.</p>
|
<p class="help-block">Test if ${agent['name']} notifications are working. See <a href="/logs">logs</a> for troubleshooting.</p>
|
||||||
|
% if agent['name'] == 'Scripts':
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="test_script">Script</label>
|
||||||
|
<select class="form-control" id="test_script" name="test_script">
|
||||||
|
% for key, value in sorted(data[2]['select_options'].iteritems()):
|
||||||
|
<option value="${key}">${value}</option>
|
||||||
|
% endfor
|
||||||
|
</select>
|
||||||
|
<p class="help-block">Choose the script to test.</p>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="test_script_args">Script Arguments</label>
|
||||||
|
<input class="form-control" type="text" id="test_script_args" name="test_script_args" value="">
|
||||||
|
<p class="help-block">Set custom arguments passed to the script.</p>
|
||||||
|
</div>
|
||||||
|
% else:
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="test_subject">Subject Line</label>
|
<label for="test_subject">Subject Line</label>
|
||||||
<input class="form-control" type="text" id="test_subject" name="test_subject" value="PlexPy">
|
<input class="form-control" type="text" id="test_subject" name="test_subject" value="PlexPy">
|
||||||
|
@ -85,31 +101,6 @@ from plexpy import helpers
|
||||||
<input class="form-control" type="text" id="test_body" name="test_body" value="Test notification">
|
<input class="form-control" type="text" id="test_body" name="test_body" value="Test notification">
|
||||||
<p class="help-block">Set a custom body.</p>
|
<p class="help-block">Set a custom body.</p>
|
||||||
</div>
|
</div>
|
||||||
%if agent['name'] == 'Scripts':
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="test_script_action">Script action</label>
|
|
||||||
<select class="form-control" id="test_script_action" name="test_script_action">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="play">Playback start</option>
|
|
||||||
<option value="stop">Playback stop</option>
|
|
||||||
<option value="pause">Playback pause</option>
|
|
||||||
<option value="resume">Playback resume</option>
|
|
||||||
<option value="watched">Watched</option>
|
|
||||||
<option value="buffer">Buffer warnings</option>
|
|
||||||
<option value="created">Recently added</option>
|
|
||||||
<option value="extdown">Plex remote access down</option>
|
|
||||||
<option value="intdown">Plex server down</option>
|
|
||||||
<option value="extup">Plex remote access back up</option>
|
|
||||||
<option value="intup">Plex server back up</option>
|
|
||||||
</select>
|
|
||||||
<p class="help-block">Choose a notification action.</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="test_script_args">Script args</label>
|
|
||||||
<input class="form-control" type="text" id="test_script_args" name="test_script_args" value="">
|
|
||||||
<p class="help-block">Set custom script arguments: -zomg --x.</p>
|
|
||||||
</div>
|
|
||||||
% endif
|
% endif
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -199,11 +190,13 @@ from plexpy import helpers
|
||||||
doAjaxCall('set_notification_config', $(this), 'tabs', true);
|
doAjaxCall('set_notification_config', $(this), 'tabs', true);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'test_notifier',
|
url: 'test_notifier',
|
||||||
data: { config_id: '${agent["id"]}',
|
data: {
|
||||||
subject: $('#test_subject').val(),
|
config_id: '${agent["id"]}',
|
||||||
body: $('#test_body').val(),
|
subject: $('#test_subject').val(),
|
||||||
notify_action: $('#test_script_action').val(),
|
body: $('#test_body').val(),
|
||||||
script_args: $('#test_script_args').val() },
|
script: $('#test_script').val(),
|
||||||
|
script_args: $('#test_script_args').val()
|
||||||
|
},
|
||||||
cache: false,
|
cache: false,
|
||||||
async: true,
|
async: true,
|
||||||
complete: function (xhr, status) {
|
complete: function (xhr, status) {
|
||||||
|
|
|
@ -757,9 +757,9 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
|
||||||
<ul class="submenu">
|
<ul class="submenu">
|
||||||
<li>
|
<li>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="notify_scripts_args_text">Script arguments</label>
|
<label for="notify_scripts_args_text">Script Arguments</label>
|
||||||
<input class="form-control" type="text" id="notify_scripts_args_text" name="notify_scripts_args_text" value="${config['notify_scripts_args_text']}" data-parsley-trigger="change">
|
<input class="form-control" type="text" id="notify_scripts_args_text" name="notify_scripts_args_text" value="${config['notify_scripts_args_text']}" data-parsley-trigger="change">
|
||||||
<p class="help-block">Set arguments passed to the script</p>
|
<p class="help-block">Set custom arguments passed to the scripts.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -1758,7 +1758,7 @@ class SLACK(object):
|
||||||
class Scripts(object):
|
class Scripts(object):
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
pass
|
self.script_exts = ('.bat', '.cmd', '.exe', '.php', '.pl', '.py', '.pyw', '.rb', '.sh')
|
||||||
|
|
||||||
def conf(self, options):
|
def conf(self, options):
|
||||||
return cherrypy.config['config'].get('Scripts', options)
|
return cherrypy.config['config'].get('Scripts', options)
|
||||||
|
@ -1781,14 +1781,14 @@ class Scripts(object):
|
||||||
for root, dirs, files in os.walk(scriptdir):
|
for root, dirs, files in os.walk(scriptdir):
|
||||||
for f in files:
|
for f in files:
|
||||||
name, ext = os.path.splitext(f)
|
name, ext = os.path.splitext(f)
|
||||||
if ext in ('.rb', '.pl', '.bat', '.py', '.sh', '.cmd', '.php'):
|
if ext in self.script_exts:
|
||||||
rfp = os.path.join(os.path.relpath(root, scriptdir), f)
|
rfp = os.path.join(os.path.relpath(root, scriptdir), f)
|
||||||
fp = os.path.join(root, f)
|
fp = os.path.join(root, f)
|
||||||
scripts[fp] = rfp
|
scripts[fp] = rfp
|
||||||
|
|
||||||
return scripts
|
return scripts
|
||||||
|
|
||||||
def notify(self, subject='', message='', notify_action='', script_args='', *args, **kwargs):
|
def notify(self, subject='', message='', notify_action='', script_args=[], *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
subject(string, optional): Head text,
|
subject(string, optional): Head text,
|
||||||
|
@ -1796,12 +1796,9 @@ class Scripts(object):
|
||||||
notify_action(string): 'play'
|
notify_action(string): 'play'
|
||||||
script_args(list): ["python2", '-p', '-zomg']
|
script_args(list): ["python2", '-p', '-zomg']
|
||||||
"""
|
"""
|
||||||
logger.debug(u"PlexPy Notifiers :: Trying to run notify script, subject: %s, message: %s, action: %s, script_args: %s" %
|
logger.debug(u"PlexPy Notifiers :: Trying to run notify script, action: %s, arguments: %s" %
|
||||||
(subject, message, notify_action, script_args))
|
(notify_action if notify_action else None, script_args if script_args else None))
|
||||||
|
|
||||||
prefix = ''
|
|
||||||
script = kwargs.get('script', '') # for manual scripts
|
|
||||||
|
|
||||||
if not plexpy.CONFIG.SCRIPTS_FOLDER:
|
if not plexpy.CONFIG.SCRIPTS_FOLDER:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -1839,31 +1836,42 @@ class Scripts(object):
|
||||||
elif notify_action == 'watched':
|
elif notify_action == 'watched':
|
||||||
script = plexpy.CONFIG.SCRIPTS_ON_WATCHED_SCRIPT
|
script = plexpy.CONFIG.SCRIPTS_ON_WATCHED_SCRIPT
|
||||||
|
|
||||||
# Dont try to run the script
|
else:
|
||||||
# if the action does not have one
|
# For manual scripts
|
||||||
if not script:
|
script = kwargs.get('script', '')
|
||||||
logger.debug(u"PlexPy Notifiers :: Action %s has no script, exiting..." % notify_action)
|
|
||||||
|
# Don't try to run the script if the action does not have one
|
||||||
|
if notify_action and not script:
|
||||||
|
logger.debug(u"PlexPy Notifiers :: No script selected for action %s, exiting..." % notify_action)
|
||||||
|
return
|
||||||
|
elif not script:
|
||||||
|
logger.debug(u"PlexPy Notifiers :: No script selected, exiting...")
|
||||||
return
|
return
|
||||||
|
|
||||||
name, ext = os.path.splitext(script)
|
name, ext = os.path.splitext(script)
|
||||||
|
|
||||||
if ext == '.py':
|
if ext == '.py':
|
||||||
prefix = 'python'
|
prefix = 'python'
|
||||||
|
elif ext == '.pyw':
|
||||||
|
prefix = 'pythonw'
|
||||||
elif ext == '.php':
|
elif ext == '.php':
|
||||||
prefix = 'php'
|
prefix = 'php'
|
||||||
elif ext == '.pl':
|
elif ext == '.pl':
|
||||||
prefix = 'perl'
|
prefix = 'perl'
|
||||||
elif ext == '.rb':
|
elif ext == '.rb':
|
||||||
prefix = 'ruby'
|
prefix = 'ruby'
|
||||||
|
else:
|
||||||
|
prefix = ''
|
||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
script = script.encode(plexpy.SYS_ENCODING, 'ignore')
|
script = script.encode(plexpy.SYS_ENCODING, 'ignore')
|
||||||
script = [script]
|
|
||||||
|
|
||||||
if prefix:
|
if prefix:
|
||||||
script.insert(0, prefix)
|
script = [prefix, script]
|
||||||
|
else:
|
||||||
|
script = [script]
|
||||||
|
|
||||||
# for manual notifications
|
# For manual notifications
|
||||||
if script_args and isinstance(script_args, basestring):
|
if script_args and isinstance(script_args, basestring):
|
||||||
# attemps for format it for the user
|
# attemps for format it for the user
|
||||||
script_args = shlex.split(script_args)
|
script_args = shlex.split(script_args)
|
||||||
|
@ -1875,13 +1883,13 @@ class Scripts(object):
|
||||||
|
|
||||||
# Allow overrides for shitty systems
|
# Allow overrides for shitty systems
|
||||||
if prefix and script_args:
|
if prefix and script_args:
|
||||||
if script_args[0] in ['python2', 'python', 'php', 'ruby', 'perl']:
|
if script_args[0] in ['python2', 'python', 'pythonw', 'php', 'ruby', 'perl']:
|
||||||
script[0] = script_args[0]
|
script[0] = script_args[0]
|
||||||
del script_args[0]
|
del script_args[0]
|
||||||
|
|
||||||
script.extend(script_args)
|
script.extend(script_args)
|
||||||
|
|
||||||
logger.debug(u"PlexPy Notifiers :: Full script is: %s" % ' '.join(script))
|
logger.debug(u"PlexPy Notifiers :: Full script is: %s" % script)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
p = subprocess.Popen(script, stdin=subprocess.PIPE,
|
p = subprocess.Popen(script, stdin=subprocess.PIPE,
|
||||||
|
@ -1894,7 +1902,7 @@ class Scripts(object):
|
||||||
|
|
||||||
if out and status:
|
if out and status:
|
||||||
out = out.strip()
|
out = out.strip()
|
||||||
logger.debug(u"PlexPy Notifiers :: Script returned %s" % out)
|
logger.debug(u"PlexPy Notifiers :: Script returned: %s" % out)
|
||||||
|
|
||||||
if error:
|
if error:
|
||||||
error = error.strip()
|
error = error.strip()
|
||||||
|
@ -1906,7 +1914,12 @@ class Scripts(object):
|
||||||
logger.error(u"PlexPy Notifiers :: Failed to run script: %s" % e)
|
logger.error(u"PlexPy Notifiers :: Failed to run script: %s" % e)
|
||||||
|
|
||||||
def return_config_options(self):
|
def return_config_options(self):
|
||||||
config_option = [{'label': 'Script folder',
|
config_option = [{'label': 'Warning',
|
||||||
|
'description': '<strong>Script notifications are currently experimental!</strong><br><br>\
|
||||||
|
Supported file types: ' + ', '.join(self.script_exts),
|
||||||
|
'input_type': 'help'
|
||||||
|
},
|
||||||
|
{'label': 'Script folder',
|
||||||
'value': plexpy.CONFIG.SCRIPTS_FOLDER,
|
'value': plexpy.CONFIG.SCRIPTS_FOLDER,
|
||||||
'name': 'scripts_folder',
|
'name': 'scripts_folder',
|
||||||
'description': 'Add your script folder.',
|
'description': 'Add your script folder.',
|
||||||
|
@ -1915,77 +1928,77 @@ class Scripts(object):
|
||||||
{'label': 'Playback Start',
|
{'label': 'Playback Start',
|
||||||
'value': plexpy.CONFIG.SCRIPTS_ON_PLAY_SCRIPT,
|
'value': plexpy.CONFIG.SCRIPTS_ON_PLAY_SCRIPT,
|
||||||
'name': 'scripts_on_play_script',
|
'name': 'scripts_on_play_script',
|
||||||
'description': 'Pick the script for on play.',
|
'description': 'Choose the script for on play.',
|
||||||
'input_type': 'select',
|
'input_type': 'select',
|
||||||
'select_options': self.list_scripts()
|
'select_options': self.list_scripts()
|
||||||
},
|
},
|
||||||
{'label': 'Playback Stop',
|
{'label': 'Playback Stop',
|
||||||
'value': plexpy.CONFIG.SCRIPTS_ON_STOP_SCRIPT,
|
'value': plexpy.CONFIG.SCRIPTS_ON_STOP_SCRIPT,
|
||||||
'name': 'scripts_on_stop_script',
|
'name': 'scripts_on_stop_script',
|
||||||
'description': 'Pick the script for on stop.',
|
'description': 'Choose the script for on stop.',
|
||||||
'input_type': 'select',
|
'input_type': 'select',
|
||||||
'select_options': self.list_scripts()
|
'select_options': self.list_scripts()
|
||||||
},
|
},
|
||||||
{'label': 'Playback Pause',
|
{'label': 'Playback Pause',
|
||||||
'value': plexpy.CONFIG.SCRIPTS_ON_PAUSE_SCRIPT,
|
'value': plexpy.CONFIG.SCRIPTS_ON_PAUSE_SCRIPT,
|
||||||
'name': 'scripts_on_pause_script',
|
'name': 'scripts_on_pause_script',
|
||||||
'description': 'Pick the script for on pause.',
|
'description': 'Choose the script for on pause.',
|
||||||
'input_type': 'select',
|
'input_type': 'select',
|
||||||
'select_options': self.list_scripts()
|
'select_options': self.list_scripts()
|
||||||
},
|
},
|
||||||
{'label': 'Playback Resume',
|
{'label': 'Playback Resume',
|
||||||
'value': plexpy.CONFIG.SCRIPTS_ON_RESUME_SCRIPT,
|
'value': plexpy.CONFIG.SCRIPTS_ON_RESUME_SCRIPT,
|
||||||
'name': 'scripts_on_resume_script',
|
'name': 'scripts_on_resume_script',
|
||||||
'description': 'Pick the script for on resume.',
|
'description': 'Choose the script for on resume.',
|
||||||
'input_type': 'select',
|
'input_type': 'select',
|
||||||
'select_options': self.list_scripts()
|
'select_options': self.list_scripts()
|
||||||
},
|
},
|
||||||
{'label': 'Watched',
|
{'label': 'Watched',
|
||||||
'value': plexpy.CONFIG.SCRIPTS_ON_WATCHED_SCRIPT,
|
'value': plexpy.CONFIG.SCRIPTS_ON_WATCHED_SCRIPT,
|
||||||
'name': 'scripts_on_watched_script',
|
'name': 'scripts_on_watched_script',
|
||||||
'description': 'Pick the script for on watched.',
|
'description': 'Choose the script for on watched.',
|
||||||
'input_type': 'select',
|
'input_type': 'select',
|
||||||
'select_options': self.list_scripts()
|
'select_options': self.list_scripts()
|
||||||
},
|
},
|
||||||
{'label': 'Buffer Warnings',
|
{'label': 'Buffer Warnings',
|
||||||
'value': plexpy.CONFIG.SCRIPTS_ON_BUFFER_SCRIPT,
|
'value': plexpy.CONFIG.SCRIPTS_ON_BUFFER_SCRIPT,
|
||||||
'name': 'scripts_on_buffer_script',
|
'name': 'scripts_on_buffer_script',
|
||||||
'description': 'Pick the script for buffer warnings.',
|
'description': 'Choose the script for buffer warnings.',
|
||||||
'input_type': 'select',
|
'input_type': 'select',
|
||||||
'select_options': self.list_scripts()
|
'select_options': self.list_scripts()
|
||||||
},
|
},
|
||||||
{'label': 'Recently Added',
|
{'label': 'Recently Added',
|
||||||
'value': plexpy.CONFIG.SCRIPTS_ON_CREATED_SCRIPT,
|
'value': plexpy.CONFIG.SCRIPTS_ON_CREATED_SCRIPT,
|
||||||
'name': 'scripts_on_created_script',
|
'name': 'scripts_on_created_script',
|
||||||
'description': 'Pick the script for recently added.',
|
'description': 'Choose the script for recently added.',
|
||||||
'input_type': 'select',
|
'input_type': 'select',
|
||||||
'select_options': self.list_scripts()
|
'select_options': self.list_scripts()
|
||||||
},
|
},
|
||||||
{'label': 'Plex Remote Access Down',
|
{'label': 'Plex Remote Access Down',
|
||||||
'value': plexpy.CONFIG.SCRIPTS_ON_EXTDOWN_SCRIPT,
|
'value': plexpy.CONFIG.SCRIPTS_ON_EXTDOWN_SCRIPT,
|
||||||
'name': 'scripts_on_extdown_script',
|
'name': 'scripts_on_extdown_script',
|
||||||
'description': 'Pick the script for external connection down.',
|
'description': 'Choose the script for Plex remote access down.',
|
||||||
'input_type': 'select',
|
|
||||||
'select_options': self.list_scripts()
|
|
||||||
},
|
|
||||||
{'label': 'Plex Remote Access Up',
|
|
||||||
'value': plexpy.CONFIG.SCRIPTS_ON_EXTUP_SCRIPT,
|
|
||||||
'name': 'scripts_on_extup_script',
|
|
||||||
'description': 'Pick the script for external connection up.',
|
|
||||||
'input_type': 'select',
|
'input_type': 'select',
|
||||||
'select_options': self.list_scripts()
|
'select_options': self.list_scripts()
|
||||||
},
|
},
|
||||||
{'label': 'Plex Server Down',
|
{'label': 'Plex Server Down',
|
||||||
'value': plexpy.CONFIG.SCRIPTS_ON_INTDOWN_SCRIPT,
|
'value': plexpy.CONFIG.SCRIPTS_ON_INTDOWN_SCRIPT,
|
||||||
'name': 'scripts_on_intdown_script',
|
'name': 'scripts_on_intdown_script',
|
||||||
'description': 'Pick the script for pms down',
|
'description': 'Choose the script for Plex server down.',
|
||||||
'input_type': 'select',
|
'input_type': 'select',
|
||||||
'select_options': self.list_scripts()
|
'select_options': self.list_scripts()
|
||||||
},
|
},
|
||||||
{'label': 'Plex Server Up',
|
{'label': 'Plex Remote Access Back Up',
|
||||||
|
'value': plexpy.CONFIG.SCRIPTS_ON_EXTUP_SCRIPT,
|
||||||
|
'name': 'scripts_on_extup_script',
|
||||||
|
'description': 'Choose the script for Plex remote access back up.',
|
||||||
|
'input_type': 'select',
|
||||||
|
'select_options': self.list_scripts()
|
||||||
|
},
|
||||||
|
{'label': 'Plex Server Back Up',
|
||||||
'value': plexpy.CONFIG.SCRIPTS_ON_INTUP_SCRIPT,
|
'value': plexpy.CONFIG.SCRIPTS_ON_INTUP_SCRIPT,
|
||||||
'name': 'scripts_on_intup_script',
|
'name': 'scripts_on_intup_script',
|
||||||
'description': 'Pick the script for pms up',
|
'description': 'Choose the script for Plex server back up.',
|
||||||
'input_type': 'select',
|
'input_type': 'select',
|
||||||
'select_options': self.list_scripts()
|
'select_options': self.list_scripts()
|
||||||
}
|
}
|
||||||
|
@ -2075,7 +2088,7 @@ class FacebookNotifier(object):
|
||||||
|
|
||||||
def return_config_options(self):
|
def return_config_options(self):
|
||||||
config_option = [{'label': 'Instructions',
|
config_option = [{'label': 'Instructions',
|
||||||
'description': '<strong>Facebook notifications are experimental!</strong><br><br> \
|
'description': '<strong>Facebook notifications are currently experimental!</strong><br><br> \
|
||||||
Step 1: Visit <a href="https://developers.facebook.com/apps/" target="_blank">Facebook Developers</a> to create a new app using <strong>advanced setup</strong>.<br>\
|
Step 1: Visit <a href="https://developers.facebook.com/apps/" target="_blank">Facebook Developers</a> to create a new app using <strong>advanced setup</strong>.<br>\
|
||||||
Step 2: Go to <strong>Settings > Advanced</strong> and fill in <strong>Valid OAuth redirect URIs</strong> with your PlexPy URL (i.e. http://localhost:8181).<br>\
|
Step 2: Go to <strong>Settings > Advanced</strong> and fill in <strong>Valid OAuth redirect URIs</strong> with your PlexPy URL (i.e. http://localhost:8181).<br>\
|
||||||
Step 3: Fill in the <strong>App ID</strong> and <strong>App Secret</strong> below.<br>\
|
Step 3: Fill in the <strong>App ID</strong> and <strong>App Secret</strong> below.<br>\
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue