def disk_action(**kwargs):
    ret = False
    try:
        if 'action' not in kwargs or kwargs['action'] not in ['disk_blink', 'disk_unblink']:
            raise Exception('Invalid disk action')

        our_hw_platform, err = config.get_hardware_platform()
        if err:
            raise Exception(err)
        if our_hw_platform == 'dell':
            if 'controller' not in kwargs or 'target_id' not in kwargs or 'channel' not in kwargs or 'enclosure_id' not in kwargs:
                raise Exception(
                    'Insufficient information received for the specified action')
            from integralstor_utils.platforms import dell
            err = None
            if kwargs['action'] == 'disk_blink':
                ret, err = dell.blink_unblink_disk(
                    'blink', kwargs['controller'], kwargs['channel'], kwargs['enclosure_id'], kwargs['target_id'])
            elif kwargs['action'] == 'disk_unblink':
                ret, err = dell.blink_unblink_disk(
                    'unblink', kwargs['controller'], kwargs['channel'], kwargs['enclosure_id'], kwargs['target_id'])
            if err:
                raise Exception(err)
        else:
            raise Exception(
                'Unsupported hardware platform for the specified action')
    except Exception, e:
        return ret, str(e)
Exemplo n.º 2
0
class ViewLogsForm(forms.Form):
    """ Form to get the info about which log to view"""

    ch = [('alerts', 'Alerts log'), ('audit', 'Audit log')]
    hw_platform, err = config.get_hardware_platform()
    if hw_platform and hw_platform == 'dell':
        ch.append(('hardware', 'Hardware log'))
    log_type = forms.ChoiceField(choices=ch)
Exemplo n.º 3
0
class DownloadLogsForm(forms.Form):
    """ Form to get the info about which log to download"""

    ch = [('boot', 'Boot log'), ('dmesg', 'Dmesg log'), ('message', 'Message log'), ('smb', 'Samba logs'),
          ('winbind', 'Samba Winbind logs'), ('alerts', 'Alerts log'), ('audit', 'Audit log')]
    hw_platform, err = config.get_hardware_platform()
    if hw_platform and hw_platform == 'dell':
        ch.append(('hardware', 'Hardware log'))
    log_type = forms.ChoiceField(choices=ch)
def get_ipmi_status():
    """Hardware status using IPMI."""
    ipmi_status = []
    try:
        fil = os.popen("ipmitool sdr")
        str4 = fil.read()
        lines = re.split("\r?\n", str4)
        ipmi_status = []
        for line in lines:
            l = line.rstrip()
            if not l:
                continue
            # print l
            comp_list = l.split('|')
            comp = comp_list[0].strip()
            status = comp_list[2].strip()
            hw_platform, err = config.get_hardware_platform()
            if status != "ns":
                if hw_platform and hw_platform == 'dell':
                    if ('fan' not in comp.lower()) and ('PS' not in comp) and ('voltage' not in comp.lower()) and ('current' not in comp.lower()) and (comp not in ['Inlet Temp', 'CMOS Battery', 'Pwr Consumption', 'Temp']):
                        continue
                td = {}
                td["parameter_name"] = comp_list[0].strip()
                td["reading"] = comp_list[1].strip()
                td["status"] = comp_list[2].strip()
                '''
        if comp in ["CPU Temp", "CPU1 Temperature"]:
          td["parameter_name"] = "CPU Temperature"
          td["component_name"] = "CPU"
        elif comp in ["System Temp", "MB1 Temperature"]:
          td["parameter_name"] = "System Temperature"
          td["component_name"] = "System"
        elif comp == "DIMMA1 Temp":
          td["parameter_name"] = "Memory card 1 temperature"
          td["component_name"] = "Memory card 1"
        elif comp == "DIMMA2 Temp":
          td["parameter_name"] = "Memory card 2 temperature"
          td["component_name"] = "Memory card 2"
        elif comp == "DIMMA3 Temp":
          td["parameter_name"] = "Memory card 3 temperature"
          td["component_name"] = "Memory card 3"
        elif comp == "FAN1":
          td["parameter_name"] = "Fan 1 speed"
          td["component_name"] = "Fan 1"
        elif comp == "FAN2":
          td["parameter_name"] = "Fan 2 speed"
          td["component_name"] = "Fan 2"
        elif comp == "FAN3":
          td["parameter_name"] = "Fan 3 speed"
          td["component_name"] = "Fan 3"
        elif comp == "CPU_FAN1":
          td["parameter_name"] = "CPU Fan"
          td["component_name"] = "CPU Fan"
        '''
                ipmi_status.append(td)
    except Exception, e:
        return None, 'Error retrieving IPMI information: %s' % str(e)
