示例#1
0
def get_disk_status():
    return_dict = None
    try:
        return_dict, err = disks.get_disk_info_status_all(rescan=False,
                                                          type='status')
        if err:
            raise Exception(err)
        if return_dict:
            pool_list, err = zfs.get_pools()
            if pool_list:
                for sn, disk in return_dict.items():
                    # print disk['name']
                    id, err = disks.get_disk_id(disk['name'])
                    if err:
                        raise Exception(err)
                    # print id
                    #id = disk['id']
                    found = False
                    for pool in pool_list:
                        devices_list, err = zfs.get_disks_in_component(
                            pool['config']['pool']['root'])
                        if err:
                            raise Exception(err)
                        # print 'devices list is ', devices_list
                        # print 'id is', id
                        if devices_list and id in devices_list:
                            # print 'in devices list'
                            disk['pool'] = pool['pool_name']
    except Exception, e:
        return None, 'Error retrieving disk status : %s' % str(e)
def get_disk_status():
    return_dict = None
    try:
        return_dict, err = disks.get_disk_info_status_all(
            rescan=False, type='status')
        if err:
            raise Exception(err)
        if return_dict:
            pool_list, err = zfs.get_pools()
            if pool_list:
                for sn, disk in return_dict.items():
                    # print disk['name']
                    id, err = disks.get_disk_id(disk['name'])
                    if err:
                        raise Exception(err)
                    # print id
                    #id = disk['id']
                    found = False
                    for pool in pool_list:
                        devices_list, err = zfs.get_disks_in_component(
                            pool['config']['pool']['root'])
                        if err:
                            raise Exception(err)
                        # print 'devices list is ', devices_list
                        # print 'id is', id
                        if devices_list and id in devices_list:
                            # print 'in devices list'
                            disk['pool'] = pool['pool_name']
    except Exception, e:
        return None, 'Error retrieving disk status : %s' % str(e)
def create_rsync_share(request):
    return_dict = {}
    try:
        pools, err = zfs.get_pools()
        if err:
            raise Exception(err)

        ds_list = []
        for pool in pools:
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    ds_list.append(
                        {'name': ds["name"], 'mountpoint': ds["mountpoint"]})
        if not ds_list:
            raise Exception(
                'No ZFS datasets available. Please create a dataset before creating shares.')

        if request.method == "GET":
            form = rsync_forms.CreateShareForm(dataset_list=ds_list)
            return_dict['form'] = form
            return django.shortcuts.render_to_response("create_rsync_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            form = rsync_forms.CreateShareForm(
                request.POST, dataset_list=ds_list)
            path = request.POST.get("path")
            if not os.path.exists(path):
                os.mkdir(path)
            owner_dict, err = config.get_default_file_dir_owner()
            if err:
                raise Exception(err)
            owner_uid, err = config.get_system_uid_gid(
                owner_dict['user'], 'user')
            if err:
                raise Exception(err)
            owner_gid, err = config.get_system_uid_gid(
                owner_dict['group'], 'group')
            if err:
                raise Exception(err)

            os.chown(path, owner_uid, owner_gid)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response("create_rsync_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
            cd = form.cleaned_data
            result, err = rsync.create_rsync_share(
                cd["name"], cd["path"], cd["comment"], cd["browsable"], cd["readonly"], "integralstor", "integralstor")
            if err:
                raise Exception(err)
            audit_str = "Created RSYNC share with name '%s'. The share is set to be %s and %s" % (
                cd["name"], "Browsable" if cd["browsable"] else "Not Browsable", "Readonly" if cd["readonly"] else "Read/Write")
            audit.audit("create_rsync_share", audit_str, request)
            return django.http.HttpResponseRedirect('/storage_access/view_rsync_shares/?ack=created')
    except Exception, e:
        return_dict['base_template'] = "storage_access_base.html"
        return_dict["page_title"] = 'RSync shares'
        return_dict['tab'] = 'view_rsync_shares_tab'
        return_dict["error"] = 'Error creating RSync shares'
        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 main():
    lg = None
    try:
        stop_services = False
        scripts_log, err = config.get_scripts_log_path()
        if err:
            raise Exception(err)
        lg, err = logger.get_script_logger(
            'ZFS pool usage check', scripts_log, level=logging.DEBUG)

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

        logger.log_or_print(
            'ZFS pool usage check initiated.', lg, level='info')
        if len(sys.argv) != 3:
            raise Exception(
                'Usage : python check_zfs_pools_usage.py <warning_percentage> <critical_percentage>')
        warning_percentage = int(sys.argv[1])
        critical_percentage = int(sys.argv[2])

        pool_list, err = zfs.get_pools()
        if err:
            raise Exception(err)
        alerts_list = []
        for pool_info in pool_list:
            percentage = float(pool_info['usage']['used_percent'])

            alert = False
            if percentage > critical_percentage:
                severity_str = 'CRITICAL'
                severity_type = 3
                alert = True
                print_percentage = critical_percentage
                logger.log_or_print('ZFS pool %s is %d%% full.' % (
                    pool_info['pool_name'], int(percentage)), lg, level='critical')
            elif percentage > warning_percentage:
                severity_type = 2
                severity_str = 'warning'
                print_percentage = warning_percentage
                alert = True
            if alert:
                alert_str = 'ZFS pool %s has exceeded the %s threshold capacity of %d%% and is now %d%% full.' % (
                    pool_info['pool_name'], severity_str, print_percentage, percentage)
                alerts_list.append({'subsystem_type_id': 6, 'severity_type_id': severity_type,
                                    'component': pool_info['pool_name'], 'alert_str': alert_str})
        if alerts_list:
            retval, err = alerts.record_alerts(alerts_list)
            if err:
                raise Exception(err)
    except Exception, e:
        # print str(e)
        lock.release_lock('check_zfs_pools_usage')
        logger.log_or_print('Error checking ZFS pool usage: %s' %
                            e, lg, level='critical')
        return -1,  'Error checking ZFS pool usage : %s' % e
示例#5
0
def get_pool_status():
    """Get status of all zfs pools."""
    pl = None
    try:
        pl, err = zfs.get_pools()
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error retrieving pool status : %s' % str(e)
def get_pool_status():
    """Get status of all zfs pools."""
    pl = None
    try:
        pl, err = zfs.get_pools()
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error retrieving pool status : %s' % str(e)
def view_dir_manager(request):
    return_dict = {}
    try:
        if not "error" in return_dict:
            if "ack" in request.GET:
                if request.GET["ack"] == "ace_deleted":
                    return_dict['ack_message'] = "ACL entry successfully removed"
                elif request.GET["ack"] == "aces_added":
                    return_dict['ack_message'] = "ACL entries successfully added"
                elif request.GET["ack"] == "aces_modified":
                    return_dict['ack_message'] = "ACL entries successfully modified"
                elif request.GET["ack"] == "created_dir":
                    return_dict['ack_message'] = "Directory successfully created"
                elif request.GET["ack"] == "deleted_dir":
                    return_dict['ack_message'] = "Directory successfully deleted"
                elif request.GET["ack"] == "modified_ownership":
                    return_dict['ack_message'] = "Directory ownership successfully modified"

        initial = {}
        req_ret, err = django_utils.get_request_parameter_values(request, [
                                                                 'pool'])
        if err:
            raise Exception(err)
        if 'pool' in req_ret:
            pool = req_ret['pool']
            initial['pool'] = pool

        pools, err = zfs.get_pools()
        pool_list = []
        for pool in pools:
            # print pool['pool_name']
            pool_list.append(pool['pool_name'])
        if not pool_list:
            raise Exception(
                'No ZFS pools available. Please create a pool and dataset before using the directory manager.')

        form = folder_management_forms.DirManagerForm1(
            initial=initial, pool_list=pool_list)
        return_dict["form"] = form
        return django.shortcuts.render_to_response('view_dir_manager.html', return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "storage_base.html"
        return_dict["page_title"] = 'Directory manager'
        return_dict['tab'] = 'dir_manager_tab'
        return_dict["error"] = 'Error loading directory manager'
        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))
