Beispiel #1
0
    def undo(self, workflow_dict):
        try:

            databaseinfra = workflow_dict['databaseinfra']
            environment = databaseinfra.environment
            integration = CredentialType.objects.get(
                type=CredentialType.ZABBIX)
            credentials = Credential.get_credentials(environment=environment,
                                                     integration=integration)
            zabbix_provider = factory_for(databaseinfra=databaseinfra,
                                          credentials=credentials)
            LOG.info(
                "Updating zabbix monitoring for {}...".format(databaseinfra))

            zabbix_provider.migrate_database_monitors_fox2flipper()

            hosts = workflow_dict['source_hosts']
            for host in hosts:
                LOG.info("Updating zabbix host for{}".format(host))
                zabbix_provider.update_host_interface(host_name=host.hostname,
                                                      ip=host.address)

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0012)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
 def zabbix_provider(self):
     if not self.provider:
         self.provider = factory_for(
             databaseinfra=self.instance.databaseinfra,
             credentials=self.credentials
         )
     return self.provider
    def undo(self, workflow_dict):
        try:
            if 'databaseinfra' not in workflow_dict:
                return False

            databaseinfra = workflow_dict['databaseinfra']
            environment = workflow_dict['environment']
            integration = CredentialType.objects.get(
                type=CredentialType.ZABBIX)
            credentials = Credential.get_credentials(environment=environment,
                                                     integration=integration)
            zabbix_provider = factory_for(databaseinfra=databaseinfra,
                                          credentials=credentials)
            LOG.info("Deleting zabbix monitoring for {}...".format(
                workflow_dict['dbtype']))
            zabbix_provider.delete_basic_monitors()
            zabbix_provider.delete_database_monitors()

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0012)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
    def do(self, workflow_dict):
        try:

            if "databaseinfra" not in workflow_dict:
                return False

            databaseinfra = workflow_dict["databaseinfra"]
            environment = workflow_dict["source_environment"]
            integration = CredentialType.objects.get(type=CredentialType.ZABBIX)
            credentials = Credential.get_credentials(environment=environment, integration=integration)
            zabbix_provider = factory_for(databaseinfra=databaseinfra, credentials=credentials)
            LOG.info("Updating zabbix monitoring for {}...".format(databaseinfra))

            hosts = workflow_dict["source_hosts"]
            for host in hosts:
                future_host = host.future_host
                zabbix_provider.update_host_interface(host_name=host.hostname, ip=future_host.address)

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict["exceptions"]["error_codes"].append(DBAAS_0012)
            workflow_dict["exceptions"]["traceback"].append(traceback)

            return False
    def test_factory_for(self):
        databaseinfra = factory.set_up_databaseinfra(is_ha=False)
        provider = factory_for(databaseinfra=databaseinfra,
                               credentials=self.credential,
                               zabbix_api=self.zabbix_api)

        self.assertIsInstance(provider,
                              database_providers.FakeSingleZabbixProvider)
    def test_factory_for(self):
        databaseinfra = factory.set_up_databaseinfra(is_ha=False)
        provider = factory_for(databaseinfra=databaseinfra,
                               credentials=self.credential,
                               zabbix_api=self.zabbix_api)

        self.assertIsInstance(provider,
                              database_providers.FakeSingleZabbixProvider)
Beispiel #7
0
def handle_zabbix_alarms(database):
    from dbaas_zabbix import factory_for
    from dbaas_credentials.credential import Credential
    from dbaas_credentials.models import CredentialType
    integration = CredentialType.objects.get(type=CredentialType.ZABBIX)
    credentials = Credential.get_credentials(environment=database.databaseinfra.environment,
                                             integration=integration)

    return factory_for(databaseinfra=database.databaseinfra, credentials=credentials)
 def test_get_all_hosts_name(self):
     databaseinfra = factory.set_up_databaseinfra(is_ha=False)
     provider = factory_for(databaseinfra=databaseinfra,
                            credentials=self.credential,
                            zabbix_api=self.zabbix_api)
     infra_hosts = ([host.hostname for host in provider.hosts] +
                    provider.get_zabbix_databases_hosts())
     provider_hosts = provider.get_all_hosts_name()
     self.assertEqual(len(infra_hosts), len(provider_hosts))
