def refresh_alerts(request, random=None): try: from django.utils import timezone 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, timezone.now())] cmd_list.append(cmd) db_path, err = config.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.get_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, *args): return_dict = {} try: log_type = '' if args: log_type = args[0] 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.get_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'] = "log_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_alerts(request): return_dict = {} try: alerts_list, err = alerts.get_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_alerts(request): return_dict = {} try: alerts_list, err = alerts.get_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'] = "log_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): ret = None return_dict = {} try: return_dict['base_template'] = "log_base.html" return_dict["page_title"] = 'System alerts' return_dict['tab'] = 'view_current_alerts_tab' return_dict["error"] = 'Error loading system alerts' 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 = config.get_db_path() if err: raise Exception(err) test, err = db.execute_iud("%s" % db_path, cmd_list) if err: raise Exception(err) ret, err = alerts.new_alerts() if err: raise Exception(err) if ret: alerts_list, err = alerts.get_alerts() if err: raise Exception(err) 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_dict[ "error_details"] = "An error occurred when processing your request : %s" % str( e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
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']: raise Exception('Invalid log type specified') if log_type == 'alerts': alerts_list, err = alerts.get_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_entries() 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 == 'hardware': hw_platform, err = config.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_utils.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 view_rotated_log_file(request, *args): return_dict = {} try: log_type = '' if args: log_type = args[0] 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.get_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'] = "log_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 refresh_alerts(request): ret = None return_dict = {} try: return_dict['base_template'] = "log_base.html" return_dict["page_title"] = 'System alerts' return_dict['tab'] = 'view_current_alerts_tab' return_dict["error"] = 'Error loading system alerts' 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 = config.get_db_path() if err: raise Exception(err) test, err = db.execute_iud("%s" % db_path, cmd_list) if err: raise Exception(err) ret, err = alerts.new_alerts() if err: raise Exception(err) if ret: alerts_list, err = alerts.get_alerts() if err: raise Exception(err) 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_dict["error_details"] = "An error occurred when processing your request : %s" % str( e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def show(request, page, info=None): return_dict = {} try: gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.' ) assert request.method == 'GET' vil, err = gluster_volumes.get_basic_volume_info_all() if err: raise Exception(err) si, err = system_info.load_system_config() if err: raise Exception(err) if not si: raise Exception('Could not obtain system information') #assert False return_dict['system_info'] = si return_dict['volume_info_list'] = vil # By default show error page if page == "dir_contents": dir_name = None error = False path_base = None vol_name = "" dir_list = [] try: if ("vol_name" in request.GET) and ("dir" in request.GET): vol_name = request.GET.get("vol_name") dir_name = request.GET.get("dir") first = request.GET.get("first") # print first else: raise Exception("No volume or Directory Specified") if first: dirs, err = gluster_gfapi.get_gluster_dir_list( vol_name, "") else: dirs, err = gluster_gfapi.get_gluster_dir_list( vol_name, dir_name) if err: raise Exception(err) dir_list = json.dumps(dirs) except Exception as e: return django.http.HttpResponse("Exception Occured : %s" % str(e)) #iv_logging.debug("Exception while getting dir listing : "%e) return django.http.HttpResponse(dir_list, mimetype='application/json') elif page == "integral_view_log_level": template = "view_integral_view_log_level.html" log_level, err = iv_logging.get_log_level_str() if err: raise Exception(err) return_dict["log_level_str"] = log_level if "saved" in request.REQUEST: return_dict["saved"] = request.REQUEST["saved"] elif page == "batch_start_conf": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View batch job' return_dict['tab'] = 'volume_background_tab' return_dict[ "error"] = 'Error displaying batch job creation confirmation' # Display a confirmation that the batch job has been scheduled. # info contains the filename of the batch job template = "batch_start_conf.html" return_dict["fname"] = info elif page == "batch_status": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View batch jobs' return_dict['tab'] = 'volume_background_tab' return_dict["error"] = 'Error loading batch jobs' # Load the list of entries from all the files in the start and # process directories file_list, err = batch.load_all_files() if err: raise Exception(err) return_dict["file_list"] = file_list template = "view_batch_process_list.html" elif page == "batch_status_details": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View batch job status' return_dict['tab'] = 'volume_background_tab' return_dict["error"] = 'Error loading batch job status' d, err = batch.load_specific_file(info) if err: raise Exception(err) if not d: raise Exception('Unknown batch job specified') else: return_dict["process_info"] = d template = "view_batch_status_details.html" elif page == "volume_info": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume information' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume information' vol, err = gluster_volumes.get_complete_volume_info(info) if err: raise Exception(err) if not vol: raise Exception("Could not locate information for volume %s" % info) quota_enabled = False if "options" in vol: for o in vol["options"]: if "features.quota" == o["name"] and o["value"] == "on": quota_enabled = True break return_dict['quota_enabled'] = quota_enabled template = "view_volume_info.html" return_dict["vol"] = vol data_locations_list, err = gluster_volumes.get_brick_hostname_list( vol) if err: raise Exception(err) # print data_locations_list return_dict["data_locations_list"] = data_locations_list ivl, err = iscsi.load_iscsi_volumes_list(vil) if err: raise Exception(err) if ivl and vol["name"] in ivl: return_dict["iscsi"] = True # To accomodate django template quirks # if vol["type"] in ["Replicate", "Distributed-Replicate"]: # elif vol["type"] in ["Distribute", "Distributed-Replicate"]: if 'replicate' in vol["type"].lower(): return_dict["replicate"] = True if 'distribute' in vol["type"].lower(): return_dict["distribute"] = True elif page == "volume_status": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume status' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume status' vol, err = gluster_volumes.get_volume_status(vil, info) if err: raise Exception(err) if not vol: raise Exception("Could not locate information for volume %s" % info) template = "view_volume_status.html" return_dict["vol"] = vol # To accomodate django template quirks if vol["type"] in ["Replicate", "Distributed-Replicate"]: return_dict["replicate"] = True if vol["type"] in ["Distribute", "Distributed-Replicate"]: return_dict["distribute"] = True elif page == "node_info": return_dict['base_template'] = "gridcell_base.html" return_dict["page_title"] = 'View GRIDCell information' return_dict['tab'] = 'gridcell_list_tab' return_dict["error"] = 'Error loading GRIDCell information' template = "view_node_info.html" if "from" in request.GET: frm = request.GET["from"] return_dict['frm'] = frm vol_list, err = gluster_volumes.get_volumes_on_node(info, vil) if err: raise Exception(err) return_dict['node'] = si[info] return_dict['vol_list'] = vol_list elif page == "manifest": # Read a generated manifest file and display the results. if "manifest" not in request.GET: raise Exception('Invalid request. No manifest file specified') manifest = request.GET["manifest"] ss_path, err = config.get_system_status_path() if err: raise Exception(err) with open("%s/%s" % (ss_path, manifest), "r") as f: nodes = json.load(f) return_dict["manifest"] = nodes return_dict["manifest_file"] = manifest return django.shortcuts.render_to_response( 'view_manifest.html', return_dict, context_instance=django.template.context.RequestContext( request)) elif page == "iscsi_auth_access_info": return_dict['base_template'] = "shares_and_targets_base.html" return_dict["page_title"] = 'View ISCSI authorized access info' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading ISCSI authorized access info' if 'id' not in request.GET: raise Exception('Invalid request. No auth access id specified') id = int(request.GET['id']) l, err = iscsi.load_auth_access_users_info(id) if err: raise Exception(err) if not l: raise Exception( 'No auth access information for the id specified') istr = "<b>Authorized access group users : </b>" for i in l: istr += i["user"] istr += ", " # return django.http.HttpResponse("<b>Authorized access details # </b><br>User : %s, Peer user : %s"%(d["user"],d["peer_user"] )) return django.http.HttpResponse("%s" % istr) elif page == "iscsi_initiator_info": return_dict['base_template'] = "shares_and_targets_base.html" return_dict["page_title"] = 'View ISCSI initiator info' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading ISCSI initiator info' if 'id' not in request.GET: raise Exception( 'Invalid request. No initiator access id specified') id = int(request.GET['id']) d, err = iscsi.load_initiator_info(id) if err: raise Exception(err) if not d: raise Exception( 'No initiator information for the id specified') return django.http.HttpResponse( "<b>Initiator details</b><br>Initiators : %s, Auth network : %s, Comment : %s" % (d["initiators"], d["auth_network"], d["comment"])) elif page == "system_config": template = "view_system_config.html" elif page == "system_status": return_dict['base_template'] = "gridcell_base.html" return_dict["page_title"] = 'View system status' return_dict['tab'] = 'gridcell_list_tab' return_dict["error"] = 'Error loading system status' # Disk Status page and system status page has been integrated. # Get the disk status disk_status = {} disk_new = {} if request.GET.get("node_id") is not None: disk_status = si[request.GET.get("node_id")] return_dict["disk_status"] = {} return_dict["disk_status"][request.GET.get( "node_id")] = disk_status template = "view_disk_status_details.html" else: """ Iterate the system information, and get the following data : 1. The status of every disk 2. The status of the pool 3. The name of the pool 4. Calcualte the background_color Format : {'node_id':{'name':'pool_name','background_color':'background_color','disks':{disks_pool}}} """ for key, value in si.iteritems(): # count the failures in case of Offline or degraded disk_failures = 0 # Default background color background_color = "bg-green" if not si[key]["in_cluster"]: disk_new[key] = {} disk_new[key]["disks"] = {} disk_new[key]["in_cluster"] = si[key]["in_cluster"] for disk_key, disk_value in si[key]["disks"].iteritems( ): # print disk_key, disk_value if disk_value["rotational"]: disk_new[key]["disks"][disk_key] = disk_value[ "status"] # print disk_value["status"] if disk_value["status"] != "PASSED": disk_failures += 1 if disk_failures >= 1: background_color = "bg-yellow" if disk_failures >= 4: background_color == "bg-red" if si[key]['node_status_str'] == "Degraded": background_color = "bg-yellow" # print type(si[key]["pools"][0]["state"]) if si[key]["pools"][0]["state"] == unicode("ONLINE"): background_color == "bg-red" disk_new[key]["background_color"] = background_color disk_new[key]["name"] = si[key]["pools"][0][ "pool_name"] sorted_disks = [] for key1, value1 in sorted( si[key]["disks"].iteritems(), key=lambda (k, v): v["position"]): sorted_disks.append(key1) disk_new[key]["disk_pos"] = sorted_disks # print disk_new #disk_new[key]["info"] = pool_status else: disk_status[key] = {} if si[key]["node_status"] != -1: disk_status[key]["disks"] = {} disk_status[key]["in_cluster"] = si[key][ "in_cluster"] for disk_key, disk_value in si[key][ "disks"].iteritems(): # print disk_key, disk_value if disk_value["rotational"]: disk_status[key]["disks"][ disk_key] = disk_value["status"] # print disk_value["status"] if disk_value["status"] != "PASSED": disk_failures += 1 if disk_failures >= 1: background_color = "bg-yellow" if disk_failures >= 4: background_color == "bg-red" if si[key]['node_status_str'] == "Degraded": background_color = "bg-yellow" # print type(si[key]["pools"][0]["state"]) if si[key]["pools"][0]["state"] == unicode( "ONLINE"): background_color == "bg-red" disk_status[key][ "background_color"] = background_color disk_status[key]["name"] = si[key]["pools"][0][ "pool_name"] sorted_disks = [] for key1, value1 in sorted( si[key]["disks"].iteritems(), key=lambda (k, v): v["position"]): sorted_disks.append(key1) disk_status[key]["disk_pos"] = sorted_disks # print disk_status #disk_status[key]["info"] = pool_status else: disk_status[key] = {} disk_status[key]["background_color"] = "bg-red" disk_status[key]["disk_pos"] = {} disk_status[key]["name"] = "Unknown" template = "view_disk_status.html" return_dict["disk_status"] = disk_status return_dict["disk_new"] = disk_new elif page == "pool_status": template = "view_pool_status.html" num_free_nodes = 0 for name, node in si.items(): if node["node_status"] >= 0 and (not node["in_cluster"]): num_free_nodes += 1 return_dict['num_free_nodes'] = num_free_nodes elif page == "alerts": return_dict['base_template'] = "system_log_base.html" return_dict["page_title"] = 'View alerts' return_dict['tab'] = 'system_log_alert_tab' return_dict["error"] = 'Error loading system alerts' template = "view_alerts.html" alerts_list, err = alerts.get_alerts() if err: raise Exception(err) return_dict['alerts_list'] = alerts_list elif page == "volume_info_all": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume info' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume info' template = "view_volume_info_all.html" return_dict['volume_info_list'] = vil ivl, err = iscsi.load_iscsi_volumes_list(vil) if err: raise Exception(err) return_dict['iscsi_volumes'] = ivl elif page == "volume_status_all": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume status' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume status' template = "view_volume_status_all.html" return_dict['volume_info_list'] = vil 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_details"] = "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_details"] = s return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def show(request, page, info=None): return_dict = {} try: gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.') assert request.method == 'GET' vil, err = gluster_volumes.get_basic_volume_info_all() if err: raise Exception(err) si, err = system_info.load_system_config() if err: raise Exception(err) if not si: raise Exception('Could not obtain system information') #assert False return_dict['system_info'] = si return_dict['volume_info_list'] = vil # By default show error page if page == "dir_contents": dir_name = None error = False path_base = None vol_name = "" dir_list = [] try: if ("vol_name" in request.GET) and ("dir" in request.GET): vol_name = request.GET.get("vol_name") dir_name = request.GET.get("dir") first = request.GET.get("first") # print first else: raise Exception("No volume or Directory Specified") if first: dirs, err = gluster_gfapi.get_gluster_dir_list( vol_name, "") else: dirs, err = gluster_gfapi.get_gluster_dir_list( vol_name, dir_name) if err: raise Exception(err) dir_list = json.dumps(dirs) except Exception as e: return django.http.HttpResponse("Exception Occured : %s" % str(e)) #iv_logging.debug("Exception while getting dir listing : "%e) return django.http.HttpResponse(dir_list, mimetype='application/json') elif page == "integral_view_log_level": template = "view_integral_view_log_level.html" log_level, err = iv_logging.get_log_level_str() if err: raise Exception(err) return_dict["log_level_str"] = log_level if "saved" in request.REQUEST: return_dict["saved"] = request.REQUEST["saved"] elif page == "batch_start_conf": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View batch job' return_dict['tab'] = 'volume_background_tab' return_dict["error"] = 'Error displaying batch job creation confirmation' # Display a confirmation that the batch job has been scheduled. # info contains the filename of the batch job template = "batch_start_conf.html" return_dict["fname"] = info elif page == "batch_status": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View batch jobs' return_dict['tab'] = 'volume_background_tab' return_dict["error"] = 'Error loading batch jobs' # Load the list of entries from all the files in the start and # process directories file_list, err = batch.load_all_files() if err: raise Exception(err) return_dict["file_list"] = file_list template = "view_batch_process_list.html" elif page == "batch_status_details": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View batch job status' return_dict['tab'] = 'volume_background_tab' return_dict["error"] = 'Error loading batch job status' d, err = batch.load_specific_file(info) if err: raise Exception(err) if not d: raise Exception('Unknown batch job specified') else: return_dict["process_info"] = d template = "view_batch_status_details.html" elif page == "volume_info": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume information' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume information' vol, err = gluster_volumes.get_complete_volume_info(info) if err: raise Exception(err) if not vol: raise Exception( "Could not locate information for volume %s" % info) quota_enabled = False if "options" in vol: for o in vol["options"]: if "features.quota" == o["name"] and o["value"] == "on": quota_enabled = True break return_dict['quota_enabled'] = quota_enabled template = "view_volume_info.html" return_dict["vol"] = vol data_locations_list, err = gluster_volumes.get_brick_hostname_list( vol) if err: raise Exception(err) # print data_locations_list return_dict["data_locations_list"] = data_locations_list ivl, err = iscsi.load_iscsi_volumes_list(vil) if err: raise Exception(err) if ivl and vol["name"] in ivl: return_dict["iscsi"] = True # To accomodate django template quirks # if vol["type"] in ["Replicate", "Distributed-Replicate"]: # elif vol["type"] in ["Distribute", "Distributed-Replicate"]: if 'replicate' in vol["type"].lower(): return_dict["replicate"] = True if 'distribute' in vol["type"].lower(): return_dict["distribute"] = True elif page == "volume_status": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume status' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume status' vol, err = gluster_volumes.get_volume_status(vil, info) if err: raise Exception(err) if not vol: raise Exception( "Could not locate information for volume %s" % info) template = "view_volume_status.html" return_dict["vol"] = vol # To accomodate django template quirks if vol["type"] in ["Replicate", "Distributed-Replicate"]: return_dict["replicate"] = True if vol["type"] in ["Distribute", "Distributed-Replicate"]: return_dict["distribute"] = True elif page == "node_info": return_dict['base_template'] = "gridcell_base.html" return_dict["page_title"] = 'View GRIDCell information' return_dict['tab'] = 'gridcell_list_tab' return_dict["error"] = 'Error loading GRIDCell information' template = "view_node_info.html" if "from" in request.GET: frm = request.GET["from"] return_dict['frm'] = frm vol_list, err = gluster_volumes.get_volumes_on_node(info, vil) if err: raise Exception(err) return_dict['node'] = si[info] return_dict['vol_list'] = vol_list elif page == "manifest": # Read a generated manifest file and display the results. if "manifest" not in request.GET: raise Exception('Invalid request. No manifest file specified') manifest = request.GET["manifest"] ss_path, err = config.get_system_status_path() if err: raise Exception(err) with open("%s/%s" % (ss_path, manifest), "r") as f: nodes = json.load(f) return_dict["manifest"] = nodes return_dict["manifest_file"] = manifest return django.shortcuts.render_to_response('view_manifest.html', return_dict, context_instance=django.template.context.RequestContext(request)) elif page == "iscsi_auth_access_info": return_dict['base_template'] = "shares_and_targets_base.html" return_dict["page_title"] = 'View ISCSI authorized access info' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading ISCSI authorized access info' if 'id' not in request.GET: raise Exception('Invalid request. No auth access id specified') id = int(request.GET['id']) l, err = iscsi.load_auth_access_users_info(id) if err: raise Exception(err) if not l: raise Exception( 'No auth access information for the id specified') istr = "<b>Authorized access group users : </b>" for i in l: istr += i["user"] istr += ", " # return django.http.HttpResponse("<b>Authorized access details # </b><br>User : %s, Peer user : %s"%(d["user"],d["peer_user"] )) return django.http.HttpResponse("%s" % istr) elif page == "iscsi_initiator_info": return_dict['base_template'] = "shares_and_targets_base.html" return_dict["page_title"] = 'View ISCSI initiator info' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading ISCSI initiator info' if 'id' not in request.GET: raise Exception( 'Invalid request. No initiator access id specified') id = int(request.GET['id']) d, err = iscsi.load_initiator_info(id) if err: raise Exception(err) if not d: raise Exception( 'No initiator information for the id specified') return django.http.HttpResponse("<b>Initiator details</b><br>Initiators : %s, Auth network : %s, Comment : %s" % (d["initiators"], d["auth_network"], d["comment"])) elif page == "system_config": template = "view_system_config.html" elif page == "system_status": return_dict['base_template'] = "gridcell_base.html" return_dict["page_title"] = 'View system status' return_dict['tab'] = 'gridcell_list_tab' return_dict["error"] = 'Error loading system status' # Disk Status page and system status page has been integrated. # Get the disk status disk_status = {} disk_new = {} if request.GET.get("node_id") is not None: disk_status = si[request.GET.get("node_id")] return_dict["disk_status"] = {} return_dict["disk_status"][request.GET.get( "node_id")] = disk_status template = "view_disk_status_details.html" else: """ Iterate the system information, and get the following data : 1. The status of every disk 2. The status of the pool 3. The name of the pool 4. Calcualte the background_color Format : {'node_id':{'name':'pool_name','background_color':'background_color','disks':{disks_pool}}} """ for key, value in si.iteritems(): # count the failures in case of Offline or degraded disk_failures = 0 # Default background color background_color = "bg-green" if not si[key]["in_cluster"]: disk_new[key] = {} disk_new[key]["disks"] = {} disk_new[key]["in_cluster"] = si[key]["in_cluster"] for disk_key, disk_value in si[key]["disks"].iteritems(): # print disk_key, disk_value if disk_value["rotational"]: disk_new[key]["disks"][disk_key] = disk_value["status"] # print disk_value["status"] if disk_value["status"] != "PASSED": disk_failures += 1 if disk_failures >= 1: background_color = "bg-yellow" if disk_failures >= 4: background_color == "bg-red" if si[key]['node_status_str'] == "Degraded": background_color = "bg-yellow" # print type(si[key]["pools"][0]["state"]) if si[key]["pools"][0]["state"] == unicode("ONLINE"): background_color == "bg-red" disk_new[key]["background_color"] = background_color disk_new[key]["name"] = si[key]["pools"][0]["pool_name"] sorted_disks = [] for key1, value1 in sorted(si[key]["disks"].iteritems(), key=lambda (k, v): v["position"]): sorted_disks.append(key1) disk_new[key]["disk_pos"] = sorted_disks # print disk_new #disk_new[key]["info"] = pool_status else: disk_status[key] = {} if si[key]["node_status"] != -1: disk_status[key]["disks"] = {} disk_status[key]["in_cluster"] = si[key]["in_cluster"] for disk_key, disk_value in si[key]["disks"].iteritems(): # print disk_key, disk_value if disk_value["rotational"]: disk_status[key]["disks"][disk_key] = disk_value["status"] # print disk_value["status"] if disk_value["status"] != "PASSED": disk_failures += 1 if disk_failures >= 1: background_color = "bg-yellow" if disk_failures >= 4: background_color == "bg-red" if si[key]['node_status_str'] == "Degraded": background_color = "bg-yellow" # print type(si[key]["pools"][0]["state"]) if si[key]["pools"][0]["state"] == unicode("ONLINE"): background_color == "bg-red" disk_status[key]["background_color"] = background_color disk_status[key]["name"] = si[key]["pools"][0]["pool_name"] sorted_disks = [] for key1, value1 in sorted(si[key]["disks"].iteritems(), key=lambda (k, v): v["position"]): sorted_disks.append(key1) disk_status[key]["disk_pos"] = sorted_disks # print disk_status #disk_status[key]["info"] = pool_status else: disk_status[key] = {} disk_status[key]["background_color"] = "bg-red" disk_status[key]["disk_pos"] = {} disk_status[key]["name"] = "Unknown" template = "view_disk_status.html" return_dict["disk_status"] = disk_status return_dict["disk_new"] = disk_new elif page == "pool_status": template = "view_pool_status.html" num_free_nodes = 0 for name, node in si.items(): if node["node_status"] >= 0 and (not node["in_cluster"]): num_free_nodes += 1 return_dict['num_free_nodes'] = num_free_nodes elif page == "alerts": return_dict['base_template'] = "system_log_base.html" return_dict["page_title"] = 'View alerts' return_dict['tab'] = 'system_log_alert_tab' return_dict["error"] = 'Error loading system alerts' template = "view_alerts.html" alerts_list, err = alerts.get_alerts() if err: raise Exception(err) return_dict['alerts_list'] = alerts_list elif page == "volume_info_all": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume info' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume info' template = "view_volume_info_all.html" return_dict['volume_info_list'] = vil ivl, err = iscsi.load_iscsi_volumes_list(vil) if err: raise Exception(err) return_dict['iscsi_volumes'] = ivl elif page == "volume_status_all": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume status' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume status' template = "view_volume_status_all.html" return_dict['volume_info_list'] = vil 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_details"] = "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_details"] = s return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
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.get_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 = config.get_hardware_platform() if not hw_platform or hw_platform != 'dell': raise Exception('Unknown hardware platform') if hw_platform == 'dell': from integralstor_utils.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))