示例#8
0
def get_pool_on_disk(disk_id):
    pool_name = None
    try:
        if disk_id:
            pool_list, err = zfs.get_pools()
            if pool_list:
                found = False
                for pool in pool_list:
                    devices_list, err = zfs.get_disks_in_component(
                        pool['config']['pool']['root'])
                    if err:
                        raise Exception(err)
                    # print 'devices list is ', devices_list
                    if devices_list and disk_id in devices_list:
                        pool_name = pool['pool_name']
                        break
                        # print 'in devices list'
    except Exception, e:
        return None, 'Error updating pool information for disk : %s' % str(e)
def get_pool_on_disk(disk_id):
    pool_name = None
    try:
        if disk_id:
            pool_list, err = zfs.get_pools()
            if pool_list:
                found = False
                for pool in pool_list:
                    devices_list, err = zfs.get_disks_in_component(
                        pool['config']['pool']['root'])
                    if err:
                        raise Exception(err)
                    # print 'devices list is ', devices_list
                    if devices_list and disk_id in devices_list:
                        pool_name = pool['pool_name']
                        break
                        # print 'in devices list'
    except Exception, e:
        return None, 'Error updating pool information for disk : %s' % str(e)
示例#10
0
def _record_pool_usage_stats():
    try:
        pool_list, err = zfs.get_pools()
        if err:
            raise Exception(err)
        if pool_list:
            midnight, err = datetime_utils.get_epoch(when='midnight')
            if err:
                raise Exception(err)
            db_path, err = config.get_db_path()
            if err:
                raise Exception(err)
            for pool_info in pool_list:
                cmd_list = []
                cmd_list.append(["insert into pool_usage_stats(pool_name, date, used_bytes, available_bytes) values (?,?,?,?)", (
                    pool_info['pool_name'], midnight, pool_info['usage']['total_space_used_bytes'], pool_info['usage']['total_space_avail_bytes'],)])
                # Run multiple times as a duplicate entry will cause other
                # inserts to fail otherwise..
                ret, err = db.execute_iud(db_path, cmd_list)
            # Best effort.. continue if duplicate dates cause a problem when rerunning
            # print ret, err
    except Exception, e:
        # print str(e)
        return False, "Error recording ZFS pool usage statistics : %s" % str(e)
def update_dir_permissions(request):
    return_dict = {}
    try:
        if not "error" in return_dict:
            if "ack" in request.GET:
                if request.GET["ack"] == "ace_deleted":
                    return_dict['ack_message'] = "ACL entry successfully removed"
                elif request.GET["ack"] == "aces_added":
                    return_dict['ack_message'] = "ACL entries successfully added"
                elif request.GET["ack"] == "aces_modified":
                    return_dict['ack_message'] = "ACL entries successfully modified"
                elif request.GET["ack"] == "created_dir":
                    return_dict['ack_message'] = "Directory successfully created"
                elif request.GET["ack"] == "deleted_dir":
                    return_dict['ack_message'] = "Directory successfully deleted"
        users, err = local_users.get_local_users()
        if err:
            raise Exception('Error retrieving local user list : %s' % err)
        if not users:
            raise Exception(
                'No local users seem to be created. Please create at least one local user before performing this operation.')

        groups, err = local_users.get_local_groups()
        if err:
            raise Exception('Error retrieving local group list : %s' % err)
        if not groups:
            raise Exception(
                'No local groups seem to be created. Please create at least one local group before performing this operation.')

        pools, err = zfs.get_pools()
        ds_list = []
        for pool in pools:
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    ds_list.append(ds["name"])
        if not ds_list:
            raise Exception(
                'No ZFS datasets available. Please create a dataset before creating shares.')

        req_ret, err = django_utils.get_request_parameter_values(request, [
                                                                 'path'])
        if err:
            raise Exception(err)
        if 'path' not in req_ret:
            path = "/" + pools[0]["datasets"][0]["name"]
        else:
            path = req_ret['path']
        try:
            stat_info = os.stat(path)
        except Exception, e:
            raise Exception('Error accessing specified path : %s' % str(e))
        uid = stat_info.st_uid
        gid = stat_info.st_gid
        username = pwd.getpwuid(uid)[0]
        grpname = grp.getgrgid(gid)[0]
        return_dict["username"] = username
        return_dict["grpname"] = grpname

        aces, err = acl.get_all_aces(path)
        if err:
            raise Exception(err)
        minimal_aces, err = acl.get_minimal_aces(aces)
        if err:
            raise Exception(err)
        user_aces, err = acl.get_ug_aces(aces, None, 'user')
        if err:
            raise Exception(err)
        group_aces, err = acl.get_ug_aces(aces, None, 'group')
        if err:
            raise Exception(err)

        return_dict['aces'] = aces
        return_dict['minimal_aces'] = minimal_aces
        if user_aces:
            return_dict['user_aces'] = user_aces
        if group_aces:
            return_dict['group_aces'] = group_aces

        return_dict['path'] = path
        return_dict["dataset"] = ds_list
        if request.method == "GET":
            # Shd be an edit request

            # Set initial form values
            initial = {}
            initial['path'] = path
            initial['owner_read'] = _owner_readable(stat_info)
            initial['owner_write'] = _owner_writeable(stat_info)
            initial['owner_execute'] = _owner_executeable(stat_info)
            initial['group_read'] = _group_readable(stat_info)
            initial['group_write'] = _group_writeable(stat_info)
            initial['group_execute'] = _group_executeable(stat_info)
            initial['other_read'] = _other_readable(stat_info)
            initial['other_write'] = _other_writeable(stat_info)
            initial['other_execute'] = _other_executeable(stat_info)
            if 'dataset' in request.GET:
                initial['dataset'] = request.GET['dataset']

            form = folder_management_forms.SetFileOwnerAndPermissionsForm(
                initial=initial, user_list=users, group_list=groups)

            return_dict["form"] = form
            return django.shortcuts.render_to_response('update_dir_permissions.html', return_dict, context_instance=django.template.context.RequestContext(request))

        elif request.method == "POST":
            path = request.POST.get("path")
            # Shd be an save request
            if request.POST.get("action") == "add_folder":
                folder_name = request.POST.get("new_folder_name")
                directory = path + "/" + folder_name
                if not os.path.exists(directory):
                    os.makedirs(directory)
                    audit_str = "Creating %s" % directory
                    audit.audit("modify_dir_owner_permissions",
                                audit_str, request)
            elif request.POST.get("action") == "delete_folder":
                delete = "false"
                if len(path.split("/")) > 2:
                    delete = "true"
                # Need to also check if the path is a share or not. If share, dont delete again.
                # Checking NFS
                exports, err = nfs.load_exports_list()
                if exports:
                    for export in exports:
                        print id(export["path"]), id(path)
                        if export["path"] == path:
                            delete = "false"
                            break
                        else:
                            delete = "true"

                if delete:
                    print delete
                    # shutil.rmtree(path,ignore_errors=True)
                    audit_str = "Deleting directory %s" % path
                    audit.audit("modify_dir_owner_permissions",
                                audit_str, request)
                else:
                    raise Exception(
                        "Cannot delete folder. It is either a dataset of a share")
            else:
                form = folder_management_forms.SetFileOwnerAndPermissionsForm(
                    request.POST, user_list=users, group_list=groups)
                return_dict["form"] = form
                if form.is_valid():
                    cd = form.cleaned_data
                    ret, err = file_processing.update_dir_ownership_and_permissions(
                        cd)
                    if not ret:
                        if err:
                            raise Exception(err)
                        else:
                            raise Exception(
                                "Error setting directory ownership/permissions.")

                    audit_str = "Modified directory ownsership/permissions for %s" % cd["path"]
                    audit.audit("modify_dir_owner_permissions",
                                audit_str, request)

            return django.http.HttpResponseRedirect('/storage/update_dir_permissions/?ack=set_permissions')

        else:
            return django.shortcuts.render_to_response('update_dir_permissions.html', return_dict, context_instance=django.template.context.RequestContext(request))
