Add newsletter logs table

This commit is contained in:
JonnyWong16 2018-03-18 21:40:57 -07:00
parent b9b82b23f7
commit 50b37d6b3a
5 changed files with 382 additions and 14 deletions

View file

@ -1563,6 +1563,77 @@ class DataFactory(object):
logger.warn(u"Tautulli DataFactory :: Unable to execute database query for delete_notification_log: %s." % e)
return False
def get_newsletter_log(self, kwargs=None):
data_tables = datatables.DataTables()
columns = ['newsletter_log.id',
'newsletter_log.timestamp',
'newsletter_log.newsletter_id',
'newsletter_log.agent_id',
'newsletter_log.agent_name',
'newsletter_log.notify_action',
'newsletter_log.subject_text',
'newsletter_log.start_date',
'newsletter_log.end_date',
'newsletter_log.uuid',
'newsletter_log.success'
]
try:
query = data_tables.ssp_query(table_name='newsletter_log',
columns=columns,
custom_where=[],
group_by=[],
join_types=[],
join_tables=[],
join_evals=[],
kwargs=kwargs)
except Exception as e:
logger.warn(u"Tautulli DataFactory :: Unable to execute database query for get_newsletter_log: %s." % e)
return {'recordsFiltered': 0,
'recordsTotal': 0,
'draw': 0,
'data': 'null',
'error': 'Unable to execute database query.'}
newsletters = query['result']
rows = []
for item in newsletters:
row = {'id': item['id'],
'timestamp': item['timestamp'],
'newsletter_id': item['newsletter_id'],
'agent_id': item['agent_id'],
'agent_name': item['agent_name'],
'notify_action': item['notify_action'],
'subject_text': item['subject_text'],
'start_date': item['start_date'],
'end_date': item['end_date'],
'uuid': item['uuid'],
'success': item['success']
}
rows.append(row)
dict = {'recordsFiltered': query['filteredCount'],
'recordsTotal': query['totalCount'],
'data': rows,
'draw': query['draw']
}
return dict
def delete_newsletter_log(self):
monitor_db = database.MonitorDatabase()
try:
logger.info(u"Tautulli DataFactory :: Clearing newsletter logs from database.")
monitor_db.action('DELETE FROM newsletter_log')
monitor_db.action('VACUUM')
return True
except Exception as e:
logger.warn(u"Tautulli DataFactory :: Unable to execute database query for delete_newsletter_log: %s." % e)
return False
def get_user_devices(self, user_id=''):
monitor_db = database.MonitorDatabase()

View file

@ -2394,8 +2394,8 @@ class WebInterface(object):
None
Optional parameters:
order_column (str): "timestamp", "agent_name", "notify_action",
"subject_text", "body_text", "script_args"
order_column (str): "timestamp", "notifier_id", "agent_name", "notify_action",
"subject_text", "body_text",
order_dir (str): "desc" or "asc"
start (int): Row to start from, 0
length (int): Number of items to return, 25
@ -2408,15 +2408,14 @@ class WebInterface(object):
"recordsFiltered": 163,
"data":
[{"agent_id": 13,
"agent_name": "Telegram",
"body_text": "Game of Thrones - S06E01 - The Red Woman [Transcode].",
"agent_name": "telegram",
"body_text": "DanyKhaleesi69 started playing The Red Woman.",
"id": 1000,
"notify_action": "play",
"poster_url": "http://i.imgur.com/ZSqS8Ri.jpg",
"notify_action": "on_play",
"rating_key": 153037,
"script_args": "[]",
"session_key": 147,
"subject_text": "Tautulli (Winterfell-Server)",
"success": 1,
"timestamp": 1462253821,
"user": "DanyKhaleesi69",
"user_id": 8008135
@ -2432,17 +2431,79 @@ class WebInterface(object):
if not kwargs.get('json_data'):
# TODO: Find some one way to automatically get the columns
dt_columns = [("timestamp", True, True),
("notifier_id", True, True),
("agent_name", True, True),
("notify_action", True, True),
("subject_text", True, True),
("body_text", True, True),
("script_args", True, True)]
("body_text", True, True)]
kwargs['json_data'] = build_datatables_json(kwargs, dt_columns, "timestamp")
data_factory = datafactory.DataFactory()
notifications = data_factory.get_notification_log(kwargs=kwargs)
notification_logs = data_factory.get_notification_log(kwargs=kwargs)
return notifications
return notification_logs
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))
@addtoapi()
def get_newsletter_log(self, **kwargs):
""" Get the data on the Tautulli newsletter logs table.
```
Required parameters:
None
Optional parameters:
order_column (str): "timestamp", "newsletter_id", "agent_name", "notify_action",
"subject_text", "start_date", "end_date", "uuid"
order_dir (str): "desc" or "asc"
start (int): Row to start from, 0
length (int): Number of items to return, 25
search (str): A string to search for, "Telegram"
Returns:
json:
{"draw": 1,
"recordsTotal": 1039,
"recordsFiltered": 163,
"data":
[{"agent_id": 0,
"agent_name": "recently_added",
"end_date": "2018-03-18",
"id": 7,
"newsletter_id": 1,
"notify_action": "on_cron",
"start_date": "2018-03-05",
"subject_text": "Recently Added to Plex (Winterfell-Server)! (2018-03-18)",
"success": 1,
"timestamp": 1462253821,
"uuid": "7fe4g65i"
},
{...},
{...}
]
}
```
"""
# Check if datatables json_data was received.
# If not, then build the minimal amount of json data for a query
if not kwargs.get('json_data'):
# TODO: Find some one way to automatically get the columns
dt_columns = [("timestamp", True, True),
("newsletter_id", True, True),
("agent_name", True, True),
("notify_action", True, True),
("subject_text", True, True),
("start_date", True, True),
("end_date", True, True),
("uuid", True, True)]
kwargs['json_data'] = build_datatables_json(kwargs, dt_columns, "timestamp")
data_factory = datafactory.DataFactory()
newsletter_logs = data_factory.get_newsletter_log(kwargs=kwargs)
return newsletter_logs
@cherrypy.expose
@cherrypy.tools.json_out()
@ -2469,6 +2530,31 @@ class WebInterface(object):
return {'result': res, 'message': msg}
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))
@addtoapi()
def delete_newsletter_log(self, **kwargs):
""" Delete the Tautulli newsletter logs.
```
Required paramters:
None
Optional parameters:
None
Returns:
None
```
"""
data_factory = datafactory.DataFactory()
result = data_factory.delete_newsletter_log()
res = 'success' if result else 'error'
msg = 'Cleared newsletter logs.' if result else 'Failed to clear newsletter logs.'
return {'result': res, 'message': msg}
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))