# -*- coding: utf-8 -*-
# Argus模块公共封装类
# 作者: 陈磊
# 时间: 2019-12-17
import time

from WorkApi.APP.AddressBook.Iplist.addressbook_iplist_get import AddressBookIplistGet
from WorkApi.APP.AddressBook.addressbook_create import AddressBookCreate
from WorkApi.APP.AddressBook.addressbook_delete import AddressBookDelete
from WorkApi.APP.AddressBook.addressbook_disabled import AddressBookDisabled
from WorkApi.APP.AddressBook.addressbook_enabled import AddressBookEnabled
from WorkApi.APP.AddressBook.addressbook_get import AddressBookGet
from WorkApi.APP.AddressBook.addressbook_update import AddressBookUpdate
from WorkApi.APP.Api.api_login import ApiLogin
from WorkApi.APP.Businesses.Type.businesses_type_create import BusinessesTypeCreate
from WorkApi.APP.Businesses.Type.businesses_type_delete import BusinessesTypeDelete
from WorkApi.APP.Businesses.Type.businesses_type_get import BusinessesTypeGet
from WorkApi.APP.Businesses.Type.businesses_type_update import BusinessesTypeUpdate
from WorkApi.APP.Businesses.businesses_create import BusinessesCreate
from WorkApi.APP.Businesses.businesses_delete import BusinessesDelete
from WorkApi.APP.Businesses.businesses_get import BusinessesGet
from WorkApi.APP.Businesses.businesses_tree import BusinessesTree
from WorkApi.APP.Businesses.businesses_update import BusinessesUpdate
from WorkApi.APP.Device.Asset.device_asset_getFactoryList import DeviceAssetGetFactoryList
from WorkApi.APP.Device.Asset.device_asset_ips import DeviceAssetIps
from WorkApi.APP.Device.device_create import DeviceCreate
import allure

from WorkApi.APP.Device.device_delete import DeviceDelete
from WorkApi.APP.Device.device_get import DeviceGet
from WorkApi.APP.Device.device_status import DeviceStatus
from WorkApi.APP.Device.device_update import DeviceUpdate
from WorkApi.APP.Experience.Items.experience_items_list import ExperienceItemsList
from WorkApi.APP.Experience.Problem.experience_problem_list import ExperienceProblemList
from WorkApi.APP.Experience.experience_create import ExperienceCreate
from WorkApi.APP.Experience.experience_delete import ExperienceDelete
from WorkApi.APP.Experience.experience_get import ExperienceGet
from WorkApi.APP.Experience.experience_update import ExperienceUpdate
from WorkApi.APP.File.file_upload import FileUpload
from WorkApi.APP.HostMonitor.hostMonitor_get import HostMonitorGet
from WorkApi.APP.HostMonitor.hostMonitor_get_hostid import HostMonitorGetHostid
from WorkApi.APP.HostMonitor.hostMonitor_thread_hostid import HostMonitorThreadHostid
from WorkApi.APP.HostType.hostType_create import HostTypeCreate
from WorkApi.APP.HostType.hostType_delete import HostTypeDelete
from WorkApi.APP.HostType.hostType_get import HostTypeGet
from WorkApi.APP.HostType.hostType_list import HostTypeList
from WorkApi.APP.HostType.hostType_tree import HostTypeTree
from WorkApi.APP.HostType.hostType_update import HostTypeUpdate
from WorkApi.APP.LatestWarning.latestWarning_acknowledge_eventid import LatestWarningAcknowledgeEventid
from WorkApi.APP.LatestWarning.latestWarning_get import LatestWarningGet
from WorkApi.APP.LatestWarning.latestWarning_ignore_eventid import LatestWarningIgnoreEventid
from WorkApi.APP.Members.Get.members_get_role import MembersGetRole
from WorkApi.APP.Members.Update.members_update_info import MembersUpdateInfo
from WorkApi.APP.Members.Update.members_update_status import MembersUpdateStatus
from WorkApi.APP.Members.members_create import MembersCreate
from WorkApi.APP.Members.members_delete import MembersDelete
from WorkApi.APP.Members.members_get import MembersGet
from WorkApi.APP.Members.members_list import MembersList
from WorkApi.APP.Rule.rule_create import RuleCreate
from WorkApi.APP.Rule.rule_delete import RuleDelete
from WorkApi.APP.Rule.rule_get import RuleGet
from WorkApi.APP.Rule.rule_list import RuleList
from WorkApi.APP.Rule.rule_update import RuleUpdate
from WorkApi.APP.Settings.Get.settings_get_member import SettingsGetMember
from WorkApi.APP.Settings.settings_changePassword import SettingsChangePassword
from WorkData.Argus.members import DataMembers
from WorkUtils.UtilsResponse import UtilsResponse

from WorkApi.APP.Inspection.Rule.inspection_rule_create import InspectionRuleCreate
from WorkApi.APP.Inspection.Rule.inspection_rule_delete import InspectionRuleDelete
from WorkApi.APP.Inspection.Rule.inspection_rule_get import InspectionRuleGet
from WorkApi.APP.Inspection.Rule.inspection_rule_update import InspectionRuleUpdate
from WorkApi.APP.Inspection.Rule.inspection_rule_status import InspectionRuleStatus