def delete_dir(request):
    return_dict = {}
    try:
        req_ret, err = django_utils.get_request_parameter_values(request, [
                                                                 'path'])
        if err:
            raise Exception(err)
        if 'path' not in req_ret:
            raise Exception('Invalid request, please use the menus')
        path = req_ret['path']
        pools, err = zfs.get_pools()
        ds_list = []
        for pool in pools:
            if pool['properties']['mountpoint']['value'] == path:
                raise Exception(
                    'The selected directory is the mountpoint of a pool and so cannot be deleted.')
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    if ds['properties']['mountpoint']['value'] == path:
                        raise Exception(
                            'The selected directory is the mountpoint of a dataset and so cannot be deleted.')
        if request.method == "GET":
            if 'path' not in request.GET:
                raise Exception('No directory specified')
            initial = {}
            initial['path'] = request.GET['path']
            form = folder_management_forms.DirForm(initial=initial)
            return_dict['form'] = form
            return django.shortcuts.render_to_response('delete_dir_conf.html', return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            form = folder_management_forms.DirForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                path = cd['path']
                if not os.path.exists(path):
                    raise Exception('The specified directory does not exist!')

                if len(path.split("/")) < 2:
                    raise Exception(
                        'Cannot delete specified directory - Invalid path')

                # Need to also check if the path is a share or not. If share, dont delete again.
                # Checking NFS
                exports, err = nfs.load_exports_list()
                if exports:
                    for export in exports:
                        # print id(export["path"]),id(path)
                        if export["path"] == path:
                            raise Exception(
                                'Cannot delete the specified directory as it is path of an NFS share')

                shutil.rmtree(path, ignore_errors=True)
                audit_str = "Deleted directory '%s'" % path
                audit.audit("delete_dir", audit_str, request)

                return django.http.HttpResponseRedirect('/storage/view_dir_manager/?ack=deleted_dir')
            else:
                raise Exception(
                    'Could not delete the specified directory as there was an error in the specified parameters.')
    except Exception, e:
        return_dict['base_template'] = "storage_base.html"
        return_dict["page_title"] = 'Delete a directory'
        return_dict['tab'] = 'dir_permissions_tab'
        return_dict["error"] = 'Error deleting directory'
        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 create_cifs_share(request):

    return_dict = {}
    try:

        pools, err = zfs.get_pools()
        if err:
            raise Exception(
                'No ZFS pools available. Please create a pool and dataset before creating shares.')

        ds_list = []
        for pool in pools:
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    ds_list.append(
                        (ds['properties']['mountpoint']['value'], ds["name"]))

        if not ds_list:
            raise Exception(
                'No ZFS datasets available. Please create a dataset before creating shares.')

        dataset = path = None
        ret, err = django_utils.get_request_parameter_values(
            request, ['dataset', 'path'])
        if err:
            raise Exception(err)
        if 'dataset' not in ret:
            dataset = ds_list[0][0]
        elif 'dataset' in ret:
            dataset = ret['dataset']
        if 'path' not in ret:
            path = dataset
        elif 'path' in ret:
            path = ret['path']

        return_dict['path'] = path
        return_dict["dataset"] = ds_list

        initial = {}
        initial['path'] = path
        initial['dataset'] = dataset
        if request.method == "GET":
            # Return the form
            initial['guest_ok'] = True
            if 'name' in request.GET:
                initial['name'] = request.GET['name']

            form = samba_shares_forms.CreateShareForm(
                dataset_list=ds_list, initial=initial)
            return_dict["form"] = form

            return django.shortcuts.render_to_response("create_cifs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            # Form submission so create
            form = samba_shares_forms.CreateShareForm(
                request.POST, initial=initial, dataset_list=ds_list)
            return_dict["form"] = form
            if form.is_valid():
                cd = form.cleaned_data
                # print cd
                name = cd["name"]
                path = cd["path"]
                if not path:
                    return_dict["path_error"] = "Please select a dataset."
                    return django.shortcuts.render_to_response("create_cifs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
                if 'new_folder' in cd and cd['new_folder']:
                    try:
                        path = '%s/%s' % (cd['path'], cd['new_folder'])
                        # print path
                        os.mkdir(path)
                        audit_str = 'Created new directory "%s" in "%s"' % (
                            cd['new_folder'], cd['path'])
                        audit.audit("create_dir", audit_str, request)
                    except Exception, e:
                        raise Exception('Error creating subfolder %s : %s' % (
                            cd['new_folder'], str(e)))

                owner_dict, err = config.get_default_file_dir_owner()
                if err:
                    raise Exception(err)
                owner_uid, err = config.get_system_uid_gid(
                    owner_dict['user'], 'user')
                if err:
                    raise Exception(err)
                owner_gid, err = config.get_system_uid_gid(
                    owner_dict['group'], 'group')
                if err:
                    raise Exception(err)

                os.chown(path, owner_uid, owner_gid)

                if "comment" in cd:
                    comment = cd["comment"]
                else:
                    comment = None
                if "read_only" in cd:
                    read_only = cd["read_only"]
                else:
                    read_only = None
                if "browseable" in cd:
                    browseable = cd["browseable"]
                else:
                    browseable = None

                if 'hosts_allow_choice' in cd and cd['hosts_allow_choice'] == 'restricted':
                    if 'hosts_allow' not in cd or not cd['hosts_allow']:
                        raise Exception(
                            'Please enter a valid list of allowed hosts')
                    hosts_allow = cd['hosts_allow']
                else:
                    hosts_allow = None
                # print hosts_allow

                if 'hosts_deny_choice' in cd and cd['hosts_deny_choice'] == 'restricted':
                    if 'hosts_deny' not in cd or not cd['hosts_deny']:
                        raise Exception(
                            'Please enter a valid list of denied hosts')
                    hosts_deny = cd['hosts_deny']
                else:
                    hosts_deny = None
                # print hosts_deny

                guest_ok = True
                ret, err = cifs.create_share(
                    name, comment, True, read_only, path, path, browseable, None, None, "integralstor_novol", hosts_allow=hosts_allow, hosts_deny=hosts_deny)
                if err:
                    raise Exception(err)
                ret, err = cifs.generate_smb_conf()
                if err:
                    raise Exception(err)

                audit_str = "Created Samba share %s" % name
                audit.audit("create_cifs_share", audit_str, request)
                return django.http.HttpResponseRedirect('/storage_access/view_cifs_shares?ack=created')
            else:
示例#14
0
def create_rsync_share(request):
    return_dict = {}
    try:
        pools, err = zfs.get_pools()
        if err:
            raise Exception(err)

        ds_list = []
        for pool in pools:
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    ds_list.append({
                        'name': ds["name"],
                        'mountpoint': ds["mountpoint"]
                    })
        if not ds_list:
            raise Exception(
                'No ZFS datasets available. Please create a dataset before creating shares.'
            )

        if request.method == "GET":
            form = rsync_forms.CreateShareForm(dataset_list=ds_list)
            return_dict['form'] = form
            return django.shortcuts.render_to_response(
                "create_rsync_share.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            form = rsync_forms.CreateShareForm(request.POST,
                                               dataset_list=ds_list)
            path = request.POST.get("path")
            if not os.path.exists(path):
                os.mkdir(path)
            owner_dict, err = config.get_default_file_dir_owner()
            if err:
                raise Exception(err)
            owner_uid, err = config.get_system_uid_gid(owner_dict['user'],
                                                       'user')
            if err:
                raise Exception(err)
            owner_gid, err = config.get_system_uid_gid(owner_dict['group'],
                                                       'group')
            if err:
                raise Exception(err)

            os.chown(path, owner_uid, owner_gid)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response(
                    "create_rsync_share.html",
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
            cd = form.cleaned_data
            result, err = rsync.create_rsync_share(
                cd["name"], cd["path"], cd["comment"], cd["browsable"],
                cd["readonly"], "integralstor", "integralstor")
            if err:
                raise Exception(err)
            audit_str = "Created RSYNC share with name '%s'. The share is set to be %s and %s" % (
                cd["name"],
                "Browsable" if cd["browsable"] else "Not Browsable",
                "Readonly" if cd["readonly"] else "Read/Write")
            audit.audit("create_rsync_share", audit_str, request)
            return django.http.HttpResponseRedirect(
                '/storage_access/view_rsync_shares/?ack=created')
    except Exception, e:
        return_dict['base_template'] = "storage_access_base.html"
        return_dict["page_title"] = 'RSync shares'
        return_dict['tab'] = 'view_rsync_shares_tab'
        return_dict["error"] = 'Error creating RSync shares'
        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))
示例#15
0
def main():
    lg = None
    try:
        stop_services = False
        scripts_log, err = config.get_scripts_log_path()
        if err:
            raise Exception(err)
        lg, err = logger.get_script_logger('ZFS pool usage check',
                                           scripts_log,
                                           level=logging.DEBUG)

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

        logger.log_or_print('ZFS pool usage check initiated.',
                            lg,
                            level='info')
        if len(sys.argv) != 3:
            raise Exception(
                'Usage : python check_zfs_pools_usage.py <warning_percentage> <critical_percentage>'
            )
        warning_percentage = int(sys.argv[1])
        critical_percentage = int(sys.argv[2])

        pool_list, err = zfs.get_pools()
        if err:
            raise Exception(err)
        alerts_list = []
        for pool_info in pool_list:
            percentage = float(pool_info['usage']['used_percent'])

            alert = False
            if percentage > critical_percentage:
                severity_str = 'CRITICAL'
                severity_type = 3
                alert = True
                print_percentage = critical_percentage
                logger.log_or_print('ZFS pool %s is %d%% full.' %
                                    (pool_info['pool_name'], int(percentage)),
                                    lg,
                                    level='critical')
            elif percentage > warning_percentage:
                severity_type = 2
                severity_str = 'warning'
                print_percentage = warning_percentage
                alert = True
            if alert:
                alert_str = 'ZFS pool %s has exceeded the %s threshold capacity of %d%% and is now %d%% full.' % (
                    pool_info['pool_name'], severity_str, print_percentage,
                    percentage)
                alerts_list.append({
                    'subsystem_type_id': 6,
                    'severity_type_id': severity_type,
                    'component': pool_info['pool_name'],
                    'alert_str': alert_str
                })
        if alerts_list:
            retval, err = alerts.record_alerts(alerts_list)
            if err:
                raise Exception(err)
    except Exception, e:
        # print str(e)
        lock.release_lock('check_zfs_pools_usage')
        logger.log_or_print('Error checking ZFS pool usage: %s' % e,
                            lg,
                            level='critical')
        return -1, 'Error checking ZFS pool usage : %s' % e
def generate_status_info(path):
    status_dict = {}
    try:
        pp = pprint.PrettyPrinter(indent=4)

        # First load the status
        fqdn = socket.getfqdn()
        # Load the manifest to check for discrepencies
        try:
            with open(path, 'r') as f:
                manifest_dict = json.load(f)
        except Exception, e:
            raise Exception('Error reading the manifest file : %s' % str(e))
        # pp.pprint(md)

        # Match the status against the manifest entries for discrepencies
        status_dict["errors"] = []
        hardware_dict, err = get_hardware_specific_status()
        if err:
            raise Exception(err)
        if hardware_dict:
            status_dict['hardware_specific_status'] = hardware_dict
        node_status = 0

        # Process disk information
        disks_dict = {}
        disk_status_dict, err = disks.get_disk_info_status_all(
            rescan=False, type='status')
        #disk_status_dict, err = get_disk_status()
        if err:
            raise Exception(err)
        # print disk_status_dict.keys()
        for disk_sn, disk_info_dict in manifest_dict["disks"].items():
            # print disk_info_dict
            # print disk_sn
            dd = {}
            if disk_sn in disk_status_dict.keys():
                for k in disk_status_dict[disk_sn].keys():
                    dd[k] = disk_status_dict[disk_sn][k]
                if dd['status']:
                    if ('hw_raid' not in disk_info_dict) or (not disk_info_dict['hw_raid']):
                        if (dd["status"].lower() not in ['ok', 'passed']):
                            node_status = 1
                            status_dict["errors"].append(
                                {'subsystem_type_id': 1, 'severity_type_id': 2, 'component': disk_sn, 'alert_str': "Disk with serial number %s is reporting SMART errors." % disk_sn})
            else:
                dd['status'] = 'Disk missing'
                node_status = 1
                status_dict["errors"].append(
                    {'subsystem_type_id': 1, 'severity_type_id': 3, 'component':  disk_sn, 'alert_str':
                     "Disk with serial number %s seems to be missing." % disk_sn})
            pool_on_disk, err = get_pool_on_disk(disk_info_dict['id'])
            if err:
                raise Exception(err)
            dd['pool'] = pool_on_disk
            disks_dict[disk_sn] = dd
            '''
            #Dont detect new disks here because it requires a costly disk rescan
            new_disk = False
            for td in sd[hostname]["disks"].keys():
                if td not in manifest["disks"]:
                    new_disk = True
                    status_dict["errors"].append(
                        { 'subsystem_type_id': 1, 'severity_type_id': 1, 'component' : disk_sn, 'alert_str' : 
                        "New disk detected. Disk with serial number %s  seems to be new." % td})
                    node_status = 2
            #temp_d["disks"] = disks
            temp_d["disks"] = sd[hostname]['disks']
            # pp.pprint(temp_d['disks'])
            '''
        status_dict['disks'] = disks_dict

        services_status_dict, err = get_services_status()
        if err:
            raise Exception(err)
        status_dict["services"] = services_status_dict
        if services_status_dict:
            for service_name, service_info in services_status_dict.items():
                if service_info[0] != 0:
                    status_dict['errors'].append(
                        {'subsystem_type_id': 2, 'severity_type_id': 3, 'component': service_name, 'alert_str':
                         'Service %s seems to have failed.' % service_name})
                    node_status = 1

        # Process interface information
        interfaces = {}
        interface_status_dict, err = get_interface_status()
        if err:
            raise Exception(err)
        # Check the status of existing interfaces
        for ifname, ifdict in manifest_dict["interfaces"].items():
            # Check for all initially present interfaces
            id = {}
            if ifname in interface_status_dict:
                id, err = _convert_to_status_interface_dict(
                    interface_status_dict[ifname])
                if err:
                    raise Exception(err)
            else:
                id["status"] = "Interface Missing"
                node_status = 1
                status_dict["errors"].append(
                    {'subsystem_type_id': 3, 'severity_type_id': 3, 'component': ifname, 'alert_str':
                     "Interface with name %s seems to be missing." % ifname})
            interfaces[ifname] = id
        # Check to see if there are any new interfaces
        for ifname, ifinfo in interface_status_dict.items():
            # Check for all newly created interfaces - bonds, vlans, etc
            # print 'ifname is ', ifname
            if ifname not in manifest_dict["interfaces"]:
                id, err = _convert_to_status_interface_dict(
                    interface_status_dict[ifname])
                if err:
                    raise Exception(err)
                interfaces[ifname] = id
        status_dict["interfaces"] = interfaces

        for ifname, id in status_dict['interfaces'].items():
            if ('ip_configured' in id or 'slave_to' in id)and id["status"] != 'up':
                node_status = 1
                status_dict["errors"].append(
                    {'subsystem_type_id': 3, 'severity_type_id': 3, 'component': ifname, 'alert_str':
                     "Interface %s is not up." % ifname})

        # print 'interfaces are ', status_dict['interfaces']

        mem_status_dict, err = get_mem_info_status(type='status')
        if err:
            raise Exception(err)
        status_dict['memory'] = mem_status_dict
        '''
                if sd[hostname]["memory"]["mem_total"]["unit"] == "kB":
                    sd[hostname]["memory"]["mem_total"]["value"] = str(
                        int(sd[hostname]["memory"]["mem_total"]["value"]) / 1024)
                    sd[hostname]["memory"]["mem_total"]["unit"] = "MB"
                if sd[hostname]["memory"]["mem_free"]["unit"] == "kB":
                    sd[hostname]["memory"]["mem_free"]["value"] = str(
                        int(sd[hostname]["memory"]["mem_free"]["value"]) / 1024)
                    sd[hostname]["memory"]["mem_free"]["unit"] = "MB"
                temp_d["memory"] = sd[hostname]["memory"]
        '''

        lavg, err = get_load_avg()
        if err:
            raise Exception(err)
        if lavg:
            status_dict['load_avg'] = lavg

        if fqdn:
            status_dict['fqdn'] = fqdn

        ipmi, err = get_ipmi_status()
        if err:
            raise Exception(err)
        if ipmi:
            status_dict["ipmi_status"] = ipmi

        if status_dict["load_avg"]['15_min'] >= status_dict["load_avg"]['cpu_cores']:
            status_dict["errors"].append(
                {'subsystem_type_id': 4, 'severity_type_id': 2, 'component': 'None', 'alert_str':
                 "The 15-minute load average has been high."})
            node_status = 1
            '''
                    "The 15-minute load average (%.2f) has been high." % temp_d["load_avg"]['15_min']})
            '''
        if status_dict["load_avg"]['5_min'] >= status_dict["load_avg"]['cpu_cores']:
            status_dict["errors"].append(
                {'subsystem_type_id': 4, 'severity_type_id': 2, 'component': 'None', 'alert_str':
                 "The 5-minute load average has been high."})
            '''
                    "The 5-minute load average (%.2f) has been high." % temp_d["load_avg"]['5_min']})
            '''

        if 'ipmi_status' in status_dict:
            for status_item in status_dict['ipmi_status']:
                if status_item["status"] not in ['ok', 'nr']:
                    status_dict["errors"].append(
                        {'subsystem_type_id': 5, 'severity_type_id': 2, 'component': parameter_name, 'alert_str':
                         'The %s of the %s is reporting errors' % (
                             status_item["parameter_name"], status_item["component_name"])})

        pools, err = zfs.get_pools()
        if err:
            raise Exception(err)
        if pools:
            status_dict['pools'] = pools

        component_status_dict, err = zfs.get_all_components_status(
            pools)
        if err:
            raise Exception(err)
        if component_status_dict:
            for pool_name, component_status_list in component_status_dict.items():
                msg = None
                severity_type_id = 1
                for component in component_status_list:
                    if 'status' in component and 'state' in component['status'] and component['status']['state'] != 'ONLINE':
                        if component['type'].lower() == 'pool':
                            if component['status']['state'] == 'DEGRADED':
                                severity_type_id = 2
                            else:
                                severity_type_id = 3
                        if not msg:
                            msg = "The ZFS pool '%s' has the following issue(s) : " % pool_name
                        msg += "The component %s of type '%s' has a state of '%s'. " % (
                            component['name'], component['type'], component['status']['state'])
                if msg:
                    status_dict['errors'].append(
                        {'subsystem_type_id': 6, 'severity_type_id': severity_type_id, 'component': pool_name, 'alert_str': msg})

        zfs_ver, err = get_zfs_version()
        if err:
            raise Exception(err)
        status_dict["zfs_version"] = zfs_ver

        os_ver = '%s %s' % (platform.system(), platform.release())
        status_dict["os_version"] = os_ver

        status_dict["node_status"] = node_status
        if node_status == 0:
            status_dict["node_status_str"] = "Healthy"
        elif node_status == 1:
            status_dict["node_status_str"] = "Degraded"
        elif node_status == 2:
            status_dict["node_status_str"] = "New on-node hardware detected"
        elif node_status == -1:
            status_dict["node_status_str"] = "No response. Down?"
            status_dict['errors'].append(
                {'subsystem_type_id': 99, 'severity_type_id': 3, 'component': hostname, 'alert_str':
                 'Node %s seems to be down' % hostname})
def view_dir_contents(request):
    dir_dict_list = []
    first = request.GET.get("first")
    if first:
        src = request.GET['from']
        if src == 'dataset':
            if 'dataset_name' not in request.GET:
                raise Exception('No dataset supplied')
            ds_name = request.GET['dataset_name']
            mnt_pnt = '/%s' % ds_name
            dirs = []
            if os.path.isdir(mnt_pnt):
                dirs = os.listdir(mnt_pnt)
            if not dirs:
                d_dict = {'id': mnt_pnt, 'text': '/', 'icon': 'fa',
                          'children': False, 'data': {'dir': mnt_pnt}, 'parent': "#"}
                dir_dict_list.append(d_dict)
            for dir in dirs:
                if os.path.isdir('%s/%s' % (mnt_pnt, dir)):
                    subdirs, err = _has_subdirs('%s/%s' % (mnt_pnt, dir))
                    if err:
                        raise Exception(err)
                    #subdirs = os.listdir('%s/%s'%(mnt_pnt, dir))
                    if subdirs:
                        d_dict = {'id': '%s/%s' % (mnt_pnt, dir), 'text': dir, 'icon': 'fa fa-angle-right',
                                  'children': True, 'data': {'dir': '%s/%s' % (mnt_pnt, dir)}, 'parent': "#"}
                    else:
                        d_dict = {'id': '%s/%s' % (mnt_pnt, dir), 'text': dir, 'icon': 'fa', 'children': False, 'data': {
                            'dir': '%s/%s' % (mnt_pnt, dir)}, 'parent': "#"}
                    dir_dict_list.append(d_dict)
        elif src == 'pool':
            if 'pool_name' not in request.GET:
                pools, err = zfs.get_pools()
                if err:
                    raise Exception(err)
                p = pools[0]
            else:
                pool = request.GET['pool_name']
                p, err = zfs.get_pool(pool)
                if err:
                    raise Exception(err)
            dir_dict_list = []
            for ds in p["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    mnt_pnt = ds['properties']['mountpoint']['value']
                    #subdirs = os.listdir(mnt_pnt)
                    subdirs, err = _has_subdirs(mnt_pnt)
                    if err:
                        raise Exception(err)
                    name = os.path.basename(mnt_pnt)
                    if subdirs:
                        d_dict = {'id': mnt_pnt, 'text': name, 'icon': 'fa fa-angle-right',
                                  'children': True, 'data': {'dir': mnt_pnt}, 'parent': "#"}
                    else:
                        d_dict = {'id': mnt_pnt, 'text': name, 'icon': 'fa', 'children': False, 'data': {
                            'dir': mnt_pnt}, 'parent': "#"}
                    dir_dict_list.append(d_dict)
    else:
        if 'dir' in request.GET and request.GET['dir'] != '/':
            path = request.GET['dir']
        else:
            path = request.GET.get("pool_name")
        dirs = os.listdir(path)
        # print 'path ', path
        for d in dirs:
            # print 'dir', d
            true = True
            if os.path.isdir(path + "/" + d):
                parent = path
                subdirs, err = _has_subdirs('%s/%s' % (path, d))
                if err:
                    raise Exception(err)
                '''
        contents = os.listdir('%s/%s'%(path, d))
        subdirs = False
        for content in contents:
          if os.path.isdir('%s/%s/%s'%(path,d, content)):
            subdirs = True
            break
        '''
                # print 'subdirs ', subdirs
                if subdirs:
                    # print 'yes'
                    d_dict = {'id': path + "/" + d, 'text': d, 'icon': 'fa fa-angle-right',
                              'children': True, 'data': {'dir': path + "/" + d}, 'parent': parent}
                else:
                    # print 'no'
                    d_dict = {'id': path + "/" + d, 'text': d, 'icon': 'fa',
                              'children': False, 'data': {'dir': path + "/" + d}, 'parent': parent}
                dir_dict_list.append(d_dict)
    return HttpResponse(json.dumps(dir_dict_list), content_type='application/json')
def create_nfs_share(request):
    return_dict = {}
    try:
        pools, err = zfs.get_pools()
        if err:
            raise Exception(err)

        ds_list = []
        for pool in pools:
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    ds_list.append(
                        {'name': ds["name"], 'mountpoint': ds["mountpoint"]})
        if not ds_list:
            raise Exception(
                'No ZFS datasets available. Please create a dataset before creating shares.')

        req_ret, err = django_utils.get_request_parameter_values(
            request, ['dataset', 'path'])
        if err:
            raise Exception(err)

        if 'dataset' in req_ret:
            dataset = req_ret['dataset']
        else:
            dataset = ds_list[0]['mountpoint']
        if 'path' in req_ret:
            path = req_ret['path']
        else:
            path = dataset

        return_dict['path'] = path
        return_dict["dataset"] = ds_list

        if request.method == "GET":
            # Return the conf page
            initial = {}
            initial['path'] = path
            initial['dataset'] = dataset
            form = nfs_shares_forms.CreateShareForm(
                initial=initial, dataset_list=ds_list)
            return_dict['form'] = form
            return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            form = nfs_shares_forms.CreateShareForm(
                request.POST, dataset_list=ds_list)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
            cd = form.cleaned_data
            if 'new_folder' in cd and cd['new_folder']:
                try:
                    os.mkdir('%s/%s' % (cd['path'], cd['new_folder']))
                    audit_str = 'Created new directory "%s" in "%s"' % (
                        cd['new_folder'], cd['path'])
                    audit.audit("create_dir", audit_str, request)
                    cd['path'] = '%s/%s' % (cd['path'], cd['new_folder'])
                except Exception, e:
                    raise Exception('Error creating subfolder %s : %s' % (
                        cd['new_folder'], str(e)))
            result, err = nfs.save_share(cd, True)
            if err:
                raise Exception(err)

            audit_str = "Created NFS share %s" % cd['path']
            audit.audit("create_nfs_share", audit_str, request)
            return django.http.HttpResponseRedirect('/storage_access/view_nfs_shares?ack=created')
    except Exception, e:
        return_dict['base_template'] = "storage_access_base.html"
        return_dict["page_title"] = 'Create a NFS share '
        return_dict['tab'] = 'view_nfs_shares_tab'
        return_dict["error"] = 'Error creating a NFS share'
        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))
示例#19
0
def update_ftp_configuration(request):
    return_dict = {}
    try:
        config, err = vsftp.get_ftp_config()
        if err:
            raise Exception(err)
        pools, err = zfs.get_pools()
        ds_list = []
        for pool in pools:
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    ds_list.append(ds["name"])
        cert_list, err = pki.get_ssl_certificates()
        if err:
            raise Exception(err)
        cert_name_list = []
        for cert in cert_list:
            cert_name_list.append(cert['name'])
        # print ds_list
        if not ds_list:
            raise Exception(
                'No ZFS datasets available. Please create a dataset before configuring the FTP service.')

        if request.method == 'GET':
            initial = {}
            if config:
                for key in config.keys():
                    initial[key] = config[key]
            form = ftp_management_forms.ConfigureFTPForm(
                datasets=ds_list, cert_names=cert_name_list, initial=initial)
            return_dict['form'] = form
            return django.shortcuts.render_to_response('update_ftp_configuration.html', return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            form = ftp_management_forms.ConfigureFTPForm(
                request.POST, cert_names=cert_name_list, datasets=ds_list)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response("update_ftp_configuration.html", return_dict, context_instance=django.template.context.RequestContext(request))
            cd = form.cleaned_data
            ret, err = vsftp.update_ftp_config(cd)
            if err:
                raise Exception(err)
            users, err = local_users.get_local_users()
            if err:
                raise Exception(err)
            ret, err = vsftp.create_ftp_user_dirs(cd['dataset'], users)
            if err:
                raise Exception(err)
            audit_str = 'Updated FTP configuration.'
            if cd['ssl_enabled']:
                audit_str = audit_str + \
                    ' SSL enabled with certificate %s' % cd['cert_name']
            else:
                audit_str = audit_str + ' SSL disabled.'
            ret, err = audit.audit("update_ftp_config",
                                   audit_str, request)
            return django.http.HttpResponseRedirect('/view_ftp_configuration?ack=saved')
    except Exception, e:
        return_dict['base_template'] = "services_base.html"
        return_dict["page_title"] = 'Configure FTP service'
        return_dict['tab'] = 'ftp_service_settings'
        return_dict["error"] = 'Error configuring the FTP service '
        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))