def get_hardware_specific_info():
    return_dict = {}
    try:
        hw_platform, err = config.get_hardware_platform()
        if hw_platform:
            return_dict['hw_platform'] = hw_platform
            if hw_platform == 'dell':
                return_dict['hw_platform'] = 'dell'
                from integralstor_utils.platforms import dell
                idrac_url, err = dell.get_idrac_addr()
                if idrac_url:
                    return_dict['idrac_url'] = idrac_url
    except Exception, e:
        return None, 'Error retrieving hardware specific information: %s' % str(e)
def get_hardware_specific_info():
    return_dict = {}
    try:
        hw_platform, err = config.get_hardware_platform()
        if hw_platform:
            return_dict['hw_platform'] = hw_platform
            if hw_platform == 'dell':
                return_dict['hw_platform'] = 'dell'
                from integralstor_utils.platforms import dell
                idrac_url, err = dell.get_idrac_addr()
                if idrac_url:
                    return_dict['idrac_url'] = idrac_url
    except Exception, e:
        return None, 'Error retrieving hardware specific information: %s' % str(
            e)
Exemplo n.º 7
0
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))
Exemplo n.º 8
0
def view_disks(request):
    return_dict = {}
    try:
        if "ack" in request.GET:
            if request.GET["ack"] == "blink":
                return_dict[
                    'ack_message'] = "Disk identification LED successfully activated"
            elif request.GET["ack"] == "unblink":
                return_dict[
                    'ack_message'] = "Disk identification LED successfully de-activated"
        si, err = system_info.load_system_config()
        if err:
            raise Exception(err)
        if not si:
            raise Exception('Error loading system configuration')
        hw_platform, err = config.get_hardware_platform()
        if hw_platform:
            return_dict['hw_platform'] = hw_platform
            if hw_platform == 'dell':
                from integralstor_utils.platforms import dell
                idrac_url, err = dell.get_idrac_addr()
                if idrac_url:
                    return_dict['idrac_url'] = idrac_url
        return_dict['node'] = si[si.keys()[0]]
        return_dict['system_info'] = si
        return_dict["disk_status"] = si[si.keys()[0]]['disks']
        return_dict['node_name'] = si.keys()[0]
        return django.shortcuts.render_to_response(
            'view_disks.html',
            return_dict,
            context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "storage_base.html"
        return_dict["page_title"] = 'Disks'
        return_dict['tab'] = 'view_disks_tab'
        return_dict["error"] = 'Error loading disk information'
        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 disk_action(**kwargs):
    ret = False
    try:
        if 'action' not in kwargs or kwargs['action'] not in [
                'disk_blink', 'disk_unblink'
        ]:
            raise Exception('Invalid disk action')

        our_hw_platform, err = config.get_hardware_platform()
        if err:
            raise Exception(err)
        if our_hw_platform == 'dell':
            if 'controller' not in kwargs or 'target_id' not in kwargs or 'channel' not in kwargs or 'enclosure_id' not in kwargs:
                raise Exception(
                    'Insufficient information received for the specified action'
                )
            from integralstor_utils.platforms import dell
            err = None
            if kwargs['action'] == 'disk_blink':
                ret, err = dell.blink_unblink_disk('blink',
                                                   kwargs['controller'],
                                                   kwargs['channel'],
                                                   kwargs['enclosure_id'],
                                                   kwargs['target_id'])
            elif kwargs['action'] == 'disk_unblink':
                ret, err = dell.blink_unblink_disk('unblink',
                                                   kwargs['controller'],
                                                   kwargs['channel'],
                                                   kwargs['enclosure_id'],
                                                   kwargs['target_id'])
            if err:
                raise Exception(err)
        else:
            raise Exception(
                'Unsupported hardware platform for the specified action')
    except Exception, e:
        return ret, str(e)
Exemplo n.º 10
0
def get_disk_status(disk_name):
    """Get the smart status of dell hw raid status if applicable of a disk given its name """
    return_list = []
    try:
        hw_platform, err = config.get_hardware_platform()
        hw_raid = False
        disk_hw_info_all = {}
        if hw_platform and hw_platform == 'dell':
            from platforms import dell
            disk_hw_info_tmp, err = dell.get_all_disks(0)
            iter = 1
            while disk_hw_info_tmp:
                disk_hw_info_all.update(disk_hw_info_tmp)
                disk_hw_info_tmp, err = dell.get_all_disks(iter)
                iter += 1
            raid_to_unix_mapping, err = dell.get_hardware_raid_to_unix_mapping()
            if raid_to_unix_mapping and '/dev/%s' % disk_name in raid_to_unix_mapping.keys():
                # Its a hardware RAID so pull the underlying info
                hw_raid = True
                controller_id = raid_to_unix_mapping['/dev/%s' %
                                                     disk_name]['controller_number']
                device_id = raid_to_unix_mapping['/dev/%s' %
                                                 disk_name]['device_id']
                disk_list, err = dell.get_hardware_raid_hard_drives(
                    controller_id, device_id)
                if disk_list:
                    for disk in disk_list:
                        disk_dict = {}
                        disk_dict['serial_number'] = disk['serial_number']
                        disk_dict['hw_raid'] = True
                        disk_dict['status'] = disk['status']
                    return_list.append(disk_dict)
        if not hw_raid:
            disk_dict = {}
            serial_number, err = get_serial_number(disk_name)
            if err:
                raise Exception(err)
            disk_dict['serial_number'] = serial_number
            status, err = get_smart_status(disk_name)
            if err:
                raise Exception(err)
            disk_dict['status'] = status
            return_list.append(disk_dict)

        partitions, err = get_partitions(disk_name)
        if err:
            raise Exception(err)
        scsi_info, err = get_disk_scsi_info(disk_name)
        if err:
            raise Exception(err)
        os_devices, err = get_os_devices()
        if err:
            raise Exception(err)
        for disk_dict in return_list:
            disk_dict['os_device'] = False
            if partitions:
                disk_dict['partitions'] = partitions
                for partition in partitions:
                    if partition['name'] in os_devices:
                        disk_dict['os_device'] = True
            if scsi_info:
                disk_dict['scsi_info'] = scsi_info
            disk_dict['name'] = disk_name
            disk_dict['path'] = '/dev/%s' % disk_name
            if hw_platform and hw_platform == 'dell':
                if disk_hw_info_all and disk_dict['serial_number'] in disk_hw_info_all.keys():
                    disk_dict['target_id'] = disk_hw_info_all[serial_number]['target_id']
                    disk_dict['controller_number'] = disk_hw_info_all[serial_number]['controller_number']
                    disk_dict['enclosure_id'] = disk_hw_info_all[serial_number]['enclosure_id']
                    disk_dict['channel'] = disk_hw_info_all[serial_number]['channel']
    except Exception, e:
        return None, "Error getting disk status : %s" % str(e)
Exemplo n.º 11
0
def get_ipmi_status():
    """Hardware status using IPMI."""
    ipmi_status = []
    try:
        fil = os.popen("ipmitool sdr")
        str4 = fil.read()
        lines = re.split("\r?\n", str4)
        ipmi_status = []
        for line in lines:
            l = line.rstrip()
            if not l:
                continue
            # print l
            comp_list = l.split('|')
            comp = comp_list[0].strip()
            status = comp_list[2].strip()
            hw_platform, err = config.get_hardware_platform()
            if status != "ns":
                if hw_platform and hw_platform == 'dell':
                    if ('fan' not in comp.lower()) and ('PS' not in comp) and (
                            'voltage' not in comp.lower()
                    ) and ('current' not in comp.lower()) and (comp not in [
                            'Inlet Temp', 'CMOS Battery', 'Pwr Consumption',
                            'Temp'
                    ]):
                        continue
                td = {}
                td["parameter_name"] = comp_list[0].strip()
                td["reading"] = comp_list[1].strip()
                td["status"] = comp_list[2].strip()
                '''
        if comp in ["CPU Temp", "CPU1 Temperature"]:
          td["parameter_name"] = "CPU Temperature"
          td["component_name"] = "CPU"
        elif comp in ["System Temp", "MB1 Temperature"]:
          td["parameter_name"] = "System Temperature"
          td["component_name"] = "System"
        elif comp == "DIMMA1 Temp":
          td["parameter_name"] = "Memory card 1 temperature"
          td["component_name"] = "Memory card 1"
        elif comp == "DIMMA2 Temp":
          td["parameter_name"] = "Memory card 2 temperature"
          td["component_name"] = "Memory card 2"
        elif comp == "DIMMA3 Temp":
          td["parameter_name"] = "Memory card 3 temperature"
          td["component_name"] = "Memory card 3"
        elif comp == "FAN1":
          td["parameter_name"] = "Fan 1 speed"
          td["component_name"] = "Fan 1"
        elif comp == "FAN2":
          td["parameter_name"] = "Fan 2 speed"
          td["component_name"] = "Fan 2"
        elif comp == "FAN3":
          td["parameter_name"] = "Fan 3 speed"
          td["component_name"] = "Fan 3"
        elif comp == "CPU_FAN1":
          td["parameter_name"] = "CPU Fan"
          td["component_name"] = "CPU Fan"
        '''
                ipmi_status.append(td)
    except Exception, e:
        return None, 'Error retrieving IPMI information: %s' % str(e)
Exemplo n.º 12
0
def get_disk_status(disk_name):
    """Get the smart status of dell hw raid status if applicable of a disk given its name """
    return_list = []
    try:
        hw_platform, err = config.get_hardware_platform()
        hw_raid = False
        disk_hw_info_all = {}
        if hw_platform and hw_platform == 'dell':
            from platforms import dell
            disk_hw_info_tmp, err = dell.get_all_disks(0)
            iter = 1
            while disk_hw_info_tmp:
                disk_hw_info_all.update(disk_hw_info_tmp)
                disk_hw_info_tmp, err = dell.get_all_disks(iter)
                iter += 1
            raid_to_unix_mapping, err = dell.get_hardware_raid_to_unix_mapping(
            )
            if raid_to_unix_mapping and '/dev/%s' % disk_name in raid_to_unix_mapping.keys(
            ):
                # Its a hardware RAID so pull the underlying info
                hw_raid = True
                controller_id = raid_to_unix_mapping[
                    '/dev/%s' % disk_name]['controller_number']
                device_id = raid_to_unix_mapping['/dev/%s' %
                                                 disk_name]['device_id']
                disk_list, err = dell.get_hardware_raid_hard_drives(
                    controller_id, device_id)
                if disk_list:
                    for disk in disk_list:
                        disk_dict = {}
                        disk_dict['serial_number'] = disk['serial_number']
                        disk_dict['hw_raid'] = True
                        disk_dict['status'] = disk['status']
                    return_list.append(disk_dict)
        if not hw_raid:
            disk_dict = {}
            serial_number, err = get_serial_number(disk_name)
            if err:
                raise Exception(err)
            disk_dict['serial_number'] = serial_number
            status, err = get_smart_status(disk_name)
            if err:
                raise Exception(err)
            disk_dict['status'] = status
            return_list.append(disk_dict)

        partitions, err = get_partitions(disk_name)
        if err:
            raise Exception(err)
        scsi_info, err = get_disk_scsi_info(disk_name)
        if err:
            raise Exception(err)
        os_devices, err = get_os_devices()
        if err:
            raise Exception(err)
        for disk_dict in return_list:
            disk_dict['os_device'] = False
            if partitions:
                disk_dict['partitions'] = partitions
                for partition in partitions:
                    if partition['name'] in os_devices:
                        disk_dict['os_device'] = True
            if scsi_info:
                disk_dict['scsi_info'] = scsi_info
            disk_dict['name'] = disk_name
            disk_dict['path'] = '/dev/%s' % disk_name
            if hw_platform and hw_platform == 'dell':
                if disk_hw_info_all and disk_dict[
                        'serial_number'] in disk_hw_info_all.keys():
                    disk_dict['target_id'] = disk_hw_info_all[serial_number][
                        'target_id']
                    disk_dict['controller_number'] = disk_hw_info_all[
                        serial_number]['controller_number']
                    disk_dict['enclosure_id'] = disk_hw_info_all[
                        serial_number]['enclosure_id']
                    disk_dict['channel'] = disk_hw_info_all[serial_number][
                        'channel']
    except Exception, e:
        return None, "Error getting disk status : %s" % str(e)
Exemplo n.º 13
0
def view_dashboard(request, page):
    return_dict = {}
    try:
        return_dict["page_title"] = 'Overall system health'
        return_dict['tab'] = 'system_health_tab'
        return_dict["error"] = 'Error loading system health data'

        if request.method != 'GET':
            raise Exception('Invalid access method. Please use the menus')

        si, err = system_info.load_system_config()
        if err:
            raise Exception(err)
        if not si:
            raise Exception('Error loading system configuration')

        node_name = si.keys()[0]
        node = si[node_name]
        return_dict['node'] = node
        # print node.keys()

        # By default show error page
        template = "logged_in_error.html"

        # Chart specific declarations
        # will return 02, instead of 2.
        todays_date = (datetime.date.today()).strftime('%02d')
        start_hour = '%02d' % (datetime.datetime.today().hour - 3)
        end_hour = '%02d' % (datetime.datetime.today().hour)
        minute = '%02d' % (datetime.datetime.today().minute)
        start = str(start_hour) + ":" + str(minute) + str(":10")
        end = str(end_hour) + ":" + str(minute) + str(":40")

        value_list = []
        time_list = []

        num_bad_disks = 0
        num_hw_raid_bad_disks = 0
        num_hw_raid_ctrl_disks = 0
        num_smart_ctrl_disks = 0
        num_disks = len(node['disks'])
        disks_ok = True
        for sn, disk in node['disks'].items():
            if 'status' in disk:
                if 'hw_raid' in disk:
                    if not disk['hw_raid']:
                        num_smart_ctrl_disks += 1
                        if (disk['status'] is not None
                                and disk['status'].upper()
                                not in ['PASSED', 'OK']):
                            num_bad_disks += 1
                            disks_ok = False
                    else:
                        num_hw_raid_ctrl_disks += 1
                        if (disk['status'] is not None
                                and disk['status'].upper() != 'OK'):
                            num_hw_raid_bad_disks += 1
                            disks_ok = False
                else:
                    # Assume its a non raid disk
                    num_smart_ctrl_disks += 1
                    if (disk['status'] is not None and disk['status'].upper()
                            not in ['PASSED', 'OK']):
                        num_bad_disks += 1
                        disks_ok = False

        return_dict['num_disks'] = num_disks
        return_dict['num_bad_disks'] = num_bad_disks
        return_dict['disks_ok'] = disks_ok
        return_dict['num_hw_raid_bad_disks'] = num_hw_raid_bad_disks
        return_dict['num_hw_raid_ctrl_disks'] = num_hw_raid_ctrl_disks
        return_dict['num_smart_ctrl_disks'] = num_smart_ctrl_disks

        if 'ipmi_status' in node:
            num_sensors = len(node['ipmi_status'])
            num_bad_sensors = 0
            ipmi_ok = True
            for sensor in node['ipmi_status']:
                if sensor['status'] in ['ok', 'nr', 'na']:
                    continue
                else:
                    num_bad_sensors += 1
                    ipmi_ok = False
            return_dict['num_sensors'] = num_sensors
            return_dict['num_bad_sensors'] = num_bad_sensors
            return_dict['ipmi_ok'] = ipmi_ok

        services_dict, err = services_management.get_sysd_services_status()
        if err:
            raise Exception(err)

        num_services = len(services_dict)
        num_failed_services = 0
        num_active_services = 0
        num_inactive_services = 0
        services_ok = True

        if services_dict:
            for service, service_d in services_dict.items():
                if service_d["info"]["status"]["status_str"] == "Active":
                    num_active_services += 1
                elif service_d["info"]["status"]["status_str"] == "Inactive":
                    num_inactive_services += 1
                elif service_d["info"]["status"]["status_str"] == "Failed":
                    num_failed_services += 1
                    services_ok = False
                elif service_d["info"]["status"][
                        "status_str"] == "Unknown State":
                    num_failed_services += 1
                    services_ok = False
            return_dict['num_services'] = num_services
            return_dict['num_active_services'] = num_active_services
            return_dict['num_inactive_services'] = num_inactive_services
            return_dict['num_failed_services'] = num_failed_services
            return_dict['services_ok'] = services_ok
        else:
            raise Exception('Error retrieving services status')

        pools, err = zfs.get_pools()
        if err:
            raise Exception(err)

        num_pools = len(pools)
        num_bad_pools = 0
        num_degraded_pools = 0
        num_high_usage_pools = 0
        for pool in pools:
            if pool['usage']['capacity']['value'] > 75:
                num_high_usage_pools += 1
            if pool['config']['pool']['root']['status']['state'] == 'ONLINE':
                pass
            elif pool['config']['pool']['root']['status'][
                    'state'] == 'DEGRADED':
                num_degraded_pools += 1
            else:
                num_bad_pools += 1
        return_dict['num_pools'] = num_pools
        return_dict['num_bad_pools'] = num_bad_pools
        return_dict['num_degraded_pools'] = num_degraded_pools
        return_dict['num_high_usage_pools'] = num_high_usage_pools

        load_avg_ok = True
        if (node["load_avg"]["5_min"] > node["load_avg"]["cpu_cores"]) or (
                node["load_avg"]["15_min"] > node["load_avg"]["cpu_cores"]):
            load_avg_ok = False
        return_dict['load_avg_ok'] = load_avg_ok

        shares_list, err = cifs_common.get_shares_list()
        if err:
            raise Exception(err)
        return_dict['num_cifs_shares'] = len(shares_list)

        exports_list, err = nfs.load_exports_list()
        if err:
            raise Exception(err)
        return_dict['num_nfs_exports'] = len(exports_list)

        target_list, err = iscsi_stgt.get_targets()
        if err:
            raise Exception(err)
        return_dict['num_iscsi_targets'] = len(target_list)

        with open('/proc/uptime', 'r') as f:
            uptime_seconds = float(f.readline().split()[0])
            uptime_str = '%s hours' % (':'.join(
                str(timedelta(seconds=uptime_seconds)).split(':')[:2]))
            return_dict['uptime_str'] = uptime_str

        # CPU status
        if page == "cpu":
            return_dict["page_title"] = 'CPU statistics'
            return_dict['tab'] = 'cpu_tab'
            return_dict["error"] = 'Error loading CPU statistics'
            cpu, err = stats.get_system_stats(todays_date, start, end, "cpu")
            if err:
                raise Exception(err)
            value_dict = {}
            if cpu:
                for key in cpu.keys():
                    value_list = []
                    time_list = []
                    if key == "date":
                        pass
                    else:
                        if cpu[key]:
                            for a in cpu[key]:
                                time_list.append(a[0])
                                value_list.append(a[1])
                        value_dict[key] = value_list
            return_dict["data_dict"] = value_dict
            queue, err = stats.get_system_stats(todays_date, start, end,
                                                "queue")
            if err:
                raise Exception(err)
            value_dict = {}
            if queue:
                for key in queue.keys():
                    value_list = []
                    time_list = []
                    if key == "date":
                        pass
                    else:
                        for a in queue[key]:
                            time_list.append(a[0])
                            value_list.append(a[1])
                        value_dict[key] = value_list
            return_dict["data_dict_queue"] = value_dict
            return_dict['node_name'] = node_name
            return_dict['node'] = si[node_name]
            d = {}
            template = "view_cpu_stats.html"
        elif page == "sys_health":
            return_dict["page_title"] = 'Overall system health'
            return_dict['tab'] = 'system_health_tab'
            return_dict["error"] = 'Error loading system health data'
            template = "view_dashboard.html"
            hw_platform, err = config.get_hardware_platform()
            if hw_platform:
                return_dict['hw_platform'] = hw_platform
                if hw_platform == 'dell':
                    from integralstor_utils.platforms import dell
                    idrac_url, err = dell.get_idrac_addr()
                    if idrac_url:
                        return_dict['idrac_url'] = idrac_url
        # Memory
        elif page == "memory":
            return_dict["page_title"] = 'Memory statistics'
            return_dict['tab'] = 'memory_tab'
            return_dict["error"] = 'Error loading memory statistics'
            mem, err = stats.get_system_stats(todays_date, start, end,
                                              "memory")
            if err:
                raise Exception(err)
            if mem:
                for a in mem["memused"]:
                    time_list.append(a[0])
                    value_list.append((a[1] / (1024 * 1024)))
            return_dict['memory_status'] = si[node_name]['memory']
            template = "view_memory_stats.html"
        # Network
        elif page == "network":
            return_dict["page_title"] = 'Network statistics'
            return_dict['tab'] = 'network_tab'
            return_dict["error"] = 'Error loading Network statistics'
            network, err = stats.get_system_stats(todays_date, start, end,
                                                  "network")
            if err:
                raise Exception(err)
            value_dict = {}
            if network:
                for key in network.keys():
                    value_list = []
                    time_list = []
                    if key == "date" or key == "lo":
                        pass
                    else:
                        for a in network[key]["ifutil-percent"]:
                            time_list.append(a[0])
                            value_list.append(a[1])
                        value_dict[key] = value_list

            return_dict["data_dict"] = value_dict
            return_dict["network_status"] = si[node_name]['interfaces']
            template = "view_network_stats.html"
        return_dict["labels"] = time_list
        return_dict["data"] = value_list
        return django.shortcuts.render_to_response(
            template,
            return_dict,
            context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "dashboard_base.html"
        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))
