Exemple #1
0
    def get(self, proj_id, event_category_id):
        try:
            project = yield _executor.submit(Project.objects.get, id=proj_id)
            event_category = yield _executor.submit(EventCategory.objects.get,
                                                    id=event_category_id)

            total_events = yield _executor.submit(
                Event.objects(category=event_category).count)
            last_submitted_event = yield _executor.submit(
                Event.objects(category=event_category).only(
                    'timestamp', 'source').order_by("-timestamp").first)
        except DoesNotExist:
            raise HTTPError(404)
        self.render("category_view.html",
                    version=__version__,
                    require_plots=False,
                    require_datatable=True,
                    project=project,
                    event_category=event_category,
                    event_count=total_events,
                    last_submit_time=(humanize.naturaltime(
                        last_submitted_event.timestamp) if last_submitted_event
                                      else "No events"),
                    last_submit_source=(last_submitted_event.source if
                                        last_submitted_event else "No events"))
Exemple #2
0
    def submit_event(self, source, category, values):
        event = Event()
        event.source = source
        event.category = category
        event.set_values(**values)

        event.save()
        return str(event.id)
Exemple #3
0
    def make_event(self, values):
        event_source = values.pop("__source__")
        event = Event()

        event.category = self.category
        event.source = event_source
        event.set_values(**values)
        return event
Exemple #4
0
    def query_events(self, query, save_history=True):
        _start = time.time()
        parse_result = QueryParser().parse_query(query)
        events = Event.filter_by_query(parse_result)
        to_return = [{
            "timestamp": event.timestamp.strftime("%Y-%m-%d %H:%M:%S"),
            "values": event.values,
            "source": event.source
        } for event in events]
        _duration = time.time() - _start

        if save_history:
            QueryHistory.create_new("unknown", query, events, _duration)

        return to_return
Exemple #5
0
    def make_event(self, values):
        # TODO: Make this accept values other than strings
        event_source = None
        element_values = {}
        for child in values:
            if child.tag == "source" and event_source is None:
                event_source = child.text
            elif child.tag == "field":
                element_values[child.attrib["name"]] = child.attrib["value"]
            else:
                if child.tag == "source":
                    raise ValueError("Duplicate tag 'source'")
                raise ValueError("Invalid tag: '{}'".format(child.tag))
        event = Event()

        event.category = self.category
        event.source = event_source
        event.set_values(**element_values)
        return event