<commit_before>#
# ==============================
# Copyright 2011 Whamcloud, Inc.
# ==============================

from chroma_core.models.event import Event
import logging

from tastypie.resources import ModelResource
from tastypie import fields
from tastypie.authorization import DjangoAuthorization
from chroma_api.authentication import AnonymousAuthentication
import tastypie.constants

STR_TO_SEVERITY = dict([(logging.getLevelName(level), level) for level in [
    logging.INFO,
    logging.ERROR,
    logging.CRITICAL,
    logging.WARNING,
    logging.DEBUG
    ]])


class EventResource(ModelResource):
    """
    Events are messages generated by Chroma to represent what
    changes on hosts or filesystems it monitors.  Events are essentially
    log messages, separate from the ``log`` resource because they are
    internally synthesized rather than gathered from syslog.
    """
    host_name = fields.CharField(attribute = 'host', blank = True, null = True,
            help_text = "The ``label`` attribute of the host on which the event\
                    occurred, or null if the event is not specific to a single\
                    host")
    host = fields.ToOneField('chroma_api.host.HostResource', 'host', null = True,
            help_text = "The host on which the event occurred, or null if the event\
                    is not specific to a single host")
    message = fields.CharField()

    severity = fields.CharField(help_text = "String indicating the severity of the\
            event, one of %s" % STR_TO_SEVERITY.keys())

    class Meta:
        queryset = Event.objects.all()
        authorization = DjangoAuthorization()
        authentication = AnonymousAuthentication()
        ordering = ['created_at', 'host', 'host_name']
        filtering = {
                'severity': ['exact'],
                'host': tastypie.constants.ALL_WITH_RELATIONS,
                }
        list_allowed_methods = ['get']
        detail_allowed_methods = ['get']

    def dehydrate_host_name(self, bundle):
        return bundle.obj.host.pretty_name() if bundle.obj.host else "---"

    def dehydrate_message(self, bundle):
        return bundle.obj.message()

    def dehydrate_severity(self, bundle):<commit_msg>Fix filtering alerts on severity<commit_after>#
# ==============================
# Copyright 2011 Whamcloud, Inc.
# ==============================

from chroma_core.models.event import Event
import logging

from tastypie.resources import ModelResource
from tastypie import fields
from tastypie.authorization import DjangoAuthorization
from chroma_api.authentication import AnonymousAuthentication
import tastypie.constants

STR_TO_SEVERITY = dict([(logging.getLevelName(level), level) for level in [
    logging.INFO,
    logging.ERROR,
    logging.CRITICAL,
    logging.WARNING,
    logging.DEBUG
    ]])


class EventResource(ModelResource):
    """
    Events are messages generated by Chroma to represent what
    changes on hosts or filesystems it monitors.  Events are essentially
    log messages, separate from the ``log`` resource because they are
    internally synthesized rather than gathered from syslog.
    """
    host_name = fields.CharField(attribute = 'host', blank = True, null = True,
            help_text = "The ``label`` attribute of the host on which the event\
                    occurred, or null if the event is not specific to a single\
                    host")
    host = fields.ToOneField('chroma_api.host.HostResource', 'host', null = True,
            help_text = "The host on which the event occurred, or null if the event\
                    is not specific to a single host")
    message = fields.CharField()

    severity = fields.CharField(attribute='severity',
            help_text = "String indicating the severity of the\
            event, one of %s" % STR_TO_SEVERITY.keys())

    class Meta:
        queryset = Event.objects.all()
        authorization = DjangoAuthorization()
        authentication = AnonymousAuthentication()
        ordering = ['created_at', 'host', 'host_name']
        filtering = {
                'severity': ['exact'],
                'host': tastypie.constants.ALL_WITH_RELATIONS,
                }
        list_allowed_methods = ['get']
        detail_allowed_methods = ['get']

    def dehydrate_host_name(self, bundle):
        return bundle.obj.host.pretty_name() if bundle.obj.host else "---"

    def dehydrate_message(self, bundle):
        return bundle.obj.message()

    def dehydrate_severity(self, bundle):
{'fraction_non_alphanumeric': 0.11118464592984778, 'fraction_numerical': 0.0017648356496801235, 'mean_word_length': 2.956369982547993, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '69142', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1173, 'n_words': 376}