# -*- coding: utf-8 -*-
# 查询主机组
# 作者: 陈磊
# 时间: 2019-10-21
from WorkUtils.UtilsRequest import UtilsRequest
from WorkUtils.UtilsLog import UtilsLog
from WorkApi.ApiBase import ApiBase, GetBase


class HostGroupGet(GetBase):
    def __init__(self, _host):
        """
        :param _host: 域名
        :return:
        """
        super().__init__()
        self.log = UtilsLog()
        self.log.info("调用查询主机组")
        self.log.info(self.__class__)

        self._host = _host
        self._headers = {}
        self._path = "/hostgroup/get"
        self._url = self._host + self._path
        self._params = {}
        self._json = {}
        self._data = {}
        self.response = ""

        self.local_json = {}

        self.graphids = None
        self.groupids = None
        self.hostids = None
        self.maintenanceids = None
        self.monitored_hosts = None
        self.real_hosts = None
        self.templated_hosts = None
        self.templateids = None
        self.triggerids = None
        self.with_applications = None
        self.with_graphs = None
        self.with_hosts_and_templates = None
        self.with_httptests = None
        self.with_items = None
        self.with_monitored_httptests = None
        self.with_monitored_items = None
        self.with_monitored_triggers = None
        self.with_simple_graph_items = None
        self.with_triggers = None
        self.selectDiscoveryRule = None
        self.selectGroupDiscovery = None
        self.selectHosts = None
        self.selectTemplates = None
        self.limitSelects = None

        self.api = UtilsRequest()

    def get_response(self):
        self.get_base_json()

        base = ApiBase()
        base.dict_add_key(_key="graphids", value=self.graphids)
        base.dict_add_key(_key="groupids", value=self.groupids)
        base.dict_add_key(_key="hostids", value=self.hostids)
        base.dict_add_key(_key="maintenanceids", value=self.maintenanceids)
        base.dict_add_key(_key="monitored_hosts", value=self.monitored_hosts)
        base.dict_add_key(_key="real_hosts", value=self.real_hosts)
        base.dict_add_key(_key="templated_hosts", value=self.templated_hosts)
        base.dict_add_key(_key="templateids", value=self.templateids)
        base.dict_add_key(_key="triggerids", value=self.triggerids)
        base.dict_add_key(_key="with_applications", value=self.with_applications)
        base.dict_add_key(_key="with_graphs", value=self.with_graphs)
        base.dict_add_key(_key="with_hosts_and_templates", value=self.with_hosts_and_templates)
        base.dict_add_key(_key="with_httptests", value=self.with_httptests)
        base.dict_add_key(_key="with_items", value=self.with_items)
        base.dict_add_key(_key="with_monitored_httptests", value=self.with_monitored_httptests)
        base.dict_add_key(_key="with_monitored_items", value=self.with_monitored_items)
        base.dict_add_key(_key="with_monitored_triggers", value=self.with_monitored_triggers)
        base.dict_add_key(_key="with_simple_graph_items", value=self.with_simple_graph_items)
        base.dict_add_key(_key="with_triggers", value=self.with_triggers)
        base.dict_add_key(_key="selectDiscoveryRule", value=self.selectDiscoveryRule)
        base.dict_add_key(_key="selectGroupDiscovery", value=self.selectGroupDiscovery)
        base.dict_add_key(_key="selectHosts", value=self.selectHosts)
        base.dict_add_key(_key="selectTemplates", value=self.selectTemplates)
        base.dict_add_key(_key="limitSelects", value=self.limitSelects)

        self.local_json = base._json

        # self.log.debug(self.local_json)
        # self.log.debug(self.base_json)

        # 当前接口支持的参数与公共参数合并
        add = ApiBase()
        add.dict_add_dict(_dict_1=self.local_json, _dict_2=self.base_json)
        self._json = add._json
        self.response = self.api.post(url=self._url, json=self._json)