示例#20
0
def generate_status_info(path):
    status_dict = {}
    try:
        pp = pprint.PrettyPrinter(indent=4)

        # First load the status
        fqdn = socket.getfqdn()
        # Load the manifest to check for discrepencies
        try:
            with open(path, 'r') as f:
                manifest_dict = json.load(f)
        except Exception, e:
            raise Exception('Error reading the manifest file : %s' % str(e))
        # pp.pprint(md)

        # Match the status against the manifest entries for discrepencies
        status_dict["errors"] = []
        hardware_dict, err = get_hardware_specific_status()
        if err:
            raise Exception(err)
        if hardware_dict:
            status_dict['hardware_specific_status'] = hardware_dict
        node_status = 0

        # Process disk information
        disks_dict = {}
        disk_status_dict, err = disks.get_disk_info_status_all(rescan=False,
                                                               type='status')
        #disk_status_dict, err = get_disk_status()
        if err:
            raise Exception(err)
        # print disk_status_dict.keys()
        for disk_sn, disk_info_dict in manifest_dict["disks"].items():
            # print disk_info_dict
            # print disk_sn
            dd = {}
            if disk_sn in disk_status_dict.keys():
                for k in disk_status_dict[disk_sn].keys():
                    dd[k] = disk_status_dict[disk_sn][k]
                if dd['status']:
                    if ('hw_raid' not in disk_info_dict) or (
                            not disk_info_dict['hw_raid']):
                        if (dd["status"].lower() not in ['ok', 'passed']):
                            node_status = 1
                            status_dict["errors"].append({
                                'subsystem_type_id':
                                1,
                                'severity_type_id':
                                2,
                                'component':
                                disk_sn,
                                'alert_str':
                                "Disk with serial number %s is reporting SMART errors."
                                % disk_sn
                            })
            else:
                dd['status'] = 'Disk missing'
                node_status = 1
                status_dict["errors"].append({
                    'subsystem_type_id':
                    1,
                    'severity_type_id':
                    3,
                    'component':
                    disk_sn,
                    'alert_str':
                    "Disk with serial number %s seems to be missing." % disk_sn
                })
            pool_on_disk, err = get_pool_on_disk(disk_info_dict['id'])
            if err:
                raise Exception(err)
            dd['pool'] = pool_on_disk
            disks_dict[disk_sn] = dd
            '''
            #Dont detect new disks here because it requires a costly disk rescan
            new_disk = False
            for td in sd[hostname]["disks"].keys():
                if td not in manifest["disks"]:
                    new_disk = True
                    status_dict["errors"].append(
                        { 'subsystem_type_id': 1, 'severity_type_id': 1, 'component' : disk_sn, 'alert_str' : 
                        "New disk detected. Disk with serial number %s  seems to be new." % td})
                    node_status = 2
            #temp_d["disks"] = disks
            temp_d["disks"] = sd[hostname]['disks']
            # pp.pprint(temp_d['disks'])
            '''
        status_dict['disks'] = disks_dict

        services_status_dict, err = get_services_status()
        if err:
            raise Exception(err)
        status_dict["services"] = services_status_dict
        if services_status_dict:
            for service_name, service_info in services_status_dict.items():
                if service_info[0] != 0:
                    status_dict['errors'].append({
                        'subsystem_type_id':
                        2,
                        'severity_type_id':
                        3,
                        'component':
                        service_name,
                        'alert_str':
                        'Service %s seems to have failed.' % service_name
                    })
                    node_status = 1

        # Process interface information
        interfaces = {}
        interface_status_dict, err = get_interface_status()
        if err:
            raise Exception(err)
        # Check the status of existing interfaces
        for ifname, ifdict in manifest_dict["interfaces"].items():
            # Check for all initially present interfaces
            id = {}
            if ifname in interface_status_dict:
                id, err = _convert_to_status_interface_dict(
                    interface_status_dict[ifname])
                if err:
                    raise Exception(err)
            else:
                id["status"] = "Interface Missing"
                node_status = 1
                status_dict["errors"].append({
                    'subsystem_type_id':
                    3,
                    'severity_type_id':
                    3,
                    'component':
                    ifname,
                    'alert_str':
                    "Interface with name %s seems to be missing." % ifname
                })
            interfaces[ifname] = id
        # Check to see if there are any new interfaces
        for ifname, ifinfo in interface_status_dict.items():
            # Check for all newly created interfaces - bonds, vlans, etc
            # print 'ifname is ', ifname
            if ifname not in manifest_dict["interfaces"]:
                id, err = _convert_to_status_interface_dict(
                    interface_status_dict[ifname])
                if err:
                    raise Exception(err)
                interfaces[ifname] = id
        status_dict["interfaces"] = interfaces

        for ifname, id in status_dict['interfaces'].items():
            if ('ip_configured' in id
                    or 'slave_to' in id) and id["status"] != 'up':
                node_status = 1
                status_dict["errors"].append({
                    'subsystem_type_id':
                    3,
                    'severity_type_id':
                    3,
                    'component':
                    ifname,
                    'alert_str':
                    "Interface %s is not up." % ifname
                })

        # print 'interfaces are ', status_dict['interfaces']

        mem_status_dict, err = get_mem_info_status(type='status')
        if err:
            raise Exception(err)
        status_dict['memory'] = mem_status_dict
        '''
                if sd[hostname]["memory"]["mem_total"]["unit"] == "kB":
                    sd[hostname]["memory"]["mem_total"]["value"] = str(
                        int(sd[hostname]["memory"]["mem_total"]["value"]) / 1024)
                    sd[hostname]["memory"]["mem_total"]["unit"] = "MB"
                if sd[hostname]["memory"]["mem_free"]["unit"] == "kB":
                    sd[hostname]["memory"]["mem_free"]["value"] = str(
                        int(sd[hostname]["memory"]["mem_free"]["value"]) / 1024)
                    sd[hostname]["memory"]["mem_free"]["unit"] = "MB"
                temp_d["memory"] = sd[hostname]["memory"]
        '''

        lavg, err = get_load_avg()
        if err:
            raise Exception(err)
        if lavg:
            status_dict['load_avg'] = lavg

        if fqdn:
            status_dict['fqdn'] = fqdn

        ipmi, err = get_ipmi_status()
        if err:
            raise Exception(err)
        if ipmi:
            status_dict["ipmi_status"] = ipmi

        if status_dict["load_avg"]['15_min'] >= status_dict["load_avg"][
                'cpu_cores']:
            status_dict["errors"].append({
                'subsystem_type_id':
                4,
                'severity_type_id':
                2,
                'component':
                'None',
                'alert_str':
                "The 15-minute load average has been high."
            })
            node_status = 1
            '''
                    "The 15-minute load average (%.2f) has been high." % temp_d["load_avg"]['15_min']})
            '''
        if status_dict["load_avg"]['5_min'] >= status_dict["load_avg"][
                'cpu_cores']:
            status_dict["errors"].append({
                'subsystem_type_id':
                4,
                'severity_type_id':
                2,
                'component':
                'None',
                'alert_str':
                "The 5-minute load average has been high."
            })
            '''
                    "The 5-minute load average (%.2f) has been high." % temp_d["load_avg"]['5_min']})
            '''

        if 'ipmi_status' in status_dict:
            for status_item in status_dict['ipmi_status']:
                if status_item["status"] not in ['ok', 'nr']:
                    status_dict["errors"].append({
                        'subsystem_type_id':
                        5,
                        'severity_type_id':
                        2,
                        'component':
                        parameter_name,
                        'alert_str':
                        'The %s of the %s is reporting errors' %
                        (status_item["parameter_name"],
                         status_item["component_name"])
                    })

        pools, err = zfs.get_pools()
        if err:
            raise Exception(err)
        if pools:
            status_dict['pools'] = pools

        component_status_dict, err = zfs.get_all_components_status(pools)
        if err:
            raise Exception(err)
        if component_status_dict:
            for pool_name, component_status_list in component_status_dict.items(
            ):
                msg = None
                severity_type_id = 1
                for component in component_status_list:
                    if 'status' in component and 'state' in component[
                            'status'] and component['status'][
                                'state'] != 'ONLINE':
                        if component['type'].lower() == 'pool':
                            if component['status']['state'] == 'DEGRADED':
                                severity_type_id = 2
                            else:
                                severity_type_id = 3
                        if not msg:
                            msg = "The ZFS pool '%s' has the following issue(s) : " % pool_name
                        msg += "The component %s of type '%s' has a state of '%s'. " % (
                            component['name'], component['type'],
                            component['status']['state'])
                if msg:
                    status_dict['errors'].append({
                        'subsystem_type_id': 6,
                        'severity_type_id': severity_type_id,
                        'component': pool_name,
                        'alert_str': msg
                    })

        zfs_ver, err = get_zfs_version()
        if err:
            raise Exception(err)
        status_dict["zfs_version"] = zfs_ver

        os_ver = '%s %s' % (platform.system(), platform.release())
        status_dict["os_version"] = os_ver

        status_dict["node_status"] = node_status
        if node_status == 0:
            status_dict["node_status_str"] = "Healthy"
        elif node_status == 1:
            status_dict["node_status_str"] = "Degraded"
        elif node_status == 2:
            status_dict["node_status_str"] = "New on-node hardware detected"
        elif node_status == -1:
            status_dict["node_status_str"] = "No response. Down?"
            status_dict['errors'].append({
                'subsystem_type_id':
                99,
                'severity_type_id':
                3,
                'component':
                hostname,
                'alert_str':
                'Node %s seems to be down' % hostname
            })