class AppBase(object):
    def __init__(self, host):
        self.host = host
        self.token = None

    @allure.step("调用接口：api.login")
    def api_login(self, name=None, password=None):
        api = ApiLogin(_host=self.host)
        api.name = name
        api.password = password
        api.get_response()
        return api.response

    @allure.step("获取token")
    def get_base_token(self, login_name, base_password):
        response = self.api_login(name=login_name, password=base_password)
        self.token = UtilsResponse().get_data(response=response)
        return self.token

    @allure.step("调用接口：businesses.type.create")
    def businesses_type_create(self, token=None, typeName=None):
        api = BusinessesTypeCreate(_host=self.host)
        api.token = token
        api.typeName = typeName
        api.get_response()
        return api.response

    @allure.step("调用接口：businesses.type.delete")
    def businesses_type_delete(self, token=None, typeIds=None):
        api = BusinessesTypeDelete(_host=self.host)
        api.token = token
        api.typeIds = typeIds
        api.get_response()
        return api.response

    @allure.step("调用接口：businesses.type.get")
    def businesses_type_get(self, token=None):
        api = BusinessesTypeGet(_host=self.host)
        api.token = token
        api.get_response()
        return api.response

    @allure.step("调用接口：businesses.type.update")
    def businesses_type_update(self, token=None, _id=None, typeName=None):
        api = BusinessesTypeUpdate(_host=self.host)
        api.token = token
        api.id = _id
        api.typeName = typeName
        api.get_response()
        return api.response

    @allure.step("调用接口：businesses.create")
    def businesses_create(self, token=None, name=None, description=None, _type=None, principalName=None, principalPhone=None,
                          memberid=None):
        api = BusinessesCreate(_host=self.host)
        api.token = token
        api.name = name
        api.description = description
        api.type = _type
        api.principalName = principalName
        api.principalPhone = principalPhone
        api.memberid = memberid
        api.get_response()
        return api.response

    @allure.step("调用接口：businesses.delete")
    def businesses_delete(self, token=None, businessidList=None):
        api = BusinessesDelete(_host=self.host)
        api.token = token
        api.businessidList = businessidList
        api.get_response()
        return api.response

    @allure.step("调用接口：businesses.get")
    def businesses_get(self, token=None, memberid=None, principal=None, _type=None, hostName=None, businessesName=None):
        api = BusinessesGet(_host=self.host)
        api.token = token
        api.memberid = memberid
        api.principal = principal
        api.type = _type
        api.hostName = hostName
        api.businessesName = businessesName
        api.get_response()
        return api.response

    @allure.step("调用接口：businesses.update")
    def businesses_update(self, token=None, businessid=None, name=None, description=None, _type=None, principalName=None, principalPhone=None, memberid=None):
        api = BusinessesUpdate(_host=self.host)
        api.token = token
        api.businessid = businessid
        api.name = name
        api.description = description
        api.type = _type
        api.principalName = principalName
        api.principalPhone = principalPhone
        api.memberid = memberid
        api.get_response()
        return api.response

    @allure.step("调用接口：businesses.tree")
    def businesses_tree(self, token=None):
        api = BusinessesTree(_host=self.host)
        api.token = token
        api.get_response()
        return api.response

    @allure.step("调用接口：addressbook.create")
    def addressbook_create(self, token=None, name=None, iplist=None, available=None, _type=None, delay=None):
        api = AddressBookCreate(_host=self.host)
        api.token = token
        api.name = name
        api.iplist = iplist
        api.available = available
        api.type = _type
        api.delay = delay
        api.get_response()
        return api.response

    @allure.step("调用接口：addressbook.delete")
    def addressbook_delete(self, token=None, bookids=None):
        api = AddressBookDelete(_host=self.host)
        api.token = token
        api.bookids = bookids
        api.get_response()
        return api.response

    @allure.step("调用接口：addressbook.disable")
    def addressbook_disabled(self, token=None, bookids=None):
        api = AddressBookDisabled(_host=self.host)
        api.token = token
        api.bookids = bookids
        api.get_response()
        return api.response

    @allure.step("调用接口：addressbook.enable")
    def addressbook_enabled(self, token=None, bookids=None):
        api = AddressBookEnabled(_host=self.host)
        api.token = token
        api.bookids = bookids
        api.get_response()
        return api.response

    @allure.step("调用接口：addressbook.iplist.get")
    def addressbook_iplist_get(self, token=None, ruleid=None, available=None):
        api = AddressBookIplistGet(_host=self.host)
        api.token = token
        api.ruleid = ruleid
        api.available = available
        api.get_response()
        return api.response

    @allure.step("调用接口：addressbook.get")
    def addressbook_get(self, token=None, name=None, available=None):
        api = AddressBookGet(_host=self.host)
        api.token = token
        api.name = name
        api.available = available
        api.get_response()
        return api.response

    @allure.step("调用接口：addressbook.update")
    def addressbook_update(self, token=None, bookid=None, name=None, iplist=None, _type=None, available=None):
        api = AddressBookUpdate(_host=self.host)
        api.token = token
        api.bookid = bookid
        api.name = name
        api.iplist = iplist
        api.type = _type
        api.available = available
        api.get_response()
        return api.response

    @allure.step("调用接口：device.create")
    def device_create(self, token=None, hostName=None, hostType=None, manageLevel=None, iplist=None, dns=None,
                      monitorInterface=None, monitorType=None, parentHost=None, businessIds=None,
                      hostTypeTree=None, businessTree=None, opsPerson=None, snmpCommunity=None, ipmiAuthtype=None,
                      ipmiPrivilege=None, ipmiUsername=None, ipmiPassword=None,
                      factoryId=None, model=None, version=None, serialnumber=None,
                      description=None, monitorStatus=None):
        api = DeviceCreate(_host=self.host)
        api.token = token
        api.hostName = hostName
        api.hostType = hostType
        api.manageLevel = manageLevel
        api.iplist = iplist
        api.dns = dns
        api.monitorInterface = monitorInterface
        api.monitorType = monitorType
        api.parentHost = parentHost
        api.businessIds = businessIds
        api.hostTypeTree = hostTypeTree
        api.businessTree = businessTree
        api.opsPerson = opsPerson
        api.snmpCommunity = snmpCommunity
        api.ipmiAuthtype = ipmiAuthtype
        api.ipmiPrivilege = ipmiPrivilege
        api.ipmiUsername = ipmiUsername
        api.ipmiPassword = ipmiPassword
        api.factoryId = factoryId
        api.model = model
        api.version = version
        api.serialnumber = serialnumber
        api.description = description
        api.monitorStatus = monitorStatus
        api.get_response()
        return api.response

    @allure.step("调用接口：device.update")
    def device_update(self, token=None, hostid=None, hostName=None, hostType=None, manageLevel=None, iplist=None, dns=None,
                      monitorInterface=None, monitorType=None, parentHost=None, businessIds=None,
                      hostTypeTree=None, businessTree=None, opsPerson=None, snmpCommunity=None, ipmiAuthtype=None,
                      ipmiPrivilege=None, ipmiUsername=None, ipmiPassword=None,
                      factoryId=None, model=None, version=None, serialnumber=None,
                      description=None, monitorStatus=None):
        api = DeviceUpdate(_host=self.host)
        api.token = token
        api.hostid = hostid
        api.hostName = hostName
        api.hostType = hostType
        api.manageLevel = manageLevel
        api.iplist = iplist
        api.dns = dns
        api.monitorInterface = monitorInterface
        api.monitorType = monitorType
        api.parentHost = parentHost
        api.businessIds = businessIds
        api.hostTypeTree = hostTypeTree
        api.businessTree = businessTree
        api.opsPerson = opsPerson
        api.snmpCommunity = snmpCommunity
        api.ipmiAuthtype = ipmiAuthtype
        api.ipmiPrivilege = ipmiPrivilege
        api.ipmiUsername = ipmiUsername
        api.ipmiPassword = ipmiPassword
        api.factoryId = factoryId
        api.model = model
        api.version = version
        api.serialnumber = serialnumber
        api.description = description
        api.monitorStatus = monitorStatus
        api.get_response()
        return api.response

    @allure.step("调用接口：device.delete")
    def device_delete(self, token=None, hostids=None):
        api = DeviceDelete(_host=self.host)
        api.token = token
        api.hostids = hostids
        api.get_response()
        return api.response

    @allure.step("调用接口：device.get")
    def device_get(self, token=None, menuId=None, name=None, _type=None, manageLevel=None, monitorStatus=None,
                   parentHost=None, businessIds=None, available=None, memberId=None, factoryId=None,
                   assetCode=None, manageIp=None):
        api = DeviceGet(_host=self.host)
        api.token = token
        api.menuId = menuId
        api.name = name
        api.type = _type
        api.manageLevel = manageLevel
        api.monitorStatus = monitorStatus
        api.available = available
        api.parentHost = parentHost
        api.businessIds = businessIds
        api.memberId = memberId
        api.factoryId = factoryId
        api.assetCode = assetCode
        api.manageIp = manageIp
        api.get_response()
        return api.response

    @allure.step("调用接口：device.status")
    def device_status(self, token=None, hostids=None, monitorStatus=None):
        api = DeviceStatus(_host=self.host)
        api.token = token
        api.hostids = hostids
        api.monitorStatus = monitorStatus
        api.get_response()
        return api.response

    @allure.step("调用接口：device.asset.ips")
    def device_asset_ips(self, token=None, ipName=None):
        api = DeviceAssetIps(_host=self.host)
        api.token = token
        api.ipName = ipName
        api.get_response()
        return api.response

    @allure.step("调用接口：device.asset.getFactoryList")
    def device_asset_getFactoryList(self, token=None, hostType=None):
        api = DeviceAssetGetFactoryList(_host=self.host)
        api.token = token
        api.hostType = hostType
        api.get_response()
        return api.response

    @allure.step("创建测试数据-资产")
    def case_create_host(self, name, host_type, port, businessIds, iplist=None, dns=None, parentHost=None, monitorType=None, monitorStatus=None):
        if monitorStatus is not None and monitorType is not None and parentHost is not None:
            response = self.device_create(
                token=self.token, hostName=name, hostType=host_type, iplist=iplist, dns=dns, monitorInterface=port,
                monitorType=monitorType, manageLevel=1, parentHost=parentHost, businessIds=businessIds,
                opsPerson=11, snmpCommunity="public",
                ipmiAuthtype=1, ipmiPrivilege=1, ipmiUsername="ipmiUsername", ipmiPassword="ipmiPassword",
                factoryId=1, model="model", version="version", serialnumber="serialnumber", description="description",
                monitorStatus=monitorStatus)
        elif monitorStatus is not None and monitorType is not None and parentHost is None:
            response = self.device_create(
                token=self.token, hostName=name, hostType=host_type, iplist=iplist, dns=dns, monitorInterface=port,
                monitorType=monitorType, manageLevel=1, parentHost=1, businessIds=businessIds,
                opsPerson=11, snmpCommunity="public",
                ipmiAuthtype=1, ipmiPrivilege=1, ipmiUsername="ipmiUsername", ipmiPassword="ipmiPassword",
                factoryId=1, model="model", version="version", serialnumber="serialnumber", description="description",
                monitorStatus=monitorStatus)
        elif monitorStatus is not None and monitorType is None and parentHost is not None:
            response = self.device_create(
                token=self.token, hostName=name, hostType=host_type, iplist=iplist, dns=dns, monitorInterface=port,
                monitorType=1, manageLevel=1, parentHost=parentHost, businessIds=businessIds,
                opsPerson=11, snmpCommunity="public",
                ipmiAuthtype=1, ipmiPrivilege=1, ipmiUsername="ipmiUsername", ipmiPassword="ipmiPassword",
                factoryId=1, model="model", version="version", serialnumber="serialnumber", description="description",
                monitorStatus=monitorStatus)
        elif monitorStatus is None and monitorType is not None and parentHost is not None:
            response = self.device_create(
                token=self.token, hostName=name, hostType=host_type, iplist=iplist, dns=dns, monitorInterface=port,
                monitorType=monitorType, manageLevel=1, parentHost=parentHost, businessIds=businessIds,
                opsPerson=11, snmpCommunity="public",
                ipmiAuthtype=1, ipmiPrivilege=1, ipmiUsername="ipmiUsername", ipmiPassword="ipmiPassword",
                factoryId=1, model="model", version="version", serialnumber="serialnumber", description="description",
                monitorStatus=1)

        elif monitorStatus is not None and monitorType is None and parentHost is None:
            response = self.device_create(
                token=self.token, hostName=name, hostType=host_type, iplist=iplist, dns=dns, monitorInterface=port,
                monitorType=1, manageLevel=1, parentHost=1, businessIds=businessIds,
                opsPerson=11, snmpCommunity="public",
                ipmiAuthtype=1, ipmiPrivilege=1, ipmiUsername="ipmiUsername", ipmiPassword="ipmiPassword",
                factoryId=1, model="model", version="version", serialnumber="serialnumber", description="description",
                monitorStatus=monitorStatus)
        elif monitorStatus is None and monitorType is not None and parentHost is None:
            response = self.device_create(
                token=self.token, hostName=name, hostType=host_type, iplist=iplist, dns=dns, monitorInterface=port,
                monitorType=monitorType, manageLevel=1, parentHost=1, businessIds=businessIds,
                opsPerson=11, snmpCommunity="public",
                ipmiAuthtype=1, ipmiPrivilege=1, ipmiUsername="ipmiUsername", ipmiPassword="ipmiPassword",
                factoryId=1, model="model", version="version", serialnumber="serialnumber", description="description",
                monitorStatus=1)
        elif monitorStatus is None and monitorType is None and parentHost is not None:
            response = self.device_create(
                token=self.token, hostName=name, hostType=host_type, iplist=iplist, dns=dns, monitorInterface=port,
                monitorType=1, manageLevel=1, parentHost=parentHost, businessIds=businessIds,
                opsPerson=11, snmpCommunity="public",
                ipmiAuthtype=1, ipmiPrivilege=1, ipmiUsername="ipmiUsername", ipmiPassword="ipmiPassword",
                factoryId=1, model="model", version="version", serialnumber="serialnumber", description="description",
                monitorStatus=1)

        else:
            response = self.device_create(
                token=self.token, hostName=name, hostType=host_type, iplist=iplist, dns=dns, monitorInterface=port,
                monitorType=1, manageLevel=1, parentHost=1, businessIds=businessIds,
                opsPerson=11, snmpCommunity="public",
                ipmiAuthtype=1, ipmiPrivilege=1, ipmiUsername="ipmiUsername", ipmiPassword="ipmiPassword",
                factoryId=1, model="model", version="version", serialnumber="serialnumber", description="description",
                monitorStatus=1)

        self.check_code(response=response, code=0)
        host_id = UtilsResponse().get_data(response=response)
        return host_id

    @allure.step("创建测试数据-业务类型")
    def case_create_businesses_type(self, name):
        response = self.businesses_type_create(token=self.token, typeName=name)
        self.check_code(response=response, code=0)
        type_id = UtilsResponse().get_data(response=response)
        return type_id

    @allure.step("创建测试数据-业务")
    def case_create_businesses(self, name, _type, principalPhone=None, principalName=None):
        response = self.businesses_create(token=self.token, name=name, _type=_type, principalPhone=principalPhone, principalName=principalName)
        business_id = UtilsResponse().get_data(response=response)
        return business_id

    @allure.step("创建测试数据-地址簿")
    def case_create_addressbook(self, name, iplist, available, _type=None):
        response = self.addressbook_create(token=self.token, name=name, iplist=iplist, available=available, _type=_type, delay="1h")
        self.check_code(response=response, code=0)
        address_id = UtilsResponse().get_data(response=response)
        return address_id

    @allure.step("创建测试数据")
    def case_create_member(self, name, password, role=None, position=None, phone=None,
                           email=None, wechatUrl=None, dingdingUrl=None, remark=None,
                           silenceTime=None, period=None, severity=None):
        response = self.members_create(token=self.token, name=name, password=password, role=role, position=position,
                                       phone=phone, email=email, wechatUrl=wechatUrl, dingdingUrl=dingdingUrl,
                                       remark=remark, silenceTime=silenceTime, period=period, severity=severity)
        self.check_code(response=response, code=0)
        member_id = UtilsResponse().get_data(response=response)
        return member_id

    @allure.step("断言返回结果")
    def check_code(self, response, code):
        _code = UtilsResponse().get_code(response=response)
        assert _code == code

    @allure.step("断言返回结果数据")
    def check_msg(self, response, msg):
        _msg = UtilsResponse().get_msg(response=response)
        assert _msg == msg

    @allure.step("校验数据")
    def check_keyValue(self, _json, _key, _value, isIn=None):
        assert _json != []
        for x, y in enumerate(_json):
            if isIn == 1:
                assert _value in y[_key]
            else:
                assert y[_key] == _value

    @allure.step("更新表数据：members -- del_flag")
    def update_members_del_flag(self, session, members_id=None, value=None):
        sql = DataMembers().update_del_flag(session=session, _id=members_id, value=value)
        time.sleep(10)
        return sql

    @allure.step("更新表数据：members -- status")
    def update_members_status(self, session, members_id=None, value=None):
        sql = DataMembers().update_status(session=session, _id=members_id, value=value)
        time.sleep(10)
        return sql

    @allure.step("更新表数据：members -- password")
    def update_members_password(self, session, members_id=None, value=None):
        sql = DataMembers().update_password(session=session, _id=members_id, value=value)
        return sql

    @allure.step("调用接口：settings.changePassword")
    def settings_changePassword(self, token=None, memberId=None, oldPassword=None, newPassword=None):
        api = SettingsChangePassword(_host=self.host)
        api.token = token
        api.memberId = memberId
        api.oldPassword = oldPassword
        api.newPassword = newPassword
        api.get_response()
        return api.response

    @allure.step("调用接口：settings.get.member")
    def settings_get_member(self, token=None, memberId=None):
        api = SettingsGetMember(_host=self.host)
        api.token = token
        api.memberId = memberId
        api.get_response()
        return api.response

    @allure.step("调用接口：members.create")
    def members_create(self, token=None, name=None, position=None, role=None, password=None,
                       phone=None, email=None, wechatUrl=None, dingdingUrl=None, remark=None,
                       silenceTime=None, period=None, severity=None):
        api = MembersCreate(_host=self.host)
        api.token = token
        api.name = name
        api.position = position
        api.role = role
        api.password = password
        api.phone = phone
        api.email = email
        api.wechatUrl = wechatUrl
        api.dingdingUrl = dingdingUrl
        api.remark = remark
        api.silenceTime = silenceTime
        api.period = period
        api.severity = severity
        api.get_response()
        return api.response

    @allure.step("调用接口：members.delete")
    def members_delete(self, token=None, memberIds=None):
        api = MembersDelete(_host=self.host)
        api.token = token
        api.memberIds = memberIds
        api.get_response()
        return api.response

    @allure.step("调用接口：members.get")
    def members_get(self, token=None, name=None, status=None):
        api = MembersGet(_host=self.host)
        api.token = token
        api.name = name
        api.status = status
        api.get_response()
        return api.response

    @allure.step("调用接口：members.get.role")
    def members_get_role(self, token=None):
        api = MembersGetRole(_host=self.host)
        api.token = token
        api.get_response()
        return api.response

    @allure.step("调用接口：members.list")
    def members_list(self, token=None):
        api = MembersList(_host=self.host)
        api.token = token
        api.get_response()
        return api.response

    @allure.step("调用接口：members.update.info")
    def members_update_info(self, token=None, name=None, position=None, role=None, password=None,
                            phone=None, email=None, wechatUrl=None, dingdingUrl=None, remark=None, _id=None,
                            silenceTime=None, period=None, severity=None):
        api = MembersUpdateInfo(_host=self.host)
        api.token = token
        api.name = name
        api.position = position
        api.role = role
        api.password = password
        api.phone = phone
        api.email = email
        api.wechatUrl = wechatUrl
        api.dingdingUrl = dingdingUrl
        api.remark = remark
        api.silenceTime = silenceTime
        api.period = period
        api.severity = severity
        api.id = _id
        api.get_response()
        return api.response

    @allure.step("调用接口：members.update.status")
    def members_update_status(self, token=None, status=None, memberIds=None):
        api = MembersUpdateStatus(_host=self.host)
        api.token = token
        api.status = status
        api.memberIds = memberIds
        api.get_response()
        return api.response

    @allure.step("调用接口：rule.create")
    def rule_create(self, token=None, name=None, severity=None, url=None, description=None, status=None,
                    manualClose=None, enableTimeDefault=None, period=None, periodType=None, triggersList=None,
                    triggersList_hostid=None, triggersList_hostName=None, triggersList_itemid=None,
                    triggersList_itemName=None, triggersList_function=None, triggersList_parameters=None, triggersList_parameters_value=None,
                    triggersList_parameters_unit=None, triggersList_operator=None, triggersList_constant=None,
                    triggersList_logicalSymbol=None, triggersList_onlineFlag=None):
        api = RuleCreate(_host=self.host)
        api.token = token
        api.name = name
        api.severity = severity
        api.url = url
        api.description = description
        api.status = status
        api.manualClose = manualClose
        api.enableTimeDefault = enableTimeDefault
        api.period = period
        api.periodType = periodType
        api.triggersList = triggersList
        api.triggersList_hostid = triggersList_hostid
        api.triggersList_hostName = triggersList_hostName
        api.triggersList_itemid = triggersList_itemid
        api.triggersList_itemName = triggersList_itemName
        api.triggersList_function = triggersList_function
        api.triggersList_parameters = triggersList_parameters
        api.triggersList_parameters_value = triggersList_parameters_value
        api.triggersList_parameters_unit = triggersList_parameters_unit
        api.triggersList_operator = triggersList_operator
        api.triggersList_constant = triggersList_constant
        api.triggersList_logicalSymbol = triggersList_logicalSymbol
        api.triggersList_onlineFlag = triggersList_onlineFlag
        api.get_response()
        return api.response

    @allure.step("调用接口：rule.delete")
    def rule_delete(self, token=None, alarmRuleidList=None):
        api = RuleDelete(_host=self.host)
        api.token = token
        api.alarmRuleidList = alarmRuleidList
        api.get_response()
        return api.response

    @allure.step("调用接口：rule.get")
    def rule_get(self, token=None, severity=None, itemid=None, status=None,
                 manageLevel=None, manageIp=None, hostName=None):
        api = RuleGet(_host=self.host)
        api.token = token
        api.severity = severity
        api.status = status
        api.itemid = itemid
        api.manageLevel = manageLevel
        api.manageIp = manageIp
        api.hostName = hostName
        api.get_response()
        return api.response

    @allure.step("调用接口：rule.update")
    def rule_update(self, token=None, _id=None, name=None, severity=None, url=None, description=None, status=None,
                    manualClose=None, enableTimeDefault=None, period=None, periodType=None, triggersList=None,
                    triggersList_hostid=None, triggersList_hostName=None, triggersList_itemid=None,
                    triggersList_itemName=None, triggersList_function=None, triggersList_parameters=None, triggersList_parameters_value=None,
                    triggersList_parameters_unit=None, triggersList_operator=None, triggersList_constant=None,
                    triggersList_logicalSymbol=None, triggersList_onlineFlag=None):
        api = RuleUpdate(_host=self.host)
        api.id = _id
        api.token = token
        api.name = name
        api.severity = severity
        api.url = url
        api.description = description
        api.status = status
        api.manualClose = manualClose
        api.enableTimeDefault = enableTimeDefault
        api.period = period
        api.periodType = periodType
        api.triggersList = triggersList
        api.triggersList_hostid = triggersList_hostid
        api.triggersList_hostName = triggersList_hostName
        api.triggersList_itemid = triggersList_itemid
        api.triggersList_itemName = triggersList_itemName
        api.triggersList_function = triggersList_function
        api.triggersList_parameters = triggersList_parameters
        api.triggersList_parameters_value = triggersList_parameters_value
        api.triggersList_parameters_unit = triggersList_parameters_unit
        api.triggersList_operator = triggersList_operator
        api.triggersList_constant = triggersList_constant
        api.triggersList_logicalSymbol = triggersList_logicalSymbol
        api.triggersList_onlineFlag = triggersList_onlineFlag
        api.get_response()
        return api.response

    @allure.step("调用接口：rule.list")
    def rule_list(self, token=None, ruleName=None):
        api = RuleList(_host=self.host)
        api.token = token
        api.ruleName = ruleName
        api.get_response()
        return api.response

    @allure.step("调用接口：file.upload")
    def file_upload(self, token=None, _file=None):
        api = FileUpload(_host=self.host)
        api.token = token
        api.file = _file
        api.get_response()
        return api.response

    @allure.step("创建测试数据-告警规则")
    def case_create_rule(self, name, status, severity, host_id, host_name, item_key, itemid, online_flag=None):
        response = self.rule_create(token=self.token, name=name, severity=severity, status=status, manualClose=0, triggersList_hostid=[host_id],
                                    triggersList_hostName=[host_name], triggersList_itemid=[itemid],
                                    triggersList_itemName=[item_key], triggersList_function=["avg"],
                                    triggersList_operator=["="], triggersList_constant=[888],
                                    triggersList_parameters_unit=["m"], triggersList_parameters_value=[5], triggersList_onlineFlag=[online_flag])
        self.check_code(response=response, code=0)
        rule_id = UtilsResponse().get_data(response=response)
        return rule_id

    @allure.step("调用接口：hosttype.create")
    def hostType_create(self, token=None, title=None, parentId=None, templateIds=None, interfaces=None, description=None,
                        sortid=None):
        api = HostTypeCreate(_host=self.host)
        api.token = token
        api.title = title
        api.parentId = parentId
        api.templateIds = templateIds
        api.interfaces = interfaces
        api.description = description
        api.sortid = sortid
        api.get_response()
        return api.response

    @allure.step("调用接口：hosttype.delete")
    def hostType_delete(self, token=None, hosttypeids=None):
        api = HostTypeDelete(_host=self.host)
        api.token = token
        api.hosttypeids = hosttypeids
        api.get_response()
        return api.response

    @allure.step("调用接口：hosttype.get")
    def hostType_get(self, token=None, title=None, parentId=None, description=None):
        api = HostTypeGet(_host=self.host)
        api.token = token
        api.parentId = parentId
        api.title = title
        api.description = description
        api.get_response()
        return api.response

    @allure.step("调用接口：hosttype.list")
    def hostType_list(self, token=None, parentId=None):
        api = HostTypeList(_host=self.host)
        api.token = token
        api.parentId = parentId
        api.get_response()
        return api.response

    @allure.step("调用接口：hosttype.tree")
    def hostType_tree(self, token=None):
        api = HostTypeTree(_host=self.host)
        api.token = token
        api.get_response()
        return api.response

    @allure.step("调用接口：hosttype.update")
    def hostType_update(self, token=None, _id=None, title=None, parentId=None, templateIds=None, interfaces=None, description=None,
                        sortid=None):
        api = HostTypeUpdate(_host=self.host)
        api.token = token
        api.id = _id
        api.title = title
        api.parentId = parentId
        api.templateIds = templateIds
        api.interfaces = interfaces
        api.description = description
        api.sortid = sortid
        api.get_response()
        return api.response

    @allure.step("创建测试数据")
    def case_create_hostType(self, title, parentId, description):
        response = self.hostType_create(token=self.token, title=title, parentId=parentId, description=description)
        host_type_id = UtilsResponse().get_data(response=response)
        return host_type_id

    @allure.step("调用接口：experience.create")
    def experience_create(self, token=None, title=None, content=None, businessids=None, hostTypes=None, hostids=None,
                          itemids=None, manageIpList=None, alarmRuleids=None, description=None, tagNameList=None, problemidList=None,
                          hostTypeTree=None):
        api = ExperienceCreate(_host=self.host)
        api.token = token
        api.title = title
        api.content = content
        api.businessids = businessids
        api.hostTypes = hostTypes
        api.hostids = hostids
        api.itemids = itemids
        api.manageIpList = manageIpList
        api.alarmRuleids = alarmRuleids
        api.description = description
        api.tagNameList = tagNameList
        api.problemidList = problemidList
        api.hostTypeTree = hostTypeTree
        api.get_response()
        return api.response

    @allure.step("调用接口：experience.delete")
    def experience_delete(self, token=None, experienceids=None):
        api = ExperienceDelete(_host=self.host)
        api.token = token
        api.experienceids = experienceids
        api.get_response()
        return api.response

    @allure.step("调用接口：experience.get")
    def experience_get(self, token=None, hostType=None, hostName=None, manageLevel=None, manageIp=None, businessid=None, alarmRuleid=None,
                       itemid=None, title=None, tagid=None, tagName=None, description=None):
        api = ExperienceGet(_host=self.host)
        api.token = token
        api.hostType = hostType
        api.hostName = hostName
        api.manageLevel = manageLevel
        api.manageIp = manageIp
        api.businessid = businessid
        api.alarmRuleid = alarmRuleid
        api.itemid = itemid
        api.title = title
        api.tagid = tagid
        api.tagName = tagName
        api.description = description
        api.get_response()
        return api.response

    @allure.step("调用接口：experience.items.list")
    def experience_items_list(self, token=None, itemName=None):
        api = ExperienceItemsList(_host=self.host)
        api.token = token
        api.itemName = itemName
        api.get_response()
        return api.response

    @allure.step("调用接口：experience.problem.list")
    def experience_problem_list(self, token=None, problemName=None):
        api = ExperienceProblemList(_host=self.host)
        api.token = token
        api.problemName = problemName
        api.get_response()
        return api.response

    @allure.step("调用接口：experience.update")
    def experience_update(self, token=None, _id=None, title=None, content=None, businessids=None, hostTypes=None,
                          hostids=None, itemids=None, manageIpList=None, alarmRuleids=None, description=None, tagNameList=None, problemidList=None,
                          hostTypeTree=None):
        api = ExperienceUpdate(_host=self.host)
        api.token = token
        api.id = _id
        api.title = title
        api.content = content
        api.businessids = businessids
        api.hostTypes = hostTypes
        api.hostids = hostids
        api.itemids = itemids
        api.manageIpList = manageIpList
        api.alarmRuleids = alarmRuleids
        api.description = description
        api.tagNameList = tagNameList
        api.problemidList = problemidList
        api.hostTypeTree = hostTypeTree
        api.get_response()
        return api.response

    @allure.step("创建测试数据-经验手册")
    def case_create_experience(self, title, content, description, host_types, alarmRuleids=None, businessids=None,
                               hostids=None, host_ids=None, itemids=None, problemidLists=None, tagNameLists=None):
        response = self.experience_create(token=self.token, title=title, content=content, hostTypes=host_types,
                                          alarmRuleids=alarmRuleids, businessids=businessids, hostids=hostids,
                                          manageIpList=host_ids, itemids=itemids, problemidList=problemidLists,
                                          tagNameList=tagNameLists, description=description)
        self.check_code(response=response, code=0)
        experienceid = UtilsResponse().get_data(response=response)
        return experienceid

    @allure.step("调用接口：hostmonitor.get")
    def hostmonitor_get(self, token=None, hostName=None, assetCode=None, manageIp=None, parentHost=None, available=None, status=None,
                        page=None, size=None):
        api = HostMonitorGet(_host=self.host)
        api.token = token
        api.hostName = hostName
        api.assetCode = assetCode
        api.manageIp = manageIp
        api.parentHost = parentHost
        api.available = available
        api.status = status
        api.page = page
        api.size = size
        api.get_response()
        return api.response

    @allure.step("调用接口：hostmonitor.get.hostid")
    def hostmonitor_get_hostid(self, token=None, hostid=None):
        api = HostMonitorGetHostid(_host=self.host)
        api.token = token
        api.hostid = hostid
        api.get_response()
        return api.response

    @allure.step("调用接口：hostmonitor.thread.hostid")
    def hostmonitor_thread_hostid(self, token=None, hostid=None):
        api = HostMonitorThreadHostid(_host=self.host)
        api.token = token
        api.hostid = hostid
        api.get_response()
        return api.response

    @allure.step("调用接口：latestWarning.get")
    def latestWarning_get(self, token=None, severity=None, manageLevel=None, acknowledged=None, dateFrom=None,
                          dateTo=None, _object=None, source=None, alarmRuleid=None, experienceid=None, businessid=None):
        api = LatestWarningGet(_host=self.host)
        api.token = token
        api.severity = severity
        api.manageLevel = manageLevel
        api.acknowledged = acknowledged
        api.dateFrom = dateFrom
        api.dateTo = dateTo
        api.object = _object
        api.source = source
        api.alarmRuleid = alarmRuleid
        api.experienceid = experienceid
        api.businessid = businessid
        api.get_response()
        return api.response

    @allure.step("调用接口：latestWarning.acknowledge.eventid")
    def latestWarning_acknowledge_eventid(self, token=None, eventid=None):
        api = LatestWarningAcknowledgeEventid(_host=self.host)
        api.token = token
        api.eventid = eventid
        api.get_response()
        return api.response

    @allure.step("调用接口：latestWarning.ignore.eventid")
    def latestWarning_ignore_eventid(self, token=None, eventid=None):
        api = LatestWarningIgnoreEventid(_host=self.host)
        api.token = token
        api.eventid = eventid
        api.get_response()
        return api.response

    @allure.step("调用接口：inspection.rule.create")
    def inspection_rule_create(self, token=None, name=None, _type=None, time=None, period=None, hosts=None, status=None):
        api = InspectionRuleCreate(_host=self.host)
        api.token = token
        api.name = name
        api.type = _type
        api.time = time
        api.period = period
        api.hosts = hosts
        api.status = status
        api.get_response()
        return api.response

    @allure.step("调用接口：inspection.rule.get")
    def inspection_rule_get(self, token=None, name=None, period=None):
        api = InspectionRuleGet(_host=self.host)
        api.token = token
        api.name = name
        api.period = period
        api.get_response()
        return api.response

    @allure.step("调用接口：inspection.rule.update")
    def inspection_rule_update(self, token=None, _id=None, name=None, _type=None, time=None, period=None,
                               hosts=None, status=None):
        api = InspectionRuleUpdate(_host=self.host)
        api.token = token
        api.id = _id
        api.name = name
        api.type = _type
        api.time = time
        api.period = period
        api.hosts = hosts
        api.status = status
        api.get_response()
        return api.response

    @allure.step("调用接口：inspection.rule.delete")
    def inspection_rule_delete(self, token=None, ruleids=None):
        api = InspectionRuleDelete(_host=self.host)
        api.token = token
        api.ruleids = ruleids
        api.get_response()
        return api.response

    @allure.step("调用接口：inspection.rule.status")
    def inspection_rule_status(self, token=None, _id=None, status=None):
        api = InspectionRuleStatus(_host=self.host)
        api.token = token
        api.id = _id
        api.status = status
        api.get_response()
        return api.response

    @allure.step("创建测试数据-巡检任务")
    def case_create_inspection_rule(self, name=None, time=None, period=None, _type=None, hosts=None, status=None):
        response = self.inspection_rule_create(token=self.token, name=name, time=time, period=period, _type=_type, hosts=hosts, status=status)
        self.check_code(response=response, code=0)
        data = UtilsResponse().get_data(response=response)
        rule_id = data[0]
        return rule_id
