def _setTimeline(self, start, end): for t in "time_desc", "time_asc", "count_desc", "count_asc": self.dataset["timeline.%s_selected" % t] = "" self.dataset["timeline.%s_selected" % self.parameters["orderby"]] = "selected='selected'" for unit in "min", "hour", "day", "month", "year", "unlimited": self.dataset["timeline.%s_selected" % unit] = "" self.dataset["timeline.value"] = self.parameters["timeline_value"] self.dataset["timeline.%s_selected" % self.parameters["timeline_unit"]] = "selected='selected'" if self.parameters["timezone"] == "utc": func = time.gmtime self.dataset["timeline.range_timezone"] = "UTC" else: func = time.localtime self.dataset["timeline.range_timezone"] = "%+.2d:%.2d" % utils.get_gmt_offset() if not start and not end: return self.dataset["timeline.start"] = utils.time_to_ymdhms(func(int(start))) self.dataset["timeline.end"] = utils.time_to_ymdhms(func(int(end))) self.dataset["timeline.current"] = utils.create_link(self.view_name, self.parameters - ["timeline_end"]) if not self.parameters.has_key("timeline_end") and self.parameters["timeline_unit"] in ("min", "hour"): tmp = copy.copy(end) tmp.round(self.parameters["timeline_unit"]) tmp = tmp[self.parameters["timeline_unit"]] - 1 self._setTimelineNext(tmp[self.parameters["timeline_unit"]] + self.parameters["timeline_value"]) self._setTimelinePrev(tmp[self.parameters["timeline_unit"]] - (self.parameters["timeline_value"] - 1)) else: self._setTimelineNext(end[self.parameters["timeline_unit"]] + self.parameters["timeline_value"]) self._setTimelinePrev(end[self.parameters["timeline_unit"]] - self.parameters["timeline_value"])
def render(self): analyzers = { } criteria = None if self.parameters.has_key("filter_path"): criteria = "%s == '%s'" % (self.parameters["filter_path"], utils.escape_criteria(self.parameters["filter_value"])) locations = { } nodes = { } for analyzerid in self.env.idmef_db.getAnalyzerids(): analyzer = self.env.idmef_db.getAnalyzer(analyzerid) parameters = { "analyzerid": analyzer["analyzerid"] } analyzer["alert_listing"] = utils.create_link("sensor_alert_listing", parameters) analyzer["heartbeat_listing"] = utils.create_link("sensor_heartbeat_listing", parameters) analyzer["heartbeat_analyze"] = utils.create_link("heartbeat_analyze", parameters) if analyzer["node_name"]: analyzer["node_name_link"] = utils.create_link(self.view_name, { "filter_path": "heartbeat.analyzer(-1).node.name", "filter_value": analyzer["node_name"] }) if analyzer["node_location"]: analyzer["node_location_link"] = utils.create_link(self.view_name, { "filter_path": "heartbeat.analyzer(-1).node.location", "filter_value": analyzer["node_location"] }) node_key = "" for i in range(len(analyzer["node_addresses"])): addr = analyzer["node_addresses"][i] node_key += addr analyzer["node_addresses"][i] = {} analyzer["node_addresses"][i]["value"] = addr analyzer["node_addresses"][i]["inline_filter"] = utils.create_link(self.view_name, { "filter_path": "heartbeat.analyzer(-1).node.address.address", "filter_value": addr }) analyzer["node_addresses"][i]["host_commands"] = [] for command in self.env.host_commands.keys(): analyzer["node_addresses"][i]["host_commands"].append((command.capitalize(), utils.create_link("Command", { "origin": self.view_name, "command": command, "host": addr }))) analyzer["status"], analyzer["status_meaning"] = \ get_analyzer_status_from_latest_heartbeat(analyzer["last_heartbeat_status"], analyzer["last_heartbeat_time"], analyzer["last_heartbeat_interval"], self._heartbeat_error_margin) analyzer["last_heartbeat_time"] = utils.time_to_ymdhms(time.localtime(int(analyzer["last_heartbeat_time"]))) + \ " %+.2d:%.2d" % utils.get_gmt_offset() node_location = analyzer["node_location"] or _("Node location n/a") node_name = analyzer.get("node_name") or _("Node name n/a") osversion = analyzer["osversion"] or _("OS version n/a") ostype = analyzer["ostype"] or _("OS type n/a") addresses = analyzer["node_addresses"] node_key = node_name + osversion + ostype if not locations.has_key(node_location): locations[node_location] = { "total": 1, "missing": 0, "unknown": 0, "offline": 0, "online": 0, "nodes": { } } else: locations[node_location]["total"] += 1 if not locations[node_location]["nodes"].has_key(node_key): locations[node_location]["nodes"][node_key] = { "total": 1, "missing": 0, "unknown": 0, "offline": 0, "online": 0, "analyzers": [ ], "node_name": node_name, "node_location": node_location, "ostype": ostype, "osversion": osversion, "node_addresses": addresses, "node_key": node_key } else: locations[node_location]["nodes"][node_key]["total"] += 1 status = analyzer["status"] locations[node_location][status] += 1 locations[node_location]["nodes"][node_key][status] += 1 if status == "missing" or status == "unknown": locations[node_location]["nodes"][node_key]["analyzers"].insert(0, analyzer) else: locations[node_location]["nodes"][node_key]["analyzers"].append(analyzer) self.dataset["locations"] = locations