wazuh-kibana-app/public/utils/generate-metric.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

/*
* Wazuh app - Useful function to manage metrics
2019-01-14 16:36:47 +00:00
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import $ from 'jquery';
2018-09-11 09:52:54 +00:00
export function generateMetric(id) {
2018-09-10 08:32:49 +00:00
const html = $(id).html();
2018-06-15 08:30:46 +00:00
2018-09-10 08:32:49 +00:00
// New Kibana structure
if (
html.split('ng-non-bindable') &&
html.split('ng-non-bindable')[1] &&
html.split('ng-non-bindable')[1].split('>') &&
html.split('ng-non-bindable')[1].split('>')[1] &&
html
.split('ng-non-bindable')[1]
.split('>')[1]
.split('</') &&
html
.split('ng-non-bindable')[1]
.split('>')[1]
.split('</')[0]
) {
return html
.split('ng-non-bindable')[1]
.split('>')[1]
.split('</')[0];
}
2018-06-15 08:30:46 +00:00
2018-09-10 08:32:49 +00:00
if (typeof html !== 'undefined' && html.includes('<span')) {
if (typeof html.split('<span>')[1] !== 'undefined') {
return html.split('<span>')[1].split('</span')[0];
} else if (html.includes('table') && html.includes('cell-hover')) {
let nonB = html.split('ng-non-bindable')[1];
if (nonB && nonB.split('>')[1] && nonB.split('>')[1].split('</')[0]) {
return nonB.split('>')[1].split('</')[0];
}
2018-06-15 08:30:46 +00:00
}
2018-09-10 08:32:49 +00:00
}
return '';
2018-09-11 09:52:54 +00:00
}