Merge branch 'ent-5353-Refactorizacion_de_los_dashboard' into 'develop'
dashboards See merge request artica/pandorafms!3043
|
@ -71,21 +71,8 @@ if (isset($_GET['loginhash'])) {
|
|||
}
|
||||
}
|
||||
|
||||
$public_hash = get_parameter('hash', false);
|
||||
|
||||
// Check user.
|
||||
if ($public_hash == false) {
|
||||
check_login();
|
||||
} else {
|
||||
enterprise_include_once('include/functions_dashboard.php');
|
||||
if (dashboard_check_public_hash($public_hash) === false) {
|
||||
db_pandora_audit('Invalid public hash', 'Trying to access public dashboard');
|
||||
include 'general/noaccess.php';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
check_login();
|
||||
|
||||
// Enterprise support.
|
||||
if (file_exists(ENTERPRISE_DIR.'/load_enterprise.php')) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
START TRANSACTION;
|
||||
|
||||
ALTER TABLE `twidget_dashboard` ADD COLUMN `position` TEXT NOT NULL default '';
|
||||
|
||||
ALTER TABLE `tagente_estado` ADD COLUMN `last_status_change` bigint(20) NOT NULL default '0';
|
||||
|
||||
UPDATE `tconfig` SET `value`='policy,agent,data_type,module_name,server_type,interval,status,last_status_change,graph,warn,data,timestamp' WHERE `token` = 'status_monitor_fields';
|
||||
|
|
|
@ -1342,13 +1342,13 @@ ALTER TABLE `tmap` MODIFY COLUMN `id_user` varchar(250) NOT NULL DEFAULT '';
|
|||
INSERT INTO `tconfig` (`token`, `value`) VALUES ('big_operation_step_datos_purge', '100');
|
||||
INSERT INTO `tconfig` (`token`, `value`) VALUES ('small_operation_step_datos_purge', '1000');
|
||||
INSERT INTO `tconfig` (`token`, `value`) VALUES ('days_autodisable_deletion', '30');
|
||||
INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 36);
|
||||
INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 37);
|
||||
INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_docs_logo', 'default_docs.png');
|
||||
INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_support_logo', 'default_support.png');
|
||||
INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_logo_white_bg_preview', 'pandora_logo_head_white_bg.png');
|
||||
UPDATE tconfig SET value = 'https://licensing.artica.es/pandoraupdate7/server.php' WHERE token='url_update_manager';
|
||||
DELETE FROM `tconfig` WHERE `token` = 'current_package_enterprise';
|
||||
INSERT INTO `tconfig` (`token`, `value`) VALUES ('current_package_enterprise', '744');
|
||||
INSERT INTO `tconfig` (`token`, `value`) VALUES ('current_package_enterprise', '745');
|
||||
INSERT INTO `tconfig` (`token`, `value`) VALUES ('status_monitor_fields', 'policy,agent,data_type,module_name,server_type,interval,status,graph,warn,data,timestamp');
|
||||
UPDATE `tconfig` SET `value` = 'mini_severity,evento,id_agente,estado,timestamp' WHERE `token` LIKE 'event_fields';
|
||||
DELETE FROM `tconfig` WHERE `token` LIKE 'integria_api_password';
|
||||
|
@ -1641,7 +1641,8 @@ UPDATE `tmetaconsole_agent` SET tmetaconsole_agent.alias = tmetaconsole_agent.no
|
|||
-- ---------------------------------------------------------------------
|
||||
-- Table `twidget_dashboard`
|
||||
-- ---------------------------------------------------------------------
|
||||
ALTER TABLE twidget_dashboard MODIFY options LONGTEXT NOT NULL default "";
|
||||
ALTER TABLE `twidget_dashboard` MODIFY `options` LONGTEXT NOT NULL default "";
|
||||
ALTER TABLE `twidget_dashboard` ADD COLUMN `position` TEXT NOT NULL default "";
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Table `trecon_task`
|
||||
|
|
|
@ -180,7 +180,7 @@ if ($config['menu_type'] == 'classic') {
|
|||
break;
|
||||
|
||||
case 'Dashboard':
|
||||
$_GET['sec2'] = 'enterprise/dashboard/main_dashboard';
|
||||
$_GET['sec2'] = 'operation/dashboard/dashboard';
|
||||
break;
|
||||
|
||||
case 'Visual console':
|
||||
|
@ -779,9 +779,7 @@ if ($config['menu_type'] == 'classic') {
|
|||
}
|
||||
}
|
||||
|
||||
$new_dashboard = get_parameter('new_dashboard', 0);
|
||||
|
||||
if ($_GET['sec2'] == 'enterprise/dashboard/main_dashboard' && $new_dashboard) {
|
||||
if ($_GET['sec2'] == 'operation/dashboard/dashboard' && $new_dashboard) {
|
||||
$do_refresh = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ function open_submenus () {
|
|||
if (value)
|
||||
$('div.menu>ul>li#' + index + '>ul').show();
|
||||
});
|
||||
$('div.menu>ul>li.selected>ul').removeClass('invisible');
|
||||
//$('div.menu>ul>li.selected>ul').removeClass('invisible');
|
||||
}
|
||||
|
||||
function close_submenus () {
|
||||
|
@ -189,7 +189,7 @@ function close_submenus () {
|
|||
if (value)
|
||||
$('div.menu>ul>li#' + index + '>ul').hide();
|
||||
});
|
||||
$('div.menu>ul>li.selected>ul').addClass('invisible');
|
||||
//$('div.menu>ul>li.selected>ul').addClass('invisible');
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,10 @@ global $config;
|
|||
|
||||
check_login();
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use PandoraFMS\Dashboard\Manager;
|
||||
|
||||
enterprise_hook('open_meta_frame');
|
||||
|
||||
require_once $config['homedir'].'/include/functions_profile.php';
|
||||
|
@ -31,7 +35,6 @@ if (enterprise_installed() && defined('METACONSOLE')) {
|
|||
}
|
||||
|
||||
$isFunctionSkins = enterprise_include_once('include/functions_skins.php');
|
||||
enterprise_include_once('include/functions_dashboard.php');
|
||||
|
||||
// Add the columns for the enterprise Pandora edition.
|
||||
$enterprise_include = false;
|
||||
|
@ -833,27 +836,27 @@ $values = [
|
|||
'External link' => __('External link'),
|
||||
'Other' => __('Other'),
|
||||
];
|
||||
if (enterprise_installed() && !is_metaconsole()) {
|
||||
if (!is_metaconsole()) {
|
||||
$values['Dashboard'] = __('Dashboard');
|
||||
}
|
||||
|
||||
|
||||
$table->data[12][1] = html_print_select($values, 'section', io_safe_output($user_info['section']), 'show_data_section();', '', -1, true, false, false);
|
||||
|
||||
if (enterprise_installed()) {
|
||||
$dashboards = dashboard_get_dashboards();
|
||||
$dashboards_aux = [];
|
||||
if ($dashboards === false) {
|
||||
$dashboards = ['None' => 'None'];
|
||||
} else {
|
||||
foreach ($dashboards as $key => $dashboard) {
|
||||
$dashboards_aux[$dashboard['name']] = $dashboard['name'];
|
||||
}
|
||||
}
|
||||
|
||||
$table->data[12][1] .= html_print_select($dashboards_aux, 'dashboard', $user_info['data_section'], '', '', '', true);
|
||||
$dashboards = Manager::getDashboards(-1, -1);
|
||||
$dashboards_aux = [];
|
||||
if ($dashboards === false) {
|
||||
$dashboards = ['None' => 'None'];
|
||||
} else {
|
||||
foreach ($dashboards as $key => $dashboard) {
|
||||
$dashboards_aux[$dashboard['id']] = $dashboard['name'];
|
||||
}
|
||||
}
|
||||
|
||||
$table->data[12][1] .= html_print_select($dashboards_aux, 'dashboard', $user_info['data_section'], '', '', '', true);
|
||||
|
||||
|
||||
$layouts = visual_map_get_user_layouts($config['id_user'], true);
|
||||
$layouts_aux = [];
|
||||
if ($layouts === false) {
|
||||
|
|
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 46 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 4.1 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 4.1 KiB |
|
@ -64,7 +64,6 @@ if ($print_custom_graph) {
|
|||
'only_image' => (bool) get_parameter('only_image', false),
|
||||
'homeurl' => (string) get_parameter('homeurl', ''),
|
||||
'ttl' => (int) get_parameter('ttl', 1),
|
||||
'dashboard' => (bool) get_parameter('dashboard', false),
|
||||
'vconsole' => (bool) get_parameter('vconsole', false),
|
||||
'fullscale' => (bool) get_parameter('fullscale', false),
|
||||
'backgroundColor' => (string) get_parameter('background_color', 'white'),
|
||||
|
@ -114,7 +113,6 @@ if ($print_sparse_graph) {
|
|||
'menu' => (bool) get_parameter('menu', true),
|
||||
'backgroundColor' => (string) get_parameter('background_color', 'white'),
|
||||
'percentil' => get_parameter('percentil', null),
|
||||
'dashboard' => (bool) get_parameter('dashboard'),
|
||||
'vconsole' => (bool) get_parameter('vconsole'),
|
||||
'type_graph' => get_parameter('type_g', $config['type_module_charts']),
|
||||
'fullscale' => get_parameter('fullscale', 0),
|
||||
|
|
|
@ -14,28 +14,8 @@
|
|||
if (is_ajax()) {
|
||||
global $config;
|
||||
|
||||
enterprise_include_once('include/functions_dashboard.php');
|
||||
|
||||
$public_hash = get_parameter('hash', 0);
|
||||
|
||||
// Try to authenticate by hash on public dashboards
|
||||
if ($public_hash == 0) {
|
||||
// Login check
|
||||
check_login();
|
||||
} else {
|
||||
$validate_hash = enterprise_hook(
|
||||
'dasboard_validate_public_hash',
|
||||
[
|
||||
$public_hash,
|
||||
'tree_view',
|
||||
]
|
||||
);
|
||||
if ($validate_hash === false || $validate_hash === ENTERPRISE_NOT_HOOK) {
|
||||
db_pandora_audit('Invalid public hash', 'Trying to access report builder');
|
||||
include 'general/noaccess.php';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// Login check.
|
||||
check_login();
|
||||
|
||||
include_once $config['homedir'].'/include/class/Tree.class.php';
|
||||
include_once $config['homedir'].'/include/class/TreeOS.class.php';
|
||||
|
@ -61,10 +41,6 @@ if (is_ajax()) {
|
|||
$rootID = get_parameter('rootID', -1);
|
||||
$serverID = get_parameter('serverID', false);
|
||||
$childrenMethod = get_parameter('childrenMethod', 'on_demand');
|
||||
$hash = get_parameter('hash', false);
|
||||
if ($hash !== false) {
|
||||
enterprise_hook('dasboard_validate_public_hash', [$hash, 'tree_view']);
|
||||
}
|
||||
|
||||
$default_filters = [
|
||||
'searchAgent' => '',
|
||||
|
|
|
@ -12,32 +12,13 @@
|
|||
// GNU General Public License for more details.
|
||||
global $config;
|
||||
|
||||
enterprise_include_once('include/functions_dashboard.php');
|
||||
require_once 'include/functions_visual_map.php';
|
||||
enterprise_include_once('include/functions_visual_map.php');
|
||||
|
||||
$public_hash = get_parameter('hash', false);
|
||||
$id_visual_console = get_parameter('id_visual_console', null);
|
||||
|
||||
// Try to authenticate by hash on public dashboards
|
||||
if ($public_hash === false) {
|
||||
// Login check
|
||||
check_login();
|
||||
} else {
|
||||
$validate_hash = enterprise_hook(
|
||||
'dasboard_validate_public_hash',
|
||||
[
|
||||
$public_hash,
|
||||
$id_visual_console,
|
||||
'visual_console',
|
||||
]
|
||||
);
|
||||
if ($validate_hash === false || $validate_hash === ENTERPRISE_NOT_HOOK) {
|
||||
db_pandora_audit('Invalid public hash', 'Trying to access report builder');
|
||||
include 'general/noaccess.php';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// Login check.
|
||||
check_login();
|
||||
|
||||
// Fix: IW was the old ACL to check for report editing, now is RW
|
||||
if (! check_acl($config['id_user'], 0, 'VR')) {
|
||||
|
|
|
@ -216,24 +216,7 @@ if (file_exists('languages/'.$user_language.'.mo') === true) {
|
|||
break;
|
||||
|
||||
case 'vbar':
|
||||
echo flot_vcolumn_chart(
|
||||
$params['chart_data'],
|
||||
$params['width'],
|
||||
$params['height'],
|
||||
$params['color'],
|
||||
$params['legend'],
|
||||
$params['long_index'],
|
||||
$params['homeurl'],
|
||||
$params['unit'],
|
||||
$params['water_mark_url'],
|
||||
$params['homedir'],
|
||||
$params['font'],
|
||||
$config['font_size'],
|
||||
$params['from_ux'],
|
||||
$params['from_wux'],
|
||||
$params['backgroundColor'],
|
||||
$params['tick_color']
|
||||
);
|
||||
echo flot_vcolumn_chart($params);
|
||||
break;
|
||||
|
||||
case 'hbar':
|
||||
|
@ -292,7 +275,7 @@ if (file_exists('languages/'.$user_language.'.mo') === true) {
|
|||
$params['full_legend_daterray'],
|
||||
$params['not_interactive'],
|
||||
$params['ttl'],
|
||||
$params['widgets'],
|
||||
$params['sizeForTicks'],
|
||||
$params['show'],
|
||||
$params['date_to']
|
||||
);
|
||||
|
|
|
@ -2676,10 +2676,15 @@ class NetworkMap
|
|||
|
||||
$simulate = false;
|
||||
if (isset($networkmap['__simulated']) === false) {
|
||||
$networkmap['filter'] = json_decode(
|
||||
$networkmap['filter'],
|
||||
true
|
||||
);
|
||||
if ($this->widget) {
|
||||
$networkmap['filter'] = $this->mapOptions;
|
||||
} else {
|
||||
$networkmap['filter'] = json_decode(
|
||||
$networkmap['filter'],
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
$networkmap['filter']['holding_area'] = [
|
||||
500,
|
||||
500,
|
||||
|
@ -3460,7 +3465,11 @@ class NetworkMap
|
|||
// Open networkconsole_id div.
|
||||
$output .= '<div id="networkconsole_'.$networkmap['id'].'"';
|
||||
if ($this->fullSize) {
|
||||
$output .= ' style="width: 100%; height: 100%;position: relative; overflow: hidden; background: #FAFAFA">';
|
||||
if ($this->widget) {
|
||||
$output .= ' style="width: 100%; height: 100%;position: relative; overflow: hidden;">';
|
||||
} else {
|
||||
$output .= ' style="width: 100%; height: 100%;position: relative; overflow: hidden; background: #FAFAFA">';
|
||||
}
|
||||
} else {
|
||||
$output .= ' style="width: '.$this->mapOptions['width'].'px; height: '.$this->mapOptions['height'].'px;position: relative; overflow: hidden; background: #FAFAFA">';
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ class OrderInterpreter extends Wizard
|
|||
'images/op_reporting.menu_gray.png'
|
||||
),
|
||||
'url' => ui_get_full_url(
|
||||
'index.php?sec=reporting&sec2=enterprise/dashboard/dashboards'
|
||||
'index.php?sec=reporting&sec2=operation/dashboard/dashboard'
|
||||
),
|
||||
'acl' => check_acl(
|
||||
$config['id_user'],
|
||||
|
|
|
@ -227,7 +227,7 @@ $config['extensions'] = extensions_get_extensions();
|
|||
// Detect if enterprise extension is installed
|
||||
// NOTICE: This variable (config[enterprise_installed] is used in several
|
||||
// sections. Faking or forcing to 1 will make pandora fails.
|
||||
if (file_exists($config['homedir'].'/'.ENTERPRISE_DIR.'/index.php')) {
|
||||
if (file_exists($config['homedir'].'/'.ENTERPRISE_DIR.'/load_enterprise.php')) {
|
||||
$config['enterprise_installed'] = 1;
|
||||
enterprise_include_once('include/functions_enterprise.php');
|
||||
} else {
|
||||
|
|
|
@ -2482,12 +2482,12 @@ function get_os_name($id_os)
|
|||
function get_user_dashboards($id_user)
|
||||
{
|
||||
if (users_is_admin($id_user)) {
|
||||
$sql = "SELECT name
|
||||
$sql = "SELECT id, name
|
||||
FROM tdashboard WHERE id_user = '".$id_user."' OR id_user = ''";
|
||||
} else {
|
||||
$user_can_manage_all = users_can_manage_group_all('RR');
|
||||
if ($user_can_manage_all) {
|
||||
$sql = "SELECT name
|
||||
$sql = "SELECT id, name
|
||||
FROM tdashboard WHERE id_user = '".$id_user."' OR id_user = ''";
|
||||
} else {
|
||||
$user_groups = users_get_groups($id_user, 'RR', false);
|
||||
|
@ -2500,7 +2500,7 @@ function get_user_dashboards($id_user)
|
|||
$u_groups[] = $id;
|
||||
}
|
||||
|
||||
$sql = 'SELECT name
|
||||
$sql = 'SELECT id, name
|
||||
FROM tdashboard
|
||||
WHERE id_group IN ('.implode(',', $u_groups).") AND (id_user = '".$id_user."' OR id_user = '')";
|
||||
}
|
||||
|
@ -3870,12 +3870,17 @@ function generator_chart_to_pdf($type_graph_pdf, $params, $params_combined=false
|
|||
$img_url = ui_get_full_url(false).$hack_metaconsole.'/attachment/'.$img_file;
|
||||
}
|
||||
|
||||
$width_img = 550;
|
||||
$height_img = $params['height'];
|
||||
if ($type_graph_pdf === 'vbar') {
|
||||
$width_img = $params['generals']['pdf']['width'];
|
||||
$height_img = $params['generals']['pdf']['height'];
|
||||
} else {
|
||||
$width_img = 550;
|
||||
$height_img = $params['height'];
|
||||
|
||||
if ((int) $params['landscape'] === 1) {
|
||||
$height_img = 150;
|
||||
$params['height'] = 150;
|
||||
if ((int) $params['landscape'] === 1) {
|
||||
$height_img = 150;
|
||||
$params['height'] = 150;
|
||||
}
|
||||
}
|
||||
|
||||
$params_encode_json = urlencode(json_encode($params));
|
||||
|
|
|
@ -1078,7 +1078,7 @@ function agents_get_group_agents(
|
|||
}
|
||||
|
||||
if ($childGroups) {
|
||||
if (is_array($id_group)) {
|
||||
if (is_array($id_group) === true) {
|
||||
foreach ($id_group as $parent) {
|
||||
$id_group = array_merge(
|
||||
$id_group,
|
||||
|
@ -1098,7 +1098,7 @@ function agents_get_group_agents(
|
|||
}
|
||||
|
||||
// Search for primary and secondary groups.
|
||||
if (!empty($id_group)) {
|
||||
if (empty($id_group) === false) {
|
||||
$filter[] = '('.db_format_array_where_clause_sql(
|
||||
[
|
||||
'id_group' => $id_group,
|
||||
|
@ -1108,83 +1108,59 @@ function agents_get_group_agents(
|
|||
).')';
|
||||
}
|
||||
|
||||
if ($search === true) {
|
||||
// No added search. Show both disabled and non-disabled.
|
||||
} else if (is_array($search)) {
|
||||
if (is_array($search) === true) {
|
||||
if (!$search['all_agents']) {
|
||||
$filter['disabled'] = 0;
|
||||
if (isset($search['disabled'])) {
|
||||
if (isset($search['disabled']) === true) {
|
||||
$filter['disabled'] = (int) $search['disabled'];
|
||||
|
||||
unset($search['disabled']);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($search['string'])) {
|
||||
if (isset($search['string']) === true) {
|
||||
$string = io_safe_input($search['string']);
|
||||
switch ($config['dbtype']) {
|
||||
case 'mysql':
|
||||
case 'postgresql':
|
||||
$filter[] = "(nombre COLLATE utf8_general_ci LIKE '%$string%' OR direccion LIKE '%$string%')";
|
||||
break;
|
||||
|
||||
case 'oracle':
|
||||
$filter[] = "(UPPER(nombre) LIKE UPPER('%$string%') OR direccion LIKE upper('%$string%'))";
|
||||
break;
|
||||
}
|
||||
|
||||
$filter[] = "(nombre COLLATE utf8_general_ci LIKE '%$string%' OR direccion LIKE '%$string%')";
|
||||
unset($search['string']);
|
||||
}
|
||||
|
||||
if (isset($search['name'])) {
|
||||
if (isset($search['name']) === true) {
|
||||
$name = io_safe_input($search['name']);
|
||||
switch ($config['dbtype']) {
|
||||
case 'mysql':
|
||||
case 'postgresql':
|
||||
$filter[] = "nombre COLLATE utf8_general_ci LIKE '$name'";
|
||||
break;
|
||||
|
||||
case 'oracle':
|
||||
$filter[] = "UPPER(nombre) LIKE UPPER('$name')";
|
||||
break;
|
||||
}
|
||||
|
||||
$filter[] = "nombre COLLATE utf8_general_ci LIKE '$name'";
|
||||
unset($search['name']);
|
||||
}
|
||||
|
||||
if (isset($search['alias'])) {
|
||||
if (isset($search['alias']) === true) {
|
||||
$name = io_safe_input($search['alias']);
|
||||
switch ($config['dbtype']) {
|
||||
case 'mysql':
|
||||
case 'postgresql':
|
||||
$filter[] = "alias COLLATE utf8_general_ci LIKE '$name'";
|
||||
break;
|
||||
|
||||
case 'oracle':
|
||||
$filter[] = "UPPER(alias) LIKE UPPER('$name')";
|
||||
break;
|
||||
}
|
||||
|
||||
$filter[] = "alias COLLATE utf8_general_ci LIKE '$name'";
|
||||
unset($search['alias']);
|
||||
}
|
||||
|
||||
if (isset($search['id_os'])) {
|
||||
if (isset($search['aliasRegex']) === true) {
|
||||
$name = io_safe_input($search['aliasRegex']);
|
||||
$filter[] = sprintf(
|
||||
'alias COLLATE utf8_general_ci REGEXP "%s"',
|
||||
$name
|
||||
);
|
||||
unset($search['aliasRegex']);
|
||||
}
|
||||
|
||||
if (isset($search['id_os']) === true) {
|
||||
$filter['id_os'] = $search['id_os'];
|
||||
}
|
||||
|
||||
if (isset($search['status'])) {
|
||||
if (isset($search['status']) === true) {
|
||||
switch ($search['status']) {
|
||||
case AGENT_STATUS_NORMAL:
|
||||
$filter[] = '(
|
||||
critical_count = 0
|
||||
AND warning_count = 0
|
||||
AND unknown_count = 0
|
||||
AND unknown_count = 0
|
||||
AND normal_count > 0)';
|
||||
break;
|
||||
|
||||
case AGENT_STATUS_WARNING:
|
||||
$filter[] = '(
|
||||
critical_count = 0
|
||||
critical_count = 0
|
||||
AND warning_count > 0
|
||||
AND total_count > 0)';
|
||||
break;
|
||||
|
@ -1195,8 +1171,8 @@ function agents_get_group_agents(
|
|||
|
||||
case AGENT_STATUS_UNKNOWN:
|
||||
$filter[] = '(
|
||||
critical_count = 0
|
||||
AND warning_count = 0
|
||||
critical_count = 0
|
||||
AND warning_count = 0
|
||||
AND unknown_count > 0)';
|
||||
break;
|
||||
|
||||
|
@ -1214,6 +1190,10 @@ function agents_get_group_agents(
|
|||
total_count = 0
|
||||
OR total_count = notinit_count)';
|
||||
break;
|
||||
|
||||
default:
|
||||
// Not posible.
|
||||
break;
|
||||
}
|
||||
|
||||
unset($search['status']);
|
||||
|
@ -1229,7 +1209,7 @@ function agents_get_group_agents(
|
|||
$filter['id_tmetaconsole_setup'] = $search['id_server'];
|
||||
|
||||
if ($filter['id_tmetaconsole_setup'] == 0) {
|
||||
// All nodes
|
||||
// All nodes.
|
||||
unset($filter['id_tmetaconsole_setup']);
|
||||
}
|
||||
|
||||
|
@ -1237,12 +1217,12 @@ function agents_get_group_agents(
|
|||
}
|
||||
|
||||
if (!$add_alert_bulk_op) {
|
||||
// Add the rest of the filter from the search array
|
||||
// Add the rest of the filter from the search array.
|
||||
foreach ($search as $key => $value) {
|
||||
$filter[] = $value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if ($filter !== true) {
|
||||
$filter['disabled'] = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -4810,7 +4810,7 @@ function events_page_comments($event, $ajax=false)
|
|||
__('Add comment'),
|
||||
'comment_button',
|
||||
false,
|
||||
'event_comment();',
|
||||
'event_comment(\''.base64_encode(json_encode($event)).'\');',
|
||||
'class="sub next"',
|
||||
true
|
||||
);
|
||||
|
|
|
@ -1720,6 +1720,10 @@ function graphic_combined_module(
|
|||
$params['threshold_data'] = $threshold_data;
|
||||
}
|
||||
|
||||
if ($params['vconsole'] === true) {
|
||||
$water_mark = false;
|
||||
}
|
||||
|
||||
$output = area_graph(
|
||||
$agent_module_id,
|
||||
$array_data,
|
||||
|
@ -1861,6 +1865,7 @@ function graphic_combined_module(
|
|||
$height = 50;
|
||||
} else {
|
||||
$height = ($height / $number_elements);
|
||||
$water_mark = false;
|
||||
}
|
||||
|
||||
$color = color_graph_array();
|
||||
|
@ -1983,18 +1988,25 @@ function graphic_combined_module(
|
|||
|
||||
$color = color_graph_array();
|
||||
|
||||
if (!$params['vconsole']) {
|
||||
if ($params['vconsole'] === false) {
|
||||
$width = 200;
|
||||
$height = 200;
|
||||
} else {
|
||||
$width = ($width / $number_elements);
|
||||
$height = ($height / $number_elements);
|
||||
$ratio = ((200 * ( $height / (200 * $number_elements) )) / (200 * ( $width / (200 * $number_elements))));
|
||||
|
||||
$new_width = ( 200 * ( $width / (200 * $number_elements) ) );
|
||||
$new_height = ( 200 * ( $height / (200 * $number_elements) / $ratio ) );
|
||||
|
||||
if ($height > $width) {
|
||||
$new_height = (200 * ($height / (200 * $number_elements)));
|
||||
$new_width = (200 * ($width / (200 * $number_elements)) / $ratio);
|
||||
}
|
||||
}
|
||||
|
||||
$output = stacked_gauge(
|
||||
$graph_values,
|
||||
$width,
|
||||
$height,
|
||||
$new_width,
|
||||
$new_height,
|
||||
$color,
|
||||
$module_name_list,
|
||||
ui_get_full_url(
|
||||
|
@ -2015,10 +2027,10 @@ function graphic_combined_module(
|
|||
$label = '';
|
||||
foreach ($module_list as $module_item) {
|
||||
$automatic_custom_graph_meta = false;
|
||||
if ($config['metaconsole']) {
|
||||
if (is_metaconsole() === true) {
|
||||
// Automatic custom graph from the report
|
||||
// template in metaconsole.
|
||||
if (is_array($module_list[$i])) {
|
||||
if (is_array($module_list[$i]) === true) {
|
||||
$server = metaconsole_get_connection_by_id(
|
||||
$module_item['server']
|
||||
);
|
||||
|
@ -2027,7 +2039,7 @@ function graphic_combined_module(
|
|||
}
|
||||
}
|
||||
|
||||
if ($automatic_custom_graph_meta) {
|
||||
if ($automatic_custom_graph_meta === true) {
|
||||
$module = $module_item['module'];
|
||||
} else {
|
||||
$module = $module_item;
|
||||
|
@ -2035,8 +2047,7 @@ function graphic_combined_module(
|
|||
|
||||
$module_data = modules_get_agentmodule($module);
|
||||
$query_last_value = sprintf(
|
||||
'
|
||||
SELECT datos
|
||||
'SELECT datos
|
||||
FROM tagente_datos
|
||||
WHERE id_agente_modulo = %d
|
||||
AND utimestamp < %d
|
||||
|
@ -2050,8 +2061,8 @@ function graphic_combined_module(
|
|||
modules_get_agentmodule_agent_name($module)
|
||||
);
|
||||
|
||||
if (!empty($params_combined['labels'])
|
||||
&& isset($params_combined['labels'][$module])
|
||||
if (empty($params_combined['labels']) === false
|
||||
&& isset($params_combined['labels'][$module]) === true
|
||||
) {
|
||||
$label = $params_combined['labels'][$module];
|
||||
} else {
|
||||
|
@ -2061,15 +2072,30 @@ function graphic_combined_module(
|
|||
'id_agente',
|
||||
$module_data['id_agente']
|
||||
);
|
||||
$label = $alias.' - '.$module_data['nombre'];
|
||||
if ($params['vconsole'] === true) {
|
||||
if ($width < 250 || $height < 250) {
|
||||
$label = \ui_print_truncate_text($module_data['nombre'], 3, false);
|
||||
} else {
|
||||
$label = $module_data['nombre'];
|
||||
}
|
||||
} else {
|
||||
$label = $alias.' - '.$module_data['nombre'];
|
||||
}
|
||||
}
|
||||
|
||||
$temp[$label]['g'] = round($temp_data, 4);
|
||||
if ($params_combined['stacked'] == CUSTOM_GRAPH_VBARS) {
|
||||
$temp[] = [
|
||||
'tick' => $label,
|
||||
'data' => (int) round($temp_data, 4),
|
||||
];
|
||||
} else {
|
||||
$temp[$label]['g'] = round($temp_data, 4);
|
||||
}
|
||||
|
||||
if ($config['metaconsole']) {
|
||||
if (is_metaconsole() === true) {
|
||||
// Automatic custom graph from the report
|
||||
// template in metaconsole.
|
||||
if (is_array($module_list[0])) {
|
||||
if (is_array($module_list[0]) === true) {
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
}
|
||||
|
@ -2079,12 +2105,14 @@ function graphic_combined_module(
|
|||
|
||||
$graph_values = $temp;
|
||||
|
||||
if (!$params['vconsole']) {
|
||||
$width = 1024;
|
||||
$height = 500;
|
||||
}
|
||||
|
||||
if ($params_combined['stacked'] == CUSTOM_GRAPH_HBARS) {
|
||||
if ($params['vconsole'] === false) {
|
||||
$width = 1024;
|
||||
$height = 500;
|
||||
} else {
|
||||
$water_mark = false;
|
||||
}
|
||||
|
||||
$output = hbar_graph(
|
||||
$graph_values,
|
||||
$width,
|
||||
|
@ -2112,32 +2140,27 @@ function graphic_combined_module(
|
|||
}
|
||||
|
||||
if ($params_combined['stacked'] == CUSTOM_GRAPH_VBARS) {
|
||||
$output = vbar_graph(
|
||||
$graph_values,
|
||||
$width,
|
||||
$height,
|
||||
$color,
|
||||
$module_name_list,
|
||||
$long_index,
|
||||
ui_get_full_url(
|
||||
'images/image_problem_area_small.png',
|
||||
false,
|
||||
false,
|
||||
false
|
||||
),
|
||||
'',
|
||||
'',
|
||||
$water_mark,
|
||||
$config['fontpath'],
|
||||
$fixed_font_size,
|
||||
'',
|
||||
$ttl,
|
||||
$homeurl,
|
||||
$background_color,
|
||||
true,
|
||||
false,
|
||||
'#c1c1c1'
|
||||
);
|
||||
$options = [];
|
||||
$sizeLabelTickWidth = 85;
|
||||
if ($params['vconsole'] === true) {
|
||||
$water_mark = false;
|
||||
if (isset($width) === true) {
|
||||
$sizeLabelTickWidth = 30;
|
||||
}
|
||||
} else {
|
||||
$options['grid']['hoverable'] = true;
|
||||
}
|
||||
|
||||
$options['generals']['rotate'] = true;
|
||||
$options['generals']['forceTicks'] = true;
|
||||
$options['x']['labelWidth'] = $sizeLabelTickWidth;
|
||||
$options['generals']['arrayColors'] = $color;
|
||||
$options['grid']['backgroundColor'] = 'transparent';
|
||||
$options['grid']['backgroundColor'] = $background_color;
|
||||
$options['y']['color'] = $background_color;
|
||||
$options['x']['color'] = $background_color;
|
||||
|
||||
$output = vbar_graph($graph_values, $options, $ttl);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -2176,6 +2199,7 @@ function graphic_combined_module(
|
|||
$datelimit,
|
||||
$params['date']
|
||||
);
|
||||
|
||||
$temp_data = db_get_value_sql($query_last_value);
|
||||
|
||||
if ($temp_data) {
|
||||
|
@ -2223,9 +2247,11 @@ function graphic_combined_module(
|
|||
|
||||
$graph_values = $temp;
|
||||
|
||||
if (!$params['vconsole']) {
|
||||
if ($params['vconsole'] === false) {
|
||||
$width = $width;
|
||||
$height = 500;
|
||||
} else {
|
||||
$water_mark = false;
|
||||
}
|
||||
|
||||
$color = color_graph_array();
|
||||
|
@ -2358,100 +2384,62 @@ function combined_graph_summatory_average(
|
|||
|
||||
|
||||
/**
|
||||
* Print a graph with access data of agents
|
||||
* Print a graph with access data of agents.
|
||||
*
|
||||
* @param integer $id_agent Agent ID.
|
||||
* @param integer $width Pie graph width.
|
||||
* @param integer $height Pie graph height.
|
||||
* @param integer $period Time period.
|
||||
* @param boolean $return Return.
|
||||
* @param boolean $tree View tree.
|
||||
* @param integer $id_agent Agent Id.
|
||||
* @param integer $period Timestamp period graph.
|
||||
* @param boolean|null $return Type return.
|
||||
*
|
||||
* @return string Return or echo the result flag.
|
||||
* @return string
|
||||
*/
|
||||
function graphic_agentaccess(
|
||||
$id_agent,
|
||||
$width,
|
||||
$height,
|
||||
$period=0,
|
||||
$return=false,
|
||||
$tree=false
|
||||
int $id_agent,
|
||||
int $period=0,
|
||||
?bool $return=false
|
||||
) {
|
||||
global $config;
|
||||
global $graphic_type;
|
||||
|
||||
// Dates.
|
||||
$date = get_system_time();
|
||||
$datelimit = ($date - $period);
|
||||
$data_array = [];
|
||||
$interval = agents_get_interval($id_agent);
|
||||
$interval = 3600;
|
||||
|
||||
$data = db_get_all_rows_sql(
|
||||
sprintf(
|
||||
'SELECT utimestamp, count(*) as data
|
||||
FROM tagent_access
|
||||
WHERE id_agent = %d
|
||||
AND utimestamp > %d
|
||||
AND utimestamp < %d
|
||||
GROUP BY ROUND(utimestamp/%d)',
|
||||
$id_agent,
|
||||
$datelimit,
|
||||
$date,
|
||||
$interval
|
||||
)
|
||||
// Query.
|
||||
$sql = sprintf(
|
||||
'SELECT utimestamp, count(*) as data
|
||||
FROM tagent_access
|
||||
WHERE id_agent = %d
|
||||
AND utimestamp >= %d
|
||||
AND utimestamp <= %d
|
||||
GROUP BY TRUNCATE(utimestamp/%d,0)',
|
||||
$id_agent,
|
||||
$datelimit,
|
||||
$date,
|
||||
$interval
|
||||
);
|
||||
|
||||
if (isset($data) && is_array($data)) {
|
||||
$data = db_get_all_rows_sql($sql);
|
||||
|
||||
// Array data.
|
||||
$data_array = [];
|
||||
if (isset($data) === true && is_array($data) === true) {
|
||||
foreach ($data as $key => $value) {
|
||||
$data_array['Agent access']['data'][$key][0] = ($value['utimestamp'] * 1000);
|
||||
$data_array['Agent access']['data'][$key][1] = $value['data'];
|
||||
}
|
||||
|
||||
$data_array['Agent access']['color'] = 'green';
|
||||
} else {
|
||||
if ($return) {
|
||||
return graph_nodata_image($width, $height);
|
||||
} else {
|
||||
echo graph_nodata_image($width, $height);
|
||||
$time = (date('H:m', $value['utimestamp']));
|
||||
$data_array[] = [
|
||||
'tick' => $time,
|
||||
'data' => (int) $value['data'],
|
||||
'color' => '#82b92f',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ($config['fixed_graph'] == false) {
|
||||
$water_mark = [
|
||||
'file' => $config['homedir'].'/images/logo_vertical_water.png',
|
||||
'url' => ui_get_full_url(
|
||||
'images/logo_vertical_water.png',
|
||||
false,
|
||||
false,
|
||||
false
|
||||
),
|
||||
];
|
||||
}
|
||||
$options = [];
|
||||
$options['grid']['hoverable'] = true;
|
||||
|
||||
$params = [
|
||||
'agent_module_id' => false,
|
||||
'period' => $period,
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
'unit' => $unit,
|
||||
'only_image' => $only_image,
|
||||
'homeurl' => $homeurl,
|
||||
'menu' => true,
|
||||
'backgroundColor' => 'transparent',
|
||||
'type_graph' => 'area',
|
||||
'font' => $config['fontpath'],
|
||||
'font_size' => $config['font_size'],
|
||||
'array_data_create' => $data_array,
|
||||
'show_overview' => false,
|
||||
'show_export_csv' => false,
|
||||
'vconsole' => true,
|
||||
'show_legend' => false,
|
||||
'grid_color' => 'grey',
|
||||
];
|
||||
|
||||
if ($return) {
|
||||
return grafico_modulo_sparse($params);
|
||||
if ($return === true) {
|
||||
return vbar_graph($data_array, $options, 1);
|
||||
} else {
|
||||
echo grafico_modulo_sparse($params);
|
||||
echo vbar_graph($data_array, $options, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3667,6 +3655,7 @@ function graph_custom_sql_graph(
|
|||
$data = [];
|
||||
|
||||
$count = 0;
|
||||
$flagOther = false;
|
||||
foreach ($data_result as $data_item) {
|
||||
$count++;
|
||||
$value = 0;
|
||||
|
@ -3688,7 +3677,13 @@ function graph_custom_sql_graph(
|
|||
|
||||
switch ($type) {
|
||||
case 'sql_graph_vbar':
|
||||
// vertical bar
|
||||
// Vertical bar.
|
||||
$data[] = [
|
||||
'tick' => $label.'_'.$count,
|
||||
'data' => $value,
|
||||
];
|
||||
break;
|
||||
|
||||
case 'sql_graph_hbar':
|
||||
// horizontal bar
|
||||
$data[$label.'_'.$count]['g'] = $value;
|
||||
|
@ -3702,7 +3697,19 @@ function graph_custom_sql_graph(
|
|||
} else {
|
||||
switch ($type) {
|
||||
case 'sql_graph_vbar':
|
||||
// vertical bar
|
||||
// Vertical bar.
|
||||
if ($flagOther === false) {
|
||||
$data[] = [
|
||||
'tick' => __('Other'),
|
||||
'data' => $value,
|
||||
];
|
||||
|
||||
$flagOther = true;
|
||||
}
|
||||
|
||||
$data[(count($data) - 1)]['data'] += $value;
|
||||
break;
|
||||
|
||||
case 'sql_graph_hbar':
|
||||
// horizontal bar
|
||||
if (!isset($data[__('Other')]['g'])) {
|
||||
|
@ -3733,28 +3740,32 @@ function graph_custom_sql_graph(
|
|||
|
||||
switch ($type) {
|
||||
case 'sql_graph_vbar':
|
||||
// vertical bar
|
||||
return vbar_graph(
|
||||
$data,
|
||||
$width,
|
||||
$height,
|
||||
[],
|
||||
[],
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
$water_mark,
|
||||
$config['fontpath'],
|
||||
$config['font_size'],
|
||||
'',
|
||||
$ttl,
|
||||
$homeurl,
|
||||
'white',
|
||||
true,
|
||||
false,
|
||||
'#c1c1c1'
|
||||
);
|
||||
// Vertical bar.
|
||||
$color = color_graph_array();
|
||||
|
||||
$options = [];
|
||||
$options['generals']['rotate'] = true;
|
||||
$options['generals']['forceTicks'] = true;
|
||||
$options['generals']['arrayColors'] = $color;
|
||||
$options['x']['labelWidth'] = 75;
|
||||
if ($ttl === 2) {
|
||||
$options['backgroundColor'] = 'transparent';
|
||||
$options['grid']['backgroundColor'] = 'transparent';
|
||||
$options['y']['color'] = 'transparent';
|
||||
$options['x']['color'] = 'transparent';
|
||||
$options['generals']['pdf']['width'] = $width;
|
||||
$options['generals']['pdf']['height'] = $height;
|
||||
|
||||
$output .= '<img style="margin-left:20px;" src="data:image/jpg;base64,';
|
||||
$output .= vbar_graph($data, $options, $ttl);
|
||||
$output .= '" />';
|
||||
} else {
|
||||
$options['grid']['hoverable'] = true;
|
||||
$output = '<div style="width:100%; height:'.$height.'px">';
|
||||
$output .= vbar_graph($data, $options, $ttl);
|
||||
$output .= '</div>';
|
||||
}
|
||||
return $output;
|
||||
|
||||
break;
|
||||
case 'sql_graph_hbar':
|
||||
|
@ -3809,8 +3820,18 @@ function graph_custom_sql_graph(
|
|||
* @param string homeurl
|
||||
* @param bool return or echo the result
|
||||
*/
|
||||
function graph_graphic_agentevents($id_agent, $width, $height, $period=0, $homeurl, $return=false, $from_agent_view=false, $widgets=false, $server_id='')
|
||||
{
|
||||
function graph_graphic_agentevents(
|
||||
$id_agent,
|
||||
$width,
|
||||
$height,
|
||||
$period=0,
|
||||
$homeurl,
|
||||
$return=false,
|
||||
$from_agent_view=false,
|
||||
$widgets=false,
|
||||
$not_interactive=0,
|
||||
$server_id=''
|
||||
) {
|
||||
global $config;
|
||||
global $graphic_type;
|
||||
|
||||
|
@ -3885,8 +3906,27 @@ function graph_graphic_agentevents($id_agent, $width, $height, $period=0, $homeu
|
|||
];
|
||||
|
||||
// Draw slicebar graph
|
||||
$out = flot_slicesbar_graph($data, $period, $width, $height, $full_legend, $colors, $config['fontpath'], $config['round_corner'], $homeurl, '', '', false, $id_agent, $full_legend_date, 0, 1, $widgets, true, false, $server_id);
|
||||
// id_server
|
||||
$out = flot_slicesbar_graph(
|
||||
$data,
|
||||
$period,
|
||||
$width,
|
||||
$height,
|
||||
$full_legend,
|
||||
$colors,
|
||||
$config['fontpath'],
|
||||
$config['round_corner'],
|
||||
$homeurl,
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
$id_agent,
|
||||
$full_legend_date,
|
||||
$not_interactive,
|
||||
1,
|
||||
$widgets,
|
||||
$server_id
|
||||
);
|
||||
|
||||
if ($return) {
|
||||
return $out;
|
||||
} else {
|
||||
|
@ -3905,8 +3945,17 @@ function graph_graphic_agentevents($id_agent, $width, $height, $period=0, $homeu
|
|||
* @param string homeurl
|
||||
* @param bool return or echo the result
|
||||
*/
|
||||
function graph_graphic_moduleevents($id_agent, $id_module, $width, $height, $period=0, $homeurl, $return=false, $ttl=1)
|
||||
{
|
||||
function graph_graphic_moduleevents(
|
||||
$id_agent,
|
||||
$id_module,
|
||||
$width,
|
||||
$height,
|
||||
$period=0,
|
||||
$homeurl='',
|
||||
$return=false,
|
||||
$ttl=1,
|
||||
$widthForTicks=false
|
||||
) {
|
||||
global $config;
|
||||
global $graphic_type;
|
||||
|
||||
|
@ -3995,7 +4044,7 @@ function graph_graphic_moduleevents($id_agent, $id_module, $width, $height, $per
|
|||
[],
|
||||
true,
|
||||
$ttl,
|
||||
true
|
||||
$widthForTicks
|
||||
);
|
||||
|
||||
if ($return) {
|
||||
|
@ -4851,8 +4900,13 @@ function graphic_module_events($id_module, $width, $height, $period=0, $homeurl=
|
|||
}
|
||||
|
||||
|
||||
function graph_nodata_image($width=300, $height=110, $type='area', $text='')
|
||||
{
|
||||
function graph_nodata_image(
|
||||
$width=300,
|
||||
$height=110,
|
||||
$type='area',
|
||||
$text='',
|
||||
$percent=false
|
||||
) {
|
||||
$image = ui_get_full_url(
|
||||
'images/image_problem_area.png',
|
||||
false,
|
||||
|
@ -4860,14 +4914,20 @@ function graph_nodata_image($width=300, $height=110, $type='area', $text='')
|
|||
false
|
||||
);
|
||||
|
||||
// if ($text == '') {
|
||||
// $text = __('No data to show');
|
||||
// }
|
||||
$text_div = '<div class="nodata_text" style="text-align:center; padding: 30px 0; display:block; font-size:9.5pt;">'.$text.'</div>';
|
||||
$style = 'text-align:center; padding: 30px 0; display:block; font-size:9.5pt;';
|
||||
$text_div = '<div class="nodata_text" style="'.$style.'">';
|
||||
$text_div .= $text;
|
||||
$text_div .= '</div>';
|
||||
|
||||
$image_div = $text_div.'<div class="nodata_container" style="background-position: top; width:40%;height:40%;background-size: contain;background-image: url(\''.$image.'\');"><div></div></div>';
|
||||
$style = 'background-size: contain;background-image: url(\''.$image.'\');';
|
||||
$image_div = '<div class="nodata_container" style="'.$style.'"></div>';
|
||||
|
||||
$div = '<div style="width:'.$width.'px; height:'.$height.'px; background-color: white; margin: 0 auto;">'.$image_div.'</div>';
|
||||
if ($percent === true) {
|
||||
$div = $image_div;
|
||||
} else {
|
||||
$style = 'width:'.$width.'px; height:'.$height.'px; background-color: white; margin: 0 auto;';
|
||||
$div = '<div style="'.$style.'">'.$image_div.'</div>';
|
||||
}
|
||||
|
||||
return $div;
|
||||
}
|
||||
|
|
|
@ -1270,8 +1270,21 @@ function html_print_extended_select_for_cron($hour='*', $minute='*', $mday='*',
|
|||
*
|
||||
* @return string HTML code if return parameter is true.
|
||||
*/
|
||||
function html_print_input_text_extended($name, $value, $id, $alt, $size, $maxlength, $disabled, $script, $attributes, $return=false, $password=false, $function='', $autocomplete='off')
|
||||
{
|
||||
function html_print_input_text_extended(
|
||||
$name,
|
||||
$value,
|
||||
$id,
|
||||
$alt,
|
||||
$size,
|
||||
$maxlength,
|
||||
$disabled,
|
||||
$script,
|
||||
$attributes,
|
||||
$return=false,
|
||||
$password=false,
|
||||
$function='',
|
||||
$autocomplete='off'
|
||||
) {
|
||||
static $idcounter = 0;
|
||||
|
||||
if ($maxlength == 0) {
|
||||
|
@ -1288,6 +1301,7 @@ function html_print_input_text_extended($name, $value, $id, $alt, $size, $maxlen
|
|||
|
||||
$valid_attrs = [
|
||||
'accept',
|
||||
'autofocus',
|
||||
'disabled',
|
||||
'maxlength',
|
||||
'name',
|
||||
|
@ -1345,7 +1359,7 @@ function html_print_input_text_extended($name, $value, $id, $alt, $size, $maxlen
|
|||
$output .= 'alt="'.$alt.'" ';
|
||||
}
|
||||
|
||||
// Attributes specified by function call
|
||||
// Attributes specified by function call.
|
||||
$attrs = [
|
||||
'name' => 'unnamed',
|
||||
'value' => '',
|
||||
|
@ -1523,8 +1537,21 @@ function html_print_input_password(
|
|||
*
|
||||
* @return string HTML code if return parameter is true.
|
||||
*/
|
||||
function html_print_input_text($name, $value, $alt='', $size=50, $maxlength=255, $return=false, $disabled=false, $required=false, $function='', $class='', $onChange='', $autocomplete='')
|
||||
{
|
||||
function html_print_input_text(
|
||||
$name,
|
||||
$value,
|
||||
$alt='',
|
||||
$size=50,
|
||||
$maxlength=255,
|
||||
$return=false,
|
||||
$disabled=false,
|
||||
$required=false,
|
||||
$function='',
|
||||
$class='',
|
||||
$onChange='',
|
||||
$autocomplete='',
|
||||
$autofocus=false
|
||||
) {
|
||||
if ($maxlength == 0) {
|
||||
$maxlength = 255;
|
||||
}
|
||||
|
@ -1552,7 +1579,24 @@ function html_print_input_text($name, $value, $alt='', $size=50, $maxlength=255,
|
|||
$attr['autocomplete'] = $autocomplete;
|
||||
}
|
||||
|
||||
return html_print_input_text_extended($name, $value, 'text-'.$name, $alt, $size, $maxlength, $disabled, '', $attr, $return, false, $function);
|
||||
if ($autofocus === true) {
|
||||
$attr['autofocus'] = $autofocus;
|
||||
}
|
||||
|
||||
return html_print_input_text_extended(
|
||||
$name,
|
||||
$value,
|
||||
'text-'.$name,
|
||||
$alt,
|
||||
$size,
|
||||
$maxlength,
|
||||
$disabled,
|
||||
'',
|
||||
$attr,
|
||||
$return,
|
||||
false,
|
||||
$function
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1687,6 +1731,7 @@ function html_print_input_number(array $settings):string
|
|||
'autocomplete',
|
||||
'min',
|
||||
'max',
|
||||
'step',
|
||||
];
|
||||
|
||||
$output = '';
|
||||
|
@ -3466,7 +3511,8 @@ function html_print_input($data, $wrapper='div', $input_only=false)
|
|||
((isset($data['function']) === true) ? $data['function'] : ''),
|
||||
((isset($data['class']) === true) ? $data['class'] : ''),
|
||||
((isset($data['onChange']) === true) ? $data['onChange'] : ''),
|
||||
((isset($data['autocomplete']) === true) ? $data['autocomplete'] : '')
|
||||
((isset($data['autocomplete']) === true) ? $data['autocomplete'] : ''),
|
||||
((isset($data['autofocus']) === true) ? $data['autofocus'] : false)
|
||||
);
|
||||
break;
|
||||
|
||||
|
@ -3727,6 +3773,16 @@ function html_print_input($data, $wrapper='div', $input_only=false)
|
|||
$params['add_none_module'] = $data['module_none'];
|
||||
}
|
||||
|
||||
if (isset($data['size']) === true) {
|
||||
$params['size'] = $data['size'];
|
||||
}
|
||||
|
||||
if (isset($data['from_wux']) === true
|
||||
&& $data['from_wux'] === true
|
||||
) {
|
||||
$params['from_wux'] = 1;
|
||||
}
|
||||
|
||||
$params['use_hidden_input_idagent'] = true;
|
||||
$params['hidden_input_idagent_id'] = 'hidden-'.$data['name_agent_hidden'];
|
||||
if (is_metaconsole()) {
|
||||
|
@ -3766,6 +3822,10 @@ function html_print_input($data, $wrapper='div', $input_only=false)
|
|||
$string_filter = 'AND id_tipo_modulo IN (17,23,3,10,33,36)';
|
||||
}
|
||||
|
||||
if ($data['from_wux'] === true) {
|
||||
$string_filter = ' AND id_tipo_modulo = 25 ';
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT id_agente_modulo, nombre
|
||||
FROM tagente_modulo
|
||||
|
|
|
@ -437,7 +437,8 @@ function menu_print_menu(&$menu)
|
|||
$visible = false;
|
||||
}
|
||||
|
||||
$output .= '<ul id="subicon_'.$id.'" class="submenu'.($visible ? '' : ' invisible').'">';
|
||||
// $output .= '<ul id="subicon_'.$id.'" class="submenu'.($visible ? '' : ' invisible').'">';
|
||||
$output .= '<ul id="subicon_'.$id.'" class="submenu">';
|
||||
$output .= $submenu_output;
|
||||
$output .= '</ul>';
|
||||
}
|
||||
|
@ -521,8 +522,6 @@ function menu_add_extras(&$menu)
|
|||
$menu_extra['reporting']['sub']['enterprise/godmode/reporting/graph_template_item_editor']['text'] = __('Graph template items');
|
||||
$menu_extra['reporting']['sub']['enterprise/godmode/reporting/graph_template_wizard']['text'] = __('Graph template wizard');
|
||||
|
||||
$menu_extra['reporting']['sub']['enterprise/dashboard/dashboard_replicate']['text'] = __('Copy dashboard');
|
||||
|
||||
if ($config['activate_gis']) {
|
||||
$menu_extra['godgismaps']['sub']['godmode/gis_maps/configure_gis_map']['text'] = __('Manage GIS Maps');
|
||||
}
|
||||
|
|
|
@ -829,7 +829,7 @@ function reporting_make_reporting_data(
|
|||
break;
|
||||
|
||||
case 'module_histogram_graph':
|
||||
$report['contents'][] = reporting_enterprise_module_histogram_graph(
|
||||
$report['contents'][] = reporting_module_histogram_graph(
|
||||
$report,
|
||||
$content,
|
||||
$pdf
|
||||
|
@ -12346,3 +12346,327 @@ function reporting_nt_top_n_report($period, $content, $pdf)
|
|||
);
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Will display an hourly analysis of the selected period.
|
||||
*
|
||||
* @param array $report Info report.
|
||||
* @param array $content Info contents.
|
||||
* @param boolean $pdf If pdf.
|
||||
*
|
||||
* @return html
|
||||
*/
|
||||
function reporting_module_histogram_graph($report, $content, $pdf=0)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$metaconsole_on = is_metaconsole();
|
||||
|
||||
$return = [];
|
||||
|
||||
$urlImage = ui_get_full_url(false, true, false, false);
|
||||
|
||||
$return['type'] = 'module_histogram_graph';
|
||||
|
||||
$ttl = 1;
|
||||
if ($pdf) {
|
||||
$ttl = 2;
|
||||
}
|
||||
|
||||
if (empty($content['name'])) {
|
||||
$content['name'] = __('Module Histogram Graph');
|
||||
}
|
||||
|
||||
$server_name = $content['server_name'];
|
||||
// Metaconsole connection.
|
||||
if ($metaconsole_on && $server_name != '') {
|
||||
$connection = metaconsole_get_connection($server_name);
|
||||
if (!metaconsole_load_external_db($connection)) {
|
||||
ui_print_error_message('Error connecting to '.$server_name);
|
||||
}
|
||||
}
|
||||
|
||||
$module_name = io_safe_output(
|
||||
modules_get_agentmodule_name(
|
||||
$content['id_agent_module']
|
||||
)
|
||||
);
|
||||
$agent_name = io_safe_output(
|
||||
modules_get_agentmodule_agent_alias(
|
||||
$content['id_agent_module']
|
||||
)
|
||||
);
|
||||
|
||||
$return['title'] = $content['name'];
|
||||
$return['landscape'] = $content['landscape'];
|
||||
$return['pagebreak'] = $content['pagebreak'];
|
||||
$return['subtitle'] = $agent_name.' - '.$module_name;
|
||||
$return['description'] = $content['description'];
|
||||
$return['date'] = reporting_get_date_text(
|
||||
$report,
|
||||
$content
|
||||
);
|
||||
|
||||
if (modules_is_disable_agent($content['id_agent_module'])
|
||||
|| modules_is_not_init($content['id_agent_module'])
|
||||
) {
|
||||
if ($metaconsole_on) {
|
||||
// Restore db connection.
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$uncompress_module = db_uncompress_module_data(
|
||||
$content['id_agent_module'],
|
||||
($report['datetime'] - $content['period']),
|
||||
$report['datetime']
|
||||
);
|
||||
|
||||
// Select Warning and critical values.
|
||||
$agentmodule_info = modules_get_agentmodule($content['id_agent_module']);
|
||||
$min_value_critical = ($agentmodule_info['min_critical'] == 0) ? null : $agentmodule_info['min_critical'];
|
||||
|
||||
// Check if module type is string.
|
||||
$modules_is_string = modules_is_string($agentmodule_info['id_agente_modulo']);
|
||||
|
||||
if ($modules_is_string === false) {
|
||||
if ($agentmodule_info['max_critical'] == 0) {
|
||||
$max_value_critical = null;
|
||||
} else {
|
||||
$max_value_critical = $agentmodule_info['max_critical'];
|
||||
}
|
||||
} else {
|
||||
if ($agentmodule_info['str_critical'] == '') {
|
||||
$max_value_critical = null;
|
||||
} else {
|
||||
$max_value_critical = $agentmodule_info['str_critical'];
|
||||
}
|
||||
}
|
||||
|
||||
$inverse_critical = $agentmodule_info['critical_inverse'];
|
||||
|
||||
$min_value_warning = ($agentmodule_info['min_warning'] == 0) ? null : $agentmodule_info['min_warning'];
|
||||
|
||||
if ($modules_is_string === false) {
|
||||
if ($agentmodule_info['max_warning'] == 0) {
|
||||
$max_value_warning = null;
|
||||
} else {
|
||||
$max_value_warning = $agentmodule_info['max_warning'];
|
||||
}
|
||||
} else {
|
||||
if ($agentmodule_info['str_warning'] == '') {
|
||||
$max_value_warning = null;
|
||||
} else {
|
||||
$max_value_warning = $agentmodule_info['str_warning'];
|
||||
}
|
||||
}
|
||||
|
||||
$inverse_warning = $agentmodule_info['warning_inverse'];
|
||||
|
||||
// Initialize vars.
|
||||
$tstart = 0;
|
||||
$tend = 0;
|
||||
$tacum = 0;
|
||||
$tacum_data = 0;
|
||||
|
||||
$array_graph = [];
|
||||
|
||||
$data_not_init = 0;
|
||||
$data_unknown = 0;
|
||||
$data_critical = 0;
|
||||
$data_warning = 0;
|
||||
$data_ok = 0;
|
||||
$data_total = 0;
|
||||
|
||||
$time_not_init = 0;
|
||||
$time_unknown = 0;
|
||||
$time_critical = 0;
|
||||
$time_warning = 0;
|
||||
$time_ok = 0;
|
||||
|
||||
$legend = [];
|
||||
foreach ($uncompress_module as $data) {
|
||||
foreach ($data['data'] as $key => $value) {
|
||||
if ($tacum == 0) {
|
||||
// Initialize the accumulators.
|
||||
$tacum = $value['utimestamp'];
|
||||
$tacum_data = $value['datos'];
|
||||
} else {
|
||||
// Utimestand end and final.
|
||||
$tstart = $tacum;
|
||||
$tend = $value['utimestamp'];
|
||||
|
||||
// Module type isn't string.
|
||||
$sla_check_value_critical = sla_check_value(
|
||||
$tacum_data,
|
||||
$min_value_critical,
|
||||
$max_value_critical,
|
||||
$inverse_critical
|
||||
);
|
||||
$sla_check_value_warning = sla_check_value(
|
||||
$tacum_data,
|
||||
$min_value_warning,
|
||||
$max_value_warning,
|
||||
$inverse_warning
|
||||
);
|
||||
|
||||
// Module type is string.
|
||||
$string_check_value_critical = preg_match('/'.$max_value_critical.'/', $tacum_data);
|
||||
$string_check_value_warning = preg_match('/'.$max_value_warning.'/', $tacum_data);
|
||||
|
||||
if ($inverse_critical) {
|
||||
$string_check_value_critical = !preg_match('/'.$max_value_critical.'/', $tacum_data);
|
||||
}
|
||||
|
||||
if ($string_check_value_warning) {
|
||||
$string_check_value_warning = !preg_match('/'.$max_value_warning.'/', $tacum_data);
|
||||
}
|
||||
|
||||
// Contruct array period and data.
|
||||
if ($tacum_data === false) {
|
||||
$array_graph[$data_total]['data'] = AGENT_MODULE_STATUS_NOT_INIT;
|
||||
// NOT INIT.
|
||||
$time_not_init = ($time_not_init + ($tend - $tstart));
|
||||
$data_not_init ++;
|
||||
} else if ($tacum_data === null) {
|
||||
$array_graph[$data_total]['data'] = AGENT_MODULE_STATUS_UNKNOWN;
|
||||
// UNKNOWN.
|
||||
$time_unknown = ($time_unknown + ($tend - $tstart));
|
||||
$data_unknown ++;
|
||||
} else if (( (isset($min_value_critical) || isset($max_value_critical)) && ($modules_is_string === false) && ($sla_check_value_critical == true) )
|
||||
|| ( isset($max_value_critical) && ($modules_is_string === true) && $string_check_value_critical )
|
||||
) {
|
||||
$array_graph[$data_total]['data'] = AGENT_MODULE_STATUS_CRITICAL_BAD;
|
||||
// CRITICAL.
|
||||
$time_critical = ($time_critical + ($tend - $tstart));
|
||||
$data_critical ++;
|
||||
} else if (( (isset($min_value_warning) || isset($max_value_warning)) && ($modules_is_string === false) && ($sla_check_value_warning == true) )
|
||||
|| ( isset($max_value_warning) && ($modules_is_string === true) && $sla_check_value_warning )
|
||||
) {
|
||||
$array_graph[$data_total]['data'] = AGENT_MODULE_STATUS_WARNING;
|
||||
// WARNING.
|
||||
$time_warning = ($time_warning + ($tend - $tstart));
|
||||
$data_warning ++;
|
||||
} else {
|
||||
$array_graph[$data_total]['data'] = AGENT_MODULE_STATUS_NORMAL;
|
||||
// OK.
|
||||
$time_ok = ($time_ok + ($tend - $tstart));
|
||||
$data_ok ++;
|
||||
}
|
||||
|
||||
$array_graph[$data_total]['utimestamp'] = ($tend - $tstart);
|
||||
$array_graph[$data_total]['real_data'] = $tacum_data;
|
||||
|
||||
// Reassign accumulators.
|
||||
$tacum = $value['utimestamp'];
|
||||
$tacum_data = $value['datos'];
|
||||
$data_total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data_init = -1;
|
||||
$acum = 0;
|
||||
$sum = 0;
|
||||
$array_result = [];
|
||||
$i = 0;
|
||||
foreach ($array_graph as $key => $value) {
|
||||
if ($data_init == -1) {
|
||||
$data_init = $value['data'];
|
||||
$acum = $value['utimestamp'];
|
||||
} else {
|
||||
if ($data_init == $value['data']) {
|
||||
$acum = ($acum + $value['utimestamp']);
|
||||
if ($modules_is_string === false) {
|
||||
$sum = ($sum + $value['real_data']);
|
||||
} else {
|
||||
$sum = $value['real_data'];
|
||||
}
|
||||
} else {
|
||||
$array_result[$i]['data'] = $data_init;
|
||||
$array_result[$i]['utimestamp'] = $acum;
|
||||
$array_result[$i]['real_data'] = $sum;
|
||||
$i++;
|
||||
$data_init = $value['data'];
|
||||
$acum = $value['utimestamp'];
|
||||
$sum = $value['real_data'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($array_result) == 0) {
|
||||
$array_result = $array_graph;
|
||||
} else {
|
||||
$array_result[$i]['data'] = $data_init;
|
||||
$array_result[$i]['utimestamp'] = $acum;
|
||||
$array_result[$i]['real_data'] = $sum;
|
||||
}
|
||||
|
||||
$time_total = ($time_not_init + $time_unknown + $time_critical + $time_warning + $time_ok);
|
||||
// Slice graphs calculation.
|
||||
$return['agent'] = modules_get_agentmodule_agent_alias(
|
||||
$content['id_agent_module']
|
||||
);
|
||||
$return['module'] = modules_get_agentmodule_name(
|
||||
$content['id_agent_module']
|
||||
);
|
||||
$return['max_critical'] = $max_value_critical;
|
||||
$return['min_critical'] = $min_value_critical;
|
||||
$return['critical_inverse'] = $inverse_critical;
|
||||
$return['max_warning'] = $max_value_warning;
|
||||
$return['min_warning'] = $min_value_warning;
|
||||
$return['warning_inverse'] = $inverse_warning;
|
||||
$return['data_not_init'] = $data_not_init;
|
||||
$return['data_unknown'] = $data_unknown;
|
||||
$return['data_critical'] = $data_critical;
|
||||
$return['data_warning'] = $data_warning;
|
||||
$return['data_ok'] = $data_ok;
|
||||
$return['data_total'] = $data_total;
|
||||
$return['time_not_init'] = $time_not_init;
|
||||
$return['time_unknown'] = $time_unknown;
|
||||
$return['time_critical'] = $time_critical;
|
||||
$return['time_warning'] = $time_warning;
|
||||
$return['time_ok'] = $time_ok;
|
||||
$return['percent_ok'] = (($data_ok * 100) / $data_total);
|
||||
|
||||
$colors = [
|
||||
AGENT_MODULE_STATUS_NORMAL => COL_NORMAL,
|
||||
AGENT_MODULE_STATUS_WARNING => COL_WARNING,
|
||||
AGENT_MODULE_STATUS_CRITICAL_BAD => COL_CRITICAL,
|
||||
AGENT_MODULE_STATUS_UNKNOWN => COL_UNKNOWN,
|
||||
AGENT_MODULE_STATUS_NOT_INIT => COL_NOTINIT,
|
||||
];
|
||||
|
||||
$width_graph = 100;
|
||||
$height_graph = 80;
|
||||
$return['chart'] = flot_slicesbar_graph(
|
||||
$array_result,
|
||||
$time_total,
|
||||
$width_graph,
|
||||
$height_graph,
|
||||
$legend,
|
||||
$colors,
|
||||
$config['fontpath'],
|
||||
$config['round_corner'],
|
||||
$homeurl,
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
0,
|
||||
[],
|
||||
true,
|
||||
$ttl,
|
||||
$content['sizeForTicks'],
|
||||
true
|
||||
);
|
||||
|
||||
if ($metaconsole_on) {
|
||||
// Restore db connection.
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
|
||||
return reporting_check_structure_content($return);
|
||||
}
|
||||
|
|
|
@ -769,13 +769,28 @@ function treeview_printTable($id_agente, $server_data=[], $no_head=false)
|
|||
|
||||
if ($config['agentaccess']) {
|
||||
$access_graph = '<div style="width:100%; height:130px;">';
|
||||
$access_graph .= graphic_agentaccess($id_agente, 380, 120, SECONDS_1DAY, true, true);
|
||||
$access_graph .= graphic_agentaccess(
|
||||
$id_agente,
|
||||
SECONDS_1DAY,
|
||||
true
|
||||
);
|
||||
$access_graph .= '</div>';
|
||||
ui_toggle($access_graph, __('Agent access rate (24h)'));
|
||||
}
|
||||
|
||||
$events_graph = '<div style="margin-left:10px; width:100%;">';
|
||||
$events_graph .= graph_graphic_agentevents($id_agente, 375, 45, SECONDS_1DAY, '', true, false, true, $server_id);
|
||||
$events_graph = '<div style="width: 100%; height: 90px; display: flex; flex-direction: row; justify-content: center;">';
|
||||
$events_graph .= graph_graphic_agentevents(
|
||||
$id_agente,
|
||||
'385px;',
|
||||
45,
|
||||
SECONDS_1DAY,
|
||||
'',
|
||||
true,
|
||||
false,
|
||||
550,
|
||||
1,
|
||||
$server_id
|
||||
);
|
||||
$events_graph .= '</div><br>';
|
||||
|
||||
ui_toggle($events_graph, __('Events (24h)'));
|
||||
|
|
|
@ -1451,12 +1451,17 @@ function ui_print_help_icon(
|
|||
*
|
||||
* @return boolean True if the file was added. False if the file doesn't exist.
|
||||
*/
|
||||
function ui_require_css_file($name, $path='include/styles/')
|
||||
function ui_require_css_file($name, $path='include/styles/', $echo_tag=false)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$filename = $path.$name.'.css';
|
||||
|
||||
if ($echo_tag === true) {
|
||||
echo '<link type="text/css" rel="stylesheet" href="'.ui_get_full_url($filename, false, false, false).'">';
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! isset($config['css'])) {
|
||||
$config['css'] = [];
|
||||
}
|
||||
|
@ -1678,7 +1683,7 @@ function ui_process_page_head($string, $bitfield)
|
|||
|| $_GET['sec2'] == 'operation/agentes/group_view'
|
||||
|| $_GET['sec2'] == 'operation/events/events'
|
||||
|| $_GET['sec2'] == 'operation/snmpconsole/snmp_view'
|
||||
|| $_GET['sec2'] == 'enterprise/dashboard/main_dashboard'
|
||||
|| $_GET['sec2'] == 'operation/dashboard/dashboard'
|
||||
) {
|
||||
$query = ui_get_url_refresh(false, false);
|
||||
|
||||
|
|
|
@ -1025,11 +1025,13 @@ function visual_map_print_item(
|
|||
$params_combined
|
||||
).'</div>';
|
||||
} else {
|
||||
$img = graphic_combined_module(
|
||||
$img = '<div style="width:'.$width.'px; height:'.$height.'px;">';
|
||||
$img .= graphic_combined_module(
|
||||
false,
|
||||
$params,
|
||||
$params_combined
|
||||
);
|
||||
$img .= '</div>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1223,7 +1225,16 @@ function visual_map_print_item(
|
|||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
|
||||
$module_data = get_bars_module_data($id_module);
|
||||
$module_data = get_bars_module_data(
|
||||
$id_module,
|
||||
($layoutData['type_graph'] !== 'horizontal')
|
||||
);
|
||||
$options = [];
|
||||
$options['generals']['rotate'] = true;
|
||||
$options['generals']['forceTicks'] = true;
|
||||
$options['generals']['arrayColors'] = $color;
|
||||
$options['x']['labelWidth'] = 60;
|
||||
|
||||
$water_mark = [
|
||||
'file' => '/var/www/html/pandora_console/images/logo_vertical_water.png',
|
||||
'url' => 'http://localhost/pandora_console/images/logo_vertical_water.png',
|
||||
|
@ -1252,27 +1263,9 @@ function visual_map_print_item(
|
|||
$layoutData['border_color']
|
||||
).'</div>';
|
||||
} else {
|
||||
$img = '<div style="float:right;height:'.$himg.'px;">'.vbar_graph(
|
||||
$module_data,
|
||||
400,
|
||||
400,
|
||||
$color,
|
||||
[],
|
||||
[],
|
||||
ui_get_full_url('images/image_problem_area.png', false, false, false),
|
||||
'',
|
||||
'',
|
||||
$water_mark,
|
||||
$config['fontpath'],
|
||||
6,
|
||||
'',
|
||||
0,
|
||||
$config['homeurl'],
|
||||
$layoutData['image'],
|
||||
true,
|
||||
false,
|
||||
$layoutData['border_color']
|
||||
).'</div>';
|
||||
$img = '<div style="float:right;height:'.$himg.'px;">';
|
||||
$img .= vbar_graph($module_data, $options, 1);
|
||||
$img .= '</div>';
|
||||
}
|
||||
} else if ($layoutData['label_position'] == 'right') {
|
||||
if ($layoutData['type_graph'] == 'horizontal') {
|
||||
|
@ -1296,27 +1289,9 @@ function visual_map_print_item(
|
|||
$layoutData['border_color']
|
||||
).'</div>';
|
||||
} else {
|
||||
$img = '<div style="float:left;height:'.$himg.'px;">'.vbar_graph(
|
||||
$module_data,
|
||||
400,
|
||||
400,
|
||||
$color,
|
||||
[],
|
||||
[],
|
||||
ui_get_full_url('images/image_problem_area.png', false, false, false),
|
||||
'',
|
||||
'',
|
||||
$water_mark,
|
||||
$config['fontpath'],
|
||||
6,
|
||||
'',
|
||||
0,
|
||||
$config['homeurl'],
|
||||
$layoutData['image'],
|
||||
true,
|
||||
false,
|
||||
$layoutData['border_color']
|
||||
).'</div>';
|
||||
$img = '<div style="float:left;height:'.$himg.'px;">';
|
||||
$img .= vbar_graph($module_data, $options, 1);
|
||||
$img .= '</div>';
|
||||
}
|
||||
} else {
|
||||
if ($layoutData['type_graph'] == 'horizontal') {
|
||||
|
@ -1340,27 +1315,7 @@ function visual_map_print_item(
|
|||
$layoutData['border_color']
|
||||
);
|
||||
} else {
|
||||
$img = vbar_graph(
|
||||
$module_data,
|
||||
400,
|
||||
400,
|
||||
$color,
|
||||
[],
|
||||
[],
|
||||
ui_get_full_url('images/image_problem_area.png', false, false, false),
|
||||
'',
|
||||
'',
|
||||
$water_mark,
|
||||
$config['fontpath'],
|
||||
6,
|
||||
'',
|
||||
0,
|
||||
$config['homeurl'],
|
||||
$layoutData['image'],
|
||||
true,
|
||||
false,
|
||||
$layoutData['border_color']
|
||||
);
|
||||
$img = vbar_graph($module_data, $options, 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1386,27 +1341,9 @@ function visual_map_print_item(
|
|||
$layoutData['border_color']
|
||||
).'</div>';
|
||||
} else {
|
||||
$img = '<div style="float:right;height:'.$himg.'px;">'.vbar_graph(
|
||||
$module_data,
|
||||
$width,
|
||||
$height,
|
||||
$color,
|
||||
[],
|
||||
[],
|
||||
ui_get_full_url('images/image_problem_area.png', false, false, false),
|
||||
'',
|
||||
'',
|
||||
$water_mark,
|
||||
$config['fontpath'],
|
||||
6,
|
||||
'',
|
||||
0,
|
||||
$config['homeurl'],
|
||||
$layoutData['image'],
|
||||
true,
|
||||
false,
|
||||
$layoutData['border_color']
|
||||
).'</div>';
|
||||
$img = '<div style="float:right;height:'.$himg.'px;">';
|
||||
$img .= vbar_graph($module_data, $options, 1);
|
||||
$img .= '</div>';
|
||||
}
|
||||
} else if ($layoutData['label_position'] == 'right') {
|
||||
if ($layoutData['type_graph'] == 'horizontal') {
|
||||
|
@ -1430,27 +1367,9 @@ function visual_map_print_item(
|
|||
$layoutData['border_color']
|
||||
).'</div>';
|
||||
} else {
|
||||
$img = '<div style="float:left;height:'.$himg.'px;">'.vbar_graph(
|
||||
$module_data,
|
||||
$width,
|
||||
$height,
|
||||
$color,
|
||||
[],
|
||||
[],
|
||||
ui_get_full_url('images/image_problem_area.png', false, false, false),
|
||||
'',
|
||||
'',
|
||||
$water_mark,
|
||||
$config['fontpath'],
|
||||
6,
|
||||
'',
|
||||
0,
|
||||
$config['homeurl'],
|
||||
$layoutData['image'],
|
||||
true,
|
||||
false,
|
||||
$layoutData['border_color']
|
||||
).'</div>';
|
||||
$img = '<div style="float:left;height:'.$himg.'px;">';
|
||||
$img .= vbar_graph($module_data, $options, 1);
|
||||
$img .= '</div>';
|
||||
}
|
||||
} else {
|
||||
if ($layoutData['type_graph'] == 'horizontal') {
|
||||
|
@ -1474,27 +1393,9 @@ function visual_map_print_item(
|
|||
$layoutData['border_color']
|
||||
);
|
||||
} else {
|
||||
$img = vbar_graph(
|
||||
$module_data,
|
||||
$width,
|
||||
$height,
|
||||
$color,
|
||||
[],
|
||||
[],
|
||||
ui_get_full_url('images/image_problem_area.png', false, false, false),
|
||||
'',
|
||||
'',
|
||||
$water_mark,
|
||||
$config['fontpath'],
|
||||
6,
|
||||
'',
|
||||
0,
|
||||
$config['homeurl'],
|
||||
$layoutData['image'],
|
||||
true,
|
||||
false,
|
||||
$layoutData['border_color']
|
||||
);
|
||||
$img = '<div style="width:'.$width.'px; height:'.$height.'px;">';
|
||||
$img .= vbar_graph($module_data, $options, 1);
|
||||
$img .= '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2443,7 +2344,7 @@ function get_if_module_is_image($id_module)
|
|||
}
|
||||
|
||||
|
||||
function get_bars_module_data($id_module)
|
||||
function get_bars_module_data($id_module, $vBars=false)
|
||||
{
|
||||
// This charts is only serialize graphs.
|
||||
// In other string show image no data to show.
|
||||
|
@ -2472,9 +2373,19 @@ function get_bars_module_data($id_module)
|
|||
return false;
|
||||
}
|
||||
|
||||
foreach ($values as $val) {
|
||||
$data = explode(',', $val);
|
||||
$values_to_return[$data[0]] = ['g' => $data[1]];
|
||||
if ($vBars === false) {
|
||||
foreach ($values as $val) {
|
||||
$data = explode(',', $val);
|
||||
$values_to_return[$data[0]] = ['g' => $data[1]];
|
||||
}
|
||||
} else {
|
||||
foreach ($values as $val) {
|
||||
$data = explode(',', $val);
|
||||
$values_to_return[] = [
|
||||
'tick' => $data[0],
|
||||
'data' => $data[1],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $values_to_return;
|
||||
|
|
|
@ -149,75 +149,404 @@ function progressbar(
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw vertical bars graph.
|
||||
*
|
||||
* @param array $data Data chart.
|
||||
* @param array $params Params draw chart.
|
||||
* @param integer $ttl Pdf option.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function vbar_graph(
|
||||
$chart_data,
|
||||
$width,
|
||||
$height,
|
||||
$color,
|
||||
$legend,
|
||||
$long_index,
|
||||
$no_data_image,
|
||||
$xaxisname='',
|
||||
$yaxisname='',
|
||||
$water_mark='',
|
||||
$font='',
|
||||
$font_size='',
|
||||
$unit='',
|
||||
$ttl=1,
|
||||
$homeurl='',
|
||||
$backgroundColor='white',
|
||||
$from_ux=false,
|
||||
$from_wux=false,
|
||||
$tick_color='white',
|
||||
$base64=false
|
||||
array $data,
|
||||
array $options,
|
||||
int $ttl=1
|
||||
) {
|
||||
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
|
||||
global $config;
|
||||
|
||||
if (empty($chart_data)) {
|
||||
return graph_nodata_image($width, $height, 'vbar');
|
||||
// INFO IN: https://github.com/flot/flot/blob/master/API.md.
|
||||
// Xaxes chart Title.
|
||||
if (isset($options['x']['title']['title']) === false) {
|
||||
$options['x']['title']['title'] = '';
|
||||
}
|
||||
|
||||
if ($ttl == 2) {
|
||||
$params = [
|
||||
'chart_data' => $chart_data,
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
'color' => $color,
|
||||
'legend' => $legend,
|
||||
'long_index' => $long_index,
|
||||
'homeurl' => $homeurl,
|
||||
'unit' => $unit,
|
||||
'water_mark_url' => $water_mark_url,
|
||||
'homedir' => $homedir,
|
||||
'font' => $font,
|
||||
'font_size' => $font_size,
|
||||
'from_ux' => $from_ux,
|
||||
'from_wux' => $from_wux,
|
||||
'backgroundColor' => $backgroundColor,
|
||||
'tick_color' => $tick_color,
|
||||
'return_img_base_64' => $base64,
|
||||
if (isset($options['x']['title']['fontSize']) === false) {
|
||||
$options['x']['title']['fontSize'] = ((int) $config['font_size'] + 2);
|
||||
}
|
||||
|
||||
if (isset($options['x']['title']['fontFamily']) === false) {
|
||||
$options['x']['title']['fontFamily'] = preg_replace(
|
||||
'/.ttf/',
|
||||
'Font, Arial',
|
||||
$config['fontpath']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($options['x']['title']['padding']) === false) {
|
||||
$options['x']['title']['padding'] = 10;
|
||||
}
|
||||
|
||||
// Xaxes font ticks.
|
||||
if (isset($options['x']['font']['size']) === false) {
|
||||
$options['x']['font']['size'] = ((int) $config['font_size'] + 2);
|
||||
}
|
||||
|
||||
if (isset($options['x']['font']['lineHeight']) === false) {
|
||||
$options['x']['font']['lineHeight'] = ((int) $config['font_size'] + 2);
|
||||
}
|
||||
|
||||
if (isset($options['x']['font']['style']) === false) {
|
||||
$options['x']['font']['style'] = 'normal';
|
||||
}
|
||||
|
||||
if (isset($options['x']['font']['weight']) === false) {
|
||||
$options['x']['font']['weight'] = 'normal';
|
||||
}
|
||||
|
||||
if (isset($options['x']['font']['family']) === false) {
|
||||
$options['x']['font']['family'] = preg_replace(
|
||||
'/.ttf/',
|
||||
'Font',
|
||||
$config['fontpath']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($options['x']['font']['variant']) === false) {
|
||||
$options['x']['font']['variant'] = 'small-caps';
|
||||
}
|
||||
|
||||
if (isset($options['x']['font']['color']) === false) {
|
||||
$options['x']['font']['color'] = '#545454';
|
||||
}
|
||||
|
||||
// Show ticks.
|
||||
if (isset($options['x']['show']) === false) {
|
||||
$options['x']['show'] = true;
|
||||
}
|
||||
|
||||
// Type position bottom or top or left or right.
|
||||
if (isset($options['x']['position']) === false) {
|
||||
$options['x']['position'] = 'bottom';
|
||||
}
|
||||
|
||||
// Grid color axes x.
|
||||
if (isset($options['x']['color']) === false) {
|
||||
$options['x']['color'] = '#ffffff';
|
||||
}
|
||||
|
||||
if (isset($options['x']['labelWidth']) === false) {
|
||||
$options['x']['labelWidth'] = null;
|
||||
}
|
||||
|
||||
if (isset($options['x']['labelHeight']) === false) {
|
||||
$options['x']['labelHeight'] = null;
|
||||
}
|
||||
|
||||
// Yaxes chart Title.
|
||||
if (isset($options['y']['title']['title']) === false) {
|
||||
$options['y']['title']['title'] = '';
|
||||
}
|
||||
|
||||
if (isset($options['y']['title']['fontSize']) === false) {
|
||||
$options['y']['title']['fontSize'] = ((int) $config['font_size'] + 2);
|
||||
}
|
||||
|
||||
if (isset($options['y']['title']['fontFamily']) === false) {
|
||||
$options['y']['title']['fontFamily'] = preg_replace(
|
||||
'/.ttf/',
|
||||
'Font, Arial',
|
||||
$config['fontpath']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($options['y']['title']['padding']) === false) {
|
||||
$options['y']['title']['padding'] = 10;
|
||||
}
|
||||
|
||||
// Yaxes font ticks.
|
||||
if (isset($options['y']['font']['size']) === false) {
|
||||
$options['y']['font']['size'] = ((int) $config['font_size'] + 2);
|
||||
}
|
||||
|
||||
if (isset($options['y']['font']['lineHeight']) === false) {
|
||||
$options['y']['font']['lineHeight'] = ((int) $config['font_size'] + 2);
|
||||
}
|
||||
|
||||
if (isset($options['y']['font']['style']) === false) {
|
||||
$options['y']['font']['style'] = 'normal';
|
||||
}
|
||||
|
||||
if (isset($options['y']['font']['weight']) === false) {
|
||||
$options['y']['font']['weight'] = 'normal';
|
||||
}
|
||||
|
||||
if (isset($options['y']['font']['family']) === false) {
|
||||
$options['y']['font']['family'] = preg_replace(
|
||||
'/.ttf/',
|
||||
'Font',
|
||||
$config['fontpath']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($options['y']['font']['variant']) === false) {
|
||||
$options['y']['font']['variant'] = 'small-caps';
|
||||
}
|
||||
|
||||
if (isset($options['y']['font']['color']) === false) {
|
||||
$options['y']['font']['color'] = '#545454';
|
||||
}
|
||||
|
||||
// Show ticks.
|
||||
if (isset($options['y']['show']) === false) {
|
||||
$options['y']['show'] = true;
|
||||
}
|
||||
|
||||
// Type position bottom or top or left or right.
|
||||
if (isset($options['y']['position']) === false) {
|
||||
$options['y']['position'] = 'left';
|
||||
}
|
||||
|
||||
// Grid color axes y.
|
||||
if (isset($options['y']['color']) === false) {
|
||||
$options['y']['color'] = '#ffffff';
|
||||
}
|
||||
|
||||
if (isset($options['y']['labelWidth']) === false) {
|
||||
$options['y']['labelWidth'] = null;
|
||||
}
|
||||
|
||||
if (isset($options['y']['labelHeight']) === false) {
|
||||
$options['y']['labelHeight'] = null;
|
||||
}
|
||||
|
||||
// Bars options.
|
||||
// left, right or center.
|
||||
if (isset($options['bars']['align']) === false) {
|
||||
$options['bars']['align'] = 'center';
|
||||
}
|
||||
|
||||
if (isset($options['bars']['barWidth']) === false) {
|
||||
$options['bars']['barWidth'] = 0.8;
|
||||
}
|
||||
|
||||
if (isset($options['bars']['horizontal']) === false) {
|
||||
$options['bars']['horizontal'] = false;
|
||||
}
|
||||
|
||||
// Grid Options.
|
||||
if (isset($options['grid']['show']) === false) {
|
||||
$options['grid']['show'] = true;
|
||||
}
|
||||
|
||||
if (isset($options['grid']['aboveData']) === false) {
|
||||
$options['grid']['aboveData'] = false;
|
||||
}
|
||||
|
||||
if (isset($options['grid']['color']) === false) {
|
||||
$options['grid']['color'] = '#ffffff';
|
||||
}
|
||||
|
||||
if (isset($options['grid']['backgroundColor']) === false) {
|
||||
$options['grid']['backgroundColor'] = [
|
||||
'colors' => [
|
||||
'#ffffff',
|
||||
'#ffffff',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($options['grid']['margin']) === false) {
|
||||
$options['grid']['margin'] = 0;
|
||||
}
|
||||
|
||||
if (isset($options['grid']['labelMargin']) === false) {
|
||||
$options['grid']['labelMargin'] = 5;
|
||||
}
|
||||
|
||||
if (isset($options['grid']['axisMargin']) === false) {
|
||||
$options['grid']['axisMargin'] = 5;
|
||||
}
|
||||
|
||||
if (isset($options['grid']['markings']) === false) {
|
||||
$options['grid']['markings'] = [];
|
||||
}
|
||||
|
||||
if (isset($options['grid']['borderWidth']) === false) {
|
||||
$options['grid']['borderWidth'] = 0;
|
||||
}
|
||||
|
||||
if (isset($options['grid']['borderColor']) === false) {
|
||||
$options['grid']['borderColor'] = '#ffffff';
|
||||
}
|
||||
|
||||
if (isset($options['grid']['minBorderMargin']) === false) {
|
||||
$options['grid']['minBorderMargin'] = 5;
|
||||
}
|
||||
|
||||
if (isset($options['grid']['clickable']) === false) {
|
||||
$options['grid']['clickable'] = false;
|
||||
}
|
||||
|
||||
if (isset($options['grid']['hoverable']) === false) {
|
||||
$options['grid']['hoverable'] = false;
|
||||
}
|
||||
|
||||
if (isset($options['grid']['autoHighlight']) === false) {
|
||||
$options['grid']['autoHighlight'] = false;
|
||||
}
|
||||
|
||||
if (isset($options['grid']['mouseActiveRadius']) === false) {
|
||||
$options['grid']['mouseActiveRadius'] = false;
|
||||
}
|
||||
|
||||
// Series bars.
|
||||
if (isset($options['seriesBars']['show']) === false) {
|
||||
$options['seriesBars']['show'] = true;
|
||||
}
|
||||
|
||||
if (isset($options['seriesBars']['lineWidth']) === false) {
|
||||
$options['seriesBars']['lineWidth'] = 0.3;
|
||||
}
|
||||
|
||||
if (isset($options['seriesBars']['fill']) === false) {
|
||||
$options['seriesBars']['fill'] = true;
|
||||
}
|
||||
|
||||
if (isset($options['seriesBars']['fillColor']) === false) {
|
||||
$options['seriesBars']['fillColor'] = [
|
||||
'colors' => [
|
||||
[ 'opacity' => 0.9 ],
|
||||
[ 'opacity' => 0.9 ],
|
||||
],
|
||||
];
|
||||
};
|
||||
|
||||
// Generals options.
|
||||
if (isset($options['generals']['unit']) === false) {
|
||||
$options['generals']['unit'] = '';
|
||||
}
|
||||
|
||||
if (isset($options['generals']['divisor']) === false) {
|
||||
$options['generals']['divisor'] = 1000;
|
||||
}
|
||||
|
||||
if (isset($options['generals']['forceTicks']) === false) {
|
||||
$options['generals']['forceTicks'] = false;
|
||||
}
|
||||
|
||||
if (isset($options['generals']['arrayColors']) === false) {
|
||||
$options['generals']['arrayColors'] = false;
|
||||
}
|
||||
|
||||
if (isset($options['generals']['rotate']) === false) {
|
||||
$options['generals']['rotate'] = false;
|
||||
}
|
||||
|
||||
if (isset($options['generals']['pdf']['width']) === false) {
|
||||
$options['generals']['pdf']['width'] = false;
|
||||
}
|
||||
|
||||
if (isset($options['generals']['pdf']['height']) === false) {
|
||||
$options['generals']['pdf']['height'] = false;
|
||||
}
|
||||
|
||||
$params = [
|
||||
'data' => $data,
|
||||
'x' => [
|
||||
'title' => [
|
||||
'title' => $options['x']['title']['title'],
|
||||
'fontSize' => $options['x']['title']['fontSize'],
|
||||
'fontFamily' => $options['x']['title']['fontFamily'],
|
||||
'padding' => $options['x']['title']['padding'],
|
||||
],
|
||||
'font' => [
|
||||
'size' => $options['x']['font']['size'],
|
||||
'lineHeight' => $options['x']['font']['lineHeight'],
|
||||
'style' => $options['x']['font']['style'],
|
||||
'weight' => $options['x']['font']['weight'],
|
||||
'family' => $options['x']['font']['family'],
|
||||
'variant' => $options['x']['font']['variant'],
|
||||
'color' => $options['x']['font']['color'],
|
||||
],
|
||||
'show' => $options['x']['show'],
|
||||
'position' => $options['x']['position'],
|
||||
'color' => $options['x']['color'],
|
||||
'labelWidth' => $options['x']['labelWidth'],
|
||||
'labelHeight' => $options['x']['labelHeight'],
|
||||
],
|
||||
'y' => [
|
||||
'title' => [
|
||||
'title' => $options['y']['title']['title'],
|
||||
'fontSize' => $options['y']['title']['fontSize'],
|
||||
'fontFamily' => $options['y']['title']['fontFamily'],
|
||||
'padding' => $options['y']['title']['padding'],
|
||||
],
|
||||
'font' => [
|
||||
'size' => $options['y']['font']['size'],
|
||||
'lineHeight' => $options['y']['font']['lineHeight'],
|
||||
'style' => $options['y']['font']['style'],
|
||||
'weight' => $options['y']['font']['weight'],
|
||||
'family' => $options['y']['font']['family'],
|
||||
'variant' => $options['y']['font']['variant'],
|
||||
'color' => $options['y']['font']['color'],
|
||||
],
|
||||
'show' => $options['y']['show'],
|
||||
'position' => $options['y']['position'],
|
||||
'color' => $options['y']['color'],
|
||||
'labelWidth' => $options['y']['labelWidth'],
|
||||
'labelHeight' => $options['y']['labelHeight'],
|
||||
],
|
||||
'bars' => [
|
||||
'align' => $options['bars']['align'],
|
||||
'barWidth' => $options['bars']['barWidth'],
|
||||
'horizontal' => $options['bars']['horizontal'],
|
||||
],
|
||||
'grid' => [
|
||||
'show' => $options['grid']['show'],
|
||||
'aboveData' => $options['grid']['aboveData'],
|
||||
'color' => $options['grid']['color'],
|
||||
'backgroundColor' => $options['grid']['backgroundColor'],
|
||||
'margin' => $options['grid']['margin'],
|
||||
'labelMargin' => $options['grid']['labelMargin'],
|
||||
'axisMargin' => $options['grid']['axisMargin'],
|
||||
'markings' => $options['grid']['markings'],
|
||||
'borderWidth' => $options['grid']['borderWidth'],
|
||||
'borderColor' => $options['grid']['borderColor'],
|
||||
'minBorderMargin' => $options['grid']['minBorderMargin'],
|
||||
'clickable' => $options['grid']['clickable'],
|
||||
'hoverable' => $options['grid']['hoverable'],
|
||||
'autoHighlight' => $options['grid']['autoHighlight'],
|
||||
'mouseActiveRadius' => $options['grid']['mouseActiveRadius'],
|
||||
],
|
||||
'seriesBars' => [
|
||||
'show' => $options['seriesBars']['show'],
|
||||
'lineWidth' => $options['seriesBars']['lineWidth'],
|
||||
'fill' => $options['seriesBars']['fill'],
|
||||
'fillColor' => $options['seriesBars']['fillColor'],
|
||||
],
|
||||
'generals' => [
|
||||
'unit' => $options['generals']['unit'],
|
||||
'divisor' => $options['generals']['divisor'],
|
||||
'forceTicks' => $options['generals']['forceTicks'],
|
||||
'arrayColors' => $options['generals']['arrayColors'],
|
||||
'rotate' => $options['generals']['rotate'],
|
||||
],
|
||||
];
|
||||
|
||||
if (empty($params['data']) === true) {
|
||||
return graph_nodata_image(0, 0, 'vbar', '', true);
|
||||
}
|
||||
|
||||
if ((int) $ttl === 2) {
|
||||
$params['backgroundColor'] = $options['grid']['backgroundColor'];
|
||||
$params['return_img_base_64'] = true;
|
||||
$params['generals']['pdf']['width'] = $options['generals']['pdf']['width'];
|
||||
$params['generals']['pdf']['height'] = $options['generals']['pdf']['height'];
|
||||
return generator_chart_to_pdf('vbar', $params);
|
||||
}
|
||||
|
||||
return flot_vcolumn_chart(
|
||||
$chart_data,
|
||||
$width,
|
||||
$height,
|
||||
$color,
|
||||
$legend,
|
||||
$long_index,
|
||||
$homeurl,
|
||||
$unit,
|
||||
$water_mark_url,
|
||||
$homedir,
|
||||
$font,
|
||||
$font_size,
|
||||
$from_ux,
|
||||
$from_wux,
|
||||
$backgroundColor,
|
||||
$tick_color
|
||||
);
|
||||
return flot_vcolumn_chart($params);
|
||||
}
|
||||
|
||||
|
||||
|
@ -237,7 +566,9 @@ function area_graph(
|
|||
|
||||
include_once 'functions_flot.php';
|
||||
|
||||
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
|
||||
if ($water_mark !== false) {
|
||||
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
|
||||
}
|
||||
|
||||
return flot_area_graph(
|
||||
$agent_module_id,
|
||||
|
@ -274,7 +605,9 @@ function stacked_bullet_chart(
|
|||
) {
|
||||
include_once 'functions_d3.php';
|
||||
|
||||
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
|
||||
if ($water_mark !== false) {
|
||||
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
|
||||
}
|
||||
|
||||
if (empty($chart_data)) {
|
||||
return '<img src="'.$no_data_image.'" />';
|
||||
|
@ -350,7 +683,9 @@ function hbar_graph(
|
|||
$val_max=null,
|
||||
$base64=false
|
||||
) {
|
||||
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
|
||||
if ($water_mark !== false) {
|
||||
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
|
||||
}
|
||||
|
||||
if ($chart_data === false || empty($chart_data) === true) {
|
||||
return graph_nodata_image($width, $height, 'hbar');
|
||||
|
@ -402,16 +737,18 @@ function pie_graph(
|
|||
$colors='',
|
||||
$hide_labels=false
|
||||
) {
|
||||
if (empty($chart_data)) {
|
||||
if (empty($chart_data) === true) {
|
||||
return graph_nodata_image($width, $height, 'pie');
|
||||
}
|
||||
|
||||
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
|
||||
if ($water_mark !== false) {
|
||||
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
|
||||
}
|
||||
|
||||
// This library allows only 8 colors
|
||||
// This library allows only 8 colors.
|
||||
$max_values = 9;
|
||||
|
||||
// Remove the html_entities
|
||||
// Remove the html_entities.
|
||||
$temp = [];
|
||||
foreach ($chart_data as $key => $value) {
|
||||
$temp[io_safe_output($key)] = $value;
|
||||
|
|
|
@ -507,23 +507,45 @@ $.fn.HUseTooltip = function() {
|
|||
}
|
||||
});
|
||||
};
|
||||
|
||||
$.fn.VUseTooltip = function() {
|
||||
$(this).bind("plothover", function(event, pos, item) {
|
||||
if (item) {
|
||||
if (
|
||||
previousLabel != item.series.label ||
|
||||
previousPoint != item.seriesIndex
|
||||
previousPoint != item.dataIndex
|
||||
) {
|
||||
previousPoint = item.seriesIndex;
|
||||
previousPoint = item.dataIndex;
|
||||
previousLabel = item.series.label;
|
||||
|
||||
$("#tooltip").remove();
|
||||
|
||||
// var x = item.datapoint[0];
|
||||
var x = item.datapoint[0];
|
||||
|
||||
var y = item.datapoint[1];
|
||||
if (typeof y != "string") {
|
||||
y = number_format(y, false, "", 2, 1000);
|
||||
}
|
||||
|
||||
var color = item.series.color;
|
||||
showTooltip(pos.pageX, pos.pageY, color, "<strong>" + y + "</strong>");
|
||||
|
||||
//console.log(item.series.xaxis.ticks[x].label);
|
||||
|
||||
/*
|
||||
"<strong>" +
|
||||
item.series.label +
|
||||
"</strong><br>" +
|
||||
item.series.xaxis.ticks[x].label +
|
||||
" : <strong>" +
|
||||
y +
|
||||
"</strong>"
|
||||
*/
|
||||
|
||||
showTooltip(
|
||||
item.pageX,
|
||||
item.pageY,
|
||||
color,
|
||||
"<strong>" + item.series.label + " : " + y + "</strong>"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$("#tooltip").remove();
|
||||
|
@ -552,223 +574,143 @@ function showTooltip(x, y, color, contents) {
|
|||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function pandoraFlotVBars(
|
||||
graph_id,
|
||||
values,
|
||||
labels,
|
||||
labels_long,
|
||||
legend,
|
||||
colors,
|
||||
maxvalue,
|
||||
water_mark,
|
||||
separator,
|
||||
separator2,
|
||||
font,
|
||||
font_size,
|
||||
from_ux,
|
||||
from_wux,
|
||||
background_color,
|
||||
tick_color
|
||||
) {
|
||||
values = values.split(separator2);
|
||||
legend = legend.split(separator);
|
||||
font = font
|
||||
.split("/")
|
||||
.pop()
|
||||
.split(".")
|
||||
.shift();
|
||||
labels_long = labels_long.length > 0 ? labels_long.split(separator) : 0;
|
||||
colors = colors.length > 0 ? colors.split(separator) : [];
|
||||
function pandoraFlotVBars(settings) {
|
||||
settings = JSON.parse(atob(settings));
|
||||
|
||||
var colors_data =
|
||||
colors.length > 0
|
||||
? colors
|
||||
: ["#FFA631", "#e63c52", "#f3b200", "#5BB6E5", "#F2919D", "#82b92e"];
|
||||
var datas = new Array();
|
||||
var unit = settings.generals.unit;
|
||||
var divisor = settings.generals.divisor;
|
||||
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
var serie = values[i].split(separator);
|
||||
|
||||
var aux = new Array();
|
||||
for (var j = 0; j < serie.length; j++) {
|
||||
var aux2 = parseFloat(serie[j]);
|
||||
aux.push([aux2, j]);
|
||||
if (from_ux) {
|
||||
datas.push({
|
||||
data: [[j, aux2]],
|
||||
color: colors_data[j]
|
||||
});
|
||||
} else {
|
||||
datas.push({
|
||||
data: [[j, aux2]],
|
||||
color: colors_data[0]
|
||||
});
|
||||
var datas = [];
|
||||
var ticks = [];
|
||||
var labels = [];
|
||||
settings.data.forEach(function(element, index) {
|
||||
var color = element.color;
|
||||
if (settings.generals.arrayColors) {
|
||||
if (settings.generals.arrayColors[index] != undefined) {
|
||||
color = settings.generals.arrayColors[index].color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var labels_total = new Array();
|
||||
labels = labels.split(separator);
|
||||
i = 0;
|
||||
for (i = 0; i < labels.length; i++) {
|
||||
labels_total.push([i, labels[i]]);
|
||||
datas.push({
|
||||
label: element.tick,
|
||||
color: color,
|
||||
data: [[index, element.data]]
|
||||
});
|
||||
|
||||
if (settings.generals.forceTicks === true) {
|
||||
ticks.push([index, element.tick]);
|
||||
} else {
|
||||
ticks.push([element.tick]);
|
||||
}
|
||||
|
||||
labels.push([index, element.tick]);
|
||||
});
|
||||
|
||||
var formatterTicks = "";
|
||||
if (settings.generals.forceTicks === true) {
|
||||
formatterTicks = "";
|
||||
} else {
|
||||
var ticksformatter = ticks;
|
||||
ticks = null;
|
||||
formatterTicks = function(v) {
|
||||
return ticksformatter[Math.round(v)];
|
||||
};
|
||||
}
|
||||
|
||||
var options = {
|
||||
series: {
|
||||
bars: {
|
||||
show: true,
|
||||
lineWidth: 1,
|
||||
fill: 1,
|
||||
align: "center",
|
||||
barWidth: 1
|
||||
show: settings.seriesBars.show,
|
||||
lineWidth: settings.seriesBars.lineWidth,
|
||||
fill: settings.seriesBars.fill,
|
||||
fillColor: settings.seriesBars.fillColor
|
||||
}
|
||||
},
|
||||
bars: {
|
||||
align: settings.bars.align,
|
||||
barWidth: settings.bars.barWidth,
|
||||
horizontal: settings.bars.horizontal
|
||||
},
|
||||
xaxis: {
|
||||
color: tick_color,
|
||||
axisLabel: settings.x.title.title,
|
||||
axisLabelUseCanvas: true,
|
||||
axisLabelFontSizePixels: font_size,
|
||||
axisLabelFontFamily: font + "Font",
|
||||
axisLabelPadding: 0,
|
||||
ticks: xFormatter,
|
||||
labelWidth: 130,
|
||||
labelHeight: 50
|
||||
axisLabelFontSizePixels: settings.x.title.fontSize,
|
||||
axisLabelFontFamily: settings.x.title.fontFamily,
|
||||
axisLabelPadding: settings.x.title.padding,
|
||||
font: {
|
||||
size: settings.x.font.size,
|
||||
lineHeight: settings.x.font.lineHeight,
|
||||
style: settings.x.font.style,
|
||||
weight: settings.x.font.weight,
|
||||
family: settings.x.font.family,
|
||||
variant: settings.x.font.variant,
|
||||
color: settings.x.font.color
|
||||
},
|
||||
show: settings.x.show,
|
||||
position: settings.x.position,
|
||||
color: settings.x.color,
|
||||
ticks: ticks,
|
||||
tickFormatter: formatterTicks,
|
||||
labelWidth: settings.x.labelWidth,
|
||||
labelHeight: settings.x.labelHeight
|
||||
},
|
||||
yaxis: {
|
||||
color: tick_color,
|
||||
axisLabel: settings.y.title.title,
|
||||
axisLabelUseCanvas: true,
|
||||
axisLabelFontSizePixels: font_size,
|
||||
axisLabelFontFamily: font + "Font",
|
||||
axisLabelPadding: 100,
|
||||
autoscaleMargin: 0.02,
|
||||
axisLabelFontSizePixels: settings.y.title.fontSize,
|
||||
axisLabelFontFamily: settings.y.title.fontFamily,
|
||||
axisLabelPadding: settings.y.title.padding,
|
||||
font: {
|
||||
size: settings.y.font.size,
|
||||
lineHeight: settings.y.font.lineHeight,
|
||||
style: settings.y.font.style,
|
||||
weight: settings.y.font.weight,
|
||||
family: settings.y.font.family,
|
||||
variant: settings.y.font.variant,
|
||||
color: settings.y.font.color
|
||||
},
|
||||
show: settings.y.show,
|
||||
position: settings.y.position,
|
||||
color: settings.y.color,
|
||||
tickFormatter: function(v) {
|
||||
var label = parseFloat(v);
|
||||
var text = label.toLocaleString();
|
||||
if (label >= 1000000) text = text.substring(0, 4) + "M";
|
||||
else if (label >= 100000) text = text.substring(0, 3) + "K";
|
||||
else if (label >= 1000) text = text.substring(0, 2) + "K";
|
||||
var formatted = v;
|
||||
if (typeof formatted != "string") {
|
||||
formatted = number_format(v, false, unit, 2, divisor);
|
||||
}
|
||||
|
||||
return (
|
||||
'<div style="font-size:' +
|
||||
font_size +
|
||||
'pt !important;">' +
|
||||
text +
|
||||
"</div>"
|
||||
);
|
||||
}
|
||||
return formatted;
|
||||
},
|
||||
labelWidth: settings.y.labelWidth,
|
||||
labelHeight: settings.y.labelHeight,
|
||||
reserveSpace: true
|
||||
},
|
||||
legend: {
|
||||
noColumns: 100,
|
||||
labelBoxBorderColor: "",
|
||||
margin: 100,
|
||||
container: true,
|
||||
sorted: false
|
||||
// TODO: settings.
|
||||
show: false
|
||||
},
|
||||
grid: {
|
||||
hoverable: true,
|
||||
borderWidth: 1,
|
||||
tickColor: tick_color,
|
||||
borderColor: "#C1C1C1",
|
||||
backgroundColor: { colors: [background_color, background_color] }
|
||||
show: settings.grid.show,
|
||||
aboveData: settings.grid.aboveData,
|
||||
color: settings.grid.color,
|
||||
backgroundColor: settings.grid.backgroundColor,
|
||||
margin: settings.grid.margin,
|
||||
labelMargin: settings.grid.labelMargin,
|
||||
axisMargin: settings.grid.axisMargin,
|
||||
markings: settings.grid.markings,
|
||||
borderWidth: settings.grid.borderWidth,
|
||||
borderColor: settings.grid.borderColor,
|
||||
minBorderMargin: settings.grid.minBorderMargin,
|
||||
clickable: settings.grid.clickable,
|
||||
hoverable: settings.grid.hoverable,
|
||||
autoHighlight: settings.grid.autoHighlight,
|
||||
mouseActiveRadius: settings.grid.mouseActiveRadius
|
||||
}
|
||||
};
|
||||
|
||||
if (from_wux) {
|
||||
options.series.bars.barWidth = 0.5;
|
||||
options.grid.aboveData = true;
|
||||
options.grid.borderWidth = 0;
|
||||
options.grid.markings = [
|
||||
{ xaxis: { from: -0.25, to: -0.25 }, color: "#000" },
|
||||
{ yaxis: { from: 0, to: 0 }, color: "#000" }
|
||||
];
|
||||
options.grid.markingsLineWidth = 0.3;
|
||||
$.plot($("#" + settings.graphId), datas, options);
|
||||
|
||||
options.xaxis.tickLength = 0;
|
||||
options.yaxis.tickLength = 0;
|
||||
}
|
||||
|
||||
if (
|
||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
||||
navigator.userAgent
|
||||
)
|
||||
)
|
||||
options.xaxis.labelWidth = 100;
|
||||
|
||||
var plot = $.plot($("#" + graph_id), datas, options);
|
||||
$("#" + graph_id).VUseTooltip();
|
||||
$("#" + graph_id).css("margin-left", "auto");
|
||||
$("#" + graph_id).css("margin-right", "auto");
|
||||
|
||||
if (
|
||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
||||
navigator.userAgent
|
||||
)
|
||||
)
|
||||
$("#" + graph_id + " .xAxis .tickLabel")
|
||||
.find("div")
|
||||
.css("top", "+0px")
|
||||
.css("left", "-20px");
|
||||
// Format functions
|
||||
function xFormatter() {
|
||||
var format = new Array();
|
||||
for (i = 0; i < labels_total.length; i++) {
|
||||
var label = labels_total[i][1];
|
||||
var shortLabel = reduceText(label, 28);
|
||||
if (
|
||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
||||
navigator.userAgent
|
||||
)
|
||||
)
|
||||
shortLabel = reduceText(label, 18);
|
||||
var title = "";
|
||||
if (label !== shortLabel) {
|
||||
title = label;
|
||||
label = shortLabel;
|
||||
}
|
||||
|
||||
format.push([
|
||||
i,
|
||||
'<div class="' +
|
||||
font +
|
||||
'" title="' +
|
||||
title +
|
||||
'" style="word-break: normal; overflow:hidden; transform: rotate(-45deg); position:relative; top:+30px; left:0px; max-width: 100px;font-size:' +
|
||||
font_size +
|
||||
'pt !important;">' +
|
||||
label +
|
||||
"</div>"
|
||||
]);
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
||||
/*
|
||||
function yFormatter(v) {
|
||||
return (
|
||||
'<div class="' +
|
||||
font +
|
||||
'" style="font-size:' +
|
||||
font_size +
|
||||
'pt !important;">' +
|
||||
v +
|
||||
"</div>"
|
||||
);
|
||||
}
|
||||
|
||||
function lFormatter(v, axis) {
|
||||
return (
|
||||
'<div style="font-size:' + font_size + 'pt !important;">' + v + "</div>"
|
||||
);
|
||||
}
|
||||
*/
|
||||
|
||||
if (water_mark) {
|
||||
set_watermark(
|
||||
graph_id,
|
||||
plot,
|
||||
$("#watermark_image_" + graph_id).attr("src")
|
||||
);
|
||||
}
|
||||
// Hover in bars graph.
|
||||
$("#" + settings.graphId).VUseTooltip();
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
|
@ -968,6 +910,11 @@ function pandoraFlotSlicebar(
|
|||
|
||||
// Format functions
|
||||
function xFormatter(v) {
|
||||
var ct = new Date();
|
||||
var currentTime = ct.getTime();
|
||||
|
||||
var diffDates = (currentTime - 1000 * datelimit) / 1000;
|
||||
|
||||
var d = new Date(1000 * (v + datelimit));
|
||||
var monthNames = [
|
||||
"Jan",
|
||||
|
@ -984,17 +931,27 @@ function pandoraFlotSlicebar(
|
|||
"Dec"
|
||||
];
|
||||
|
||||
var date_format =
|
||||
(d.getDate() < 10 ? "0" : "") +
|
||||
d.getDate() +
|
||||
" " +
|
||||
monthNames[d.getMonth()] +
|
||||
"<br>" +
|
||||
(d.getHours() < 10 ? "0" : "") +
|
||||
d.getHours() +
|
||||
":" +
|
||||
(d.getMinutes() < 10 ? "0" : "") +
|
||||
d.getMinutes();
|
||||
var date_format = "";
|
||||
if (diffDates > 86500) {
|
||||
date_format =
|
||||
(d.getDate() < 10 ? "0" : "") +
|
||||
d.getDate() +
|
||||
" " +
|
||||
monthNames[d.getMonth()] +
|
||||
"<br>" +
|
||||
(d.getHours() < 10 ? "0" : "") +
|
||||
d.getHours() +
|
||||
":" +
|
||||
(d.getMinutes() < 10 ? "0" : "") +
|
||||
d.getMinutes();
|
||||
} else {
|
||||
date_format =
|
||||
(d.getHours() < 10 ? "0" : "") +
|
||||
d.getHours() +
|
||||
":" +
|
||||
(d.getMinutes() < 10 ? "0" : "") +
|
||||
d.getMinutes();
|
||||
}
|
||||
return date_format;
|
||||
}
|
||||
}
|
||||
|
@ -1030,13 +987,12 @@ function pandoraFlotArea(
|
|||
var type = parseInt(params.stacked);
|
||||
var show_legend = params.show_legend;
|
||||
var image_treshold = params.image_treshold;
|
||||
var short_data = params.short_data;
|
||||
var short_data = params.short_data != "" ? params.short_data : 3;
|
||||
var grid_color = params.grid_color;
|
||||
var background_color = params.backgroundColor;
|
||||
var legend_color = params.legend_color;
|
||||
var update_legend = {};
|
||||
var force_integer = 0;
|
||||
// var title = params.title;
|
||||
var divisor = params.divisor;
|
||||
|
||||
if (typeof divisor === "undefined") {
|
||||
|
@ -2088,23 +2044,6 @@ function pandoraFlotArea(
|
|||
|
||||
var plot = $.plot($("#" + graph_id), datas, options);
|
||||
|
||||
// Re-calculate the graph height with the legend height
|
||||
if (dashboard) {
|
||||
var $acum = 0;
|
||||
if (dashboard) $acum = 35;
|
||||
var hDiff =
|
||||
$("#" + graph_id).height() - $("#legend_" + graph_id).height() - $acum;
|
||||
if (
|
||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
||||
navigator.userAgent
|
||||
)
|
||||
) {
|
||||
// not defined.???
|
||||
} else {
|
||||
$("#" + graph_id).css("height", hDiff);
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust the overview plot to the width and position of the main plot
|
||||
adjust_left_width_canvas(graph_id, "overview_" + graph_id);
|
||||
update_left_width_canvas(graph_id);
|
||||
|
@ -3058,6 +2997,7 @@ function check_adaptions(graph_id) {
|
|||
|
||||
function number_format(number, force_integer, unit, short_data, divisor) {
|
||||
divisor = typeof divisor !== "undefined" ? divisor : 1000;
|
||||
var decimals = 2;
|
||||
|
||||
if (unit == "KB") {
|
||||
return number + unit;
|
||||
|
|
|
@ -305,7 +305,7 @@ function d3_gauges(
|
|||
$output = include_javascript_d3(true);
|
||||
|
||||
foreach ($chart_data as $module) {
|
||||
$output .= "<div id='".$module['gauge']."' style='float:left; overflow: hidden; margin-left: 10px;'></div>";
|
||||
$output .= "<div class='gauge_d3_class' id='".$module['gauge']."' style='float:left; overflow: hidden; margin-left: 10px;'></div>";
|
||||
}
|
||||
|
||||
$output .= "<script language=\"javascript\" type=\"text/javascript\">
|
||||
|
@ -317,8 +317,13 @@ function d3_gauges(
|
|||
}
|
||||
|
||||
|
||||
function ux_console_phases_donut($phases, $id, $return=false)
|
||||
{
|
||||
function ux_console_phases_donut(
|
||||
$phases,
|
||||
$id,
|
||||
$width=800,
|
||||
$height=500,
|
||||
$return=false
|
||||
) {
|
||||
global $config;
|
||||
|
||||
foreach ($phases as $i => $phase) {
|
||||
|
@ -341,10 +346,10 @@ function ux_console_phases_donut($phases, $id, $return=false)
|
|||
}
|
||||
</style>';
|
||||
$output .= "<script language=\"javascript\" type=\"text/javascript\">
|
||||
print_phases_donut('".$recipient_name_to_js."', ".$phases.');
|
||||
print_phases_donut('".$recipient_name_to_js."', ".$phases.', '.$width.', '.$height.');
|
||||
</script>';
|
||||
|
||||
if (!$return) {
|
||||
if ($return === false) {
|
||||
echo $output;
|
||||
}
|
||||
|
||||
|
@ -479,79 +484,78 @@ function d3_donut_graph($id, $width, $height, $module_data, $resume_color)
|
|||
}
|
||||
|
||||
|
||||
function print_clock_analogic_1($time_format, $timezone, $clock_animation, $width, $height, $id_element, $color)
|
||||
{
|
||||
function print_clock_analogic_1(
|
||||
$time_format,
|
||||
$timezone,
|
||||
$clock_animation,
|
||||
$width,
|
||||
$height,
|
||||
$id_element,
|
||||
$color,
|
||||
$title=true
|
||||
) {
|
||||
global $config;
|
||||
$output .= '<style type="text/css">
|
||||
body {
|
||||
background: #fff;
|
||||
}
|
||||
#rim {
|
||||
fill: none;
|
||||
stroke: #999;
|
||||
stroke-width: 3px;
|
||||
}
|
||||
|
||||
svg{
|
||||
stroke: #000;
|
||||
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
|
||||
}
|
||||
.second-hand{
|
||||
stroke-width:3;
|
||||
|
||||
#rim {
|
||||
fill: none;
|
||||
stroke: #999;
|
||||
stroke-width: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
.second-hand{
|
||||
stroke-width:3;
|
||||
.minute-hand{
|
||||
stroke-width:8;
|
||||
stroke-linecap:round;
|
||||
}
|
||||
|
||||
}
|
||||
.hour-hand{
|
||||
stroke-width:12;
|
||||
stroke-linecap:round;
|
||||
}
|
||||
|
||||
.minute-hand{
|
||||
stroke-width:8;
|
||||
stroke-linecap:round;
|
||||
}
|
||||
.hands-cover{
|
||||
stroke-width:3;
|
||||
fill:#fff;
|
||||
}
|
||||
|
||||
.hour-hand{
|
||||
stroke-width:12;
|
||||
stroke-linecap:round;
|
||||
}
|
||||
.second-tick{
|
||||
stroke-width:3;
|
||||
fill:#000;
|
||||
}
|
||||
|
||||
.hands-cover{
|
||||
stroke-width:3;
|
||||
fill:#fff;
|
||||
}
|
||||
.hour-tick{
|
||||
stroke-width:8; //same as the miute hand
|
||||
}
|
||||
|
||||
.second-tick{
|
||||
stroke-width:3;
|
||||
fill:#000;
|
||||
}
|
||||
.second-label{
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.hour-tick{
|
||||
stroke-width:8; //same as the miute hand
|
||||
}
|
||||
.hour-label{
|
||||
font-size: 24px;
|
||||
}
|
||||
}
|
||||
</style>';
|
||||
|
||||
.second-label{
|
||||
font-size: 12px;
|
||||
}
|
||||
$tz = $timezone;
|
||||
$timestamp = time();
|
||||
$dt = new DateTime('now', new DateTimeZone($tz));
|
||||
// first argument "must" be a string.
|
||||
$dt->setTimestamp($timestamp);
|
||||
// adjust the object to correct timestamp.
|
||||
$dateTimeZoneOption = new DateTimeZone(date_default_timezone_get());
|
||||
$dateTimeZonePandora = new DateTimeZone($timezone);
|
||||
|
||||
.hour-label{
|
||||
font-size: 24px;
|
||||
}
|
||||
}
|
||||
</style>';
|
||||
$dateTimeOption = new DateTime('now', $dateTimeZoneOption);
|
||||
$dateTimePandora = new DateTime('now', $dateTimeZonePandora);
|
||||
|
||||
$tz = $timezone;
|
||||
$timestamp = time();
|
||||
$dt = new DateTime('now', new DateTimeZone($tz));
|
||||
// first argument "must" be a string
|
||||
$dt->setTimestamp($timestamp);
|
||||
// adjust the object to correct timestamp
|
||||
$dateTimeZoneOption = new DateTimeZone(date_default_timezone_get());
|
||||
$dateTimeZonePandora = new DateTimeZone($timezone);
|
||||
$timeOffset = $dateTimeZonePandora->getOffset($dateTimeOption);
|
||||
|
||||
$dateTimeOption = new DateTime('now', $dateTimeZoneOption);
|
||||
$dateTimePandora = new DateTime('now', $dateTimeZonePandora);
|
||||
|
||||
$timeOffset = $dateTimeZonePandora->getOffset($dateTimeOption);
|
||||
|
||||
$output .= include_javascript_d3(true);
|
||||
$output .= include_javascript_d3(true);
|
||||
|
||||
if ($width == 0) {
|
||||
$date_width = 200;
|
||||
|
@ -559,24 +563,25 @@ function print_clock_analogic_1($time_format, $timezone, $clock_animation, $widt
|
|||
$date_width = $width;
|
||||
}
|
||||
|
||||
$output .= '<div style="width:'.$date_width.'px;text-align:center;font-style:italic;font-size:12pt;color:'.$color.'">';
|
||||
if ($title === true) {
|
||||
$output .= '<div style="width:'.$date_width.'px;text-align:center;font-style:italic;font-size:12pt;color:'.$color.'">';
|
||||
|
||||
if ($time_format == 'timedate') {
|
||||
$output .= $dt->format('d / m / Y').' - ';
|
||||
if ($time_format == 'timedate') {
|
||||
$output .= $dt->format('d / m / Y').' - ';
|
||||
}
|
||||
|
||||
$output .= $dt->format('a').'</div>';
|
||||
|
||||
$timezone_short = explode('/', $timezone);
|
||||
$timezone_short_end = end($timezone_short);
|
||||
$output .= '<div style="width:'.$date_width.'px;text-align:center;font-style:italic;font-size:12pt;color:'.$color.'">'.$timezone_short_end.'</div>';
|
||||
}
|
||||
|
||||
$output .= $dt->format('a').'</div>';
|
||||
$output .= "<script language=\"javascript\" type=\"text/javascript\">
|
||||
printClockAnalogic1('".$time_format."', '".$timeOffset."', '".$clock_animation."','".$width."','".$height."','".$id_element."','".$color."');
|
||||
</script>";
|
||||
|
||||
$output .= "<script language=\"javascript\" type=\"text/javascript\">
|
||||
printClockAnalogic1('".$time_format."', '".$timeOffset."', '".$clock_animation."','".$width."','".$height."','".$id_element."','".$color."');
|
||||
</script>";
|
||||
|
||||
$timezone_short = explode('/', $timezone);
|
||||
$timezone_short_end = end($timezone_short);
|
||||
|
||||
$output .= '<div style="width:'.$date_width.'px;text-align:center;font-style:italic;font-size:12pt;color:'.$color.'">'.$timezone_short_end.'</div>';
|
||||
|
||||
return $output;
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -138,10 +138,8 @@ function flot_area_graph(
|
|||
break;
|
||||
}
|
||||
|
||||
$padding_vconsole = ($params['dashboard']) ? 'padding: 1px 0px 10px 10px;' : '';
|
||||
|
||||
// Parent layer.
|
||||
$return = "<div class='parent_graph' style='width: ".($params['width']).';'.$background_style.$padding_vconsole."'>";
|
||||
$return = "<div class='parent_graph' style='width: ".$params['width'].'px;'.$background_style."'>";
|
||||
|
||||
if ($params['title'] === true && empty($params['title']) === false) {
|
||||
$return .= '<p style="text-align:center;">'.$params['title'].'</p>';
|
||||
|
@ -149,14 +147,14 @@ function flot_area_graph(
|
|||
|
||||
// Set some containers to legend, graph, timestamp tooltip, etc.
|
||||
if ($params['show_legend']) {
|
||||
$return .= '<p id="legend_'.$graph_id.'" style="text-align:left;"></p>';
|
||||
$return .= '<p id="legend_'.$graph_id.'" style="text-align:left; width: '.$params['width'].'px;"></p>';
|
||||
}
|
||||
|
||||
if (isset($params['graph_combined']) && $params['graph_combined']
|
||||
&& (!isset($params['from_interface']) || !$params['from_interface'])
|
||||
if (isset($params['graph_combined']) === true && $params['graph_combined']
|
||||
&& (isset($params['from_interface']) === false || !$params['from_interface'])
|
||||
) {
|
||||
if (isset($params['threshold_data'])
|
||||
&& is_array($params['threshold_data'])
|
||||
if (isset($params['threshold_data']) === true
|
||||
&& is_array($params['threshold_data']) === true
|
||||
) {
|
||||
$yellow_threshold = $params['threshold_data']['yellow_threshold'];
|
||||
$red_threshold = $params['threshold_data']['red_threshold'];
|
||||
|
@ -170,7 +168,7 @@ function flot_area_graph(
|
|||
$yellow_inverse = false;
|
||||
$red_inverse = false;
|
||||
}
|
||||
} else if (!isset($params['combined']) || !$params['combined']) {
|
||||
} else if (isset($params['combined']) === false || !$params['combined']) {
|
||||
$yellow_threshold = $data_module_graph['w_min'];
|
||||
$red_threshold = $data_module_graph['c_min'];
|
||||
// Get other required module datas to draw warning and critical.
|
||||
|
@ -185,10 +183,10 @@ function flot_area_graph(
|
|||
$yellow_inverse = !($data_module_graph['w_inv'] == 0);
|
||||
$red_inverse = !($data_module_graph['c_inv'] == 0);
|
||||
}
|
||||
} else if (isset($params['from_interface'])
|
||||
} else if (isset($params['from_interface']) === true
|
||||
&& $params['from_interface']
|
||||
) {
|
||||
if (isset($params['threshold_data'])
|
||||
if (isset($params['threshold_data']) === true
|
||||
&& is_array($params['threshold_data'])
|
||||
) {
|
||||
$yellow_threshold = $params['threshold_data']['yellow_threshold'];
|
||||
|
@ -228,12 +226,14 @@ function flot_area_graph(
|
|||
$config['custom_graph_width'],
|
||||
true
|
||||
);
|
||||
$return .= "<div id='timestamp_$graph_id'
|
||||
class='timestamp_graph'
|
||||
style=' font-size:".$params['font_size']."pt;
|
||||
display:none; position:absolute;
|
||||
background:#fff; border: solid 1px #aaa;
|
||||
padding: 2px; z-index:1000;'></div>";
|
||||
/*
|
||||
$return .= "<div id='timestamp_$graph_id'
|
||||
class='timestamp_graph'
|
||||
style=' font-size:".$params['font_size']."pt;
|
||||
display:none; position:absolute;
|
||||
background:#fff; border: solid 1px #aaa;
|
||||
padding: 2px; z-index:1000;'></div>";
|
||||
*/
|
||||
$return .= "<div id='$graph_id' class='";
|
||||
|
||||
if ($params['type'] == 'area_simple') {
|
||||
|
@ -252,23 +252,24 @@ function flot_area_graph(
|
|||
|
||||
if (!$vconsole) {
|
||||
$return .= "<div id='overview_$graph_id' class='overview_graph'
|
||||
style='margin:0px; margin-top:30px; margin-bottom:50px; width: ".$params['width']."; height: 200px;'></div>";
|
||||
}
|
||||
style='margin:0px; margin-top:30px; margin-bottom:50px; width: ".$params['width']."px; height: 200px;'></div>";
|
||||
|
||||
if ($water_mark != '') {
|
||||
$return .= "<div id='watermark_$graph_id' style='display:none; position:absolute;'><img id='watermark_image_$graph_id' src='".$water_mark['url']."'></div>";
|
||||
$watermark = 'true';
|
||||
} else {
|
||||
$watermark = 'false';
|
||||
if ($water_mark != '') {
|
||||
$return .= "<div id='watermark_$graph_id' style='display:none; position:absolute;'><img id='watermark_image_$graph_id' src='".$water_mark['url']."'></div>";
|
||||
$watermark = 'true';
|
||||
} else {
|
||||
$watermark = 'false';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($series_type as $k => $v) {
|
||||
$series_type_unique['data_'.$graph_id.'_'.$k] = $v;
|
||||
}
|
||||
|
||||
// Store data series in javascript format.
|
||||
$extra_width = (int) ($params['width'] / 3);
|
||||
$return .= "<div id='extra_$graph_id'
|
||||
/*
|
||||
// Store data series in javascript format.
|
||||
$extra_width = (int) ($params['width'] / 3);
|
||||
$return .= "<div id='extra_$graph_id'
|
||||
style='font-size: ".$params['font_size'].'pt;
|
||||
display:none; position:absolute; overflow: auto;
|
||||
max-height: '.($params['height'] + 50).'px;
|
||||
|
@ -276,8 +277,9 @@ function flot_area_graph(
|
|||
background:#fff; padding: 2px 2px 2px 2px;
|
||||
border: solid #000 1px;'></div>";
|
||||
|
||||
// Trick to get translated string from javascript.
|
||||
$return .= html_print_input_hidden('unknown_text', __('Unknown'), true);
|
||||
// Trick to get translated string from javascript.
|
||||
$return .= html_print_input_hidden('unknown_text', __('Unknown'), true);
|
||||
*/
|
||||
|
||||
$values = json_encode($array_data);
|
||||
|
||||
|
@ -334,52 +336,32 @@ function menu_graph(
|
|||
$threshold = true;
|
||||
}
|
||||
|
||||
if ($params['dashboard'] == false and $params['vconsole'] == false) {
|
||||
$return .= "<div id='general_menu_$graph_id' class='menu_graph' style='
|
||||
width: 20px;
|
||||
height: 150px;
|
||||
left:100%;
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
background-color: tranparent;'>";
|
||||
$return .= "<div id='menu_$graph_id' "."style='display: none; ".'text-align: center;'.'position: relative;'."border-bottom: 0px;'>
|
||||
<a href='javascript:'><img id='menu_cancelzoom_$graph_id' src='".$params['homeurl']."images/zoom_cross_grey.disabled.png' alt='".__('Cancel zoom')."' title='".__('Cancel zoom')."'></a>";
|
||||
if ($threshold) {
|
||||
$return .= " <a href='javascript:'><img id='menu_threshold_$graph_id' src='".$params['homeurl']."images/chart_curve_threshold.png' alt='".__('Warning and Critical thresholds')."' title='".__('Warning and Critical thresholds')."'></a>";
|
||||
}
|
||||
|
||||
if ($params['show_overview']) {
|
||||
$return .= " <a href='javascript:'>
|
||||
<img id='menu_overview_$graph_id' class='menu_overview' src='".$params['homeurl']."images/chart_curve_overview.png' alt='".__('Overview graph')."' title='".__('Overview graph')."'></a>";
|
||||
}
|
||||
|
||||
// Export buttons
|
||||
if ($params['show_export_csv']) {
|
||||
$return .= " <a href='javascript:'><img id='menu_export_csv_$graph_id' src='".$params['homeurl']."images/csv_grey.png' alt='".__('Export to CSV')."' title='".__('Export to CSV')."'></a>";
|
||||
}
|
||||
|
||||
// Button disabled. This feature works, but seems that is not useful enough to the final users.
|
||||
// $return .= " <a href='javascript:'><img id='menu_export_json_$graph_id' src='".$homeurl."images/json.png' alt='".__('Export to JSON')."' title='".__('Export to JSON')."'></a>";
|
||||
$return .= '</div>';
|
||||
$return .= '</div>';
|
||||
$return .= "<div id='general_menu_$graph_id' class='menu_graph' style='
|
||||
width: 20px;
|
||||
height: 150px;
|
||||
left:100%;
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
background-color: tranparent;'>";
|
||||
$return .= "<div id='menu_$graph_id' "."style='display: none; ".'text-align: center;'.'position: relative;'."border-bottom: 0px;'>
|
||||
<a href='javascript:'><img id='menu_cancelzoom_$graph_id' src='".$params['homeurl']."images/zoom_cross_grey.disabled.png' alt='".__('Cancel zoom')."' title='".__('Cancel zoom')."'></a>";
|
||||
if ($threshold) {
|
||||
$return .= " <a href='javascript:'><img id='menu_threshold_$graph_id' src='".$params['homeurl']."images/chart_curve_threshold.png' alt='".__('Warning and Critical thresholds')."' title='".__('Warning and Critical thresholds')."'></a>";
|
||||
}
|
||||
|
||||
if ($params['dashboard']) {
|
||||
$return .= "<div id='general_menu_$graph_id' class='menu_graph' style='
|
||||
width: 30px;
|
||||
height: 250px;
|
||||
left: ".$params['width']."px;
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
background-color: white;'>";
|
||||
|
||||
$return .= "<div id='menu_$graph_id' "."style='display: none; ".'text-align: center;'.'position: relative;'."border-bottom: 0px;'>
|
||||
<a href='javascript:'><img id='menu_cancelzoom_$graph_id' src='".$params['homeurl']."images/zoom_cross_grey.disabled.png' alt='".__('Cancel zoom')."' title='".__('Cancel zoom')."'></a>";
|
||||
|
||||
$return .= '</div>';
|
||||
$return .= '</div>';
|
||||
if ($params['show_overview']) {
|
||||
$return .= " <a href='javascript:'>
|
||||
<img id='menu_overview_$graph_id' class='menu_overview' src='".$params['homeurl']."images/chart_curve_overview.png' alt='".__('Overview graph')."' title='".__('Overview graph')."'></a>";
|
||||
}
|
||||
|
||||
// Export buttons.
|
||||
if ($params['show_export_csv']) {
|
||||
$return .= " <a href='javascript:'><img id='menu_export_csv_$graph_id' src='".$params['homeurl']."images/csv_grey.png' alt='".__('Export to CSV')."' title='".__('Export to CSV')."'></a>";
|
||||
}
|
||||
|
||||
$return .= '</div>';
|
||||
$return .= '</div>';
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
@ -436,8 +418,7 @@ function flot_pie_chart(
|
|||
$colors = implode($separator, $colors);
|
||||
}
|
||||
|
||||
include_javascript_dependencies_flot_graph();
|
||||
|
||||
// include_javascript_dependencies_flot_graph();
|
||||
$return .= "<script type='text/javascript'>";
|
||||
$return .= "pandoraFlotPie('$graph_id', '$values', '$labels',
|
||||
'$series', '$width', $font_size, $water_mark, '$separator',
|
||||
|
@ -622,99 +603,50 @@ function flot_hcolumn_chart($graph_data, $width, $height, $water_mark, $font='',
|
|||
}
|
||||
|
||||
|
||||
// Returns a 3D column chart
|
||||
function flot_vcolumn_chart($graph_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $water_mark, $homedir, $font, $font_size, $from_ux, $from_wux, $background_color='white', $tick_color='white')
|
||||
/**
|
||||
* Draw html graph vertical bars.
|
||||
*
|
||||
* @param array $options Settings draw chart.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function flot_vcolumn_chart(array $options)
|
||||
{
|
||||
global $config;
|
||||
|
||||
// include_javascript_dependencies_flot_graph();
|
||||
$stacked_str = '';
|
||||
$multicolor = false;
|
||||
|
||||
// Get a unique identifier to graph
|
||||
$graph_id = uniqid('graph_');
|
||||
$graph_id2 = uniqid('graph_');
|
||||
// Get a unique identifier to graph.
|
||||
$graphId = uniqid('graph_');
|
||||
|
||||
if ($width != 'auto') {
|
||||
$width = $width.'px';
|
||||
// Div draw chart.
|
||||
$style = 'width: 100%; height: 100%;';
|
||||
if (isset($options['generals']['pdf']['width']) === true
|
||||
&& isset($options['generals']['pdf']['height']) === true
|
||||
) {
|
||||
$style = 'width:'.$options['generals']['pdf']['width'].'px;';
|
||||
$style .= 'height:'.$options['generals']['pdf']['height'].'px;';
|
||||
}
|
||||
|
||||
$class = '';
|
||||
if ($options['generals']['rotate'] === true) {
|
||||
$class = 'bars-graph-rotate';
|
||||
}
|
||||
|
||||
$return .= '<div id="'.$graphId.'" class="'.$class.'" style="'.$style.'">';
|
||||
$return .= '</div>';
|
||||
|
||||
// Set some containers to legend, graph, timestamp tooltip, etc.
|
||||
$return .= "<div id='$graph_id' class='graph $adapt_key' style='width: ".$width.'; height: '.$height."px; padding-left: 20px;'></div>";
|
||||
$return .= "<div id='value_$graph_id' style='display:none; position:absolute; background:#fff; border: solid 1px #aaa; padding: 2px'></div>";
|
||||
$return .= '<div id="value_'.$graphId.'" style="display:none;"></div>';
|
||||
|
||||
if ($water_mark != '') {
|
||||
$return .= "<div id='watermark_$graph_id' style='display:none; position:absolute;'><img id='watermark_image_$graph_id' src='$water_mark'></div>";
|
||||
$watermark = 'true';
|
||||
} else {
|
||||
$watermark = 'false';
|
||||
}
|
||||
|
||||
$colors = array_map(
|
||||
function ($elem) {
|
||||
return $elem['color'] ? $elem['color'] : null;
|
||||
},
|
||||
$color
|
||||
);
|
||||
|
||||
// Set a weird separator to serialize and unserialize passing data from php to javascript
|
||||
$separator = ';;::;;';
|
||||
$separator2 = ':,:,,,:,:';
|
||||
|
||||
// Transform data from our format to library format
|
||||
$labels = [];
|
||||
$a = [];
|
||||
$vars = [];
|
||||
|
||||
$max = 0;
|
||||
$i = count($graph_data);
|
||||
foreach ($graph_data as $label => $values) {
|
||||
$labels[] = $label;
|
||||
$i--;
|
||||
|
||||
foreach ($values as $key => $value) {
|
||||
$jsvar = 'data_'.$graph_id.'_'.$key;
|
||||
|
||||
$data[$jsvar][] = $value;
|
||||
|
||||
if ($value > $max) {
|
||||
$max = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store serialized data to use it from javascript
|
||||
$labels = implode($separator, $labels);
|
||||
$colors = implode($separator, $colors);
|
||||
|
||||
// Store data series in javascript format
|
||||
$jsvars = '';
|
||||
$jsseries = [];
|
||||
|
||||
$i = 0;
|
||||
|
||||
$values2 = [];
|
||||
|
||||
foreach ($data as $jsvar => $values) {
|
||||
$values2[] = implode($separator, $values);
|
||||
}
|
||||
|
||||
$values = implode($separator2, $values2);
|
||||
|
||||
$jsseries = implode(',', $jsseries);
|
||||
|
||||
// Javascript code
|
||||
$return .= "<script type='text/javascript'>";
|
||||
if ($from_ux) {
|
||||
if ($from_wux) {
|
||||
$return .= "pandoraFlotVBars('$graph_id', '$values', '$labels', '$labels', '$legend', '$colors', $max, '$water_mark', '$separator', '$separator2','$font',$font_size, true, true, '$background_color', '$tick_color')";
|
||||
} else {
|
||||
$return .= "pandoraFlotVBars('$graph_id', '$values', '$labels', '$labels', '$legend', '$colors', $max, '$water_mark', '$separator', '$separator2','$font',$font_size, true, false, '$background_color', '$tick_color')";
|
||||
}
|
||||
} else {
|
||||
$return .= "pandoraFlotVBars('$graph_id', '$values', '$labels', '$labels', '$legend', '$colors', $max, '$water_mark', '$separator', '$separator2','$font',$font_size, false, false, '$background_color', '$tick_color')";
|
||||
}
|
||||
// Add id to options.
|
||||
$options['graphId'] = $graphId;
|
||||
$settings = base64_encode(json_encode($options));
|
||||
|
||||
// Javascript code.
|
||||
$return .= '<script type="text/javascript">';
|
||||
$return .= 'pandoraFlotVBars(\''.$settings.'\')';
|
||||
$return .= '</script>';
|
||||
|
||||
return $return;
|
||||
|
@ -738,7 +670,7 @@ function flot_slicesbar_graph(
|
|||
$full_legend_date=[],
|
||||
$not_interactive=0,
|
||||
$ttl=1,
|
||||
$widgets=false,
|
||||
$sizeForTicks=false,
|
||||
$show=true,
|
||||
$date_to=false,
|
||||
$server_id=''
|
||||
|
@ -763,7 +695,7 @@ function flot_slicesbar_graph(
|
|||
'full_legend_date' => $full_legend_date,
|
||||
'not_interactive' => $not_interactive,
|
||||
'ttl' => 1,
|
||||
'widgets' => $widgets,
|
||||
'sizeForTicks' => $sizeForTicks,
|
||||
'show' => $show,
|
||||
'return_img_base_64' => true,
|
||||
'date_to' => $date_to,
|
||||
|
@ -776,67 +708,62 @@ function flot_slicesbar_graph(
|
|||
return $graph;
|
||||
}
|
||||
|
||||
// Get a unique identifier to graph
|
||||
// Get a unique identifier to graph.
|
||||
$graph_id = uniqid('graph_');
|
||||
|
||||
// Set some containers to legend, graph, timestamp tooltip, etc.
|
||||
$height = ((int) $height + 15);
|
||||
if ($stat_win) {
|
||||
$height = ((int) $height + 15);
|
||||
$return = "<div id='$graph_id' class='noresizevc graph $adapt_key' style='width: ".$width.'%; height: '.$height."px; display: inline-block;'></div>";
|
||||
} else {
|
||||
if ($widgets) {
|
||||
$width = ((int) $width - 10);
|
||||
$height = ((int) $height - 10);
|
||||
$return = "<div id='$graph_id' class='noresizevc graph $adapt_key' style='width: ".$width.'px; height: '.$height."px;'></div>";
|
||||
} else {
|
||||
$height = ((int) $height + 15);
|
||||
$return = "<div id='$graph_id' class='noresizevc graph $adapt_key' style='width: ".$width.'%; height: '.$height."px;'></div>";
|
||||
}
|
||||
$return = "<div id='$graph_id' class='noresizevc graph $adapt_key' style='width: ".$width.'%; height: '.$height."px;'></div>";
|
||||
}
|
||||
|
||||
$return .= "<div id='value_$graph_id' style='display:none; position:absolute; background:#fff; border: solid 1px #aaa; padding: 2px'></div>";
|
||||
|
||||
// Set a weird separator to serialize and unserialize passing data from php to javascript
|
||||
// Set a weird separator to serialize and unserialize
|
||||
// passing data from php to javascript.
|
||||
$separator = ';;::;;';
|
||||
$separator2 = ':,:,,,:,:';
|
||||
|
||||
// Transform data from our format to library format
|
||||
// Transform data from our format to library format.
|
||||
$vars = [];
|
||||
|
||||
$datacolor = [];
|
||||
|
||||
$max = 0;
|
||||
|
||||
$i = count($graph_data);
|
||||
|
||||
$intervaltick = ($period / $i);
|
||||
|
||||
$fontsize = $config['font_size'];
|
||||
$fontpath = $config['fontpath'];
|
||||
|
||||
$extra_height = 40;
|
||||
if (defined('METACONSOLE')) {
|
||||
$extra_height = 50;
|
||||
}
|
||||
|
||||
$return .= '<div id="extra_'.$graph_id.'" class="slicebar-box-hover-styles" style="display:none; font-size:'.$fontsize.'"></div>';
|
||||
|
||||
$maxticks = (int) 20;
|
||||
if ($sizeForTicks === false) {
|
||||
$maxticks = (int) 20;
|
||||
} else if ($sizeForTicks < 300) {
|
||||
$maxticks = (int) 3;
|
||||
} else if ($sizeForTicks < 600) {
|
||||
$maxticks = (int) 6;
|
||||
} else if ($sizeForTicks < 900) {
|
||||
$maxticks = (int) 9;
|
||||
}
|
||||
|
||||
$i_aux = $i;
|
||||
$intervaltick = ($period / $maxticks);
|
||||
|
||||
$maxticks_aux = $maxticks;
|
||||
|
||||
while (1) {
|
||||
if ($i_aux <= $maxticks) {
|
||||
if ($maxticks_aux <= $maxticks) {
|
||||
break;
|
||||
}
|
||||
|
||||
$intervaltick *= 2;
|
||||
|
||||
$i_aux /= 2;
|
||||
$maxticks_aux /= 2;
|
||||
}
|
||||
|
||||
$intervaltick = (int) $intervaltick;
|
||||
|
||||
$i = count($graph_data);
|
||||
foreach ($graph_data as $label => $values) {
|
||||
$i--;
|
||||
|
||||
|
|
|
@ -1543,21 +1543,19 @@ function Gauge(placeholderName, configuration, font) {
|
|||
this.configure(configuration);
|
||||
}
|
||||
|
||||
function print_phases_donut(recipient, phases) {
|
||||
function print_phases_donut(recipient, phases, width, height) {
|
||||
var svg = d3
|
||||
.select(recipient)
|
||||
.append("svg")
|
||||
.attr("width", 800)
|
||||
.attr("height", 500)
|
||||
.attr("width", width)
|
||||
.attr("height", height)
|
||||
.append("g");
|
||||
|
||||
svg.append("g").attr("class", "slices");
|
||||
svg.append("g").attr("class", "labels");
|
||||
svg.append("g").attr("class", "lines");
|
||||
|
||||
var width = 550,
|
||||
height = 300,
|
||||
radius = Math.min(width, height) / 2;
|
||||
var radius = Math.min(width, height) / 2 - 50;
|
||||
|
||||
var pie = d3.layout
|
||||
.pie()
|
||||
|
@ -1576,8 +1574,6 @@ function print_phases_donut(recipient, phases) {
|
|||
.innerRadius(radius * 0.9)
|
||||
.outerRadius(radius * 0.9);
|
||||
|
||||
width = 800;
|
||||
height = 500;
|
||||
svg.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
|
||||
|
||||
var key = function(d) {
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
/**
|
||||
* gridstack.js 0.3.0
|
||||
* http://troolee.github.io/gridstack.js/
|
||||
* (c) 2014-2016 Pavel Reznikov, Dylan Weiss
|
||||
* gridstack.js may be freely distributed under the MIT license.
|
||||
* @preserve
|
||||
*/
|
||||
(function(factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define([
|
||||
"jquery",
|
||||
"lodash",
|
||||
"gridstack",
|
||||
"jquery-ui/data",
|
||||
"jquery-ui/disable-selection",
|
||||
"jquery-ui/focusable",
|
||||
"jquery-ui/form",
|
||||
"jquery-ui/ie",
|
||||
"jquery-ui/keycode",
|
||||
"jquery-ui/labels",
|
||||
"jquery-ui/jquery-1-7",
|
||||
"jquery-ui/plugin",
|
||||
"jquery-ui/safe-active-element",
|
||||
"jquery-ui/safe-blur",
|
||||
"jquery-ui/scroll-parent",
|
||||
"jquery-ui/tabbable",
|
||||
"jquery-ui/unique-id",
|
||||
"jquery-ui/version",
|
||||
"jquery-ui/widget",
|
||||
"jquery-ui/widgets/mouse",
|
||||
"jquery-ui/widgets/draggable",
|
||||
"jquery-ui/widgets/droppable",
|
||||
"jquery-ui/widgets/resizable"
|
||||
], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
try {
|
||||
jQuery = require("jquery");
|
||||
} catch (e) {}
|
||||
try {
|
||||
_ = require("lodash");
|
||||
} catch (e) {}
|
||||
try {
|
||||
GridStackUI = require("gridstack");
|
||||
} catch (e) {}
|
||||
factory(jQuery, _, GridStackUI);
|
||||
} else {
|
||||
factory(jQuery, _, GridStackUI);
|
||||
}
|
||||
})(function($, _, GridStackUI) {
|
||||
var scope = window;
|
||||
|
||||
/**
|
||||
* @class JQueryUIGridStackDragDropPlugin
|
||||
* jQuery UI implementation of drag'n'drop gridstack plugin.
|
||||
*/
|
||||
function JQueryUIGridStackDragDropPlugin(grid) {
|
||||
GridStackUI.GridStackDragDropPlugin.call(this, grid);
|
||||
}
|
||||
|
||||
GridStackUI.GridStackDragDropPlugin.registerPlugin(
|
||||
JQueryUIGridStackDragDropPlugin
|
||||
);
|
||||
|
||||
JQueryUIGridStackDragDropPlugin.prototype = Object.create(
|
||||
GridStackUI.GridStackDragDropPlugin.prototype
|
||||
);
|
||||
JQueryUIGridStackDragDropPlugin.prototype.constructor = JQueryUIGridStackDragDropPlugin;
|
||||
|
||||
JQueryUIGridStackDragDropPlugin.prototype.resizable = function(el, opts) {
|
||||
el = $(el);
|
||||
if (opts === "disable" || opts === "enable") {
|
||||
el.resizable(opts);
|
||||
} else if (opts === "option") {
|
||||
var key = arguments[2];
|
||||
var value = arguments[3];
|
||||
el.resizable(opts, key, value);
|
||||
} else {
|
||||
el.resizable(
|
||||
_.extend({}, this.grid.opts.resizable, {
|
||||
start: opts.start || function() {},
|
||||
stop: opts.stop || function() {},
|
||||
resize: opts.resize || function() {}
|
||||
})
|
||||
);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
JQueryUIGridStackDragDropPlugin.prototype.draggable = function(el, opts) {
|
||||
el = $(el);
|
||||
if (opts === "disable" || opts === "enable") {
|
||||
el.draggable(opts);
|
||||
} else {
|
||||
el.draggable(
|
||||
_.extend({}, this.grid.opts.draggable, {
|
||||
containment: this.grid.opts.isNested
|
||||
? this.grid.container.parent()
|
||||
: null,
|
||||
start: opts.start || function() {},
|
||||
stop: opts.stop || function() {},
|
||||
drag: opts.drag || function() {}
|
||||
})
|
||||
);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
JQueryUIGridStackDragDropPlugin.prototype.droppable = function(el, opts) {
|
||||
el = $(el);
|
||||
if (opts === "disable" || opts === "enable") {
|
||||
el.droppable(opts);
|
||||
} else {
|
||||
el.droppable({
|
||||
accept: opts.accept
|
||||
});
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
JQueryUIGridStackDragDropPlugin.prototype.isDroppable = function(el, opts) {
|
||||
el = $(el);
|
||||
return Boolean(el.data("droppable"));
|
||||
};
|
||||
|
||||
JQueryUIGridStackDragDropPlugin.prototype.on = function(
|
||||
el,
|
||||
eventName,
|
||||
callback
|
||||
) {
|
||||
$(el).on(eventName, callback);
|
||||
return this;
|
||||
};
|
||||
|
||||
return JQueryUIGridStackDragDropPlugin;
|
||||
});
|
|
@ -1,7 +1,6 @@
|
|||
/*global jQuery,$,forced_title_callback,Base64, dt_events*/
|
||||
|
||||
// Show the modal window of an event
|
||||
var current_event;
|
||||
function show_event_dialog(event, dialog_page, result) {
|
||||
var ajax_file = $("#hidden-ajax_file").val();
|
||||
|
||||
|
@ -9,8 +8,6 @@ function show_event_dialog(event, dialog_page, result) {
|
|||
dialog_page = "general";
|
||||
}
|
||||
|
||||
current_event = event;
|
||||
|
||||
try {
|
||||
event = JSON.parse(atob(event));
|
||||
} catch (e) {
|
||||
|
@ -480,7 +477,9 @@ function event_change_status(event_ids) {
|
|||
}
|
||||
|
||||
if (data == "status_ok") {
|
||||
dt_events.draw(false);
|
||||
if (typeof dt_events !== "undefined") {
|
||||
dt_events.draw(false);
|
||||
}
|
||||
$("#notification_status_success").show();
|
||||
} else {
|
||||
$("#notification_status_error").show();
|
||||
|
@ -526,7 +525,9 @@ function event_change_owner() {
|
|||
}
|
||||
|
||||
if (data == "owner_ok") {
|
||||
dt_events.draw(false);
|
||||
if (typeof dt_events !== "undefined") {
|
||||
dt_events.draw(false);
|
||||
}
|
||||
$("#notification_owner_success").show();
|
||||
if (new_owner == -1) {
|
||||
$("#extended_event_general_page table td.general_owner").html(
|
||||
|
@ -547,7 +548,7 @@ function event_change_owner() {
|
|||
}
|
||||
|
||||
// Save a comment into an event
|
||||
function event_comment() {
|
||||
function event_comment(current_event) {
|
||||
var event;
|
||||
try {
|
||||
event = JSON.parse(atob(current_event));
|
||||
|
@ -558,8 +559,15 @@ function event_comment() {
|
|||
|
||||
var event_id = event.id_evento;
|
||||
var comment = $("#textarea_comment").val();
|
||||
var meta = $("#hidden-meta").val();
|
||||
var history = $("#hidden-history").val();
|
||||
var meta = 0;
|
||||
if ($("#hidden-meta").val() != undefined) {
|
||||
meta = $("#hidden-meta").val();
|
||||
}
|
||||
|
||||
var history = 0;
|
||||
if ($("#hidden-history").val() != undefined) {
|
||||
history = $("#hidden-history").val();
|
||||
}
|
||||
|
||||
if (comment == "") {
|
||||
show_event_dialog(current_event, "comments", "comment_error");
|
||||
|
|
|
@ -300,6 +300,9 @@ function load_modal(settings) {
|
|||
} else {
|
||||
// No onsumbit configured. Directly close.
|
||||
$(this).dialog("close");
|
||||
if (document.getElementById(settings.form) != undefined) {
|
||||
document.getElementById(settings.form).submit();
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function(data) {
|
||||
|
|
|
@ -26,7 +26,9 @@ function createVisualConsole(
|
|||
items,
|
||||
baseUrl,
|
||||
updateInterval,
|
||||
onUpdate
|
||||
onUpdate,
|
||||
beforeUpdate,
|
||||
size
|
||||
) {
|
||||
if (container == null || props == null || items == null) return null;
|
||||
if (baseUrl == null) baseUrl = "";
|
||||
|
@ -43,6 +45,7 @@ function createVisualConsole(
|
|||
var abortable = loadVisualConsoleData(
|
||||
baseUrl,
|
||||
visualConsoleId,
|
||||
size,
|
||||
function(error, data) {
|
||||
if (error) {
|
||||
//Remove spinner change VC.
|
||||
|
@ -82,18 +85,23 @@ function createVisualConsole(
|
|||
? JSON.parse(data.items)
|
||||
: data.items;
|
||||
|
||||
// Add the datetime when the item was received.
|
||||
var receivedAt = new Date();
|
||||
items.map(function(item) {
|
||||
item["receivedAt"] = receivedAt;
|
||||
return item;
|
||||
});
|
||||
|
||||
var prevProps = visualConsole.props;
|
||||
// Update the data structure.
|
||||
visualConsole.props = props;
|
||||
// Update the items.
|
||||
visualConsole.updateElements(items);
|
||||
if (beforeUpdate) {
|
||||
beforeUpdate(items, visualConsole, props);
|
||||
} else {
|
||||
// Add the datetime when the item was received.
|
||||
items.map(function(item) {
|
||||
item["receivedAt"] = receivedAt;
|
||||
return item;
|
||||
});
|
||||
|
||||
// Update the data structure.
|
||||
visualConsole.props = props;
|
||||
// Update the items.
|
||||
visualConsole.updateElements(items);
|
||||
}
|
||||
|
||||
// Emit the VC update event.
|
||||
if (onUpdate) onUpdate(prevProps, visualConsole.props);
|
||||
} catch (ignored) {} // eslint-disable-line no-empty
|
||||
|
@ -619,7 +627,7 @@ function createVisualConsole(
|
|||
* @return {Object} Cancellable. Object which include and .abort([statusText]) function.
|
||||
*/
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function loadVisualConsoleData(baseUrl, vcId, callback) {
|
||||
function loadVisualConsoleData(baseUrl, vcId, size, callback) {
|
||||
// var apiPath = baseUrl + "/include/rest-api";
|
||||
var apiPath = baseUrl + "/ajax.php";
|
||||
var vcJqXHR = null;
|
||||
|
@ -695,6 +703,7 @@ function loadVisualConsoleData(baseUrl, vcId, callback) {
|
|||
{
|
||||
page: "include/rest-api/index",
|
||||
getVisualConsoleItems: 1,
|
||||
size: size,
|
||||
visualConsoleId: vcId
|
||||
},
|
||||
"json"
|
||||
|
|
|
@ -1086,7 +1086,10 @@ var TreeController = {
|
|||
}
|
||||
|
||||
controller.recipient.empty();
|
||||
if (controller.tree.length !== undefined) {
|
||||
if (
|
||||
controller.tree.length !== undefined &&
|
||||
controller.foundMessage !== "not"
|
||||
) {
|
||||
controller.recipient.html(
|
||||
"<div> " +
|
||||
controller.foundMessage +
|
||||
|
|
|
@ -0,0 +1,240 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Dashboard manager.
|
||||
*/
|
||||
class Cell
|
||||
{
|
||||
|
||||
/**
|
||||
* Dasboard ID.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $dashboardId;
|
||||
|
||||
/**
|
||||
* Cell ID.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $cellId;
|
||||
|
||||
/**
|
||||
* Data cell.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $fieldsCell;
|
||||
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param array|integer $data Id Cell or data forn new(insert) Cell.
|
||||
* @param integer $dashboardId Id Dashboard.
|
||||
*/
|
||||
public function __construct($data, int $dashboardId)
|
||||
{
|
||||
$this->dashboardId = $dashboardId;
|
||||
|
||||
// Check exists Cell id.
|
||||
if (is_array($data) === false && empty($data) === false) {
|
||||
$this->cellId = $data;
|
||||
} else {
|
||||
$this->cellId = $this->set($data);
|
||||
}
|
||||
|
||||
$this->fieldsCell = $this->get();
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve a cell definition.
|
||||
*
|
||||
* @return array cell data.
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT *
|
||||
FROM twidget_dashboard
|
||||
WHERE id = %d',
|
||||
$this->cellId
|
||||
);
|
||||
|
||||
$data = \db_get_row_sql($sql);
|
||||
|
||||
if ($data === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create Cell widget layout.
|
||||
*
|
||||
* @param array $position Array position widgets.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function set(array $position):int
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (isset($position['order']) === true) {
|
||||
$order = $position['order'];
|
||||
unset($position['order']);
|
||||
} else {
|
||||
$order = count(self::getCells($this->dashboardId));
|
||||
}
|
||||
|
||||
$position = json_encode($position);
|
||||
|
||||
$values = [
|
||||
'id_dashboard' => $this->dashboardId,
|
||||
'position' => $position,
|
||||
'order' => $order,
|
||||
];
|
||||
|
||||
// Insert.
|
||||
$res = \db_process_sql_insert(
|
||||
'twidget_dashboard',
|
||||
$values
|
||||
);
|
||||
|
||||
if ($res === false) {
|
||||
$res = 0;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Cell widget layout.
|
||||
*
|
||||
* @param array $position Array position widgets.
|
||||
* @param integer|null $idWidget Id widget insert to cell.
|
||||
* @param array $options Options for widget.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function put(
|
||||
array $position=[],
|
||||
?int $idWidget=null,
|
||||
array $options=[]
|
||||
):int {
|
||||
global $config;
|
||||
|
||||
// Position.
|
||||
if (empty($position) !== true) {
|
||||
$order = 0;
|
||||
if (isset($position['order']) === true) {
|
||||
$order = $position['order'];
|
||||
unset($position['order']);
|
||||
}
|
||||
|
||||
$position = json_encode($position);
|
||||
} else {
|
||||
$order = $this->fieldsCell['order'];
|
||||
$position = $this->fieldsCell['position'];
|
||||
}
|
||||
|
||||
// Id widget.
|
||||
if (isset($idWidget) === false) {
|
||||
$idWidget = $this->fieldsCell['id_widget'];
|
||||
}
|
||||
|
||||
// Options for widget.
|
||||
if (empty($options) !== true) {
|
||||
$options = json_encode($options);
|
||||
} else {
|
||||
$options = $this->fieldsCell['options'];
|
||||
}
|
||||
|
||||
// Values.
|
||||
$values = [
|
||||
'id_dashboard' => $this->dashboardId,
|
||||
'position' => $position,
|
||||
'options' => $options,
|
||||
'order' => $order,
|
||||
'id_widget' => $idWidget,
|
||||
];
|
||||
|
||||
// Update.
|
||||
$res = \db_process_sql_update(
|
||||
'twidget_dashboard',
|
||||
$values,
|
||||
['id' => $this->cellId]
|
||||
);
|
||||
|
||||
if ($res === false) {
|
||||
$res = 0;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove Cell layout.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function delete():int
|
||||
{
|
||||
global $config;
|
||||
|
||||
// Delete.
|
||||
$res = db_process_sql_delete(
|
||||
'twidget_dashboard',
|
||||
['id' => $this->cellId]
|
||||
);
|
||||
if ($res === false) {
|
||||
$res = 0;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Cells widget.
|
||||
*
|
||||
* @param integer $dashboardId Id dashboard.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getCells(int $dashboardId):array
|
||||
{
|
||||
global $config;
|
||||
|
||||
$cells = db_get_all_rows_filter(
|
||||
'twidget_dashboard',
|
||||
[
|
||||
'id_dashboard' => $dashboardId,
|
||||
'order' => [
|
||||
'order' => 'ASC',
|
||||
'field' => \db_encapsule_fields_with_same_name_to_instructions('order'),
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
if (empty($cells) === true) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $cells;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,571 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Dashboard manager.
|
||||
*/
|
||||
class Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Dasboard ID.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $dashboardId;
|
||||
|
||||
/**
|
||||
* Cell ID.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $cellId;
|
||||
|
||||
/**
|
||||
* Widget Id.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $widgetId;
|
||||
|
||||
/**
|
||||
* Values widget.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $values;
|
||||
|
||||
|
||||
/**
|
||||
* Contructor widget.
|
||||
*
|
||||
* @param integer $cellId Cell Id.
|
||||
* @param integer $dashboardId Dashboard Id.
|
||||
* @param integer $widgetId Widget Id.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId,
|
||||
int $widgetId
|
||||
) {
|
||||
// Check exists Cell id.
|
||||
if (empty($widgetId) === false) {
|
||||
$this->widgetId = $widgetId;
|
||||
$this->cellId = $cellId;
|
||||
$this->dashboardId = $dashboardId;
|
||||
$this->fields = $this->get();
|
||||
|
||||
$cellClass = new Cell($this->cellId, $this->dashboardId);
|
||||
$this->dataCell = $cellClass->get();
|
||||
$this->values = $this->getOptionsWidget();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve a cell definition.
|
||||
*
|
||||
* @return array cell data.
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT *
|
||||
FROM twidget
|
||||
WHERE id = %d',
|
||||
$this->widgetId
|
||||
);
|
||||
|
||||
$data = \db_get_row_sql($sql);
|
||||
|
||||
if ($data === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get options Cell widget configuration.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptionsWidget():array
|
||||
{
|
||||
global $config;
|
||||
|
||||
$result = [];
|
||||
if (empty($this->dataCell['options']) === false) {
|
||||
$result = \json_decode($this->dataCell['options'], true);
|
||||
|
||||
// Hack retrocompatibility.
|
||||
if ($result === null) {
|
||||
$result = \unserialize($this->dataCell['options']);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get options Cell widget configuration.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPositionWidget():array
|
||||
{
|
||||
global $config;
|
||||
|
||||
$result = [];
|
||||
if (empty($this->dataCell['position']) === false) {
|
||||
$result = \json_decode($this->dataCell['position'], true);
|
||||
|
||||
// Hack retrocompatibility.
|
||||
if ($result === null) {
|
||||
$result = \unserialize($this->dataCell['position']);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Insert widgets.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
$id = db_get_value(
|
||||
'id',
|
||||
'twidget',
|
||||
'unique_name',
|
||||
$this->getName()
|
||||
);
|
||||
|
||||
if ($id !== false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$values = [
|
||||
'unique_name' => $this->getName(),
|
||||
'description' => $this->getDescription(),
|
||||
'options' => '',
|
||||
'page' => $this->page,
|
||||
'class_name' => $this->className,
|
||||
];
|
||||
|
||||
$res = db_process_sql_insert('twidget', $values);
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all dashboard user can you see.
|
||||
*
|
||||
* @param integer $offset Offset query.
|
||||
* @param integer $limit Limit query.
|
||||
* @param string|null $search Search word.
|
||||
*
|
||||
* @return array Return info all dasboards.
|
||||
*/
|
||||
static public function getWidgets(
|
||||
int $offset=-1,
|
||||
int $limit=-1,
|
||||
?string $search=''
|
||||
):array {
|
||||
global $config;
|
||||
|
||||
$sql_limit = '';
|
||||
if ($offset !== -1 && $limit !== -1) {
|
||||
$sql_limit = ' LIMIT '.$offset.','.$limit;
|
||||
}
|
||||
|
||||
$sql_search = '';
|
||||
if (empty($search) === false) {
|
||||
$sql_search = 'AND description LIKE "%'.$search.'%" ';
|
||||
}
|
||||
|
||||
// User admin view all dashboards.
|
||||
$sql_widget = \sprintf(
|
||||
'SELECT * FROM twidget
|
||||
WHERE unique_name <> "agent_module"
|
||||
%s
|
||||
ORDER BY `description` %s',
|
||||
$sql_search,
|
||||
$sql_limit
|
||||
);
|
||||
|
||||
$widgets = \db_get_all_rows_sql($sql_widget);
|
||||
|
||||
if ($widgets === false) {
|
||||
$widgets = [];
|
||||
}
|
||||
|
||||
return $widgets;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Install Widgets.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function dashboardInstallWidgets(int $cellId)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$dir = $config['homedir'].'/include/lib/Dashboard/Widgets/';
|
||||
$handle = opendir($dir);
|
||||
if ($handle === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$file = readdir($handle);
|
||||
$ignores = [
|
||||
'.',
|
||||
'..',
|
||||
];
|
||||
|
||||
while ($file !== false) {
|
||||
if (in_array($file, $ignores) === true) {
|
||||
$file = readdir($handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
$filepath = realpath($dir.'/'.$file);
|
||||
if (is_readable($filepath) === false
|
||||
|| is_dir($filepath) === true
|
||||
|| preg_match('/.*\.php$/', $filepath) === false
|
||||
) {
|
||||
$file = readdir($handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = preg_replace('/.php/', '', $file);
|
||||
$className = 'PandoraFMS\Dashboard';
|
||||
$not_installed = false;
|
||||
switch ($name) {
|
||||
case 'agent_module':
|
||||
$not_installed = true;
|
||||
$className .= '\AgentModuleWidget';
|
||||
break;
|
||||
|
||||
case 'alerts_fired':
|
||||
$className .= '\AlertsFiredWidget';
|
||||
break;
|
||||
|
||||
case 'clock':
|
||||
$className .= '\ClockWidget';
|
||||
break;
|
||||
|
||||
case 'custom_graph':
|
||||
$className .= '\CustomGraphWidget';
|
||||
break;
|
||||
|
||||
case 'events_list':
|
||||
$className .= '\EventsListWidget';
|
||||
break;
|
||||
|
||||
case 'example':
|
||||
$className .= '\WelcomeWidget';
|
||||
break;
|
||||
|
||||
case 'graph_module_histogram':
|
||||
$className .= '\GraphModuleHistogramWidget';
|
||||
break;
|
||||
|
||||
case 'groups_status':
|
||||
$className .= '\GroupsStatusWidget';
|
||||
break;
|
||||
|
||||
case 'maps_made_by_user':
|
||||
$className .= '\MapsMadeByUser';
|
||||
break;
|
||||
|
||||
case 'maps_status':
|
||||
$className .= '\MapsStatusWidget';
|
||||
break;
|
||||
|
||||
case 'module_icon':
|
||||
$className .= '\ModuleIconWidget';
|
||||
break;
|
||||
|
||||
case 'module_status':
|
||||
$className .= '\ModuleStatusWidget';
|
||||
break;
|
||||
|
||||
case 'module_table_value':
|
||||
$className .= '\ModuleTableValueWidget';
|
||||
break;
|
||||
|
||||
case 'module_value':
|
||||
$className .= '\ModuleValueWidget';
|
||||
break;
|
||||
|
||||
case 'monitor_health':
|
||||
$className .= '\MonitorHealthWidget';
|
||||
break;
|
||||
|
||||
case 'network_map':
|
||||
if (\enterprise_installed() === false) {
|
||||
$not_installed = true;
|
||||
}
|
||||
|
||||
$className .= '\NetworkMapWidget';
|
||||
break;
|
||||
|
||||
case 'post':
|
||||
$className .= '\PostWidget';
|
||||
break;
|
||||
|
||||
case 'reports':
|
||||
$className .= '\ReportsWidget';
|
||||
break;
|
||||
|
||||
case 'service_map':
|
||||
if (\enterprise_installed() === false) {
|
||||
$not_installed = true;
|
||||
}
|
||||
|
||||
$className .= '\ServiceMapWidget';
|
||||
break;
|
||||
|
||||
case 'single_graph':
|
||||
$className .= '\SingleGraphWidget';
|
||||
break;
|
||||
|
||||
case 'sla_percent':
|
||||
$className .= '\SLAPercentWidget';
|
||||
break;
|
||||
|
||||
case 'system_group_status':
|
||||
$className .= '\SystemGroupStatusWidget';
|
||||
break;
|
||||
|
||||
case 'tactical':
|
||||
$className .= '\TacticalWidget';
|
||||
break;
|
||||
|
||||
case 'top_n_events_by_module':
|
||||
$className .= '\TopNEventByModuleWidget';
|
||||
break;
|
||||
|
||||
case 'top_n_events_by_group':
|
||||
$className .= '\TopNEventByGroupWidget';
|
||||
break;
|
||||
|
||||
case 'top_n':
|
||||
$className .= '\TopNWidget';
|
||||
break;
|
||||
|
||||
case 'tree_view':
|
||||
$className .= '\TreeViewWidget';
|
||||
break;
|
||||
|
||||
case 'url':
|
||||
$className .= '\UrlWidget';
|
||||
break;
|
||||
|
||||
case 'wux_transaction_stats':
|
||||
if (\enterprise_installed() === false) {
|
||||
$not_installed = true;
|
||||
}
|
||||
|
||||
$className .= '\WuxStatsWidget';
|
||||
break;
|
||||
|
||||
case 'wux_transaction':
|
||||
if (\enterprise_installed() === false) {
|
||||
$not_installed = true;
|
||||
}
|
||||
|
||||
$className .= '\WuxWidget';
|
||||
break;
|
||||
|
||||
default:
|
||||
$className = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($not_installed === false && $className !== false) {
|
||||
include_once $filepath;
|
||||
$instance = new $className($cellId, 0, 0);
|
||||
if (method_exists($instance, 'install') === true) {
|
||||
$instance->install();
|
||||
}
|
||||
}
|
||||
|
||||
// Check next.
|
||||
$file = readdir($handle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw html.
|
||||
*
|
||||
* @return string Html data.
|
||||
*/
|
||||
public function printHtml()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$output = '';
|
||||
|
||||
if ($this->configurationRequired === true) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_info_message(
|
||||
__('Please configure this widget before usage'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
} else if ($this->loadError === true) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('Widget cannot be loaded'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= __('Please, configure the widget again to recover it');
|
||||
$output .= '</div>';
|
||||
} else {
|
||||
$output .= $this->load();
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form.
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$inputs = [];
|
||||
|
||||
$values = $this->values;
|
||||
|
||||
// Default values.
|
||||
if (isset($values['title']) === false) {
|
||||
$values['title'] = $this->getDescription();
|
||||
}
|
||||
|
||||
if (empty($values['background']) === true) {
|
||||
$values['background'] = '#ffffff';
|
||||
}
|
||||
|
||||
$inputs[] = [
|
||||
'arguments' => [
|
||||
'type' => 'hidden',
|
||||
'name' => 'dashboardId',
|
||||
'value' => $this->dashboardId,
|
||||
],
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'arguments' => [
|
||||
'type' => 'hidden',
|
||||
'name' => 'cellId',
|
||||
'value' => $this->cellId,
|
||||
],
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'arguments' => [
|
||||
'type' => 'hidden',
|
||||
'name' => 'widgetId',
|
||||
'value' => $this->widgetId,
|
||||
],
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Title'),
|
||||
'arguments' => [
|
||||
'type' => 'text',
|
||||
'name' => 'title',
|
||||
'value' => $values['title'],
|
||||
'return' => true,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Background'),
|
||||
'arguments' => [
|
||||
'wrapper' => 'div',
|
||||
'name' => 'background',
|
||||
'type' => 'color',
|
||||
'value' => $values['background'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
$values = [];
|
||||
$values['title'] = \get_parameter('title', '');
|
||||
$values['background'] = \get_parameter('background', '#ffffff');
|
||||
|
||||
return $values;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Size Cell.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSize():array
|
||||
{
|
||||
$gridWidth = $this->gridWidth;
|
||||
if ($this->gridWidth === 0) {
|
||||
$gridWidth = 1170;
|
||||
}
|
||||
|
||||
if ($this->width === 0) {
|
||||
$width = (((int) $this->position['width'] / 12 * $gridWidth) - 50);
|
||||
} else {
|
||||
$width = (((int) $this->width / 12 * $gridWidth) - 50);
|
||||
}
|
||||
|
||||
if ($this->height === 0) {
|
||||
$height = ((((int) $this->position['height'] - 1) * 80) + 60 - 30);
|
||||
} else {
|
||||
$height = ((((int) $this->height - 1) * 80) + 60 - 30);
|
||||
}
|
||||
|
||||
$result = [
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,802 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Agent module Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Agent module
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
global $config;
|
||||
|
||||
require_once $config['homedir'].'/include/functions_agents.php';
|
||||
require_once $config['homedir'].'/include/functions_modules.php';
|
||||
|
||||
/**
|
||||
* Agent module Widgets.
|
||||
*/
|
||||
class AgentModuleWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Agent/Module View');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'agent_module';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['moduleId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// DO NOT CHANGE THIS VALUE.
|
||||
$id_group = isset($this->options['search_group_'.$id]) ? $this->options['search_group_'.$id] : 0;
|
||||
|
||||
$agent_conf_key = 'id_agent_'.$id;
|
||||
$id_agent = $this->options[$agent_conf_key];
|
||||
$module_conf_key = 'id_module_'.$id;
|
||||
$id_module = $this->options[$module_conf_key];
|
||||
$recursion_checked = $this->options['recursion'];
|
||||
|
||||
$this->add_configuration(
|
||||
'search_group_'.$id,
|
||||
__('Group'),
|
||||
OPTION_TREE_GROUP_SELECT
|
||||
);
|
||||
|
||||
$list_agents = agents_get_group_agents(
|
||||
$id_group,
|
||||
false,
|
||||
'lower',
|
||||
false,
|
||||
$recursion_checked
|
||||
);
|
||||
|
||||
if (!isset($this->options['selection_agent_module_'.$id])
|
||||
|| $this->options['selection_agent_module_'.$id] == ''
|
||||
|| $this->options['selection_agent_module_'.$id] == null
|
||||
) {
|
||||
$selection_agent_module = 'common';
|
||||
} else {
|
||||
$selection_agent_module = $this->options['selection_agent_module_'.$id];
|
||||
}
|
||||
|
||||
$limit_common = '';
|
||||
$sql = false;
|
||||
if (!empty($id_agent)) {
|
||||
if ($selection_agent_module == 'common') {
|
||||
$limit_common = sprintf(
|
||||
' AND (SELECT count(nombre)
|
||||
FROM tagente_modulo t2
|
||||
WHERE t2.delete_pending = 0
|
||||
AND t1.nombre = t2.nombre
|
||||
AND t2.id_agente IN (%s)) = (%d)',
|
||||
implode(',', (array) $id_agent),
|
||||
count($id_agent)
|
||||
);
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT DISTINCT nombre
|
||||
FROM tagente_modulo t1
|
||||
WHERE id_agente IN (%s)
|
||||
AND delete_pending = 0 %s ORDER BY nombre',
|
||||
implode(', ', (array) $id_agent),
|
||||
$limit_common
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($id_module)) {
|
||||
$this->options[$module_conf_key] = index_array(
|
||||
db_get_all_rows_sql($sql),
|
||||
'nombre',
|
||||
'nombre'
|
||||
);
|
||||
}
|
||||
|
||||
$this->add_configuration(
|
||||
'recursion',
|
||||
__('Recursion'),
|
||||
OPTION_BOOLEAN
|
||||
);
|
||||
|
||||
$this->add_configuration(
|
||||
$agent_conf_key,
|
||||
__('Agent'),
|
||||
OPTION_SELECT_MULTISELECTION,
|
||||
['values' => $list_agents]
|
||||
);
|
||||
|
||||
$this->add_configuration(
|
||||
'selection_agent_module_'.$id,
|
||||
__('Show common modules'),
|
||||
OPTION_SINGLE_SELECT,
|
||||
[
|
||||
'values' => [
|
||||
'common' => __('Show common modules'),
|
||||
'all' => __('Show all modules'),
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_configuration(
|
||||
$module_conf_key,
|
||||
__('Module'),
|
||||
OPTION_SELECT_MULTISELECTION,
|
||||
[
|
||||
'values' => index_array(
|
||||
db_get_all_rows_sql($sql),
|
||||
'nombre',
|
||||
'nombre'
|
||||
),
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_configuration(
|
||||
'',
|
||||
'',
|
||||
OPTION_CUSTOM_INPUT,
|
||||
[
|
||||
'widget' => $this,
|
||||
'entire_row' => true,
|
||||
'update' => false,
|
||||
]
|
||||
);
|
||||
*/
|
||||
|
||||
|
||||
function print_configuration_custom($return=true)
|
||||
{
|
||||
$id = $this->getId();
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
|
||||
recalculate_modules_select_agent_module(
|
||||
$("#selection_agent_module_<?php echo $id; ?>").val()
|
||||
);
|
||||
|
||||
function recalculate_modules_select_agent_module (selection_mode) {
|
||||
var idAgents = Array();
|
||||
jQuery.each ($('#id_agent_<?php echo $id; ?> option:selected'), function (i, val) {
|
||||
idAgents.push($(val).val());
|
||||
});
|
||||
jQuery.post ('ajax.php',
|
||||
{"page": "operation/agentes/ver_agente",
|
||||
"get_modules_group_value_name_json": 1,
|
||||
"selection": selection_mode == 'all' ? 1 : 0,
|
||||
"id_agents[]": idAgents
|
||||
},
|
||||
function (data, status) {
|
||||
$('#id_module_<?php echo $id; ?>').empty ();
|
||||
if (data) {
|
||||
jQuery.each (data, function (id, value) {
|
||||
$('#id_module_<?php echo $id; ?>')
|
||||
.append ($('<option></option>')
|
||||
.html(value)
|
||||
.prop("value", value)
|
||||
.prop("selected", 'selected'));
|
||||
});
|
||||
}
|
||||
},
|
||||
"json"
|
||||
);
|
||||
}
|
||||
|
||||
$('#search_group_<?php echo $id; ?>').on('change',function() {
|
||||
jQuery.post ("ajax.php",
|
||||
{
|
||||
"page" : "operation/agentes/ver_agente",
|
||||
"get_agents_group_json" : 1,
|
||||
"id_group" : this.value,
|
||||
"recursion" : ($('#checkbox-recursion-<?php echo $id; ?>').is(':checked')) ? 1 : 0
|
||||
},
|
||||
function (data, status) {
|
||||
$('#id_agent_<?php echo $id; ?>').html('');
|
||||
jQuery.each (data, function(id, value) {
|
||||
// Remove keys_prefix from the index.
|
||||
option = $("<option></option>")
|
||||
.prop("value", id)
|
||||
.prop("selected", 'selected')
|
||||
.html(value);
|
||||
$('#id_agent_<?php echo $id; ?>').append (option);
|
||||
});
|
||||
|
||||
recalculate_modules_select_agent_module(
|
||||
$("#selection_agent_module_<?php echo $id; ?>").val()
|
||||
);
|
||||
},
|
||||
"json"
|
||||
);
|
||||
});
|
||||
|
||||
$('#checkbox-recursion-<?php echo $id; ?>').on('change', function() {
|
||||
($('#hidden-recursion_sent').val() === '1') ? $('#hidden-recursion_sent').val('0') : $('#hidden-recursion_sent').val('1');
|
||||
jQuery.post ("ajax.php",
|
||||
{
|
||||
"page" : "operation/agentes/ver_agente",
|
||||
"get_agents_group_json" : 1,
|
||||
"id_group" : $('#search_group_<?php echo $id; ?>').val(),
|
||||
"recursion" : ($('#checkbox-recursion-<?php echo $id; ?>').is(':checked')) ? 1 : 0
|
||||
},
|
||||
function (data, status) {
|
||||
$('#id_agent_<?php echo $id; ?>').html('');
|
||||
jQuery.each (data, function(id, value) {
|
||||
// Remove keys_prefix from the index.
|
||||
option = $("<option></option>")
|
||||
.prop("value", id)
|
||||
.prop("selected", 'selected')
|
||||
.html(value);
|
||||
$('#id_agent_<?php echo $id; ?>').append (option);
|
||||
});
|
||||
|
||||
recalculate_modules_select_agent_module(
|
||||
$("#selection_agent_module_<?php echo $id; ?>").val()
|
||||
);
|
||||
},
|
||||
"json"
|
||||
);
|
||||
});
|
||||
|
||||
$("#id_agent_<?php echo $id; ?>").on('change',function () {
|
||||
recalculate_modules_select_agent_module(
|
||||
$("#selection_agent_module_<?php echo $id; ?>").val()
|
||||
);
|
||||
});
|
||||
|
||||
$("#selection_agent_module_<?php echo $id; ?>").on('change',function(evt) {
|
||||
recalculate_modules_select_agent_module(
|
||||
$("#selection_agent_module_<?php echo $id; ?>").val()
|
||||
);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
public function generate_data_agent_module($agents, $all_modules)
|
||||
{
|
||||
$return = [];
|
||||
$cont = 0;
|
||||
$name = '';
|
||||
|
||||
foreach ($all_modules as $key => $module) {
|
||||
if ($module == $name) {
|
||||
$modules_by_name[($cont - 1)]['id'][] = $key;
|
||||
} else {
|
||||
$name = $module;
|
||||
$modules_by_name[$cont]['name'] = $name;
|
||||
$modules_by_name[$cont]['id'][] = $key;
|
||||
$cont ++;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($agents as $agent) {
|
||||
if (!users_access_to_agent($agent['id_agente'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row = [];
|
||||
$row['agent_status'] = agents_get_status($agent['id_agente'], true);
|
||||
$row['agent_name'] = $agent['nombre'];
|
||||
$row['agent_alias'] = $agent['alias'];
|
||||
$agent_modules = agents_get_modules($agent['id_agente']);
|
||||
|
||||
$row['modules'] = [];
|
||||
foreach ($modules_by_name as $module) {
|
||||
$row['modules'][$module['name']] = null;
|
||||
foreach ($module['id'] as $module_id) {
|
||||
if (array_key_exists($module_id, $agent_modules)) {
|
||||
$row['modules'][$module['name']] = modules_get_agentmodule_status($module_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$return[] = $row;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
public function generate_view_agent_module($visual_data)
|
||||
{
|
||||
$table_data = '<div>';
|
||||
$table_data .= '<table class="widget_agent_module" cellpadding="1" cellspacing="0" border="0" style="background-color: #EEE;">';
|
||||
|
||||
if (!empty($visual_data)) {
|
||||
$table_data .= '<th>'.__('Agents').' / '.__('Modules').'</th>';
|
||||
|
||||
$array_names = [];
|
||||
|
||||
foreach ($visual_data as $data) {
|
||||
foreach ($data['modules'] as $module_name => $module) {
|
||||
if ($module === null || in_array($module_name, $array_names)) {
|
||||
continue;
|
||||
} else {
|
||||
$array_names[] = $module_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
natcasesort($array_names);
|
||||
foreach ($array_names as $module_name) {
|
||||
$file_name = ui_print_truncate_text(
|
||||
$module_name,
|
||||
'module_small',
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
'...'
|
||||
);
|
||||
$table_data .= '<th style="padding: 10px;">'.$file_name.'</th>';
|
||||
}
|
||||
|
||||
foreach ($visual_data as $row) {
|
||||
$table_data .= "<tr style='height: 35px;'>";
|
||||
switch ($row['agent_status']) {
|
||||
case AGENT_STATUS_ALERT_FIRED:
|
||||
$rowcolor = COL_ALERTFIRED;
|
||||
$textcolor = '#000';
|
||||
break;
|
||||
|
||||
case AGENT_STATUS_CRITICAL:
|
||||
$rowcolor = COL_CRITICAL;
|
||||
$textcolor = '#FFF';
|
||||
break;
|
||||
|
||||
case AGENT_STATUS_WARNING:
|
||||
$rowcolor = COL_WARNING;
|
||||
$textcolor = '#000';
|
||||
break;
|
||||
|
||||
case AGENT_STATUS_NORMAL:
|
||||
$rowcolor = COL_NORMAL;
|
||||
$textcolor = '#FFF';
|
||||
break;
|
||||
|
||||
case AGENT_STATUS_UNKNOWN:
|
||||
case AGENT_STATUS_ALL:
|
||||
default:
|
||||
$rowcolor = COL_UNKNOWN;
|
||||
$textcolor = '#FFF';
|
||||
break;
|
||||
}
|
||||
|
||||
$file_name = ui_print_truncate_text(
|
||||
$row['agent_alias'],
|
||||
'agent_small',
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
'...'
|
||||
);
|
||||
$table_data .= "<td style='background-color: ".$rowcolor.";'>".$file_name.'</td>';
|
||||
|
||||
foreach ($row['modules'] as $module_name => $module) {
|
||||
if ($module === null) {
|
||||
if (in_array($module_name, $array_names)) {
|
||||
$table_data .= "<td style='background-color: #DDD;'></td>";
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$table_data .= "<td style='text-align: center; background-color: #DDD;'>";
|
||||
switch ($module) {
|
||||
case AGENT_STATUS_NORMAL:
|
||||
$table_data .= ui_print_status_image(
|
||||
'module_ok.png',
|
||||
__(
|
||||
'%s in %s : NORMAL',
|
||||
$module_name,
|
||||
$row['agent_alias']
|
||||
),
|
||||
true,
|
||||
[
|
||||
'width' => '20px',
|
||||
'height' => '20px',
|
||||
]
|
||||
);
|
||||
break;
|
||||
|
||||
case AGENT_STATUS_CRITICAL:
|
||||
$table_data .= ui_print_status_image(
|
||||
'module_critical.png',
|
||||
__(
|
||||
'%s in %s : CRITICAL',
|
||||
$module_name,
|
||||
$row['agent_alias']
|
||||
),
|
||||
true,
|
||||
[
|
||||
'width' => '20px',
|
||||
'height' => '20px',
|
||||
]
|
||||
);
|
||||
break;
|
||||
|
||||
case AGENT_STATUS_WARNING:
|
||||
$table_data .= ui_print_status_image(
|
||||
'module_warning.png',
|
||||
__(
|
||||
'%s in %s : WARNING',
|
||||
$module_name,
|
||||
$row['agent_alias']
|
||||
),
|
||||
true,
|
||||
[
|
||||
'width' => '20px',
|
||||
'height' => '20px',
|
||||
]
|
||||
);
|
||||
break;
|
||||
|
||||
case AGENT_STATUS_UNKNOWN:
|
||||
$table_data .= ui_print_status_image(
|
||||
'module_unknown.png',
|
||||
__(
|
||||
'%s in %s : UNKNOWN',
|
||||
$module_name,
|
||||
$row['agent_alias']
|
||||
),
|
||||
true,
|
||||
[
|
||||
'width' => '20px',
|
||||
'height' => '20px',
|
||||
]
|
||||
);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$table_data .= ui_print_status_image(
|
||||
'module_no_data.png',
|
||||
__(
|
||||
'%s in %s : Not initialize',
|
||||
$module_name,
|
||||
$row['agent_alias']
|
||||
),
|
||||
true,
|
||||
[
|
||||
'width' => '20px',
|
||||
'height' => '20px',
|
||||
]
|
||||
);
|
||||
break;
|
||||
|
||||
case AGENT_STATUS_ALERT_FIRED:
|
||||
default:
|
||||
$table_data .= ui_print_status_image(
|
||||
'module_alertsfired.png',
|
||||
__(
|
||||
'%s in %s : ALERTS FIRED',
|
||||
$module_name,
|
||||
$row['agent_alias']
|
||||
),
|
||||
true,
|
||||
[
|
||||
'width' => '20px',
|
||||
'height' => '20px',
|
||||
]
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
$table_data .= '</td>';
|
||||
}
|
||||
}
|
||||
|
||||
$table_data .= '</tr>';
|
||||
}
|
||||
} else {
|
||||
$table_data .= '<tr><td>'.__('Please configure this widget before usage').'</td></tr>';
|
||||
}
|
||||
|
||||
$table_data .= '</table>';
|
||||
$table_data .= '</div>';
|
||||
|
||||
return $table_data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Autocomplete agents.
|
||||
$inputs[] = [
|
||||
'label' => __('Agent'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_agent',
|
||||
'name' => 'agentAlias',
|
||||
'id_agent_hidden' => $values['agentId'],
|
||||
'name_agent_hidden' => 'agentId',
|
||||
'server_id_hidden' => $values['metaconsoleId'],
|
||||
'name_server_hidden' => 'metaconsoleId',
|
||||
'return' => true,
|
||||
'module_input' => true,
|
||||
'module_name' => 'moduleId',
|
||||
'module_none' => false,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Autocomplete module.
|
||||
$inputs[] = [
|
||||
'label' => __('Module'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_module',
|
||||
'fields' => $fields,
|
||||
'name' => 'moduleId',
|
||||
'selected' => $values['moduleId'],
|
||||
'return' => true,
|
||||
'sort' => false,
|
||||
'agent_id' => $values['agentId'],
|
||||
'metaconsole_id' => $values['metaconsoleId'],
|
||||
'style' => 'width: inherit;',
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['agentId'] = \get_parameter('agentId', 0);
|
||||
$values['metaconsoleId'] = \get_parameter('metaconsoleId', 0);
|
||||
$values['moduleId'] = \get_parameter('moduleId', 0);
|
||||
$values['period'] = \get_parameter('period', 0);
|
||||
$values['showLegend'] = \get_parameter_switch('showLegend');
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
// TODO:XXX WIP.
|
||||
return 'WIP in this widget';
|
||||
/*
|
||||
$this->body = '';
|
||||
$id_agent = $this->options['id_agent_'.$this->getId()];
|
||||
if (! check_acl($config['id_user'], 0, 'AR')) {
|
||||
$this->body = __('You don\'t have access');
|
||||
return;
|
||||
}
|
||||
|
||||
$id_module = $this->options['id_module_'.$this->getId()];
|
||||
if ($id_agent) {
|
||||
$sql = 'SELECT id_agente,nombre,alias
|
||||
FROM tagente
|
||||
WHERE id_agente IN ('.implode(',', $id_agent).')
|
||||
ORDER BY id_agente';
|
||||
$agents = db_get_all_rows_sql($sql);
|
||||
if ($agents === false) {
|
||||
$agents = [];
|
||||
}
|
||||
|
||||
$sql = 'SELECT id_agente_modulo,nombre
|
||||
FROM tagente_modulo
|
||||
WHERE id_agente IN ('.implode(',', $id_agent).")
|
||||
AND nombre IN ('".implode("','", $id_module)."')
|
||||
AND delete_pending = 0 ORDER BY nombre";
|
||||
$modules = index_array(db_get_all_rows_sql($sql), 'id_agente_modulo', 'nombre');
|
||||
if ($modules === false) {
|
||||
$modules = [];
|
||||
}
|
||||
} else {
|
||||
$agents = [];
|
||||
$modules = [];
|
||||
}
|
||||
|
||||
$visual_data = $this->generate_data_agent_module($agents, $modules);
|
||||
|
||||
$this->body .= $this->generate_view_agent_module($visual_data);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Agent/Module View');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'agent_module';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$instance = new AgentModuleWidget(false);
|
|
@ -0,0 +1,344 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Alerts fired Pandora FMS Console.
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Alerts fired
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Alerts fired Widgets.
|
||||
*/
|
||||
class AlertsFiredWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// Includes.
|
||||
include_once $config['homedir'].'/include/functions_users.php';
|
||||
include_once $config['homedir'].'/include/functions_alerts.php';
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Triggered alerts report');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'alerts_fired';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (isset($this->values['groupId']) === false) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Groups.
|
||||
$inputs[] = [
|
||||
'label' => __('Group'),
|
||||
'arguments' => [
|
||||
'type' => 'select_groups',
|
||||
'name' => 'groupId',
|
||||
'returnAllGroup' => true,
|
||||
'privilege' => 'AR',
|
||||
'selected' => $values['groupId'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['groupId'] = \get_parameter('groupId', 0);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$output = '';
|
||||
|
||||
if ($this->values['groupId'] === 0) {
|
||||
$groups = users_get_groups(false, 'AR', false);
|
||||
} else {
|
||||
$groups = [$this->values['groupId'] => ''];
|
||||
}
|
||||
|
||||
if (isset($groups) === true && is_array($groups) === true) {
|
||||
$table = new \StdClass();
|
||||
$table->class = 'databox data';
|
||||
$table->cellspacing = '0';
|
||||
$table->width = '90%';
|
||||
$table->data = [];
|
||||
$table->size = [];
|
||||
|
||||
$url = $config['homeurl'];
|
||||
$url .= 'index.php?sec=estado&sec2=operation/agentes/alerts_status';
|
||||
$url .= '&refr=60&filter=fired&filter_standby=all';
|
||||
|
||||
$flag = false;
|
||||
foreach ($groups as $id_group => $name) {
|
||||
$alerts_group = get_group_alerts($id_group);
|
||||
if (isset($alerts_group['simple']) === true) {
|
||||
$alerts_group = $alerts_group['simple'];
|
||||
}
|
||||
|
||||
foreach ($alerts_group as $alert) {
|
||||
$data = [];
|
||||
|
||||
if ($alert['times_fired'] == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$flag = true;
|
||||
|
||||
$data[0] = '<a href="'.$url.'&ag_group='.$id_group.'">';
|
||||
$data[0] .= ui_print_group_icon(
|
||||
$id_group,
|
||||
true,
|
||||
'groups_small',
|
||||
'',
|
||||
false
|
||||
);
|
||||
$data[0] .= '</a>';
|
||||
|
||||
$data[1] = '<a href="'.$url.'&free_search='.$alert['agent_name'].'">';
|
||||
$data[1] .= $alert['agent_name'];
|
||||
$data[1] .= '</a>';
|
||||
|
||||
$data[2] = $alert['agent_module_name'];
|
||||
|
||||
$data[3] = ui_print_timestamp($alert['last_fired'], true);
|
||||
|
||||
array_push($table->data, $data);
|
||||
}
|
||||
}
|
||||
|
||||
if ($flag === true) {
|
||||
$height = (count($table->data) * 30);
|
||||
$style = 'min-width:300px; min-height:'.$height.'px;';
|
||||
$output .= '<div class="container-center" style="'.$style.'">';
|
||||
$output .= html_print_table($table, true);
|
||||
$output .= '</div>';
|
||||
} else {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_info_message(
|
||||
__('Not alert fired'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
}
|
||||
} else {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_info_message(
|
||||
__('You must select some group'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Triggered alerts report');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'alerts_fired';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,300 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Clock Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Clock
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Clock Widgets
|
||||
*/
|
||||
class ClockWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Clock');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'clock';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['clockType']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Type clock.
|
||||
$fields = [
|
||||
'analogic' => __('Analogic'),
|
||||
'digital' => __('Digital'),
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Type'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'clockType',
|
||||
'selected' => $values['clockType'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['clockType'] = \get_parameter('clockType', 0);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$size = parent::getSize();
|
||||
include_once $config['homedir'].'/include/graphs/functions_d3.php';
|
||||
|
||||
$id = \uniqid();
|
||||
$output = '<div class="container-center">';
|
||||
if ($this->values['clockType'] === 'analogic') {
|
||||
$posAnolgic = (int) $size['height'];
|
||||
if ((int) $size['width'] < (int) $size['height']) {
|
||||
$posAnolgic = (int) $size['width'];
|
||||
}
|
||||
|
||||
$output .= "<div id='clock_".$id."' style=''>";
|
||||
$output .= print_clock_analogic_1(
|
||||
'time',
|
||||
$config['timezone'],
|
||||
'analogic_1',
|
||||
$posAnolgic,
|
||||
$posAnolgic,
|
||||
$id,
|
||||
'#000000',
|
||||
false
|
||||
);
|
||||
$output .= '</div>';
|
||||
} else {
|
||||
$output .= "<div id='clock_".$id."' style=''>";
|
||||
$output .= print_clock_digital_1(
|
||||
'time',
|
||||
$config['timezone'],
|
||||
'digital_1',
|
||||
$size['width'],
|
||||
$size['height'],
|
||||
$id,
|
||||
'#000000'
|
||||
);
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Clock');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'clock';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,388 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Custom graph Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Custom graph
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Custom graph Widgets
|
||||
*/
|
||||
class CustomGraphWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Defined custom graph');
|
||||
|
||||
// Name.
|
||||
$this->name = 'custom_graph';
|
||||
|
||||
// Don't forget to include here.
|
||||
// the headers needed for any configuration file.
|
||||
include_once $config['homedir'].'/include/functions_custom_graphs.php';
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['id_graph']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Default values.
|
||||
if (isset($values['period']) === false) {
|
||||
$values['period'] = SECONDS_1DAY;
|
||||
}
|
||||
|
||||
if (isset($values['showLegend']) === false) {
|
||||
$values['showLegend'] = 1;
|
||||
}
|
||||
|
||||
// Custom graph.
|
||||
$fields = \custom_graphs_get_user();
|
||||
$inputs[] = [
|
||||
'label' => __('Graph'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'id_graph',
|
||||
'selected' => $values['id_graph'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Type charts.
|
||||
$fields = [
|
||||
CUSTOM_GRAPH_AREA => __('Area'),
|
||||
CUSTOM_GRAPH_STACKED_AREA => __('Stacked area'),
|
||||
CUSTOM_GRAPH_LINE => __('Line'),
|
||||
CUSTOM_GRAPH_STACKED_LINE => __('Stacked line'),
|
||||
CUSTOM_GRAPH_BULLET_CHART => __('Bullet chart'),
|
||||
CUSTOM_GRAPH_GAUGE => __('Gauge'),
|
||||
CUSTOM_GRAPH_HBARS => __('Horizontal Bars'),
|
||||
CUSTOM_GRAPH_VBARS => __('Vertical Bars'),
|
||||
CUSTOM_GRAPH_PIE => __('Pie'),
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Type'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'type',
|
||||
'selected' => $values['type'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Show legend.
|
||||
$inputs[] = [
|
||||
'label' => __('Show legend'),
|
||||
'arguments' => [
|
||||
'name' => 'showLegend',
|
||||
'id' => 'showLegend',
|
||||
'type' => 'switch',
|
||||
'value' => $values['showLegend'],
|
||||
],
|
||||
];
|
||||
|
||||
// Period.
|
||||
$inputs[] = [
|
||||
'label' => __('Interval'),
|
||||
'arguments' => [
|
||||
'name' => 'period',
|
||||
'type' => 'interval',
|
||||
'value' => $values['period'],
|
||||
'nothing' => __('None'),
|
||||
'nothing_value' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['id_graph'] = \get_parameter('id_graph', 0);
|
||||
$values['type'] = \get_parameter('type', 0);
|
||||
$values['period'] = \get_parameter('period', 0);
|
||||
$values['showLegend'] = \get_parameter_switch('showLegend');
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
switch ($this->values['type']) {
|
||||
case CUSTOM_GRAPH_STACKED_LINE:
|
||||
case CUSTOM_GRAPH_STACKED_AREA:
|
||||
case CUSTOM_GRAPH_AREA:
|
||||
case CUSTOM_GRAPH_LINE:
|
||||
if ($this->values['showLegend'] === 1) {
|
||||
$sources = db_get_all_rows_field_filter(
|
||||
'tgraph_source',
|
||||
'id_graph',
|
||||
$this->values['id_graph'],
|
||||
'field_order'
|
||||
);
|
||||
|
||||
$hackLegendHight = (30 * count($sources));
|
||||
if ($hackLegendHight < ($size['height'] - 10 - $hackLegendHight)) {
|
||||
$height = ($size['height'] - 10 - $hackLegendHight);
|
||||
} else {
|
||||
$height = ($size['height'] - 10);
|
||||
$this->values['showLegend'] = 0;
|
||||
}
|
||||
} else {
|
||||
$height = ($size['height'] - 10);
|
||||
}
|
||||
|
||||
$output = '<div class="container-center">';
|
||||
break;
|
||||
|
||||
case CUSTOM_GRAPH_VBARS:
|
||||
$style = 'padding: 10px;';
|
||||
$height = $size['height'];
|
||||
$output = '<div class="container-center" style="'.$style.'">';
|
||||
break;
|
||||
|
||||
case CUSTOM_GRAPH_GAUGE:
|
||||
$height = $size['height'];
|
||||
$output = '<div class="container-gauges-dashboard">';
|
||||
break;
|
||||
|
||||
default:
|
||||
$height = $size['height'];
|
||||
$output = '<div class="container-center">';
|
||||
break;
|
||||
}
|
||||
|
||||
$params = [
|
||||
'period' => $this->values['period'],
|
||||
'width' => ($size['width'] - 10),
|
||||
'height' => $height,
|
||||
'only_image' => false,
|
||||
'homeurl' => $config['homeurl'],
|
||||
'percentil' => $percentil,
|
||||
'backgroundColor' => 'transparent',
|
||||
'menu' => false,
|
||||
'show_legend' => $this->values['showLegend'],
|
||||
'vconsole' => true,
|
||||
];
|
||||
|
||||
$params_combined = [
|
||||
'stacked' => (int) $this->values['type'],
|
||||
'id_graph' => (int) $this->values['id_graph'],
|
||||
];
|
||||
|
||||
$output .= graphic_combined_module(
|
||||
false,
|
||||
$params,
|
||||
$params_combined
|
||||
);
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Defined custom graph');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'custom_graph';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,560 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Event list Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Event list
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Event list Widgets
|
||||
*/
|
||||
class EventsListWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// Includes.
|
||||
include_once $config['homedir'].'/include/functions_events.php';
|
||||
include_once $config['homedir'].'/include/functions_users.php';
|
||||
include_once $config['homedir'].'/include/functions_agents.php';
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('List of latest events');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'events_list';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (isset($this->values['groupId']) === false) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
global $config;
|
||||
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
$fields = \get_event_types();
|
||||
$fields['not_normal'] = __('Not normal');
|
||||
|
||||
// Default values.
|
||||
if (isset($values['maxHours']) === false) {
|
||||
$values['maxHours'] = 8;
|
||||
}
|
||||
|
||||
if (isset($values['limit']) === false) {
|
||||
$values['limit'] = $config['block_size'];
|
||||
}
|
||||
|
||||
// Event Type.
|
||||
$inputs[] = [
|
||||
'label' => __('Event type'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'eventType',
|
||||
'selected' => $values['eventType'],
|
||||
'return' => true,
|
||||
'nothing' => __('Any'),
|
||||
'nothing_value' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Max. hours old. Default 8.
|
||||
$inputs[] = [
|
||||
'label' => __('Max. hours old'),
|
||||
'arguments' => [
|
||||
'name' => 'maxHours',
|
||||
'type' => 'number',
|
||||
'value' => $values['maxHours'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Limit Default block_size.
|
||||
$blockSizeD4 = \format_integer_round(($config['block_size'] / 4));
|
||||
$blockSizeD2 = \format_integer_round(($config['block_size'] / 2));
|
||||
$fields = [
|
||||
$config['block_size'] => $config['block_size'],
|
||||
$blockSizeD4 => $blockSizeD4,
|
||||
$blockSizeD2 => $blockSizeD2,
|
||||
($config['block_size'] * 2) => ($config['block_size'] * 2),
|
||||
($config['block_size'] * 3) => ($config['block_size'] * 3),
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Limit'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'limit',
|
||||
'selected' => $values['limit'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Event status.
|
||||
$fields = [
|
||||
-1 => __('All event'),
|
||||
1 => __('Only validated'),
|
||||
0 => __('Only pending'),
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Event status'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'eventStatus',
|
||||
'selected' => $values['eventStatus'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Severity.
|
||||
$fields = \get_priorities();
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Severity'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'severity',
|
||||
'selected' => $values['severity'],
|
||||
'return' => true,
|
||||
'nothing' => __('All'),
|
||||
'nothing_value' => -1,
|
||||
],
|
||||
];
|
||||
|
||||
// Groups.
|
||||
$inputs[] = [
|
||||
'label' => __('Groups'),
|
||||
'arguments' => [
|
||||
'type' => 'select_groups',
|
||||
'name' => 'groupId[]',
|
||||
'returnAllGroup' => true,
|
||||
'privilege' => 'AR',
|
||||
'selected' => explode(',', $values['groupId'][0]),
|
||||
'return' => true,
|
||||
'multiple' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Tags.
|
||||
$fields = tags_get_user_tags($config['id_user'], 'AR');
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Tags'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'tagsId[]',
|
||||
'selected' => explode(',', $values['tagsId'][0]),
|
||||
'return' => true,
|
||||
'multiple' => true,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['eventType'] = \get_parameter('eventType', 0);
|
||||
$values['maxHours'] = \get_parameter('maxHours', 8);
|
||||
$values['limit'] = \get_parameter('limit', 20);
|
||||
$values['eventStatus'] = \get_parameter('eventStatus', -1);
|
||||
$values['severity'] = \get_parameter_switch('severity', -1);
|
||||
$values['groupId'] = \get_parameter_switch('groupId', []);
|
||||
$values['tagsId'] = \get_parameter_switch('tagsId', []);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$output = '';
|
||||
$user_groups = \users_get_groups();
|
||||
|
||||
ui_require_css_file('events', 'include/styles/', true);
|
||||
ui_require_css_file('tables', 'include/styles/', true);
|
||||
|
||||
$this->values['groupId'] = explode(',', $this->values['groupId'][0]);
|
||||
$this->values['tagsId'] = explode(',', $this->values['tagsId'][0]);
|
||||
|
||||
if (empty($this->values['groupId']) === true) {
|
||||
$output .= __('You must select some group');
|
||||
return $output;
|
||||
}
|
||||
|
||||
foreach ($this->values['groupId'] as $id_group) {
|
||||
// Sanity check for user access.
|
||||
if (isset($user_groups[$id_group]) === false) {
|
||||
$output .= __('You must select some group');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$useTags = \tags_has_user_acl_tags($config['id_user']);
|
||||
if ($useTags) {
|
||||
if (empty($this->values['tagsId']) === true) {
|
||||
$output .= __('You don\'t have access');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$hours = ($this->values['maxHours'] * SECONDS_1HOUR);
|
||||
$unixtime = (get_system_time() - $hours);
|
||||
|
||||
// Put hours in seconds.
|
||||
$filter = [];
|
||||
// Group all.
|
||||
if (in_array(0, $this->values['groupId'])) {
|
||||
$filter['id_grupo'] = array_keys(users_get_groups());
|
||||
} else {
|
||||
$filter['id_grupo'] = $this->values['groupId'];
|
||||
}
|
||||
|
||||
$filter['utimestamp'] = '>'.$unixtime;
|
||||
|
||||
if (empty($this->values['eventType']) === false) {
|
||||
$filter['event_type'] = $this->values['eventType'];
|
||||
|
||||
if ($filter['event_type'] === 'warning'
|
||||
|| $filter['event_type'] === 'critical'
|
||||
|| $filter['event_type'] === 'normal'
|
||||
) {
|
||||
$filter['event_type'] = '%'.$filter['event_type'].'%';
|
||||
} else if ($filter['event_type'] === 'not_normal') {
|
||||
unset($filter['event_type']);
|
||||
$filter[] = '(event_type REGEXP "warning|critical|unknown")';
|
||||
}
|
||||
}
|
||||
|
||||
if ((int) $this->values['eventStatus'] !== -1) {
|
||||
$filter['estado'] = $this->values['eventStatus'];
|
||||
}
|
||||
|
||||
$filter['limit'] = $this->values['limit'];
|
||||
$filter['order'] = '`utimestamp` DESC';
|
||||
|
||||
if ((int) $this->values['severity'] !== -1) {
|
||||
$filter['criticity'] = $this->values['severity'];
|
||||
}
|
||||
|
||||
if (empty($this->values['tagsId']) === false) {
|
||||
foreach ($this->values['tagsId'] as $tag) {
|
||||
$tag_name[$tag] = \tags_get_name($tag);
|
||||
}
|
||||
|
||||
$filter['tags'] = $tag_name;
|
||||
}
|
||||
|
||||
$events = \events_get_events($filter);
|
||||
|
||||
if ($events === false) {
|
||||
$events = [];
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
if (isset($events) === true
|
||||
&& is_array($events) === true
|
||||
&& empty($events) === false
|
||||
) {
|
||||
$output .= html_print_input_hidden(
|
||||
'ajax_file',
|
||||
ui_get_full_url('ajax.php', false, false, false),
|
||||
true
|
||||
);
|
||||
|
||||
$table = new \StdClass;
|
||||
$table->class = 'widget_groups_status databox';
|
||||
$table->cellspacing = '1';
|
||||
$table->width = '100%';
|
||||
$table->data = [];
|
||||
$table->size = [];
|
||||
$table->rowclass = [];
|
||||
|
||||
foreach ($events as $event) {
|
||||
$data = [];
|
||||
$event['evento'] = io_safe_output($event['evento']);
|
||||
if ($event['estado'] === 0) {
|
||||
$img = 'images/pixel_red.png';
|
||||
} else {
|
||||
$img = 'images/pixel_green.png';
|
||||
}
|
||||
|
||||
$data[0] = events_print_type_img($event['event_type'], true);
|
||||
$agent_alias = agents_get_alias($event['id_agente']);
|
||||
|
||||
if ($agent_alias !== '') {
|
||||
$data[1] = '<a href="'.$config['homeurl'];
|
||||
$data[1] .= 'index.php?sec=estado';
|
||||
$data[1] .= '&sec2=operation/agentes/ver_agente';
|
||||
$data[1] .= '&id_agente='.$event['id_agente'];
|
||||
$data[1] .= '" title="'.$event['evento'].'">';
|
||||
$data[1] .= $agent_alias;
|
||||
$data[1] .= '</a>';
|
||||
} else {
|
||||
$data[1] = '<em>'.__('Unknown').'</em>';
|
||||
}
|
||||
|
||||
$settings = json_encode(
|
||||
[
|
||||
'event' => $event,
|
||||
'page' => 'include/ajax/events',
|
||||
'cellId' => $id_cell,
|
||||
'ajaxUrl' => ui_get_full_url(
|
||||
'ajax.php',
|
||||
false,
|
||||
false,
|
||||
false
|
||||
),
|
||||
'result' => false,
|
||||
]
|
||||
);
|
||||
|
||||
$data[2] = '<a href="javascript:"onclick="dashboardShowEventDialog(\''.base64_encode($settings).'\');">';
|
||||
$data[2] .= substr(io_safe_output($event['evento']), 0, 150);
|
||||
if (strlen($event['evento']) > 150) {
|
||||
$data[2] .= '...';
|
||||
}
|
||||
|
||||
$data[2] .= '<a>';
|
||||
|
||||
$data[3] = ui_print_timestamp($event['timestamp'], true);
|
||||
|
||||
$table->data[$i] = $data;
|
||||
|
||||
$table->cellstyle[$i][0] = 'background: #E8E8E8;';
|
||||
$rowclass = get_priority_class($event['criticity']);
|
||||
$table->cellclass[$i][1] = $rowclass;
|
||||
$table->cellclass[$i][2] = $rowclass;
|
||||
$table->cellclass[$i][3] = $rowclass;
|
||||
$i++;
|
||||
}
|
||||
|
||||
$output .= html_print_table($table, true);
|
||||
$output .= "<div id='event_details_window'></div>";
|
||||
$output .= "<div id='event_response_window'></div>";
|
||||
$output .= "<div id='event_response_command_window' title='".__('Parameters')."'></div>";
|
||||
$output .= ui_require_javascript_file(
|
||||
'pandora_events',
|
||||
'include/javascript/',
|
||||
true
|
||||
);
|
||||
} else {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_info_message(
|
||||
__('There are no events matching selected search filters'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('List of latest events');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'events_list';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,275 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Example Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Example
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Example Widgets
|
||||
*/
|
||||
class WelcomeWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Welcome message to %s', get_product_name());
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'example';
|
||||
}
|
||||
|
||||
$this->configurationRequired = false;
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['agentId'] = \get_parameter('agentId', 0);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
$output = '';
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
if (isset($this->values['message']) === true) {
|
||||
$output .= \io_safe_output(
|
||||
str_replace('
', '<br>', $this->values['message'])
|
||||
);
|
||||
return $output;
|
||||
}
|
||||
|
||||
$style = 'height:'.$size['height'].'px; width:'.$size['width'].'px;';
|
||||
$style .= 'text-align: left;';
|
||||
|
||||
$output .= '<div style="'.$style.'">';
|
||||
$output .= '<h2>';
|
||||
$output .= __('Welcome to %s', \get_product_name());
|
||||
$output .= '</h2>';
|
||||
$output .= '<div style="display:flex; flex-direction:row; align-items:center">';
|
||||
$output .= '<div style="width:75%;">';
|
||||
$output .= __('This is an example of a dashboard widget. A widget may contain elements');
|
||||
$output .= __('To add more elements, click on "<em>Add widgets</em>" on the top of this page.');
|
||||
$output .= __('To delete this message, click on the delete button on top right corner of this element.');
|
||||
$output .= __('To do so, just click on the title and drag and drop it to the desired place.');
|
||||
$output .= __('To delete this message, click on the delete button on top right corner of this element.');
|
||||
$output .= __('Thanks for using %s.', \get_product_name());
|
||||
$output .= '</div>';
|
||||
$output .= "<div style='width:25%;'>";
|
||||
$output .= \html_print_image(
|
||||
\ui_get_logo_to_center_networkmap(),
|
||||
true,
|
||||
['style' => 'margin-top:-27px;width:75%;']
|
||||
);
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Welcome message to %s', get_product_name());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'example';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,402 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Histogram Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Histogram
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
global $config;
|
||||
|
||||
/**
|
||||
* Histogram Widgets
|
||||
*/
|
||||
class GraphModuleHistogramWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// Includes.
|
||||
include_once $config['homedir'].'/include/functions_agents.php';
|
||||
include_once $config['homedir'].'/include/functions_modules.php';
|
||||
include_once $config['homedir'].'/include/functions_reporting.php';
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Module histogram');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'graph_module_histogram';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['moduleId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Default values.
|
||||
if (isset($values['period']) === false) {
|
||||
$values['period'] = SECONDS_1DAY;
|
||||
}
|
||||
|
||||
if (isset($values['sizeLabel']) === false) {
|
||||
$values['sizeLabel'] = 30;
|
||||
}
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Label.
|
||||
$inputs[] = [
|
||||
'label' => __('Label'),
|
||||
'arguments' => [
|
||||
'name' => 'label',
|
||||
'type' => 'text',
|
||||
'value' => $values['label'],
|
||||
'return' => true,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Autocomplete agents.
|
||||
$inputs[] = [
|
||||
'label' => __('Agent'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_agent',
|
||||
'name' => 'agentAlias',
|
||||
'id_agent_hidden' => $values['agentId'],
|
||||
'name_agent_hidden' => 'agentId',
|
||||
'server_id_hidden' => $values['metaconsoleId'],
|
||||
'name_server_hidden' => 'metaconsoleId',
|
||||
'return' => true,
|
||||
'module_input' => true,
|
||||
'module_name' => 'moduleId',
|
||||
'module_none' => false,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Autocomplete module.
|
||||
$inputs[] = [
|
||||
'label' => __('Module'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_module',
|
||||
'fields' => $fields,
|
||||
'name' => 'moduleId',
|
||||
'selected' => $values['moduleId'],
|
||||
'return' => true,
|
||||
'sort' => false,
|
||||
'agent_id' => $values['agentId'],
|
||||
'metaconsole_id' => $values['metaconsoleId'],
|
||||
'style' => 'width: inherit;',
|
||||
],
|
||||
];
|
||||
|
||||
// Periodicity.
|
||||
$inputs[] = [
|
||||
'label' => __('Interval'),
|
||||
'arguments' => [
|
||||
'name' => 'period',
|
||||
'type' => 'interval',
|
||||
'value' => $values['period'],
|
||||
'nothing' => __('None'),
|
||||
'nothing_value' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Text size of label in px.
|
||||
$inputs[] = [
|
||||
'label' => __('Text size of label in px'),
|
||||
'arguments' => [
|
||||
'name' => 'sizeLabel',
|
||||
'type' => 'number',
|
||||
'value' => $values['sizeLabel'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['label'] = \get_parameter('label', '');
|
||||
$values['agentId'] = \get_parameter('agentId', 0);
|
||||
$values['metaconsoleId'] = \get_parameter('metaconsoleId', 0);
|
||||
$values['moduleId'] = \get_parameter('moduleId', 0);
|
||||
$values['period'] = \get_parameter('period', 0);
|
||||
$values['sizeLabel'] = \get_parameter_switch('sizeLabel', 0);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
// Desactive scroll bars only this item.
|
||||
$output .= '<style type="text/css">
|
||||
.grid-stack-item .grid-stack-item-content .content-widget {
|
||||
overflow-x: hidden;
|
||||
overflow-y: hidden;
|
||||
}
|
||||
</style>';
|
||||
$id_agent = $this->values['agentId'];
|
||||
$id_module = $this->values['moduleId'];
|
||||
$period = $this->values['period'];
|
||||
$label = $this->values['label'];
|
||||
$size_label = $this->values['sizeLabel'];
|
||||
|
||||
$id_group = \agents_get_agent_group($id_agent);
|
||||
|
||||
if (check_acl($config['id_user'], $id_group, 'AR') === 0) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('You don\'t have access'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
if (modules_get_agentmodule_agent($id_module) !== (int) $id_agent) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('You don\'t have access'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
$content = [
|
||||
'id_agent_module' => $id_module,
|
||||
'period' => $period,
|
||||
'time_from' => '00:00:00',
|
||||
'time_to' => '00:00:00',
|
||||
'id_group' => $id_group,
|
||||
'sizeForTicks' => $size['width'],
|
||||
[
|
||||
['id_agent_module' => $id_module],
|
||||
]
|
||||
];
|
||||
|
||||
$graph = \reporting_module_histogram_graph(
|
||||
['datetime' => time()],
|
||||
$content
|
||||
);
|
||||
|
||||
$style = 'min-width:200px; min-height:100px;';
|
||||
$output .= '<div class="container-center" style="'.$style.'">';
|
||||
$output .= '<div style="font-size:'.$size_label.'px;">';
|
||||
$output .= $label;
|
||||
$output .= '</div>';
|
||||
$style = 'min-width:200px; width:'.($size['width'] + 15).'px;';
|
||||
$output .= '<div class="widget-histogram-chart" style="'.$style.'">';
|
||||
$output .= $graph['chart'];
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Module histogram');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'graph_module_histogram';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,488 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Group status Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Group status
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Group status Widgets.
|
||||
*/
|
||||
class GroupsStatusWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('General group status');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'groups_status';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['groupId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Restrict access to group.
|
||||
$inputs[] = [
|
||||
'label' => __('Groups'),
|
||||
'arguments' => [
|
||||
'type' => 'select_groups',
|
||||
'name' => 'groupId',
|
||||
'returnAllGroup' => false,
|
||||
'privilege' => 'AR',
|
||||
'selected' => $values['groupId'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['groupId'] = \get_parameter('groupId', 0);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
include_once $config['homedir'].'/include/functions_reporting.php';
|
||||
include_once $config['homedir'].'/include/functions_graph.php';
|
||||
|
||||
$output = '';
|
||||
// Check ACL.
|
||||
$user_groups = \users_get_groups(false, 'AR', false);
|
||||
|
||||
if (empty($this->values['groupId']) === true) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('You don\'t have access'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
// Sanity check for user access.
|
||||
if (isset($user_groups[$this->values['groupId']]) === false) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('You don\'t have access'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
$stats = \reporting_get_group_stats_resume($this->values['groupId']);
|
||||
|
||||
$data = '<div class="widget-groups-status"><span>';
|
||||
$data .= ui_print_group_icon(
|
||||
$this->values['groupId'],
|
||||
true,
|
||||
'groups_small',
|
||||
'width:50px; padding-right: 10px'
|
||||
);
|
||||
$data .= '</span>';
|
||||
|
||||
$url = $config['homeurl'];
|
||||
$url .= 'index.php?sec=estado&sec2=operation/agentes/estado_agente';
|
||||
$url .= '&refr=60&group_id='.$this->values['groupId'];
|
||||
$data .= '<h1>';
|
||||
$data .= '<a href="'.$url.'">';
|
||||
$data .= $user_groups[$this->values['groupId']];
|
||||
$data .= '</a>';
|
||||
$data .= '</h1></div>';
|
||||
|
||||
$data .= '<div class="div_groups_status" style="clear: both;">';
|
||||
|
||||
$table = new \stdClass();
|
||||
$table->class = 'widget_groups_status';
|
||||
$table->cellspacing = '0';
|
||||
$table->width = '100%';
|
||||
$table->data = [];
|
||||
$table->size = [];
|
||||
$table->colspan = [];
|
||||
$table->cellstyle = [];
|
||||
|
||||
$table->size[0] = '50%';
|
||||
$table->size[1] = '50%';
|
||||
|
||||
$style = 'border-bottom:1px solid #ECECEC; text-align: center;';
|
||||
$table->cellstyle[0][0] = $style;
|
||||
$table->cellstyle[0][1] = $style;
|
||||
$table->cellstyle[1][0] = 'padding-top: 10px;';
|
||||
$table->cellstyle[1][1] = 'padding-top: 10px;';
|
||||
|
||||
// Head agents.
|
||||
$table->data[0][0] = '<span>';
|
||||
$table->data[0][0] .= html_print_image(
|
||||
'images/agent.png',
|
||||
true,
|
||||
['alt' => __('Agents')]
|
||||
);
|
||||
$table->data[0][0] .= ' <b>';
|
||||
$table->data[0][0] .= __('Agents');
|
||||
$table->data[0][0] .= '</b>';
|
||||
$table->data[0][0] .= '</span>';
|
||||
$table->data[0][1] = '<span>';
|
||||
$table->data[0][1] .= '<b>';
|
||||
$table->data[0][1] .= $stats['total_agents'];
|
||||
$table->data[0][1] .= '</b>';
|
||||
$table->data[0][1] .= '</span>';
|
||||
|
||||
if ($stats['total_agents'] !== 0) {
|
||||
// Agent Critical.
|
||||
$table->data[1][0] = $this->getCellCounter(
|
||||
$stats['agent_critical'],
|
||||
'#e63c52'
|
||||
);
|
||||
|
||||
// Agent Warning.
|
||||
$table->data[2][0] = $this->getCellCounter(
|
||||
$stats['agent_warning'],
|
||||
'#f3b200'
|
||||
);
|
||||
|
||||
// Agent OK.
|
||||
$table->data[3][0] = $this->getCellCounter(
|
||||
$stats['agent_ok'],
|
||||
'#82b92e'
|
||||
);
|
||||
|
||||
// Agent Unknown.
|
||||
$table->data[1][1] = $this->getCellCounter(
|
||||
$stats['agent_unknown'],
|
||||
'#B2B2B2'
|
||||
);
|
||||
|
||||
// Agent Not Init.
|
||||
$table->data[2][1] = $this->getCellCounter(
|
||||
$stats['agent_not_init'],
|
||||
'#5bb6e5'
|
||||
);
|
||||
|
||||
$data .= html_print_table($table, true);
|
||||
$data .= '</div>';
|
||||
|
||||
$data .= '<div class="div_groups_status">';
|
||||
|
||||
$table = new \stdClass();
|
||||
$table->class = 'widget_groups_status';
|
||||
$table->cellspacing = '0';
|
||||
$table->width = '100%';
|
||||
$table->data = [];
|
||||
$table->size = [];
|
||||
$table->colspan = [];
|
||||
$table->cellstyle = [];
|
||||
|
||||
$table->size[0] = '50%';
|
||||
$table->size[1] = '50%';
|
||||
|
||||
$style = 'border-bottom:1px solid #ECECEC; text-align: center;';
|
||||
$table->cellstyle[0][0] = $style;
|
||||
$table->cellstyle[0][1] = $style;
|
||||
$table->cellstyle[1][0] = 'padding-top: 20px;';
|
||||
$table->cellstyle[1][1] = 'padding-top: 20px;';
|
||||
|
||||
// Head Modules.
|
||||
$table->data[0][0] = '<span>';
|
||||
$table->data[0][0] .= html_print_image(
|
||||
'images/module.png',
|
||||
true,
|
||||
['alt' => __('Modules')]
|
||||
);
|
||||
|
||||
$table->data[0][0] .= '<b>';
|
||||
$table->data[0][0] .= __('Modules');
|
||||
$table->data[0][0] .= '</b>';
|
||||
$table->data[0][0] .= '</span>';
|
||||
$table->data[0][1] = '<span>';
|
||||
$table->data[0][1] .= '<b>';
|
||||
$table->data[0][1] .= $stats['monitor_total'];
|
||||
$table->data[0][1] .= '</b>';
|
||||
$table->data[0][1] .= '</span>';
|
||||
|
||||
// Modules Critical.
|
||||
$table->data[1][0] = $this->getCellCounter(
|
||||
$stats['monitor_critical'],
|
||||
'#e63c52'
|
||||
);
|
||||
|
||||
// Modules Warning.
|
||||
$table->data[2][0] = $this->getCellCounter(
|
||||
$stats['monitor_warning'],
|
||||
'#f3b200'
|
||||
);
|
||||
|
||||
// Modules OK.
|
||||
$table->data[3][0] = $this->getCellCounter(
|
||||
$stats['monitor_ok'],
|
||||
'#82b92e'
|
||||
);
|
||||
|
||||
// Modules Unknown.
|
||||
$table->data[1][1] = $this->getCellCounter(
|
||||
$stats['monitor_unknown'],
|
||||
'#B2B2B2'
|
||||
);
|
||||
|
||||
// Modules Not Init.
|
||||
$table->data[2][1] = $this->getCellCounter(
|
||||
$stats['monitor_not_init'],
|
||||
'#5bb6e5'
|
||||
);
|
||||
|
||||
$data .= html_print_table($table, true);
|
||||
$data .= '</div>';
|
||||
} else {
|
||||
// Not agents in this group.
|
||||
$table->colspan[1][0] = 2;
|
||||
$table->data[1][0] = __('Not agents in this group');
|
||||
$data .= html_print_table($table, true);
|
||||
$data .= '</div>';
|
||||
}
|
||||
|
||||
$style = 'min-width:200px; min-height:460px;';
|
||||
$output = '<div class="container-center" style="'.$style.'">';
|
||||
$output .= $data;
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw cell.
|
||||
*
|
||||
* @param integer|null $count Counter.
|
||||
* @param string $color Background color cell.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCellCounter(?int $count, string $color):string
|
||||
{
|
||||
$output = '<div class= ""';
|
||||
$output .= 'style= "background-color:'.$color.'">';
|
||||
if (isset($count) === true
|
||||
&& $count !== 0
|
||||
) {
|
||||
$output .= $count;
|
||||
} else {
|
||||
$output .= 0;
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('General group status');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'groups_status';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,426 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Maps by users Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Maps by users
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
// Load Visual Console.
|
||||
use Models\VisualConsole\Container as VisualConsole;
|
||||
|
||||
/**
|
||||
* Maps by users Widgets.
|
||||
*/
|
||||
class MapsMadeByUser extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
/**
|
||||
* Cell Id.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $cellId;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// Include.
|
||||
include_once $config['homedir'].'/include/graphs/functions_d3.php';
|
||||
include_once $config['homedir'].'/include/functions_visual_map.php';
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Cell Id.
|
||||
$this->cellId = $cellId;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Visual Console');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'maps_made_by_user';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['vcId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
global $config;
|
||||
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
$fields = \visual_map_get_user_layouts($config['id_user'], true);
|
||||
|
||||
// Event Type.
|
||||
$inputs[] = [
|
||||
'label' => __('Event type'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'vcId',
|
||||
'selected' => $values['vcId'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['vcId'] = \get_parameter('vcId', 0);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
$visualConsole = null;
|
||||
try {
|
||||
$visualConsole = VisualConsole::fromDB(
|
||||
['id' => $this->values['vcId']]
|
||||
);
|
||||
} catch (Throwable $e) {
|
||||
db_pandora_audit(
|
||||
'ACL Violation',
|
||||
'Trying to access visual console without Id'
|
||||
);
|
||||
include 'general/noaccess.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
$size['width'] = ($size['width'] + 30);
|
||||
|
||||
$visualConsoleData = $visualConsole->toArray();
|
||||
$ratio_visualconsole = ($visualConsoleData['height'] / $visualConsoleData['width']);
|
||||
$ratio_t = ($size['width'] / $visualConsoleData['width']);
|
||||
$radio_h = ($size['height'] / $visualConsoleData['height']);
|
||||
|
||||
$visualConsoleData['width'] = $size['width'];
|
||||
$visualConsoleData['height'] = ($size['width'] * $ratio_visualconsole);
|
||||
|
||||
if ($visualConsoleData['height'] > $size['height']) {
|
||||
$ratio_t = $radio_h;
|
||||
|
||||
$visualConsoleData['height'] = $size['height'];
|
||||
$visualConsoleData['width'] = ($size['height'] / $ratio_visualconsole);
|
||||
}
|
||||
|
||||
$groupId = $visualConsoleData['groupId'];
|
||||
$visualConsoleName = $visualConsoleData['name'];
|
||||
|
||||
// ACL.
|
||||
$aclRead = check_acl($config['id_user'], $groupId, 'VR');
|
||||
$aclWrite = check_acl($config['id_user'], $groupId, 'VW');
|
||||
$aclManage = check_acl($config['id_user'], $groupId, 'VM');
|
||||
|
||||
if ($aclRead === 0 && $aclWrite === 0 && $aclManage === 0) {
|
||||
db_pandora_audit(
|
||||
'ACL Violation',
|
||||
'Trying to access visual console without group access'
|
||||
);
|
||||
include 'general/noaccess.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
$uniq = uniqid();
|
||||
|
||||
$output = '<div class="container-center">';
|
||||
// Style.
|
||||
$style = 'width:'.$visualConsoleData['width'].'px;';
|
||||
// Class.
|
||||
$class = 'visual-console-container-dashboard c-'.$uniq;
|
||||
// Id.
|
||||
$id = 'visual-console-container-'.$this->cellId;
|
||||
$output .= '<div style="'.$style.'" class="'.$class.'" id="'.$id.'">';
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
|
||||
// Check groups can access user.
|
||||
$aclUserGroups = [];
|
||||
if (users_can_manage_group_all('AR') === true) {
|
||||
$aclUserGroups = array_keys(
|
||||
users_get_groups(false, 'AR')
|
||||
);
|
||||
}
|
||||
|
||||
$ignored_params['refr'] = '';
|
||||
\ui_require_javascript_file(
|
||||
'tiny_mce',
|
||||
'include/javascript/tiny_mce/'
|
||||
);
|
||||
\ui_require_javascript_file(
|
||||
'pandora_visual_console',
|
||||
'include/javascript/',
|
||||
true
|
||||
);
|
||||
\include_javascript_d3();
|
||||
\visual_map_load_client_resources();
|
||||
|
||||
// Load Visual Console Items.
|
||||
$visualConsoleItems = VisualConsole::getItemsFromDB(
|
||||
$this->values['vcId'],
|
||||
$aclUserGroups,
|
||||
$ratio_t
|
||||
);
|
||||
|
||||
// Horrible trick! due to the use of tinyMCE
|
||||
// it is necessary to modify specific classes of each
|
||||
// of the visual consoles.
|
||||
$output .= '<style type="text/css">';
|
||||
$output .= '.c-'.$uniq.', .c-'.$uniq.' *:not(.parent_graph p table tr td span) { font-size: '.(8 * $ratio_t).'pt; line-height:'.(8 * ($ratio_t) * 1.5).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_4pt, .c-'.$uniq.' .visual_font_size_4pt * { font-size: '.(4 * $ratio_t).'pt; line-height:'.(4 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_6pt, .c-'.$uniq.' .visual_font_size_6pt * { font-size: '.(6 * $ratio_t).'pt; line-height:'.(6 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_8pt, .c-'.$uniq.' .visual_font_size_8pt * { font-size: '.(8 * $ratio_t).'pt; line-height:'.(8 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_10pt, .c-'.$uniq.' .visual_font_size_10pt * { font-size: '.(10 * $ratio_t).'pt; line-height:'.(10 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_12pt, .c-'.$uniq.' .visual_font_size_12pt * { font-size: '.(12 * $ratio_t).'pt; line-height:'.(12 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_14pt, .c-'.$uniq.' .visual_font_size_14pt * { font-size: '.(14 * $ratio_t).'pt; line-height:'.(14 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_18pt, .c-'.$uniq.' .visual_font_size_18pt * { font-size: '.(18 * $ratio_t).'pt; line-height:'.(18 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_24pt, .c-'.$uniq.' .visual_font_size_24pt * { font-size: '.(24 * $ratio_t).'pt; line-height:'.(24 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_28pt, .c-'.$uniq.' .visual_font_size_28pt * { font-size: '.(28 * $ratio_t).'pt; line-height:'.(28 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_36pt, .c-'.$uniq.' .visual_font_size_36pt * { font-size: '.(36 * $ratio_t).'pt; line-height:'.(36 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_48pt, .c-'.$uniq.' .visual_font_size_48pt * { font-size: '.(48 * $ratio_t).'pt; line-height:'.(48 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_60pt, .c-'.$uniq.' .visual_font_size_60pt * { font-size: '.(60 * $ratio_t).'pt; line-height:'.(60 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_72pt, .c-'.$uniq.' .visual_font_size_72pt * { font-size: '.(72 * $ratio_t).'pt; line-height:'.(72 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_84pt, .c-'.$uniq.' .visual_font_size_84pt * { font-size: '.(84 * $ratio_t).'pt; line-height:'.(84 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_96pt, .c-'.$uniq.' .visual_font_size_96pt * { font-size: '.(96 * $ratio_t).'pt; line-height:'.(96 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_116pt, .c-'.$uniq.' .visual_font_size_116pt * { font-size: '.(116 * $ratio_t).'pt; line-height:'.(116 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_128pt, .c-'.$uniq.' .visual_font_size_128pt * { font-size: '.(128 * $ratio_t).'pt; line-height:'.(128 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_140pt, .c-'.$uniq.' .visual_font_size_140pt * { font-size: '.(140 * $ratio_t).'pt; line-height:'.(140 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_154pt, .c-'.$uniq.' .visual_font_size_154pt * { font-size: '.(154 * $ratio_t).'pt; line-height:'.(154 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .visual_font_size_196pt, .c-'.$uniq.' .visual_font_size_196pt * { font-size: '.(196 * $ratio_t).'pt; line-height:'.(196 * ($ratio_t)).'pt; }';
|
||||
$output .= '.c-'.$uniq.' .flot-text, .c-'.$uniq.' .flot-text * { font-size: '.(8 * $ratio_t).'pt !important; line-height:'.(8 * ($ratio_t)).'pt !important; }';
|
||||
$output .= '.c-'.$uniq.' .visual-console-item .digital-clock span.time {font-size: '.(50 * $ratio_t).'px !important; line-height: '.(50 * $ratio_t).'px !important;}';
|
||||
$output .= '.c-'.$uniq.' .visual-console-item .digital-clock span.date {font-size: '.(25 * $ratio_t).'px !important; line-height: '.(25 * $ratio_t).'px !important;}';
|
||||
$output .= '.c-'.$uniq.' .visual-console-item .digital-clock span.timezone {font-size: '.(25 * $ratio_t).'px !important; line-height: '.(25 * $ratio_t).'px !important;}';
|
||||
$output .= '.c-'.$uniq.' .visual-console-item .donut-graph * {font-size: '.(8 * $ratio_t).'px !important; line-height: '.(8 * $ratio_t).'px !important;}';
|
||||
$output .= '.c-'.$uniq.' .visual-console-item .donut-graph g rect {width:'.(25 * $ratio_t).' !important; height: '.(15 * $ratio_t).' !important;}';
|
||||
$output .= '</style>';
|
||||
|
||||
$visualConsoleItems = array_reduce(
|
||||
$visualConsoleItems,
|
||||
function ($carry, $item) use ($ratio_t) {
|
||||
$carry[] = $item->toArray();
|
||||
return $carry;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
$settings = \json_encode(
|
||||
[
|
||||
'props' => $visualConsoleData,
|
||||
'items' => $visualConsoleItems,
|
||||
'baseUrl' => ui_get_full_url('/', false, false, false),
|
||||
'ratio' => $ratio_t,
|
||||
'size' => $size,
|
||||
'cellId' => $this->cellId,
|
||||
]
|
||||
);
|
||||
|
||||
$output .= '<script type="text/javascript">';
|
||||
$output .= '$(document).ready(function () {';
|
||||
$output .= 'dashboardLoadVC('.$settings.')';
|
||||
$output .= '});';
|
||||
$output .= '</script>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Visual Console');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'maps_made_by_user';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,339 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Maps status Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Maps status
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Maps status Widgets.
|
||||
*/
|
||||
class MapsStatusWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('General visual maps report');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'maps_status';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['maps']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
global $config;
|
||||
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
include_once $config['homedir'].'/include/functions_visual_map.php';
|
||||
|
||||
$dataVc = \visual_map_get_user_layouts(
|
||||
$config['id_user'],
|
||||
false,
|
||||
[],
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
$fields = array_reduce(
|
||||
$dataVc,
|
||||
function ($carry, $item) {
|
||||
$carry[$item['id']] = $item['name'];
|
||||
return $carry;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Maps'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'maps[]',
|
||||
'selected' => explode(',', $values['maps'][0]),
|
||||
'multiple' => true,
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['maps'] = \get_parameter('maps', []);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
include_once $config['homedir'].'/include/functions_visual_map.php';
|
||||
|
||||
$user_layouts = \visual_map_get_user_layouts(
|
||||
$config['id_user'],
|
||||
false,
|
||||
[],
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
$table = new \stdClass();
|
||||
$table->class = 'widget_maps_status';
|
||||
$table->width = '90%';
|
||||
$table->data = [];
|
||||
|
||||
$maps = explode(',', $this->values['maps'][0]);
|
||||
$output = '';
|
||||
if (isset($maps) === true && empty($maps) === false) {
|
||||
foreach ($maps as $id_layout) {
|
||||
$data = [];
|
||||
|
||||
$url = $config['homeurl'];
|
||||
$url .= 'index.php?sec=visualc';
|
||||
$url .= '&sec2=operation/visual_console/render_view&refr=60';
|
||||
|
||||
// This will give us the group name.
|
||||
$data[0] = '<a href="'.$url.'&id='.$id_layout.'">';
|
||||
$data[0] .= $user_layouts[$id_layout]['name'];
|
||||
$data[0] .= '</a>';
|
||||
|
||||
// Status 0 is OK.
|
||||
if (!\visual_map_get_layout_status($id_layout)) {
|
||||
$data[1] = html_print_image(
|
||||
'images/pixel_green.png',
|
||||
true,
|
||||
[
|
||||
'title' => __('OK'),
|
||||
'class' => 'status',
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$data[1] = html_print_image(
|
||||
'images/pixel_red.png',
|
||||
true,
|
||||
[
|
||||
'title' => __('Bad'),
|
||||
'class' => 'status',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
array_push($table->data, $data);
|
||||
}
|
||||
|
||||
// 31 px for each map.
|
||||
$minHeight = (count($maps) * 31);
|
||||
$style = 'min-width:200px; min-height:'.$minHeight.'px';
|
||||
$output = '<div class="container-center" style="'.$style.'">';
|
||||
$output .= html_print_table($table, true);
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('General visual maps report');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'maps_status';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,485 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Module Icon Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Module Icon
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
use PandoraFMS\Dashboard;
|
||||
|
||||
global $config;
|
||||
|
||||
/**
|
||||
* Module Icon Widgets.
|
||||
*/
|
||||
class ModuleIconWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
/**
|
||||
* Dashboard ID.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $dashboardId;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Icon and module value');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'module_icon';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['moduleId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
$this->dashboardId = $dashboardId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
global $config;
|
||||
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Default values.
|
||||
if (isset($values['sizeValue']) === false) {
|
||||
$values['sizeValue'] = 20;
|
||||
}
|
||||
|
||||
if (isset($values['sizeLabel']) === false) {
|
||||
$values['sizeLabel'] = 20;
|
||||
}
|
||||
|
||||
if (isset($values['sizeIcon']) === false) {
|
||||
$values['sizeIcon'] = 70;
|
||||
}
|
||||
|
||||
// Label.
|
||||
$inputs[] = [
|
||||
'label' => __('Label'),
|
||||
'arguments' => [
|
||||
'name' => 'label',
|
||||
'type' => 'text',
|
||||
'value' => $values['label'],
|
||||
'return' => true,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Autocomplete agents.
|
||||
$inputs[] = [
|
||||
'label' => __('Agent'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_agent',
|
||||
'name' => 'agentAlias',
|
||||
'id_agent_hidden' => $values['agentId'],
|
||||
'name_agent_hidden' => 'agentId',
|
||||
'server_id_hidden' => $values['metaconsoleId'],
|
||||
'name_server_hidden' => 'metaconsoleId',
|
||||
'return' => true,
|
||||
'module_input' => true,
|
||||
'module_name' => 'moduleId',
|
||||
'module_none' => false,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Autocomplete module.
|
||||
$inputs[] = [
|
||||
'label' => __('Module'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_module',
|
||||
'fields' => $fields,
|
||||
'name' => 'moduleId',
|
||||
'selected' => $values['moduleId'],
|
||||
'return' => true,
|
||||
'sort' => false,
|
||||
'agent_id' => $values['agentId'],
|
||||
'metaconsole_id' => $values['metaconsoleId'],
|
||||
'style' => 'width: inherit;',
|
||||
],
|
||||
];
|
||||
|
||||
$all_images = \list_files(
|
||||
$config['homedir'].'/images/console/icons/',
|
||||
'png',
|
||||
1,
|
||||
0
|
||||
);
|
||||
|
||||
foreach ($all_images as $image_file) {
|
||||
if (\strpos($image_file, '_bad') !== false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (\strpos($image_file, '_ok') !== false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (\strpos($image_file, '_warning') !== false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$image_file = \substr($image_file, 0, (\strlen($image_file) - 4));
|
||||
$images_list[$image_file] = $image_file;
|
||||
}
|
||||
|
||||
$settings = \base64_encode(
|
||||
\json_encode(
|
||||
[
|
||||
'url' => ui_get_full_url('ajax.php'),
|
||||
'page' => 'operation/dashboard/dashboard',
|
||||
'dashboardId' => $this->dashboardId,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Icon'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $images_list,
|
||||
'name' => 'imageSrc',
|
||||
'selected' => $values['imageSrc'],
|
||||
'script' => 'imageIconChange(\''.$settings.'\')',
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$image = Manager::imageIconDashboard($values['imageSrc']);
|
||||
|
||||
$inputs[] = [
|
||||
'block_id' => 'image-item',
|
||||
'class' => 'flex-row flex-end w100p',
|
||||
'direct' => 1,
|
||||
'block_content' => [
|
||||
['label' => $image],
|
||||
],
|
||||
];
|
||||
|
||||
// Text size of value in px.
|
||||
$inputs[] = [
|
||||
'label' => __('Text size of value in px'),
|
||||
'arguments' => [
|
||||
'name' => 'sizeValue',
|
||||
'type' => 'number',
|
||||
'value' => $values['sizeValue'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Text size of label in px.
|
||||
$inputs[] = [
|
||||
'label' => __('Text size of label in px'),
|
||||
'arguments' => [
|
||||
'name' => 'sizeLabel',
|
||||
'type' => 'number',
|
||||
'value' => $values['sizeLabel'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// 'Size of icon.
|
||||
$inputs[] = [
|
||||
'label' => __('Size of icon'),
|
||||
'arguments' => [
|
||||
'name' => 'sizeIcon',
|
||||
'type' => 'number',
|
||||
'value' => $values['sizeIcon'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['label'] = \get_parameter('label', '');
|
||||
$values['agentId'] = \get_parameter('agentId', 0);
|
||||
$values['metaconsoleId'] = \get_parameter('metaconsoleId', 0);
|
||||
$values['moduleId'] = \get_parameter('moduleId', 0);
|
||||
$values['imageSrc'] = \get_parameter('imageSrc', 'appliance');
|
||||
$values['sizeValue'] = \get_parameter('sizeValue', 0);
|
||||
$values['sizeLabel'] = \get_parameter_switch('sizeLabel');
|
||||
$values['sizeIcon'] = \get_parameter_switch('sizeIcon');
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
include_once $config['homedir'].'/include/functions_agents.php';
|
||||
include_once $config['homedir'].'/include/functions_modules.php';
|
||||
|
||||
$output = '';
|
||||
|
||||
$id_group = \agents_get_agent_group($this->values['agentId']);
|
||||
if (check_acl($config['id_user'], $id_group, 'AR') === 0) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('You don\'t have access'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
$modulesAgent = \modules_get_agentmodule_agent(
|
||||
$this->values['moduleId']
|
||||
);
|
||||
|
||||
if ($modulesAgent !== (int) $this->values['agentId']) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('You don\'t have access'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
$data_module = \modules_get_last_value(
|
||||
$this->values['moduleId']
|
||||
);
|
||||
|
||||
$icon = $this->values['imageSrc'];
|
||||
$label = $this->values['label'];
|
||||
$sizeLabel = (($this->values['sizeLabel'] !== 0) ? $this->values['sizeLabel'] : 20);
|
||||
$sizeValue = (($this->values['sizeValue'] !== 0) ? $this->values['sizeValue'] : 20);
|
||||
$sizeIcon = (($this->values['sizeIcon'] !== 0) ? $this->values['sizeIcon'] : 100);
|
||||
|
||||
$output .= '<div class="container-center">';
|
||||
// General div.
|
||||
$output .= '<div class="container-icon">';
|
||||
|
||||
// Div image.
|
||||
$output .= '<div style="flex: 0 1 '.$sizeIcon.'px;">';
|
||||
$output .= html_print_image(
|
||||
'images/console/icons/'.$icon.'.png',
|
||||
true,
|
||||
['width' => $sizeIcon]
|
||||
);
|
||||
$output .= '</div>';
|
||||
|
||||
// Div value.
|
||||
$output .= '<div style="flex: 0 1 10px; font-size:'.$sizeValue.'px;">';
|
||||
$output .= remove_right_zeros(
|
||||
number_format($data_module, $config['graph_precision'])
|
||||
);
|
||||
$output .= '</div>';
|
||||
|
||||
if (empty($label) === false) {
|
||||
// Div Label.
|
||||
$output .= '<div style="flex: 1; font-size:'.$sizeLabel.'px;">'.$label.'</div>';
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Icon and module value');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'module_icon';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,484 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Module status Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Module status
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
global $config;
|
||||
|
||||
/**
|
||||
* Module status Widgets.
|
||||
*/
|
||||
class ModuleStatusWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
include_once $config['homedir'].'/include/functions_agents.php';
|
||||
include_once $config['homedir'].'/include/functions_modules.php';
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Module status');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'module_status';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['moduleId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
global $config;
|
||||
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Default values.
|
||||
if (isset($values['sizeLabel']) === false) {
|
||||
$values['sizeLabel'] = 20;
|
||||
}
|
||||
|
||||
if (isset($values['sizeIcon']) === false) {
|
||||
$values['sizeIcon'] = 70;
|
||||
}
|
||||
|
||||
// Label.
|
||||
$inputs[] = [
|
||||
'label' => __('Label'),
|
||||
'arguments' => [
|
||||
'name' => 'label',
|
||||
'type' => 'text',
|
||||
'value' => $values['label'],
|
||||
'return' => true,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Autocomplete agents.
|
||||
$inputs[] = [
|
||||
'label' => __('Agent'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_agent',
|
||||
'name' => 'agentAlias',
|
||||
'id_agent_hidden' => $values['agentId'],
|
||||
'name_agent_hidden' => 'agentId',
|
||||
'server_id_hidden' => $values['metaconsoleId'],
|
||||
'name_server_hidden' => 'metaconsoleId',
|
||||
'return' => true,
|
||||
'module_input' => true,
|
||||
'module_name' => 'moduleId',
|
||||
'module_none' => false,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Autocomplete module.
|
||||
$inputs[] = [
|
||||
'label' => __('Module'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_module',
|
||||
'fields' => $fields,
|
||||
'name' => 'moduleId',
|
||||
'selected' => $values['moduleId'],
|
||||
'return' => true,
|
||||
'sort' => false,
|
||||
'agent_id' => $values['agentId'],
|
||||
'metaconsole_id' => $values['metaconsoleId'],
|
||||
'style' => 'width: inherit;',
|
||||
],
|
||||
];
|
||||
|
||||
$all_images = \list_files(
|
||||
$config['homedir'].'/images/console/icons/',
|
||||
'png',
|
||||
1,
|
||||
0
|
||||
);
|
||||
|
||||
foreach ($all_images as $image_file) {
|
||||
if (\strpos($image_file, '_bad') !== false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (\strpos($image_file, '_ok') !== false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (\strpos($image_file, '_warning') !== false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$image_file = \substr($image_file, 0, (\strlen($image_file) - 4));
|
||||
$images_list[$image_file] = $image_file;
|
||||
}
|
||||
|
||||
$settings = \base64_encode(
|
||||
\json_encode(
|
||||
[
|
||||
'url' => ui_get_full_url('ajax.php'),
|
||||
'page' => 'operation/dashboard/dashboard',
|
||||
'dashboardId' => $this->dashboardId,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Icon'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $images_list,
|
||||
'name' => 'imageSrc',
|
||||
'selected' => $values['imageSrc'],
|
||||
'script' => 'imageIconChange(\''.$settings.'\')',
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$image = Manager::imageIconDashboard($values['imageSrc']);
|
||||
|
||||
$inputs[] = [
|
||||
'block_id' => 'image-item',
|
||||
'class' => 'flex-row flex-end w100p',
|
||||
'direct' => 1,
|
||||
'block_content' => [
|
||||
['label' => $image],
|
||||
],
|
||||
];
|
||||
|
||||
// Text size of label in px.
|
||||
$inputs[] = [
|
||||
'label' => __('Text size of label in px'),
|
||||
'arguments' => [
|
||||
'name' => 'sizeLabel',
|
||||
'type' => 'number',
|
||||
'value' => $values['sizeLabel'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// 'Size of icon.
|
||||
$inputs[] = [
|
||||
'label' => __('Size of icon'),
|
||||
'arguments' => [
|
||||
'name' => 'sizeIcon',
|
||||
'type' => 'number',
|
||||
'value' => $values['sizeIcon'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['label'] = \get_parameter('label', '');
|
||||
$values['agentId'] = \get_parameter('agentId', 0);
|
||||
$values['metaconsoleId'] = \get_parameter('metaconsoleId', 0);
|
||||
$values['moduleId'] = \get_parameter('moduleId', 0);
|
||||
$values['imageSrc'] = \get_parameter('imageSrc', 'appliance');
|
||||
$values['sizeValue'] = \get_parameter('sizeValue', 0);
|
||||
$values['sizeLabel'] = \get_parameter_switch('sizeLabel');
|
||||
$values['sizeIcon'] = \get_parameter_switch('sizeIcon');
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$output .= '';
|
||||
|
||||
$id_agent = $this->values['agentId'];
|
||||
$id_group = agents_get_agent_group($id_agent);
|
||||
|
||||
if (check_acl($config['id_user'], $id_group, 'AR') === 0) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('You don\'t have access'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
$id_module = $this->values['moduleId'];
|
||||
|
||||
if (modules_get_agentmodule_agent($id_module) !== (int) $id_agent) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('You don\'t have access'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
$icon = $this->values['imageSrc'];
|
||||
$label = $this->values['label'];
|
||||
$sizeLabel = (isset($this->values['sizeLabel']) === true) ? $this->values['sizeLabel'] : 30;
|
||||
$sizeIcon = (isset($this->values['sizeIcon']) === true) ? $this->values['sizeIcon'] : 80;
|
||||
|
||||
$status_module = modules_get_agentmodule_last_status($id_module);
|
||||
|
||||
switch ($status_module) {
|
||||
case 1:
|
||||
// Critical (BAD).
|
||||
$icon .= '_bad.png';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
// Critical (ALERT).
|
||||
$icon = '4'.$icon.'_bad.png';
|
||||
break;
|
||||
|
||||
case 0:
|
||||
// Normal (OK).
|
||||
$icon .= '_ok.png';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// Warning.
|
||||
$icon .= '_warning.png';
|
||||
break;
|
||||
|
||||
case 10:
|
||||
// Warning (ALERT).
|
||||
$icon = '4'.$icon.'_warning.png';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
default:
|
||||
// Unknown.
|
||||
// Default is Grey (Other).
|
||||
$icon .= '.png';
|
||||
break;
|
||||
}
|
||||
|
||||
$output .= '<div class="container-center">';
|
||||
// General div.
|
||||
$output .= '<div class="container-icon">';
|
||||
|
||||
// Div image.
|
||||
$output .= '<div style="flex: 0 1 '.$sizeIcon.'px;">';
|
||||
$output .= html_print_image(
|
||||
'images/console/icons/'.$icon,
|
||||
true,
|
||||
['width' => $sizeIcon]
|
||||
);
|
||||
$output .= '</div>';
|
||||
|
||||
if (empty($label) === false) {
|
||||
// Div Label.
|
||||
$output .= '<div style="flex: 1 1 '.$sizeLabel.'px; font-size:'.$sizeLabel.'px;">'.$label.'</div>';
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Module status');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'module_status';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,395 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Module table value Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Module table value
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
global $config;
|
||||
|
||||
|
||||
/**
|
||||
* Module table value Widgets.
|
||||
*/
|
||||
class ModuleTableValueWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// Includes.
|
||||
include_once $config['homedir'].'/include/functions_agents.php';
|
||||
include_once $config['homedir'].'/include/functions_modules.php';
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Show module value in a table');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'module_table_value';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['moduleId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
if (isset($values['sizeLabel']) === false) {
|
||||
$values['sizeLabel'] = 20;
|
||||
}
|
||||
|
||||
// Autocomplete agents.
|
||||
$inputs[] = [
|
||||
'label' => __('Agent'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_agent',
|
||||
'name' => 'agentAlias',
|
||||
'id_agent_hidden' => $values['agentId'],
|
||||
'name_agent_hidden' => 'agentId',
|
||||
'server_id_hidden' => $values['metaconsoleId'],
|
||||
'name_server_hidden' => 'metaconsoleId',
|
||||
'return' => true,
|
||||
'module_input' => true,
|
||||
'module_name' => 'moduleId',
|
||||
'module_none' => false,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Autocomplete module.
|
||||
$inputs[] = [
|
||||
'label' => __('Module'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_module',
|
||||
'fields' => $fields,
|
||||
'name' => 'moduleId',
|
||||
'selected' => $values['moduleId'],
|
||||
'return' => true,
|
||||
'sort' => false,
|
||||
'agent_id' => $values['agentId'],
|
||||
'metaconsole_id' => $values['metaconsoleId'],
|
||||
'style' => 'width: inherit;',
|
||||
],
|
||||
];
|
||||
|
||||
// Text size of label in px.
|
||||
$inputs[] = [
|
||||
'label' => __('Text size of label in px'),
|
||||
'arguments' => [
|
||||
'name' => 'sizeLabel',
|
||||
'type' => 'number',
|
||||
'value' => $values['sizeLabel'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
$fields = [
|
||||
'<br>' => __('Carriage Return'),
|
||||
'|' => __('Vertical Bar'),
|
||||
';' => __('Semicolon'),
|
||||
':' => __('Colon'),
|
||||
',' => __('Commas'),
|
||||
' ' => __('Blank'),
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Data separator'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'separator',
|
||||
'selected' => $values['separator'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['agentId'] = \get_parameter('agentId', 0);
|
||||
$values['metaconsoleId'] = \get_parameter('metaconsoleId', 0);
|
||||
$values['moduleId'] = \get_parameter('moduleId', 0);
|
||||
$values['sizeLabel'] = \get_parameter('sizeLabel', 0);
|
||||
$values['separator'] = \get_parameter_switch('separator');
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$output = '';
|
||||
$id_agent = $this->values['agentId'];
|
||||
$id_group = \agents_get_agent_group($id_agent);
|
||||
|
||||
$id_module = $this->values['moduleId'];
|
||||
$size_text = $this->values['sizeLabel'];
|
||||
|
||||
if (check_acl($config['id_user'], $id_group, 'AR') === 0) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('You don\'t have access'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
if (modules_get_agentmodule_agent($id_module) !== (int) $id_agent) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('You don\'t have access'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
$data_module = modules_get_last_value($id_module);
|
||||
$value = (string) $data_module;
|
||||
|
||||
$array_values = explode('
', io_safe_input($value));
|
||||
|
||||
if (isset($array_values) === true && is_array($array_values) === true) {
|
||||
io_safe_output_array($array_values);
|
||||
|
||||
$value = implode(
|
||||
io_safe_output(
|
||||
$this->values['separator']
|
||||
),
|
||||
$array_values
|
||||
);
|
||||
|
||||
$value = preg_replace(
|
||||
'/'.$this->values['separator'].'/i',
|
||||
'<br>',
|
||||
$value
|
||||
);
|
||||
} else {
|
||||
$value = preg_replace(
|
||||
'/\n/i',
|
||||
io_safe_output(
|
||||
$this->values['separator']
|
||||
),
|
||||
io_safe_output($value)
|
||||
);
|
||||
$value = preg_replace('/\s/i', ' ', $value);
|
||||
}
|
||||
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= '<div class="container-icon">';
|
||||
$styles = 'width:100%; font-family:monospace; word-wrap: break-word;';
|
||||
$output .= '<div style="'.$styles.' font-size:'.$size_text.'px;">';
|
||||
$output .= $value;
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Module in a table');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'module_table_value';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,387 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Module value Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Module value
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
global $config;
|
||||
|
||||
require_once $config['homedir'].'/include/functions_agents.php';
|
||||
require_once $config['homedir'].'/include/functions_modules.php';
|
||||
|
||||
/**
|
||||
* Module value Widgets.
|
||||
*/
|
||||
class ModuleValueWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Module value');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'module_value';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['moduleId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
global $config;
|
||||
|
||||
$values = $this->values;
|
||||
|
||||
// Default values.
|
||||
if (isset($values['sizeLabel']) === false) {
|
||||
$values['sizeLabel'] = 20;
|
||||
}
|
||||
|
||||
if (isset($values['sizeValue']) === false) {
|
||||
$values['sizeValue'] = 20;
|
||||
}
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Label.
|
||||
$inputs[] = [
|
||||
'label' => __('Label'),
|
||||
'arguments' => [
|
||||
'name' => 'label',
|
||||
'type' => 'text',
|
||||
'value' => $values['label'],
|
||||
'return' => true,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Autocomplete agents.
|
||||
$inputs[] = [
|
||||
'label' => __('Agent'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_agent',
|
||||
'name' => 'agentAlias',
|
||||
'id_agent_hidden' => $values['agentId'],
|
||||
'name_agent_hidden' => 'agentId',
|
||||
'server_id_hidden' => $values['metaconsoleId'],
|
||||
'name_server_hidden' => 'metaconsoleId',
|
||||
'return' => true,
|
||||
'module_input' => true,
|
||||
'module_name' => 'moduleId',
|
||||
'module_none' => false,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Autocomplete module.
|
||||
$inputs[] = [
|
||||
'label' => __('Module'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_module',
|
||||
'fields' => $fields,
|
||||
'name' => 'moduleId',
|
||||
'selected' => $values['moduleId'],
|
||||
'return' => true,
|
||||
'sort' => false,
|
||||
'agent_id' => $values['agentId'],
|
||||
'metaconsole_id' => $values['metaconsoleId'],
|
||||
'style' => 'width: inherit;',
|
||||
],
|
||||
];
|
||||
|
||||
// Text size of value in px.
|
||||
$inputs[] = [
|
||||
'label' => __('Text size of value in px'),
|
||||
'arguments' => [
|
||||
'name' => 'sizeValue',
|
||||
'type' => 'number',
|
||||
'value' => $values['sizeValue'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Text size of label in px.
|
||||
$inputs[] = [
|
||||
'label' => __('Text size of label in px'),
|
||||
'arguments' => [
|
||||
'name' => 'sizeLabel',
|
||||
'type' => 'number',
|
||||
'value' => $values['sizeLabel'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['label'] = \get_parameter('label', '');
|
||||
$values['agentId'] = \get_parameter('agentId', 0);
|
||||
$values['metaconsoleId'] = \get_parameter('metaconsoleId', 0);
|
||||
$values['moduleId'] = \get_parameter('moduleId', 0);
|
||||
$values['sizeValue'] = \get_parameter('sizeValue', 0);
|
||||
$values['sizeLabel'] = \get_parameter_switch('sizeLabel');
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$output .= '';
|
||||
|
||||
$id_agent = $this->values['agentId'];
|
||||
$id_group = agents_get_agent_group($id_agent);
|
||||
|
||||
if (check_acl($config['id_user'], $id_group, 'AR') === 0) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('You don\'t have access'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
$id_module = $this->values['moduleId'];
|
||||
|
||||
if (modules_get_agentmodule_agent($id_module) !== (int) $id_agent) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('You don\'t have access'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
$data_module = \modules_get_last_value($id_module);
|
||||
|
||||
$label = $this->values['label'];
|
||||
$sizeLabel = (isset($this->values['sizeLabel']) === true) ? $this->values['sizeLabel'] : 40;
|
||||
$sizeValue = (isset($this->values['sizeValue']) === true) ? $this->values['sizeValue'] : 40;
|
||||
|
||||
$output .= '<div class="container-center">';
|
||||
// General div.
|
||||
$output .= '<div class="container-icon">';
|
||||
// Div value.
|
||||
$output .= '<div style="flex: 0 1 '.$sizeValue.'px; font-size:'.$sizeValue.'px;">';
|
||||
$output .= remove_right_zeros(
|
||||
number_format($data_module, $config['graph_precision'])
|
||||
);
|
||||
$output .= '</div>';
|
||||
|
||||
if (empty($label) === false) {
|
||||
// Div Label.
|
||||
$output .= '<div style="flex: 1 1 '.$sizeLabel.'px; font-size:'.$sizeLabel.'px;">'.$label.'</div>';
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Module value');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'module_value';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,335 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Monitor health Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Monitor health
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Monitor health Widgets.
|
||||
*/
|
||||
class MonitorHealthWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Global health info');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'monitor_health';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (isset($this->values['title']) === false) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
include_once $config['homedir'].'/include/functions_reporting.php';
|
||||
include_once $config['homedir'].'/include/functions_graph.php';
|
||||
include_once $config['homedir'].'/include/functions_servers.php';
|
||||
include_once $config['homedir'].'/include/functions_tactical.php';
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
$all_data = tactical_status_modules_agents(
|
||||
$config['id_user'],
|
||||
$user_strict,
|
||||
'AR'
|
||||
);
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['mNI'] = (int) $all_data['_monitors_not_init_'];
|
||||
$data['monitor_unknown'] = (int) $all_data['_monitors_unknown_'];
|
||||
$data['monitor_ok'] = (int) $all_data['_monitors_ok_'];
|
||||
$data['mW'] = (int) $all_data['_monitors_warning_'];
|
||||
$data['mC'] = (int) $all_data['_monitors_critical_'];
|
||||
$data['mNN'] = (int) $all_data['_monitor_not_normal_'];
|
||||
$data['monitor_alerts'] = (int) $all_data['_monitors_alerts_'];
|
||||
$data['mAFired'] = (int) $all_data['_monitors_alerts_fired_'];
|
||||
|
||||
$data['total_agents'] = (int) $all_data['_total_agents_'];
|
||||
|
||||
$data['mChecks'] = (int) $all_data['_monitor_checks_'];
|
||||
if (empty($all_data) === false) {
|
||||
if ($data['mNN'] > 0 && $data['mChecks'] > 0) {
|
||||
$data['monitor_health'] = \format_numeric(
|
||||
(100 - ($data['mNN'] / ($data['mChecks'] / 100))),
|
||||
1
|
||||
);
|
||||
} else {
|
||||
$data['monitor_health'] = 100;
|
||||
}
|
||||
|
||||
if ($data['mNI'] > 0 && $data['mChecks'] > 0) {
|
||||
$data['module_sanity'] = \format_numeric(
|
||||
(100 - ($data['mNI'] / ($data['mChecks'] / 100))),
|
||||
1
|
||||
);
|
||||
} else {
|
||||
$data['module_sanity'] = 100;
|
||||
}
|
||||
|
||||
if (isset($data['alerts']) === true) {
|
||||
if ($data['mAfired'] > 0 && $data['alerts'] > 0) {
|
||||
$data['alert_level'] = \format_numeric(
|
||||
(100 - ($data['mAfired'] / ($data['alerts'] / 100))),
|
||||
1
|
||||
);
|
||||
} else {
|
||||
$data['alert_level'] = 100;
|
||||
}
|
||||
} else {
|
||||
$data['alert_level'] = 100;
|
||||
$data['alerts'] = 0;
|
||||
}
|
||||
|
||||
$data['monitor_bad'] = ($data['mC'] + $data['mW']);
|
||||
|
||||
if ($data['monitor_bad'] > 0 && $data['mChecks'] > 0) {
|
||||
$data['global_health'] = \format_numeric(
|
||||
(100 - ($data['monitor_bad'] / ($data['mChecks'] / 100))),
|
||||
1
|
||||
);
|
||||
} else {
|
||||
$data['global_health'] = 100;
|
||||
}
|
||||
|
||||
$data['server_sanity'] = \format_numeric(
|
||||
(100 - $data['module_sanity']),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
$table = new \stdClass;
|
||||
$table->width = '90%';
|
||||
$table->class = 'nothing';
|
||||
|
||||
$table->align[0] = 'center';
|
||||
|
||||
$table->data[0][0] = \reporting_get_stats_indicators(
|
||||
$data,
|
||||
((int) $size['width'] - 100),
|
||||
20
|
||||
);
|
||||
|
||||
$output = '<div class="container-center" style="min-width:200px; min-height:320px;">';
|
||||
$output .= \html_print_table($table, true);
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Global health info');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'monitor_health';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,380 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Network map Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Network map
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Network map Widgets.
|
||||
*/
|
||||
class NetworkMapWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $cellId;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
include_once $config['homedir'].'/include/functions_networkmap.php';
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Cell Id.
|
||||
$this->cellId = $cellId;
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Network map');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'network_map';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['networkmapId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Default values.
|
||||
if (isset($values['xOffset']) === false) {
|
||||
$values['xOffset'] = 0;
|
||||
}
|
||||
|
||||
if (isset($values['yOffset']) === false) {
|
||||
$values['yOffset'] = 0;
|
||||
}
|
||||
|
||||
if (isset($values['zoomLevel']) === false) {
|
||||
$values['zoomLevel'] = 0.5;
|
||||
}
|
||||
|
||||
// Map.
|
||||
$fields = \networkmap_get_networkmaps();
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Map'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'networkmapId',
|
||||
'selected' => $values['networkmapId'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// X offset.
|
||||
$help = ui_print_help_tip(
|
||||
__('Introduce x-axis data. Right=positive Left=negative'),
|
||||
true
|
||||
);
|
||||
$inputs[] = [
|
||||
'label' => __('X offset').$help,
|
||||
'arguments' => [
|
||||
'name' => 'xOffset',
|
||||
'type' => 'number',
|
||||
'value' => $values['xOffset'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Y offset.
|
||||
$help = ui_print_help_tip(
|
||||
__('Introduce Y-axis data. Top=positive Bottom=negative'),
|
||||
true
|
||||
);
|
||||
$inputs[] = [
|
||||
'label' => __('Y offset').$help,
|
||||
'arguments' => [
|
||||
'name' => 'yOffset',
|
||||
'type' => 'number',
|
||||
'value' => $values['yOffset'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Zoom level.
|
||||
$fields = [
|
||||
'0.1' => 'x1',
|
||||
'0.2' => 'x2',
|
||||
'0.3' => 'x3',
|
||||
'0.4' => 'x4',
|
||||
'0.5' => 'x5',
|
||||
'0.6' => 'x6',
|
||||
'0.7' => 'x7',
|
||||
'0.8' => 'x8',
|
||||
'0.9' => 'x9',
|
||||
'1' => 'x10',
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Zoom level').$help,
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'zoomLevel',
|
||||
'selected' => $values['zoomLevel'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['networkmapId'] = \get_parameter('networkmapId', 0);
|
||||
$values['xOffset'] = \get_parameter('xOffset', 0);
|
||||
$values['yOffset'] = \get_parameter('yOffset', 0);
|
||||
$values['zoomLevel'] = (float) \get_parameter('zoomLevel', 0.5);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
$id_networkmap = $this->values['networkmapId'];
|
||||
$x_offset = $this->values['xOffset'];
|
||||
$y_offset = $this->values['yOffset'];
|
||||
$zoom_dash = $this->values['zoomLevel'];
|
||||
|
||||
$hash = md5($config['dbpass'].$id_networkmap.$config['id_user']);
|
||||
|
||||
$style = 'width:'.$size['width'].'px; height:'.$size['height'].'px;';
|
||||
$id = 'body_cell-'.$this->cellId;
|
||||
$output = '<div class="body_cell" id="'.$id.'" style="'.$style.'"><div>';
|
||||
|
||||
$settings = \json_encode(
|
||||
[
|
||||
'cellId' => $this->cellId,
|
||||
'page' => 'enterprise/include/ajax/map_enterprise.ajax',
|
||||
'url' => ui_get_full_url(
|
||||
'ajax.php',
|
||||
false,
|
||||
false,
|
||||
false
|
||||
),
|
||||
'networkmap_id' => $id_networkmap,
|
||||
'x_offset' => $x_offset,
|
||||
'y_offset' => $y_offset,
|
||||
'zoom_dash' => $zoom_dash,
|
||||
'id_user' => $config['id_user'],
|
||||
'hash' => $hash,
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
$output .= '<script type="text/javascript">';
|
||||
$output .= '$(document).ready(function () {';
|
||||
$output .= 'dashboardLoadNetworkMap('.$settings.');';
|
||||
$output .= '})';
|
||||
$output .= '</script>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Network map');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'network_map';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,266 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget POST Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget POST
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* POST Widgets.
|
||||
*/
|
||||
class PostWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Panel with a message');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'post';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['text']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
$inputs[] = ['label' => __('Text')];
|
||||
|
||||
$inputs[] = [
|
||||
'class' => 'flex-row',
|
||||
'id' => 'div-textarea',
|
||||
'arguments' => [
|
||||
'name' => 'text',
|
||||
'type' => 'textarea',
|
||||
'value' => $values['text'],
|
||||
'return' => true,
|
||||
'rows' => 1,
|
||||
'columns' => 1,
|
||||
'size' => 25,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['text'] = \get_parameter('text', '');
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
$output = '';
|
||||
|
||||
if (isset($this->values['text']) === true) {
|
||||
$output .= '<div class="post-widget">';
|
||||
$output .= io_safe_output($this->values['text']);
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Panel with a message');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'post';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,360 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Reports Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Reports
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
global $config;
|
||||
require_once $config['homedir'].'/include/Image/image_functions.php';
|
||||
require_once $config['homedir'].'/include/functions_reporting_html.php';
|
||||
require_once $config['homedir'].'/include/functions_reports.php';
|
||||
require_once $config['homedir'].'/include/functions_groups.php';
|
||||
|
||||
/**
|
||||
* Reports Widgets.
|
||||
*/
|
||||
class ReportsWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Custom report');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'reports';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['reportId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Reports.
|
||||
$reports = \reports_get_reports(false, ['id_report', 'name']);
|
||||
$fields = array_reduce(
|
||||
$reports,
|
||||
function ($carry, $item) {
|
||||
$carry[$item['id_report']] = $item['name'];
|
||||
return $carry;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Report'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'reportId',
|
||||
'selected' => $values['reportId'],
|
||||
'return' => true,
|
||||
'style' => 'width: inherit;',
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['reportId'] = \get_parameter('reportId', 0);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
$output = '';
|
||||
ob_start();
|
||||
if ($this->values['reportId'] !== 0) {
|
||||
$output .= '<div style="width:90%; height:100%; display:flex; flex-direction:column;">';
|
||||
$this->printReport();
|
||||
$output .= ob_get_clean();
|
||||
|
||||
$output .= 'Click to view: <a href="?sec=reporting&sec2=operation/reporting/reporting_viewer&id='.$this->values['reportId'].'">'.__('Report').'</a>';
|
||||
$output .= '</div>';
|
||||
} else {
|
||||
$this->load_error = true;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw Report.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function printReport()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$id_report = $this->values['reportId'];
|
||||
|
||||
// Get Report record (to get id_group).
|
||||
$report = db_get_row('treport', 'id_report', $id_report);
|
||||
|
||||
// Include with the functions to calculate each kind of report.
|
||||
include_once $config['homedir'].'/include/functions_reporting.php';
|
||||
|
||||
// Check if the report is a private report.
|
||||
if (empty($report) === true
|
||||
|| ($report['private'] === true
|
||||
&& ($report['id_user'] !== $config['id_user']
|
||||
&& is_user_admin($config['id_user']) === false))
|
||||
) {
|
||||
include $config['homedir'].'/general/noaccess.php';
|
||||
return '';
|
||||
}
|
||||
|
||||
// Get different date to search the report.
|
||||
$utimestamp = get_system_time();
|
||||
$date = date('Y-m-j', $utimestamp);
|
||||
$time = date('h:iA', $utimestamp);
|
||||
|
||||
$report['datetime'] = $utimestamp;
|
||||
|
||||
// Evaluate if it's better to render blocks when are calculated
|
||||
// (enabling realtime flush) or if it's better to wait report to be
|
||||
// finished before showing anything (this could break the execution by
|
||||
// overflowing the running PHP memory on HUGE reports).
|
||||
$table = new \stdClass();
|
||||
$table->size = [];
|
||||
$table->style = [];
|
||||
$table->width = '99%';
|
||||
$table->class = 'databox report_table';
|
||||
$table->rowclass = [];
|
||||
$table->rowclass[0] = 'datos3';
|
||||
|
||||
$report['group_name'] = groups_get_name($report['id_group']);
|
||||
|
||||
$contents = db_get_all_rows_field_filter(
|
||||
'treport_content',
|
||||
'id_report',
|
||||
$id_report,
|
||||
'`order`'
|
||||
);
|
||||
|
||||
if ($contents === false) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$report = reporting_make_reporting_data(
|
||||
null,
|
||||
$id_report,
|
||||
$date,
|
||||
$time,
|
||||
false,
|
||||
'dinamic'
|
||||
);
|
||||
|
||||
reporting_html_print_report($report, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Custom report');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'reports';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,360 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Service map Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Service map
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Service map Widgets.
|
||||
*/
|
||||
class ServiceMapWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// Includes.
|
||||
enterprise_include_once('/include/functions_services.php');
|
||||
enterprise_include_once('/include/functions_servicemap.php');
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Service Map');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'service_map';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['serviceId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
$services_res = services_get_services();
|
||||
$services = [0 => __('None')];
|
||||
if ($services_res !== false) {
|
||||
$fields = array_reduce(
|
||||
$services_res,
|
||||
function ($carry, $item) {
|
||||
$carry[$item['id']] = $item['name'];
|
||||
return $carry;
|
||||
},
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Service'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'serviceId',
|
||||
'selected' => $values['serviceId'],
|
||||
'return' => true,
|
||||
'nothing' => __('None'),
|
||||
'nothing_value' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Show legend.
|
||||
$inputs[] = [
|
||||
'label' => __('Show legend'),
|
||||
'arguments' => [
|
||||
'name' => 'showLegend',
|
||||
'id' => 'showLegend',
|
||||
'type' => 'switch',
|
||||
'value' => $values['showLegend'],
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['serviceId'] = \get_parameter('serviceId', 0);
|
||||
$values['showLegend'] = \get_parameter_switch('showLegend');
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
if (check_acl($config['id_user'], 0, 'AR') === 0) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('The user doesn\'t have permission to read agents'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
if (empty($this->values['serviceId']) === true) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output = ui_print_error_message(
|
||||
__('Missing Service id'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
$output .= "<div id='container_servicemap' style='position: relative; text-align: center;'>";
|
||||
|
||||
if ($this->values['showLegend'] === 1) {
|
||||
$output .= "<div id='container_servicemap_legend'>";
|
||||
$output .= '<table>';
|
||||
$output .= "<tr class='legend_servicemap_title'><td colspan='3' style='padding-bottom: 10px; min-width: 177px;'><b>".__('Legend').'</b></td>';
|
||||
$output .= "<td><img class='legend_servicemap_toggle' style='padding-bottom: 10px;' src='images/darrowup.png'></td></tr>";
|
||||
|
||||
$output .= "<tr class='legend_servicemap_item'><td>";
|
||||
$output .= "<img src='images/service.png'>";
|
||||
$output .= '</td><td>'.__('Services').'</td>';
|
||||
|
||||
// Coulour legend.
|
||||
$output .= "<td rowspan='3'>";
|
||||
$output .= '<table>';
|
||||
$output .= "<tr><td class='legend_square'><div style='background-color: ".COL_CRITICAL.";'></div></td><td>".__('Critical').'</td></tr>';
|
||||
$output .= "<tr><td class='legend_square'><div style='background-color: ".COL_WARNING.";'></div></td><td>".__('Warning').'</td></tr>';
|
||||
$output .= "<tr><td class='legend_square'><div style='background-color: ".COL_NORMAL.";'></div></td><td>".__('Ok').'</td></tr>';
|
||||
$output .= "<tr><td class='legend_square'><div style='background-color: ".COL_UNKNOWN.";'></div></td><td>".__('Unknown').'</td></tr>';
|
||||
$output .= '</table>';
|
||||
$output .= '</td></tr>';
|
||||
|
||||
$output .= "<tr class='legend_servicemap_item'><td>";
|
||||
$output .= "<img src='images/agent.png'>";
|
||||
$output .= '</td><td>'.__('Agents').'</td>';
|
||||
$output .= '</tr>';
|
||||
|
||||
$output .= "<tr class='legend_servicemap_item'><td>";
|
||||
$output .= "<img src='images/module.png'>";
|
||||
$output .= '</td><td>'.__('Modules').'</td>';
|
||||
$output .= '</tr>';
|
||||
$output .= '</table>';
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
||||
$output .= html_print_input_hidden(
|
||||
'full_url_dashboard_map',
|
||||
$config['homeurl'],
|
||||
true
|
||||
);
|
||||
// TODO:XXX fix draw service map.
|
||||
ob_start();
|
||||
servicemap_print_servicemap(
|
||||
$this->values['serviceId'],
|
||||
false,
|
||||
$size['width'],
|
||||
$size['height']
|
||||
);
|
||||
$output .= ob_get_clean();
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Service map');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'service_map';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,348 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget URL Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget URL
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
global $config;
|
||||
|
||||
/**
|
||||
* URL Widgets
|
||||
*/
|
||||
class SingleGraphWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Agent module graph');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'single_graph';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['moduleId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Default values.
|
||||
if (isset($values['period']) === false) {
|
||||
$values['period'] = SECONDS_1DAY;
|
||||
}
|
||||
|
||||
if (isset($values['showLegend']) === false) {
|
||||
$values['showLegend'] = 1;
|
||||
}
|
||||
|
||||
// Autocomplete agents.
|
||||
$inputs[] = [
|
||||
'label' => __('Agent'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_agent',
|
||||
'name' => 'agentAlias',
|
||||
'id_agent_hidden' => $values['agentId'],
|
||||
'name_agent_hidden' => 'agentId',
|
||||
'server_id_hidden' => $values['metaconsoleId'],
|
||||
'name_server_hidden' => 'metaconsoleId',
|
||||
'return' => true,
|
||||
'module_input' => true,
|
||||
'module_name' => 'moduleId',
|
||||
'module_none' => false,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Autocomplete module.
|
||||
$inputs[] = [
|
||||
'label' => __('Module'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_module',
|
||||
'fields' => $fields,
|
||||
'name' => 'moduleId',
|
||||
'selected' => $values['moduleId'],
|
||||
'return' => true,
|
||||
'sort' => false,
|
||||
'agent_id' => $values['agentId'],
|
||||
'metaconsole_id' => $values['metaconsoleId'],
|
||||
'style' => 'width: inherit;',
|
||||
],
|
||||
];
|
||||
|
||||
// Show legend.
|
||||
$inputs[] = [
|
||||
'label' => __('Show legend'),
|
||||
'arguments' => [
|
||||
'name' => 'showLegend',
|
||||
'id' => 'showLegend',
|
||||
'type' => 'switch',
|
||||
'value' => $values['showLegend'],
|
||||
],
|
||||
];
|
||||
|
||||
// Period.
|
||||
$inputs[] = [
|
||||
'label' => __('Interval'),
|
||||
'arguments' => [
|
||||
'name' => 'period',
|
||||
'type' => 'interval',
|
||||
'value' => $values['period'],
|
||||
'nothing' => __('None'),
|
||||
'nothing_value' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['agentId'] = \get_parameter('agentId', 0);
|
||||
$values['metaconsoleId'] = \get_parameter('metaconsoleId', 0);
|
||||
$values['moduleId'] = \get_parameter('moduleId', 0);
|
||||
$values['period'] = \get_parameter('period', 0);
|
||||
$values['showLegend'] = \get_parameter_switch('showLegend');
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
include_once $config['homedir'].'/include/functions_graph.php';
|
||||
include_once $config['homedir'].'/include/functions_agents.php';
|
||||
include_once $config['homedir'].'/include/functions_modules.php';
|
||||
|
||||
$module_name = \modules_get_agentmodule_name($id_module);
|
||||
$units_name = \modules_get_unit($id_module);
|
||||
|
||||
$trickHight = 10;
|
||||
if ($this->values['showLegend'] === 1) {
|
||||
// Needed for legend.
|
||||
$trickHight = 40;
|
||||
}
|
||||
|
||||
$params = [
|
||||
'agent_module_id' => $this->values['moduleId'],
|
||||
'width' => ((int) $size['width'] - 5),
|
||||
'height' => ((int) $size['height'] - $trickHight),
|
||||
'period' => $this->values['period'],
|
||||
'title' => $module_name,
|
||||
'unit' => $units_name,
|
||||
'homeurl' => $config['homeurl'],
|
||||
'backgroundColor' => 'transparent',
|
||||
'show_legend' => $this->values['showLegend'],
|
||||
'show_title' => $module_name,
|
||||
'menu' => false,
|
||||
];
|
||||
|
||||
$output = '<div class="container-center">';
|
||||
$output .= \grafico_modulo_sparse($params);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Agent module graph');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'single_graph';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,421 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget SLA percent Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget SLA percent
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
global $config;
|
||||
|
||||
require_once $config['homedir'].'/include/functions_agents.php';
|
||||
require_once $config['homedir'].'/include/functions_modules.php';
|
||||
require_once $config['homedir'].'/include/functions_reporting.php';
|
||||
|
||||
/**
|
||||
* SLA percent Widgets.
|
||||
*/
|
||||
class SLAPercentWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('SLA percentage');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'sla_percent';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['moduleId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Default values.
|
||||
if (isset($values['period']) === false) {
|
||||
$values['period'] = 300;
|
||||
}
|
||||
|
||||
if (isset($values['sizeLabel']) === false) {
|
||||
$values['sizeLabel'] = 20;
|
||||
}
|
||||
|
||||
if (isset($values['sizeValue']) === false) {
|
||||
$values['sizeValue'] = 20;
|
||||
}
|
||||
|
||||
// Label.
|
||||
$inputs[] = [
|
||||
'label' => __('Label'),
|
||||
'arguments' => [
|
||||
'name' => 'label',
|
||||
'type' => 'text',
|
||||
'value' => $values['label'],
|
||||
'return' => true,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Autocomplete agents.
|
||||
$inputs[] = [
|
||||
'label' => __('Agent'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_agent',
|
||||
'name' => 'agentAlias',
|
||||
'id_agent_hidden' => $values['agentId'],
|
||||
'name_agent_hidden' => 'agentId',
|
||||
'server_id_hidden' => $values['metaconsoleId'],
|
||||
'name_server_hidden' => 'metaconsoleId',
|
||||
'return' => true,
|
||||
'module_input' => true,
|
||||
'module_name' => 'moduleId',
|
||||
'module_none' => false,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Autocomplete module.
|
||||
$inputs[] = [
|
||||
'label' => __('Module'),
|
||||
'arguments' => [
|
||||
'type' => 'autocomplete_module',
|
||||
'fields' => $fields,
|
||||
'name' => 'moduleId',
|
||||
'selected' => $values['moduleId'],
|
||||
'return' => true,
|
||||
'sort' => false,
|
||||
'agent_id' => $values['agentId'],
|
||||
'metaconsole_id' => $values['metaconsoleId'],
|
||||
'style' => 'width: inherit;',
|
||||
],
|
||||
];
|
||||
|
||||
// Period.
|
||||
$inputs[] = [
|
||||
'label' => __('Interval'),
|
||||
'arguments' => [
|
||||
'name' => 'period',
|
||||
'type' => 'interval',
|
||||
'value' => $values['period'],
|
||||
'nothing' => __('None'),
|
||||
'nothing_value' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Text size of value in px.
|
||||
$inputs[] = [
|
||||
'label' => __('Text size of value in px'),
|
||||
'arguments' => [
|
||||
'name' => 'sizeValue',
|
||||
'type' => 'number',
|
||||
'value' => $values['sizeValue'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Text size of label in px.
|
||||
$inputs[] = [
|
||||
'label' => __('Text size of label in px'),
|
||||
'arguments' => [
|
||||
'name' => 'sizeLabel',
|
||||
'type' => 'number',
|
||||
'value' => $values['sizeLabel'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['label'] = \get_parameter('label', '');
|
||||
$values['agentId'] = \get_parameter('agentId', 0);
|
||||
$values['metaconsoleId'] = \get_parameter('metaconsoleId', 0);
|
||||
$values['moduleId'] = \get_parameter('moduleId', 0);
|
||||
$values['period'] = \get_parameter('period', 0);
|
||||
$values['sizeValue'] = \get_parameter('sizeValue', '');
|
||||
$values['sizeLabel'] = \get_parameter('sizeLabel', '');
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
$output .= '';
|
||||
$id_agent = $this->values['agentId'];
|
||||
$id_module = $this->values['moduleId'];
|
||||
$period = $this->values['period'];
|
||||
$label = $this->values['label'];
|
||||
|
||||
$id_group = agents_get_agent_group($id_agent);
|
||||
if (check_acl($config['id_user'], $id_group, 'AR') === 0) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('You don\'t have access'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
if (modules_get_agentmodule_agent($id_module) !== (int) $id_agent) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('You don\'t have access'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
$sla_array = reporting_advanced_sla(
|
||||
$id_module,
|
||||
(time() - $period),
|
||||
time(),
|
||||
null,
|
||||
null,
|
||||
0,
|
||||
[
|
||||
'1' => 1,
|
||||
'2' => 1,
|
||||
'3' => 1,
|
||||
'4' => 1,
|
||||
'5' => 1,
|
||||
'6' => 1,
|
||||
'7' => 1,
|
||||
],
|
||||
'00:00:00',
|
||||
'00:00:00',
|
||||
1
|
||||
);
|
||||
|
||||
$sizeLabel = (isset($this->values['sizeLabel']) === true) ? $this->values['sizeLabel'] : 30;
|
||||
$sizeValue = (isset($this->values['sizeValue']) === true) ? $this->values['sizeValue'] : 30;
|
||||
|
||||
$output .= '<div class="container-center">';
|
||||
// General div.
|
||||
$output .= '<div class="container-icon">';
|
||||
// Div value.
|
||||
$output .= '<div style="flex: 0 1 '.$sizeValue.'px; font-size:'.$sizeValue.'px;">';
|
||||
$output .= $sla_array['sla_fixed'].'%';
|
||||
$output .= '</div>';
|
||||
|
||||
if (empty($label) === false) {
|
||||
// Div Label.
|
||||
$output .= '<div style="flex: 1 1; font-size:'.$sizeLabel.'px;">'.$label.'</div>';
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('SLA percentage');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'sla_percent';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,486 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget System group status Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget System group status
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* System group status Widgets.
|
||||
*/
|
||||
class SystemGroupStatusWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Groups status');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'system_group_status';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['groupId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Restrict access to group.
|
||||
$inputs[] = [
|
||||
'label' => __('Groups'),
|
||||
'arguments' => [
|
||||
'type' => 'select_groups',
|
||||
'name' => 'groupId[]',
|
||||
'returnAllGroup' => true,
|
||||
'privilege' => 'ER',
|
||||
'selected' => explode(',', $values['groupId'][0]),
|
||||
'return' => true,
|
||||
'multiple' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Graph Type.
|
||||
$fields = [
|
||||
AGENT_STATUS_NORMAL => __('Normal'),
|
||||
AGENT_STATUS_WARNING => __('Warning'),
|
||||
AGENT_STATUS_CRITICAL => __('Critical'),
|
||||
4 => __('Alert Fired'),
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Status'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'status[]',
|
||||
'selected' => explode(',', $values['status'][0]),
|
||||
'return' => true,
|
||||
'multiple' => true,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['groupId'] = \get_parameter('groupId', []);
|
||||
$values['status'] = \get_parameter('status', []);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
include_once 'include/functions_groupview.php';
|
||||
|
||||
// ACL Check.
|
||||
$agent_a = \check_acl($config['id_user'], 0, 'AR');
|
||||
$agent_w = \check_acl($config['id_user'], 0, 'AW');
|
||||
|
||||
if ($agent_a === 0 && $agent_w === 0) {
|
||||
\db_pandora_audit(
|
||||
'ACL Violation',
|
||||
'Trying to access Agent view (Grouped)'
|
||||
);
|
||||
include 'general/noaccess.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
// Groups and tags.
|
||||
$result_groups_info = \groupview_get_groups_list(
|
||||
$config['id_user'],
|
||||
($agent_a === 1) ? 'AR' : (($agent_w === 1) ? 'AW' : 'AR')
|
||||
);
|
||||
|
||||
$result_groups = $result_groups_info['groups'];
|
||||
$result_groups = array_reduce(
|
||||
$result_groups,
|
||||
function ($carry, $item) {
|
||||
$carry[$item['_id_']] = $item;
|
||||
return $carry;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
$this->values['groupId'] = explode(',', $this->values['groupId'][0]);
|
||||
|
||||
if (count($this->values['groupId']) === 1
|
||||
&& in_array(0, $this->values['groupId']) === true
|
||||
) {
|
||||
$this->values['groupId'] = [];
|
||||
foreach ($result_groups as $key => $value) {
|
||||
$this->values['groupId'][] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
$this->values['status'] = explode(',', $this->values['status'][0]);
|
||||
|
||||
$style = 'font-size: 12px; text-align: center;';
|
||||
|
||||
$table = new \stdClass();
|
||||
$table->class = 'group_modules_status_box';
|
||||
$table->cellpadding = '0';
|
||||
$table->cellspacing = '0';
|
||||
$table->width = '90%';
|
||||
$table->data = [];
|
||||
$table->size = [];
|
||||
$table->cellstyle = [];
|
||||
|
||||
$i = 1;
|
||||
|
||||
$show_normal = true;
|
||||
$show_warning = true;
|
||||
$show_critical = true;
|
||||
$show_alert_fired = true;
|
||||
$show_all = isset($this->values['status']) === false;
|
||||
if ($show_all === false) {
|
||||
$show_normal = in_array(
|
||||
AGENT_STATUS_NORMAL,
|
||||
$this->values['status']
|
||||
) === true;
|
||||
$show_warning = in_array(
|
||||
AGENT_STATUS_WARNING,
|
||||
$this->values['status']
|
||||
) === true;
|
||||
$show_critical = in_array(
|
||||
AGENT_STATUS_CRITICAL,
|
||||
$this->values['status']
|
||||
) === true;
|
||||
$show_alert_fired = in_array(
|
||||
4,
|
||||
$this->values['status']
|
||||
) === true;
|
||||
}
|
||||
|
||||
$flag_groups = false;
|
||||
foreach ($this->values['groupId'] as $groupId) {
|
||||
if (isset($result_groups[$groupId]) === true) {
|
||||
$group = $result_groups[$groupId];
|
||||
} else {
|
||||
$group = [
|
||||
'_monitors_critical_' => 0,
|
||||
'_monitors_warning_' => 0,
|
||||
'_monitors_unknown_' => 0,
|
||||
'_monitors_not_init_' => 0,
|
||||
'_monitors_ok_' => 0,
|
||||
'_monitor_checks_' => 0,
|
||||
'_monitors_alerts_fired_' => 0,
|
||||
'_agents_critical_' => 0,
|
||||
'_agents_warning_' => 0,
|
||||
'_agents_unknown_' => 0,
|
||||
'_agents_not_init_' => 0,
|
||||
'_agents_ok_' => 0,
|
||||
'_total_agents_' => 0,
|
||||
'_name_' => groups_get_name($groupId),
|
||||
'_id_' => $groupId,
|
||||
'_icon_' => groups_get_icon($groupId),
|
||||
'_monitor_not_normal_' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
if ($group['_id_'] === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$flag_groups = true;
|
||||
|
||||
if ((in_array($group['_id_'], $this->values['groupId'])) === true) {
|
||||
$table->data[$i][] = '<span>'.$group['_name_'].'</span>';
|
||||
|
||||
$url = $config['homeurl'].'index.php';
|
||||
$url .= '?sec=estado&sec2=operation/agentes/status_monitor';
|
||||
$url .= '&ag_group='.$group['_id_'];
|
||||
|
||||
if ($show_normal === true) {
|
||||
$outputLine = '<div style="background-color:#82b92e">';
|
||||
$outputLine .= '<span>';
|
||||
$outputLine .= '<a title="'.__('Modules in normal status');
|
||||
$outputLine .= '" class="group_view_data"';
|
||||
$outputLine .= ' style="'.$style.'"';
|
||||
$outputLine .= '" href="'.$url;
|
||||
$outputLine .= '&status='.AGENT_STATUS_NORMAL.'">';
|
||||
$outputLine .= $group['_monitors_ok_'];
|
||||
$outputLine .= '</a>';
|
||||
$outputLine .= '</span>';
|
||||
$outputLine .= '</div>';
|
||||
|
||||
$table->data[$i][] = $outputLine;
|
||||
}
|
||||
|
||||
if ($show_warning === true) {
|
||||
$outputLine = '<div style="background-color:#ffd036">';
|
||||
$outputLine .= '<span>';
|
||||
$outputLine .= '<a title="'.__('Modules in warning status');
|
||||
$outputLine .= '" class="group_view_data"';
|
||||
$outputLine .= ' style="'.$style.'"';
|
||||
$outputLine .= '" href="'.$url;
|
||||
$outputLine .= '&status='.AGENT_STATUS_WARNING.'">';
|
||||
$outputLine .= $group['_monitors_warning_'];
|
||||
$outputLine .= '</a>';
|
||||
$outputLine .= '</span>';
|
||||
$outputLine .= '</div>';
|
||||
|
||||
$table->data[$i][] = $outputLine;
|
||||
}
|
||||
|
||||
if ($show_critical === true) {
|
||||
$outputLine = '<div style="background-color:#ff5653">';
|
||||
$outputLine .= '<span>';
|
||||
$outputLine .= '<a title="';
|
||||
$outputLine .= __('Modules in critical status');
|
||||
$outputLine .= '" class="group_view_data"';
|
||||
$outputLine .= ' style="'.$style.'"';
|
||||
$outputLine .= '" href="'.$url;
|
||||
$outputLine .= '&status='.AGENT_STATUS_CRITICAL.'">';
|
||||
$outputLine .= $group['_monitors_critical_'];
|
||||
$outputLine .= '</a>';
|
||||
$outputLine .= '</span>';
|
||||
$outputLine .= '</div>';
|
||||
|
||||
$table->data[$i][] = $outputLine;
|
||||
}
|
||||
|
||||
if ($show_alert_fired === true) {
|
||||
$outputLine = '<div style="background-color:#ff9e39">';
|
||||
$outputLine .= '<span>';
|
||||
$outputLine .= '<a title="'.__('Alerts fired');
|
||||
$outputLine .= '" class="group_view_data"';
|
||||
$outputLine .= ' style="'.$style.'"';
|
||||
$outputLine .= '" href="'.$url;
|
||||
$outputLine .= '&filter=fired">';
|
||||
$outputLine .= $group['_monitors_alerts_fired_'];
|
||||
$outputLine .= '</a>';
|
||||
$outputLine .= '</span>';
|
||||
$outputLine .= '</div>';
|
||||
|
||||
$table->data[$i][] = $outputLine;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
$height = (count($result_groups) * 30);
|
||||
$style = 'min-width:200px; min-height:'.$height.'px;';
|
||||
$output = '<div class="container-center" style="'.$style.'">';
|
||||
if ($flag_groups === true) {
|
||||
$output .= html_print_table($table, true);
|
||||
} else {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_info_message(
|
||||
__('Not modules in this groups'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Groups status');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'system_group_status';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,459 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Tactical View Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Tactical View
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Tactical View Widgets.
|
||||
*/
|
||||
class TacticalWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
/**
|
||||
* PM access.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $pmAccess;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// Includes.
|
||||
include_once $config['homedir'].'/include/functions_reporting.php';
|
||||
include_once $config['homedir'].'/include/functions_reporting_html.php';
|
||||
|
||||
include_once $config['homedir'].'/include/functions_servers.php';
|
||||
include_once $config['homedir'].'/include/functions_tactical.php';
|
||||
include_once $config['homedir'].'/include/functions_graph.php';
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// PM Access.
|
||||
$this->pmAccess = \users_can_manage_group_all('PM');
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Tactical view');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'tactical';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['statusMonitor']) === true
|
||||
&& empty($this->values['serverPerformance']) === true
|
||||
&& empty($this->values['summary']) === true
|
||||
) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Default values.
|
||||
if (isset($values['statusMonitor']) === false) {
|
||||
$values['statusMonitor'] = 1;
|
||||
}
|
||||
|
||||
if (isset($values['serverPerformance']) === false) {
|
||||
$values['serverPerformance'] = 1;
|
||||
}
|
||||
|
||||
if (isset($values['summary']) === false) {
|
||||
$values['summary'] = 1;
|
||||
}
|
||||
|
||||
// Status and Monitor checks.
|
||||
$inputs[] = [
|
||||
'label' => __('Status and Monitor checks'),
|
||||
'arguments' => [
|
||||
'name' => 'statusMonitor',
|
||||
'id' => 'statusMonitor',
|
||||
'type' => 'switch',
|
||||
'value' => $values['statusMonitor'],
|
||||
],
|
||||
];
|
||||
|
||||
if ($this->pmAccess === true) {
|
||||
// Server performance.
|
||||
$inputs[] = [
|
||||
'label' => __('Server performance'),
|
||||
'arguments' => [
|
||||
'name' => 'serverPerformance',
|
||||
'id' => 'serverPerformance',
|
||||
'type' => 'switch',
|
||||
'value' => $values['serverPerformance'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// Summary.
|
||||
$inputs[] = [
|
||||
'label' => __('Summary'),
|
||||
'arguments' => [
|
||||
'name' => 'summary',
|
||||
'id' => 'summary',
|
||||
'type' => 'switch',
|
||||
'value' => $values['summary'],
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['statusMonitor'] = \get_parameter_switch('statusMonitor');
|
||||
$values['serverPerformance'] = \get_parameter_switch(
|
||||
'serverPerformance'
|
||||
);
|
||||
$values['summary'] = \get_parameter_switch('summary');
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$output = '';
|
||||
|
||||
$all_data = \tactical_status_modules_agents($config['id_user']);
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['monitor_not_init'] = (int) $all_data['_monitors_not_init_'];
|
||||
$data['monitor_unknown'] = (int) $all_data['_monitors_unknown_'];
|
||||
$data['monitor_ok'] = (int) $all_data['_monitors_ok_'];
|
||||
$data['monitor_warning'] = (int) $all_data['_monitors_warning_'];
|
||||
$data['monitor_critical'] = (int) $all_data['_monitors_critical_'];
|
||||
$data['monitor_not_normal'] = (int) $all_data['_monitor_not_normal_'];
|
||||
$data['monitor_alerts'] = (int) $all_data['_monitors_alerts_'];
|
||||
$data['monitor_alerts_fired'] = (int) $all_data['_monitors_alerts_fired_'];
|
||||
|
||||
$data['total_agents'] = (int) $all_data['_total_agents_'];
|
||||
|
||||
$data['monitor_checks'] = (int) $all_data['_monitor_checks_'];
|
||||
|
||||
// Percentages.
|
||||
if (empty($all_data) === false) {
|
||||
if ($data['monitor_not_normal'] > 0
|
||||
&& $data['monitor_checks'] > 0
|
||||
) {
|
||||
$data['monitor_health'] = \format_numeric(
|
||||
(100 - ($data['monitor_not_normal'] / ($data['monitor_checks'] / 100))),
|
||||
1
|
||||
);
|
||||
} else {
|
||||
$data['monitor_health'] = 100;
|
||||
}
|
||||
|
||||
if ($data['monitor_not_init'] > 0
|
||||
&& $data['monitor_checks'] > 0
|
||||
) {
|
||||
$data['module_sanity'] = \format_numeric(
|
||||
(100 - ($data['monitor_not_init'] / ($data['monitor_checks'] / 100))),
|
||||
1
|
||||
);
|
||||
} else {
|
||||
$data['module_sanity'] = 100;
|
||||
}
|
||||
|
||||
if (isset($data['alerts']) === true) {
|
||||
if ($data['monitor_alerts_fired'] > 0
|
||||
&& $data['alerts'] > 0
|
||||
) {
|
||||
$data['alert_level'] = \format_numeric(
|
||||
(100 - ($data['monitor_alerts_fired'] / ($data['alerts'] / 100))),
|
||||
1
|
||||
);
|
||||
} else {
|
||||
$data['alert_level'] = 100;
|
||||
}
|
||||
} else {
|
||||
$data['alert_level'] = 100;
|
||||
$data['alerts'] = 0;
|
||||
}
|
||||
|
||||
$data['monitor_bad'] = ($data['monitor_critical'] + $data['monitor_warning']);
|
||||
|
||||
if ($data['monitor_bad'] > 0
|
||||
&& $data['monitor_checks'] > 0
|
||||
) {
|
||||
$data['global_health'] = \format_numeric(
|
||||
(100 - ($data['monitor_bad'] / ($data['monitor_checks'] / 100))),
|
||||
1
|
||||
);
|
||||
} else {
|
||||
$data['global_health'] = 100;
|
||||
}
|
||||
|
||||
$data['server_sanity'] = \format_numeric(
|
||||
(100 - $data['module_sanity']),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->values['statusMonitor'] === 1) {
|
||||
$table = new \stdClass();
|
||||
$table->width = '100%';
|
||||
|
||||
$table->size[0] = '220px';
|
||||
|
||||
$table->align[0] = 'center';
|
||||
|
||||
$table->colspan = [];
|
||||
$table->colspan[0][1] = 2;
|
||||
|
||||
$table->rowclass = \array_fill(0, 9, '');
|
||||
|
||||
$table->data[0][0] = \reporting_get_stats_indicators(
|
||||
$data,
|
||||
120,
|
||||
25
|
||||
);
|
||||
$table->data[0][0] .= \reporting_get_stats_alerts($data);
|
||||
$table->cellstyle[0][0] = 'vertical-align: top;';
|
||||
|
||||
$table->data[0][1] = \reporting_get_stats_modules_status($data);
|
||||
$table->data[0][1] .= '<br>';
|
||||
$table->data[0][1] .= \reporting_get_stats_agents_monitors($data);
|
||||
$table->data[0][1] .= '<br>';
|
||||
$table->cellstyle[0][1] = 'vertical-align: top;';
|
||||
|
||||
$output .= \html_print_table($table, true);
|
||||
}
|
||||
|
||||
if ($this->values['serverPerformance'] === 1
|
||||
&& $this->pmAccess === true
|
||||
) {
|
||||
$table = new \stdClass();
|
||||
$table->width = '100%';
|
||||
$table->class = '';
|
||||
$table->cellpadding = 4;
|
||||
$table->cellspacing = 4;
|
||||
$table->border = 0;
|
||||
$table->head = [];
|
||||
$table->data = [];
|
||||
$table->style = [];
|
||||
|
||||
$table->data[0][0] = \reporting_get_stats_servers();
|
||||
|
||||
$output .= \html_print_table($table, true);
|
||||
}
|
||||
|
||||
if ($this->values['summary'] === 1) {
|
||||
$table = new \stdClass();
|
||||
$table->width = '100%';
|
||||
$table->class = '';
|
||||
$table->cellpadding = 4;
|
||||
$table->cellspacing = 4;
|
||||
$table->border = 0;
|
||||
$table->head = [];
|
||||
$table->data = [];
|
||||
$table->style = [];
|
||||
|
||||
$table->data[0][0] = \reporting_get_stats_summary($data, 150, 100);
|
||||
|
||||
$output .= \html_print_table($table, true);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription():string
|
||||
{
|
||||
return __('Tactical view');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'tactical';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,490 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Top N Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Top N
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Top N Widgets.
|
||||
*/
|
||||
class TopNWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// Includes.
|
||||
include_once $config['homedir'].'/include/functions_graph.php';
|
||||
include_once $config['homedir'].'/include/functions_agents.php';
|
||||
include_once $config['homedir'].'/include/functions_modules.php';
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Top N of agent modules');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'top_n';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['agent']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Default values.
|
||||
if (isset($values['quantity']) === false) {
|
||||
$values['quantity'] = 5;
|
||||
}
|
||||
|
||||
// Default values.
|
||||
if (isset($values['period']) === false) {
|
||||
$values['period'] = SECONDS_1DAY;
|
||||
}
|
||||
|
||||
// Agent.
|
||||
$inputs[] = [
|
||||
'label' => __('Agent').ui_print_help_tip(
|
||||
__('Case insensitive regular expression for agent name. For example: Network.* will match with the following agent names: network_agent1, NetworK CHECKS'),
|
||||
true
|
||||
),
|
||||
'arguments' => [
|
||||
'name' => 'agent',
|
||||
'type' => 'text',
|
||||
'value' => $values['agent'],
|
||||
'return' => true,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Module.
|
||||
$inputs[] = [
|
||||
'label' => __('Module').ui_print_help_tip(
|
||||
__('Case insensitive regular expression or string for module name. For example: .*usage.* will match: cpu_usage, vram usage.'),
|
||||
true
|
||||
),
|
||||
'arguments' => [
|
||||
'name' => 'module',
|
||||
'type' => 'text',
|
||||
'value' => $values['module'],
|
||||
'return' => true,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Period.
|
||||
$inputs[] = [
|
||||
'label' => __('Interval'),
|
||||
'arguments' => [
|
||||
'name' => 'period',
|
||||
'type' => 'interval',
|
||||
'value' => $values['period'],
|
||||
'nothing' => __('None'),
|
||||
'nothing_value' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Quantity (n).
|
||||
$inputs[] = [
|
||||
'label' => __('Quantity (n)'),
|
||||
'arguments' => [
|
||||
'name' => 'quantity',
|
||||
'type' => 'number',
|
||||
'value' => $values['quantity'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Order.
|
||||
$fields = [
|
||||
1 => __('Descending'),
|
||||
2 => __('Ascending'),
|
||||
3 => __('By agent name'),
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Order'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'order',
|
||||
'selected' => $values['order'],
|
||||
'return' => true,
|
||||
'sort' => false,
|
||||
],
|
||||
];
|
||||
|
||||
// Display.
|
||||
$fields = [
|
||||
REPORT_TOP_N_AVG => __('Avg.'),
|
||||
REPORT_TOP_N_MAX => __('Max.'),
|
||||
REPORT_TOP_N_MIN => __('Min.'),
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Display'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'display',
|
||||
'selected' => $values['display'],
|
||||
'return' => true,
|
||||
'sort' => false,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['agent'] = \get_parameter('agent', '');
|
||||
$values['module'] = \get_parameter('module', '');
|
||||
$values['period'] = \get_parameter('period', 0);
|
||||
$values['quantity'] = \get_parameter('quantity', 5);
|
||||
$values['order'] = \get_parameter('order', 1);
|
||||
$values['display'] = \get_parameter('display', REPORT_TOP_N_AVG);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$output = '';
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
$quantity = $this->values['quantity'];
|
||||
$period = $this->values['period'];
|
||||
|
||||
switch ($this->values['display']) {
|
||||
case 1:
|
||||
$display = 'max';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$display = 'min';
|
||||
break;
|
||||
|
||||
default:
|
||||
case 0:
|
||||
$display = 'avg';
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($this->values['order']) {
|
||||
case 2:
|
||||
$order = $display.' DESC';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$order = 'alias ASC';
|
||||
break;
|
||||
|
||||
default:
|
||||
case 1:
|
||||
$order = $display.' ASC';
|
||||
break;
|
||||
}
|
||||
|
||||
$agentRegex = $this->values['agent'];
|
||||
|
||||
$moduleRegex = '';
|
||||
if (empty($this->values['module']) === false) {
|
||||
$moduleRegex = sprintf(
|
||||
"AND tam.nombre REGEXP '%s'",
|
||||
$this->values['module']
|
||||
);
|
||||
}
|
||||
|
||||
// This function check ACL.
|
||||
$agents = agents_get_group_agents(0, ['aliasRegex' => $agentRegex]);
|
||||
$agentsId = \array_keys($agents);
|
||||
$agentsIdString = \implode(',', $agentsId);
|
||||
|
||||
// Initialize variables.
|
||||
$date = \get_system_time();
|
||||
$datelimit = ($date - $period);
|
||||
$search_in_history_db = db_search_in_history_db($datelimit);
|
||||
|
||||
$sql = \sprintf(
|
||||
'SELECT tam.id_agente_modulo as id_module,
|
||||
tam.id_agente as id_agent,
|
||||
ta.alias as aliasAgent,
|
||||
tam.id_tipo_modulo as type_module,
|
||||
tam.nombre as nameModule,
|
||||
tam.unit as unit,
|
||||
MIN(tad.datos) as `min`,
|
||||
MAX(tad.datos) as `max`,
|
||||
AVG(tad.datos) as `avg`
|
||||
FROM tagente_modulo tam
|
||||
INNER JOIN tagente ta
|
||||
ON ta.id_agente = tam.id_agente
|
||||
LEFT JOIN tagente_datos tad
|
||||
ON tam.id_agente_modulo = tad.id_agente_modulo
|
||||
WHERE tam.id_agente IN (%s)
|
||||
%s
|
||||
AND tad.utimestamp > %d
|
||||
AND tad.utimestamp < %d
|
||||
GROUP BY tad.id_agente_modulo
|
||||
ORDER BY %s
|
||||
LIMIT %d',
|
||||
$agentsIdString,
|
||||
$moduleRegex,
|
||||
$datelimit,
|
||||
$date,
|
||||
$order,
|
||||
$quantity
|
||||
);
|
||||
|
||||
$modules = \db_get_all_rows_sql(
|
||||
$sql,
|
||||
$search_in_history_db
|
||||
);
|
||||
|
||||
if (empty($modules) === true) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_info_message(
|
||||
__('There are no Agent/Modules defined'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
$data_hbar = [];
|
||||
foreach ($modules as $module) {
|
||||
$item_name = '';
|
||||
$item_name = $module['aliasAgent'].' - '.$module['nameModule'];
|
||||
$data_hbar[$item_name]['g'] = $module[$display];
|
||||
}
|
||||
|
||||
$height = (count($data_hbar) * 25 + 35);
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= hbar_graph(
|
||||
array_reverse($data_hbar),
|
||||
$size['width'],
|
||||
$height,
|
||||
[],
|
||||
[],
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
$config['homedir'].'/images/logo_vertical_water.png',
|
||||
$config['fontpath'],
|
||||
$config['font_size'],
|
||||
true,
|
||||
1,
|
||||
$config['homeurl'],
|
||||
'white',
|
||||
'black'
|
||||
);
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Top N of agent modules');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'top_n';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,434 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget TopN events by group Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget TopN events by group
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* TopN events by group Widgets.
|
||||
*/
|
||||
class TopNEventByGroupWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// Include.
|
||||
include_once $config['homedir'].'/include/functions_events.php';
|
||||
include_once $config['homedir'].'/include/functions_users.php';
|
||||
include_once $config['homedir'].'/include/functions_agents.php';
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Top N events by agent');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'top_n_events_by_group';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['groupId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Default values.
|
||||
if (isset($values['amountShow']) === false) {
|
||||
$values['amountShow'] = 10;
|
||||
}
|
||||
|
||||
if (isset($values['maxHours']) === false) {
|
||||
$values['maxHours'] = 8;
|
||||
}
|
||||
|
||||
// Text size of value in px.
|
||||
$inputs[] = [
|
||||
'label' => __('Amount to show'),
|
||||
'arguments' => [
|
||||
'name' => 'amountShow',
|
||||
'type' => 'number',
|
||||
'value' => $values['amountShow'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Text size of value in px.
|
||||
$inputs[] = [
|
||||
'label' => __('Max. hours old'),
|
||||
'arguments' => [
|
||||
'name' => 'maxHours',
|
||||
'type' => 'number',
|
||||
'value' => $values['maxHours'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Groups.
|
||||
$inputs[] = [
|
||||
'label' => __('Groups'),
|
||||
'arguments' => [
|
||||
'type' => 'select_groups',
|
||||
'name' => 'groupId[]',
|
||||
'returnAllGroup' => true,
|
||||
'privilege' => 'AR',
|
||||
'selected' => explode(',', $values['groupId'][0]),
|
||||
'return' => true,
|
||||
'multiple' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Legend Position.
|
||||
$fields = [
|
||||
'bottom' => __('Bottom'),
|
||||
'hidden' => __('No legend'),
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Legend Position'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'legendPosition',
|
||||
'selected' => $values['legendPosition'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['amountShow'] = \get_parameter('amountShow', 0);
|
||||
$values['maxHours'] = \get_parameter('maxHours', 0);
|
||||
$values['groupId'] = \get_parameter('groupId', []);
|
||||
$values['legendPosition'] = \get_parameter('legendPosition', 0);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$output = '';
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
$this->values['groupId'] = explode(',', $this->values['groupId'][0]);
|
||||
|
||||
if (empty($this->values['groupId']) === true) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_info_message(
|
||||
__('Please select one or more groups.'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
} else {
|
||||
$timestamp = (time() - SECONDS_1HOUR * $this->values['maxHours']);
|
||||
|
||||
$all_group = false;
|
||||
// Search all.
|
||||
if (array_search('0', $this->values['groupId']) !== false) {
|
||||
$all_group = true;
|
||||
}
|
||||
|
||||
if ($all_group === false) {
|
||||
$sql = sprintf(
|
||||
'SELECT id_agente, COUNT(*) AS count
|
||||
FROM tevento
|
||||
WHERE utimestamp >= %d
|
||||
AND id_grupo IN (%s)
|
||||
GROUP BY id_agente
|
||||
ORDER BY count DESC
|
||||
LIMIT %d',
|
||||
implode(',', $this->values['groupId']),
|
||||
$timestamp,
|
||||
$this->values['amountShow']
|
||||
);
|
||||
} else {
|
||||
$sql = sprintf(
|
||||
'SELECT id_agente, COUNT(*) AS count
|
||||
FROM tevento
|
||||
WHERE utimestamp >= %d
|
||||
GROUP BY id_agente
|
||||
ORDER BY count DESC
|
||||
LIMIT %d',
|
||||
$timestamp,
|
||||
$this->values['amountShow']
|
||||
);
|
||||
}
|
||||
|
||||
$result = db_get_all_rows_sql($sql);
|
||||
|
||||
if (empty($result) === true) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('There is not data to show.'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
} else {
|
||||
$data_pie = [];
|
||||
foreach ($result as $row) {
|
||||
if ($row['id_agente'] == 0) {
|
||||
$name = __('System');
|
||||
} else {
|
||||
$name = io_safe_output(
|
||||
agents_get_alias($row['id_agente'])
|
||||
);
|
||||
}
|
||||
|
||||
$name .= ' ('.$row['count'].')';
|
||||
|
||||
$data_pie[$name] = $row['count'];
|
||||
}
|
||||
}
|
||||
|
||||
$width = $size['width'];
|
||||
$height = $size['height'];
|
||||
|
||||
switch ($this->values['legendPosition']) {
|
||||
case 'hidden':
|
||||
$height = ($height - 50);
|
||||
break;
|
||||
|
||||
default:
|
||||
case 'bottom':
|
||||
$numleg = count($data_pie);
|
||||
if ($numleg >= 4) {
|
||||
$numleg = 4;
|
||||
} else if ($numleg < 4 && $numleg > 1) {
|
||||
$numleg = 2;
|
||||
} else if ($numleg == 1) {
|
||||
$numleg = 1.5;
|
||||
}
|
||||
|
||||
// % is for the pie group the slices and show only 5.
|
||||
$height = ($height - (65 * ($numleg)));
|
||||
break;
|
||||
}
|
||||
|
||||
$output .= pie_graph(
|
||||
$data_pie,
|
||||
$width,
|
||||
$height,
|
||||
__('other'),
|
||||
'',
|
||||
false,
|
||||
$config['fontpath'],
|
||||
$config['font_size'],
|
||||
1,
|
||||
$this->values['legendPosition'],
|
||||
'',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Top N events by agent');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'top_n_events_by_group';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,471 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Top N events by module Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Top N events by module
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Top N events by module Widgets.
|
||||
*/
|
||||
class TopNEventByModuleWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// Include.
|
||||
include_once $config['homedir'].'/include/functions_events.php';
|
||||
include_once $config['homedir'].'/include/functions_users.php';
|
||||
include_once $config['homedir'].'/include/functions_agents.php';
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Top N events by module');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'top_n_events_by_module';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['groupId']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Default values.
|
||||
if (isset($values['amountShow']) === false) {
|
||||
$values['amountShow'] = 10;
|
||||
}
|
||||
|
||||
if (isset($values['maxHours']) === false) {
|
||||
$values['maxHours'] = 8;
|
||||
}
|
||||
|
||||
// Text size of value in px.
|
||||
$inputs[] = [
|
||||
'label' => __('Amount to show'),
|
||||
'arguments' => [
|
||||
'name' => 'amountShow',
|
||||
'type' => 'number',
|
||||
'value' => $values['amountShow'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Text size of value in px.
|
||||
$inputs[] = [
|
||||
'label' => __('Max. hours old'),
|
||||
'arguments' => [
|
||||
'name' => 'maxHours',
|
||||
'type' => 'number',
|
||||
'value' => $values['maxHours'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Groups.
|
||||
$inputs[] = [
|
||||
'label' => __('Groups'),
|
||||
'arguments' => [
|
||||
'type' => 'select_groups',
|
||||
'name' => 'groupId[]',
|
||||
'returnAllGroup' => true,
|
||||
'privilege' => 'AR',
|
||||
'selected' => explode(',', $values['groupId'][0]),
|
||||
'return' => true,
|
||||
'multiple' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Legend Position.
|
||||
$fields = [
|
||||
'bottom' => __('Bottom'),
|
||||
'hidden' => __('No legend'),
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Legend Position'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'legendPosition',
|
||||
'selected' => $values['legendPosition'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['amountShow'] = \get_parameter('amountShow', 0);
|
||||
$values['maxHours'] = \get_parameter('maxHours', 0);
|
||||
$values['groupId'] = \get_parameter('groupId', []);
|
||||
$values['legendPosition'] = \get_parameter('legendPosition', 0);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
$this->values['groupId'] = explode(',', $this->values['groupId'][0]);
|
||||
|
||||
if (empty($this->values['groupId']) === true) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_info_message(
|
||||
__('Please select one or more groups.'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
} else {
|
||||
$timestamp = (time() - SECONDS_1HOUR * $this->values['maxHours']);
|
||||
|
||||
$all_group = false;
|
||||
// Search all.
|
||||
if (array_search('0', $this->values['groupId']) !== false) {
|
||||
$all_group = true;
|
||||
}
|
||||
|
||||
if ($all_group === false) {
|
||||
$sql = sprintf(
|
||||
'SELECT id_agentmodule, COUNT(*) AS count
|
||||
FROM tevento
|
||||
WHERE utimestamp >= %d
|
||||
AND id_grupo IN (%s)
|
||||
GROUP BY id_agentmodule, event_type
|
||||
ORDER BY count DESC
|
||||
LIMIT %d',
|
||||
implode(',', $this->values['groupId']),
|
||||
$timestamp,
|
||||
$this->values['amountShow']
|
||||
);
|
||||
} else {
|
||||
$sql = sprintf(
|
||||
'SELECT id_agentmodule, COUNT(*) AS count
|
||||
FROM tevento
|
||||
WHERE utimestamp >= %d
|
||||
GROUP BY id_agentmodule, event_type
|
||||
ORDER BY count DESC
|
||||
LIMIT %d',
|
||||
$timestamp,
|
||||
$this->values['amountShow']
|
||||
);
|
||||
}
|
||||
|
||||
$result = db_get_all_rows_sql($sql);
|
||||
|
||||
if (empty($result) === true) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= \ui_print_error_message(
|
||||
__('There is not data to show.'),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
} else {
|
||||
$data_pie = [];
|
||||
foreach ($result as $row) {
|
||||
if ($row['id_agentmodule'] == 0) {
|
||||
$name = __('System');
|
||||
} else {
|
||||
$name_agent = io_safe_output(
|
||||
agents_get_alias($row['id_agentmodule'])
|
||||
);
|
||||
$name_module = io_safe_output(
|
||||
modules_get_agentmodule_name($row['id_agentmodule'])
|
||||
);
|
||||
if ($size['width'] < 400) {
|
||||
$name_agent = ui_print_truncate_text(
|
||||
$name_agent,
|
||||
15,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
'…',
|
||||
false
|
||||
);
|
||||
$name_module = ui_print_truncate_text(
|
||||
$name_module,
|
||||
15,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
'…',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
$name = $name_agent.' - '.$name_module;
|
||||
}
|
||||
|
||||
$event_name = events_print_type_description(
|
||||
$row['event_type'],
|
||||
true
|
||||
);
|
||||
if ($size['width'] < 400) {
|
||||
$event_name = ui_print_truncate_text(
|
||||
$event_name,
|
||||
20,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
'…',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
$data_pie[$event_name.' [ '.$name.' ] ('.$row['count'].')'] = $row['count'];
|
||||
}
|
||||
}
|
||||
|
||||
$width = $size['width'];
|
||||
$height = $size['height'];
|
||||
|
||||
switch ($this->values['legendPosition']) {
|
||||
case 'hidden':
|
||||
$height = ($height - 50);
|
||||
break;
|
||||
|
||||
default:
|
||||
case 'bottom':
|
||||
$numleg = count($data_pie);
|
||||
if ($numleg >= 4) {
|
||||
$numleg = 4;
|
||||
} else if ($numleg < 4 && $numleg > 1) {
|
||||
$numleg = 2;
|
||||
} else if ($numleg == 1) {
|
||||
$numleg = 1.5;
|
||||
}
|
||||
|
||||
// % is for the pie group the slices and show only 5
|
||||
$height = ($height - (65 * ($numleg)));
|
||||
break;
|
||||
}
|
||||
|
||||
$output .= pie_graph(
|
||||
$data_pie,
|
||||
$width,
|
||||
$height,
|
||||
__('other'),
|
||||
'',
|
||||
false,
|
||||
$config['fontpath'],
|
||||
$config['font_size'],
|
||||
1,
|
||||
$this->values['legendPosition'],
|
||||
'',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Top N events by module');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'top_n_events_by_module';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,566 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Tree view Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Tree view
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Tree view Widgets.
|
||||
*/
|
||||
class TreeViewWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
/**
|
||||
* Cell ID.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $cellId;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
ui_require_css_file('tree');
|
||||
ui_require_css_file('fixed-bottom-box');
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Cell Id.
|
||||
$this->cellId = $cellId;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Tree view');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'tree_view';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (isset($this->values['groupId']) === false) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Type tree view.
|
||||
$fields = [
|
||||
'group' => __('Groups'),
|
||||
'tag' => __('Tags'),
|
||||
'module_group' => __('Module groups'),
|
||||
'module' => __('Modules'),
|
||||
'os' => __('OS'),
|
||||
'policies' => __('Policies'),
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Type tree'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'typeTree',
|
||||
'selected' => $values['typeTree'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Groups.
|
||||
$inputs[] = [
|
||||
'label' => __('Groups'),
|
||||
'arguments' => [
|
||||
'type' => 'select_groups',
|
||||
'name' => 'groupId',
|
||||
'returnAllGroup' => true,
|
||||
'privilege' => 'AR',
|
||||
'selected' => $values['groupId'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Open all groups.
|
||||
$inputs[] = [
|
||||
'label' => __('Open all groups'),
|
||||
'arguments' => [
|
||||
'name' => 'openAllGroups',
|
||||
'id' => 'openAllGroups',
|
||||
'type' => 'switch',
|
||||
'value' => $values['openAllGroups'],
|
||||
],
|
||||
];
|
||||
|
||||
// Agents status.
|
||||
$fields = [
|
||||
AGENT_STATUS_ALL => __('All'),
|
||||
AGENT_STATUS_NORMAL => __('Normal'),
|
||||
AGENT_STATUS_WARNING => __('Warning'),
|
||||
AGENT_STATUS_CRITICAL => __('Critical'),
|
||||
AGENT_STATUS_UNKNOWN => __('Unknown'),
|
||||
AGENT_STATUS_NOT_INIT => __('Not init'),
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Agents status'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'agentStatus',
|
||||
'selected' => $values['agentStatus'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Filter agents.
|
||||
$inputs[] = [
|
||||
'label' => __('Filter agents'),
|
||||
'arguments' => [
|
||||
'name' => 'filterAgent',
|
||||
'type' => 'text',
|
||||
'value' => $values['filterAgent'],
|
||||
'return' => true,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
// Modules status.
|
||||
$fields = [
|
||||
-1 => __('All'),
|
||||
AGENT_MODULE_STATUS_NORMAL => __('Normal'),
|
||||
AGENT_MODULE_STATUS_WARNING => __('Warning'),
|
||||
AGENT_MODULE_STATUS_CRITICAL_BAD => __('Critical'),
|
||||
AGENT_MODULE_STATUS_UNKNOWN => __('Unknown'),
|
||||
AGENT_MODULE_STATUS_NOT_INIT => __('Not init'),
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Modules status'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'name' => 'moduleStatus',
|
||||
'selected' => $values['moduleStatus'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Filter modules.
|
||||
$inputs[] = [
|
||||
'label' => __('Filter modules'),
|
||||
'arguments' => [
|
||||
'name' => 'filterModule',
|
||||
'type' => 'text',
|
||||
'value' => $values['filterModule'],
|
||||
'return' => true,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['typeTree'] = \get_parameter('typeTree', '');
|
||||
$values['groupId'] = \get_parameter('groupId', 0);
|
||||
$values['openAllGroups'] = \get_parameter_switch('openAllGroups');
|
||||
$values['agentStatus'] = \get_parameter('agentStatus', 0);
|
||||
$values['filterAgent'] = \get_parameter('filterAgent', '');
|
||||
$values['moduleStatus'] = \get_parameter('moduleStatus', 0);
|
||||
$values['filterModule'] = \get_parameter('filterModule', '');
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
$output = '';
|
||||
|
||||
if (check_acl($config['id_user'], 0, 'AR') === 0) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= ui_print_error_message(
|
||||
__(
|
||||
'The user doesn\'t have permission to read agents. Please contact with your %s administrator.',
|
||||
get_product_name()
|
||||
),
|
||||
'',
|
||||
true
|
||||
);
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
$id_cell = $this->cellId;
|
||||
$all_nodes = $this->values['openAllGroups'];
|
||||
|
||||
$tab = 'group';
|
||||
if (empty($this->values['typeTree']) === false) {
|
||||
$tab = $this->values['typeTree'];
|
||||
}
|
||||
|
||||
$statusAgent = -1;
|
||||
if (isset($this->values['agentStatus']) === true
|
||||
&& $this->values['agentStatus'] !== AGENT_STATUS_ALL
|
||||
) {
|
||||
$statusAgent = $this->values['agentStatus'];
|
||||
}
|
||||
|
||||
$searchAgent = '';
|
||||
if (empty($this->values['filterAgent']) === false) {
|
||||
$searchAgent = $this->values['filterAgent'];
|
||||
}
|
||||
|
||||
$statusModule = -1;
|
||||
if (isset($this->values['moduleStatus']) === true
|
||||
&& $this->values['moduleStatus'] !== -1
|
||||
) {
|
||||
$statusModule = $this->values['moduleStatus'];
|
||||
}
|
||||
|
||||
$searchModule = '';
|
||||
if (empty($this->values['filterModule']) === false) {
|
||||
$searchModule = $this->values['filterModule'];
|
||||
}
|
||||
|
||||
$searchGroup = 0;
|
||||
if (empty($this->values['groupId']) === false) {
|
||||
$searchGroup = $this->values['groupId'];
|
||||
}
|
||||
|
||||
$width = $size['width'];
|
||||
$height = $size['height'];
|
||||
|
||||
// Css Files.
|
||||
\ui_require_css_file('tree', 'include/styles/', true);
|
||||
|
||||
// Javascript Files.
|
||||
\ui_include_time_picker();
|
||||
\ui_require_jquery_file(
|
||||
'ui.datepicker-'.\get_user_language(),
|
||||
'include/javascript/i18n/'
|
||||
);
|
||||
|
||||
\ui_require_javascript_file(
|
||||
'TreeController',
|
||||
'include/javascript/tree/',
|
||||
true
|
||||
);
|
||||
|
||||
\ui_require_javascript_file(
|
||||
'fixed-bottom-box',
|
||||
'include/javascript/',
|
||||
true
|
||||
);
|
||||
|
||||
$base_url = \ui_get_full_url(
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
\is_metaconsole()
|
||||
);
|
||||
|
||||
// Spinner.
|
||||
$output .= \html_print_image(
|
||||
'images/spinner.gif',
|
||||
true,
|
||||
[
|
||||
'class' => 'loading_tree',
|
||||
'style' => 'display: none;',
|
||||
]
|
||||
);
|
||||
|
||||
// Container tree.
|
||||
$style = 'height:'.$height.'px; width:'.$width.'px;';
|
||||
$style .= 'text-align: left; padding:10px;';
|
||||
$idTree = 'tree-controller-recipient_'.$id_cell;
|
||||
|
||||
$output .= '<div style="'.$style.'" id="'.$idTree.'">';
|
||||
$output .= '</div>';
|
||||
|
||||
$output .= \html_print_input_hidden(
|
||||
'publi_dash_tree_view_hash',
|
||||
$hash,
|
||||
true
|
||||
);
|
||||
$output .= \html_print_input_hidden(
|
||||
'publi_dash_tree_view_id_user',
|
||||
$config['id_user'],
|
||||
true
|
||||
);
|
||||
|
||||
$settings = [
|
||||
'page' => 'include/ajax/tree.ajax',
|
||||
'user' => $config['id_user'],
|
||||
'hash' => $hash,
|
||||
'type' => $tab,
|
||||
'cellId' => $id_cell,
|
||||
'ajaxUrl' => ui_get_full_url('ajax.php', false, false, false),
|
||||
'baseUrl' => $base_url,
|
||||
'searchAgent' => $searchAgent,
|
||||
'statusAgent' => $statusAgent,
|
||||
'searchModule' => $searchModule,
|
||||
'statusModule' => $statusModule,
|
||||
'searchGroup' => $searchGroup,
|
||||
'openAllNodes' => $all_nodes,
|
||||
'timeFormat' => TIME_FORMAT_JS,
|
||||
'dateFormat' => DATE_FORMAT_JS,
|
||||
'userLanguage' => get_user_language(),
|
||||
'translate' => [
|
||||
'emptyMessage' => __('No data found'),
|
||||
'foundMessage' => 'not',
|
||||
'total' => [
|
||||
'agents' => __('Total agents'),
|
||||
'modules' => __('Total modules'),
|
||||
'none' => __('Total'),
|
||||
],
|
||||
'alerts' => [
|
||||
'agents' => __('Fired alerts'),
|
||||
'modules' => __('Fired alerts'),
|
||||
'none' => __('Fired alerts'),
|
||||
],
|
||||
'critical' => [
|
||||
'agents' => __('Critical agents'),
|
||||
'modules' => __('Critical modules'),
|
||||
'none' => __('Critical'),
|
||||
],
|
||||
'warning' => [
|
||||
'agents' => __('Warning agents'),
|
||||
'modules' => __('Warning modules'),
|
||||
'none' => __('Warning'),
|
||||
],
|
||||
'unknown' => [
|
||||
'agents' => __('Unknown agents'),
|
||||
'modules' => __('Unknown modules'),
|
||||
'none' => __('Unknown'),
|
||||
],
|
||||
'not_init' => [
|
||||
'agents' => __('Not init agents'),
|
||||
'modules' => __('Not init modules'),
|
||||
'none' => __('Not init'),
|
||||
],
|
||||
'ok' => [
|
||||
'agents' => __('Normal agents'),
|
||||
'modules' => __('Normal modules'),
|
||||
'none' => __('Normal'),
|
||||
],
|
||||
'module' => __('Module'),
|
||||
'timeOnlyTitle' => __('Choose time'),
|
||||
'timeText' => __('Time'),
|
||||
'hourText' => __('Hour'),
|
||||
'minuteText' => __('Minute'),
|
||||
'secondText' => __('Second'),
|
||||
'currentText' => __('Now'),
|
||||
'closeText' => __('Close'),
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
// Show the modal window of an module.
|
||||
$output .= '<div id="module_details_window" style="display:none;">';
|
||||
$output .= '</div>';
|
||||
|
||||
// Script.
|
||||
$output .= '<script type="text/javascript">';
|
||||
$output .= 'processTreeSearch('.\json_encode($settings).')';
|
||||
$output .= '</script>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Tree view');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'tree_view';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,276 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget URL Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget URL
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* 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 for version 2.
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* URL Widgets
|
||||
*/
|
||||
class UrlWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('URL content');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'url';
|
||||
}
|
||||
|
||||
// This forces at least a first configuration.
|
||||
$this->configurationRequired = false;
|
||||
if (empty($this->values['urlText']) === true) {
|
||||
$this->configurationRequired = true;
|
||||
}
|
||||
|
||||
$this->overflow_scrollbars = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Url.
|
||||
$inputs[] = [
|
||||
'label' => __('Url'),
|
||||
'arguments' => [
|
||||
'name' => 'urlText',
|
||||
'type' => 'text',
|
||||
'value' => $values['urlText'],
|
||||
'return' => true,
|
||||
'size' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['urlText'] = \get_parameter('urlText', '');
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string;
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
$output = '';
|
||||
|
||||
$url = $this->values['urlText'];
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
$width = $size['width'];
|
||||
$height = $size['height'];
|
||||
|
||||
if (isset($url) === false || empty($url) === true) {
|
||||
$output .= __('Please, configure this widget before use');
|
||||
} else {
|
||||
if (!preg_match('/^https?:\/\/.+/', $url)) {
|
||||
$url = 'http://'.$url;
|
||||
}
|
||||
|
||||
$url = str_replace('watch?v=', 'embed/', $url);
|
||||
$style = 'border:none; width:100%; height:'.$height.'px;';
|
||||
$output .= '<iframe id="item" src="'.$url.'" style="'.$style.'">';
|
||||
$output .= '</iframe>';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('URL content');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'url';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
/*
|
||||
// ______ __ _______ _______ _______
|
||||
//| __ \.---.-.-----.--| |.-----.----.---.-. | ___| | | __|
|
||||
//| __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
//|___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
//
|
||||
// ============================================================================
|
||||
// Copyright (c) 2007-2010 Artica Soluciones Tecnologicas, http://www.artica.es
|
||||
// This code is NOT free software. This code is NOT licenced under GPL2 licence
|
||||
// You cannnot redistribute it without written permission of copyright holder.
|
||||
// ============================================================================
|
||||
|
||||
DEPRECATED
|
||||
|
||||
This widget have been deprecated. Use WUX widgets to show UX transactions
|
||||
|
||||
*/
|