Exemplo n.º 1
0
    def filter_table(self, context: VisualContext, rows: Rows) -> Rows:
        values = context.get(self.ident, {})
        assert not isinstance(values, str)
        filtertext = self.filtertext(values)
        if not filtertext:
            return rows

        try:
            regex = re.compile(filtertext, re.IGNORECASE)
        except re.error:
            raise MKUserError(
                self.htmlvars[0],
                _("Your search statement is not valid. You need to provide a regular "
                  "expression (regex). For example you need to use <tt>\\\\</tt> instead of <tt>\\</tt> "
                  "if you like to search for a single backslash."),
            )

        newrows = []
        for row in rows:
            invdata = inventory.get_inventory_attribute(
                row["host_inventory"], self._invpath)
            if not isinstance(invdata, str):
                invdata = ""
            if regex.search(invdata):
                newrows.append(row)
        return newrows
Exemplo n.º 2
0
    def filter_table(self, context: VisualContext, rows: Rows) -> Rows:
        value = context.get(self.ident, {})
        assert not isinstance(value, str)
        tri = self.tristate_value(value)
        if tri == -1:
            return rows

        wanted_value = tri == 1
        newrows = []
        for row in rows:
            invdata = inventory.get_inventory_attribute(row["host_inventory"], self._invpath)
            if wanted_value == invdata:
                newrows.append(row)
        return newrows
Exemplo n.º 3
0
    def filter_table(self, context: VisualContext, rows: Rows) -> Rows:
        values = context.get(self.ident, {})
        assert not isinstance(values, str)
        lower, upper = self.filter_configs(values)
        if not any((lower, upper)):
            return rows

        newrows = []
        for row in rows:
            invdata = inventory.get_inventory_attribute(row["host_inventory"], self._invpath)
            if not isinstance(invdata, (int, float)):
                continue
            if lower is not None and invdata < lower:
                continue
            if upper is not None and invdata > upper:
                continue
            newrows.append(row)
        return newrows
Exemplo n.º 4
0
 def row_filter(row: Row, column: str, bounds: MaybeBounds) -> bool:
     invdata = inventory.get_inventory_attribute(row["host_inventory"],
                                                 invpath)
     if not isinstance(invdata, (int, float)):
         return False
     return value_in_range(invdata, bounds)
Exemplo n.º 5
0
 def filt(row: Row):
     invdata = inventory.get_inventory_attribute(
         row["host_inventory"], invpath)
     if not isinstance(invdata, str):
         invdata = ""
     return bool(regex.search(invdata))
Exemplo n.º 6
0
 def keep_row(on: bool, row: Row) -> bool:
     return inventory.get_inventory_attribute(row["host_inventory"],
                                              invpath) is on
Exemplo n.º 7
0
 def filter_rows(on: bool, context: VisualContext, rows: Rows) -> Rows:
     return [
         row
         for row in rows
         if inventory.get_inventory_attribute(row["host_inventory"], invpath) is on
     ]