def handle_zabbix_alarms(database):
    from dbaas_zabbix import factory_for
    from dbaas_credentials.credential import Credential
    from dbaas_credentials.models import CredentialType
    integration = CredentialType.objects.get(type=CredentialType.ZABBIX)
    credentials = Credential.get_credentials(environment=database.databaseinfra.environment,
                                             integration=integration)

    return factory_for(databaseinfra=database.databaseinfra, credentials=credentials)
Beispiel #10
0
    def __init__(self, instance):
        super(ZabbixStep, self).__init__(instance)

        integration = CredentialType.objects.get(type=CredentialType.ZABBIX)
        environment = self.instance.databaseinfra.environment
        credentials = Credential.get_credentials(environment, integration)

        self.zabbix_provider = factory_for(
            databaseinfra=self.instance.databaseinfra, credentials=credentials)
    def do(self):
        DestroyAlarms(self.instance).do()
        zabbix_provider = factory_for(
            databaseinfra=self.instance.databaseinfra,
            credentials=self.credentials,
            engine_version=self.engine_version)
        zabbix_provider.create_instance_basic_monitors(self.host)

        for instance in self.instances:
            zabbix_provider.create_instance_monitors(instance)
Beispiel #12
0
    def do(self):
        DestroyAlarms(self.instance).do()
        engine_version = self.instance.databaseinfra.plan.engine_equivalent_plan.engine.version
        zabbix_provider = factory_for(
            databaseinfra=self.instance.databaseinfra,
            credentials=self.credentials,
            engine_version=engine_version)
        zabbix_provider.create_instance_basic_monitors(self.instance.hostname)

        for instance in self.instances:
            zabbix_provider.create_instance_monitors(instance)
 def zabbix_provider(self):
     if not self.provider:
         infra = self.infra
         if self.plan != self.target_plan:
             infra = copy.deepcopy(self.infra)
             target_plan = self.target_plan
             infra.plan = target_plan
             infra.engine = target_plan.engine
             infra.engine_patch = target_plan.engine.default_engine_patch
         self.provider = factory_for(databaseinfra=infra,
                                     credentials=self.credentials)
     return self.provider
 def test_get_all_hosts_name(self):
     databaseinfra = factory.set_up_databaseinfra(is_ha=False)
     provider = factory_for(
         databaseinfra=databaseinfra,
         credentials=self.credential,
         zabbix_api=self.zabbix_api
     )
     infra_hosts = (
         [host.hostname for host in provider.hosts] +
         provider.get_zabbix_databases_hosts()
     )
     provider_hosts = provider.get_all_hosts_name()
     self.assertEqual(len(infra_hosts), len(provider_hosts))
    def undo(self, workflow_dict):
        try:
            if 'databaseinfra' not in workflow_dict:
                return False

            databaseinfra = workflow_dict['databaseinfra']
            environment = workflow_dict['environment']
            integration = CredentialType.objects.get(type=CredentialType.ZABBIX)
            credentials = Credential.get_credentials(environment=environment,
                                                     integration=integration)
            zabbix_provider = factory_for(databaseinfra=databaseinfra, credentials=credentials)
            LOG.info("Deleting zabbix monitoring for {}...".format(workflow_dict['dbtype']))
            zabbix_provider.delete_basic_monitors()
            zabbix_provider.delete_database_monitors()

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0012)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
def zabbix_collect_used_disk(task):
    # TODO: Write tests for this method
    status = TaskHistory.STATUS_SUCCESS
    threshold_disk_resize = Configuration.get_by_name_as_int(
        "threshold_disk_resize", default=80.0)
    collected = 0
    resizes = 0
    problems = 0

    integration = CredentialType.objects.get(type=CredentialType.ZABBIX)
    for environment in Environment.objects.all():
        task.add_detail("Execution for environment: {}".format(
            environment.name))
        try:
            credentials = Credential.get_credentials(environment=environment,
                                                     integration=integration)
        except IndexError:
            task.update_status_for(
                TaskHistory.STATUS_ERROR,
                "There is no Zabbix credential for {} environment.".format(
                    environment),
            )
            return

        for database in Database.objects.filter(environment=environment):
            database_resized = False
            task.add_detail(message="Database: {}".format(database.name),
                            level=1)

            if database.is_locked:
                message = ("Skip updating disk used size for database {}. "
                           "It is used by another task.").format(database)
                task.add_detail(message, level=2)
                continue

            zabbix_provider = factory_for(databaseinfra=database.databaseinfra,
                                          credentials=credentials)
            metrics = ZabbixMetrics(zabbix_provider.api,
                                    zabbix_provider.main_clientgroup)

            driver = database.databaseinfra.get_driver()
            non_database_instances = driver.get_non_database_instances()

            for host in zabbix_provider.hosts:
                instance = database.databaseinfra.instances.filter(
                    address=host.address).first()
                if instance in non_database_instances:
                    continue

                collected += 1
                task.add_detail(message="Host: {} ({})".format(
                    host.hostname, host.address),
                                level=2)

                try:
                    zabbix_size = metrics.get_current_disk_data_size(host)
                    zabbix_used = metrics.get_current_disk_data_used(host)
                    zabbix_percentage = (zabbix_used * 100) / zabbix_size
                except ZabbixMetricsError as error:
                    ret = host_mount_data_percentage(host, task)
                    if ret != (None, None, None):
                        zabbix_percentage, zabbix_used, zabbix_size = ret
                    else:
                        problems += 1
                        task.add_detail(message="Error: {}".format(error),
                                        level=3)
                        status = TaskHistory.STATUS_WARNING
                        continue

                task.add_detail(
                    message="Zabbix /data: {}% ({}kb/{}kb)".format(
                        zabbix_percentage, zabbix_used, zabbix_size),
                    level=3,
                )

                current_percentage = zabbix_percentage
                current_used = zabbix_used
                current_size = zabbix_size
                if zabbix_percentage >= threshold_disk_resize:
                    (
                        current_percentage,
                        current_used,
                        current_size,
                    ) = host_mount_data_percentage(host=host, task=task)
                    if zabbix_percentage > current_percentage:
                        problems += 1
                        status = TaskHistory.STATUS_WARNING
                        task.add_detail(
                            message="Error: Zabbix metrics not updated",
                            level=4)

                size_metadata = database.databaseinfra.disk_offering.size_kb
                if has_difference_between(size_metadata, current_size):
                    problems += 1
                    task.add_detail(
                        message="Error: Disk size different: {}kb".format(
                            size_metadata),
                        level=4,
                    )
                    status = TaskHistory.STATUS_WARNING
                elif (current_percentage >= threshold_disk_resize
                      and database.disk_auto_resize and not database_resized):
                    try:
                        task_resize = disk_auto_resize(
                            database=database,
                            current_size=size_metadata,
                            usage_percentage=current_percentage,
                        )
                        database_resized = True
                    except Exception as e:
                        problems += 1
                        status = TaskHistory.STATUS_WARNING
                        task.add_detail(
                            message="Error: Could not do resize. {}".format(e),
                            level=4)
                    else:
                        resizes += 1
                        task.add_detail(
                            message="Executing Resize... Task: {}".format(
                                task_resize.id),
                            level=4,
                        )

                if not update_disk(
                        database=database,
                        address=host.address,
                        task=task,
                        total_size=current_size,
                        used_size=current_used,
                ):
                    problems += 1
                    status = TaskHistory.STATUS_WARNING

            zabbix_provider.logout()

    details = "Collected: {} | Resize: {} | Problems: {}".format(
        collected, resizes, problems)
    task.update_status_for(status=status, details=details)
 def call_factory():
     factory_for(databaseinfra=databaseinfra,
                 credentials=self.credential,
                 zabbix_api=self.zabbix_api)
 def call_factory():
     factory_for(databaseinfra=databaseinfra,
                 credentials=self.credential,
                 zabbix_api=self.zabbix_api)
