API Module

import api from 'api';

Methods

logs(options) stats(options)

logs(options)

Queries the org's log. Very useful for creating daily activity reports, searching for access anomalies, etc.

Arguments

  • options (Object)

    • where

    • map

    • group

    • sort

    • limit

    • skip

stats(options)

Queries the org's stats.

Arguments

  • options (Object)

    • where

    • map

    • group

    • sort

    • limit

    • skip

Examples

The following example finds statistics on all the scripts that ran yesterday (does not factor in script errors or local time).Logs Example

import api from 'api'
import moment from 'moment'


let startId = new ObjectID(moment(new Date()).utc().subtract(1,'day').startOf('day').toDate())
let endId = new ObjectID(moment(new Date()).utc().subtract(1,'day').endOf('day').toDate())

return api.logs({
    where: {
        _id: {$gte: startId, $lte: endId},
        src: consts.logs.sources.script
    }
})

Logs Example Response

{
    "data": [
        {
            "_id": "59486583514ef1010000388f",
            "beg": "2017-06-20T00:00:03.161Z",
            "cms": 0,
            "ctt": 0,
            "end": "2017-06-20T00:00:03.308Z",
            "err": {
                "faults": []
            },
            "in": 0,
            "lvl": 2,
            "oid": "5888b91d35f8c91536c6ddea",
            "ops": 11852,
            "out": 0,
            "pid": "5888b91d35f8c91536c6ddea",
            "pis": [],
            "pts": [],
            "req": "59486583fc65ed0100bf97c9",
            "sid": "589a14f9494aeb77296e4309",
            "src": 2,
            "stp": "job",
            "sts": 200,
            "trc": []
        }
    ]
}

The following example returns the login statistics for the previous two days.Stats Example

import api from 'api'
import moment from 'moment'

let starting = moment(new Date()).utc().subtract(2,'day').startOf('day').toDate()

return api.stats({
    where: {
        starting: {$gte: starting},
        code: consts.stats.sources.logins
    }
})

Stats Example Response

{
    "data": [
        {
            "_id": "59237b84967e8b6cd67ed775",
            "active": 35,
            "code": 3,
            "ending": "2017-05-22T23:59:59.999Z",
            "object": "stat",
            "org": "58208081214454926424e515",
            "starting": "2017-05-22T00:00:00.000Z",
            "today": 1
        },
        {
            "_id": "5924cd03967e8b6cd6bb7a52",
            "active": 35,
            "code": 3,
            "ending": "2017-05-23T23:59:59.999Z",
            "object": "stat",
            "org": "58208081214454926424e515",
            "starting": "2017-05-23T00:00:00.000Z",
            "today": 1
        }
    ]
}

Last updated