Esempio n. 1
0
  def GET(self, deviceId, notificationId):
    """
      Get single notification

      ::

          GET /_notifications/{deviceId}/{notificationId}

      Returns:

      ::

          {
            "uid": "e78599c4-758b-4c6e-87b1-daabaccff798",
            "timestamp": "2014-02-07 16:26:44",
            "metric": "e5511f295a474037a75bc966d02b67d2",
            "acknowledged": 0,
            "seen": 0,
            "windowsize": 3600,
            "device": "9a90eaf2-6374-4230-aa96-0830c0a737fe"
          }

      :param uid: Notification ID
      :type uid: str
      :param timestamp: Notification timestamp
      :type timestamp: timestamp
      :param metric: Metric that triggered notification
      :type metric: str
      :param acknowledged: Acknowledged status
      :type acknowledged: int
      :param seen: Seen status
      :type seen: int
      :param windowsize: Notification window in seconds during which no other
        notifications for a given instance should be sent to a given device
      :type windowsize: int
      :param device: Device ID
      :type device: str
    """
    # Update the last_timestamp for the notification device.
    try:
      with web.ctx.connFactory() as conn:
        repository.updateNotificationDeviceTimestamp(conn, deviceId)
    except ObjectNotFoundError:
      return web.notfound("Notification device not found: %s" % deviceId)

    try:
      with web.ctx.connFactory() as conn:
        notificationRow = repository.getNotification(conn,
                                                     notificationId,
                                                     NotificationHandler.fields)
      notificationDict = dict([(col, notificationRow[col])
                              for col in NotificationHandler.fields])

      if notificationRow["device"] != deviceId:
        return web.notfound("Device not found: %s" % deviceId)

      self.addStandardHeaders()
      return utils.jsonEncode(notificationDict)
    except ObjectNotFoundError:
      return web.notfound("Notification not found: %s" % notificationId)
Esempio n. 2
0
    def GET(self, deviceId, notificationId):
        """
      Get single notification

      ::

          GET /_notifications/{deviceId}/{notificationId}

      Returns:

      ::

          {
            "uid": "e78599c4-758b-4c6e-87b1-daabaccff798",
            "timestamp": "2014-02-07 16:26:44",
            "metric": "e5511f295a474037a75bc966d02b67d2",
            "acknowledged": 0,
            "seen": 0,
            "windowsize": 3600,
            "device": "9a90eaf2-6374-4230-aa96-0830c0a737fe"
          }

      :param uid: Notification ID
      :type uid: str
      :param timestamp: Notification timestamp
      :type timestamp: timestamp
      :param metric: Metric that triggered notification
      :type metric: str
      :param acknowledged: Acknowledged status
      :type acknowledged: int
      :param seen: Seen status
      :type seen: int
      :param windowsize: Notification window in seconds during which no other
        notifications for a given instance should be sent to a given device
      :type windowsize: int
      :param device: Device ID
      :type device: str
    """
        # Update the last_timestamp for the notification device.
        try:
            with web.ctx.connFactory() as conn:
                repository.updateNotificationDeviceTimestamp(conn, deviceId)
        except ObjectNotFoundError:
            return web.notfound("Notification device not found: %s" % deviceId)

        try:
            with web.ctx.connFactory() as conn:
                notificationRow = repository.getNotification(
                    conn, notificationId, NotificationHandler.fields)
            notificationDict = dict([(col, notificationRow[col])
                                     for col in NotificationHandler.fields])

            if notificationRow["device"] != deviceId:
                return web.notfound("Device not found: %s" % deviceId)

            self.addStandardHeaders()
            return utils.jsonEncode(notificationDict)
        except ObjectNotFoundError:
            return web.notfound("Notification not found: %s" % notificationId)
Esempio n. 3
0
    def GET(self, deviceId):
        """
      Get notification history for device

      ::

          GET /_notifications/{deviceId}/history

      :param limit: (optional) max number of records to return
      :type limit: int

      Returns:

      ::

          [
            {
              "uid": "e78599c4-758b-4c6e-87b1-daabaccff798",
              "timestamp": "2014-02-07 16:26:44",
              "metric": "e5511f295a474037a75bc966d02b67d2",
              "acknowledged": 0,
              "windowsize": 3600,
              "device": "9a90eaf2-6374-4230-aa96-0830c0a737fe"
            },
            ...
          ]


      :param uid: Notification ID
      :type uid: str
      :param timestamp: Notification timestamp
      :type timestamp: timestamp
      :param metric: Metric that triggered notification
      :type metric: str
      :param acknowledged: Acknowledged status
      :type acknowledged: int
      :param seen: Seen status
      :type seen: int
      :param windowsize: Notification window in seconds during which no other
        notifications for a given instance should be sent to a given device
      :type windowsize: int
      :param device: Device ID
      :type device: str
    """
        # Update the last_timestamp for the notification device.
        try:
            with web.ctx.connFactory() as conn:
                repository.updateNotificationDeviceTimestamp(conn, deviceId)
        except ObjectNotFoundError:
            return web.notfound("Notification device not found: %s" % deviceId)

        queryParams = dict(urlparse.parse_qsl(web.ctx.env['QUERY_STRING']))
        if "limit" in queryParams:
            limit = int(queryParams["limit"])
        else:
            limit = None
        self.addStandardHeaders()
        with web.ctx.connFactory() as conn:
            notificationRows = repository.getUnseenNotificationList(
                conn, deviceId, limit, NotificationHandler.fields)

        notificationList = [
            dict([(col, notification[col])
                  for col in NotificationHandler.fields])
            for notification in notificationRows
        ]

        return utils.jsonEncode(notificationList)
Esempio n. 4
0
  def GET(self, deviceId):
    """
      Get notification history for device

      ::

          GET /_notifications/{deviceId}/history

      :param limit: (optional) max number of records to return
      :type limit: int

      Returns:

      ::

          [
            {
              "uid": "e78599c4-758b-4c6e-87b1-daabaccff798",
              "timestamp": "2014-02-07 16:26:44",
              "metric": "e5511f295a474037a75bc966d02b67d2",
              "acknowledged": 0,
              "windowsize": 3600,
              "device": "9a90eaf2-6374-4230-aa96-0830c0a737fe"
            },
            ...
          ]


      :param uid: Notification ID
      :type uid: str
      :param timestamp: Notification timestamp
      :type timestamp: timestamp
      :param metric: Metric that triggered notification
      :type metric: str
      :param acknowledged: Acknowledged status
      :type acknowledged: int
      :param seen: Seen status
      :type seen: int
      :param windowsize: Notification window in seconds during which no other
        notifications for a given instance should be sent to a given device
      :type windowsize: int
      :param device: Device ID
      :type device: str
    """
    # Update the last_timestamp for the notification device.
    try:
      with web.ctx.connFactory() as conn:
        repository.updateNotificationDeviceTimestamp(conn, deviceId)
    except ObjectNotFoundError:
      return web.notfound("Notification device not found: %s" % deviceId)

    queryParams = dict(urlparse.parse_qsl(web.ctx.env['QUERY_STRING']))
    if "limit" in queryParams:
      limit = int(queryParams["limit"])
    else:
      limit = None
    self.addStandardHeaders()
    with web.ctx.connFactory() as conn:
      notificationRows = repository.getUnseenNotificationList(
        conn, deviceId, limit, NotificationHandler.fields)

    notificationList = [dict([(col, notification[col])
                             for col in NotificationHandler.fields])
                        for notification in notificationRows]

    return utils.jsonEncode(notificationList)