Beispiel #19
0
def zabbix_collect_used_disk(task):
    # TODO: Write tests for this method
    status = TaskHistory.STATUS_SUCCESS
    threshold_disk_resize = Configuration.get_by_name_as_int(
        "threshold_disk_resize", default=80.0)
    collected = 0
    resizes = 0
    problems = 0

    integration = CredentialType.objects.get(type=CredentialType.ZABBIX)
    for environment in Environment.objects.all():
        task.add_detail('Execution for environment: {}'.format(
            environment.name))
        credentials = Credential.get_credentials(environment=environment,
                                                 integration=integration)

        for database in Database.objects.filter(environment=environment):
            database_resized = False
            task.add_detail(message='Database: {}'.format(database.name),
                            level=1)

            zabbix_provider = factory_for(databaseinfra=database.databaseinfra,
                                          credentials=credentials)
            metrics = ZabbixMetrics(zabbix_provider.api,
                                    zabbix_provider.main_clientgroup)

            driver = database.databaseinfra.get_driver()
            non_database_instances = driver.get_non_database_instances()

            for host in zabbix_provider.hosts:
                instance = database.databaseinfra.instances.filter(
                    address=host.address).first()
                if instance in non_database_instances:
                    continue

                collected += 1
                task.add_detail(message='Host: {} ({})'.format(
                    host.hostname, host.address),
                                level=2)

                try:
                    zabbix_size = metrics.get_current_disk_data_size(host)
                    zabbix_used = metrics.get_current_disk_data_used(host)
                    zabbix_percentage = (zabbix_used * 100) / zabbix_size
                except ZabbixMetricsError as error:
                    problems += 1
                    task.add_detail(message='Error: {}'.format(error), level=3)
                    status = TaskHistory.STATUS_WARNING
                    continue

                task.add_detail(message='Zabbix /data: {}% ({}kb/{}kb)'.format(
                    zabbix_percentage, zabbix_used, zabbix_size),
                                level=3)

                current_percentage = zabbix_percentage
                current_used = zabbix_used
                current_size = zabbix_size
                if zabbix_percentage >= threshold_disk_resize:
                    current_percentage, current_used, current_size = host_mount_data_percentage(
                        address=host.address, task=task)
                    if zabbix_percentage > current_percentage:
                        problems += 1
                        status = TaskHistory.STATUS_WARNING
                        task.add_detail(message='Zabbix metrics not updated',
                                        level=4)

                size_metadata = database.databaseinfra.disk_offering.size_kb
                if has_difference_between(size_metadata, current_size):
                    problems += 1
                    task.add_detail(
                        message='Disk size different in metadata: {}kb'.format(
                            size_metadata),
                        level=4)
                    status = TaskHistory.STATUS_WARNING
                elif current_percentage >= threshold_disk_resize and \
                        database.disk_auto_resize and \
                        not database_resized:
                    try:
                        task_resize = disk_auto_resize(
                            database=database,
                            current_size=current_size,
                            usage_percentage=current_percentage)
                        database_resized = True
                    except Exception as e:
                        problems += 1
                        status = TaskHistory.STATUS_WARNING
                        task.add_detail(
                            message='Could not do resize. {}'.format(e),
                            level=4)
                    else:
                        resizes += 1
                        task.add_detail(
                            message='Executing Resize... Task: {}'.format(
                                task_resize.id),
                            level=4)

                if not update_disk(database=database,
                                   address=host.address,
                                   task=task,
                                   total_size=current_size,
                                   used_size=current_used):
                    problems += 1
                    status = TaskHistory.STATUS_WARNING

            zabbix_provider.logout()

    details = 'Collected: {} | Resize: {} | Problems: {}'.format(
        collected, resizes, problems)
    task.update_status_for(status=status, details=details)
