def get_events(self, event_id_from, event_id_till=None): params = {"output": "extend", "eventid_from": event_id_from, "selectHosts": ["name"]} if event_id_till is not None: params["eventid_till"] = event_id_till res_dict = self.get_response_dict("event.get", params, self.auth_token) self.result = check_response(res_dict) if not self.result: return events = list() for event in res_dict["result"]: try: if int(event["ns"]) == 0: ns = 0 else: ns = Utils.translate_int_to_decimal(int(event["ns"])) trigger = self.get_select_trigger(event["objectid"]) events.append({"eventId": event["eventid"], "time": Utils.translate_unix_time_to_hatohol_time(int(event["clock"]) + ns), "type": EVENT_TYPE[event["value"]], "triggerId": trigger["triggerid"], "status": TRIGGER_STATUS[trigger["state"]], "severity": TRIGGER_SEVERITY[trigger["priority"]], "hostId": event["hosts"][0]["hostid"], "hostName": event["hosts"][0]["name"], "brief": trigger["description"], "extendedInfo": ""}) except KeyError: logging.warning("Get a imperfect event: %s" % event) return events
def get_items(self, host_ids=None): params = {"output": "extend", "selectApplications": ["name"], "monitored": True} if host_ids is not None: params["hostids"] = host_ids res_dict = self.get_response_dict("item.get", params, self.auth_token) self.result = check_response(res_dict) if not self.result: return items = list() for item in res_dict["result"]: if int(item["lastns"]) == 0: ns = 0 else: ns = Utils.translate_int_to_decimal(int(item["lastns"])) items.append({"itemId": item["itemid"], "hostId": item["hostid"], "brief": item["name"], "lastValueTime": Utils.translate_unix_time_to_hatohol_time(int(item["lastclock"]) + ns), "lastValue": item["lastvalue"], "itemGroupName": get_item_groups(item["applications"]), "unit": item["units"]}) return items
def get_triggers(self, requestSince=None, host_ids=None): params = {"output": "extend", "selectHosts": ["name"], "active": True} last_change_since = int() if requestSince: last_change_since = \ Utils.translate_hatohol_time_to_unix_time(requestSince) params["lastChangeSince"] = last_change_since if host_ids is not None: params["hostids"] = host_ids res_dict = self.get_response_dict("trigger.get", params, self.auth_token) expanded_descriptions = \ self.get_trigger_expand_description(last_change_since, host_ids) self.result = check_response(res_dict) if not self.result: return triggers = list() for num, trigger in enumerate(res_dict["result"]): try: description = [ed["description"] for ed in expanded_descriptions["result"] if ed["triggerid"] == trigger["triggerid"]][0] triggers.append({"triggerId": trigger["triggerid"], "status": TRIGGER_STATUS[trigger["state"]], "severity": TRIGGER_SEVERITY[trigger["priority"]], "lastChangeTime": Utils.translate_unix_time_to_hatohol_time(int(trigger["lastchange"])), "hostId": trigger["hosts"][0]["hostid"], "hostName": trigger["hosts"][0]["name"], "brief": trigger["description"], "extendedInfo": description}) except KeyError: logging.warning("Get a imperfect trigger: %s" % trigger) return triggers
def get_history(self, item_id, begin_time, end_time): begin_time = Utils.translate_hatohol_time_to_unix_time(begin_time) end_time = Utils.translate_hatohol_time_to_unix_time(end_time) params = {"output": "extend", "itemids": item_id, "history": self.get_item_value_type(item_id), "sortfield": "clock", "sortorder": "ASC", "time_from": begin_time, "time_till": end_time} res_dict = self.get_response_dict("history.get", params, self.auth_token) self.result = check_response(res_dict) if not self.result: return histories = list() for history in res_dict["result"]: if int(history["ns"]) == 0: ns = 0 else: ns = Utils.translate_int_to_decimal(int(history["ns"])) histories.append({"value": history["value"], "time": Utils.translate_unix_time_to_hatohol_time(int(history["clock"]) + ns)}) return histories