2013-04-10 09:57:54 +02:00
< ? php
2022-04-28 10:07:44 +02:00
/**
* Table builder for Servers View .
*
* @ category View
* @ package Pandora FMS
* @ subpackage Monitoring .
* @ version 1.0 . 0
* @ license See below
*
* ______ ___ _______ _______ ________
2023-06-08 12:42:10 +02:00
* | __ \ .-----.--.--.--| |.-----.----.-----. | ___ | | | __ |
* | __ /| _ | | _ || _ | _ | _ | | ___ | | __ |
2022-04-28 10:07:44 +02:00
* | ___ | | ___ . _ | __ | __ | _____ || _____ | __ | | ___ . _ | | ___ | | __ | _ | __ | _______ |
*
* ============================================================================
2023-06-08 11:53:13 +02:00
* Copyright ( c ) 2005 - 2023 Pandora FMS
2023-06-08 13:19:01 +02:00
* Please see https :// pandorafms . com / community / for full contribution list
2022-04-28 10:07:44 +02:00
* 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 .
* ============================================================================
*/
// Begin.
2019-01-30 16:18:44 +01:00
require_once 'include/functions_clippy.php' ;
2023-07-21 11:50:53 +02:00
require_once 'pending_alerts_list.php' ;
2015-02-03 15:43:44 +01:00
2013-04-10 09:57:54 +02:00
global $config ;
check_login ();
2022-04-28 10:07:44 +02:00
if (( bool ) check_acl ( $config [ 'id_user' ], 0 , 'AR' ) === false ) {
2019-01-30 16:18:44 +01:00
db_pandora_audit (
2022-01-20 10:55:23 +01:00
AUDIT_LOG_ACL_VIOLATION ,
2019-01-30 16:18:44 +01:00
'Trying to access Server Management'
);
include 'general/noaccess.php' ;
exit ;
2013-04-10 09:57:54 +02:00
}
global $tiny ;
2015-11-10 10:06:51 +01:00
global $hidden_toggle ;
2016-03-15 16:02:27 +01:00
$date = time ();
2013-04-10 09:57:54 +02:00
2013-08-21 14:37:37 +02:00
$servers = servers_get_info ();
2013-04-10 09:57:54 +02:00
if ( $servers === false ) {
2019-01-30 16:18:44 +01:00
$server_clippy = clippy_context_help ( 'servers_down' );
echo " <div class='nf'> " . __ ( 'There are no servers configured into the database' ) . $server_clippy . '</div>' ;
return ;
2013-04-10 09:57:54 +02:00
}
2015-06-25 10:07:53 +02:00
$table = new StdClass ();
2023-02-22 17:41:19 +01:00
$table -> class = 'info_table' ;
2019-03-27 17:03:55 +01:00
$table -> cellpadding = 0 ;
$table -> cellspacing = 0 ;
2019-01-30 16:18:44 +01:00
$table -> size = [];
2013-04-10 09:57:54 +02:00
2019-01-30 16:18:44 +01:00
$table -> style = [];
2023-02-22 12:15:17 +01:00
// $table->style[0] = 'font-weight: bold';
2019-01-30 16:18:44 +01:00
$table -> align = [];
2013-04-10 09:57:54 +02:00
$table -> align [ 1 ] = 'center' ;
$table -> align [ 3 ] = 'center' ;
2019-06-03 11:16:51 +02:00
$table -> align [ 8 ] = 'right' ;
2013-04-10 09:57:54 +02:00
2015-04-15 09:45:13 +02:00
$table -> headstyle [ 1 ] = 'text-align:center' ;
$table -> headstyle [ 3 ] = 'text-align:center' ;
2019-06-03 11:21:44 +02:00
$table -> headstyle [ 8 ] = 'text-align:right;width: 120px;' ;
2015-04-15 09:45:13 +02:00
2013-04-10 09:57:54 +02:00
$table -> titleclass = 'tabletitle' ;
$table -> titlestyle = 'text-transform:uppercase;' ;
2023-04-21 14:36:32 +02:00
$table -> style [ 6 ] = 'display: flex;align-items: center;' ;
2019-01-30 16:18:44 +01:00
$table -> head = [];
2013-04-10 09:57:54 +02:00
$table -> head [ 0 ] = __ ( 'Name' );
$table -> head [ 1 ] = __ ( 'Status' );
$table -> head [ 2 ] = __ ( 'Type' );
2015-04-28 14:01:48 +02:00
$table -> head [ 3 ] = __ ( 'Version' );
2013-04-10 09:57:54 +02:00
$table -> head [ 4 ] = __ ( 'Modules' );
2019-01-30 16:18:44 +01:00
$table -> head [ 5 ] = __ ( 'Lag' ) . ui_print_help_tip ( __ ( 'Avg. Delay(sec)/Modules delayed' ), true );
$table -> head [ 6 ] = __ ( 'T/Q' ) . ui_print_help_tip ( __ ( 'Threads / Queued modules currently' ), true );
2022-04-28 10:07:44 +02:00
// This will have a column of data such as "6 hours".
2013-04-10 09:57:54 +02:00
$table -> head [ 7 ] = __ ( 'Updated' );
2022-04-28 10:07:44 +02:00
// Only Pandora Administrator can delete servers.
if (( bool ) check_acl ( $config [ 'id_user' ], 0 , 'PM' ) === true ) {
2019-01-30 16:18:44 +01:00
$table -> head [ 8 ] = '<span title="Operations">' . __ ( 'Op.' ) . '</span>' ;
2013-04-10 09:57:54 +02:00
}
2019-01-30 16:18:44 +01:00
$table -> data = [];
$names_servers = [];
2021-01-29 14:02:35 +01:00
$master = 1 ;
// The server with the highest number in master, will be the real master.
foreach ( $servers as $server ) {
if ( $server [ 'master' ] > $master ) {
$master = $server [ 'master' ];
}
}
2013-04-10 09:57:54 +02:00
2023-06-29 16:09:25 +02:00
$ext = '' ;
// Check for any data-type server present in servers list. If none, enable server access for first server.
if ( array_search ( 'data' , array_column ( $servers , 'type' )) === false ) {
$ext = '_server' ;
}
2013-04-10 09:57:54 +02:00
foreach ( $servers as $server ) {
2019-01-30 16:18:44 +01:00
$data = [];
2022-04-28 10:07:44 +02:00
2019-04-02 13:42:30 +02:00
$table -> cellclass [] = [
3 => 'progress_bar' ,
2022-11-30 10:14:42 +01:00
8 => 'table_action_buttons' ,
2019-04-02 13:42:30 +02:00
];
2019-01-30 16:18:44 +01:00
$data [ 0 ] = '<span title="' . $server [ 'version' ] . '">' . strip_tags ( $server [ 'name' ]) . '</span>' ;
2023-01-20 13:11:49 +01:00
$server_keepalive = time_w_fixed_tz ( $server [ 'keepalive' ]);
if ( $server [ 'server_keepalive_utimestamp' ] > 0 ) {
$server_keepalive = $server [ 'server_keepalive_utimestamp' ];
}
2022-04-28 10:07:44 +02:00
// Status.
2019-01-30 16:18:44 +01:00
$data [ 1 ] = ui_print_status_image ( STATUS_SERVER_OK , '' , true );
2020-10-21 17:03:46 +02:00
if ( $server [ 'status' ] == - 1 ) {
2020-10-21 14:03:46 +02:00
$data [ 1 ] = ui_print_status_image (
2020-10-21 17:03:46 +02:00
STATUS_SERVER_CRASH ,
__ ( 'Server has crashed.' ),
2020-10-21 14:03:46 +02:00
true
);
2022-04-28 10:07:44 +02:00
} else if (( int ) ( $server [ 'status' ] === 0 )
2023-01-20 13:11:49 +01:00
|| (( $date - $server_keepalive ) > ( $server [ 'server_keepalive' ]) * 2 )
2020-10-21 17:03:46 +02:00
) {
2020-10-21 14:03:46 +02:00
$data [ 1 ] = ui_print_status_image (
2020-10-21 17:03:46 +02:00
STATUS_SERVER_DOWN ,
__ ( 'Server is stopped.' ),
2020-10-21 14:03:46 +02:00
true
);
2019-01-30 16:18:44 +01:00
}
2022-04-28 10:07:44 +02:00
// Type.
2021-03-11 15:40:23 +01:00
$data [ 2 ] = '<span class="nowrap">' . $server [ 'img' ];
2021-01-29 14:02:35 +01:00
if ( $server [ 'master' ] == $master ) {
2019-01-30 16:18:44 +01:00
$data [ 2 ] .= ui_print_help_tip ( __ ( 'This is a master server' ), true );
}
2022-04-28 10:07:44 +02:00
if (( int ) $server [ 'exec_proxy' ] === 1 ) {
2020-01-14 15:43:17 +01:00
$data [ 2 ] .= html_print_image ( 'images/star.png' , true , [ 'title' => __ ( 'Exec server enabled' )]);
}
2019-01-30 16:18:44 +01:00
switch ( $server [ 'type' ]) {
case 'snmp' :
case 'event' :
case 'autoprovision' :
case 'migration' :
$data [ 3 ] = $server [ 'version' ];
$data [ 4 ] = __ ( 'N/A' );
$data [ 5 ] = __ ( 'N/A' );
break ;
case 'export' :
$data [ 3 ] = $server [ 'version' ];
$data [ 4 ] = $server [ 'modules' ] . ' ' . __ ( 'of' ) . ' ' . $server [ 'modules_total' ];
$data [ 5 ] = __ ( 'N/A' );
break ;
default :
$data [ 3 ] = $server [ 'version' ];
$data [ 4 ] = $server [ 'modules' ] . ' ' . __ ( 'of' ) . ' ' . $server [ 'modules_total' ];
2021-03-11 15:40:23 +01:00
$data [ 5 ] = '<span class="nowrap">' . $server [ 'lag_txt' ] . '</span>' ;
2019-01-30 16:18:44 +01:00
break ;
}
2023-05-22 11:39:59 +02:00
$data [ 6 ] = '' ;
2023-04-21 14:36:32 +02:00
if ( $server [ 'queued_modules' ] > 500 ) {
2023-05-22 11:39:59 +02:00
$data [ 6 ] .= '<div class="inline"><a onclick="show_dialog();" >' . html_print_image (
2023-04-21 14:36:32 +02:00
'images/info-warning.svg' ,
true ,
[
'width' => 16 ,
'heght' => 16 ,
'class' => 'pulsate clickable' ,
2023-05-22 11:39:59 +02:00
'style' => 'margin-left: -25px;' ,
2023-04-21 14:36:32 +02:00
]
2023-05-22 11:39:59 +02:00
) . '</a></div> ' ;
2019-01-30 16:18:44 +01:00
}
2023-05-22 11:39:59 +02:00
$data [ 6 ] .= $server [ 'threads' ] . ' : ' . $server [ 'queued_modules' ];
2019-01-30 16:18:44 +01:00
$data [ 7 ] = ui_print_timestamp ( $server [ 'keepalive' ], true );
2023-06-29 16:09:25 +02:00
if ( $server [ 'type' ] === 'data' ) {
$ext = '_server' ;
2019-01-30 16:18:44 +01:00
}
$safe_server_name = servers_get_name ( $server [ 'id_server' ]);
2023-06-29 16:09:25 +02:00
if (( $ext === '_server' || $server [ 'type' ] == 'enterprise satellite' )) {
2019-01-30 16:18:44 +01:00
if ( servers_check_remote_config ( $safe_server_name . $ext ) && enterprise_installed ()) {
$names_servers [ $safe_server_name ] = true ;
} else {
$names_servers [ $safe_server_name ] = false ;
}
}
2022-04-28 10:07:44 +02:00
// Only Pandora Administrator can delete servers.
if (( bool ) check_acl ( $config [ 'id_user' ], 0 , 'PM' ) === true ) {
2019-01-30 16:18:44 +01:00
$data [ 8 ] = '' ;
2022-04-28 10:07:44 +02:00
if ( $server [ 'type' ] === 'recon' ) {
2019-06-27 16:38:00 +02:00
$data [ 8 ] .= '<a href="' . ui_get_full_url ( 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist' ) . '">' ;
2019-01-30 16:18:44 +01:00
$data [ 8 ] .= html_print_image (
2023-02-22 12:15:17 +01:00
'images/snmp-trap@svg.svg' ,
2019-01-30 16:18:44 +01:00
true ,
[
2019-06-27 16:38:00 +02:00
'title' => __ ( 'Manage Discovery tasks' ),
2023-02-22 12:15:17 +01:00
'class' => 'main_menu_icon invert_filter' ,
2021-03-11 15:40:23 +01:00
2019-01-30 16:18:44 +01:00
]
);
2019-04-02 13:42:30 +02:00
$data [ 8 ] .= '</a>' ;
2019-01-30 16:18:44 +01:00
}
2022-04-28 10:07:44 +02:00
if ( $server [ 'type' ] === 'data' ) {
2019-06-27 16:38:00 +02:00
$data [ 8 ] .= '<a href="' . ui_get_full_url ( 'index.php?sec=gservers&sec2=godmode/servers/modificar_server&refr=0&server_reset_counts=' . $server [ 'id_server' ]) . '">' ;
2019-01-30 16:18:44 +01:00
$data [ 8 ] .= html_print_image (
2023-03-30 08:59:40 +02:00
'images/force@svg.svg' ,
2019-01-30 16:18:44 +01:00
true ,
2021-03-11 15:40:23 +01:00
[
'title' => __ ( 'Reset module status and fired alert counts' ),
2023-02-22 12:15:17 +01:00
'class' => 'main_menu_icon invert_filter' ,
2021-03-11 15:40:23 +01:00
]
2019-01-30 16:18:44 +01:00
);
2019-04-02 13:42:30 +02:00
$data [ 8 ] .= '</a>' ;
2022-04-28 10:07:44 +02:00
} else if ( $server [ 'type' ] === 'enterprise snmp' ) {
2019-06-27 16:38:00 +02:00
$data [ 8 ] .= '<a href="' . ui_get_full_url ( 'index.php?sec=gservers&sec2=godmode/servers/modificar_server&refr=0&server_reset_snmp_enterprise=' . $server [ 'id_server' ]) . '">' ;
2019-01-30 16:18:44 +01:00
$data [ 8 ] .= html_print_image (
2023-03-30 08:59:40 +02:00
'images/force@svg.svg' ,
2019-01-30 16:18:44 +01:00
true ,
2021-03-11 15:40:23 +01:00
[
'title' => __ ( 'Claim back SNMP modules' ),
2023-02-22 12:15:17 +01:00
'class' => 'main_menu_icon invert_filter' ,
2021-03-11 15:40:23 +01:00
]
2019-01-30 16:18:44 +01:00
);
2019-04-02 13:42:30 +02:00
$data [ 8 ] .= '</a>' ;
2019-01-30 16:18:44 +01:00
}
2023-08-01 14:37:16 +02:00
if ( $server [ 'type' ] === 'event' && ( bool ) check_acl ( $config [ 'id_user' ], 0 , 'LM' ) === true ) {
2023-07-21 11:50:53 +02:00
$data [ 8 ] .= '<a class="open-alerts-list-modal" href="">' ;
$data [ 8 ] .= html_print_image (
'images/alert@svg.svg' ,
true ,
[
'title' => __ ( 'Pending alerts list' ),
'class' => 'main_menu_icon invert_filter' ,
]
);
$data [ 8 ] .= '</a>' ;
}
2019-06-27 16:38:00 +02:00
$data [ 8 ] .= '<a href="' . ui_get_full_url ( 'index.php?sec=gservers&sec2=godmode/servers/modificar_server&server=' . $server [ 'id_server' ]) . '">' ;
2019-01-30 16:18:44 +01:00
$data [ 8 ] .= html_print_image (
2023-02-22 12:15:17 +01:00
'images/edit.svg' ,
2019-01-30 16:18:44 +01:00
true ,
2021-03-11 15:40:23 +01:00
[
'title' => __ ( 'Edit' ),
2023-02-22 12:15:17 +01:00
'class' => 'main_menu_icon invert_filter' ,
2021-03-11 15:40:23 +01:00
]
2019-01-30 16:18:44 +01:00
);
$data [ 8 ] .= '</a>' ;
2023-06-29 16:13:47 +02:00
if (( $names_servers [ $safe_server_name ] === true ) && ( $ext === '_server' || $server [ 'type' ] === 'enterprise satellite' )) {
2022-09-19 12:17:24 +02:00
$data [ 8 ] .= '<a href="' . ui_get_full_url ( 'index.php?sec=gservers&sec2=godmode/servers/modificar_server&server_remote=' . $server [ 'id_server' ] . '&ext=' . $ext . '&tab=agent_editor' ) . '">' ;
$data [ 8 ] .= html_print_image (
2023-02-22 12:15:17 +01:00
'images/agents@svg.svg' ,
2022-09-19 12:17:24 +02:00
true ,
[
2023-05-30 16:31:39 +02:00
'title' => __ ( 'Manage server conf' ),
2023-02-22 12:15:17 +01:00
'class' => 'main_menu_icon invert_filter' ,
2022-09-19 12:17:24 +02:00
]
);
$data [ 8 ] .= '</a>' ;
2019-06-27 16:38:00 +02:00
$data [ 8 ] .= '<a href="' . ui_get_full_url ( 'index.php?sec=gservers&sec2=godmode/servers/modificar_server&server_remote=' . $server [ 'id_server' ] . '&ext=' . $ext ) . '">' ;
2019-01-30 16:18:44 +01:00
$data [ 8 ] .= html_print_image (
2023-03-27 17:03:38 +02:00
'images/remote-configuration@svg.svg' ,
2019-01-30 16:18:44 +01:00
true ,
2021-03-11 15:40:23 +01:00
[
'title' => __ ( 'Remote configuration' ),
2023-02-22 12:15:17 +01:00
'class' => 'main_menu_icon invert_filter' ,
2021-03-11 15:40:23 +01:00
]
2019-01-30 16:18:44 +01:00
);
$data [ 8 ] .= '</a>' ;
$names_servers [ $safe_server_name ] = false ;
}
2019-06-27 16:38:00 +02:00
$data [ 8 ] .= '<a href="' . ui_get_full_url ( 'index.php?sec=gservers&sec2=godmode/servers/modificar_server&server_del=' . $server [ 'id_server' ] . '&delete=1' ) . '">' ;
2019-01-30 16:18:44 +01:00
$data [ 8 ] .= html_print_image (
2023-02-22 12:15:17 +01:00
'images/delete.svg' ,
2019-01-30 16:18:44 +01:00
true ,
[
'title' => __ ( 'Delete' ),
'onclick' => " if (! confirm (' " . __ ( 'Modules run by this server will stop working. Do you want to continue?' ) . " ')) return false " ,
2023-02-22 12:15:17 +01:00
'class' => 'main_menu_icon invert_filter' ,
2019-01-30 16:18:44 +01:00
]
);
$data [ 8 ] .= '</a>' ;
}
if ( $tiny ) {
unset ( $data [ 4 ]);
unset ( $data [ 6 ]);
unset ( $data [ 7 ]);
unset ( $data [ 8 ]);
}
2023-06-29 16:09:25 +02:00
$ext = '' ;
2019-01-30 16:18:44 +01:00
array_push ( $table -> data , $data );
2013-04-10 09:57:54 +02:00
}
2013-08-21 14:37:37 +02:00
if ( $tiny ) {
2019-01-30 16:18:44 +01:00
unset ( $table -> head [ 4 ]);
unset ( $table -> head [ 6 ]);
unset ( $table -> head [ 7 ]);
unset ( $table -> head [ 8 ]);
2013-04-10 09:57:54 +02:00
}
2019-01-30 16:18:44 +01:00
2015-04-13 15:05:41 +02:00
if ( $tiny ) {
2019-05-29 17:49:09 +02:00
ui_toggle (
html_print_table ( $table , true ),
__ ( 'Tactical server information' ),
2019-06-04 13:57:55 +02:00
'' ,
'' ,
2019-05-29 17:49:09 +02:00
$hidden_toggle
);
2019-01-30 16:18:44 +01:00
} else {
html_print_table ( $table );
2015-04-13 15:05:41 +02:00
}
2023-04-21 14:36:32 +02:00
?>
< script type = " text/javascript " >
function show_dialog () {
confirmDialog ({
title : " <?php echo __('Excesive Queued.'); ?> " ,
message : " <?php echo __('You have too many items in the processing queue. This can happen if your server is overloaded and/or improperly configured. This could be something temporary, or a bottleneck. If it is associated with a delay in monitoring, with modules going to unknown, try increasing the number of threads.'); ?> " ,
strOKButton : " <?php echo __('Close'); ?> " ,
hideCancelButton : true ,
size : 675 ,
});
}
function runIt () {
$ ( '.pulsate' ) . animate ({
opacity : '1'
}, 1000 );
$ ( '.pulsate' ) . animate ({
opacity : '0.6'
}, 1000 , runIt );
}
runIt ();
</ script >