-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (24 loc) · 896 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require('dotenv').config()
const axios = require('axios')
const url = `https://papertrailapp.com/api/v1/events/search.json?system_id=portalen&q=verify-signin-jwt AND "JWT ok"&limit=2500`
axios.defaults.headers.common['X-Papertrail-Token'] = process.env.API_TOKEN
function filterData (events) {
const users = events
.map(line => line.message)
.map(line => line.split('-'))
.map(line => line[line.length - 1].trim())
return users
}
async function getData () {
try {
const { data } = await axios(url)
console.log(`Analyzing ${data.events.length} events`)
console.log(`From ${data.events[0].display_received_at}`)
console.log(`To ${data.events[data.events.length - 1].display_received_at}`)
const uniques = new Set(filterData(data.events))
console.log(`Unique users: ${uniques.size}`)
} catch (error) {
console.error(error.message)
}
}
getData()