Exemplo n.º 14
0
def get_disk_info(disk_name):
    """Get all details about a disk given its name """

    # Given a disk name like sda, get the disk info
    return_list = []
    try:
        ids, err = get_disk_ids(disk_name)
        if err:
            raise Exception(err)
        disk_id = None
        if ids:
            for id in ids:
                if id.startswith('scsi'):
                    disk_id = id
                    break
        if not disk_id:
            for id in ids:
                if id.startswith('ata'):
                    disk_id = id
                    break
        if not disk_id:
            for id in ids:
                if id.startswith('wwn'):
                    disk_id = id
                    break

        capacity, err = get_capacity(disk_name)
        if err:
            raise Exception(err)

        rotational, err = is_rotational(disk_name)
        if err:
            raise Exception(err)

        partitions, err = get_partitions(disk_name)
        if err:
            raise Exception(err)

        scsi_info, err = get_disk_scsi_info(disk_name)
        if err:
            raise Exception(err)

        raid = False
        hw_platform, err = config.get_hardware_platform()
        if hw_platform and hw_platform == 'dell':
            from platforms import dell
            disk_hw_info_all, err = dell.get_all_disks(0)
            raid_to_unix_mapping, err = dell.get_hardware_raid_to_unix_mapping(
            )
            if raid_to_unix_mapping and '/dev/%s' % disk_name in raid_to_unix_mapping.keys(
            ):
                # Its a hardware RAID so pull the underlying info
                raid = True
                controller_id = raid_to_unix_mapping[
                    '/dev/%s' % disk_name]['controller_number']
                device_id = raid_to_unix_mapping['/dev/%s' %
                                                 disk_name]['device_id']
                disk_list, err = dell.get_hardware_raid_hard_drives(
                    controller_id, device_id)
                if disk_list:
                    for disk in disk_list:
                        disk_dict = {}
                        disk_dict['serial_number'] = disk['serial_number']
                        disk_dict['name'] = disk_name
                        disk_dict['path'] = '/dev/%s' % disk_name
                        disk_dict['id'] = disk_id
                        disk_dict['capacity'] = capacity
                        disk_dict['rotational'] = rotational
                        disk_dict['partitions'] = partitions
                        disk_dict['status'] = disk['status']
                        disk_dict['scsi_info'] = scsi_info
                        disk_dict['hw_raid'] = True
                        if disk_hw_info_all and disk[
                                'serial_number'] in disk_hw_info_all.keys():
                            disk_dict['target_id'] = disk_hw_info_all[
                                disk['serial_number']]['target_id']
                            disk_dict['enclosure_id'] = disk_hw_info_all[
                                disk['serial_number']]['enclosure_id']
                            disk_dict['channel'] = disk_hw_info_all[
                                disk['serial_number']]['channel']
                        return_list.append(disk_dict)
        if not raid:
            disk_dict = {}
            disk_dict['name'] = disk_name
            disk_dict['hw_raid'] = False
            disk_dict['path'] = '/dev/%s' % disk_name
            disk_dict['id'] = disk_id
            disk_dict['capacity'] = capacity
            serial_number, err = get_serial_number(disk_name)
            if err:
                raise Exception(err)
            disk_dict['serial_number'] = serial_number
            disk_dict['rotational'] = rotational
            disk_dict['partitions'] = partitions
            status, err = get_smart_status(disk_name)
            if err:
                raise Exception(err)
            disk_dict['status'] = status
            disk_dict['scsi_info'] = scsi_info
            if hw_platform and hw_platform == 'dell':
                if disk_hw_info_all and serial_number in disk_hw_info_all.keys(
                ):
                    disk_dict['target_id'] = disk_hw_info_all[serial_number][
                        'target_id']
                    disk_dict['enclosure_id'] = disk_hw_info_all[
                        serial_number]['enclosure_id']
                    disk_dict['channel'] = disk_hw_info_all[serial_number][
                        'channel']
            return_list.append(disk_dict)

    except Exception, e:
        return None, "Error getting disk information : %s" % str(e)
