Exemplo n.º 1
0
    def parse_value(self, value: FilterHTTPVariables) -> Labels:
        # Do not restrict to a certain number, because we'd like to link to this
        # via an URL, e.g. from the virtual host tree snapin
        num = 0
        while (this_tag :=
               value.get("%s_%d" % (self.var_prefix, num))) is not None:
            if this_tag:
                negate = bool(value.get("%s_%d_neg" % (self.var_prefix, num)))
                yield Label(this_tag, this_tag, negate)

            num += 1
Exemplo n.º 2
0
 def filter(self, value: FilterHTTPVariables) -> FilterHeader:
     if filter_value := value.get(self.request_vars[0]):
         return encode_labels_for_livestatus(
             column=self.column,
             labels=[
                 Label(
                     f"cmk/kubernetes/{self._kubernetes_object_type}",
                     filter_value,
                     False,
                 )
             ],
         )
Exemplo n.º 3
0
    def parse_value(self, value: FilterHTTPVariables) -> Labels:
        # Do not restrict to a certain number, because we'd like to link to this
        # via an URL, e.g. from the virtual host tree snapin
        num = 0
        while value.get("%s_%d_grp" % (self.var_prefix, num)):
            prefix = "%s_%d" % (self.var_prefix, num)
            num += 1

            op = value.get(prefix + "_op")
            tag_group = active_config.tags.get_tag_group(
                value.get(prefix + "_grp", ""))

            if tag_group and op:
                tag = value.get(prefix + "_val", "")
                yield Label(tag_group.id, tag, negate=op != "is")
Exemplo n.º 4
0
    def _query_callback(
            sites_live: MultiSiteConnection) -> Collection[LivestatusColumn]:
        """
        we search for hosts having a certain label
        ('cmk/kubernets/object:{object_type}') and want a list of unique labels
        values of labels with the key label_name.
        """
        label_filter = encode_label_for_livestatus(
            column="labels",
            label=Label("cmk/kubernetes/object", object_type, False),
        )
        query = f"GET hosts\nColumns: labels\n{label_filter}"

        query_result = sites_live.query_column(query)
        label_values = set()
        for element in query_result:
            for label_key, label_value in element.items():
                if label_key == label_name:
                    label_values.add(label_value)
        return label_values