Esempio n. 1
0
    def get_blob_client(self,
                        resource_group_name,
                        storage_account_name,
                        storage_blob_type='block'):
        keys = dict()
        try:
            # Get keys from the storage account
            self.log('Getting keys')
            account_keys = self.storage_client.storage_accounts.list_keys(
                resource_group_name, storage_account_name)
        except Exception as exc:
            self.fail("Error getting keys for account {0} - {1}".format(
                storage_account_name, str(exc)))

        try:
            self.log('Create blob service')
            if storage_blob_type == 'page':
                return CloudStorageAccount(
                    storage_account_name,
                    account_keys.keys[0].value).create_page_blob_service()
            elif storage_blob_type == 'block':
                return CloudStorageAccount(
                    storage_account_name,
                    account_keys.keys[0].value).create_block_blob_service()
            else:
                raise Exception("Invalid storage blob type defined.")
        except Exception as exc:
            self.fail(
                "Error creating blob service client for storage account {0} - {1}"
                .format(storage_account_name, str(exc)))
Esempio n. 2
0
def check_storage_errors(management, storageact_name, storage_type, subtype,
                         key, warning, critical, verbosity):
    """Check storage errors for the metric given by key
    management -- service management object
    storageact_name -- storage account name
    storage_type -- blob/queue/table
    subtype - tx/cap (transactions or capacity)
    key - needed only for transaction metric
    warning - Nagios warning level 
    warning - Nagios critical level 
    """
    primary_key, _ = retrieve_keys(management, storageact_name.lower())
    if not primary_key:
        return 3, 'Error retrieving storage keys'

    storage_account = CloudStorageAccount(storageact_name.lower(), primary_key)
    if not storage_account:
        return 3, 'Error retrieving storage account'

    try:
        table_service = storage_account.create_table_service()
    except:
        return 3, 'System error in creating table service'
    if subtype == 'cap':
        if storage_type == 'blob':
            return check_storagecap_errors(table_service)
        else:
            return 3, 'Capacity metrics not supported for tables/queues'
    else:
        if (not key):
            return 3, 'Key missing'
        return check_storagetx_errors(table_service, storage_type, key.lower(),
                                      warning, critical, verbosity)
Esempio n. 3
0
    def account_has_blob_containers(self):
        '''
        If there are blob containers, then there are likely VMs depending on this account and it should
        not be deleted.
        '''
        self.log('Checking for existing blob containers')
        keys = dict()
        try:
            # Get keys from the storage account
            account_keys = self.storage_client.storage_accounts.list_keys(
                self.resource_group, self.name)
            keys['key1'] = account_keys.key1
            keys['key2'] = account_keys.key2
        except AzureHttpError as e:
            self.fail(
                "check_for_container:Failed to get account keys: {0}".format(
                    e))

        try:
            cloud_storage = CloudStorageAccount(
                self.name, keys['key1']).create_page_blob_service()
        except Exception as e:
            self.fail(
                "check_for_container:Error creating blob service: {0}".format(
                    e))

        try:
            response = cloud_storage.list_containers()
        except AzureMissingResourceHttpError:
            # No blob storage available?
            return False

        if len(response.items) > 0:
            return True
        return False
Esempio n. 4
0
    def get_blob_client(self, resource_group_name, storage_account_name):
        keys = dict()
        try:
            # Get keys from the storage account
            self.log('Getting keys')
            account_keys = self.storage_client.storage_accounts.list_keys(resource_group_name, storage_account_name)
        except Exception as exc:
            self.fail("Error getting keys for account {0} - {1}".format(storage_account_name, str(exc)))

        try:
            self.log('Create blob service')
            return CloudStorageAccount(storage_account_name, account_keys.keys[0].value).create_block_blob_service()
        except Exception as exc:
            self.fail("Error creating blob service client for storage account {0} - {1}".format(storage_account_name,
                                                                                                str(exc)))
Esempio n. 5
0
        return 3, 'Hosted service {0} not found'.format(cloudservice_name)

    errors = []
    if not service.deployments:
        return 1, 'No deployments found'

    # find the production deployment among deployments
    production_depl = None
    for depl in service.deployments:
        if depl.deployment_slot == 'Production':
            production_depl = depl
            break
    error_code_all = 0
    if production_depl:
        try:
            storage_account = CloudStorageAccount(storageacct_name,
                                                  primary_key)
            table_service = storage_account.create_table_service()
            table_name = 'WAD'+ str(production_depl.private_id) + \
                            'PT'+ '1H' +'R'+'Table'
            error_code_all = 0
            for role in production_depl.role_list:
                role_clause = 'Role eq \'' + role.role_name + '\''
                # we use 2 hours earlier since some times no counters
                # show up with 1 hour
                rngtime = (datetime.utcnow() - datetime.min) - \
                        timedelta(minutes = 120)
                partition_str = '0' + \
                    str(((rngtime.days * 24 * 60 * 60 + rngtime.seconds)
                         * 1000 * 1000 + rngtime.microseconds)*10)
                partition_clause = 'PartitionKey ge \'' + partition_str + '\''
                counter_clause = 'CounterName eq \'' + counter[