def rules(self, request): rules = models.Rule.objects.filter(enabled=True) return Response( serializers.AlertRuleSerializer(rules, many=True).data, headers={ "Content-Disposition": "attachment; filename=alert.rule.yml" }, )
def rules(self, request, name): rules = models.Rule.objects.filter(obj=self.get_object()) return Response( serializers.AlertRuleSerializer(rules, many=True).data, headers={ "Content-Disposition": "attachment; filename=%s.rule.yml" % name }, )
def render_rules(rules=None): ''' Render rules in a format that Prometheus understands :param rules: List of rules :type rules: list(Rule) :param int version: Prometheus rule format (1 or 2) :return: Returns rules in yaml or Prometheus v1 format :rtype: bytes This function can render in either v1 or v2 format We call prefetch_related_objects within this function to populate the other related objects that are mostly used for the sub lookups. ''' if rules is None: rules = models.Rule.objects.filter(enabled=True) return renderers.RuleRenderer().render( serializers.AlertRuleSerializer(rules, many=True).data)
def rules(self, request, name): rules = models.Rule.objects.filter(obj=self.get_object()) return Response(serializers.AlertRuleSerializer(rules, many=True).data)