示例#21
0
def create_cifs_share(request):

    return_dict = {}
    try:

        pools, err = zfs.get_pools()
        if err:
            raise Exception(
                'No ZFS pools available. Please create a pool and dataset before creating shares.')

        ds_list = []
        for pool in pools:
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    ds_list.append(
                        (ds['properties']['mountpoint']['value'], ds["name"]))

        if not ds_list:
            raise Exception(
                'No ZFS datasets available. Please create a dataset before creating shares.')

        dataset = path = None
        ret, err = django_utils.get_request_parameter_values(
            request, ['dataset', 'path'])
        if err:
            raise Exception(err)
        if 'dataset' not in ret:
            dataset = ds_list[0][0]
        elif 'dataset' in ret:
            dataset = ret['dataset']
        if 'path' not in ret:
            path = dataset
        elif 'path' in ret:
            path = ret['path']

        return_dict['path'] = path
        return_dict["dataset"] = ds_list

        initial = {}
        initial['path'] = path
        initial['dataset'] = dataset
        if request.method == "GET":
            # Return the form
            initial['guest_ok'] = True
            if 'name' in request.GET:
                initial['name'] = request.GET['name']

            form = samba_shares_forms.CreateShareForm(
                dataset_list=ds_list, initial=initial)
            return_dict["form"] = form

            return django.shortcuts.render_to_response("create_cifs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            # Form submission so create
            form = samba_shares_forms.CreateShareForm(
                request.POST, initial=initial, dataset_list=ds_list)
            return_dict["form"] = form
            if form.is_valid():
                cd = form.cleaned_data
                # print cd
                name = cd["name"]
                path = cd["path"]
                if not path:
                    return_dict["path_error"] = "Please select a dataset."
                    return django.shortcuts.render_to_response("create_cifs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
                if 'new_folder' in cd and cd['new_folder']:
                    try:
                        path = '%s/%s' % (cd['path'], cd['new_folder'])
                        # print path
                        os.mkdir(path)
                        audit_str = 'Created new directory "%s" in "%s"' % (
                            cd['new_folder'], cd['path'])
                        audit.audit("create_dir", audit_str, request)
                    except Exception, e:
                        raise Exception('Error creating subfolder %s : %s' % (
                            cd['new_folder'], str(e)))

                owner_dict, err = config.get_default_file_dir_owner()
                if err:
                    raise Exception(err)
                owner_uid, err = config.get_system_uid_gid(
                    owner_dict['user'], 'user')
                if err:
                    raise Exception(err)
                owner_gid, err = config.get_system_uid_gid(
                    owner_dict['group'], 'group')
                if err:
                    raise Exception(err)

                os.chown(path, owner_uid, owner_gid)

                if "comment" in cd:
                    comment = cd["comment"]
                else:
                    comment = None
                if "read_only" in cd:
                    read_only = cd["read_only"]
                else:
                    read_only = None
                if "browseable" in cd:
                    browseable = cd["browseable"]
                else:
                    browseable = None

                if 'hosts_allow_choice' in cd and cd['hosts_allow_choice'] == 'restricted':
                    if 'hosts_allow' not in cd or not cd['hosts_allow']:
                        raise Exception(
                            'Please enter a valid list of allowed hosts')
                    hosts_allow = cd['hosts_allow']
                else:
                    hosts_allow = None
                # print hosts_allow

                if 'hosts_deny_choice' in cd and cd['hosts_deny_choice'] == 'restricted':
                    if 'hosts_deny' not in cd or not cd['hosts_deny']:
                        raise Exception(
                            'Please enter a valid list of denied hosts')
                    hosts_deny = cd['hosts_deny']
                else:
                    hosts_deny = None
                # print hosts_deny

                guest_ok = True
                ret, err = cifs.create_share(
                    name, comment, True, read_only, path, path, browseable, None, None, "integralstor_novol", hosts_allow=hosts_allow, hosts_deny=hosts_deny)
                if err:
                    raise Exception(err)
                ret, err = cifs.generate_smb_conf()
                if err:
                    raise Exception(err)

                audit_str = "Created Samba share %s" % name
                audit.audit("create_cifs_share", audit_str, request)
                return django.http.HttpResponseRedirect('/storage_access/view_cifs_shares?ack=created')
            else:
示例#22
0
def view_dashboard(request, page = None):
    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'] = si
        # print node.keys()

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

        # Chart specific declarations
        # will return 02, instead of 2.
        end_epoch, err = datetime_utils.get_epoch(when='now')
        if err:
            raise Exception(err)
        start_epoch = end_epoch - 3 * 60 * 60
        start, err = datetime_utils.convert_from_epoch(
            start_epoch, return_format='str', str_format='%H:%M:%S', to='local')
        if err:
            raise Exception(err)
        end, err = datetime_utils.convert_from_epoch(
            end_epoch, return_format='str', str_format='%H:%M:%S', to='local')
        if err:
            raise Exception(err)

        todays_date = (datetime.date.today()).strftime('%02d')

        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(si['disks'])
        disks_ok = True
        for sn, disk in si['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 si:
            num_sensors = len(si['ipmi_status'])
            num_bad_sensors = 0
            ipmi_ok = True
            for sensor in si['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']['used_percent'] > 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 (si["load_avg"]["5_min"] > si["load_avg"]["cpu_cores"]) or (si["load_avg"]["15_min"] > si["load_avg"]["cpu_cores"]):
            load_avg_ok = False
        return_dict['load_avg_ok'] = load_avg_ok

        shares_list, err = cifs.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(datetime.timedelta(seconds=uptime_seconds)).split(':')[:2]))
            return_dict['uptime_str'] = uptime_str

        # CPU status
        if not page:
            page = "sys_health"
        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'] = si
            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.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['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['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'] = "monitoring_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))
示例#23
0
def create_nfs_share(request):
    return_dict = {}
    try:
        pools, err = zfs.get_pools()
        if err:
            raise Exception(err)

        ds_list = []
        for pool in pools:
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    ds_list.append(
                        {'name': ds["name"], 'mountpoint': ds["mountpoint"]})
        if not ds_list:
            raise Exception(
                'No ZFS datasets available. Please create a dataset before creating shares.')

        req_ret, err = django_utils.get_request_parameter_values(
            request, ['dataset', 'path'])
        if err:
            raise Exception(err)

        if 'dataset' in req_ret:
            dataset = req_ret['dataset']
        else:
            dataset = ds_list[0]['mountpoint']
        if 'path' in req_ret:
            path = req_ret['path']
        else:
            path = dataset

        return_dict['path'] = path
        return_dict["dataset"] = ds_list

        if request.method == "GET":
            # Return the conf page
            initial = {}
            initial['path'] = path
            initial['dataset'] = dataset
            form = nfs_shares_forms.CreateShareForm(
                initial=initial, dataset_list=ds_list)
            return_dict['form'] = form
            return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            form = nfs_shares_forms.CreateShareForm(
                request.POST, dataset_list=ds_list)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
            cd = form.cleaned_data
            if 'new_folder' in cd and cd['new_folder']:
                try:
                    os.mkdir('%s/%s' % (cd['path'], cd['new_folder']))
                    audit_str = 'Created new directory "%s" in "%s"' % (
                        cd['new_folder'], cd['path'])
                    audit.audit("create_dir", audit_str, request)
                    cd['path'] = '%s/%s' % (cd['path'], cd['new_folder'])
                except Exception, e:
                    raise Exception('Error creating subfolder %s : %s' % (
                        cd['new_folder'], str(e)))
            result, err = nfs.save_share(cd, True)
            if err:
                raise Exception(err)

            audit_str = "Created NFS share %s" % cd['path']
            audit.audit("create_nfs_share", audit_str, request)
            return django.http.HttpResponseRedirect('/view_nfs_shares?ack=created')
    except Exception, e:
        return_dict['base_template'] = "shares_base.html"
        return_dict["page_title"] = 'Create a NFS share '
        return_dict['tab'] = 'view_nfs_shares_tab'
        return_dict["error"] = 'Error creating a NFS share'
        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 update_ftp_configuration(request):
    return_dict = {}
    try:
        config, err = vsftp.get_ftp_config()
        if err:
            raise Exception(err)
        pools, err = zfs.get_pools()
        ds_list = []
        for pool in pools:
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    ds_list.append(ds["name"])
        cert_list, err = pki.get_ssl_certificates()
        if err:
            raise Exception(err)
        cert_name_list = []
        for cert in cert_list:
            cert_name_list.append(cert['name'])
        # print ds_list
        if not ds_list:
            raise Exception(
                'No ZFS datasets available. Please create a dataset before configuring the FTP service.')

        if request.method == 'GET':
            initial = {}
            if config:
                for key in config.keys():
                    initial[key] = config[key]
            form = ftp_management_forms.ConfigureFTPForm(
                datasets=ds_list, cert_names=cert_name_list, initial=initial)
            return_dict['form'] = form
            return django.shortcuts.render_to_response('update_ftp_configuration.html', return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            form = ftp_management_forms.ConfigureFTPForm(
                request.POST, cert_names=cert_name_list, datasets=ds_list)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response("update_ftp_configuration.html", return_dict, context_instance=django.template.context.RequestContext(request))
            cd = form.cleaned_data
            ret, err = vsftp.update_ftp_config(cd)
            if err:
                raise Exception(err)
            users, err = local_users.get_local_users()
            if err:
                raise Exception(err)
            ret, err = vsftp.create_ftp_user_dirs(cd['dataset'], users)
            if err:
                raise Exception(err)
            audit_str = 'Updated FTP configuration.'
            if cd['ssl_enabled']:
                audit_str = audit_str + \
                    ' SSL enabled with certificate %s' % cd['cert_name']
            else:
                audit_str = audit_str + ' SSL disabled.'
            ret, err = audit.audit("update_ftp_config",
                                   audit_str, request)
            return django.http.HttpResponseRedirect('/storage_access/view_ftp_configuration?ack=saved')
    except Exception, e:
        return_dict['base_template'] = "storage_access_base.html"
        return_dict["page_title"] = 'Configure FTP service'
        return_dict['tab'] = 'ftp_service_settings'
        return_dict["error"] = 'Error configuring the FTP service '
        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))