diff --git a/main.js b/main.js index a9f4d11..055d399 100644 --- a/main.js +++ b/main.js @@ -126,14 +126,20 @@ async function main(){ if (AllOrganizations.message==='invalid username or password') { console.error(`\n${error}Invalid username or password\n`.red); - process.exit(0); + process.exit(1); } console.clear(); + console.log( + `----------`.white, + `Grafana-Find (${packageJson.description})`.yellow.bold, + `v${packageJson.version}`.cyan.bold, + `---------`.white + ); console.log(colors.green.bold(`-------------------- Starting process --------------------\n`)); for (let x in AllOrganizations) { - + console.log(colors.gray.bold(`(Organization: ${AllOrganizations[x].name})\n`)); response = await fetch(`${urlDashboards}${AllOrganizations[x].id}`, { method: "GET", @@ -146,26 +152,39 @@ async function main(){ if (response.status === 302) { response = await fetch(`${urlDashboards}${AllOrganizations[x].id}`, { method: 'GET', + headers: { + Accept: 'application/json' + }, redirect: 'manual' }); } let allUID = await response.json(); - + for (let i in allUID) { - - let url = urlUID + allUID[i].uid; + let url = `${urlUID}${allUID[i].uid}`; response = await fetch(url, { method: "GET", headers: { Authorization: credentials, - } + }, + redirect: 'manual' }); - + + if (response.status === 404) { + response = await fetch(url, { + method: 'GET', + headers: { + Accept: 'application/json' + }, + redirect: 'manual' + }); + } + let data = await response.json(); - + let isFound = false; - + const dashboard = data.dashboard; if (dashboard) { if (dashboard.panels) @@ -182,7 +201,7 @@ async function main(){ } } } - + if (dashboard.templating) for (const list of dashboard.templating.list) { isFound = regexRawSQL.test(list.query); @@ -192,7 +211,7 @@ async function main(){ } } } - + if (isFound) { const linkUrl = `${grafanaUrl}/d/${allUID[i].uid}`; console.log(colors.yellow(linkUrl)); @@ -207,7 +226,7 @@ async function main(){ console.log('') numberOfDashboards++; } - + titlePanels = []; nameVariables= []; numberOfObjects = numberOfPanels + numberOfVariables + numberOfObjects @@ -222,6 +241,6 @@ async function main(){ console.log(colors.green.bold(`-------- Have been found ${numberOfObjects} results in ${numberOfDashboards} dashboards -------\n`)); - process.exit(0); + process.exit(); } main(); \ No newline at end of file