Beispiel #20
0
 def zabbix_provider(self):
     if not self.provider:
         self.provider = factory_for(
             databaseinfra=self.instance.databaseinfra,
             credentials=self.credentials)
     return self.provider
def zabbix_collect_used_disk(task):
    # TODO: Write tests for this method
    status = TaskHistory.STATUS_SUCCESS
    threshold_disk_resize = Configuration.get_by_name_as_int(
        "threshold_disk_resize", default=80.0
    )
    collected = 0
    resizes = 0
    problems = 0

    integration = CredentialType.objects.get(type=CredentialType.ZABBIX)
    for environment in Environment.objects.all():
        task.add_detail(
            'Execution for environment: {}'.format(environment.name)
        )
        try:
            credentials = Credential.get_credentials(
                environment=environment, integration=integration
            )
        except IndexError:
            task.update_status_for(
                TaskHistory.STATUS_ERROR,
                'There is no Zabbix credential for {} environment.'.format(
                    environment
                )
            )
            return

        for database in Database.objects.filter(environment=environment):
            database_resized = False
            task.add_detail(
                message='Database: {}'.format(database.name), level=1
            )

            zabbix_provider = factory_for(
                databaseinfra=database.databaseinfra, credentials=credentials
            )
            metrics = ZabbixMetrics(
                zabbix_provider.api, zabbix_provider.main_clientgroup
            )

            driver = database.databaseinfra.get_driver()
            non_database_instances = driver.get_non_database_instances()

            for host in zabbix_provider.hosts:
                instance = database.databaseinfra.instances.filter(address=host.address).first()
                if instance in non_database_instances:
                    continue

                collected += 1
                task.add_detail(
                    message='Host: {} ({})'.format(
                        host.hostname, host.address
                    ), level=2
                )

                try:
                    zabbix_size = metrics.get_current_disk_data_size(host)
                    zabbix_used = metrics.get_current_disk_data_used(host)
                    zabbix_percentage = (zabbix_used * 100)/zabbix_size
                except ZabbixMetricsError as error:
                    problems += 1
                    task.add_detail(message='Error: {}'.format(error), level=3)
                    status = TaskHistory.STATUS_WARNING
                    continue

                task.add_detail(
                    message='Zabbix /data: {}% ({}kb/{}kb)'.format(
                        zabbix_percentage, zabbix_used, zabbix_size
                    ), level=3
                )

                current_percentage = zabbix_percentage
                current_used = zabbix_used
                current_size = zabbix_size
                if zabbix_percentage >= threshold_disk_resize:
                    current_percentage, current_used, current_size = host_mount_data_percentage(
                        address=host.address, task=task
                    )
                    if zabbix_percentage > current_percentage:
                        problems += 1
                        status = TaskHistory.STATUS_WARNING
                        task.add_detail(
                            message='Error: Zabbix metrics not updated',
                            level=4
                        )

                size_metadata = database.databaseinfra.disk_offering.size_kb
                if has_difference_between(size_metadata, current_size):
                    problems += 1
                    task.add_detail(
                        message='Error: Disk size different: {}kb'.format(
                            size_metadata
                        ),
                        level=4
                    )
                    status = TaskHistory.STATUS_WARNING
                elif current_percentage >= threshold_disk_resize and \
                        database.disk_auto_resize and \
                        not database_resized:
                    try:
                        task_resize = disk_auto_resize(
                            database=database,
                            current_size=current_size,
                            usage_percentage=current_percentage
                        )
                        database_resized = True
                    except Exception as e:
                        problems += 1
                        status = TaskHistory.STATUS_WARNING
                        task.add_detail(
                            message='Error: Could not do resize. {}'.format(e),
                            level=4
                        )
                    else:
                        resizes += 1
                        task.add_detail(
                            message='Executing Resize... Task: {}'.format(
                                task_resize.id
                            ), level=4
                        )

                if not update_disk(
                    database=database, address=host.address, task=task,
                    total_size=current_size, used_size=current_used
                ):
                    problems += 1
                    status = TaskHistory.STATUS_WARNING

            zabbix_provider.logout()

    details = 'Collected: {} | Resize: {} | Problems: {}'.format(
        collected, resizes, problems
    )
    task.update_status_for(status=status, details=details)