# -*- coding: utf-8 -*-
# 查询最新告警
# 作者: 陈磊
# 时间: 2019-11-21
from WorkUtils.UtilsRequest import UtilsRequest
from WorkUtils.UtilsLog import UtilsLog
from WorkApi.ApiBase import ApiBase, GetBase


class ProblemGetLatest(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 = "/problem/getLatest"
        self._url = self._host + self._path
        self._params = {}
        self._json = {}
        self._data = {}
        self.response = ""

        self.local_json = {}

        self.eventids = None
        self.groupids = None
        self.hostids = None
        self.objectids = None
        self.applicationids = None
        self.source = None
        self.object = None
        self.acknowledged = None
        self.suppressed = None
        self.severities = None
        self.evaltype = None
        self.tags = None
        self.recent = None
        self.eventid_from = None
        self.eventid_till = None
        self.time_from = None
        self.time_till = None
        self.selectAcknowledges = None
        self.selectTags = None
        self.selectSuppressionData = None

        self.api = UtilsRequest()

    def get_response(self):
        self.get_base_json()

        base = ApiBase()
        base.dict_add_key(_key="eventids", value=self.eventids)
        base.dict_add_key(_key="groupids", value=self.groupids)
        base.dict_add_key(_key="hostids", value=self.hostids)
        base.dict_add_key(_key="objectids", value=self.objectids)
        base.dict_add_key(_key="applicationids", value=self.applicationids)
        base.dict_add_key(_key="source", value=self.source)
        base.dict_add_key(_key="object", value=self.object)
        base.dict_add_key(_key="acknowledged", value=self.acknowledged)
        base.dict_add_key(_key="suppressed", value=self.suppressed)
        base.dict_add_key(_key="severities", value=self.severities)
        base.dict_add_key(_key="evaltype", value=self.evaltype)
        base.dict_add_key(_key="tags", value=self.tags)
        base.dict_add_key(_key="recent", value=self.recent)
        base.dict_add_key(_key="eventid_from", value=self.eventid_from)
        base.dict_add_key(_key="eventid_till", value=self.eventid_till)
        base.dict_add_key(_key="time_from", value=self.time_from)
        base.dict_add_key(_key="time_till", value=self.time_till)
        base.dict_add_key(_key="selectAcknowledges", value=self.selectAcknowledges)
        base.dict_add_key(_key="selectTags", value=self.selectTags)
        base.dict_add_key(_key="selectSuppressionData", value=self.selectSuppressionData)

        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)