Exemplo n.º 15
0
def get_disk_info(disk_name):
    """Get all details about a disk given its name """

    # Given a disk name like sda, get the disk info
    return_list = []
    try:
        '''
        ids, err = get_all_disk_ids(disk_name)
        if err:
            raise Exception(err)
        disk_id = None
        if ids:
            for id in ids:
                if id.startswith('scsi'):
                    disk_id = id
                    break
        if not disk_id:
            for id in ids:
                if id.startswith('ata'):
                    disk_id = id
                    break
        if not disk_id:
            for id in ids:
                if id.startswith('wwn'):
                    disk_id = id
                    break
        '''
        disk_id, err = get_disk_id(disk_name)
        if err:
            raise Exception(err)

        capacity, err = get_capacity(disk_name)
        if err:
            raise Exception(err)

        rotational, err = is_rotational(disk_name)
        if err:
            raise Exception(err)

        '''
        partitions, err = get_partitions(disk_name)
        if err:
            raise Exception(err)

        scsi_info, err = get_disk_scsi_info(disk_name)
        if err:
            raise Exception(err)
        '''

        raid = False
        hw_platform, err = config.get_hardware_platform()
        if hw_platform and hw_platform == 'dell':
            from platforms import dell
            '''
            disk_hw_info_all = {}
            disk_hw_info_tmp, err = dell.get_all_disks(0)
            iter = 1
            while disk_hw_info_tmp:
                disk_hw_info_all.update(disk_hw_info_tmp)
                disk_hw_info_tmp, err = dell.get_all_disks(iter)
                iter += 1
            '''
            raid_to_unix_mapping, err = dell.get_hardware_raid_to_unix_mapping()
            if raid_to_unix_mapping and '/dev/%s' % disk_name in raid_to_unix_mapping.keys():
                # Its a hardware RAID so pull the underlying info
                raid = True
                controller_id = raid_to_unix_mapping['/dev/%s' %
                                                     disk_name]['controller_number']
                device_id = raid_to_unix_mapping['/dev/%s' %
                                                 disk_name]['device_id']
                disk_list, err = dell.get_hardware_raid_hard_drives(
                    controller_id, device_id)
                if disk_list:
                    for disk in disk_list:
                        disk_dict = {}
                        disk_dict['serial_number'] = disk['serial_number']
                        #disk_dict['name'] = disk_name
                        #disk_dict['path'] = '/dev/%s' % disk_name
                        disk_dict['id'] = disk_id
                        disk_dict['capacity'] = capacity
                        disk_dict['rotational'] = rotational
                        #disk_dict['partitions'] = partitions
                        #disk_dict['status'] = disk['status']
                        #disk_dict['scsi_info'] = scsi_info
                        disk_dict['hw_raid'] = True
                        '''
                        if disk_hw_info_all and disk['serial_number'] in disk_hw_info_all.keys():
                            disk_dict['target_id'] = disk_hw_info_all[disk['serial_number']]['target_id']
                            disk_dict['enclosure_id'] = disk_hw_info_all[disk['serial_number']
                                                                         ]['enclosure_id']
                            disk_dict['controller_number'] = disk_hw_info_all[disk['serial_number']
                                                                              ]['controller_number']
                            disk_dict['channel'] = disk_hw_info_all[disk['serial_number']]['channel']
                        '''
                        return_list.append(disk_dict)
        if not raid:
            disk_dict = {}
            disk_dict['hw_raid'] = False
            disk_dict['id'] = disk_id
            disk_dict['capacity'] = capacity
            serial_number, err = get_serial_number(disk_name)
            if err:
                raise Exception(err)
            disk_dict['serial_number'] = serial_number
            disk_dict['rotational'] = rotational
            '''
            disk_dict['name'] = disk_name
            disk_dict['path'] = '/dev/%s' % disk_name
            disk_dict['partitions'] = partitions
            status, err = get_smart_status(disk_name)
            if err:
                raise Exception(err)
            disk_dict['status'] = status
            disk_dict['scsi_info'] = scsi_info
            if hw_platform and hw_platform == 'dell':
                if disk_hw_info_all and serial_number in disk_hw_info_all.keys():
                    disk_dict['target_id'] = disk_hw_info_all[serial_number]['target_id']
                    disk_dict['controller_number'] = disk_hw_info_all[serial_number]['controller_number']
                    disk_dict['enclosure_id'] = disk_hw_info_all[serial_number]['enclosure_id']
                    disk_dict['channel'] = disk_hw_info_all[serial_number]['channel']
            '''
            return_list.append(disk_dict)

    except Exception, e:
        return None, "Error getting disk information : %s" % str(e)
