def refresh_alerts(request, random=None): try: from datetime import datetime cmd_list = [] #this command will insert or update the row value if the row with the user exists. cmd = ["INSERT OR REPLACE INTO admin_alerts (user, last_refresh_time) values (?,?);", (request.user.username, datetime.now())] cmd_list.append(cmd) db_path, err = common.get_db_path() if err: raise Exception(err) test, err = db.execute_iud("%s/integral_view_config.db"%db_path, cmd_list) if err: raise Exception(err) new_alerts_present, err = alerts.new_alerts() if err: raise Exception(err) if new_alerts_present: import json alerts_list, err = alerts.load_alerts() if err: raise Exception(err) if not alerts_list: raise Exception('Error loading alerts') new_alerts = json.dumps([dict(alert=pn) for pn in alerts_list]) return django.http.HttpResponse(new_alerts, mimetype='application/json') else: clss = "btn btn-default btn-sm" message = "View alerts" return django.http.HttpResponse("No New Alerts") except Exception, e: return django.http.HttpResponse("Error loading alerts : %s"%str(e))
def refresh_alerts(request, random=None): try: from datetime import datetime cmd_list = [] #this command will insert or update the row value if the row with the user exists. cmd = ["INSERT OR REPLACE INTO admin_alerts (user, last_refresh_time) values (?,?);", (request.user.username, datetime.now())] cmd_list.append(cmd) db_path, err = common.get_db_path() if err: raise Exception(err) test, err = db.execute_iud(db_path, cmd_list) if err: raise Exception(err) new_alerts_present, err = alerts.new_alerts() if err: raise Exception(err) if new_alerts_present: import json alerts_list, err = alerts.load_alerts(last_n = 5) if err: raise Exception(err) if not alerts_list: raise Exception('Error loading alerts') new_alerts = json.dumps([dict(alert=pn) for pn in alerts_list]) return django.http.HttpResponse(new_alerts, content_type='application/json') else: clss = "btn btn-default btn-sm" message = "View alerts" return django.http.HttpResponse("No New Alerts") except Exception, e: return django.http.HttpResponse("Error loading alerts : %s"%str(e))
def view_rotated_log_file(request, log_type): return_dict = {} try: if log_type not in ["alerts", "audit_trail"]: return_dict["error"] = "Unknown log type" return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance = django.template.context.RequestContext(request)) if request.method != "POST": return_dict["error"] = "Unsupported request" return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance = django.template.context.RequestContext(request)) if "file_name" not in request.POST: return_dict["error"] = "Filename not specified" return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance = django.template.context.RequestContext(request)) file_name = request.POST["file_name"] if log_type == "alerts": try: l = alerts.load_alerts(file_name) return_dict["alerts_list"] = l return_dict["historical"] = True return django.shortcuts.render_to_response('view_alerts.html', return_dict, context_instance = django.template.context.RequestContext(request)) except Exception, e: return_dict["error"] = str(e) return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance = django.template.context.RequestContext(request)) else:
def view_log(request): return_dict = {} try: form = log_management_forms.ViewLogsForm(request.POST or None) if request.method == 'POST': if form.is_valid(): cd = form.cleaned_data log_type = cd['log_type'] if log_type not in ['alerts', 'audit', 'hardware', 'av']: raise Exception('Invalid log type specified') if log_type == 'alerts': alerts_list, err = alerts.load_alerts() if err: raise Exception(err) return_dict['alerts_list'] = alerts_list return django.shortcuts.render_to_response('view_alerts.html', return_dict, context_instance=django.template.context.RequestContext(request)) elif log_type == 'audit': al, err = audit.get_lines() if err: raise Exception(err) return_dict["audit_list"] = al return django.shortcuts.render_to_response('view_audit_trail.html', return_dict, context_instance=django.template.context.RequestContext(request)) elif log_type == 'av': vs_log_list,err = clamav.get_virus_scan_log() if err: raise Exception(err) return_dict['vs_log_list'] = vs_log_list return django.shortcuts.render_to_response('view_virus_scan_logs.html', return_dict, context_instance=django.template.context.RequestContext(request)) elif log_type == 'hardware': hw_platform, err = common.get_hardware_platform() if err: raise Exception(err) if not hw_platform or hw_platform != 'dell': raise Exception('Unknown hardware platform') return_dict['hw_platform'] = hw_platform if hw_platform == 'dell': from integralstor_common.platforms import dell logs_dict, err = dell.get_alert_logs() if logs_dict: return_dict['logs_dict'] = logs_dict return django.shortcuts.render_to_response('view_hardware_logs.html', return_dict, context_instance=django.template.context.RequestContext(request)) # either a get or an invalid form so send back form return_dict['form'] = form return django.shortcuts.render_to_response('view_log_form.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "logging_base.html" return_dict["page_title"] = 'System alerts' return_dict['tab'] = 'view_current_alerts_tab' return_dict["error"] = 'Error loading system alerts' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def refresh_alerts(request, random=None): from datetime import datetime cmd_list = [] #this command will insert or update the row value if the row with the user exists. cmd = ["INSERT OR REPLACE INTO admin_alerts (user, last_refresh_time) values (?,?);", (request.user.username, datetime.now())] cmd_list.append(cmd) test = db.execute_iud("%s/integral_view_config.db"%common.get_db_path(), cmd_list) if alerts.new_alerts(): import json new_alerts = json.dumps([dict(alert=pn) for pn in alerts.load_alerts()]) return django.http.HttpResponse(new_alerts, mimetype='application/json') else: clss = "btn btn-default btn-sm" message = "View alerts" return django.http.HttpResponse("No New Alerts")
def view_alerts(request): return_dict = {} try: alerts_list, err = alerts.load_alerts() if err: raise Exception(err) return_dict['alerts_list'] = alerts_list return django.shortcuts.render_to_response('view_alerts.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "logging_base.html" return_dict["page_title"] = 'System alerts' return_dict['tab'] = 'view_current_alerts_tab' return_dict["error"] = 'Error loading system alerts' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def view_rotated_log_file(request, log_type): return_dict = {} try: return_dict['tab'] = 'view_rotated_alert_log_list_tab' if log_type not in ["alerts", "audit_trail"]: raise Exception("Unknown log type") if request.method != "POST": raise Exception("Unsupported request") if "file_name" not in request.POST: raise Exception("Filename not specified") file_name = request.POST["file_name"] return_dict["historical"] = True if log_type == "alerts": return_dict['tab'] = 'view_rotated_alert_log_list_tab' l, err = alerts.load_alerts(file_name) if err: raise Exception(err) return_dict["alerts_list"] = l return django.shortcuts.render_to_response('view_alerts.html', return_dict, context_instance = django.template.context.RequestContext(request)) else: return_dict['tab'] = 'view_rotated_audit_log_list_tab' d, err = audit.get_lines(file_name) if err: raise Exception(err) return_dict["audit_list"] = d return django.shortcuts.render_to_response('view_audit_trail.html', return_dict, context_instance = django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "logging_base.html" return_dict["page_title"] = 'View rotated log file' return_dict["error"] = 'Error viewing rotated log file' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def view_rotated_log_file(request, log_type): return_dict = {} try: return_dict['tab'] = 'view_rotated_alert_log_list_tab' if log_type not in ["alerts", "audit_trail"]: raise Exception("Unknown log type") if request.method != "POST": raise Exception("Unsupported request") if "file_name" not in request.POST: raise Exception("Filename not specified") file_name = request.POST["file_name"] return_dict["historical"] = True if log_type == "alerts": return_dict['tab'] = 'view_rotated_alert_log_list_tab' l, err = alerts.load_alerts(file_name) if err: raise Exception(err) return_dict["alerts_list"] = l return django.shortcuts.render_to_response('view_alerts.html', return_dict, context_instance = django.template.context.RequestContext(request)) else: return_dict['tab'] = 'view_rotated_audit_log_list_tab' d, err = audit.get_lines(file_name) if err: raise Exception(err) return_dict["audit_list"] = d return django.shortcuts.render_to_response('view_audit_trail.html', return_dict, context_instance = django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "logging_base.html" return_dict["page_title"] = 'View rotated log file' return_dict["error"] = 'Error viewing rotated log file' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
nodes[k] = v["node_status"] if v["node_status"] != 0: num_nodes_bad += 1 pools, err = zfs.get_pools() if pools: return_dict["pools"] = pools return_dict["num_nodes_bad"] = num_nodes_bad return_dict["total_nodes"] = total_nodes return_dict["nodes"] = nodes template = "view_dashboard.html" elif page == "alerts": template = "view_alerts.html" alerts_list = alerts.load_alerts() return_dict['alerts_list'] = alerts_list return django.shortcuts.render_to_response(template, return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict["error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict["error"] = "An error occurred when processing your request : %s"%s return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request)) #this function takes a user argument checks if the user has administrator rights and then returns True. #If he does not have the correct permissions, then then it returns a HTttpResponse stating No Permission to access this page. #Takes user object as a parameter: request.user
template = "view_node_info.html" if "from" in request.GET: frm = request.GET["from"] return_dict['frm'] = frm #return_dict['node'] = si[info] return_dict['node'] = si[si.keys()[0]] elif page == "alerts": return_dict['base_template'] = "logging_base.html" return_dict["page_title"] = 'System alerts' return_dict['tab'] = 'view_current_alerts_tab' return_dict["error"] = 'Error loading system alerts' template = "view_alerts.html" alerts_list, err = alerts.load_alerts() if err: raise Exception(err) return_dict['alerts_list'] = alerts_list return django.shortcuts.render_to_response(template, return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request)) #this function takes a user argument checks if the user has administrator rights and then returns True. #If he does not have the correct permissions, then then it returns a HTttpResponse stating No Permission to access this page. #Takes user object as a parameter: request.user # def is_superuser(user): # if user.is_superuser:
def download_log(request): """ Download the system log of the type specified in log_type POST param This calls the /sys_log via an http request on that node to get the info""" return_dict = {} try: form = log_management_forms.DownloadLogsForm(request.POST or None) if request.method == 'POST': if form.is_valid(): cd = form.cleaned_data log_type = cd['log_type'] response = django.http.HttpResponse() if log_type in ['alerts', 'audit', 'hardware']: if log_type == 'alerts': response['Content-disposition'] = 'attachment; filename=alerts_log.txt' all_alerts, err = alerts.load_alerts() if err: raise Exception(err) for alert in all_alerts: response.write('%s : %s\n'%(alert['time'], alert['message'])) response.flush() elif log_type == 'audit': response['Content-disposition'] = 'attachment; filename=audit_log.txt' all_audits, err = audit.get_lines() if err: raise Exception(err) for audit_info in all_audits: response.write('Time : %s \n'%audit_info['time']) response.write('Source IP : %s \n'%audit_info['ip']) response.write('Action : %s \n'%audit_info['action']) response.write('\n') response.flush() elif log_type == 'hardware': response['Content-disposition'] = 'attachment; filename=hardware_logs.txt' hw_platform, err = common.get_hardware_platform() if not hw_platform or hw_platform != 'dell': raise Exception('Unknown hardware platform') if hw_platform == 'dell': from integralstor_common.platforms import dell logs_dict, err = dell.get_alert_logs() if err: raise Exception(err) if not logs_dict: raise Exception('No logs detected!') for timestamp, log_list in logs_dict.items(): for log in log_list: response.write('Time : %s\n'%log['date_time']) response.write('Severity : %s\n'%log['Severity']) response.write('Description : %s\n'%log['description']) response.write('\n') response.flush() else: raise Exception('Unknown platform') else: fn = {'boot':'/var/log/boot.log', 'dmesg':'/var/log/dmesg', 'message':'/var/log/messages', 'smb':'/var/log/smblog.vfs', 'winbind':'/var/log/samba/log.winbindd','ctdb':'/var/log/log.ctdb'} dn = {'boot':'boot.log', 'dmesg':'dmesg', 'message':'messages','smb':'samba_logs','winbind':'winbind_logs','ctdb':'ctdb_logs'} file_name = fn[log_type] display_name = dn[log_type] zf_name = '%s.zip'%display_name try: zf = zipfile.ZipFile(zf_name, 'w') zf.write(file_name, arcname = display_name) zf.close() except Exception as e: raise Exception("Error compressing remote log file : %s"%str(e)) response['Content-disposition'] = 'attachment; filename=%s.zip'%(display_name) response['Content-type'] = 'application/x-compressed' with open(zf_name, 'rb') as f: byte = f.read(1) while byte: response.write(byte) byte = f.read(1) response.flush() return response # either a get or an invalid form so send back form return_dict['form'] = form return django.shortcuts.render_to_response('download_log_form.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "logging_base.html" return_dict["page_title"] = 'Download system logs' return_dict['tab'] = 'download_logs_tab' return_dict["error"] = 'Error downloading system logs' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))