def get_status(): if not request.json: abort(400) target = str(request.json['target']) try: if target == 'devices': data = get_active_devices() resp = Response() resp.data = data resp.status_code = 200 resp.mimetype = "application/json" return resp elif target == 'network': data = get_network_config() resp = Response() resp.data = data resp.status_code = 200 resp.mimetype = "application/json" return resp elif target == 'alerts': timeframe = str(request.json['timeframe']) if timeframe == "alerts_week": data = utils.get_alerts_within_time(604800) elif timeframe == "alerts_month": data = utils.get_alerts_within_time(2592000) elif timeframe == "alerts_all": data = utils.get_alerts_within_time(172800000) resp = Response() resp.data = data resp.status_code = 200 resp.mimetype = "application/json" return resp elif target == 'logs': log_count = int(request.json['log_count']) data = utils.get_syslogs(log_count) resp = Response() resp.data = data resp.status_code = 200 resp.mimetype = "application/json" return resp else: abort(400) except Exception as e: log.debug('FG-WARN: ' + e.__doc__ + " - " + e.message) resp = Response() resp.status_code = 500 return resp
def get_status(): if not request.json: abort(400) target = str(request.json['target']) try: if target == 'devices': data = get_active_devices() resp = Response() resp.data = data resp.status_code = 200 resp.mimetype = "application/json" return resp elif target == 'network': data = get_network_config() resp = Response() resp.data = data resp.status_code = 200 resp.mimetype = "application/json" return resp elif target == 'alerts': data = utils.get_alerts_within_time(604800) resp = Response() resp.data = data resp.status_code = 200 resp.mimetype = "application/json" return resp else: abort(400) except Exception as e: log.debug('FG-WARN: ' + e.__doc__ + " - " + e.message) resp = Response() resp.status_code = 500 return resp
def get_status(): if not request.json: abort(400) target = str(request.json['target']) try: if target == 'devices': data = utils.get_active_devices() resp = Response() resp.data = data resp.status_code = 200 resp.mimetype = "application/json" return resp elif target == 'network': data = utils.get_network_config() resp = Response() resp.data = data resp.status_code = 200 resp.mimetype = "application/json" return resp elif target == 'alerts': timeframe = str(request.json['timeframe']) rev_filter = str(request.json['filter']) if rev_filter == "all": handledf = "all" elif rev_filter == "reviewed": handledf = "1" elif rev_filter == "notreviewed": handledf = "0" if timeframe == "alerts_week": data = utils.get_alerts_within_time(604800, handledf) elif timeframe == "alerts_month": data = utils.get_alerts_within_time(2592000, handledf) elif timeframe == "alerts_all": data = utils.get_alerts_within_time(172800000, handledf) resp = Response() resp.data = data resp.status_code = 200 resp.mimetype = "application/json" return resp elif target == 'alerts_review': alert_id = str(request.json['alert_id']) handled = str(request.json['handled']) data = utils.update_alert_handled(alert_id, handled) resp = Response() resp.data = data resp.status_code = 200 resp.mimetype = "application/json" return resp elif target == 'logs': log_count = int(request.json['log_count']) data = utils.get_syslogs(log_count) resp = Response() resp.data = data resp.status_code = 200 resp.mimetype = "application/json" return resp else: abort(400) except Exception as e: log.debug('FG-WARN: ' + e.__doc__ + " - " + e.message) resp = Response() resp.status_code = 500 return resp