Exemple #1
0
def set_data_ruletype(notify_type='1', maddr='*****@*****.**'):
    """
    テストデータの作成
    """

    # ルール種別
    ruletype = RuleType(
        rule_type_id=9999,
        rule_type_name='pytest_name',
        summary=None,
        rule_table_name='pytest_table',
        generation_limit=5,
        group_id='pytest_com',
        artifact_id='pytest_oase',
        container_id_prefix_staging='test',
        container_id_prefix_product='prod',
        current_container_id_staging=None,
        current_container_id_product=None,
        label_count=1,
        unknown_event_notification=notify_type,
        mail_address=maddr,
        disuse_flag='0',
        last_update_timestamp=datetime.datetime(2020,
                                                6,
                                                4,
                                                12,
                                                0,
                                                0,
                                                tzinfo=datetime.timezone.utc),
        last_update_user='******')

    ruletype.save(force_insert=True)

    return ruletype
def set_data():
    """
    テストに必要なデータをDBに登録
    """
    now = datetime.datetime.now(pytz.timezone('UTC'))
    module = import_module('web_app.models.ZABBIX_monitoring_models')
    ZabbixAdapter           = getattr(module, 'ZabbixAdapter')
    ZabbixMatchInfo         = getattr(module, 'ZabbixMatchInfo')

    try:
        with transaction.atomic():

            # テスト用DT作成
            rule_type = RuleType(
                rule_type_name              = 'ZABBIX_TEST用',
                summary                     = '',
                rule_table_name             = 'zabbixtest',
                generation_limit            = 3,
                group_id                    = 'com.oase',
                artifact_id                 = 'zabbix',
                container_id_prefix_staging = 'testzabbix',
                container_id_prefix_product = 'prodzabbix',
                label_count                 = '2',
                last_update_timestamp       = now,
                last_update_user            = '******'
            )
            rule_type.save(force_insert=True)

            # テスト用ラベル作衛
            label0 = DataObject(
                rule_type_id              = rule_type.rule_type_id,
                conditional_name          = 'トリガーID',
                label                     = 'label0',
                conditional_expression_id = 1,
                last_update_timestamp     = now,
                last_update_user          = '******'
            )
            label0.save(force_insert=True)

            label1 = DataObject(
                rule_type_id              = rule_type.rule_type_id,
                conditional_name          = '説明',
                label                     = 'label1',
                conditional_expression_id = 2,
                last_update_timestamp     = now,
                last_update_user          = '******'
            )
            label1.save(force_insert=True)

            # テスト用ZABBIX監視アダプタ作成
            zabbix = ZabbixAdapter(
                zabbix_disp_name          = 'ZABBIX',
                hostname                  = 'pytest-host',
                username                  = '******',
                password                  = '******',
                protocol                  = 'http',
                port                      = 80,
                rule_type_id              = rule_type.rule_type_id,
                last_update_timestamp     = now,
                last_update_user          = '******'
            )
            zabbix.save(force_insert=True)

            # テスト用ZABBIX突合情報作成
            match1 = ZabbixMatchInfo(
                zabbix_adapter_id         = zabbix.zabbix_adapter_id,
                data_object_id            = label0.data_object_id,
                zabbix_response_key       = 'triggerid',
                last_update_timestamp     = now,
                last_update_user          = '******'
            )
            match1.save(force_insert=True)

            match2 = ZabbixMatchInfo(
                zabbix_adapter_id         = zabbix.zabbix_adapter_id,
                data_object_id            = label1.data_object_id,
                zabbix_response_key       = 'description',
                last_update_timestamp     = now,
                last_update_user          = '******'
            )
            match2.save(force_insert=True)

            return rule_type.rule_type_id, zabbix.zabbix_adapter_id

    except Exception as e:
        print(e)