def notifications(http_context, app, sessions): logger.info("Get notifications.") try: notifications = NotificationMgmt.get_last_n(app.config, -1) logger.info("Done.") return list(notifications) except (NotificationError, Exception) as e: logger.exception(e) logger.info("Failed.") raise HTTPError(500, "Internal error.")
def notifications(http_context, config=None, sessions=None): headers = http_context['headers'] logger.info("Get notifications.") try: check_sessionid(headers, sessions) except HTTPError as e: logger.exception(e.message) logger.info("Invalid session.") raise e try: notifications = NotificationMgmt.get_last_n(config, -1) logger.info("Done.") return list(notifications) except (NotificationError, Exception) as e: logger.exception(e.message) logger.info("Failed.") raise HTTPError(500, "Internal error.")
def get_notifications(self, config): return list(NotificationMgmt.get_last_n(config, 15))
def notifications(http_context, queue_in=None, config=None, sessions=None, commands=None): """ @api {get} /notifications Get all notifications. @apiVersion 0.0.1 @apiName Notifications @apiGroup User @apiHeader {String} X-Session Session ID. @apiSuccess {Object[]} notifications List of notifications. @apiSuccess {String} notifications.date Notification datetime. @apiSuccess {String} notifications.username Username. @apiSuccess {String} notifications.message Message. @apiExample {curl} Example usage: curl -k -H "X-Session: fa452548403ac53f2158a65f5eb6db9723d2b07238dd83f5b6d9ca52ce817b63" https://localhost:2345/notifications @apiSuccessExample Success-Reponse: HTTP/1.0 200 OK Server: temboard-agent/0.0.1 Python/2.7.8 Date: Wed, 22 Apr 2015 12:33:19 GMT Content-type: application/json [ {"date": "2016-04-11T16:12:38", "username": "******", "message": "Login"}, {"date": "2016-04-11T16:02:03", "username": "******", "message": "Login"}, {"date": "2016-04-11T15:51:15", "username": "******", "message": "HBA file version '2016-04-11T15:32:53' removed."}, {"date": "2016-04-11T15:51:10", "username": "******", "message": "HBA file version '2016-04-11T15:47:26' removed."}, {"date": "2016-04-11T15:51:04", "username": "******", "message": "HBA file version '2016-04-11T15:48:50' removed."}, {"date": "2016-04-11T15:50:57", "username": "******", "message": "PostgreSQL reload"}, {"date": "2016-04-11T15:50:57", "username": "******", "message": "HBA file updated"}, {"date": "2016-04-11T15:48:50", "username": "******", "message": "PostgreSQL reload"} ] @apiError (500 error) error Internal error. @apiError (401 error) error Invalid session ID. @apiError (406 error) error Session ID malformed. @apiErrorExample 401 error example HTTP/1.0 401 Unauthorized Server: temboard-agent/0.0.1 Python/2.7.8 Date: Wed, 22 Apr 2015 12:36:33 GMT Content-type: application/json {"error": "Invalid session."} @apiErrorExample 406 error example HTTP/1.0 406 Not Acceptable Server: temboard-agent/0.0.1 Python/2.7.8 Date: Wed, 22 Apr 2015 12:37:23 GMT Content-type: application/json {"error": "Parameter 'X-Session' is malformed."} """ headers = http_context['headers'] set_logger_name("api") logger = get_logger(config) logger.info("Get notifications.") try: username = check_sessionid(headers, sessions) except HTTPError as e: logger.traceback(get_tb()) logger.error(e.message) logger.info("Invalid session.") raise e try: notifications = NotificationMgmt.get_last_n(config, -1) logger.info("Done.") return list(notifications) except (NotificationError, Exception) as e: logger.traceback(get_tb()) logger.error(e.message) logger.info("Failed.") raise HTTPError(500, "Internal error.")