Exemplo n.º 16
0
def main():
    try:
        platform, err = config.get_platform()
        if err:
            raise Exception(err)

        lck, err = lock.get_lock('poll_for_alerts')
        if err:
            raise Exception(err)
        if not lck:
            raise Exception('Could not acquire lock. Exiting.')

        if platform == 'gridcell':
            from integralstor_gridcell import system_info
            gluster_lck, err = lock.get_lock('gluster_commands')
        else:
            from integralstor import system_info

        si, err = system_info.load_system_config()
        if platform == 'gridcell':
            lock.release_lock('gluster_commands')
        if err:
            raise Exception(err)
        if not si:
            raise Exception('Could not load system information')

        alert_list = []

        for node_name, node in si.items():
            if 'errors' in node and node['errors']:
                if platform == 'gridcell':
                    msg = 'GRIDCell : %s. ' % node_name
                else:
                    msg = ''
                msg += '. '.join(node['errors'])

                alert_list.append(msg)

        hw_platform, err = config.get_hardware_platform()
        if hw_platform:
            if hw_platform == 'dell':
                from integralstor_utils.platforms import dell
                alerts_dict, err = dell.get_alert_logs()
                if alerts_dict:
                    current_time = int(time.time())
                    for time_stamp, alerts_list in alerts_dict.items():
                        for alert_dict in alerts_list:
                            if alert_dict['Severity'] == 'Critical':
                                if (current_time - time_stamp) < (60 * 60):
                                    alert_list.append(
                                        alert_dict['description'])
                                    # print time_stamp, alert_dict

        # print "======================"
        # print alert_list
        # print "======================"
        if alert_list:
            alerts.raise_alert(alert_list)

        lock.release_lock('poll_for_alerts')
    except Exception, e:
        print "Error generating alerts : %s ! Exiting." % str(e)
        sys.exit(-1)
Exemplo n.º 17
0
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))