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
Exemple #2
0
    def __init__(self, instance):
        super(ZabbixStep, self).__init__(instance)

        integration = CredentialType.objects.get(type=CredentialType.ZABBIX)
        environment = self.instance.databaseinfra.environment
        self.credentials = Credential.get_credentials(environment, integration)
        self.provider = None
    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
Exemple #4
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
Exemple #5
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 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)
Exemple #7
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)
Exemple #8
0
    def __init__(self, instance):
        super(VmStep, self).__init__(instance)

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

        self.provider = CloudStackProvider(credentials=credentials)
        self.host = self.instance.hostname
        self.host_cs = HostAttr.objects.get(host=self.host)

        new_plan = self.instance.databaseinfra.plan.engine_equivalent_plan
        cs_plan = PlanAttr.objects.get(plan=new_plan)
        self.bundle = cs_plan.bundle.first()
    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 credentials(self):
     integration = CredentialType.objects.get(type=CredentialType.ZABBIX)
     return Credential.get_credentials(self.environment, integration)
 def credentials(self):
     integration = CredentialType.objects.get(type=CredentialType.ZABBIX)
     return Credential.get_credentials(self.environment, integration)
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 credentials(self):
     integration = CredentialType.objects.get(type=CredentialType.ZABBIX)
     environment = self.instance.databaseinfra.environment
     return Credential.get_credentials(environment, integration)
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)
Exemple #15
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)