mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-07 05:31:15 -07:00
Add notification success to database
This commit is contained in:
parent
fc37a8afa3
commit
006e7c214d
5 changed files with 68 additions and 19 deletions
|
@ -80,13 +80,34 @@ notification_log_table_options = {
|
||||||
$(td).html(cellData);
|
$(td).html(cellData);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"width": "50%"
|
"width": "48%"
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"targets": [6],
|
||||||
|
"data": "success",
|
||||||
|
"createdCell": function (td, cellData, rowData, row, col) {
|
||||||
|
if (cellData == 1) {
|
||||||
|
$(td).html('<span class="success-tooltip" data-toggle="tooltip" title="Notification Sent"><i class="fa fa-lg fa-check"></i></span>');
|
||||||
|
} else {
|
||||||
|
$(td).html('<span class="success-tooltip" data-toggle="tooltip" title="Notification Failed"><i class="fa fa-lg fa-times"></i></span>');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"searchable": false,
|
||||||
|
"orderable": false,
|
||||||
|
"className": "no-wrap",
|
||||||
|
"width": "2%"
|
||||||
|
},
|
||||||
],
|
],
|
||||||
"drawCallback": function (settings) {
|
"drawCallback": function (settings) {
|
||||||
// Jump to top of page
|
// Jump to top of page
|
||||||
//$('html,body').scrollTop(0);
|
//$('html,body').scrollTop(0);
|
||||||
$('#ajaxMsg').fadeOut();
|
$('#ajaxMsg').fadeOut();
|
||||||
|
|
||||||
|
// Create the tooltips.
|
||||||
|
$('body').tooltip({
|
||||||
|
selector: '[data-toggle="tooltip"]',
|
||||||
|
container: 'body'
|
||||||
|
});
|
||||||
},
|
},
|
||||||
"preDrawCallback": function(settings) {
|
"preDrawCallback": function(settings) {
|
||||||
var msg = "<i class='fa fa-refresh fa-spin'></i> Fetching rows...";
|
var msg = "<i class='fa fa-refresh fa-spin'></i> Fetching rows...";
|
||||||
|
|
|
@ -109,6 +109,7 @@
|
||||||
<th align="left" id="notification_notify_action">Action</th>
|
<th align="left" id="notification_notify_action">Action</th>
|
||||||
<th align="left" id="notification_subject_text">Subject Text</th>
|
<th align="left" id="notification_subject_text">Subject Text</th>
|
||||||
<th align="left" id="notification_body_text">Body Text</th>
|
<th align="left" id="notification_body_text">Body Text</th>
|
||||||
|
<th align="left" id="notification_success"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody></tbody>
|
<tbody></tbody>
|
||||||
|
|
|
@ -481,7 +481,7 @@ def dbcheck():
|
||||||
'CREATE TABLE IF NOT EXISTS notify_log (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp INTEGER, '
|
'CREATE TABLE IF NOT EXISTS notify_log (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp INTEGER, '
|
||||||
'session_key INTEGER, rating_key INTEGER, parent_rating_key INTEGER, grandparent_rating_key INTEGER, '
|
'session_key INTEGER, rating_key INTEGER, parent_rating_key INTEGER, grandparent_rating_key INTEGER, '
|
||||||
'user_id INTEGER, user TEXT, notifier_id INTEGER, agent_id INTEGER, agent_name TEXT, notify_action TEXT, '
|
'user_id INTEGER, user TEXT, notifier_id INTEGER, agent_id INTEGER, agent_name TEXT, notify_action TEXT, '
|
||||||
'subject_text TEXT, body_text TEXT, script_args TEXT)'
|
'subject_text TEXT, body_text TEXT, script_args TEXT, success INTEGER DEFAULT 0)'
|
||||||
)
|
)
|
||||||
|
|
||||||
# library_sections table :: This table keeps record of the servers library sections
|
# library_sections table :: This table keeps record of the servers library sections
|
||||||
|
@ -958,6 +958,18 @@ def dbcheck():
|
||||||
'ALTER TABLE notify_log ADD COLUMN notifier_id INTEGER'
|
'ALTER TABLE notify_log ADD COLUMN notifier_id INTEGER'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Upgrade notify_log table from earlier versions
|
||||||
|
try:
|
||||||
|
c_db.execute('SELECT send_success FROM notify_log')
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
logger.debug(u"Altering database. Updating database table notify_log.")
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE notify_log ADD COLUMN success INTEGER DEFAULT 0'
|
||||||
|
)
|
||||||
|
c_db.execute(
|
||||||
|
'UPDATE notify_log SET success = 1'
|
||||||
|
)
|
||||||
|
|
||||||
# Upgrade library_sections table from earlier versions (remove UNIQUE constraint on section_id)
|
# Upgrade library_sections table from earlier versions (remove UNIQUE constraint on section_id)
|
||||||
try:
|
try:
|
||||||
result = c_db.execute('SELECT SQL FROM sqlite_master WHERE type="table" AND name="library_sections"').fetchone()
|
result = c_db.execute('SELECT SQL FROM sqlite_master WHERE type="table" AND name="library_sections"').fetchone()
|
||||||
|
|
|
@ -1321,7 +1321,8 @@ class DataFactory(object):
|
||||||
'notify_log.agent_name',
|
'notify_log.agent_name',
|
||||||
'notify_log.notify_action',
|
'notify_log.notify_action',
|
||||||
'notify_log.subject_text',
|
'notify_log.subject_text',
|
||||||
'notify_log.body_text'
|
'notify_log.body_text',
|
||||||
|
'notify_log.success'
|
||||||
]
|
]
|
||||||
try:
|
try:
|
||||||
query = data_tables.ssp_query(table_name='notify_log',
|
query = data_tables.ssp_query(table_name='notify_log',
|
||||||
|
@ -1360,7 +1361,8 @@ class DataFactory(object):
|
||||||
'agent_name': item['agent_name'],
|
'agent_name': item['agent_name'],
|
||||||
'notify_action': item['notify_action'],
|
'notify_action': item['notify_action'],
|
||||||
'subject_text': item['subject_text'],
|
'subject_text': item['subject_text'],
|
||||||
'body_text': body_text
|
'body_text': body_text,
|
||||||
|
'success': item['success']
|
||||||
}
|
}
|
||||||
|
|
||||||
rows.append(row)
|
rows.append(row)
|
||||||
|
|
|
@ -192,21 +192,25 @@ def notify(notifier_id=None, notify_action=None, stream_data=None, timeline_data
|
||||||
parameters=parameters,
|
parameters=parameters,
|
||||||
agent_id=notifier_config['agent_id'])
|
agent_id=notifier_config['agent_id'])
|
||||||
|
|
||||||
# Send the notification
|
|
||||||
notifiers.send_notification(notifier_id=notifier_config['id'],
|
|
||||||
subject=subject,
|
|
||||||
body=body,
|
|
||||||
script_args=script_args,
|
|
||||||
notify_action=notify_action,
|
|
||||||
parameters=parameters)
|
|
||||||
|
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data or timeline_data,
|
notification_id = set_notify_state(session=stream_data or timeline_data,
|
||||||
notify_action=notify_action,
|
notify_action=notify_action,
|
||||||
notifier=notifier_config,
|
notifier=notifier_config,
|
||||||
subject=subject,
|
subject=subject,
|
||||||
body=body,
|
body=body,
|
||||||
script_args=script_args)
|
script_args=script_args)
|
||||||
|
|
||||||
|
# Send the notification
|
||||||
|
success = notifiers.send_notification(notifier_id=notifier_config['id'],
|
||||||
|
subject=subject,
|
||||||
|
body=body,
|
||||||
|
script_args=script_args,
|
||||||
|
notify_action=notify_action,
|
||||||
|
notification_id=notification_id,
|
||||||
|
parameters=parameters)
|
||||||
|
|
||||||
|
if success:
|
||||||
|
set_notify_success(notification_id)
|
||||||
|
|
||||||
|
|
||||||
def get_notify_state(session):
|
def get_notify_state(session):
|
||||||
|
@ -254,10 +258,19 @@ def set_notify_state(notify_action, notifier, subject, body, script_args, sessio
|
||||||
'script_args': script_args}
|
'script_args': script_args}
|
||||||
|
|
||||||
monitor_db.upsert(table_name='notify_log', key_dict=keys, value_dict=values)
|
monitor_db.upsert(table_name='notify_log', key_dict=keys, value_dict=values)
|
||||||
|
return monitor_db.last_insert_id()
|
||||||
else:
|
else:
|
||||||
logger.error(u"PlexPy NotificationHandler :: Unable to set notify state.")
|
logger.error(u"PlexPy NotificationHandler :: Unable to set notify state.")
|
||||||
|
|
||||||
|
|
||||||
|
def set_notify_success(notification_id):
|
||||||
|
keys = {'id': notification_id}
|
||||||
|
values = {'success': 1}
|
||||||
|
|
||||||
|
monitor_db = database.MonitorDatabase()
|
||||||
|
monitor_db.upsert(table_name='notify_log', key_dict=keys, value_dict=values)
|
||||||
|
|
||||||
|
|
||||||
def build_media_notify_params(notify_action=None, session=None, timeline=None, **kwargs):
|
def build_media_notify_params(notify_action=None, session=None, timeline=None, **kwargs):
|
||||||
# Get time formats
|
# Get time formats
|
||||||
date_format = plexpy.CONFIG.DATE_FORMAT.replace('Do','')
|
date_format = plexpy.CONFIG.DATE_FORMAT.replace('Do','')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue