def log_class_filter(value: FilterHTTPVariables) -> FilterHeader: if not any(value.values()): return "Limit: 0\n" # no class allowed toggled = [ request_var[-1] for request_var, value in value.items() if value == "on" ] return lq_logic("Filter: class =", toggled, "Or")
def options_toggled_filter(column: str, value: FilterHTTPVariables) -> FilterHeader: "When VALUE keys are the options, return filterheaders that equal column to option." def drop_column_prefix(var: str): if var.startswith(column + "_"): return var[len(column) + 1:] return var selected = sorted( drop_column_prefix(name) for name, on in value.items() if on == "on") return lq_logic("Filter: %s =" % column, selected, "Or")
def log_alerts_filter(value: FilterHTTPVariables) -> FilterHeader: if not any(value.values()): return "Limit: 0\n" # no allowed state headers = [] for request_var, toggled in value.items(): if toggled: log_type = "HOST" if request_var[-2] == "h" else "SERVICE" state = request_var[-1] headers.append( lq_logic("Filter:", [f"log_type ~ {log_type} .*", f"log_state = {state}"], "And")) return "".join(headers) + ("Or: %d\n" % len(headers))
def host_state_filter(value: FilterHTTPVariables) -> FilterHeader: if not any(value.values()): # empty selection discard return "" headers = [] for request_var, toggled in value.items(): if toggled: continue if request_var == "hstp": headers.append("Filter: host_has_been_checked = 1\n") else: headers.append("Filter: host_state = %s\n" "Filter: host_has_been_checked = 1\n" "And: 2\nNegate:\n" % request_var[-1]) return "".join(headers)
def service_state_filter(prefix: str, value: FilterHTTPVariables) -> FilterHeader: if not any(value.values()): # empty selection discard return "" headers = [] for request_var, toggled in value.items(): if toggled: continue if request_var.endswith("p"): headers.append("Filter: service_has_been_checked = 1\n") else: if prefix == "hd": column = "service_last_hard_state" else: column = "service_state" headers.append("Filter: %s = %s\n" "Filter: service_has_been_checked = 1\n" "And: 2\nNegate:\n" % (column, request_var[-1])) return "".join(headers)