Public
Authored by rakhmatulina

Sentry syscheck reports

Edited
syscheck_reports.js 1.2 KB
  • let fetch = require('node-fetch')
    let {writeFileSync} = require('fs')
    
    
    let debug = label => x => {
    	console.log(label, x)
    	return x
    }
    
    /**
     *  Data shape.
     */
    
    let getData = status => ({dateReceived, user: {ip_address, id}}) =>
    	([dateReceived, ip_address, id, status])
    
    let release = ({tags}) => 
    	tags
    	.find(x => x.key === 'release')
    	.value
    
    let fields = status => xs => [...getData(status)(xs),	release(xs)]
    
    let headers = ['dateReceived','ip_address', 'id', 'status','release']
    
    /* */
    
    let f = async ({issueId, status}, acc, url) => {
    	url =
    		url ||
    		`https://sentry.examus.net/api/0/issues/${issueId}/events/`
    
    	console.log('XXX', url)
    
    	let r =
    		fetch(url,
    		{headers: {Authorization: 'Bearer 95521f70a4f6438b81d1f425f78194ac00cf6c6898764373a9deaad85d33a8f6'}})
    
    	acc = await
    	r
    	.then(r => r.json())
    	.then(xs => xs.map(fields(status)))
    	.then(x => acc.concat(x))
    
    	let [_, nextUrl, gotNext] =
    		(await r)
    		.headers.get('Link')
    		.match(/.*, <(.+)>;.+; results="(true|false)";/)
    
    	return gotNext === 'true'
    		? f({issueId, status}, acc, nextUrl)
    		: acc
    }
    
    
    let success = f({issueId: 902, status: 'success'}, [])
    
    let fail = f({issueId: 2465, status: 'fail'}, [])
    
    
    let writeFile = file => data => writeFileSync(file, data)
    
    void
    	// lines
    	Promise.all([success, fail])
    	.then(([x, y]) => x.concat(y))
    
    	// prepend headers
    	.then(xs => [headers].concat(xs) )
    
    	// join fields with '\t'
    	.then(xs => xs.map( xs => xs.join('	') ))
    
    	// write file
    	.then(x => x.join('\n'))
    	.then(writeFile('./out'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment