示例#1
0
    def getLastDataMessageDate(self):
        if LAST_DATA_MESSAGE_DATE not in self.sensor:
            lastMessageTimeStamp = 0
        else:
            lastMessageTimeStamp = self.sensor[LAST_DATA_MESSAGE_DATE]

        messages = DbCollections.getDataMessages(self.sensor[SENSOR_ID])
        lastMessage = messages.find_one({"t": lastMessageTimeStamp})
        if lastMessage:
            del lastMessage["_id"]
            t = lastMessage["_localDbInsertionTime"]
            return timezone.getDateTimeFromLocalTimeStamp(t), lastMessage
        else:
            return "NONE", {}
def getSessions():
    retval = {}
    sessions = getSessionLock().getSessions()
    userSessions = []
    adminSessions = []

    for sessionKey in sessions.keys():
        session = sessions[sessionKey]
        if sessionKey.startswith(USER):
            userSession = {}
            if session[USER_NAME] is not None:
                userSession[USER_NAME] = session[USER_NAME]
            else:
                userSession[USER_NAME] = UNKNOWN
            userSession[
                SESSION_LOGIN_TIME] = timezone.getDateTimeFromLocalTimeStamp(
                    session[SESSION_LOGIN_TIME])
            userSession[EXPIRE_TIME] = timezone.getDateTimeFromLocalTimeStamp(
                session[EXPIRE_TIME])
            userSession[REMOTE_ADDRESS] = session[REMOTE_ADDRESS]
            userSessions.append(userSession)
        elif sessionKey.startswith(ADMIN):
            adminSession = {}
            adminSession[USER_NAME] = session[USER_NAME]
            adminSession[
                SESSION_LOGIN_TIME] = timezone.getDateTimeFromLocalTimeStamp(
                    session[SESSION_LOGIN_TIME])
            adminSession[EXPIRE_TIME] = timezone.getDateTimeFromLocalTimeStamp(
                session[EXPIRE_TIME])
            adminSession[REMOTE_ADDRESS] = session[REMOTE_ADDRESS]
            adminSessions.append(adminSession)
    retval[FROZEN] = getSessionLock().isFrozen(None)
    retval[FREEZE_REQUESTER] = getSessionLock().getFreezeRequester()
    retval[USER_SESSIONS] = userSessions
    retval[ADMIN_SESSIONS] = adminSessions
    retval[STATUS] = "OK"
    return retval
示例#3
0
    def getFirstSystemMessageDate(self):
        if FIRST_SYSTEM_MESSAGE_DATE not in self.sensor:
            messageTimeStamp = 0
        else:
            messageTimeStamp = self.sensor[FIRST_SYSTEM_MESSAGE_DATE]

        messages = DbCollections.getSystemMessages()
        query = {"t": messageTimeStamp, SENSOR_ID: self.sensor[SENSOR_ID]}
        message = messages.find_one(query)
        if message:
            del message["_id"]
            t = message["_localDbInsertionTime"]
            return timezone.getDateTimeFromLocalTimeStamp(t), message
        else:
            return "NONE", {}
示例#4
0
def getCaptureEventTimes(sensorId):
    """
    get an ordered list of all capture events from the sensor, most recent event first.

    at present the capture event feature is not implemented.  An ordered list of data
    message timestamps for this sensor is returned instead
    """
    cur = DbCollections.getDataMessages(sensorId).find({SENSOR_ID: sensorId})
    if cur is None or cur.count() == 0:
        return -1
    else:
        captureEventTimes = []
        for dataMsg in cur.sort('t', pymongo.DESCENDING):
            eventTime = timezone.getDateTimeFromLocalTimeStamp(dataMsg["t"])
            captureEventTimes.append(eventTime)
        return captureEventTimes
示例#5
0
    def getLastLocationMessageDate(self):
        if LAST_LOCATION_MESSAGE_DATE not in self.sensor:
            lastMessageTimeStamp = 0
        else:
            lastMessageTimeStamp = self.sensor[LAST_LOCATION_MESSAGE_DATE]

        messages = DbCollections.getLocationMessages()
        query = {"t": lastMessageTimeStamp, SENSOR_ID: self.sensor[SENSOR_ID]}
        lastMessage = messages.find_one(query)

        if lastMessage:
            del lastMessage["_id"]
            t = lastMessage["_localDbInsertionTime"]
            return timezone.getDateTimeFromLocalTimeStamp(t), lastMessage
        else:
            return "NONE", {}
示例#6
0
 def getLastMessageDate(self):
     if LAST_MESSAGE_DATE not in self.sensor:
         lastMessageTimeStamp = 0
     else:
         lastMessageTimeStamp = self.sensor[LAST_MESSAGE_DATE]
     return timezone.getDateTimeFromLocalTimeStamp(lastMessageTimeStamp)