last commits
This commit is contained in:
parent
ef094b4dff
commit
8a9dc64917
|
@ -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": []
|
||||||
|
}
|
|
@ -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".
|
|
@ -22,6 +22,14 @@ $ npm install grafana-find
|
||||||
$ npx grafana-find <command>
|
$ npx grafana-find <command>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Create a file ".grafana-find.json" with this content:
|
||||||
|
|
||||||
|
```text
|
||||||
|
{
|
||||||
|
"grafanaUrl": "<server>"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
Execute *grafana-find* with the desired command.
|
Execute *grafana-find* with the desired command.
|
||||||
|
|
62
main.js
62
main.js
|
@ -14,21 +14,8 @@ if (!fs.existsSync(configFile)) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pedir contraseña
|
const findAll = `Client`;
|
||||||
-----------------
|
const apiKey = `Bearer eyJrIjoickI3WVBab0lscldRdk9JV29YYUFKMEdqUDl6UmsyaHIiLCJuIjoiZ3JhZmFuYS1maW5kIiwiaWQiOjF9`;
|
||||||
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 config = require(configFile);
|
const config = require(configFile);
|
||||||
const grafanaUrl = config.grafanaUrl;
|
const grafanaUrl = config.grafanaUrl;
|
||||||
|
@ -37,14 +24,30 @@ const grafanaApi = `${grafanaUrl}/api`;
|
||||||
const urlDashboards = `${grafanaApi}/search`;
|
const urlDashboards = `${grafanaApi}/search`;
|
||||||
const urlUID = `${grafanaApi}/dashboards/uid/`;
|
const urlUID = `${grafanaApi}/dashboards/uid/`;
|
||||||
let numberOfDashboards = 0;
|
let numberOfDashboards = 0;
|
||||||
let numberOfObjects = 0;
|
let numberOfPanels = 0;
|
||||||
let numberOfVariables = 0;
|
let numberOfVariables = 0;
|
||||||
|
let numberOfObjects = 0;
|
||||||
let titlePanels = new Array;
|
let titlePanels = new Array;
|
||||||
|
let nameVariables = new Array;
|
||||||
|
|
||||||
const regexRawSQL = new RegExp(findAll, 'i');
|
const regexRawSQL = new RegExp(findAll, 'i');
|
||||||
|
|
||||||
async function main(){
|
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.clear();
|
||||||
console.log(colors.green.bold(`-------------------- Starting process --------------------`));
|
console.log(colors.green.bold(`-------------------- Starting process --------------------`));
|
||||||
|
|
||||||
|
@ -81,7 +84,7 @@ async function main(){
|
||||||
titlePanels.push(panel.title);
|
titlePanels.push(panel.title);
|
||||||
else
|
else
|
||||||
titlePanels.push("?");
|
titlePanels.push("?");
|
||||||
numberOfObjects++;
|
numberOfPanels++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,31 +93,38 @@ async function main(){
|
||||||
for (const list of dashboard.templating.list) {
|
for (const list of dashboard.templating.list) {
|
||||||
isFound = regexRawSQL.test(list.query);
|
isFound = regexRawSQL.test(list.query);
|
||||||
if (isFound) {
|
if (isFound) {
|
||||||
|
nameVariables.push(list.name)
|
||||||
numberOfVariables++;
|
numberOfVariables++;
|
||||||
numberOfObjects++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFound) {
|
if (isFound) {
|
||||||
const linkUrl = `${grafanaUrl}/d/${allUID[i].uid}`;
|
const linkUrl = `${grafanaUrl}/d/${allUID[i].uid}`;
|
||||||
if (titlePanels.length)
|
console.log(colors.yellow(linkUrl));
|
||||||
console.log(colors.yellow(linkUrl), colors.white(titlePanels.toString().split(",")));
|
if (numberOfPanels) {
|
||||||
else
|
console.log(colors.cyan.bold(`> ${numberOfPanels} panels`));
|
||||||
console.log(colors.yellow(linkUrl));
|
console.log(colors.cyan(titlePanels.toString().split(",")));
|
||||||
if (numberOfVariables)
|
}
|
||||||
console.log(colors.magenta(`> ${numberOfVariables} variables`));
|
if (numberOfVariables) {
|
||||||
|
console.log(colors.magenta.bold(`> ${numberOfVariables} variables`));
|
||||||
|
console.log(colors.magenta(nameVariables.toString().split(",")));
|
||||||
|
}
|
||||||
numberOfDashboards++;
|
numberOfDashboards++;
|
||||||
}
|
}
|
||||||
|
|
||||||
titlePanels.pop();
|
titlePanels = [];
|
||||||
|
nameVariables= [];
|
||||||
|
numberOfObjects = numberOfPanels + numberOfVariables + numberOfObjects
|
||||||
|
numberOfPanels=0;
|
||||||
numberOfVariables=0;
|
numberOfVariables=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numberOfDashboards==0)
|
if (numberOfDashboards==0)
|
||||||
console.log(`No results found`.red);
|
console.log(`No results found`.red);
|
||||||
else
|
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();
|
main();
|
|
@ -1,4 +1,7 @@
|
||||||
{
|
{
|
||||||
|
"author": "Verdnatura Levante SL",
|
||||||
|
"description": "MySQL Version Control",
|
||||||
|
"license": "GPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"colors": "^1.4.0",
|
"colors": "^1.4.0",
|
||||||
"getopts": "^2.3.0",
|
"getopts": "^2.3.0",
|
||||||
|
@ -7,5 +10,6 @@
|
||||||
"bin": {
|
"bin": {
|
||||||
"grafana-find": "main.js",
|
"grafana-find": "main.js",
|
||||||
"gfind": "main.js"
|
"gfind": "main.js"
|
||||||
}
|
},
|
||||||
|
"main": "main.js"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue