Esempio n. 1
0
    def _get_disks_without_uuid(self):
        """
            Gets all disks by querying "df" command (does not handles Disks UUID)
            Use only this method when the /dev/disk/by-uuid/ folder is not available (like in OpenVZ virtual machine)
        """

        df_dict = system.execute_command('df -kP')
        df_split = df_dict.splitlines()

        list_disks = checks.Disks()

        for i in range(1, len(df_split)):
            if df_split[i].startswith('/dev/'):
                line_split = df_split[i].split()

                disk_dict = line_split[0].split('/')
                disk_name = disk_dict[-1]

                check_disk = checks.Disk()
                check_disk.name = text.clean(disk_name)
                check_disk.display_name = text.clean(
                    disk_name.replace('/dev/', ''))
                check_disk.uuid = disk_name

                # Linux count with '1K block' unit
                check_disk.size = int(line_split[1]) * 1024
                check_disk.used = int(line_split[2]) * 1024
                check_disk.free = int(line_split[3]) * 1024

                list_disks.disks.append(check_disk)

        return list_disks
Esempio n. 2
0
    def _get_disks_without_uuid(self):
        """
            Gets all disks by querying "df" command (does not handles Disks UUID)
            Use only this method when the /dev/disk/by-uuid/ folder is not available (like in OpenVZ virtual machine)
        """

        df_dict = system.execute_command('df -kP')
        df_split = df_dict.splitlines()

        list_disks = checks.Disks()

        for i in range(1, len(df_split)):
            if df_split[i].startswith('/dev/'):
                line_split = df_split[i].split()

                disk_dict = line_split[0].split('/')
                disk_name = disk_dict[-1]

                check_disk = checks.Disk()
                check_disk.name = text.clean(disk_name)
                check_disk.display_name = text.clean(disk_name.replace('/dev/', ''))
                check_disk.uuid = disk_name

                # Linux count with '1K block' unit
                check_disk.size = int(line_split[1]) * 1024
                check_disk.used = int(line_split[2]) * 1024
                check_disk.free = int(line_split[3]) * 1024

                list_disks.disks.append(check_disk)

        return list_disks
Esempio n. 3
0
    def _get_disks_by_uuid(self):
        """
            Gets all active disks by UUID
        """

        # Getting all disks by UUID
        disks_by_uuid = {}
        list_disks_uuid = os.listdir('/dev/disk/by-uuid/')

        # This associates UUID with the partition name
        for disk in list_disks_uuid:
            disks_by_uuid[disk] = os.path.realpath(
                os.path.join('/dev/disk/by-uuid/', disk))

        # The "df" command is used to get the size of each disk
        df_dict = system.execute_command('df -kP')
        df_split = df_dict.splitlines()

        list_disks = checks.Disks()

        for i in range(1, len(df_split)):
            if df_split[i].startswith('/dev/'):
                line_split = df_split[i].split()

                # On Linux, "df" can return two name possibilities:
                # - /dev/disk/by-uuid/(uuid)
                # - /dev/(partition_name)
                # We keep only the last part
                disk_id_dict = line_split[0].split('/')
                disk_id = disk_id_dict[-1]

                # Default values whenever the disk_id is not found in the uuid dictionary.
                disk_name = disk_id
                disk_uuid = ''

                if disk_id in disks_by_uuid:
                    disk_name = disks_by_uuid[disk_id]
                    disk_uuid = disk_id
                else:
                    for key, value in disks_by_uuid.iteritems():
                        if value == disk_id:
                            disk_name = value
                            disk_uuid = key

                check_disk = checks.Disk()
                check_disk.name = text.clean(disk_name)
                check_disk.display_name = text.clean(
                    disk_name.replace('/dev/', ''))
                check_disk.uuid = disk_uuid

                # Linux count with '1K block' unit
                check_disk.size = int(line_split[1]) * 1024
                check_disk.used = int(line_split[2]) * 1024
                check_disk.free = int(line_split[3]) * 1024

                list_disks.disks.append(check_disk)

        return list_disks
Esempio n. 4
0
    def _get_disks_by_uuid(self):
        """
            Gets all active disks by UUID
        """

        # Getting all disks by UUID
        disks_by_uuid = {}
        list_disks_uuid = os.listdir('/dev/disk/by-uuid/')

        # This associates UUID with the partition name
        for disk in list_disks_uuid:
            disks_by_uuid[disk] = os.path.realpath(os.path.join('/dev/disk/by-uuid/', disk))

        # The "df" command is used to get the size of each disk
        df_dict = system.execute_command('df -kP')
        df_split = df_dict.splitlines()

        list_disks = checks.Disks()

        for i in range(1, len(df_split)):
            if df_split[i].startswith('/dev/'):
                line_split = df_split[i].split()

                # On Linux, "df" can return two name possibilities:
                # - /dev/disk/by-uuid/(uuid)
                # - /dev/(partition_name)
                # We keep only the last part
                disk_id_dict = line_split[0].split('/')
                disk_id = disk_id_dict[-1]

                # Default values whenever the disk_id is not found in the uuid dictionary.
                disk_name = disk_id
                disk_uuid = ''

                if disk_id in disks_by_uuid:
                    disk_name = disks_by_uuid[disk_id]
                    disk_uuid = disk_id
                else:
                    for key, value in disks_by_uuid.iteritems():
                        if value == disk_id:
                            disk_name = value
                            disk_uuid = key

                check_disk = checks.Disk()
                check_disk.name = text.clean(disk_name)
                check_disk.display_name = text.clean(disk_name.replace('/dev/', ''))
                check_disk.uuid = disk_uuid

                # Linux count with '1K block' unit
                check_disk.size = int(line_split[1]) * 1024
                check_disk.used = int(line_split[2]) * 1024
                check_disk.free = int(line_split[3]) * 1024

                list_disks.disks.append(check_disk)

        return list_disks
Esempio n. 5
0
    def get_disks(self):
        """
            Gets active disks (with disk size for the moment).
        """

        df_dict = system.execute_command('df')

        df_split = df_dict.splitlines()
        header = df_split[0].split()

        # New return entity
        list_disks = checks.Disks()

        for i in range(1, len(df_split)):
            if df_split[i].startswith('/dev/'):
                line_split = df_split[i].split()
                line_dict = dict(zip(header, line_split))

                # Getting info in MB (Mac OS count with '512 blocks' unit)
                disk_total = int(
                    line_dict['512-blocks']) * MacCollector.BLOCKBYTES_TO_BYTES
                disk_used = int(
                    line_dict['Used']) * MacCollector.BLOCKBYTES_TO_BYTES
                disk_free = int(
                    line_dict['Available']) * MacCollector.BLOCKBYTES_TO_BYTES

                # Getting user friendly name
                disk_name = system.execute_command(
                    'diskutil info "' + line_dict['Filesystem'] + '"'
                    ' | grep "Volume Name"'
                    ' | awk "BEGIN { FS=\\":\\" } END { print $2; }"')

                disk_uuid = system.execute_command(
                    'diskutil info "' + line_dict['Filesystem'] + '"'
                    ' | grep "Volume UUID"'
                    ' | awk "BEGIN { FS=\\":\\" } END { print $2; }"')

                # Using new check entity
                check_disk = checks.Disk()
                check_disk.name = text.clean(line_dict['Filesystem'])
                check_disk.display_name = text.clean(disk_name.lstrip())
                check_disk.uuid = text.clean(disk_uuid)
                check_disk.size = disk_total
                check_disk.used = disk_used
                check_disk.free = disk_free

                list_disks.disks.append(check_disk)

        return list_disks
Esempio n. 6
0
    def get_disks(self):
        """
            Gets active disks (with disk size for the moment).
        """

        df_dict = system.execute_command('df')

        df_split = df_dict.splitlines()
        header = df_split[0].split()

        # New return entity
        list_disks = checks.Disks()

        for i in range(1, len(df_split)):
            if df_split[i].startswith('/dev/'):
                line_split = df_split[i].split()
                line_dict = dict(zip(header, line_split))

                # Getting info in MB (Mac OS count with '512 blocks' unit)
                disk_total = int(line_dict['512-blocks']) * MacCollector.BLOCKBYTES_TO_BYTES
                disk_used = int(line_dict['Used']) * MacCollector.BLOCKBYTES_TO_BYTES
                disk_free = int(line_dict['Available']) * MacCollector.BLOCKBYTES_TO_BYTES

                # Getting user friendly name
                disk_name = system.execute_command('diskutil info "' + line_dict['Filesystem'] + '"'
                                                   ' | grep "Volume Name"'
                                                   ' | awk "BEGIN { FS=\\":\\" } END { print $2; }"')

                disk_uuid = system.execute_command('diskutil info "' + line_dict['Filesystem'] + '"'
                                                   ' | grep "Volume UUID"'
                                                   ' | awk "BEGIN { FS=\\":\\" } END { print $2; }"')

                # Using new check entity
                check_disk = checks.Disk()
                check_disk.name = text.clean(line_dict['Filesystem'])
                check_disk.display_name = text.clean(disk_name.lstrip())
                check_disk.uuid = text.clean(disk_uuid)
                check_disk.size = disk_total
                check_disk.used = disk_used
                check_disk.free = disk_free

                list_disks.disks.append(check_disk)

        return list_disks