def get(self):
        """**Get all Events**

        **Example Request:**

        .. sourcecode: http

            GET /api/v1/events HTTP/1.1
            Host: localhost

        **Example response:**

        .. sourcecode:: http

            HTTP/1.1 200 OK
            Content-Type: application/json

            {
                "status": "ok",
                "limit": 10,
                "offset": 0,
                "totalEvents": 10,
                "events": [
                    {
                        "id": 1,
                        "hostId": 1,
                        "timestamp": "2015-06-01 12:11:01",
                        "user": "jonny",
                        "eventTypeId": 1,
                        "note": "Event note",
                    },
                    ...
                ],
            }

        :query int eventTypeId: (*optional/multiple*) Filter Events by EventType id.
        :query int hostId: (*optional*) Filter Events by Host id.
        :query string hostname: (*optional*) Filter Events by Host's hostname
        :query int limit: (*optional*) Limit result to N resources.
        :query int offset: (*optional*) Skip the first N resources.
        :query string after: (*optional*) Only select events at and after a given timestamp
        :query string before: (*optional*) Only select events before a given timestamp
        :query int afterEventType: (*optional*) Only select events at and after the last event of a given event type
        :query string hostQuery: (*optional*) Only select events that match a given host query

        :statuscode 200: The request was successful.
        :statuscode 401: The request was made without being logged in.
        """

        event_type_id = self.get_arguments("eventTypeId")
        host_id = self.get_argument("hostId", None)
        hostname = self.get_argument("hostname", None)
        after_event_type = self.get_argument("afterEventType", None)
        host_query = self.get_argument("hostQuery", None)

        after_time = self.get_argument("after", None)
        if after_time:
            after_time = parser.parse(after_time, yearfirst=True)
            after_time = after_time.replace(tzinfo=None)
            
        before_time = self.get_argument("before", None)
        if before_time:
            before_time = parser.parse(before_time, yearfirst=True)
            before_time = before_time.replace(tzinfo=None)

        events = self.session.query(Event).order_by(desc(Event.timestamp))

        if event_type_id:
            events = events.filter(Event.event_type_id.in_(event_type_id))

        if host_id:
            events = events.filter_by(host_id=host_id)

        found_host = None
        if hostname:
            try:
                found_host = (
                    self.session.query(Host).filter(
                        Host.hostname == hostname
                    ).one()
                )
            except sqlalchemy.orm.exc.NoResultFound:
                raise exc.BadRequest("No host {} found".format(hostname))

            events = events.filter(Event.host == found_host)

        hostnames = []
        if host_query:
            response = PluginHelper.request_get(params={"query": host_query})
            if (
                response.status_code == 200
                and response.json()["status"] == "ok"
            ):
                for hostname in response.json()["results"]:
                    hostnames.append(hostname)
                    logging.info("found host {}".format(hostname))
            else:
                raise exc.BadRequest("Bad host query: {}".format(host_query))

        if hostnames:
            events = (
                events.join(Event.host).filter(Host.hostname.in_(hostnames))
            )

        if after_time:
            logging.info(after_time)
            events = events.filter(Event.timestamp >= after_time)
        if before_time:
            logging.info(before_time)
            events = events.filter(Event.timestamp < before_time)

        if after_event_type:
            # find most recent event of that type for the given host
            # want all events greater than or equal to the time for that event
            subquery = self.session.query(Event).order_by(desc(Event.timestamp)).filter(Event.event_type_id == after_event_type)

            if host_id:
                subquery = subquery.filter_by(host_id=host_id)

            if found_host:
                subquery = subquery.filter(Event.host == found_host)

            if hostnames:
                subquery = (
                    subquery.join(Event.host).filter(Host.hostname.in_(hostnames))
                )

            event = subquery.first()
            if not event:
                raise exc.BadRequest("No event of type {} found".format(after_event_type))
            else:
                events = events.from_self().filter(Event.id >= event.id)

        offset, limit, expand = self.get_pagination_values()
        events, total = self.paginate_query(events, offset, limit)

        events = events.from_self().order_by(Event.timestamp)

        json = {
            "limit": limit,
            "offset": offset,
            "totalEvents": total,
            "events": [
                event.to_dict(base_uri=self.href_prefix, expand=set(expand))
                for event in events.all()
            ],
        }

        self.success(json)
dataset/ETHPy150Open dropbox/hermes/hermes/handlers/api.py/EventsHandler.get/original