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 item["lastclock"] == "0": continue self.expand_item_brief(item) 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_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_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
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 item["lastclock"] == "0": continue self.expand_item_brief(item) 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_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