Good Morning everyone,
Im triying to download csv,excel or whatever format from the logs of gateway Zero Trust, but i dont find any button or method.
This is possible?
Very thanks in advance.
Good Morning everyone,
Im triying to download csv,excel or whatever format from the logs of gateway Zero Trust, but i dont find any button or method.
This is possible?
Very thanks in advance.
The documentation says
Enterprise users can generate more detailed logs with Logpush
If you don’t have an Enterprise plan, you can try pasting this JavaScript code into the browser dev tools to downloads logs from https://api.teams.cloudflare.com/analytics/accounts/${accountId}/activities?${queryString}
. It is a while ago that I tested this, the script might no longer work.
const accountId = '???????????????';
const pageEntryLimit = 50
let day = new Date('2023-07-01').getTime() / 1000
const allLogs = []
for (let dayIndex = 0; dayIndex < 30; dayIndex++) {
const nextDay = day + 86400
for (let page = 1; page < 30; page++) {
const logsForPage = await fetchPage(day, nextDay - 1, page)
allLogs.push(...logsForPage)
if (logsForPage.length < pageEntryLimit) {
break;
}
}
day = nextDay
}
console.log(allLogs)
async function fetchPage(from, to, page) {
const queryString = new URLSearchParams({
page: '' + page,
from: '' + from,
to: '' + to,
decisionType: 'blocked',
limit: '' + pageEntryLimit,
includeInternalId: '' + true
})
const body = await fetchAndRetry();
if (!body.success) {
console.warn(body)
throw new Error('no success')
}
return body.result.logs;
async function fetchAndRetry() {
for (let index = 0; index < 4; index++) {
if (index > 0) {
console.warn(`retry ${index}`);
}
const resp = await fetch(`https://api.teams.cloudflare.com/analytics/accounts/${accountId}/activities?${queryString}`, {
"credentials": "include",
"headers": {
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.7,nl;q=0.3",
"X-CSRF-TOKEN": "--token",
},
"method": "GET",
"mode": "cors"
});
if (resp.status !== 200) {
continue;
}
return await resp.json();
}
throw new Error('gave up retrying');
}
}