last commits

This commit is contained in:
Guillermo Bonet 2022-06-17 14:45:02 +02:00
parent ef094b4dff
commit 8a9dc64917
5 changed files with 73 additions and 27 deletions

7
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
// Use IntelliSense para saber los atributos posibles.
// Mantenga el puntero para ver las descripciones de los existentes atributos.
// Para más información, visite: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}

17
LICENSE Normal file
View File

@ -0,0 +1,17 @@
Copyright (C) 2020 - Verdnatura Levante S.L.
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
On Debian systems, the complete text of the GNU General Public
License can be found in "/usr/share/common-licenses/GPL-3".

View File

@ -22,6 +22,14 @@ $ npm install grafana-find
$ npx grafana-find <command>
```
Create a file ".grafana-find.json" with this content:
```text
{
"grafanaUrl": "<server>"
}
```
## How to use
Execute *grafana-find* with the desired command.

62
main.js
View File

@ -14,21 +14,8 @@ if (!fs.existsSync(configFile)) {
process.exit(1);
}
/* Pedir contraseña
-----------------
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const answer = await new Promise(resolve => {
rl.question('Are you sure? (Default: no) [yes|no] ', resolve);
});
rl.close();
*/
const findAll = `WHERE d.name LIKE '%EQUIPO %'`;
const apiKey = `Bearer eyJrIjoiaHczdnZsOGd5M0xNUHJwZ3V4MGpvQzV0QVNGblpySloiLCJuIjoiZmluZEFsbF9HcmFmYW5hIiwiaWQiOjF9`;
const findAll = `Client`;
const apiKey = `Bearer eyJrIjoickI3WVBab0lscldRdk9JV29YYUFKMEdqUDl6UmsyaHIiLCJuIjoiZ3JhZmFuYS1maW5kIiwiaWQiOjF9`;
const config = require(configFile);
const grafanaUrl = config.grafanaUrl;
@ -37,14 +24,30 @@ const grafanaApi = `${grafanaUrl}/api`;
const urlDashboards = `${grafanaApi}/search`;
const urlUID = `${grafanaApi}/dashboards/uid/`;
let numberOfDashboards = 0;
let numberOfObjects = 0;
let numberOfPanels = 0;
let numberOfVariables = 0;
let numberOfObjects = 0;
let titlePanels = new Array;
let nameVariables = new Array;
const regexRawSQL = new RegExp(findAll, 'i');
async function main(){
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});/*
const answer = await new Promise(resolve => {
rl.question(colors.yellow('Enter your password: '), resolve);
});
if (!answer) {
console.error(`You need to put a password`.red);
process.exit(0);
}
rl.close();
*/
console.clear();
console.log(colors.green.bold(`-------------------- Starting process --------------------`));
@ -81,7 +84,7 @@ async function main(){
titlePanels.push(panel.title);
else
titlePanels.push("?");
numberOfObjects++;
numberOfPanels++;
}
}
}
@ -90,31 +93,38 @@ async function main(){
for (const list of dashboard.templating.list) {
isFound = regexRawSQL.test(list.query);
if (isFound) {
nameVariables.push(list.name)
numberOfVariables++;
numberOfObjects++;
}
}
}
if (isFound) {
const linkUrl = `${grafanaUrl}/d/${allUID[i].uid}`;
if (titlePanels.length)
console.log(colors.yellow(linkUrl), colors.white(titlePanels.toString().split(",")));
else
console.log(colors.yellow(linkUrl));
if (numberOfVariables)
console.log(colors.magenta(`> ${numberOfVariables} variables`));
console.log(colors.yellow(linkUrl));
if (numberOfPanels) {
console.log(colors.cyan.bold(`> ${numberOfPanels} panels`));
console.log(colors.cyan(titlePanels.toString().split(",")));
}
if (numberOfVariables) {
console.log(colors.magenta.bold(`> ${numberOfVariables} variables`));
console.log(colors.magenta(nameVariables.toString().split(",")));
}
numberOfDashboards++;
}
titlePanels.pop();
titlePanels = [];
nameVariables= [];
numberOfObjects = numberOfPanels + numberOfVariables + numberOfObjects
numberOfPanels=0;
numberOfVariables=0;
}
if (numberOfDashboards==0)
console.log(`No results found`.red);
else
console.log(colors.green.bold(`---- Have been found ${numberOfObjects} results in ${numberOfDashboards} dashboards ----`));
console.log(colors.green.bold(`-------- Have been found ${numberOfObjects} results in ${numberOfDashboards} dashboards -------`));
process.exit(0);
}
main();

View File

@ -1,4 +1,7 @@
{
"author": "Verdnatura Levante SL",
"description": "MySQL Version Control",
"license": "GPL-3.0",
"dependencies": {
"colors": "^1.4.0",
"getopts": "^2.3.0",
@ -7,5 +10,6 @@
"bin": {
"grafana-find": "main.js",
"gfind": "main.js"
}
},
"main": "main.js"
}