diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index f1ec05c..9e44815 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -38,12 +38,12 @@ jobs: strategy: fail-fast: false matrix: - php: ['8.1', '8.2', '8.3'] + php: ['8.1', '8.2', '8.3', '8.4'] os: [ubuntu-latest] services: - mysql: - image: mysql:8.0 + mariadb: + image: mariadb:10.6 env: MYSQL_ROOT_PASSWORD: cactiroot MYSQL_DATABASE: cacti @@ -66,7 +66,7 @@ jobs: repository: Cacti/cacti path: cacti - - name: Checkout Intropage Plugin + - name: Checkout intropage Plugin uses: actions/checkout@v4 with: path: cacti/plugins/intropage @@ -81,7 +81,6 @@ jobs: - name: Check PHP version run: php -v - - name: Run apt-get update run: sudo apt-get update @@ -141,7 +140,6 @@ jobs: sed -r "s/'cactiuser'/'cactiuser'/g" > ${{ github.workspace }}/cacti/include/config.php sudo chmod 664 ${{ github.workspace }}/cacti/include/config.php - - name: Configure Apache run: | cat << 'EOF' | sed 's#GITHUB_WORKSPACE#${{ github.workspace }}#g' > /tmp/cacti.conf @@ -167,11 +165,10 @@ jobs: cd ${{ github.workspace }}/cacti sudo php cli/install_cacti.php --accept-eula --install --force - - name: Install Intropage Plugin + - name: Install intropage Plugin run: | cd ${{ github.workspace }}/cacti sudo php cli/plugin_manage.php --plugin=intropage --install --enable - - name: Check PHP Syntax for Plugin run: | @@ -180,13 +177,37 @@ jobs: echo "Syntax errors found!" exit 1 fi + + - name: Remove the plugins directory exclusion from the .phpstan.neon + run: sed '/plugins/d' -i .phpstan.neon + working-directory: ${{ github.workspace }}/cacti + + - name: Mark composer scripts executable + run: sudo chmod +x ${{ github.workspace }}/cacti/include/vendor/bin/* + + - name: Run Linter on base code + run: composer run-script lint ${{ github.workspace }}/cacti/plugins/intropage + working-directory: ${{ github.workspace }}/cacti + + - name: Checking coding standards on base code + run: composer run-script phpcsfixer ${{ github.workspace }}/cacti/plugins/intropage + working-directory: ${{ github.workspace }}/cacti + +# - name: Run PHPStan at Level 6 on base code outside of Composer due to technical issues +# run: ./include/vendor/bin/phpstan analyze --level 6 ${{ github.workspace }}/cacti/plugins/intropage +# working-directory: ${{ github.workspace }}/cacti - - name: Run intropage poller + - name: Run Cacti Poller run: | cd ${{ github.workspace }}/cacti + sudo php poller.php --poller=1 --force --debug + if ! grep -q "SYSTEM STATS" log/cacti.log; then + echo "Cacti poller did not finish successfully" + cat log/cacti.log + exit 1 + fi sudo php plugins/intropage/poller_intropage.php - - + - name: View Cacti Logs if: always() run: | @@ -194,5 +215,3 @@ jobs: echo "=== Cacti Log ===" sudo cat ${{ github.workspace }}/cacti/log/cacti.log fi - - diff --git a/display.php b/display.php index 327560d..8bb7bc2 100644 --- a/display.php +++ b/display.php @@ -52,7 +52,7 @@ function display_information() { db_execute_prepared('INSERT INTO plugin_intropage_user_auth (user_id) VALUES (?)', - array($_SESSION['sess_user_id'])); + [$_SESSION['sess_user_id']]); $user_panels = 0; } @@ -82,19 +82,19 @@ function display_information() { $number_of_dashboards = db_fetch_cell_prepared('SELECT COUNT(*) FROM plugin_intropage_dashboard WHERE user_id = ?', - array($_SESSION['sess_user_id'])); + [$_SESSION['sess_user_id']]); // console access $console_access = api_plugin_user_realm_auth('index.php'); // remove admin prohibited panels - $panels = db_fetch_assoc_prepared ('SELECT pd.panel_id AS panel_name, pd.id AS id + $panels = db_fetch_assoc_prepared('SELECT pd.panel_id AS panel_name, pd.id AS id FROM plugin_intropage_panel_data AS pd INNER JOIN plugin_intropage_panel_dashboard AS pda ON pd.id = pda.panel_id WHERE pda.user_id = ? AND pda.dashboard_id = ?', - array($_SESSION['sess_user_id'], $dashboard_id)); + [$_SESSION['sess_user_id'], $dashboard_id]); if (cacti_sizeof($panels)) { $removed = 0; @@ -107,12 +107,12 @@ function display_information() { WHERE user_id = ? AND dashboard_id = ? AND panel_id = ?', - array($_SESSION['sess_user_id'], $dashboard_id, $one['id'])); + [$_SESSION['sess_user_id'], $dashboard_id, $one['id']]); db_execute_prepared('DELETE FROM plugin_intropage_panel_data WHERE user_id = ? AND panel_id = ?', - array($_SESSION['sess_user_id'], $one['id'])); + [$_SESSION['sess_user_id'], $one['id']]); $removed++; } @@ -148,12 +148,12 @@ function display_information() { AND t3.panel_id = 'favourite_graph' AND t3.fav_graph_id IS NOT NULL $sql_order", - array( + [ $_SESSION['sess_user_id'], $dashboard_id, $_SESSION['sess_user_id'], $dashboard_id - ) + ] ); // remove prohibited panels (for common panels (user_id=0)) @@ -162,7 +162,7 @@ function display_information() { $allowed = is_panel_allowed($value['panel_id']); if (!$allowed) { - unset ($panels[$key]); + unset($panels[$key]); } else { // user has permission but no active panel $upanels = db_fetch_cell_prepared('SELECT COUNT(*) @@ -170,10 +170,10 @@ function display_information() { WHERE user_id = ? AND dashboard_id = ? AND panel_id = ?', - array($_SESSION['sess_user_id'], $dashboard_id, $value['id'])); + [$_SESSION['sess_user_id'], $dashboard_id, $value['id']]); if ($upanels == 0) { - unset ($panels[$key]); + unset($panels[$key]); } } } @@ -182,15 +182,15 @@ function display_information() { // Notice about disable cacti dashboard if (read_config_option('hide_console') != 'on') { print '
' . __('You can disable rows above in Configure > Settings > General > Hide Cacti Dashboard and use the whole page for Intropage ', 'intropage'); - print '

'; + print '
'; } $dashboards = array_rekey( - db_fetch_assoc_prepared ('SELECT dashboard_id, name + db_fetch_assoc_prepared('SELECT dashboard_id, name FROM plugin_intropage_dashboard WHERE user_id = ? ORDER BY dashboard_id', - array($_SESSION['sess_user_id'])), + [$_SESSION['sess_user_id']]), 'dashboard_id', 'name' ); @@ -203,18 +203,18 @@ function display_information() { db_execute_prepared('INSERT INTO plugin_intropage_dashboard (user_id, dashboard_id, name) VALUES (?, ?, ?)', - array($_SESSION['sess_user_id'], $dashboard_id, $dashboards[1])); + [$_SESSION['sess_user_id'], $dashboard_id, $dashboards[1]]); } // wide or normal number of panels on line if ($display_wide == 'on') { $width_quarter = 'calc(25% - 1em)'; - $width_third = 'calc(33% - 1em)'; - $width_half = 'calc(50% - 1em)'; + $width_third = 'calc(33% - 1em)'; + $width_half = 'calc(50% - 1em)'; } else { $width_quarter = 'calc(33% - 1em)'; - $width_third = 'calc(50% - 1em)'; - $width_half = 'calc(66% - 1em)'; + $width_third = 'calc(50% - 1em)'; + $width_half = 'calc(66% - 1em)'; } // Intropage Display ---------------------------------- @@ -234,7 +234,7 @@ function display_information() { } } - print ""; + print ''; print ''; print '
'; @@ -254,7 +254,7 @@ function display_information() { print ""; + print ''; print '    '; print ""; print ''; if (cacti_sizeof($add_panels)) { - foreach ($add_panels as $panel) { $uniqid = db_fetch_cell_prepared('SELECT id FROM plugin_intropage_panel_data WHERE user_id IN (0, ?) AND panel_id = ?', - array($_SESSION['sess_user_id'],$panel['panel_id'])); + [$_SESSION['sess_user_id'], $panel['panel_id']]); // if ($panel['panel_id'] != 'maint' && $panel['panel_id'] != 'admin_alert') { if ($panel['panel_id'] != 'admin_alert') { @@ -1734,7 +1733,7 @@ function intropage_addpanel_select($dashboard_id) { print "'; } } else { - print "'; + print "'; } } else { if ($allowed) { @@ -1742,7 +1741,7 @@ function intropage_addpanel_select($dashboard_id) { print "'; } } else { - print "'; + print "'; } } } @@ -1758,12 +1757,13 @@ function ntp_time($host) { $timestamp = -1; // create a UDP socket $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); + if (!$sock) { return 'error: socket_create failed:' . socket_strerror(socket_last_error($sock)); } // set a timeout of 5 second - $timeout = array('sec' => 5, 'usec' => 0); + $timeout = ['sec' => 5, 'usec' => 0]; socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, $timeout); // clear any existing error @@ -1771,29 +1771,34 @@ function ntp_time($host) { // send an NTP request to the server $request = "\x1b" . str_repeat("\x00", 47); + if (socket_sendto($sock, $request, strlen($request), 0, $host, 123) === false) { $error = socket_strerror(socket_last_error($sock)); socket_close($sock); + return 'error: socket_sendto failed:' . $error; } // receive the NTP response from the server - $recv=''; - if ($config['cacti_server_os'] == 'win32'){ + $recv = ''; + + if ($config['cacti_server_os'] == 'win32') { if (socket_recv($sock, $recv, 48, MSG_PEEK) === false) { $error = socket_strerror(socket_last_error($sock)); socket_close($sock); + return 'error: socket_recv failed: ' . $error; } } else { if (socket_recv($sock, $recv, 48, MSG_WAITALL) === false) { $error = socket_strerror(socket_last_error($sock)); socket_close($sock); - return 'error: socket_recv failed: ' . $error ; + + return 'error: socket_recv failed: ' . $error; } } // extract the timestamp from the received data - $data = unpack('N12', $recv); + $data = unpack('N12', $recv); $timestamp = sprintf('%u', $data[9]); // close the socket @@ -1809,6 +1814,7 @@ function intropage_graph_button($data) { global $config, $callbackPage, $redirectPage; $login_opts = get_login_opts(); + if ($login_opts == 4) { $redirectPage = $config['url_path'] . 'plugins/intropage/intropage.php'; } else { @@ -1830,7 +1836,7 @@ function intropage_graph_button($data) { WHERE user_id = ? AND fav_graph_id = ? AND fav_graph_timespan = ?', - array($_SESSION['sess_user_id'], $local_graph_id, $_SESSION['sess_current_timespan'])); + [$_SESSION['sess_user_id'], $local_graph_id, $_SESSION['sess_current_timespan']]); if ($present) { $fav = ''; @@ -1857,7 +1863,7 @@ function get_login_opts($refresh = false) { $login_opts = db_fetch_cell_prepared('SELECT login_opts FROM user_auth WHERE id = ?', - array($_SESSION['sess_user_id'])); + [$_SESSION['sess_user_id']]); $_SESSION['intropage_login_opts'] = $login_opts; } @@ -1873,7 +1879,7 @@ function intropage_configure_panel() { FROM plugin_intropage_dashboard WHERE user_id = ? ORDER BY dashboard_id', - array($_SESSION['sess_user_id'])), + [$_SESSION['sess_user_id']]), 'dashboard_id', 'name' ); @@ -1885,8 +1891,8 @@ function intropage_configure_panel() { $class = 'odd'; - foreach($dashboards as $f => $name) { - $class = ($class == 'odd' ? 'even':'odd'); + foreach ($dashboards as $f => $name) { + $class = ($class == 'odd' ? 'even' : 'odd'); print '
@@ -1895,7 +1901,7 @@ function intropage_configure_panel() {
'; - print '
'; + print '
'; print '
'; } @@ -1911,7 +1917,7 @@ function intropage_configure_panel() { WHERE pda.user_id = ? AND pda.fav_graph_id IS NULL ORDER BY level, name', - array($_SESSION['sess_user_id'])); + [$_SESSION['sess_user_id']]); if (cacti_sizeof($panels)) { html_start_box(__('User Level Panel Update Frequencies', 'intropage'), '100%', '', '3', 'center', ''); @@ -1919,7 +1925,7 @@ function intropage_configure_panel() { $class = 'odd'; foreach ($panels as $panel) { - $class = ($class == 'odd' ? 'even':'odd'); + $class = ($class == 'odd' ? 'even' : 'odd'); // Don't show admin pages to normal users if ($panel['level'] == 0 && !api_user_realm_auth('intropage_admin.php')) { @@ -1968,7 +1974,7 @@ function intropage_configure_panel() { $class = 'odd'; foreach ($panels as $panel) { - $class = ($class == 'odd' ? 'even':'odd'); + $class = ($class == 'odd' ? 'even' : 'odd'); // Don't show admin pages to normal users if ($panel['level'] == 0 && !api_user_realm_auth('intropage_admin.php')) { @@ -2009,7 +2015,7 @@ function intropage_configure_panel() { AND pda.fav_graph_id IS NULL AND pd.trends_func != "" ORDER BY level, name', - array($_SESSION['sess_user_id'])); + [$_SESSION['sess_user_id']]); if (cacti_sizeof($panels)) { html_start_box(__('Trend Update Frequencies', 'intropage'), '100%', '', '3', 'center', ''); @@ -2017,7 +2023,7 @@ function intropage_configure_panel() { $class = 'odd'; foreach ($panels as $panel) { - $class = ($class == 'odd' ? 'even':'odd'); + $class = ($class == 'odd' ? 'even' : 'odd'); print '
@@ -2053,8 +2059,7 @@ function intropage_configure_panel() { print '
'; } -function human_readable ($bytes, $decimal = true, $precision = 2) { - +function human_readable($bytes, $decimal = true, $precision = 2) { if ($decimal) { $factor = 1000; } else { @@ -2063,10 +2068,12 @@ function human_readable ($bytes, $decimal = true, $precision = 2) { if ($bytes == 0) { return 0; - } elseif ($bytes < 1) { - $sizes = array(0 => '', -1 => 'm', -2 => 'µ',- 3 => 'n', -4 => 'p'); + } + + if ($bytes < 1) { + $sizes = [0 => '', -1 => 'm', -2 => 'µ', - 3 => 'n', -4 => 'p']; } else { - $sizes = array(0 => '', 1 => 'K', 2 => 'M', 3 => 'G', 4 => 'T', 5=> 'P'); + $sizes = [0 => '', 1 => 'K', 2 => 'M', 3 => 'G', 4 => 'T', 5=> 'P']; } $i = (int) floor(log(abs($bytes)) / log($factor)); @@ -2074,32 +2081,30 @@ function human_readable ($bytes, $decimal = true, $precision = 2) { if (!array_key_exists($i, $sizes)) { if (function_exists('cacti_log')) { - cacti_log('INTROPAGE WARNING: Bytes = [' . $bytes .'], Factor = [' . $factor . '], i = [' . $i . '] d = [' . $d . ']'); + cacti_log('INTROPAGE WARNING: Bytes = [' . $bytes . '], Factor = [' . $factor . '], i = [' . $i . '] d = [' . $d . ']'); cacti_debug_backtrace('intropage-hr'); } else { - print 'INTROPAGE WARNING: Bytes = [' . $bytes .'], Factor = [' . $factor . '], i = [' . $i . '] d = [' . $d . ']'; + print 'INTROPAGE WARNING: Bytes = [' . $bytes . '], Factor = [' . $factor . '], i = [' . $i . '] d = [' . $d . ']'; } $size = ''; - $i = 1; + $i = 1; } else { $size = $sizes[$i]; } - return round(empty($d)?0:($bytes / pow($factor, $i)), $precision).' '.$size; + return round(empty($d) ? 0 : ($bytes / pow($factor, $i)), $precision) . ' ' . $size; } -function get_panel_lines_count ($height, $user_id) { - +function get_panel_lines_count($height, $user_id) { $lines = read_user_setting('intropage_number_of_lines', read_config_option('intropage_number_of_lines'), false, $user_id); if (!is_numeric($lines)) { $lines = 5; - } - elseif ($height == 'double') { + } elseif ($height == 'double') { $lines *= 2; } elseif ($height == 'triple') { $lines *= 3; } return $lines; -} \ No newline at end of file +} diff --git a/include/index.php b/include/index.php index 4f8fcac..4298bd5 100644 --- a/include/index.php +++ b/include/index.php @@ -23,4 +23,3 @@ */ header('Location:../index.php'); - diff --git a/include/settings.php b/include/settings.php index e539efb..0141395 100644 --- a/include/settings.php +++ b/include/settings.php @@ -34,7 +34,7 @@ function intropage_config_settings() { $settings['intropage'] = $intropage_settings; if (function_exists('auth_augment_roles')) { - auth_augment_roles(__('Normal User'), array('intropage.php')); + auth_augment_roles(__('Normal User'), ['intropage.php']); } } @@ -69,7 +69,7 @@ function intropage_console_after() { $login_opts = get_login_opts(true); - if (api_user_realm_auth('intropage.php') && $config['poller_id'] == 1 || ($config['poller_id'] > 1 && $config['connection'] == 'online')) + if (api_user_realm_auth('intropage.php') && $config['poller_id'] == 1 || ($config['poller_id'] > 1 && $config['connection'] == 'online')) { if ($login_opts != 4) { $panels = initialize_panel_library(); @@ -78,6 +78,7 @@ function intropage_console_after() { display_information(); } } +} function intropage_user_admin_tab() { global $config; @@ -110,9 +111,7 @@ function intropage_user_group_admin_tab() { print ''; } - - -function intropage_user_admin_run_action($current_tab){ +function intropage_user_admin_run_action($current_tab) { global $config, $registry; if ($current_tab != 'intropage_settings_edit') { @@ -125,24 +124,24 @@ function intropage_user_admin_run_action($current_tab){ $panels = initialize_panel_library(); - $fields_intropage_user_edit = array(); + $fields_intropage_user_edit = []; $exists = db_fetch_cell_prepared('SELECT COUNT(*) FROM plugin_intropage_user_auth WHERE user_id = ?', - array(get_request_var('id'))); + [get_request_var('id')]); if (!$exists) { db_execute_prepared('INSERT INTO plugin_intropage_user_auth (user_id) VALUES (?)', - array(get_request_var('id'))); + [get_request_var('id')]); } $user = db_fetch_row_prepared('SELECT * FROM plugin_intropage_user_auth WHERE user_id = ?', - array(get_request_var('id'))); + [get_request_var('id')]); if (isset($user['permissions'])) { $permissions = json_decode($user['permissions'], true); @@ -159,7 +158,7 @@ function intropage_user_admin_run_action($current_tab){ SELECT "favourite_graph", 1, "graphs", "Favorite Graphs", "green", "Allow you to add your favorite graphs to the dashboard of your choice" ORDER BY level, class, name'); - $header_label = __('[edit: %s]', db_fetch_cell_prepared('SELECT username FROM user_auth WHERE id = ?', array(get_request_var('id')))); + $header_label = __('[edit: %s]', db_fetch_cell_prepared('SELECT username FROM user_auth WHERE id = ?', [get_request_var('id')])); $prev_level = -1; $prev_class = -1; @@ -177,11 +176,11 @@ function intropage_user_admin_run_action($current_tab){ $name = 'spacer_user'; } - $temp[$name . $i] = array( + $temp[$name . $i] = [ 'method' => 'spacer', 'friendly_name' => $level, 'description' => $desc, - ); + ]; } $i++; @@ -189,23 +188,23 @@ function intropage_user_admin_run_action($current_tab){ $prev_level = $field['level']; if ($prev_class != $field['class']) { - $temp[$name . $i] = array( + $temp[$name . $i] = [ 'method' => 'spacer', 'friendly_name' => $registry[$field['class']]['name'], 'description' => $registry[$field['class']]['description'], - ); + ]; } $prev_class = $field['class']; if ($field['panel_id'] != 'admin_alert' && $field['panel_id'] != 'maint') { - $temp[$field['panel_id']] = array( + $temp[$field['panel_id']] = [ 'value' => '|arg1:' . $field['panel_id'] . '|', 'method' => 'checkbox', 'friendly_name' => $field['name'], 'description' => $field['description'], 'default' => '1' - ); + ]; $fields_intropage_user_edit = $fields_intropage_user_edit + $temp; } @@ -221,10 +220,10 @@ function intropage_user_admin_run_action($current_tab){ print '
'; draw_edit_form( - array( - 'config' => array('no_form_tag' => true), - 'fields' => inject_form_variables($fields_intropage_user_edit, (isset($user) ? $user : array())) - ) + [ + 'config' => ['no_form_tag' => true], + 'fields' => inject_form_variables($fields_intropage_user_edit, (isset($user) ? $user : [])) + ] ); ?> @@ -244,7 +243,7 @@ function selectAllPerms(checked) { return false; } -function intropage_user_group_admin_run_action($current_tab){ +function intropage_user_group_admin_run_action($current_tab) { global $config, $registry; if ($current_tab != 'intropage_group_settings_edit') { @@ -257,30 +256,30 @@ function intropage_user_group_admin_run_action($current_tab){ $panels = initialize_panel_library(); - $fields_intropage_group_edit = array(); + $fields_intropage_group_edit = []; $exists = db_fetch_cell_prepared('SELECT COUNT(*) FROM plugin_intropage_user_group_auth WHERE user_group_id = ?', - array(get_request_var('id'))); + [get_request_var('id')]); if (!$exists) { db_execute_prepared('INSERT INTO plugin_intropage_user_group_auth (user_group_id) VALUES (?)', - array(get_request_var('id'))); + [get_request_var('id')]); } $group = db_fetch_row_prepared('SELECT * FROM plugin_intropage_user_group_auth WHERE user_group_id = ?', - array(get_request_var('id'))); + [get_request_var('id')]); if (isset($group['permissions'])) { $permissions = json_decode($group['permissions'], true); $permissions['user_group_id'] = $group['user_group_id']; - $permissions['login_opts'] = $group['login_opts']; + $permissions['login_opts'] = $group['login_opts']; $group = $permissions; } @@ -291,7 +290,7 @@ function intropage_user_group_admin_run_action($current_tab){ SELECT "favourite_graph", 1, "graphs", "Favorite Graphs", "green", "Allow you to add your favorite graphs to the dashboard of your choice" ORDER BY level, class, name'); - $header_label = __('[edit: %s]', db_fetch_cell_prepared('SELECT name FROM user_auth_group WHERE id = ?', array(get_request_var('id')))); + $header_label = __('[edit: %s]', db_fetch_cell_prepared('SELECT name FROM user_auth_group WHERE id = ?', [get_request_var('id')])); $prev_level = -1; $prev_class = -1; @@ -309,11 +308,11 @@ function intropage_user_group_admin_run_action($current_tab){ $name = 'spacer_user'; } - $temp[$name . $i] = array( + $temp[$name . $i] = [ 'method' => 'spacer', 'friendly_name' => $level, 'description' => $desc, - ); + ]; } $i++; @@ -321,23 +320,23 @@ function intropage_user_group_admin_run_action($current_tab){ $prev_level = $field['level']; if ($prev_class != $field['class']) { - $temp[$name . $i] = array( + $temp[$name . $i] = [ 'method' => 'spacer', 'friendly_name' => $registry[$field['class']]['name'], 'description' => $registry[$field['class']]['description'], - ); + ]; } $prev_class = $field['class']; if ($field['panel_id'] != 'admin_alert' && $field['panel_id'] != 'maint') { - $temp[$field['panel_id']] = array( + $temp[$field['panel_id']] = [ 'value' => '|arg1:' . $field['panel_id'] . '|', 'method' => 'checkbox', 'friendly_name' => $field['name'], 'description' => $field['description'], 'default' => '1' - ); + ]; $fields_intropage_group_edit = $fields_intropage_group_edit + $temp; } @@ -353,10 +352,10 @@ function intropage_user_group_admin_run_action($current_tab){ print '
'; draw_edit_form( - array( - 'config' => array('no_form_tag' => true), - 'fields' => inject_form_variables($fields_intropage_group_edit, (isset($group) ? $group : array())) - ) + [ + 'config' => ['no_form_tag' => true], + 'fields' => inject_form_variables($fields_intropage_group_edit, (isset($group) ? $group : [])) + ] ); ?> @@ -376,9 +375,7 @@ function selectAllPerms(checked) { return false; } - - -function intropage_user_admin_user_save($save){ +function intropage_user_admin_user_save($save) { global $config; if (get_nfilter_request_var('tab') == 'intropage_settings_edit') { @@ -386,7 +383,7 @@ function intropage_user_admin_user_save($save){ $user_id = get_filter_request_var('id'); - $permissions = array(); + $permissions = []; if (db_column_exists('plugin_intropage_user_auth', 'permissions')) { $permmode = true; @@ -400,10 +397,10 @@ function intropage_user_admin_user_save($save){ db_execute_prepared('UPDATE plugin_intropage_user_auth SET `' . $panel['panel_id'] . '` = ? WHERE user_id = ?', - array(get_nfilter_request_var($panel['panel_id']), $user_id)); + [get_nfilter_request_var($panel['panel_id']), $user_id]); } } else { - $permissions[$panel['panel_id']] = (isset_request_var($panel['panel_id']) ? 'on':''); + $permissions[$panel['panel_id']] = (isset_request_var($panel['panel_id']) ? 'on' : ''); } } @@ -412,19 +409,19 @@ function intropage_user_admin_user_save($save){ } if ($permmode) { - foreach($permissions as $panel_id => $data) { + foreach ($permissions as $panel_id => $data) { $exists = db_fetch_cell_prepared('SELECT id FROM plugin_intropage_panel_data WHERE panel_id = ? AND user_id in (0, ?)', - array($panel_id, $user_id)); + [$panel_id, $user_id]); if (!$exists) { $panel = db_fetch_row_prepared('SELECT * FROM plugin_intropage_panel_definition WHERE panel_id = ?', - array($panel_id)); + [$panel_id]); - $save = array(); + $save = []; $save['id'] = 0; $save['panel_id'] = $panel_id; @@ -437,9 +434,9 @@ function intropage_user_admin_user_save($save){ $save['last_update'] = '0000-00-00'; $save['data'] = ''; - $save['priority'] = (isset($panel['priority']) ? $panel['priority']:99); - $save['alarm'] = (isset($panel['alarm']) ? $panel['alarm']:'green'); - $save['refresh_interval'] = (isset($panel['refresh']) ? $panel['refresh']:300); + $save['priority'] = (isset($panel['priority']) ? $panel['priority'] : 99); + $save['alarm'] = (isset($panel['alarm']) ? $panel['alarm'] : 'green'); + $save['refresh_interval'] = (isset($panel['refresh']) ? $panel['refresh'] : 300); $id = sql_save($save, 'plugin_intropage_panel_data'); } @@ -448,7 +445,7 @@ function intropage_user_admin_user_save($save){ db_execute_prepared('UPDATE plugin_intropage_user_auth SET permissions = ? WHERE user_id = ?', - array(json_encode($permissions), $user_id)); + [json_encode($permissions), $user_id]); } raise_message(1); @@ -461,8 +458,7 @@ function intropage_user_admin_user_save($save){ return ($save); } - -function intropage_user_group_admin_save($save){ +function intropage_user_group_admin_save($save) { global $config; if (get_nfilter_request_var('tab') == 'intropage_group_settings_edit') { @@ -470,10 +466,10 @@ function intropage_user_group_admin_save($save){ $group_id = get_filter_request_var('id'); - $permissions = array(); + $permissions = []; foreach ($panels as $panel) { - $permissions[$panel['panel_id']] = (isset_request_var($panel['panel_id']) ? 'on':''); + $permissions[$panel['panel_id']] = (isset_request_var($panel['panel_id']) ? 'on' : ''); } if (isset_request_var('favourite_graph')) { @@ -483,7 +479,7 @@ function intropage_user_group_admin_save($save){ db_execute_prepared('UPDATE plugin_intropage_user_group_auth SET permissions = ? WHERE user_group_id = ?', - array(json_encode($permissions), $group_id)); + [json_encode($permissions), $group_id]); raise_message(1); @@ -495,30 +491,27 @@ function intropage_user_group_admin_save($save){ return ($save); } - -function intropage_new_user_permission ($user_id) { - - $permissions = array(); +function intropage_new_user_permission($user_id) { + $permissions = []; $exists = db_fetch_cell_prepared('SELECT COUNT(*) FROM plugin_intropage_user_auth WHERE user_id = ?', - array($user_id)); + [$user_id]); if (!$exists) { db_execute_prepared('INSERT INTO plugin_intropage_user_auth (user_id) VALUES (?)', - array($user_id)); + [$user_id]); } $user = db_fetch_row_prepared('SELECT * FROM plugin_intropage_user_auth WHERE user_id = ?', - array($user_id)); + [$user_id]); if ($user['permissions'] == '') { - $panels = db_fetch_assoc('SELECT panel_id FROM plugin_intropage_panel_definition WHERE level = 1'); foreach ($panels as $panel) { @@ -530,22 +523,18 @@ function intropage_new_user_permission ($user_id) { db_execute_prepared('UPDATE plugin_intropage_user_auth SET permissions = ? WHERE user_id = ?', - array(json_encode($permissions), $user_id)); + [json_encode($permissions), $user_id]); } } +function intropage_copy_user($user) { + intropage_new_user_permission($user['new_id']); -function intropage_copy_user($user){ - - intropage_new_user_permission ($user['new_id']); return ($user); } +function intropage_user_admin_setup_sql_save($save) { + intropage_new_user_permission($save['id']); -function intropage_user_admin_setup_sql_save($save){ - - intropage_new_user_permission ($save['id']); return ($save); } - - diff --git a/include/tab.php b/include/tab.php index 1b923e3..acc9f8b 100644 --- a/include/tab.php +++ b/include/tab.php @@ -28,11 +28,11 @@ function intropage_show_tab() { global $config; $console_access = api_plugin_user_realm_auth('index.php'); - $login_opts = db_fetch_cell_prepared('SELECT login_opts FROM user_auth WHERE id = ?', array($_SESSION['sess_user_id'])); + $login_opts = db_fetch_cell_prepared('SELECT login_opts FROM user_auth WHERE id = ?', [$_SESSION['sess_user_id']]); if ($config['poller_id'] == 1 || ($config['poller_id'] > 1 && $config['connection'] == 'online')) { if (api_user_realm_auth('intropage.php') && isset($_SESSION['sess_user_id'])) { - if (($console_access && $login_opts == 4) || !$console_access) { + if (($console_access && $login_opts == 4) || !$console_access) { $cp = false; if (basename($_SERVER['PHP_SELF']) == 'intropage.php') { diff --git a/include/variables.php b/include/variables.php index f15e11f..156947b 100644 --- a/include/variables.php +++ b/include/variables.php @@ -24,85 +24,85 @@ +-------------------------------------------------------------------------+ */ -$status_colors = array( +$status_colors = [ 'red' => __('Red Status', 'intropage'), 'yellow' => __('Yellow Status', 'intropage'), 'green' => __('Green Status', 'intropage') -); +]; -$intropage_settings = array( - 'intropage_display_header' => array( +$intropage_settings = [ + 'intropage_display_header' => [ 'friendly_name' => __('Display Settings', 'intropage'), 'method' => 'spacer', - ), - 'intropage_display_important_first' => array( + ], + 'intropage_display_important_first' => [ 'friendly_name' => __('Important things will be at the top', 'intropage'), 'description' => __('If checked Intropage displays important (errors, warnings) information first', 'intropage'), 'method' => 'checkbox', 'default' => 'off', - ), - 'intropage_display_wide' => array( + ], + 'intropage_display_wide' => [ 'friendly_name' => __('Display more panels on a line', 'intropage'), 'description' => __('For wide screen', 'intropage'), 'method' => 'checkbox', 'default' => 'off', - ), - 'intropage_unregister' => array( + ], + 'intropage_unregister' => [ 'friendly_name' => __('Automatically Uninstall Panels', 'intropage'), 'description' => __('If a Panel is installed and required plugin is removed, automatically uninstall the panel too', 'intropage'), 'method' => 'checkbox', 'default' => '', - ), - 'intropage_autorefresh' => array( + ], + 'intropage_autorefresh' => [ 'friendly_name' => __('Automatic Page Refresh', 'intropage'), 'description' => __('How often', 'intropage'), 'method' => 'drop_array', - 'array' => array( + 'array' => [ '-1' => __('Automatically by poller', 'intropage'), '0' => __('Never', 'intropage'), '60' => __('Every Minute', 'intropage'), '300' => __('Every %d Minutes', 5, 'intropage'), '3600' => __('Every Hour', 'intropage'), - ), + ], 'default' => '60', - ), - 'intropage_important_period' => array( + ], + 'intropage_important_period' => [ 'friendly_name' => __('Important period', 'intropage'), 'description' => __('From now to past. Affects row coloring, older events will not be highlighted, only displayed', 'intropage'), 'method' => 'drop_array', - 'array' => array( + 'array' => [ '-1' => __('Disabled', 'intropage'), '900' => __('15 minutes', 'intropage'), '3600' => __('1 hour', 'intropage'), '14400' => __('4 hours', 'intropage'), '86400' => __('1 day', 'intropage'), - ), + ], 'default' => '3600', - ), - 'intropage_number_of_lines' => array( + ], + 'intropage_number_of_lines' => [ 'friendly_name' => __('Number of panel lines', 'intropage'), 'description' => __('How many lines in panel', 'intropage'), 'method' => 'drop_array', - 'array' => array( + 'array' => [ '5' => __('%d lines', 5, 'intropage'), '10' => __('%d lines', 10, 'intropage'), '15' => __('%d lines', 15, 'intropage'), - ), + ], 'default' => '5', - ), - 'intropage_timespan' => array( + ], + 'intropage_timespan' => [ 'friendly_name' => __('Trend Timespan', 'intropage'), 'description' => __('For Trend charts, what should be the default timespan for those charts.', 'intropage'), 'method' => 'drop_array', 'default' => '14400', 'array' => $trend_timespans - ), - 'intropage_timeout' => array( + ], + 'intropage_timeout' => [ 'friendly_name' => __('Poller Timeout', 'intropage'), 'description' => __('The amount of time, in minutes, that the Intropage background poller can run before being interrupted and killed by Cacti.', 'intropage'), 'method' => 'drop_array', 'default' => '1800', - 'array' => array( + 'array' => [ 60 => __('%d Minute', 1, 'intropage'), 300 => __('%d Minutes', 5, 'intropage'), 600 => __('%d Minutes', 10, 'intropage'), @@ -111,247 +111,246 @@ 1800 => __('%d Minutes', 30, 'intropage'), 2400 => __('%d Minutes', 40, 'intropage'), 3600 => __('%d Hour', 1, 'intropage') - ) - ), - 'intropage_analyse_log_rows' => array( + ] + ], + 'intropage_analyse_log_rows' => [ 'friendly_name' => __('Analyze Log - number of lines', 'intropage'), 'description' => __('How many lines of log will be analysed. Lines = in panel, 2x lines = in detail. Big number may causes slow page load', 'intropage'), 'method' => 'textbox', - 'max_length' => 5, + 'max_length' => 5, 'default' => '500', - ), - 'intropage_analyse_db_interval' => array( + ], + 'intropage_analyse_db_interval' => [ 'friendly_name' => __('How often analyze DB', 'intropage'), 'description' => __('Poller runs this task. It could cause long poller run.', 'intropage'), 'method' => 'drop_array', - 'array' => array( - '0' => __('Never', 'intropage'), - '3600' => __('Every Hour', 'intropage'), - '86400' => __('Every Day', 'intropage'), - '604800' => __('Every Week', 'intropage'), + 'array' => [ + '0' => __('Never', 'intropage'), + '3600' => __('Every Hour', 'intropage'), + '86400' => __('Every Day', 'intropage'), + '604800' => __('Every Week', 'intropage'), '2592000' => __('Every Month', 'intropage') - ), + ], 'default' => '604800', - ), - 'intropage_analyse_db_level' => array( + ], + 'intropage_analyse_db_level' => [ 'friendly_name' => __('Analyze DB - Level of db check', 'intropage'), 'description' => __('Quick - No Check rows for incorrect links
Fast - check only not properly closed tables
Changed - check tables changed from last check
Medium - with rows scan
Extended - full rows and keys
Medium and extended may cause a slow page load!', 'intropage'), 'method' => 'drop_array', - 'array' => array( + 'array' => [ 'QUICK' => __('Quick', 'intropage'), 'FAST' => __('Fast', 'intropage'), 'CHANGED' => __('Changed', 'intropage'), 'MEDIUM' => __('Medium', 'intropage'), 'EXTENDED' => __('Extended', 'intropage') - ), + ], 'default' => 'CHANGED', - ), - 'intropage_ntp_server' => array( + ], + 'intropage_ntp_server' => [ 'friendly_name' => __('NTP Time Check - IP or DNS name of NTP server', 'intropage'), 'description' => __('Insert IP or DNS name of NTP server', 'intropage'), 'method' => 'textbox', - 'max_length' => 50, + 'max_length' => 50, 'default' => 'pool.ntp.org', - ), - 'intropage_ntp_interval' => array( + ], + 'intropage_ntp_interval' => [ 'friendly_name' => __('How often check NTP', 'intropage'), 'description' => __('Poller runs this task. It could cause long poller run.', 'intropage'), 'method' => 'drop_array', - 'array' => array( + 'array' => [ '900' => __('Every %d Minutes', 15, 'intropage'), '3600' => __('Every Hour', 'intropage'), '86400' => __('Every Day', 'intropage') - ), + ], 'default' => '3600', - ), - 'intropage_dns_host' => array( + ], + 'intropage_dns_host' => [ 'friendly_name' => __('DNS Check - Any DNS name', 'intropage'), 'description' => __('Insert DNS name for test', 'intropage'), 'method' => 'textbox', - 'max_length' => 50, + 'max_length' => 50, 'default' => 'dns.google', - ), - 'intropage_dns_interval' => array( + ], + 'intropage_dns_interval' => [ 'friendly_name' => __('How often check DNS', 'intropage'), 'description' => __('Poller runs this task. It could cause long poller run.', 'intropage'), 'method' => 'drop_array', - 'array' => array( + 'array' => [ '900' => __('Every %d Minutes', 15, 'intropage'), '3600' => __('Every Hour', 'intropage'), '86400' => __('Every Day', 'intropage') - ), + ], 'default' => '3600', - ), - 'intropage_admin_alert' => array( + ], + 'intropage_admin_alert' => [ 'friendly_name' => __('Admin Information Panel about Maintenance Tasks, Down Devices, ..', 'intropage'), 'description' => __('If isn\'t empty, Panel will be displayed on the top. You can use html tags (b, i, ...).', 'intropage'), 'method' => 'textarea', - 'max_length' => 1000, + 'max_length' => 1000, 'textarea_rows' => '4', 'textarea_cols' => '60', 'default' => '', - ), - 'intropage_maint_plugin_days_before' => array( + ], + 'intropage_maint_plugin_days_before' => [ 'friendly_name' => __('Upcoming Maint Schedule warning days', 'intropage'), 'description' => __('How many days before a scheduled maintenance schedule should a warning be displayed?', 'intropage'), 'method' => 'drop_array', - 'array' => array( + 'array' => [ '-1' => __('Never warn', 'intropage'), '0' => __('When maintenance starts', 'intropage'), '86400' => __('%d Day Before', 1, 'intropage'), '259200' => __('%d Days Before', 3, 'intropage'), '604800' => __('%d Days Before', 7, 'intropage') - ), + ], 'default' => '86400', - ), - 'intropage_mb' => array( + ], + 'intropage_mb' => [ 'friendly_name' => __('Network stats in', 'intropage'), 'description' => __('bytes or bits', 'intropage'), 'method' => 'drop_array', - 'array' => array( - 'B' => __('Bytes', 'intropage'), + 'array' => [ + 'B' => __('Bytes', 'intropage'), 'b' => __('Bits', 'intropage'), - ), + ], 'default' => 'b', - ), - 'intropage_display_header2' => array( + ], + 'intropage_display_header2' => [ 'friendly_name' => __('Alarm Settings', 'intropage'), 'method' => 'spacer', - ), - 'intropage_alert_db_abort' => array( + ], + 'intropage_alert_db_abort' => [ 'friendly_name' => __('Alarm DB check Aborted Clients', 'intropage'), 'description' => __('If this event has occurred, trigger the selected Normal, Warning, or Alert status color.', 'intropage'), 'method' => 'drop_array', 'array' => $status_colors, 'default' => 'yellow', - ), - 'intropage_alert_same_description' => array( + ], + 'intropage_alert_same_description' => [ 'friendly_name' => __('Alarm Host with the same Description', 'intropage'), 'description' => __('If this event has occurred, trigger the selected Normal, Warning, or Alert status color.', 'intropage'), 'method' => 'drop_array', 'array' => $status_colors, 'default' => 'yellow', - ), - 'intropage_alert_orphaned_ds' => array( + ], + 'intropage_alert_orphaned_ds' => [ 'friendly_name' => __('Alarm Orphaned Data Source', 'intropage'), 'description' => __('If this event has occurred, trigger the selected Normal, Warning, or Alert status color.', 'intropage'), 'method' => 'drop_array', 'array' => $status_colors, 'default' => 'yellow', - ), - 'intropage_alert_poller_output' => array( + ], + 'intropage_alert_poller_output' => [ 'friendly_name' => __('Alarm non-empty Poller Output', 'intropage'), 'description' => __('If this event has occurred, trigger the selected Normal, Warning, or Alert status color.', 'intropage'), 'method' => 'drop_array', 'array' => $status_colors, 'default' => 'red', - ), - 'intropage_alert_bad_indexes' => array( + ], + 'intropage_alert_bad_indexes' => [ 'friendly_name' => __('Alarm Bad indexes Data Source', 'intropage'), 'description' => __('If this event has occurred, trigger the selected Normal, Warning, or Alert status color.', 'intropage'), 'method' => 'drop_array', 'array' => $status_colors, 'default' => 'red', - ), - 'intropage_alert_thold_logonly' => array( + ], + 'intropage_alert_thold_logonly' => [ 'friendly_name' => __('Alarm Threshold logonly action', 'intropage'), 'description' => __('If this event has occurred, trigger the selected Normal, Warning, or Alert status color.', 'intropage'), 'method' => 'drop_array', 'array' => $status_colors, 'default' => 'red', - ), - 'intropage_bulk_walk_size' => array( + ], + 'intropage_bulk_walk_size' => [ 'friendly_name' => __('Alarm when device bulk_walk_size is not optimized', 'intropage'), 'description' => __('If this event has occurred, trigger the selected Normal, Warning, or Alert status color.', 'intropage'), 'method' => 'drop_array', 'array' => $status_colors, 'default' => 'red', - ), - 'intropage_alert_same_ip' => array( + ], + 'intropage_alert_same_ip' => [ 'friendly_name' => __('Alarm Devices with the same IP/port', 'intropage'), 'description' => __('If this event has occurred, trigger the selected Normal, Warning, or Alert status color.', 'intropage'), 'method' => 'drop_array', 'array' => $status_colors, 'default' => 'yellow', - ), - 'intropage_alert_more_trees' => array( + ], + 'intropage_alert_more_trees' => [ 'friendly_name' => __('Alarm Device in more than one Tree', 'intropage'), 'description' => __('If this event has occurred, trigger the selected Normal, Warning, or Alert status color.', 'intropage'), 'method' => 'drop_array', 'array' => $status_colors, 'default' => 'yellow', - ), - 'intropage_alert_without_tree' => array( + ], + 'intropage_alert_without_tree' => [ 'friendly_name' => __('Alarm Device without a Tree', 'intropage'), 'description' => __('If this event has occurred, trigger the selected Normal, Warning, or Alert status color.', 'intropage'), 'method' => 'drop_array', 'array' => $status_colors, 'default' => 'yellow', - ), - 'intropage_alert_default_community' => array( + ], + 'intropage_alert_default_community' => [ 'friendly_name' => __('Alarm Device with Default public/private SNMP Community', 'intropage'), 'description' => __('If this event has occurred, trigger the selected Normal, Warning, or Alert status color.', 'intropage'), 'method' => 'drop_array', 'array' => $status_colors, 'default' => 'yellow', - ), - 'intropage_alert_without_monitoring' => array( + ], + 'intropage_alert_without_monitoring' => [ 'friendly_name' => __('Alarm Device without Monitoring', 'intropage'), 'description' => __('If this event has occurred, trigger the selected Normal, Warning, or Alert status color.', 'intropage'), 'method' => 'drop_array', 'array' => $status_colors, 'default' => 'yellow', - ), - 'intropage_alert_without_graph' => array( + ], + 'intropage_alert_without_graph' => [ 'friendly_name' => __('Alarm Device without Graph', 'intropage'), 'description' => __('If this event has occurred, trigger the selected Normal, Warning, or Alert status color.', 'intropage'), 'method' => 'drop_array', 'array' => $status_colors, 'default' => 'yellow', - ), - 'intropage_alert_worst_polling_time' => array( + ], + 'intropage_alert_worst_polling_time' => [ 'friendly_name' => __('Alarm Red/Yellow Polling Time', 'intropage'), 'description' => __('Polling times above these thresholds will trigger a Warning or Alert status color.', 'intropage'), 'method' => 'drop_array', 'default' => '20/10', - 'array' => array( + 'array' => [ '10/5' => __('5s / 10s Yellow / Red', 'intropage'), '20/10' => __('10s / 20s Yellow / Red', 'intropage'), '40/20' => __('20s / 40s Yellow / Red', 'intropage') - ), - ), - 'intropage_alert_worst_polling_ratio' => array( + ], + ], + 'intropage_alert_worst_polling_ratio' => [ 'friendly_name' => __('Alarm Red/Yellow Failed/All Ratio', 'intropage'), 'description' => __('The ratio of failed availability checks to successful checks to trigger as Warning or Alert status color.', 'intropage'), 'method' => 'drop_array', 'default' => '0.4/0.2', - 'array' => array( + 'array' => [ '0.2/0.1' => __('0.1 / 0.2 Yellow / Red', 'intropage'), '0.4/0.2' => __('0.2 / 0.4 Yellow / Red', 'intropage'), '0.5/more' => __('0.5 / 0.5++ Yellow / Red', 'intropage') - ), - ), - 'intropage_alert_worst_ping' => array( + ], + ], + 'intropage_alert_worst_ping' => [ 'friendly_name' => __('Alarm Red/Yellow Ping', 'intropage'), 'description' => __('Ping latency above these levels will trigger a Warning or Alert status color.', 'intropage'), 'method' => 'drop_array', 'default' => '20/10', - 'array' => array( + 'array' => [ '20/10' => __('10ms / 20ms Yellow / Red', 'intropage'), '50/20' => __('20ms / 50ms Yellow / Red', 'intropage'), '200/100' => __('100ms / 200+ms Yellow / Red', 'intropage') - ), - ), - 'intropage_alert_worst_availability' => array( + ], + ], + 'intropage_alert_worst_availability' => [ 'friendly_name' => __('Alarm Red/Yellow Worst Availability', 'intropage'), 'description' => __('Availability below these levels will trigger either a Yellow or a Red status color.', 'intropage'), 'method' => 'drop_array', 'default' => '99/95', - 'array' => array( - '99/95' => '99 / 95% ' . __('Yellow / Red', 'intropage'), - '95/85' => '95 / 85% ' . __('Yellow / Red', 'intropage'), + 'array' => [ + '99/95' => '99 / 95% ' . __('Yellow / Red', 'intropage'), + '95/85' => '95 / 85% ' . __('Yellow / Red', 'intropage'), '85/0' => '85 / 84-0% ' . __('Yellow / Red', 'intropage') - ), - ), -); - + ], + ], +]; diff --git a/index.php b/index.php index 4f8fcac..4298bd5 100644 --- a/index.php +++ b/index.php @@ -23,4 +23,3 @@ */ header('Location:../index.php'); - diff --git a/intropage.php b/intropage.php index ada281d..8d3cb42 100644 --- a/intropage.php +++ b/intropage.php @@ -35,6 +35,7 @@ $login_opts = get_login_opts(true); $callbackPage = $config['url_path'] . 'plugins/intropage/intropage.php'; + if ($login_opts == 4) { $redirectPage = $config['url_path'] . 'plugins/intropage/intropage.php'; } else { diff --git a/locales/LC_MESSAGES/index.php b/locales/LC_MESSAGES/index.php index 4f8fcac..4298bd5 100644 --- a/locales/LC_MESSAGES/index.php +++ b/locales/LC_MESSAGES/index.php @@ -23,4 +23,3 @@ */ header('Location:../index.php'); - diff --git a/locales/index.php b/locales/index.php index 4f8fcac..4298bd5 100644 --- a/locales/index.php +++ b/locales/index.php @@ -23,4 +23,3 @@ */ header('Location:../index.php'); - diff --git a/locales/po/index.php b/locales/po/index.php index 4f8fcac..4298bd5 100644 --- a/locales/po/index.php +++ b/locales/po/index.php @@ -23,4 +23,3 @@ */ header('Location:../index.php'); - diff --git a/panellib/alert.php b/panellib/alert.php index 4f31242..5225019 100644 --- a/panellib/alert.php +++ b/panellib/alert.php @@ -27,13 +27,13 @@ function register_alert() { global $registry; - $registry['alert'] = array( + $registry['alert'] = [ 'name' => __('Alerts', 'intropage'), 'description' => __('Panels that provide alerting.', 'intropage') - ); + ]; - $panels = array( - 'alert_host' => array( + $panels = [ + 'alert_host' => [ 'name' => __('Host alerts', 'intropage'), 'description' => __('Host alerts (up/down/recovering) recently', 'intropage'), 'class' => 'alert', @@ -50,19 +50,20 @@ function register_alert() { 'update_func' => 'alert_host', 'details_func' => 'alert_host_detail', 'trends_func' => false - ), - ); + ], + ]; return $panels; } -//------------------------------------ alert host ----------------------------------------------------- +// ------------------------------------ alert host ----------------------------------------------------- function alert_host($panel, $user_id) { global $config; $lines = get_panel_lines_count($panel['height'], $user_id); $important_period = read_user_setting('intropage_important_period', read_config_option('intropage_important_period'), false, $user_id); + if ($important_period == -1) { $important_period = time(); } @@ -73,10 +74,10 @@ function alert_host($panel, $user_id) { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'AND host.id IN (' . $allowed_devices . ')'; + $host_cond = 'AND host.id IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $host_cond = ''; + $host_cond = ''; } if ($allowed_devices !== false || $simple_perms) { @@ -103,23 +104,23 @@ function alert_host($panel, $user_id) { FROM host WHERE disabled != 'on' $host_cond - AND status = 3 AND status_fail_date > DATE_SUB(now(), INTERVAL " . $important_period . " SECOND) + AND status = 3 AND status_fail_date > DATE_SUB(now(), INTERVAL " . $important_period . ' SECOND) ORDER BY status_fail_date DESC - LIMIT " . $lines); + LIMIT ' . $lines); $sql_host_down = db_fetch_assoc("SELECT id, description, status_fail_date as chdate, UNIX_TIMESTAMP(status_fail_date) AS secs, 'Down' AS state FROM host WHERE disabled != 'on' $host_cond - AND status = 1 AND status_fail_date > DATE_SUB(now(), INTERVAL " . $important_period . " SECOND) + AND status = 1 AND status_fail_date > DATE_SUB(now(), INTERVAL " . $important_period . ' SECOND) ORDER BY status_fail_date DESC - LIMIT " . $lines); + LIMIT ' . $lines); $result = $sql_host_reco + $sql_host_up + $sql_host_fall + $sql_host_down; - + $panel['data'] = '' . '' . - '' . + '' . '' . '' . ''; @@ -127,27 +128,26 @@ function alert_host($panel, $user_id) { $i = 0; if (cacti_sizeof($result)) { - foreach ($result as $line) { if ($console_access) { - $row = ''; + $row = ''; } else { - $row = ''; + $row = ''; } $row .= ''; @@ -170,15 +169,16 @@ function alert_host($panel, $user_id) { $row .= html_escape(substr($line['description'],0,37)) . ''; } - $row .= ''; + $row .= ''; $panel['data'] .= $row; $i++; - + if ($i > $lines) { $panel['data'] .= '
' . __('Date', 'intropage') . '' . __('Date', 'intropage') . '' . __('Host', 'intropage') . '' . __('State', 'intropage') . '
' . $line['chdate'] . ''; - $color = 'grey'; + $color = 'grey'; - if ($line['secs'] > (time()-($important_period))) { - if (preg_match('/(UP)/i', $line['state'])) { - $color = 'green'; - } elseif (preg_match('/(DOWN)/i', $line['state'])) { - $color = 'red'; - } elseif (preg_match('/(RECOVERING|FALLING)/i', $line['state'])) { - $color = 'yellow'; - } - } + if ($line['secs'] > (time() - ($important_period))) { + if (preg_match('/(UP)/i', $line['state'])) { + $color = 'green'; + } elseif (preg_match('/(DOWN)/i', $line['state'])) { + $color = 'red'; + } elseif (preg_match('/(RECOVERING|FALLING)/i', $line['state'])) { + $color = 'yellow'; + } + } if ($panel['alarm'] == 'grey' && $color == 'green') { $panel['alarm'] = 'green'; @@ -161,8 +161,7 @@ function alert_host($panel, $user_id) { $panel['alarm'] = 'red'; } - $row .= ''; - + $row .= ''; if ($console_access) { $row .= '' . html_escape(substr($line['description'],0,37)) . '' . $line['state'] . '
' . $line['state'] . '
'; - $panel['data'] .= '
' . __('More records, use detail window', 'intropage'); + $panel['data'] .= '
' . __('More records, use detail window', 'intropage'); + break; } } @@ -194,21 +194,21 @@ function alert_host($panel, $user_id) { save_panel_result($panel, $user_id); } - -//------------------------------------ alert host detail ----------------------------------------------------- +// ------------------------------------ alert host detail ----------------------------------------------------- function alert_host_detail() { global $config, $console_access; - $important_period = read_user_setting('intropage_important_period', read_config_option('intropage_important_period'), false, $_SESSION['sess_user_id']); - if ($important_period == -1) { - $important_period = time(); - } + $important_period = read_user_setting('intropage_important_period', read_config_option('intropage_important_period'), false, $_SESSION['sess_user_id']); + + if ($important_period == -1) { + $important_period = time(); + } - $panel = array( + $panel = [ 'name' => __('Host alerts', 'intropage'), 'alarm' => 'green', 'detail' => '', - ); + ]; $lines = 20; @@ -216,80 +216,79 @@ function alert_host_detail() { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'AND host.id IN (' . $allowed_devices . ')'; + $host_cond = 'AND host.id IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $host_cond = ''; + $host_cond = ''; } if ($allowed_devices !== false || $simple_perms) { - $console_access = get_console_access($_SESSION['sess_user_id']); $sql_host_reco = db_fetch_assoc("SELECT id, description, status_rec_date as chdate, UNIX_TIMESTAMP(status_rec_date) AS secs, 'Recovering' AS state FROM host WHERE disabled != 'on' $host_cond - AND status_event_count > 0 AND status = 2 AND status_rec_date > DATE_SUB(now(), INTERVAL " . $important_period . " SECOND) + AND status_event_count > 0 AND status = 2 AND status_rec_date > DATE_SUB(now(), INTERVAL " . $important_period . ' SECOND) ORDER BY status_rec_date DESC - LIMIT " . $lines); + LIMIT ' . $lines); $sql_host_up = db_fetch_assoc("SELECT id, description, status_rec_date as chdate, UNIX_TIMESTAMP(status_rec_date) AS secs, 'Up' AS state FROM host WHERE disabled != 'on' $host_cond - AND status_event_count = 0 AND status = 3 AND status_rec_date > DATE_SUB(now(), INTERVAL " . $important_period . " SECOND) + AND status_event_count = 0 AND status = 3 AND status_rec_date > DATE_SUB(now(), INTERVAL " . $important_period . ' SECOND) ORDER BY status_rec_date DESC - LIMIT " . $lines); + LIMIT ' . $lines); $sql_host_fall = db_fetch_assoc("SELECT id, description, status_fail_date as chdate, UNIX_TIMESTAMP(status_fail_date) AS secs, 'Falling' AS state FROM host WHERE disabled != 'on' $host_cond - AND status = 3 AND status_fail_date > DATE_SUB(now(), INTERVAL " . $important_period . " SECOND) + AND status = 3 AND status_fail_date > DATE_SUB(now(), INTERVAL " . $important_period . ' SECOND) ORDER BY status_fail_date DESC - LIMIT " . $lines); + LIMIT ' . $lines); $sql_host_down = db_fetch_assoc("SELECT id, description, status_fail_date as chdate, UNIX_TIMESTAMP(status_fail_date) AS secs, 'Down' AS state FROM host WHERE disabled != 'on' $host_cond - AND status = 1 AND status_fail_date > DATE_SUB(now(), INTERVAL " . $important_period . " SECOND) + AND status = 1 AND status_fail_date > DATE_SUB(now(), INTERVAL " . $important_period . ' SECOND) ORDER BY status_fail_date DESC - LIMIT " . $lines); + LIMIT ' . $lines); $result = $sql_host_reco + $sql_host_up + $sql_host_fall + $sql_host_down; - - if (cacti_sizeof($result)) { + if (cacti_sizeof($result)) { $panel['detail'] = '' . '' . - '' . + '' . '' . '' . ''; $i = 0; + foreach ($result as $line) { if ($console_access) { - $row = ''; + $row = ''; } else { - $row = ''; + $row = ''; } $row .= ''; @@ -311,15 +310,16 @@ function alert_host_detail() { $row .= html_escape(substr($line['description'],0,37)) . ''; } - $row .= ''; + $row .= ''; $panel['detail'] .= $row; $i++; - + if ($i > $lines) { $panel['detail'] .= '
' . __('Date', 'intropage') . '' . __('Date', 'intropage') . '' . __('Host', 'intropage') . '' . __('State', 'intropage') . '
' . $line['chdate'] . ''; - $color = 'grey'; + $color = 'grey'; - if ($line['secs'] > (time()-($important_period))) { - if (preg_match('/(UP)/i', $line['state'])) { - $color = 'green'; - } elseif (preg_match('/(DOWN)/i', $line['state'])) { - $color = 'red'; - } elseif (preg_match('/(RECOVERING|FALLING)/i', $line['state'])) { - $color = 'yellow'; - } - } + if ($line['secs'] > (time() - ($important_period))) { + if (preg_match('/(UP)/i', $line['state'])) { + $color = 'green'; + } elseif (preg_match('/(DOWN)/i', $line['state'])) { + $color = 'red'; + } elseif (preg_match('/(RECOVERING|FALLING)/i', $line['state'])) { + $color = 'yellow'; + } + } if ($panel['alarm'] == 'grey' && $color == 'green') { $panel['alarm'] = 'green'; @@ -303,7 +302,7 @@ function alert_host_detail() { $panel['alarm'] = 'red'; } - $row .= ''; + $row .= ''; if ($console_access) { $row .= '' . html_escape(substr($line['description'],0,37)) . '' . $line['state'] . '
' . $line['state'] . '
'; - $panel['detail'] .= '
' . __('More records, use detail window', 'intropage'); + $panel['detail'] .= '
' . __('More records, use detail window', 'intropage'); + break; } } @@ -334,4 +334,3 @@ function alert_host_detail() { return $panel; } - diff --git a/panellib/analyze.php b/panellib/analyze.php index 31f510b..fe63960 100644 --- a/panellib/analyze.php +++ b/panellib/analyze.php @@ -27,13 +27,13 @@ function register_analyze() { global $registry; - $registry['analyze'] = array( + $registry['analyze'] = [ 'name' => __('Analysis Panels', 'intropage'), 'description' => __('Panels that analyze the current behavior of Cacti and it\'s plugins.', 'intropage') - ); + ]; - $panels = array( - 'analyse_login' => array( + $panels = [ + 'analyse_login' => [ 'name' => __('Analyze Logins', 'intropage'), 'description' => __('Analyze the last several Cacti logins for trends and errors.', 'intropage'), 'class' => 'analyze', @@ -50,8 +50,8 @@ function register_analyze() { 'update_func' => 'analyse_login', 'details_func' => 'analyse_login_detail', 'trends_func' => false - ), - 'analyse_log' => array( + ], + 'analyse_log' => [ 'name' => __('Analyze Logs', 'intropage'), 'description' => __('Look for common errors in Cacti\'s log file that should be a cause for concern.', 'intropage'), 'class' => 'analyze', @@ -68,8 +68,8 @@ function register_analyze() { 'update_func' => 'analyse_log', 'details_func' => 'analyse_log_detail', 'trends_func' => false - ), - 'analyse_db' => array( + ], + 'analyse_db' => [ 'name' => __('Database Checks', 'intropage'), 'description' => __('Analyze MySQL/MariaDB database for common errors. Note that this process may take a long time on very large systems.', 'intropage'), 'class' => 'analyze', @@ -86,8 +86,8 @@ function register_analyze() { 'update_func' => 'analyse_db', 'details_func' => false, 'trends_func' => false - ), - 'analyse_tree_host_graph' => array( + ], + 'analyse_tree_host_graph' => [ 'name' => __('Analyze Cacti Objects', 'intropage'), 'description' => __('Analyze Trees, Graphs, Hosts, ...', 'intropage'), 'class' => 'analyze', @@ -104,8 +104,8 @@ function register_analyze() { 'update_func' => 'analyse_tree_host_graph', 'details_func' => 'analyse_tree_host_graph_detail', 'trends_func' => false - ), - 'analyse_ds_stat' => array( + ], + 'analyse_ds_stat' => [ 'name' => __('Analyze DS stats', 'intropage'), 'description' => __('Analyze data source stats', 'intropage'), 'class' => 'analyze', @@ -122,20 +122,20 @@ function register_analyze() { 'update_func' => 'analyse_ds_stats', 'details_func' => false, 'trends_func' => 'ds_stats_trend' - ), - ); + ], + ]; return $panels; } -//------------------------------------ analyse_login ----------------------------------------------------- +// ------------------------------------ analyse_login ----------------------------------------------------- function analyse_login($panel, $user_id) { global $config; - $lines = read_user_setting('intropage_number_of_lines', read_config_option('intropage_number_of_lines'), false, $user_id); + $lines = read_user_setting('intropage_number_of_lines', read_config_option('intropage_number_of_lines'), false, $user_id); $important_period = read_user_setting('intropage_important_period', read_config_option('intropage_important_period'), false, $user_id); - if ($important_period == -1) { + if ($important_period == -1) { $important_period = time(); } @@ -157,7 +157,7 @@ function analyse_login($panel, $user_id) { INNER JOIN user_log ON user_auth.username = user_log.username ORDER BY user_log.time desc - LIMIT ' . ($lines-3)); + LIMIT ' . ($lines - 3)); if (cacti_sizeof($rows)) { $panel['data'] .= @@ -171,27 +171,24 @@ function analyse_login($panel, $user_id) { $i = 0; foreach ($rows as $row) { - $color = 'grey'; if ($row['result'] == 0) { $status = __('Failed', 'intropage'); - if ($row['secs'] > (time()-($important_period))) { + if ($row['secs'] > (time() - ($important_period))) { $color = 'red'; } - } elseif ($row['result'] == 1) { $status = __('Success - Login', 'intropage'); - if ($row['secs'] > (time()-($important_period))) { + if ($row['secs'] > (time() - ($important_period))) { $color = 'green'; } - } else { $status = __('Success - Token', 'intropage'); - if ($row['secs'] > (time()-($important_period))) { + if ($row['secs'] > (time() - ($important_period))) { $color = 'green'; } } @@ -213,7 +210,7 @@ function analyse_login($panel, $user_id) { '%s' . '%s' . '%s' . - '', $i % 2 == 0 ? 'even':'odd', substr($row['time'], 5), $row['username'], $row['ip'], $status); + '', $i % 2 == 0 ? 'even' : 'odd', substr($row['time'], 5), $row['username'], $row['ip'], $status); $i++; } @@ -228,7 +225,7 @@ function analyse_login($panel, $user_id) { WHERE time > adddate(now(), INTERVAL -1 HOUR)'); if (cacti_sizeof($data)) { - $text = implode (', ', array_column($data,'username')); + $text = implode(', ', array_column($data,'username')); } else { $text = __('None', 'intropage'); } @@ -240,7 +237,7 @@ function analyse_login($panel, $user_id) { save_panel_result($panel, $user_id); } -//------------------------------------ analyse_log ----------------------------------------------------- +// ------------------------------------ analyse_log ----------------------------------------------------- function analyse_log($panel, $user_id) { global $config; @@ -260,17 +257,17 @@ function analyse_log($panel, $user_id) { $panel['data'] = ''; $panel['alarm'] = 'green'; - $log = array( - 'file' => read_config_option('path_cactilog'), + $log = [ + 'file' => read_config_option('path_cactilog'), 'nbr_lines' => read_config_option('intropage_analyse_log_rows'), - ); + ]; $log['size'] = @filesize($log['file']); $log['lines'] = tail_log($log['file'], $log['nbr_lines']); if (!$log['size'] || empty($log['lines'])) { $panel['alarm'] = 'red'; - $panel['data'] = __('Log file not accessible or empty', 'intropage'); + $panel['data'] = __('Log file not accessible or empty', 'intropage'); } else { $error = 0; $ecount = 0; @@ -303,14 +300,14 @@ function analyse_log($panel, $user_id) { ''; if ($log['size'] < 0) { - $panel['alarm'] = 'red'; + $panel['alarm'] = 'red'; $log_size_text = __('Log Size: Larger than 2GB', 'intropage'); $log_size_note = ''; } elseif ($log['size'] < 255999999) { $log_size_text = human_filesize($log['size']); $log_size_note = __('Log Size: OK', 'intropage'); } else { - $panel['alarm'] = 'yellow'; + $panel['alarm'] = 'yellow'; $log_size_text = human_filesize($log['size']); $log_size_note = __('Log Size: Quite Large', 'intropage'); } @@ -327,11 +324,11 @@ function analyse_log($panel, $user_id) { $log['lines'] = array_reverse(tail_log($log['file'], $lines - 3)); - $datechar = array( + $datechar = [ GDC_HYPHEN => '-', GDC_SLASH => '/', GDC_DOT => '.' - ); + ]; $date_fmt = read_config_option('default_date_format'); $dateCharSetting = read_config_option('default_datechar'); @@ -345,24 +342,31 @@ function analyse_log($panel, $user_id) { switch ($date_fmt) { case GD_MO_D_Y: $format = 'm' . $datecharacter . 'd' . $datecharacter . 'Y H:i:s'; + break; case GD_MN_D_Y: $format = 'M' . $datecharacter . 'd' . $datecharacter . 'Y H:i:s'; + break; case GD_D_MO_Y: $format = 'd' . $datecharacter . 'm' . $datecharacter . 'Y H:i:s'; + break; case GD_D_MN_Y: $format = 'd' . $datecharacter . 'M' . $datecharacter . 'Y H:i:s'; + break; case GD_Y_MO_D: $format = 'Y' . $datecharacter . 'm' . $datecharacter . 'd H:i:s'; + break; case GD_Y_MN_D: $format = 'Y' . $datecharacter . 'M' . $datecharacter . 'd H:i:s'; + break; default: $format = 'Y' . $datecharacter . 'm' . $datecharacter . 'd H:i:s'; + break; } @@ -372,10 +376,10 @@ function analyse_log($panel, $user_id) { if (strlen($line) > 3) { $date = explode(' - ', $line); - $d_p = date_parse_from_format($format, $date[0]); - $timestamp = mktime ($d_p['hour'], $d_p['minute'], $d_p['second'], $d_p['month'], $d_p['day'], $d_p['year']); + $d_p = date_parse_from_format($format, $date[0]); + $timestamp = mktime($d_p['hour'], $d_p['minute'], $d_p['second'], $d_p['month'], $d_p['day'], $d_p['year']); - if ($timestamp > (time()-($important_period))) { + if ($timestamp > (time() - ($important_period))) { if (preg_match('/( ERROR|FATAL)/', $line)) { $color = 'red'; } elseif (preg_match('/( WARNING)/', $line)) { @@ -404,7 +408,6 @@ function analyse_log($panel, $user_id) { save_panel_result($panel, $user_id); } - // -------------------------------------analyse db------------------------------------------- function analyse_db($panel, $user_id) { global $config, $database_default; @@ -419,11 +422,11 @@ function analyse_db($panel, $user_id) { SET last_update = NOW() WHERE panel_id = ? AND user_id = 0', - array($panel['panel_id'])); + [$panel['panel_id']]); $size = db_fetch_cell_prepared('SELECT SUM(DATA_LENGTH+INDEX_LENGTH) FROM information_schema.TABLES WHERE TABLE_SCHEMA=?', - array($database_default)); + [$database_default]); $tables = db_fetch_assoc('SHOW TABLES'); @@ -431,7 +434,6 @@ function analyse_db($panel, $user_id) { $panel['alarm'] = 'grey'; $panel['data'] = '' . __('Skipping DB tables checks. Database too large') . ''; } else { - $db_check_level = read_config_option('intropage_analyse_db_level'); foreach ($tables as $key => $val) { @@ -496,7 +498,6 @@ function analyse_db($panel, $user_id) { } if ($cerrors > 0) { - if ($color == 'red') { $panel['alarm'] = 'red'; } elseif ($panel['alarm'] == 'green' && $color == 'yellow') { @@ -515,7 +516,6 @@ function analyse_db($panel, $user_id) { } if ($aerrors > 0) { - if ($color == 'red') { $panel['alarm'] = 'red'; } elseif ($panel['alarm'] == 'green' && $color == 'yellow') { @@ -535,14 +535,12 @@ function analyse_db($panel, $user_id) { } $panel['data'] .= '' . - '' . __('Memory tables: %s', $memtables, 'intropage') . '' . + '' . __('Memory tables: %s', $memtables, 'intropage') . '' . '' . __('All tables: %s', cacti_count($tables), 'intropage') . ''; save_panel_result($panel, $user_id); - } - // --------------------------------analyse_tree_host_graph function analyse_tree_host_graph($panel, $user_id) { global $config; @@ -552,16 +550,16 @@ function analyse_tree_host_graph($panel, $user_id) { $console_access = get_console_access($user_id); $total_errors = 0; - $data = array(); + $data = []; $simple_perms = get_simple_device_perms($user_id); if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = ' IN (' . $allowed_devices . ')'; + $host_cond = ' IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if ($allowed_devices !== false || $simple_perms) { @@ -626,11 +624,11 @@ function analyse_tree_host_graph($panel, $user_id) { } // last run of reindex, rrdchecker, ... - $last_runs = array ( + $last_runs = [ 'reindex_last_run_time' => __('Reindex last run'), 'rrdcheck_last_run_time' => __('RRD Checker last run'), 'rrdcleaner_last_run_time' => __('RRD Cleaner last run') - ); + ]; $date_fmt = date_time_format(); @@ -640,7 +638,7 @@ function analyse_tree_host_graph($panel, $user_id) { if (config_value_exists($key)) { $last = read_config_option($key); - if ($last < (time() - 86400*7)) { + if ($last < (time() - 86400 * 7)) { $color = 'yellow'; $panel['data'] .= '' . __('%s: %s', $value, date($date_fmt, $last), 'intropage'); $panel['data'] .= display_tooltip(__('It is recommended to run this tool at least occasionally', 'intropage')) . ''; @@ -680,7 +678,7 @@ function analyse_tree_host_graph($panel, $user_id) { $q_host_cond ORDER BY `name_cache` ASC"); } else { - $data = array(); + $data = []; } $sql_count = ($data === false) ? __('N/A', 'intropage') : cacti_count($data); @@ -713,7 +711,7 @@ function analyse_tree_host_graph($panel, $user_id) { WHERE (dl.snmp_index = "" AND dl.snmp_query_id > 0) ' . $q_host_cond); } else { - $data = array(); + $data = []; } $sql_count = ($data === false) ? __('N/A', 'intropage') : cacti_count($data); @@ -736,7 +734,6 @@ function analyse_tree_host_graph($panel, $user_id) { // I don't use thold get_allowed_thold because of join plugin_thold_threshold_contact if (api_plugin_is_enabled('thold')) { - if ($allowed_devices !== false || $simple_perms) { if (!$simple_perms) { $q_host_cond = 'AND gl.host_id ' . $host_cond; @@ -765,7 +762,7 @@ function analyse_tree_host_graph($panel, $user_id) { $q_host_cond HAVING (user0 IS NULL OR (user1 IS NULL OR user2 IS NULL))"); } else { - $data = array(); + $data = []; } $sql_count = ($data === false) ? __('N/A', 'intropage') : cacti_count($data); @@ -814,7 +811,6 @@ function analyse_tree_host_graph($panel, $user_id) { } } - if ($allowed_devices !== false || $simple_perms) { if (!$simple_perms) { $q_host_cond = 'WHERE host_id ' . $host_cond; @@ -955,7 +951,6 @@ function analyse_tree_host_graph($panel, $user_id) { $sql_count = ($data === false) ? __('N/A', 'intropage') : cacti_count($data); if (cacti_sizeof($data)) { - $panel['alarm'] = 'red'; $panel['data'] .= '' . __('Graph items/template items issue: %s', $sql_count, 'intropage') . ''; @@ -989,8 +984,10 @@ function analyse_tree_host_graph($panel, $user_id) { } $cpu_cores = 0; + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - $output = shell_exec("powershell -Command \"Get-WmiObject Win32_Processor | Select-Object NumberOfLogicalProcessors\""); + $output = shell_exec('powershell -Command "Get-WmiObject Win32_Processor | Select-Object NumberOfLogicalProcessors"'); + if (!is_null($output) && $output !== false) { preg_match_all('/\d+/', $output, $matches); $cpu_cores = array_sum($matches[0]); @@ -1004,6 +1001,7 @@ function analyse_tree_host_graph($panel, $user_id) { $cpu_cores = shell_exec('/bin/nproc'); } else { $output = shell_exec('nproc'); + if (!is_null($output) && $output !== false) { $cpu_cores = $output; } @@ -1011,36 +1009,36 @@ function analyse_tree_host_graph($panel, $user_id) { } $cpu_cores = trim($cpu_cores); - $sett = db_fetch_row('SELECT processes, threads FROM poller WHERE id = 1'); + $sett = db_fetch_row('SELECT processes, threads FROM poller WHERE id = 1'); $color = 'green'; - $text = __('OK'); + $text = __('OK'); if ($cpu_cores == 0) { if ($sett['processes'] == 1 || $sett['threads'] == 1) { $color = 'yellow'; - $text = 'Cannot determine number of CPU cores. You have set only 1 process or thread for poller. You may have performance problems.'; + $text = 'Cannot determine number of CPU cores. You have set only 1 process or thread for poller. You may have performance problems.'; } } elseif ($cpu_cores == 1 && ($sett['processes'] == 1 || $sett['threads'] == 1)) { - $color = 'yellow'; - $text = 'You have set only 1 process or thread for poller. You may have performance problems. Try to increase poller processes or threads.'; - $total_errors++; + $color = 'yellow'; + $text = 'You have set only 1 process or thread for poller. You may have performance problems. Try to increase poller processes or threads.'; + $total_errors++; } elseif ($cpu_cores > 1) { if ($sett['processes'] == 1 || $sett['threads'] == 1) { $color = 'red'; - $text = 'You have set only 1 process or thread for poller. You may have performance problems. Try to increase poller processes or threads.'; + $text = 'You have set only 1 process or thread for poller. You may have performance problems. Try to increase poller processes or threads.'; $total_errors++; - } elseif ($sett['processes']/$cpu_cores < 0.4 || $sett['threads']/$cpu_cores < 0.4) { + } elseif ($sett['processes'] / $cpu_cores < 0.4 || $sett['threads'] / $cpu_cores < 0.4) { $color = 'yellow'; - $text = 'You are using less than half of CPU cores. For better performance, consider increasing poller processes or threads.'; + $text = 'You are using less than half of CPU cores. For better performance, consider increasing poller processes or threads.'; } } $panel['data'] .= '' . __('Server CPU (cores / processes / threads): %s / %s / %s', $cpu_cores, $sett['processes'], $sett['threads'], 'intropage'); $panel['data'] .= display_tooltip($text) . ''; - $notify = db_fetch_cell ("SELECT COUNT(*) FROM settings WHERE name = 'notify_admin' AND value='on'"); + $notify = db_fetch_cell("SELECT COUNT(*) FROM settings WHERE name = 'notify_admin' AND value='on'"); $admin_email = db_fetch_cell("SELECT email_address FROM user_auth WHERE username = 'admin' LIMIT 1"); - $text = 'Administrator can be notified by email about problems. It is therefore necessary to set the admin account email address and at the same time enable notifications in Settings - Mail/Reporting/DNS'; + $text = 'Administrator can be notified by email about problems. It is therefore necessary to set the admin account email address and at the same time enable notifications in Settings - Mail/Reporting/DNS'; if (!$notify || $admin_email == '') { $panel['data'] .= '' . __('Notify admin is disabled and admin email is not set', 'intropage'); @@ -1058,27 +1056,27 @@ function analyse_tree_host_graph($panel, $user_id) { $panel['data'] = ' ' . $panel['data'] . ' -
' . __('Everything OK', 'intropage') . '
';; + '; } save_panel_result($panel, $user_id); } -//------------------------------------ analyse_ds_stats ----------------------------------------------------- +// ------------------------------------ analyse_ds_stats ----------------------------------------------------- function analyse_ds_stats($panel, $user_id, $timespan = 0) { global $config; $panel['alarm'] = 'green'; - $graph = array ( - 'line' => array( + $graph = [ + 'line' => [ 'title' => __('DS stats: ', 'intropage'), - 'label1' => array(), - 'data1' => array(), - 'label2' => array(), - 'data2' => array(), - ), - ); + 'label1' => [], + 'data1' => [], + 'label2' => [], + 'data2' => [], + ], + ]; if ($timespan == 0) { if (isset($_SESSION['sess_user_id'])) { @@ -1092,13 +1090,13 @@ function analyse_ds_stats($panel, $user_id, $timespan = 0) { $refresh = db_fetch_cell_prepared('SELECT refresh_interval FROM plugin_intropage_panel_data WHERE id = ?', - array($panel['id'])); + [$panel['id']]); } else { $refresh = $panel['refresh']; } if (read_config_option('dsstats_enable') != 'on') { - $panel['data'] = __('Panel needs DS stats enabled.', 'intropage') . '
'; + $panel['data'] = __('Panel needs DS stats enabled.', 'intropage') . '
'; $panel['alarm'] = 'grey'; unset($graph); } else { @@ -1107,10 +1105,10 @@ function analyse_ds_stats($panel, $user_id, $timespan = 0) { WHERE cur_timestamp > date_sub(NOW(), INTERVAL ? SECOND) AND name = 'dsstats_all' ORDER BY cur_timestamp ASC", - array($timespan)); + [$timespan]); if (cacti_sizeof($rows)) { - $graph['line']['title1'] = __('DS all records ', 'intropage'); + $graph['line']['title1'] = __('DS all records ', 'intropage'); $graph['line']['unit1']['title'] = 'All'; foreach ($rows as $row) { @@ -1123,10 +1121,10 @@ function analyse_ds_stats($panel, $user_id, $timespan = 0) { WHERE cur_timestamp > date_sub(NOW(), INTERVAL ? SECOND) AND name = 'dsstats_null' ORDER BY cur_timestamp ASC", - array($timespan)); + [$timespan]); if (cacti_sizeof($rows)) { - $graph['line']['title2'] = __('DS null records ', 'intropage'); + $graph['line']['title2'] = __('DS null records ', 'intropage'); $graph['line']['unit2']['title'] = 'Null'; foreach ($rows as $row) { @@ -1150,26 +1148,23 @@ function analyse_ds_stats($panel, $user_id, $timespan = 0) { save_panel_result($panel, $user_id); } - -function ds_stats_trend () { - - $count = db_fetch_cell("SELECT COUNT(*) FROM data_source_stats_hourly_last"); +function ds_stats_trend() { + $count = db_fetch_cell('SELECT COUNT(*) FROM data_source_stats_hourly_last'); db_execute_prepared('REPLACE INTO plugin_intropage_trends (name, value, user_id) VALUES (?, ?, 0)', - array('dsstats_all', $count)); + ['dsstats_all', $count]); - $count = db_fetch_cell("SELECT COUNT(*) FROM data_source_stats_hourly_last WHERE value IS NULL"); + $count = db_fetch_cell('SELECT COUNT(*) FROM data_source_stats_hourly_last WHERE value IS NULL'); db_execute_prepared('REPLACE INTO plugin_intropage_trends (name, value, user_id) VALUES (?, ?, 0)', - array('dsstats_null', $count)); + ['dsstats_null', $count]); } - -//------------------------------------ analyse_log ----------------------------------------------------- +// ------------------------------------ analyse_log ----------------------------------------------------- function analyse_log_detail() { global $log; @@ -1184,19 +1179,19 @@ function analyse_log_detail() { $important_period = time(); } - $panel = array( + $panel = [ 'name' => __('Analyze Cacti Log Details [ Warnings/Errors ]', 'intropage'), 'alarm' => 'green', 'detail' => '', - ); + ]; - $log = array( + $log = [ 'file' => read_config_option('path_cactilog'), 'nbr_lines' => read_config_option('intropage_analyse_log_rows'), - ); + ]; $log['size'] = @filesize($log['file']); - $log['lines'] = tail_log($log['file'], $log['nbr_lines']*2); + $log['lines'] = tail_log($log['file'], $log['nbr_lines'] * 2); $panel['detail'] .= ''; @@ -1231,14 +1226,14 @@ function analyse_log_detail() { ''; if ($log['size'] < 0) { - $panel['alarm'] = 'red'; + $panel['alarm'] = 'red'; $log_size_text = __('WARNING: File is Larger than 2GB', 'intropage'); $log_size_note = ''; } elseif ($log['size'] < 255999999) { $log_size_text = human_filesize($log['size']); $log_size_note = __('Log Size: OK', 'intropage'); } else { - $panel['alarm'] = 'yellow'; + $panel['alarm'] = 'yellow'; $log_size_text = human_filesize($log['size']); $log_size_note = __('Log Size: Quite Large', 'intropage'); } @@ -1249,11 +1244,11 @@ function analyse_log_detail() { $panel['detail'] .= ''; } - $datechar = array( + $datechar = [ GDC_HYPHEN => '-', GDC_SLASH => '/', GDC_DOT => '.' - ); + ]; $date_fmt = read_config_option('default_date_format'); $dateCharSetting = read_config_option('default_datechar'); @@ -1267,31 +1262,37 @@ function analyse_log_detail() { switch ($date_fmt) { case GD_MO_D_Y: $format = 'm' . $datecharacter . 'd' . $datecharacter . 'Y H:i:s'; + break; case GD_MN_D_Y: $format = 'M' . $datecharacter . 'd' . $datecharacter . 'Y H:i:s'; + break; case GD_D_MO_Y: $format = 'd' . $datecharacter . 'm' . $datecharacter . 'Y H:i:s'; + break; case GD_D_MN_Y: $format = 'd' . $datecharacter . 'M' . $datecharacter . 'Y H:i:s'; + break; case GD_Y_MO_D: $format = 'Y' . $datecharacter . 'm' . $datecharacter . 'd H:i:s'; + break; case GD_Y_MN_D: $format = 'Y' . $datecharacter . 'M' . $datecharacter . 'd H:i:s'; + break; default: $format = 'Y' . $datecharacter . 'm' . $datecharacter . 'd H:i:s'; + break; } $count = 0; foreach ($log['lines'] as $line) { - if ($count > 99) { break; } @@ -1299,13 +1300,12 @@ function analyse_log_detail() { $color = 'grey'; if (strlen($line) > 3) { - $date = explode(' - ', $line); - $d_p = date_parse_from_format($format, $date[0]); - $timestamp = mktime ($d_p['hour'], $d_p['minute'], $d_p['second'], $d_p['month'], $d_p['day'], $d_p['year']); + $d_p = date_parse_from_format($format, $date[0]); + $timestamp = mktime($d_p['hour'], $d_p['minute'], $d_p['second'], $d_p['month'], $d_p['day'], $d_p['year']); - if ($timestamp > (time()-($important_period))) { + if ($timestamp > (time() - ($important_period))) { if (preg_match('/( ERROR)/', $line)) { $color = 'red'; } elseif (preg_match('/( WARNING)/', $line)) { @@ -1331,7 +1331,7 @@ function analyse_log_detail() { return $panel; } -//------------------------------------ analyse_login ----------------------------------------------------- +// ------------------------------------ analyse_login ----------------------------------------------------- function analyse_login_detail() { global $config; @@ -1348,11 +1348,11 @@ function analyse_login_detail() { $lines = 20; - $panel = array( + $panel = [ 'name' => __('Analyze Logins Detail', 'intropage'), 'alarm' => 'green', 'detail' => '', - ); + ]; $data = db_fetch_assoc('SELECT user_log.username, user_auth.full_name, user_log.time, user_log.result, user_log.ip, UNIX_TIMESTAMP(user_log.time) AS secs @@ -1365,10 +1365,10 @@ function analyse_login_detail() { if (cacti_sizeof($data)) { $panel['detail'] .= '
' . $log_size_note . '
' . '' . - '' . + '' . '' . - '' . - '' . + '' . + '' . ''; foreach ($data as $row) { @@ -1377,21 +1377,19 @@ function analyse_login_detail() { if ($row['result'] == 0) { $status = __('Failed', 'intropage'); - if ($row['secs'] > (time()-($important_period))) { + if ($row['secs'] > (time() - ($important_period))) { $color = 'red'; } - } elseif ($row['result'] == 1) { $status = __('Success - Login', 'intropage'); - if ($row['secs'] > (time()-($important_period))) { + if ($row['secs'] > (time() - ($important_period))) { $color = 'green'; } - } else { $status = __('Success - Token', 'intropage'); - if ($row['secs'] > (time()-($important_period))) { + if ($row['secs'] > (time() - ($important_period))) { $color = 'green'; } } @@ -1431,36 +1429,38 @@ function analyse_login_detail() { return $panel; } -//------------------------------------ analyse_tree_host_graph ----------------------------------------------------- +// ------------------------------------ analyse_tree_host_graph ----------------------------------------------------- function analyse_tree_host_graph_detail() { global $config, $console_access; if (isset($_SESSION['sess_user_id'])) { $simple_perms = get_simple_device_perms($_SESSION['sess_user_id']); + if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = ' IN (' . $allowed_devices . ')'; + $host_cond = ' IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } } else { - $admin_user = read_config_option('admin_user'); + $admin_user = read_config_option('admin_user'); $simple_perms = get_simple_device_perms($admin_user); + if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($admin_user); - $host_cond = ' IN (' . $allowed_devices . ')'; + $host_cond = ' IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } } - $panel = array( + $panel = [ 'name' => __('Analyze Tree, Graphs, Hosts', 'intropage'), 'alarm' => 'green', 'detail' => '', - ); + ]; $total_errors = 0; @@ -1485,16 +1485,16 @@ function analyse_tree_host_graph_detail() { if (cacti_sizeof($data)) { $total_errors += $sql_count; - if ($color == 'red') { + if ($color == 'red') { $panel['alarm'] = 'red'; } elseif ($panel['alarm'] == 'green' && $color == 'yellow') { $panel['alarm'] = 'yellow'; } foreach ($data as $row) { - $sql_hosts = db_fetch_assoc("SELECT id, description, hostname + $sql_hosts = db_fetch_assoc('SELECT id, description, hostname FROM host - WHERE hostname = " . db_qstr($row['hostname']) . " AND snmp_port=" . $row['snmp_port']); + WHERE hostname = ' . db_qstr($row['hostname']) . ' AND snmp_port=' . $row['snmp_port']); if (cacti_sizeof($sql_hosts)) { foreach ($sql_hosts as $row2) { @@ -1546,23 +1546,21 @@ function analyse_tree_host_graph_detail() { } // last run of reindex, rrdchecker, ... - $last_runs = array ( + $last_runs = [ 'reindex_last_run_time' => __('Reindex last run'), 'rrdcheck_last_run_time' => __('RRD Checker last run'), 'rrdcleaner_last_run_time' => __('RRD Cleaner last run') - ); + ]; $date_fmt = date_time_format(); $tmp_data = ''; - $color = 'green'; - + $color = 'green'; foreach ($last_runs as $key => $value) { - if (config_value_exists($key)) { $last = read_config_option($key); - if ($last < (time() - 86400*7)) { + if ($last < (time() - 86400 * 7)) { if ($color == 'green') { $color = 'yellow'; } @@ -1580,7 +1578,6 @@ function analyse_tree_host_graph_detail() { $panel['detail'] .= '

' . __('Data maintenance', 'intropage') . '

'; $panel['detail'] .= $tmp_data; - if ($allowed_devices !== false || $simple_perms) { if (!$simple_perms) { $q_host_cond = 'AND dl.host_id ' . $host_cond; @@ -1655,7 +1652,7 @@ function analyse_tree_host_graph_detail() { $panel['detail'] .= '

' . __('Datasources with bad indexes - %s', $sql_count, 'intropage') . '

'; if (cacti_sizeof($data)) { - if ($color == 'red') { + if ($color == 'red') { $panel['alarm'] = 'red'; } elseif ($panel['alarm'] == 'green' && $color == 'yellow') { $panel['alarm'] = 'yellow'; @@ -1724,8 +1721,6 @@ function analyse_tree_host_graph_detail() { } } - - if ($allowed_devices !== false || $simple_perms) { if (!$simple_perms) { $q_host_cond = 'AND id ' . $host_cond; @@ -1747,16 +1742,16 @@ function analyse_tree_host_graph_detail() { if (cacti_sizeof($data)) { $total_errors += $sql_count; - if ($color == 'red') { + if ($color == 'red') { $panel['alarm'] = 'red'; } elseif ($panel['alarm'] == 'green' && $color == 'yellow') { $panel['alarm'] = 'yellow'; } foreach ($data as $row) { - $sql_hosts = db_fetch_assoc("SELECT id, description, hostname + $sql_hosts = db_fetch_assoc('SELECT id, description, hostname FROM host - WHERE description = " . db_qstr($row['description'])); + WHERE description = ' . db_qstr($row['description'])); if (cacti_sizeof($sql_hosts)) { foreach ($sql_hosts as $row2) { @@ -1767,7 +1762,6 @@ function analyse_tree_host_graph_detail() { } } - if ($allowed_devices !== false || $simple_perms) { if (!$simple_perms) { $q_host_cond = 'WHERE host.id ' . $host_cond; @@ -1803,12 +1797,13 @@ function analyse_tree_host_graph_detail() { INNER JOIN graph_tree ON (graph_tree_items.graph_tree_id = graph_tree.id) WHERE host.id = ?', - array($row['id'])); + [$row['id']]); if (cacti_sizeof($sql_hosts)) { foreach ($sql_hosts as $host) { $parent = $host['parent']; $tree = $host['name'] . ' / '; + while ($parent != 0) { $sql_parent = db_fetch_row('SELECT parent, title FROM graph_tree_items WHERE id = ' . $parent); $parent = $sql_parent['parent']; @@ -1877,7 +1872,7 @@ function analyse_tree_host_graph_detail() { $panel['detail'] .= '

' . __('Devices without tree - %s', $sql_count, 'intropage') . '

'; if (cacti_sizeof($data)) { - if ($color == 'red') { + if ($color == 'red') { $panel['alarm'] = 'red'; } elseif ($panel['alarm'] == 'green' && $color == 'yellow') { $panel['alarm'] = 'yellow'; @@ -1909,7 +1904,7 @@ function analyse_tree_host_graph_detail() { $panel['detail'] .= '

' . __('Devices with default public/private community - %s', $sql_count, 'intropage') . '

'; if (cacti_sizeof($data)) { - if ($color == 'red') { + if ($color == 'red') { $panel['alarm'] = 'red'; } elseif ($panel['alarm'] == 'green' && $color == 'yellow') { $panel['alarm'] = 'yellow'; @@ -1948,7 +1943,6 @@ function analyse_tree_host_graph_detail() { $panel['detail'] .= '

' . __('Graph items/template items issue - %s', $sql_count, 'intropage') . '

'; if (cacti_sizeof($data)) { - $panel['alarm'] = 'red'; $panel['detail'] .= '
' . __('Date', 'intropage') . '' . __('Date', 'intropage') . '' . __('IP Address', 'intropage') . '' . __('User', 'intropage') . '' . __('Result', 'intropage') . '' . __('User', 'intropage') . '' . __('Result', 'intropage') . '
'; @@ -1959,6 +1953,7 @@ function analyse_tree_host_graph_detail() { foreach ($data as $row) { $panel['detail'] .= ''; @@ -1973,7 +1968,6 @@ function analyse_tree_host_graph_detail() { $panel['detail'] .= '
'; + if ($console_access) { $panel['detail'] .= '' . $row['name'] . '
'; } - // plugin monitor - host without monitoring if (api_plugin_is_enabled('monitor')) { if ($allowed_devices !== false || $simple_perms) { @@ -1994,7 +1988,7 @@ function analyse_tree_host_graph_detail() { $panel['detail'] .= '

' . __('Plugin Monitor - Unmonitored hosts - %s', $sql_count, 'intropage') . '

'; if (cacti_sizeof($data)) { - if ($color == 'red') { + if ($color == 'red') { $panel['alarm'] = 'red'; } elseif ($panel['alarm'] == 'green' && $color == 'yellow') { $panel['alarm'] = 'yellow'; @@ -2008,8 +2002,10 @@ function analyse_tree_host_graph_detail() { } $cpu_cores = 0; + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - $output = shell_exec("powershell -Command \"Get-WmiObject Win32_Processor | Select-Object NumberOfLogicalProcessors\""); + $output = shell_exec('powershell -Command "Get-WmiObject Win32_Processor | Select-Object NumberOfLogicalProcessors"'); + if (!is_null($output) && $output !== false) { preg_match_all('/\d+/', $output, $matches); $cpu_cores = array_sum($matches[0]); @@ -2023,6 +2019,7 @@ function analyse_tree_host_graph_detail() { $cpu_cores = shell_exec('/bin/nproc'); } else { $output = shell_exec('nproc'); + if (!is_null($output) && $output !== false) { $cpu_cores = $output; } @@ -2030,36 +2027,36 @@ function analyse_tree_host_graph_detail() { } $cpu_cores = trim($cpu_cores); - $sett = db_fetch_row('SELECT processes, threads FROM poller WHERE id = 1'); + $sett = db_fetch_row('SELECT processes, threads FROM poller WHERE id = 1'); $color = 'green'; - $text = __('OK'); + $text = __('OK'); if ($cpu_cores == 0) { if ($sett['processes'] == 1 || $sett['threads'] == 1) { $color = 'yellow'; - $text = 'Cannot determine number of CPU cores. You have set only 1 process or thread for poller. You may have performance problems.'; + $text = 'Cannot determine number of CPU cores. You have set only 1 process or thread for poller. You may have performance problems.'; } } elseif ($cpu_cores == 1 && ($sett['processes'] == 1 || $sett['threads'] == 1)) { - $color = 'yellow'; - $text = 'You have set only 1 process or thread for poller. You may have performance problems. Try to increase poller processes or threads.'; - $total_errors++; + $color = 'yellow'; + $text = 'You have set only 1 process or thread for poller. You may have performance problems. Try to increase poller processes or threads.'; + $total_errors++; } elseif ($cpu_cores > 1) { if ($sett['processes'] == 1 || $sett['threads'] == 1) { $color = 'red'; - $text = 'You have set only 1 process or thread for poller. You may have performance problems. Try to increase poller processes or threads.'; + $text = 'You have set only 1 process or thread for poller. You may have performance problems. Try to increase poller processes or threads.'; $total_errors++; - } elseif ($sett['processes']/$cpu_cores < 0.4 || $sett['threads']/$cpu_cores < 0.4) { + } elseif ($sett['processes'] / $cpu_cores < 0.4 || $sett['threads'] / $cpu_cores < 0.4) { $color = 'yellow'; - $text = 'You are using less than half of CPU cores. For better performance, consider increasing poller processes or threads. '; + $text = 'You are using less than half of CPU cores. For better performance, consider increasing poller processes or threads. '; } } $panel['detail'] .= '' . __('Server CPU cores / processes / threads: %s / %s / %s', $cpu_cores, $sett['processes'], $sett['threads'], 'intropage'); $panel['detail'] .= display_tooltip($text) . '
'; - $notify = db_fetch_cell ("SELECT COUNT(*) FROM settings WHERE name = 'notify_admin' AND value='on'"); + $notify = db_fetch_cell("SELECT COUNT(*) FROM settings WHERE name = 'notify_admin' AND value='on'"); $admin_email = db_fetch_cell("SELECT email_address FROM user_auth WHERE username = 'admin' LIMIT 1"); - $text = 'Administrator can be notified by email about problems. It is therefore necessary to set the admin account email address and at the same time enable notifications in Settings - Mail/Reporting/DNS'; + $text = 'Administrator can be notified by email about problems. It is therefore necessary to set the admin account email address and at the same time enable notifications in Settings - Mail/Reporting/DNS'; if (!$notify && $admin_email == '') { $panel['detail'] .= '' . __('Notify admin is disabled and admin email is not set', 'intropage'); @@ -2070,6 +2067,7 @@ function analyse_tree_host_graph_detail() { $panel['detail'] .= '' . __('Notify admin is disabled or admin email is not set', 'intropage'); $panel['detail'] .= display_tooltip($text) . '
'; $total_errors++; + if ($panel['alarm'] == 'green') { $panel['alarm'] = 'yellow'; } @@ -2083,4 +2081,3 @@ function analyse_tree_host_graph_detail() { return $panel; } - diff --git a/panellib/busiest.php b/panellib/busiest.php index 6bbf60a..4012e1b 100644 --- a/panellib/busiest.php +++ b/panellib/busiest.php @@ -27,13 +27,13 @@ function register_busiest() { global $registry; - $registry['busiest'] = array( + $registry['busiest'] = [ 'name' => __('The busiest', 'intropage'), 'description' => __('Panels that finds the busiest hosts.', 'intropage') - ); + ]; - $panels = array( - 'busiest_cpu' => array( + $panels = [ + 'busiest_cpu' => [ 'name' => __('Busiest CPU', 'intropage'), 'description' => __('Devices with the busiest CPU (Host MIB)', 'intropage'), 'class' => 'busiest', @@ -50,8 +50,8 @@ function register_busiest() { 'update_func' => 'busiest_cpu', 'details_func' => 'busiest_cpu_detail', 'trends_func' => false - ), - 'busiest_load' => array( + ], + 'busiest_load' => [ 'name' => __('Busiest ucd/net - Load', 'intropage'), 'description' => __('Devices with the highest Load (ucd/net)', 'intropage'), 'class' => 'busiest', @@ -68,8 +68,8 @@ function register_busiest() { 'update_func' => 'busiest_load', 'details_func' => 'busiest_load_detail', 'trends_func' => false - ), - 'busiest_hdd' => array( + ], + 'busiest_hdd' => [ 'name' => __('Busiest Hard Drive Space', 'intropage'), 'description' => __('Devices with the highest Hard Drive Space used (Host MIB)', 'intropage'), 'class' => 'busiest', @@ -86,8 +86,8 @@ function register_busiest() { 'update_func' => 'busiest_hdd', 'details_func' => 'busiest_hdd_detail', 'trends_func' => false - ), - 'busiest_uptime' => array( + ], + 'busiest_uptime' => [ 'name' => __('Busiest uptime', 'intropage'), 'description' => __('Devices with the highest uptime', 'intropage'), 'class' => 'busiest', @@ -104,8 +104,8 @@ function register_busiest() { 'update_func' => 'busiest_uptime', 'details_func' => 'busiest_uptime_detail', 'trends_func' => false - ), - 'busiest_traffic' => array( + ], + 'busiest_traffic' => [ 'name' => __('Busiest Interface in/out traffic', 'intropage'), 'description' => __('Devices with the highest in/out traffic (Interface)', 'intropage'), 'class' => 'busiest', @@ -122,8 +122,8 @@ function register_busiest() { 'update_func' => 'busiest_traffic', 'details_func' => 'busiest_traffic_detail', 'trends_func' => false - ), - 'busiest_interface_error' => array( + ], + 'busiest_interface_error' => [ 'name' => __('Busiest Interface error', 'intropage'), 'description' => __('Devices with the highest errors/discards (Interface)', 'intropage'), 'class' => 'busiest', @@ -140,8 +140,8 @@ function register_busiest() { 'update_func' => 'busiest_interface_error', 'details_func' => 'busiest_interface_error_detail', 'trends_func' => false - ), - 'busiest_interface_utilization' => array( + ], + 'busiest_interface_utilization' => [ 'name' => __('Busiest Interface utilization', 'intropage'), 'description' => __('Ports with the highest interface utilization', 'intropage'), 'class' => 'busiest', @@ -158,13 +158,13 @@ function register_busiest() { 'update_func' => 'busiest_interface_util', 'details_func' => 'busiest_interface_util_detail', 'trends_func' => false - ), - ); + ], + ]; return $panels; } -//------------------------------------ busiest cpu ----------------------------------------------------- +// ------------------------------------ busiest cpu ----------------------------------------------------- function busiest_cpu($panel, $user_id) { global $config; @@ -178,12 +178,13 @@ function busiest_cpu($panel, $user_id) { $panel['data'] = __('Panel needs DS stats enabled.', 'intropage') . '
'; if ($console_access) { - $panel['data'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; + $panel['data'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; } else { - $panel['data'] .= __('Ask admin to enable DS stats', 'intropage') . ''; + $panel['data'] .= __('Ask admin to enable DS stats', 'intropage') . ''; } save_panel_result($panel, $user_id); + return true; } @@ -191,10 +192,10 @@ function busiest_cpu($panel, $user_id) { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } $ds = db_fetch_row("SELECT id, name @@ -217,17 +218,17 @@ function busiest_cpu($panel, $user_id) { WHERE h.disabled != 'on' $q_host_cond AND dsh.average IS NOT NULL - AND dtd.data_template_id = " . $ds['id'] . " + AND dtd.data_template_id = " . $ds['id'] . ' ORDER BY dsh.average DESC - LIMIT " . $lines; + LIMIT ' . $lines; - $avg = db_fetch_cell('SELECT AVG(average)' . $query); + $avg = db_fetch_cell('SELECT AVG(average)' . $query); $result = db_fetch_assoc("SELECT $columns $query"); if (cacti_sizeof($result)) { $panel['data'] = '' . '' . - '' . + '' . '' . '' . ''; @@ -241,7 +242,7 @@ function busiest_cpu($panel, $user_id) { ON gti.task_item_id = dtr.id WHERE dtr.local_data_id = ? LIMIT 1', - array($row['ldid'])); + [$row['ldid']]); $color = 'green'; @@ -251,7 +252,7 @@ function busiest_cpu($panel, $user_id) { $color = 'yellow'; } - $panel['data'] .= ''; + $panel['data'] .= ''; $panel['data'] .= ''; $panel['data'] .= ''; $panel['data'] .= ''; @@ -260,7 +261,7 @@ function busiest_cpu($panel, $user_id) { $host_id = db_fetch_cell_prepared('SELECT host_id FROM data_local WHERE id = ?', - array($row['ldid'])); + [$row['ldid']]); cacti_log("WARNING: Problem with DSSTAT data for Device[$host_id] and DS[{$row['ldid']}]. Please investigate or clear DSSTAT data.", false, 'INTROPAGE'); } @@ -273,7 +274,6 @@ function busiest_cpu($panel, $user_id) { } else { $panel['data'] = __('Waiting for data or you don\'t have permission for any device with this template.', 'intropage'); } - } else { $panel['data'] = __('You don\'t have permissions to any hosts or there isn\'t any host with this template', 'intropage'); } @@ -281,8 +281,7 @@ function busiest_cpu($panel, $user_id) { save_panel_result($panel, $user_id); } - -//------------------------------------ busiest load ----------------------------------------------------- +// ------------------------------------ busiest load ----------------------------------------------------- function busiest_load($panel, $user_id) { global $config; @@ -296,12 +295,13 @@ function busiest_load($panel, $user_id) { $panel['data'] = __('Panel needs DS stats enabled.', 'intropage') . '
'; if ($console_access) { - $panel['data'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; + $panel['data'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; } else { - $panel['data'] .= __('Ask admin to enable DS stats', 'intropage') . ''; + $panel['data'] .= __('Ask admin to enable DS stats', 'intropage') . ''; } save_panel_result($panel, $user_id); + return true; } @@ -309,17 +309,17 @@ function busiest_load($panel, $user_id) { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } $ds = db_fetch_row("SELECT id, name FROM data_template WHERE hash='9b82d44eb563027659683765f92c9757'"); - if (($allowed_devices !== false || $simple_perms)&& cacti_sizeof($ds)) { + if (($allowed_devices !== false || $simple_perms) && cacti_sizeof($ds)) { $columns = " dtd.local_data_id AS ldid, concat(dtd.name_cache,' - ', dsh.rrd_name) AS name, dsh.average AS xvalue, dsh.peak AS xpeak "; if (!$simple_perms) { @@ -335,9 +335,9 @@ function busiest_load($panel, $user_id) { WHERE h.disabled != 'on' $q_host_cond AND dsh.average IS NOT NULL - AND dtd.data_template_id = " . $ds['id'] . " + AND dtd.data_template_id = " . $ds['id'] . ' ORDER BY dsh.average DESC - LIMIT " . $lines; + LIMIT ' . $lines; $avg = db_fetch_cell('SELECT AVG(average)' . $query); $result = db_fetch_assoc("SELECT $columns $query"); @@ -345,7 +345,7 @@ function busiest_load($panel, $user_id) { if (cacti_sizeof($result)) { $panel['data'] = '
' . $ds['name'] . '' . $ds['name'] . '' . __('Average', 'intropage') . '' . __('Peak', 'intropage') . '
' . html_escape($row['name']) . '' . round($row['xvalue'], 2) . ' % ' . round($row['xpeak'], 2) . ' %
' . '' . - '' . + '' . '' . '' . ''; @@ -359,7 +359,7 @@ function busiest_load($panel, $user_id) { ON gti.task_item_id = dtr.id WHERE dtr.local_data_id = ? LIMIT 1', - array($row['ldid'])); + [$row['ldid']]); $color = 'green'; @@ -369,7 +369,7 @@ function busiest_load($panel, $user_id) { $color = 'yellow'; } - $panel['data'] .= ''; + $panel['data'] .= ''; $panel['data'] .= ''; $panel['data'] .= "'; $panel['data'] .= "'; @@ -379,11 +379,9 @@ function busiest_load($panel, $user_id) { $panel['data'] .= ''; $panel['data'] .= '
' . $ds['name'] . '' . $ds['name'] . '' . __('Average', 'intropage') . '' . __('Peak', 'intropage') . '
' . html_escape($row['name']) . '" . round($row['xvalue'], 2) . '" . round($row['xpeak'], 2) . '
' . __('Average of all allowed DS') . '' . round($avg, 2) . '
'; - } else { $panel['data'] = __('Waiting for data or you don\'t have permission for any device with this template.', 'intropage'); } - } else { $panel['data'] = __('You don\'t have permissions to any hosts or there isn\'t any host with this template', 'intropage'); } @@ -391,8 +389,7 @@ function busiest_load($panel, $user_id) { save_panel_result($panel, $user_id); } - -//------------------------------------ busiest_hdd ----------------------------------------------------- +// ------------------------------------ busiest_hdd ----------------------------------------------------- function busiest_hdd($panel, $user_id) { global $config; @@ -406,12 +403,13 @@ function busiest_hdd($panel, $user_id) { $panel['data'] = __('Panel needs DS stats enabled.', 'intropage') . '
'; if ($console_access) { - $panel['data'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; + $panel['data'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; } else { - $panel['data'] .= __('Ask admin to enable DS stats', 'intropage') . ''; + $panel['data'] .= __('Ask admin to enable DS stats', 'intropage') . ''; } save_panel_result($panel, $user_id); + return true; } @@ -419,10 +417,10 @@ function busiest_hdd($panel, $user_id) { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } $ds = db_fetch_row("SELECT id,name @@ -447,9 +445,9 @@ function busiest_hdd($panel, $user_id) { WHERE h.disabled != 'on' $q_host_cond AND dsh.rrd_name = 'hdd_used' - AND dtd.data_template_id = " . $ds['id'] . " + AND dtd.data_template_id = " . $ds['id'] . ' ORDER BY xvalue DESC - LIMIT " . $lines; + LIMIT ' . $lines; $result = db_fetch_assoc("SELECT $columns $query"); @@ -465,21 +463,21 @@ function busiest_hdd($panel, $user_id) { $q_host_cond AND dtd.data_template_id = " . $ds['id']; - $xavg = db_fetch_assoc ('SELECT ' . $columns . ' ' . $query); - $avg = 0; + $xavg = db_fetch_assoc('SELECT ' . $columns . ' ' . $query); + $avg = 0; if ($xavg) { foreach ($xavg as $row) { - $avg+=$row['xvalue']; + $avg += $row['xvalue']; } - $avg = $avg/count($xavg); + $avg = $avg / count($xavg); } if (cacti_sizeof($result)) { $panel['data'] = '' . '' . - '' . + '' . '' . '' . ''; @@ -493,7 +491,7 @@ function busiest_hdd($panel, $user_id) { ON gti.task_item_id = dtr.id WHERE dtr.local_data_id = ? LIMIT 1', - array($row['ldid'])); + [$row['ldid']]); $color = 'green'; @@ -503,7 +501,7 @@ function busiest_hdd($panel, $user_id) { $color = 'yellow'; } - $panel['data'] .= ''; + $panel['data'] .= ''; $panel['data'] .= ''; $panel['data'] .= ''; $panel['data'] .= ''; @@ -512,7 +510,7 @@ function busiest_hdd($panel, $user_id) { $host_id = db_fetch_cell_prepared('SELECT host_id FROM data_local WHERE id = ?', - array($row['ldid'])); + [$row['ldid']]); cacti_log("WARNING: Problem with DSSTAT data for Device[$host_id] and DS[{$row['ldid']}]. Please investigate or clear DSSTAT data.", false, 'INTROPAGE'); } @@ -522,11 +520,9 @@ function busiest_hdd($panel, $user_id) { $panel['data'] .= ''; $panel['data'] .= '
' . $ds['name'] . '' . $ds['name'] . '' . __('Average', 'intropage') . '' . __('Peak', 'intropage') . '
' . html_escape($row['name']) . '' . round($row['xvalue'], 2) . ' % ' . round($row['xpeak'], 2) . ' %
' . __('Average of all allowed DS') . '' . round($avg, 2) . ' %
'; - } else { $panel['data'] = __('Waiting for data or you don\'t have permission for any device with this template.', 'intropage'); } - } else { $panel['data'] = __('You don\'t have permissions to any hosts or there isn\'t any host with this template', 'intropage'); } @@ -534,8 +530,7 @@ function busiest_hdd($panel, $user_id) { save_panel_result($panel, $user_id); } - -//------------------------------------ busiest uptime ----------------------------------------------------- +// ------------------------------------ busiest uptime ----------------------------------------------------- function busiest_uptime($panel, $user_id) { global $config; @@ -549,14 +544,14 @@ function busiest_uptime($panel, $user_id) { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if ($allowed_devices !== false || $simple_perms) { - $columns = " id, description, snmp_sysUpTimeInstance"; + $columns = ' id, description, snmp_sysUpTimeInstance'; if (!$simple_perms) { $q_host_cond = 'AND id ' . $host_cond; @@ -572,35 +567,31 @@ function busiest_uptime($panel, $user_id) { $result = db_fetch_assoc("SELECT $columns $query"); if (cacti_sizeof($result)) { - $panel['data'] = '' . '' . - '' . + '' . '' . ''; $i = 0; foreach ($result as $row) { - if ($console_access) { - $panel['data'] .= ''; + $panel['data'] .= ''; } else { - $panel['data'] .= ''; + $panel['data'] .= ''; } - $panel['data'] .= "'; + $panel['data'] .= "'; $i++; } - $panel['data'] .= ''; + $panel['data'] .= ''; $panel['data'] .= '
' . __('Host', 'intropage') . '' . __('Host', 'intropage') . '' . __('Uptime', 'intropage') . '
' . html_escape($row['description']) . '
' . html_escape($row['description']) . '
' . html_escape($row['description']) . '
' . html_escape($row['description']) . '" . get_daysfromtime($row['snmp_sysUpTimeInstance']/100) . '
" . get_daysfromtime($row['snmp_sysUpTimeInstance'] / 100) . '
' . __('Average of all allowed hosts') . '' . get_daysfromtime($avg/100) . '
' . __('Average of all allowed hosts') . '' . get_daysfromtime($avg / 100) . '
'; - } else { $panel['data'] = __('Waiting for data or you don\'t have permission for any device', 'intropage'); } - } else { $panel['data'] = __('You don\'t have permissions to any hosts', 'intropage'); } @@ -608,8 +599,7 @@ function busiest_uptime($panel, $user_id) { save_panel_result($panel, $user_id); } - -//------------------------------------ busiest_traffic ----------------------------------------------------- +// ------------------------------------ busiest_traffic ----------------------------------------------------- function busiest_traffic($panel, $user_id) { global $config; @@ -625,12 +615,13 @@ function busiest_traffic($panel, $user_id) { $panel['data'] = __('Panel needs DS stats enabled.', 'intropage') . '
'; if ($console_access) { - $panel['data'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; + $panel['data'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; } else { - $panel['data'] .= __('Ask admin to enable DS stats', 'intropage') . ''; + $panel['data'] .= __('Ask admin to enable DS stats', 'intropage') . ''; } save_panel_result($panel, $user_id); + return true; } @@ -638,10 +629,10 @@ function busiest_traffic($panel, $user_id) { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } $ds = db_fetch_row("SELECT id,name @@ -680,21 +671,21 @@ function busiest_traffic($panel, $user_id) { WHERE dtd.data_template_id = ' . $ds['id'] . ' AND rrd_name=\'traffic_out\' '; - $xavg = db_fetch_assoc ('SELECT ' . $columns . ' ' . $query); - $avg = 0; + $xavg = db_fetch_assoc('SELECT ' . $columns . ' ' . $query); + $avg = 0; if ($xavg) { foreach ($xavg as $row) { - $avg+=$row['xvalue']; + $avg += $row['xvalue']; } - $avg = $avg/count($xavg); + $avg = $avg / count($xavg); } if (cacti_sizeof($result)) { $panel['data'] = '' . '' . - '' . + '' . '' . '' . ''; @@ -708,9 +699,9 @@ function busiest_traffic($panel, $user_id) { ON gti.task_item_id = dtr.id WHERE dtr.local_data_id = ? LIMIT 1', - array($row['ldid'])); + [$row['ldid']]); - $panel['data'] .= ''; + $panel['data'] .= ''; $panel['data'] .= ''; if ($intropage_mb == 'b') { @@ -722,7 +713,7 @@ function busiest_traffic($panel, $user_id) { } $panel['data'] .= "'; - $panel['data'] .= "'; + $panel['data'] .= "'; $i++; } @@ -733,11 +724,9 @@ function busiest_traffic($panel, $user_id) { $panel['data'] .= ''; $panel['data'] .= '
' . $ds['name'] . '' . $ds['name'] . '' . __('Average', 'intropage') . '' . __('Peak', 'intropage') . '
' . html_escape($row['name']) . '" . human_readable($row['xvalue'], false,1) . $units . '" . human_readable($row['xpeak'], false,1) . $units .'
" . human_readable($row['xpeak'], false,1) . $units . '
' . __('Average of all allowed DS') . '' . human_readable($avg, false,1) . $units . '
'; - } else { $panel['data'] = __('Waiting for data or you don\'t have permission for any device with this template.', 'intropage'); } - } else { $panel['data'] = __('You don\'t have permissions to any hosts or there isn\'t any host with this template', 'intropage'); } @@ -745,8 +734,7 @@ function busiest_traffic($panel, $user_id) { save_panel_result($panel, $user_id); } - -//------------------------------------ busiest_traffic_error ----------------------------------------------------- +// ------------------------------------ busiest_traffic_error ----------------------------------------------------- function busiest_interface_error($panel, $user_id) { global $config; @@ -760,12 +748,13 @@ function busiest_interface_error($panel, $user_id) { $panel['data'] = __('Panel needs DS stats enabled.', 'intropage') . '
'; if ($console_access) { - $panel['data'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; + $panel['data'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; } else { - $panel['data'] .= __('Ask admin to enable DS stats', 'intropage') . ''; + $panel['data'] .= __('Ask admin to enable DS stats', 'intropage') . ''; } save_panel_result($panel, $user_id); + return true; } @@ -773,10 +762,10 @@ function busiest_interface_error($panel, $user_id) { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } $ds = db_fetch_row("SELECT id, name @@ -798,10 +787,10 @@ function busiest_interface_error($panel, $user_id) { LEFT JOIN host as h on h.id = dl.host_id WHERE h.disabled != 'on' $q_host_cond - AND dtd.data_template_id = " . $ds['id'] . " + AND dtd.data_template_id = " . $ds['id'] . ' AND dsh.average IS NOT NULL ORDER BY dsh.average DESC - LIMIT " . $lines; + LIMIT ' . $lines; $result = db_fetch_assoc("SELECT $columns $query"); @@ -816,7 +805,7 @@ function busiest_interface_error($panel, $user_id) { if (cacti_sizeof($result)) { $panel['data'] = '' . '' . - '' . + '' . '' . '' . ''; @@ -830,7 +819,7 @@ function busiest_interface_error($panel, $user_id) { ON gti.task_item_id = dtr.id WHERE dtr.local_data_id = ? LIMIT 1', - array($row['ldid'])); + [$row['ldid']]); $color = 'green'; @@ -840,7 +829,7 @@ function busiest_interface_error($panel, $user_id) { $color = 'yellow'; } - $panel['data'] .= ''; + $panel['data'] .= ''; $panel['data'] .= ''; $panel['data'] .= ''; @@ -851,11 +840,9 @@ function busiest_interface_error($panel, $user_id) { $panel['data'] .= ''; $panel['data'] .= '
' . $ds['name'] . '' . $ds['name'] . '' . __('Average', 'intropage') . '' . __('Peak', 'intropage') . '
' . html_escape($row['name']) . '' . human_readable($row['xvalue']) . '
' . __('Average of all allowed DS') . '' . human_readable($avg) . ' Err/Discard
'; - } else { $panel['data'] = __('Waiting for data or you don\'t have permission for any device with this template.', 'intropage'); } - } else { $panel['data'] = __('You don\'t have permissions to any hosts or there isn\'t any host with this template', 'intropage'); } @@ -863,8 +850,7 @@ function busiest_interface_error($panel, $user_id) { save_panel_result($panel, $user_id); } - -//------------------------------------ busiest_traffic_utilization ----------------------------------------------------- +// ------------------------------------ busiest_traffic_utilization ----------------------------------------------------- function busiest_interface_util($panel, $user_id) { global $config; @@ -880,12 +866,13 @@ function busiest_interface_util($panel, $user_id) { $panel['data'] = __('Panel needs DS stats enabled.', 'intropage') . '
'; if ($console_access) { - $panel['data'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; + $panel['data'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; } else { - $panel['data'] .= __('Ask admin to enable DS stats', 'intropage') . ''; + $panel['data'] .= __('Ask admin to enable DS stats', 'intropage') . ''; } save_panel_result($panel, $user_id); + return true; } @@ -893,10 +880,10 @@ function busiest_interface_util($panel, $user_id) { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } $ds = db_fetch_row("SELECT id,name @@ -904,7 +891,7 @@ function busiest_interface_util($panel, $user_id) { WHERE hash='6632e1e0b58a565c135d7ff90440c335'"); if (($allowed_devices !== false || $simple_perms) && cacti_sizeof($ds)) { - $perc = array(); + $perc = []; if (!$simple_perms) { $q_host_cond = 'AND dl.host_id ' . $host_cond; @@ -920,16 +907,15 @@ function busiest_interface_util($panel, $user_id) { LEFT JOIN host as h on h.id = dl.host_id WHERE h.disabled != 'on' $q_host_cond - AND dtd.data_template_id = " . $ds['id'] . " + AND dtd.data_template_id = " . $ds['id'] . ' AND value > 0 AND time > DATE_SUB(NOW(), INTERVAL 5 MINUTE) - ORDER BY value DESC"); + ORDER BY value DESC'); foreach ($result as $row) { + $speed = api_data_source_get_interface_speed($row) / 8; - $speed = api_data_source_get_interface_speed ($row)/8; - - $key = $row['local_data_id'] . '-' . $row['rrd_name']; + $key = $row['local_data_id'] . '-' . $row['rrd_name']; $perc[$key] = round(100 * $row['value'] / $speed, 2); } @@ -938,7 +924,7 @@ function busiest_interface_util($panel, $user_id) { $panel['data'] = '' . '' . - '' . + '' . '' . '' . ''; @@ -946,9 +932,9 @@ function busiest_interface_util($panel, $user_id) { $i = 0; foreach ($perc as $key=>$value) { - list($real_key,$direction) = explode ('-', $key); + [$real_key,$direction] = explode('-', $key); - $gdata = db_fetch_row_prepared ('SELECT DISTINCT(gti.local_graph_id) AS graph_id, name_cache + $gdata = db_fetch_row_prepared('SELECT DISTINCT(gti.local_graph_id) AS graph_id, name_cache FROM graph_templates_item AS gti LEFT JOIN data_template_rrd AS dtr ON gti.task_item_id = dtr.id @@ -956,7 +942,7 @@ function busiest_interface_util($panel, $user_id) { ON dtr.local_data_id = dtd.local_data_id WHERE dtd.local_data_id = ? LIMIT 1', - array($real_key)); + [$real_key]); $color = 'green'; @@ -966,10 +952,10 @@ function busiest_interface_util($panel, $user_id) { $color = 'yellow'; } - $panel['data'] .= ''; + $panel['data'] .= ''; $panel['data'] .= ''; - $panel['data'] .= ''; + $panel['data'] .= ''; $panel['data'] .= ''; $i++; @@ -981,11 +967,9 @@ function busiest_interface_util($panel, $user_id) { $panel['data'] .= ''; $panel['data'] .= '
' . $ds['name'] . '' . $ds['name'] . '' . __('Direction', 'intropage') . '%
'; $panel['data'] .= html_escape($gdata['name_cache']) . '' . ($direction == 'traffic_in' ? 'In':'Out') . '' . ($direction == 'traffic_in' ? 'In' : 'Out') . '' . $value . '
' . __('Time interval last 5 minutes') . '
'; - } else { $panel['data'] = __('Waiting for data or you don\'t have permission for any device with this template.', 'intropage'); } - } else { $panel['data'] = __('You don\'t have permissions to any hosts or there isn\'t any host with this template', 'intropage'); } @@ -993,16 +977,15 @@ function busiest_interface_util($panel, $user_id) { save_panel_result($panel, $user_id); } - -//------------------------------------ busiest_cpu_detail ----------------------------------------------------- +// ------------------------------------ busiest_cpu_detail ----------------------------------------------------- function busiest_cpu_detail() { global $config; - $panel = array( + $panel = [ 'name' => __('Busiest 30 Host MIB CPU utilization (last hour)', 'intropage'), 'alarm' => 'grey', 'detail' => '', - ); + ]; $console_access = get_console_access($_SESSION['sess_user_id']); @@ -1010,9 +993,9 @@ function busiest_cpu_detail() { $panel['detail'] = __('Panel needs DS stats enabled.', 'intropage') . '
'; if ($console_access) { - $panel['detail'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; + $panel['detail'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; } else { - $panel['detail'] .= __('Ask admin to enable DS stats', 'intropage') . ''; + $panel['detail'] .= __('Ask admin to enable DS stats', 'intropage') . ''; } return ($panel); @@ -1022,10 +1005,10 @@ function busiest_cpu_detail() { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } $ds = db_fetch_row("SELECT id, name @@ -1048,9 +1031,9 @@ function busiest_cpu_detail() { WHERE h.disabled != 'on' $q_host_cond AND dsh.average IS NOT NULL - AND dtd.data_template_id = " . $ds['id'] . " + AND dtd.data_template_id = " . $ds['id'] . ' ORDER BY dsh.average DESC - LIMIT 30"; + LIMIT 30'; $avg = db_fetch_cell('SELECT AVG(average)' . $query); $result = db_fetch_assoc("SELECT $columns $query"); @@ -1058,7 +1041,7 @@ function busiest_cpu_detail() { if (cacti_sizeof($result)) { $panel['detail'] = '' . '' . - '' . + '' . '' . '' . ''; @@ -1073,11 +1056,11 @@ function busiest_cpu_detail() { ON gti.task_item_id = dtr.id WHERE dtr.local_data_id = ? LIMIT 1', - array($row['ldid'])); + [$row['ldid']]); - $panel['detail'] .= ''; + $panel['detail'] .= ''; } else { - $panel['detail'] .= ''; + $panel['detail'] .= ''; } $color = 'green'; @@ -1097,11 +1080,9 @@ function busiest_cpu_detail() { $panel['detail'] .= ''; $panel['detail'] .= '
' . $ds['name'] . '' . $ds['name'] . '' . __('Average', 'intropage') . '' . __('Peak', 'intropage') . '
' . html_escape($row['name']) . '
' . html_escape($row['name']) . '
' . html_escape($row['name']) . '
' . html_escape($row['name']) . '
' . __('Average of all allowed DS') . '' . round($avg, 2) . ' %

'; $panel['detail'] .= __('Install TopX plugin for more DS statistics'); - } else { $panel['detail'] = __('Waiting for data or you don\'t have permission for any device with this template.', 'intropage'); } - } else { $panel['detail'] = __('You don\'t have permissions to any hosts or there isn\'t any host with this template', 'intropage'); } @@ -1109,16 +1090,15 @@ function busiest_cpu_detail() { return $panel; } - -//------------------------------------ busiest_load_detail ----------------------------------------------------- +// ------------------------------------ busiest_load_detail ----------------------------------------------------- function busiest_load_detail() { global $config; - $panel = array( + $panel = [ 'name' => __('Busiest 30 ucd/net Load (last hour)', 'intropage'), 'alarm' => 'grey', 'detail' => '', - ); + ]; $console_access = get_console_access($_SESSION['sess_user_id']); @@ -1126,9 +1106,9 @@ function busiest_load_detail() { $panel['detail'] = __('Panel needs DS stats enabled.', 'intropage') . '
'; if ($console_access) { - $panel['detail'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; + $panel['detail'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; } else { - $panel['detail'] .= __('Ask admin to enable DS stats', 'intropage') . ''; + $panel['detail'] .= __('Ask admin to enable DS stats', 'intropage') . ''; } return ($panel); @@ -1138,10 +1118,10 @@ function busiest_load_detail() { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } $ds = db_fetch_row("SELECT id,name @@ -1164,9 +1144,9 @@ function busiest_load_detail() { WHERE h.disabled != 'on' $q_host_cond AND dsh.average IS NOT NULL - AND dtd.data_template_id = " . $ds['id'] . " + AND dtd.data_template_id = " . $ds['id'] . ' ORDER BY dsh.average DESC - LIMIT 30"; + LIMIT 30'; $avg = db_fetch_cell('SELECT AVG(average)' . $query); $result = db_fetch_assoc("SELECT $columns $query"); @@ -1174,7 +1154,7 @@ function busiest_load_detail() { if (cacti_sizeof($result)) { $panel['detail'] = '' . '' . - '' . + '' . '' . '' . ''; @@ -1189,11 +1169,11 @@ function busiest_load_detail() { ON gti.task_item_id = dtr.id WHERE dtr.local_data_id = ? LIMIT 1', - array($row['ldid'])); + [$row['ldid']]); - $panel['detail'] .= ''; + $panel['detail'] .= ''; } else { - $panel['detail'] .= ''; + $panel['detail'] .= ''; } $color = 'green'; @@ -1213,11 +1193,9 @@ function busiest_load_detail() { $panel['detail'] .= ''; $panel['detail'] .= '
' . $ds['name'] . '' . $ds['name'] . '' . __('Average', 'intropage') . '' . __('Peak', 'intropage') . '
' . html_escape($row['name']) . '
' . html_escape($row['name']) . '
' . html_escape($row['name']) . '
' . html_escape($row['name']) . '
' . __('Average of all allowed DS') . '' . round($avg, 2) . '

'; $panel['detail'] .= __('Install TopX plugin for more DS statistics'); - } else { $panel['detail'] = __('Waiting for data or you don\'t have permission for any device with this template.', 'intropage'); } - } else { $panel['detail'] = __('You don\'t have permissions to any hosts or there isn\'t any host with this template', 'intropage'); } @@ -1225,17 +1203,15 @@ function busiest_load_detail() { return $panel; } - - -//------------------------------------ busiest hdd detail ----------------------------------------------------- +// ------------------------------------ busiest hdd detail ----------------------------------------------------- function busiest_hdd_detail() { global $config; - $panel = array( + $panel = [ 'name' => __('Busiest 30 Host MIB Hard Drive space (last hour)', 'intropage'), 'alarm' => 'grey', 'detail' => '', - ); + ]; $console_access = get_console_access($_SESSION['sess_user_id']); @@ -1243,9 +1219,9 @@ function busiest_hdd_detail() { $panel['detail'] = __('Panel needs DS stats enabled.', 'intropage') . '
'; if ($console_access) { - $panel['detail'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; + $panel['detail'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; } else { - $panel['detail'] .= __('Ask admin to enable DS stats', 'intropage') . ''; + $panel['detail'] .= __('Ask admin to enable DS stats', 'intropage') . ''; } return ($panel); @@ -1255,10 +1231,10 @@ function busiest_hdd_detail() { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } $ds = db_fetch_row("SELECT id,name @@ -1283,9 +1259,9 @@ function busiest_hdd_detail() { WHERE h.disabled != 'on' $q_host_cond AND dsh.rrd_name = 'hdd_used' - AND dtd.data_template_id = " . $ds['id'] . " + AND dtd.data_template_id = " . $ds['id'] . ' ORDER BY xvalue DESC - LIMIT 30"; + LIMIT 30'; $result = db_fetch_assoc("SELECT $columns $query"); @@ -1301,21 +1277,21 @@ function busiest_hdd_detail() { $q_host_cond AND dtd.data_template_id = " . $ds['id']; - $xavg = db_fetch_assoc ('SELECT ' . $columns . ' ' . $query); - $avg = 0; + $xavg = db_fetch_assoc('SELECT ' . $columns . ' ' . $query); + $avg = 0; if ($xavg) { foreach ($xavg as $row) { - $avg+=$row['xvalue']; + $avg += $row['xvalue']; } - $avg = $avg/count($xavg); + $avg = $avg / count($xavg); } if (cacti_sizeof($result)) { $panel['detail'] = '' . '' . - '' . + '' . '' . '' . ''; @@ -1330,11 +1306,11 @@ function busiest_hdd_detail() { ON gti.task_item_id = dtr.id WHERE dtr.local_data_id = ? LIMIT 1', - array($row['ldid'])); + [$row['ldid']]); - $panel['detail'] .= ''; + $panel['detail'] .= ''; } else { - $panel['detail'] .= ''; + $panel['detail'] .= ''; } $color = 'green'; @@ -1354,11 +1330,9 @@ function busiest_hdd_detail() { $panel['detail'] .= ''; $panel['detail'] .= '
' . $ds['name'] . '' . $ds['name'] . '' . __('Average', 'intropage') . '' . __('Peak', 'intropage') . '
' . html_escape($row['name']) . '
' . html_escape($row['name']) . '
' . html_escape($row['name']) . '
' . html_escape($row['name']) . '
' . __('Average of all allowed DS') . '' . round($avg, 2) . ' %

'; $panel['detail'] .= __('Install TopX plugin for more DS statistics'); - } else { $panel['detail'] = __('Waiting for data or you don\'t have permission for any device with this template.', 'intropage'); } - } else { $panel['detail'] = __('You don\'t have permissions to any hosts or there isn\'t any host with this template', 'intropage'); } @@ -1366,16 +1340,15 @@ function busiest_hdd_detail() { return $panel; } - -//------------------------------------ busiest uptime detail ----------------------------------------------------- +// ------------------------------------ busiest uptime detail ----------------------------------------------------- function busiest_uptime_detail() { global $config; - $panel = array( + $panel = [ 'name' => __('Busiest uptime', 'intropage'), 'alarm' => 'grey', 'detail' => '', - ); + ]; $console_access = get_console_access($_SESSION['sess_user_id']); @@ -1383,14 +1356,14 @@ function busiest_uptime_detail() { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if ($allowed_devices !== false || $simple_perms) { - $columns = " id, description, snmp_sysUpTimeInstance"; + $columns = ' id, description, snmp_sysUpTimeInstance'; if (!$simple_perms) { $q_host_cond = 'AND id ' . $host_cond; @@ -1403,13 +1376,13 @@ function busiest_uptime_detail() { ORDER BY snmp_sysUpTimeInstance DESC LIMIT 30"; - $avg = db_fetch_cell('SELECT AVG(snmp_sysUpTimeInstance)' . $query); + $avg = db_fetch_cell('SELECT AVG(snmp_sysUpTimeInstance)' . $query); $result = db_fetch_assoc("SELECT $columns $query"); if (cacti_sizeof($result)) { $panel['detail'] = '' . '' . - '' . + '' . '' . ''; @@ -1417,23 +1390,21 @@ function busiest_uptime_detail() { foreach ($result as $row) { if ($console_access) { - $panel['detail'] .= ''; + $panel['detail'] .= ''; } else { - $panel['detail'] .= ''; + $panel['detail'] .= ''; } - $panel['detail'] .= "'; + $panel['detail'] .= "'; $i++; } - $panel['detail'] .= ''; + $panel['detail'] .= ''; $panel['detail'] .= '
' . __('Host', 'intropage') . '' . __('Host', 'intropage') . '' . __('Uptime', 'intropage') . '
' . html_escape($row['description']) . '
' . html_escape($row['description']) . '
' . html_escape($row['description']) . '
' . html_escape($row['description']) . '" . get_daysfromtime($row['snmp_sysUpTimeInstance']/100) . '
" . get_daysfromtime($row['snmp_sysUpTimeInstance'] / 100) . '
' . __('Average of all allowed hosts') . '' . get_daysfromtime($avg/100) . '
' . __('Average of all allowed hosts') . '' . get_daysfromtime($avg / 100) . '
'; - } else { $panel['detail'] = __('Waiting for data or you don\'t have permission for any device', 'intropage'); } - } else { $panel['detail'] = __('You don\'t have permissions to any hosts', 'intropage'); } @@ -1441,16 +1412,15 @@ function busiest_uptime_detail() { return ($panel); } - -//------------------------------------ busiest_traffic_detail ----------------------------------------------------- +// ------------------------------------ busiest_traffic_detail ----------------------------------------------------- function busiest_traffic_detail() { global $config; - $panel = array( + $panel = [ 'name' => __('Busiest traffic (in+out)', 'intropage'), 'alarm' => 'grey', 'detail' => '', - ); + ]; $console_access = get_console_access($_SESSION['sess_user_id']); @@ -1458,9 +1428,9 @@ function busiest_traffic_detail() { $panel['detail'] = __('Panel needs DS stats enabled.', 'intropage') . '
'; if ($console_access) { - $panel['detail'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; + $panel['detail'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; } else { - $panel['detail'] .= __('Ask admin to enable DS stats', 'intropage') . ''; + $panel['detail'] .= __('Ask admin to enable DS stats', 'intropage') . ''; } return ($panel); @@ -1472,10 +1442,10 @@ function busiest_traffic_detail() { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } $ds = db_fetch_row("SELECT id, name @@ -1515,21 +1485,21 @@ function busiest_traffic_detail() { WHERE dtd.data_template_id = ' . $ds['id'] . ' AND rrd_name = \'traffic_out\' '; - $xavg = db_fetch_assoc ('SELECT ' . $columns . ' ' . $query); - $avg = 0; + $xavg = db_fetch_assoc('SELECT ' . $columns . ' ' . $query); + $avg = 0; if ($xavg) { foreach ($xavg as $row) { - $avg+=$row['xvalue']; + $avg += $row['xvalue']; } - $avg = $avg/count($xavg); + $avg = $avg / count($xavg); } if (cacti_sizeof($result)) { $panel['detail'] = '' . '' . - '' . + '' . '' . '' . ''; @@ -1544,11 +1514,11 @@ function busiest_traffic_detail() { ON gti.task_item_id = dtr.id WHERE dtr.local_data_id = ? LIMIT 1', - array($row['ldid'])); + [$row['ldid']]); - $panel['detail'] .= ''; + $panel['detail'] .= ''; } else { - $panel['detail'] .= ''; + $panel['detail'] .= ''; } if ($intropage_mb == 'b') { @@ -1571,11 +1541,9 @@ function busiest_traffic_detail() { $panel['detail'] .= ''; $panel['detail'] .= '
' . $ds['name'] . '' . $ds['name'] . '' . __('Average', 'intropage') . '' . __('Peak', 'intropage') . '
' . html_escape($row['name']) . '
' . html_escape($row['name']) . '
' . html_escape($row['name']) . '
' . html_escape($row['name']) . '
' . __('Average of all allowed DS') . '' . human_readable($avg, false) . $units . '
'; - } else { $panel['detail'] = __('Waiting for data or you don\'t have permission for any device with this template.', 'intropage'); } - } else { $panel['detail'] = __('You don\'t have permissions to any hosts or there isn\'t any host with this template', 'intropage'); } @@ -1583,16 +1551,15 @@ function busiest_traffic_detail() { return ($panel); } - -//------------------------------------ busiest_traffic_error_detail ----------------------------------------------------- +// ------------------------------------ busiest_traffic_error_detail ----------------------------------------------------- function busiest_interface_error_detail() { global $config; - $panel = array( + $panel = [ 'name' => __('Busiest traffic (in+out)', 'intropage'), 'alarm' => 'grey', 'detail' => '', - ); + ]; $console_access = get_console_access($_SESSION['sess_user_id']); @@ -1600,9 +1567,9 @@ function busiest_interface_error_detail() { $panel['detail'] = __('Panel needs DS stats enabled.', 'intropage') . '
'; if ($console_access) { - $panel['detail'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; + $panel['detail'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; } else { - $panel['detail'] .= __('Ask admin to enable DS stats', 'intropage') . ''; + $panel['detail'] .= __('Ask admin to enable DS stats', 'intropage') . ''; } return ($panel); @@ -1612,10 +1579,10 @@ function busiest_interface_error_detail() { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } $ds = db_fetch_row("SELECT id, name @@ -1637,10 +1604,10 @@ function busiest_interface_error_detail() { LEFT JOIN host as h on h.id = dl.host_id WHERE h.disabled != 'on' $q_host_cond - AND dtd.data_template_id = " . $ds['id'] . " + AND dtd.data_template_id = " . $ds['id'] . ' AND dsh.average IS NOT NULL ORDER BY dsh.average DESC - LIMIT 30"; + LIMIT 30'; $result = db_fetch_assoc("SELECT $columns $query"); @@ -1655,7 +1622,7 @@ function busiest_interface_error_detail() { if (cacti_sizeof($result)) { $panel['detail'] = '' . '' . - '' . + '' . '' . '' . ''; @@ -1670,11 +1637,11 @@ function busiest_interface_error_detail() { ON gti.task_item_id = dtr.id WHERE dtr.local_data_id = ? LIMIT 1', - array($row['ldid'])); + [$row['ldid']]); - $panel['detail'] .= ''; + $panel['detail'] .= ''; } else { - $panel['detail'] .= ''; + $panel['detail'] .= ''; } $color = 'green'; @@ -1693,11 +1660,9 @@ function busiest_interface_error_detail() { $panel['detail'] .= ''; $panel['detail'] .= '
' . $ds['name'] . '' . $ds['name'] . '' . __('Average', 'intropage') . '' . __('Peak', 'intropage') . '
' . html_escape($row['name']) . '
' . html_escape($row['name']) . '
' . html_escape($row['name']) . '
' . html_escape($row['name']) . '
' . __('Average of all allowed DS') . '' . human_readable($avg) . ' Err/Discard
'; - } else { $panel['detail'] = __('Waiting for data or you don\'t have permission for any device with this template.', 'intropage'); } - } else { $panel['detail'] = __('You don\'t have permissions to any hosts or there isn\'t any host with this template', 'intropage'); } @@ -1705,15 +1670,15 @@ function busiest_interface_error_detail() { return ($panel); } -//------------------------------------ busiest_traffic_utilization_detail----------------------------------------------- +// ------------------------------------ busiest_traffic_utilization_detail----------------------------------------------- function busiest_interface_util_detail() { global $config; - $panel = array( + $panel = [ 'name' => __('Busiest interface utilization', 'intropage'), 'alarm' => 'grey', 'detail' => '', - ); + ]; include_once($config['base_path'] . '/lib/api_data_source.php'); @@ -1723,9 +1688,9 @@ function busiest_interface_util_detail() { $panel['detail'] = __('Panel needs DS stats enabled.', 'intropage') . '
'; if ($console_access) { - $panel['detail'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; + $panel['detail'] .= '' . __('Please enable and configure DS stats', 'intropage') . ''; } else { - $panel['detail'] .= __('Ask admin to enable DS stats', 'intropage') . ''; + $panel['detail'] .= __('Ask admin to enable DS stats', 'intropage') . ''; } return ($panel); @@ -1735,10 +1700,10 @@ function busiest_interface_util_detail() { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } $ds = db_fetch_row("SELECT id,name @@ -1746,7 +1711,7 @@ function busiest_interface_util_detail() { WHERE hash='6632e1e0b58a565c135d7ff90440c335'"); if (($allowed_devices !== false || $simple_perms) && cacti_sizeof($ds)) { - $perc = array(); + $perc = []; if (!$simple_perms) { $q_host_cond = 'AND dl.host_id ' . $host_cond; @@ -1762,15 +1727,15 @@ function busiest_interface_util_detail() { LEFT JOIN host as h on h.id = dl.host_id WHERE h.disabled != 'on' $q_host_cond - AND dtd.data_template_id = " . $ds['id'] . " + AND dtd.data_template_id = " . $ds['id'] . ' AND value > 0 AND time > date_sub(now(), INTERVAL 5 MINUTE) - ORDER BY value DESC"); + ORDER BY value DESC'); foreach ($result as $row) { - $speed = api_data_source_get_interface_speed ($row)/8; + $speed = api_data_source_get_interface_speed($row) / 8; - $key = $row['local_data_id'] . '-' . $row['rrd_name']; + $key = $row['local_data_id'] . '-' . $row['rrd_name']; $perc[$key] = round(100 * $row['value'] / $speed,2); } @@ -1779,7 +1744,7 @@ function busiest_interface_util_detail() { $panel['detail'] = '' . '' . - '' . + '' . '' . '' . ''; @@ -1787,7 +1752,7 @@ function busiest_interface_util_detail() { $i = 0; foreach ($perc as $key => $value) { - list($real_key,$direction) = explode ('-', $key); + [$real_key,$direction] = explode('-', $key); $gdata = db_fetch_row_prepared('SELECT DISTINCT(gti.local_graph_id) AS graph_id, name_cache FROM graph_templates_item AS gti @@ -1797,7 +1762,7 @@ function busiest_interface_util_detail() { ON dtr.local_data_id = dtd.local_data_id WHERE dtd.local_data_id = ? LIMIT 1', - array($real_key)); + [$real_key]); $color = 'green'; @@ -1807,9 +1772,9 @@ function busiest_interface_util_detail() { $color = 'yellow'; } - $panel['detail'] .= ''; - $panel['detail'] .= ''; + $panel['detail'] .= ''; $panel['detail'] .= ''; $i++; @@ -1821,14 +1786,12 @@ function busiest_interface_util_detail() { $panel['detail'] .= ''; $panel['detail'] .= '
' . $ds['name'] . '' . $ds['name'] . '' . __('Direction', 'intropage') . '%
'; + $panel['detail'] .= '
'; $panel['detail'] .= html_escape($gdata['name_cache']) . '' . ($direction == 'traffic_in' ? 'In':'Out') . '' . ($direction == 'traffic_in' ? 'In' : 'Out') . '' . $value . '
' . __('Time interval last 5 minutes', 'intropage') . '
'; - } else { $panel['detail'] = __('Waiting for data or you don\'t have permission for any device with this template.', 'intropage'); } - } else { $panel['detail'] = __('You don\'t have permissions to any hosts or there isn\'t any host with this template', 'intropage'); } - return($panel); + return ($panel); } diff --git a/panellib/graphs.php b/panellib/graphs.php index 20d7281..cb868fa 100644 --- a/panellib/graphs.php +++ b/panellib/graphs.php @@ -27,13 +27,13 @@ function register_graphs() { global $registry; - $registry['graphs'] = array( + $registry['graphs'] = [ 'name' => __('Graphical Panels', 'intropage'), 'description' => __('Panels that provide information about Cacti and it\'s plugins in a Graphical way.', 'intropage') - ); + ]; - $panels = array( - 'graph_data_source' => array( + $panels = [ + 'graph_data_source' => [ 'name' => __('Data Sources', 'intropage'), 'description' => __('Graph of Data Sources', 'intropage'), 'class' => 'graphs', @@ -50,8 +50,8 @@ function register_graphs() { 'update_func' => 'graph_data_source', 'details_func' => 'graph_data_source_detail', 'trends_func' => false - ), - 'graph_host_template' => array( + ], + 'graph_host_template' => [ 'name' => __('Device Templates', 'intropage'), 'description' => __('Graph of Device Templates', 'intropage'), 'class' => 'graphs', @@ -68,8 +68,8 @@ function register_graphs() { 'update_func' => 'graph_host_template', 'details_func' => 'graph_host_template_detail', 'trends_func' => false - ), - 'graph_host' => array( + ], + 'graph_host' => [ 'name' => __('Devices by Status', 'intropage'), 'description' => __('Graph of Devices by Status (up,down,...)', 'intropage'), 'class' => 'graphs', @@ -86,8 +86,8 @@ function register_graphs() { 'update_func' => 'graph_host', 'details_func' => 'graph_host_detail', 'trends_func' => 'host_collect' - ), - ); + ], + ]; return $panels; } @@ -100,20 +100,20 @@ function graph_data_source($panel, $user_id) { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if ($allowed_devices !== false || $simple_perms) { - $graph = array ( - 'pie' => array( + $graph = [ + 'pie' => [ 'title' => __('Datasources: ', 'intropage'), - 'label' => array(), - 'data' => array(), - ), - ); + 'label' => [], + 'data' => [], + ], + ]; if (!$simple_perms) { $q_host_cond = 'AND data_local.host_id ' . $host_cond; @@ -161,10 +161,10 @@ function graph_host_template($panel, $user_id) { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (defined('CACTI_VERSION')) { @@ -174,20 +174,19 @@ function graph_host_template($panel, $user_id) { } if ($allowed_devices !== false || $simple_perms) { - if (!$simple_perms) { $q_host_cond = 'WHERE host.id ' . $host_cond; } // 1.2.24+ has billboard.js with treemap if (cacti_version_compare($cv, '1.2.24', '>=')) { - $graph = array( - 'treemap' => array( + $graph = [ + 'treemap' => [ 'title' => __('Device Templates: ', 'intropage'), - 'label' => array(), - 'data' => array(), - ), - ); + 'label' => [], + 'data' => [], + ], + ]; $sql_ht = db_fetch_assoc("SELECT host_template.id as id, name, COUNT(host.host_template_id) AS total @@ -204,17 +203,15 @@ function graph_host_template($panel, $user_id) { array_push($graph['treemap']['label'], substr($item['name'],0,20)); array_push($graph['treemap']['data'], $item['total']); } - } } else { - - $graph = array( - 'pie' => array( + $graph = [ + 'pie' => [ 'title' => __('Device Templates: ', 'intropage'), - 'label' => array(), - 'data' => array(), - ), - ); + 'label' => [], + 'data' => [], + ], + ]; $sql_ht = db_fetch_assoc("SELECT host_template.id as id, name, COUNT(host.host_template_id) AS total @@ -237,8 +234,6 @@ function graph_host_template($panel, $user_id) { $panel['data'] = intropage_prepare_graph($graph, $user_id); unset($graph); - - } else { $panel['data'] = __('You don\'t have permissions to any hosts', 'intropage'); } @@ -246,7 +241,7 @@ function graph_host_template($panel, $user_id) { save_panel_result($panel, $user_id); } -//--------------------------------------- graph host----------------------------- +// --------------------------------------- graph host----------------------------- function graph_host($panel, $user_id, $timespan = 0) { global $config; @@ -256,27 +251,27 @@ function graph_host($panel, $user_id, $timespan = 0) { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if ($allowed_devices !== false || $simple_perms) { - $graph = array ( - 'line' => array( + $graph = [ + 'line' => [ 'title' => __('Devices: ', 'intropage'), - 'label1' => array(), - 'data1' => array(), - 'label2' => array(), - 'data2' => array(), - 'label3' => array(), - 'data3' => array(), - ), - ); + 'label1' => [], + 'data1' => [], + 'label2' => [], + 'data2' => [], + 'label3' => [], + 'data3' => [], + ], + ]; if ($timespan == 0) { - if (isset($_SESSION['sess_user_id'])) { + if (isset($_SESSION['sess_user_id'])) { $timespan = read_user_setting('intropage_timespan', read_config_option('intropage_timespan'), $_SESSION['sess_user_id']); } else { $timespan = $panel['refresh']; @@ -287,7 +282,7 @@ function graph_host($panel, $user_id, $timespan = 0) { $refresh = db_fetch_cell_prepared('SELECT refresh_interval FROM plugin_intropage_panel_data WHERE id = ?', - array($panel['id'])); + [$panel['id']]); } else { $refresh = $panel['refresh']; } @@ -298,27 +293,24 @@ function graph_host($panel, $user_id, $timespan = 0) { AND name = 'host_down' AND user_id = $user_id ORDER BY cur_timestamp ASC", - array($timespan)); + [$timespan]); if (cacti_sizeof($rows)) { - - $graph['line']['title1'] = __('Down', 'intropage'); + $graph['line']['title1'] = __('Down', 'intropage'); $graph['line']['unit1']['title'] = 'Down'; foreach ($rows as $row) { - $graph['line']['label1'][] = $row['date']; $graph['line']['data1'][] = $row['value']; - $last = $row['value']; + $last = $row['value']; } if ($last > 0) { $panel['alarm'] = 'red'; } - } else { - unset($graph['line']['label1']); - unset($graph['line']['data1']); + unset($graph['line']['label1']); + unset($graph['line']['data1']); } $rows = db_fetch_assoc_prepared("SELECT cur_timestamp AS `date`, value @@ -327,23 +319,21 @@ function graph_host($panel, $user_id, $timespan = 0) { AND name = 'host_reco' AND user_id = $user_id ORDER BY cur_timestamp ASC", - array($timespan)); + [$timespan]); if (cacti_sizeof($rows)) { - - $graph['line']['title2'] = __('Recovering', 'intropage'); + $graph['line']['title2'] = __('Recovering', 'intropage'); $graph['line']['unit2']['title'] = 'Recovering'; foreach ($rows as $row) { $graph['line']['label2'][] = $row['date']; $graph['line']['data2'][] = $row['value']; - $last = $row['value']; + $last = $row['value']; } if ($last > 0 && $panel['alarm'] == 'green') { $panel['alarm'] = 'yellow'; } - } else { unset($graph['line']['label2']); unset($graph['line']['data2']); @@ -355,10 +345,10 @@ function graph_host($panel, $user_id, $timespan = 0) { AND name = 'host_disa' AND user_id = $user_id ORDER BY cur_timestamp ASC", - array($timespan)); + [$timespan]); if (cacti_sizeof($rows)) { - $graph['line']['title3'] = __('Disabled', 'intropage'); + $graph['line']['title3'] = __('Disabled', 'intropage'); $graph['line']['unit3']['title'] = 'Disabled'; foreach ($rows as $row) { @@ -383,25 +373,24 @@ function graph_host($panel, $user_id, $timespan = 0) { save_panel_result($panel, $user_id); } - -//------------------------------------ graph_datasource ----------------------------------------------------- +// ------------------------------------ graph_datasource ----------------------------------------------------- function graph_data_source_detail() { global $config, $input_types; - $panel = array( + $panel = [ 'name' => __('Data Sources', 'intropage'), 'alarm' => 'green', 'detail' => '' - ); + ]; $simple_perms = get_simple_device_perms($_SESSION['sess_user_id']); if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -426,14 +415,15 @@ function graph_data_source_detail() { if (cacti_sizeof($sql_ds)) { $panel['detail'] .= ' - ' . __('Data Type', 'intropage') . ' - ' . __('Data Sources') . ' + ' . __('Data Type', 'intropage') . ' + ' . __('Data Sources') . ' '; $i = 0; + foreach ($sql_ds as $item) { if (!is_null($item['type_id'])) { - $class = ($i % 2 == 0 ? 'odd':'even'); + $class = ($i % 2 == 0 ? 'odd' : 'even'); $panel['detail'] .= '' . preg_replace('/script server/', 'SS', $input_types[$item['type_id']]) . ''; $panel['detail'] .= '' . number_format_i18n($item['total'], -1) . ''; @@ -442,7 +432,7 @@ function graph_data_source_detail() { } } - $class = ($i % 2 == 0 ? 'odd':'even'); + $class = ($i % 2 == 0 ? 'odd' : 'even'); $panel['detail'] .= '' . __('Total', 'intropage') . '' . number_format_i18n($total, -1) . ''; @@ -454,24 +444,24 @@ function graph_data_source_detail() { return $panel; } -//------------------------------------ graph_host ----------------------------------------------------- +// ------------------------------------ graph_host ----------------------------------------------------- function graph_host_detail() { global $config, $console_access; - $panel = array( + $panel = [ 'name' => __('Devices', 'intropage'), 'alarm' => 'green', 'detail' => '', - ); + ]; $simple_perms = get_simple_device_perms($_SESSION['sess_user_id']); if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -508,40 +498,40 @@ function graph_host_detail() { $panel['detail'] = ''; $panel['detail'] .= ''; - $status = array( - array( + $status = [ + [ 'class' => 'odd', 'status' => '-1', 'text' => __esc('All', 'intropage'), 'value' => $h_all - ), - array( + ], + [ 'class' => 'even', 'status' => '3', 'text' => __esc('Up', 'intropage'), 'value' => $h_up - ), - array( + ], + [ 'class' => 'odd', 'status' => '1', 'text' => __esc('Down', 'intropage'), 'value' => $h_down - ), - array( + ], + [ 'class' => 'even', 'status' => '2', 'text' => __esc('Recovering', 'intropage'), 'value' => $h_reco - ), - array( + ], + [ 'class' => 'even', 'status' => '-2', 'text' => __esc('Disabled', 'intropage'), 'value' => $h_disa - ) - ); + ] + ]; - foreach($status as $s) { + foreach ($status as $s) { if (api_plugin_user_realm_auth('host.php')) { $panel['detail'] .= ''; $panel['detail'] .= ''; + $panel['data'] .= ''; } elseif (!filter_var(trim($ntp_server), FILTER_VALIDATE_IP) && !filter_var(trim($ntp_server), FILTER_VALIDATE_DOMAIN)) { $panel['alarm'] = 'red'; - $panel['data'] .= ''; + $panel['data'] .= ''; } else { $i = 0; while (true) { $timestamp = ntp_time($ntp_server); + if (is_numeric($timestamp)) { break; } else { @@ -139,6 +140,7 @@ function ntp_dns($panel, $user_id) { if ($i > 2) { $timestamp = 'error'; + break; } } @@ -165,36 +167,36 @@ function ntp_dns($panel, $user_id) { } } else { $panel['alarm'] = 'red'; - $panel['data'] .= ''; - $panel['data'] .= ''; + $panel['data'] .= ''; + $panel['data'] .= ''; - $panel['data'] .= ''; - $panel['data'] .= ''; + $panel['data'] .= ''; + $panel['data'] .= ''; } } - $panel['data'] .= ''; + $panel['data'] .= ''; if (empty($dns_host)) { $panel['alarm'] = 'grey'; - $panel['data'] .= ''; + $panel['data'] .= ''; } elseif (!filter_var(trim($dns_host), FILTER_VALIDATE_DOMAIN)) { $panel['alarm'] = 'red'; - $panel['data'] .= ''; + $panel['data'] .= ''; } else { $start = microtime(true); $dns_response = cacti_gethostinfo($dns_host, DNS_A | DNS_CNAME | DNS_AAAA); - $total_time = 1000*(microtime(true) - $start); + $total_time = 1000 * (microtime(true) - $start); if ($dns_response) { $panel['data'] .= ''; $panel['data'] .= ''; } else { $panel['alarm'] = 'red'; - $panel['data'] .= ''; - $panel['data'] .= ''; + $panel['data'] .= ''; + $panel['data'] .= ''; } } @@ -203,25 +205,24 @@ function ntp_dns($panel, $user_id) { save_panel_result($panel, $user_id); } -//---------------------------maint plugin-------------------- +// ---------------------------maint plugin-------------------- function maint($panel, $user_id) { global $config; $panel['alarm'] = 'green'; - $panel['data'] = ''; + $panel['data'] = ''; $maint_days_before = read_config_option('intropage_maint_plugin_days_before'); if (api_plugin_is_enabled('maint') && $maint_days_before >= 0) { - $simple_perms = get_simple_device_perms($user_id); if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -238,67 +239,66 @@ function maint($panel, $user_id) { $t = time(); switch ($sc['mtype']) { - case 1: - if ($t > ($sc['stime'] - $maint_days_before) && $t < $sc['etime']) { - $hosts = db_fetch_assoc_prepared("SELECT description FROM host + case 1: + if ($t > ($sc['stime'] - $maint_days_before) && $t < $sc['etime']) { + $hosts = db_fetch_assoc_prepared("SELECT description FROM host INNER JOIN plugin_maint_hosts ON host.id=plugin_maint_hosts.host WHERE schedule = ? $q_host_cond", - array($sc['id'])); - - if (cacti_sizeof($hosts)) { - $panel['data'] .= '' . date('d. m . Y H:i', $sc['stime']) . - ' - ' . date('d. m . Y H:i', $sc['etime']) . - ' - ' . $sc['name'] . ' (One time)
'; + [$sc['id']]); - $text = 'Affected hosts:
' . implode (', ', array_column($hosts,'description')); + if (cacti_sizeof($hosts)) { + $panel['data'] .= '' . date('d. m . Y H:i', $sc['stime']) . + ' - ' . date('d. m . Y H:i', $sc['etime']) . + ' - ' . $sc['name'] . ' (One time)
'; - $panel['data'] .= '
' . $text . '


'; + $text = 'Affected hosts:
' . implode(', ', array_column($hosts,'description')); - } - } - - break; - case 2: - /* past, calculate next */ - if ($sc['etime'] < $t) { - /* convert start and end to local so that hour stays same for add days across daylight saving time change */ - $starttimelocal = (new DateTime('@' . strval($sc['stime'])))->setTimezone( new DateTimeZone( date_default_timezone_get())); - $endtimelocal = (new DateTime('@' . strval($sc['etime'])))->setTimezone( new DateTimeZone( date_default_timezone_get())); - $nowtime = new DateTime(); - /* add interval days */ - $addday = new DateInterval( 'P' . strval($sc['minterval'] / 86400) . 'D'); - while ($endtimelocal < $nowtime) { - $starttimelocal = $starttimelocal->add( $addday ); - $endtimelocal = $endtimelocal->add( $addday ); + $panel['data'] .= '
' . $text . '


'; + } } - $sc['stime'] = $starttimelocal->getTimestamp(); - $sc['etime'] = $endtimelocal->getTimestamp(); - } + break; + case 2: + // past, calculate next + if ($sc['etime'] < $t) { + // convert start and end to local so that hour stays same for add days across daylight saving time change + $starttimelocal = (new DateTime('@' . strval($sc['stime'])))->setTimezone(new DateTimeZone(date_default_timezone_get())); + $endtimelocal = (new DateTime('@' . strval($sc['etime'])))->setTimezone(new DateTimeZone(date_default_timezone_get())); + $nowtime = new DateTime(); + // add interval days + $addday = new DateInterval('P' . strval($sc['minterval'] / 86400) . 'D'); + + while ($endtimelocal < $nowtime) { + $starttimelocal = $starttimelocal->add($addday); + $endtimelocal = $endtimelocal->add($addday); + } + + $sc['stime'] = $starttimelocal->getTimestamp(); + $sc['etime'] = $endtimelocal->getTimestamp(); + } - if ($t > ($sc['stime'] - $maint_days_before) && $t < $sc['etime']) { - $hosts = db_fetch_assoc_prepared("SELECT description FROM host + if ($t > ($sc['stime'] - $maint_days_before) && $t < $sc['etime']) { + $hosts = db_fetch_assoc_prepared("SELECT description FROM host INNER JOIN plugin_maint_hosts ON host.id=plugin_maint_hosts.host WHERE schedule = ? $q_host_cond", - array($sc['id'])); + [$sc['id']]); - if (cacti_sizeof($hosts)) { - $panel['data'] .= '' . date('d. m . Y H:i', $sc['stime']) . - ' - ' . date('d. m . Y H:i', $sc['etime']) . - ' - ' . $sc['name'] . ' (Reoccurring)
'; + if (cacti_sizeof($hosts)) { + $panel['data'] .= '' . date('d. m . Y H:i', $sc['stime']) . + ' - ' . date('d. m . Y H:i', $sc['etime']) . + ' - ' . $sc['name'] . ' (Reoccurring)
'; - $text = 'Affected hosts:
' . implode (', ', array_column($hosts,'description')); + $text = 'Affected hosts:
' . implode(', ', array_column($hosts,'description')); - $panel['data'] .= '
' . $text . '


'; + $panel['data'] .= '
' . $text . '


'; + } } - } - - break; + break; } } } @@ -316,8 +316,9 @@ function webseer($panel, $user_id) { $panel['alarm'] = 'green'; - $lines = get_panel_lines_count($panel['height'], $user_id); + $lines = get_panel_lines_count($panel['height'], $user_id); $important_period = read_user_setting('intropage_important_period', read_config_option('intropage_important_period'), false, $user_id); + if ($important_period == -1) { $important_period = time(); } @@ -325,7 +326,7 @@ function webseer($panel, $user_id) { if (!api_plugin_is_enabled('webseer')) { $panel['alarm'] = 'yellow'; $panel['data'] = __('Plugin Webseer isn\'t installed or started', 'intropage'); - $panel['detail'] = FALSE; + $panel['detail'] = false; } else { $all = db_fetch_cell('SELECT COUNT(*) FROM plugin_webseer_urls'); $disa = db_fetch_cell("SELECT COUNT(*) FROM plugin_webseer_urls WHERE enabled != 'on'"); @@ -340,7 +341,7 @@ function webseer($panel, $user_id) { $panel['data'] .= __('Number of checks (all/disabled): ', 'intropage') . $all . ' / ' . $disa . '
'; $panel['data'] .= __('Status (up/down): ', 'intropage') . $ok . ' / ' . $ko . '

'; - $logs = db_fetch_assoc ('SELECT pwul.lastcheck, pwul.result, pwul.http_code, pwul.error, pwu.url, + $logs = db_fetch_assoc('SELECT pwul.lastcheck, pwul.result, pwul.http_code, pwul.error, pwu.url, UNIX_TIMESTAMP(pwul.lastcheck) AS secs FROM plugin_webseer_urls_log AS pwul INNER JOIN plugin_webseer_urls AS pwu @@ -350,7 +351,6 @@ function webseer($panel, $user_id) { LIMIT ' . ($lines - 4)); if (cacti_sizeof($logs) > 0) { - $panel['data'] .= '
' . __esc('Status', 'intropage') . '' . __esc('Device Count', 'intropage') . '
'; @@ -561,8 +551,8 @@ function graph_host_detail() { FROM host WHERE disabled = '' $q_host_cond - AND status = " . $s['status'] . " - "); + AND status = " . $s['status'] . ' + '); $panel['detail'] .= '
'; @@ -602,24 +592,24 @@ function graph_host_detail() { return $panel; } -//------------------------------------ graph host_template ----------------------------------------------------- +// ------------------------------------ graph host_template ----------------------------------------------------- function graph_host_template_detail() { global $config; - $panel = array( - 'name' => __('Device Templates', 'intropage'), - 'alarm' => 'green', + $panel = [ + 'name' => __('Device Templates', 'intropage'), + 'alarm' => 'green', 'detail' => '', - ); + ]; $simple_perms = get_simple_device_perms($_SESSION['sess_user_id']); if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -639,22 +629,23 @@ function graph_host_template_detail() { if (cacti_sizeof($rows)) { $panel['detail'] .= ' - + '; $i = 0; + foreach ($rows as $item) { - $class = ($i % 2 == 0 ? 'odd':'even'); + $class = ($i % 2 == 0 ? 'odd' : 'even'); $panel['detail'] .= ''; - $panel['detail'] .= ''; + $panel['detail'] .= ''; $total += $item['total']; $i++; } - $class = ($i % 2 == 0 ? 'odd':'even'); + $class = ($i % 2 == 0 ? 'odd' : 'even'); $panel['detail'] .= ' - + '; @@ -666,8 +657,7 @@ function graph_host_template_detail() { return $panel; } - -//------------------------------------ host collect ----------------------------------------------------- +// ------------------------------------ host collect ----------------------------------------------------- function host_collect() { global $config; @@ -675,15 +665,14 @@ function host_collect() { $users = get_user_list(); foreach ($users as $user) { - $simple_perms = get_simple_device_perms($user['id']); if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user['id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -691,7 +680,6 @@ function host_collect() { } if ($allowed_devices !== false || $simple_perms) { - db_execute_prepared("INSERT INTO plugin_intropage_trends (name,value,user_id) SELECT 'host_down', COUNT(*),? @@ -699,7 +687,7 @@ function host_collect() { WHERE status='1' $q_host_cond AND disabled=''", - array($user['id'])); + [$user['id']]); db_execute_prepared("INSERT INTO plugin_intropage_trends (name,value,user_id) @@ -708,7 +696,7 @@ function host_collect() { WHERE status='2' $q_host_cond AND disabled=''", - array($user['id'])); + [$user['id']]); db_execute_prepared("INSERT INTO plugin_intropage_trends (name,value,user_id) @@ -716,22 +704,22 @@ function host_collect() { FROM host WHERE disabled='on' $q_host_cond", - array($user['id'])); + [$user['id']]); } else { db_execute_prepared("INSERT INTO plugin_intropage_trends (name,value,user_id) VALUES ('host_down', 0, ?)", - array($user['id'])); + [$user['id']]); db_execute_prepared("INSERT INTO plugin_intropage_trends (name,value,user_id) VALUES ('host_reco', 0, ?)", - array($user['id'])); + [$user['id']]); db_execute_prepared("INSERT INTO plugin_intropage_trends (name,value,user_id) VALUES ('host_disa', 0, ?)", - array($user['id'])); + [$user['id']]); } } } diff --git a/panellib/index.php b/panellib/index.php index 4f8fcac..4298bd5 100644 --- a/panellib/index.php +++ b/panellib/index.php @@ -23,4 +23,3 @@ */ header('Location:../index.php'); - diff --git a/panellib/mactrack.php b/panellib/mactrack.php index 47a52b1..8e3369e 100644 --- a/panellib/mactrack.php +++ b/panellib/mactrack.php @@ -27,13 +27,13 @@ function register_mactrack() { global $registry; - $registry['mactrack'] = array( + $registry['mactrack'] = [ 'name' => __('MacTrack Panels', 'intropage'), 'description' => __('Panels that provide information about Cacti\'s MacTrack plugins.', 'intropage') - ); + ]; - $panels = array( - 'mactrack' => array( + $panels = [ + 'mactrack' => [ 'name' => __('MacTrack Plugin', 'intropage'), 'description' => __('Various MacTrack collection and site statistics.', 'intropage'), 'class' => 'mactrack', @@ -50,8 +50,8 @@ function register_mactrack() { 'update_func' => 'mactrack', 'details_func' => false, 'trends_func' => false - ), - 'mactrack_sites' => array( + ], + 'mactrack_sites' => [ 'name' => __('MacTrack Sites', 'intropage'), 'description' => __('Various MacTrack Site statistics.', 'intropage'), 'class' => 'mactrack', @@ -68,13 +68,13 @@ function register_mactrack() { 'update_func' => 'mactrack_sites', 'details_func' => 'mactrack_sites_detail', 'trends_func' => false - ), - ); + ], + ]; return $panels; } -//------------------------------------ mactrack ----------------------------------------------------- +// ------------------------------------ mactrack ----------------------------------------------------- function mactrack($panel, $user_id) { global $config; @@ -98,24 +98,24 @@ function mactrack($panel, $user_id) { $panel['alarm'] = 'yellow'; } - $panel['data'] = __('All: %s', $m_all, 'intropage') . ' | '; - $panel['data'] .= __('Up: %s', $m_up, 'intropage') . ' | '; - $panel['data'] .= __('Down: %s', $m_down, 'intropage') . ' | '; - $panel['data'] .= __('Error: %s', $m_err, 'intropage') . ' | '; - $panel['data'] .= __('Unknown: %s', $m_unkn, 'intropage') . ' | '; + $panel['data'] = __('All: %s', $m_all, 'intropage') . ' | '; + $panel['data'] .= __('Up: %s', $m_up, 'intropage') . ' | '; + $panel['data'] .= __('Down: %s', $m_down, 'intropage') . ' | '; + $panel['data'] .= __('Error: %s', $m_err, 'intropage') . ' | '; + $panel['data'] .= __('Unknown: %s', $m_unkn, 'intropage') . ' | '; $panel['data'] .= __('Disabled: %s', $m_disa, 'intropage') . ' | '; - $graph = array ('pie' => array( + $graph = ['pie' => [ 'title' => __('MacTrack', 'intropage'), - 'label' => array( + 'label' => [ __('Up', 'intropage'), __('Down', 'intropage'), __('Error', 'intropage'), __('Unknown', 'intropage'), __('Disabled', 'intropage'), - ), - 'data' => array($m_up, $m_down, $m_err, $m_unkn, $m_disa)) - ); + ], + 'data' => [$m_up, $m_down, $m_err, $m_unkn, $m_disa]] + ]; $panel['data'] = intropage_prepare_graph($graph, $user_id); } else { @@ -125,7 +125,7 @@ function mactrack($panel, $user_id) { save_panel_result($panel, $user_id); } -//------------------------------------ mactrack sites ----------------------------------------------------- +// ------------------------------------ mactrack sites ----------------------------------------------------- function mactrack_sites($panel, $user_id) { global $config; @@ -139,12 +139,12 @@ function mactrack_sites($panel, $user_id) { } elseif (api_plugin_user_realm_auth('mactrack_view_sites.php') || api_plugin_user_realm_auth('mactrack_devices.php')) { $panel['data'] = '
' . __('Template Name', 'intropage') . '' . __('Template Name', 'intropage') . ' ' . __('Total Devices', 'intropage') . '
' . html_escape($item['name']) . '' . number_format_i18n($item['total'], -1) . '
' . number_format_i18n($item['total'], -1) . '
' . __('Total', 'intropage') . '' . __('Total', 'intropage') . ' ' . number_format_i18n($total, -1) . '
' . '' . - '' . - '' . - '' . - '' . - '' . - '' . + '' . + '' . + '' . + '' . + '' . + '' . '' . ''; @@ -157,13 +157,13 @@ function mactrack_sites($panel, $user_id) { if (cacti_sizeof($data)) { foreach ($data as $site) { $row = '' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . ''; $panel['data'] .= $row; @@ -180,24 +180,24 @@ function mactrack_sites($panel, $user_id) { save_panel_result($panel, $user_id); } -//------------------------------------ mactrack sites ----------------------------------------------------- +// ------------------------------------ mactrack sites ----------------------------------------------------- function mactrack_sites_detail() { global $config, $console_access; - $panel = array( + $panel = [ 'name' => __('MacTrack Sites', 'intropage'), 'alarm' => 'green', 'detail' => '', - ); + ]; $panel['detail'] = '
' . __('Site', 'intropage') . '' . __('Devices', 'intropage') . '' . __('IPs', 'intropage') . '' . __('Ports', 'intropage') . '' . __('Ports up', 'intropage') . '' . __('MACs', 'intropage') . '' . __('Site', 'intropage') . '' . __('Devices', 'intropage') . '' . __('IPs', 'intropage') . '' . __('Ports', 'intropage') . '' . __('Ports up', 'intropage') . '' . __('MACs', 'intropage') . '' . __('Device Errors', 'intropage') . '
' . html_escape($site['site_name']) . '' . $site['total_devices'] . '' . $site['total_ips'] . '' . $site['total_user_ports'] . '' . $site['total_oper_ports'] . '' . $site['total_macs'] . '' . $site['total_device_errors'] . '' . html_escape($site['site_name']) . '' . $site['total_devices'] . '' . $site['total_ips'] . '' . $site['total_user_ports'] . '' . $site['total_oper_ports'] . '' . $site['total_macs'] . '' . $site['total_device_errors'] . '
' . '' . - ''; @@ -208,13 +208,13 @@ function mactrack_sites_detail() { if (cacti_sizeof($data)) { foreach ($data as $site) { $row = '' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . ''; if ($site['total_device_errors'] > 0) { @@ -226,7 +226,7 @@ function mactrack_sites_detail() { $panel['detail'] .= '
' . __('Site', 'intropage') . '' . - '' . __('Devices', 'intropage') . '' . - '' . __('IPs', 'intropage') . '' . - '' . __('Ports', 'intropage') . '' . - '' . __('Ports up', 'intropage') . '' . - '' . __('MACs', 'intropage') . '' . + '' . __('Site', 'intropage') . '' . + '' . __('Devices', 'intropage') . '' . + '' . __('IPs', 'intropage') . '' . + '' . __('Ports', 'intropage') . '' . + '' . __('Ports up', 'intropage') . '' . + '' . __('MACs', 'intropage') . '' . '' . __('Device Errors', 'intropage') . '' . '
' . html_escape($site['site_name']) . '' . $site['total_devices'] . '' . $site['total_ips'] . '' . $site['total_user_ports'] . '' . $site['total_oper_ports'] . '' . $site['total_macs'] . '' . $site['total_device_errors'] . '' . html_escape($site['site_name']) . '' . $site['total_devices'] . '' . $site['total_ips'] . '' . $site['total_user_ports'] . '' . $site['total_oper_ports'] . '' . $site['total_macs'] . '' . $site['total_device_errors'] . '
'; } else { - $panel['detail'] = __('No mactrack sites found', 'intropage'); + $panel['detail'] = __('No mactrack sites found', 'intropage'); } return $panel; diff --git a/panellib/misc.php b/panellib/misc.php index 64f7ba5..2e337af 100644 --- a/panellib/misc.php +++ b/panellib/misc.php @@ -27,13 +27,13 @@ function register_misc() { global $registry; - $registry['misc'] = array( + $registry['misc'] = [ 'name' => __('Miscellaneous Panels', 'intropage'), 'description' => __('Panels that general non-categorized data about Cacti\'s.', 'intropage') - ); + ]; - $panels = array( - 'ntp_dns' => array( + $panels = [ + 'ntp_dns' => [ 'name' => __('NTP/DNS Status', 'intropage'), 'description' => __('Checking your Cacti system clock for drift from a known baseline and DNS resolving check', 'intropage'), 'class' => 'misc', @@ -50,8 +50,8 @@ function register_misc() { 'update_func' => 'ntp_dns', 'details_func' => false, 'trends_func' => false - ), - 'maint' => array( + ], + 'maint' => [ 'name' => __('Maint Plugin Details', 'intropage'), 'description' => __('Maint Plugin details on upcoming schedules', 'intropage'), 'class' => 'misc', @@ -68,8 +68,8 @@ function register_misc() { 'update_func' => 'maint', 'details_func' => false, 'trends_func' => false - ), - 'webseer' => array( + ], + 'webseer' => [ 'name' => __('Webseer Details', 'intropage'), 'description' => __('Plugin webseer URL Service Check Details', 'intropage'), 'class' => 'misc', @@ -86,8 +86,8 @@ function register_misc() { 'update_func' => 'webseer', 'details_func' => 'webseer_detail', 'trends_func' => false - ), - 'servcheck' => array( + ], + 'servcheck' => [ 'name' => __('Servcheck plugin Details', 'intropage'), 'description' => __('Plugin ServCheck Details', 'intropage'), 'class' => 'misc', @@ -104,8 +104,8 @@ function register_misc() { 'update_func' => 'servcheck', 'details_func' => 'servcheck_detail', 'trends_func' => false - ), - ); + ], + ]; return $panels; } @@ -122,15 +122,16 @@ function ntp_dns($panel, $user_id) { if (empty($ntp_server)) { $panel['alarm'] = 'grey'; - $panel['data'] .= '
' . __('No NTP server configured', 'intropage') . '
' . __('No NTP server configured', 'intropage') . '
' . __('Wrong NTP server configured - %s
Please fix it in settings', $ntp_server, 'intropage') . '
' . __('Wrong NTP server configured - %s
Please fix it in settings', $ntp_server, 'intropage') . '
' . __('Unable to contact the NTP server indicated.', 'intropage') . '
' . 'Server: ' . $ntp_server . '
' . __('Unable to contact the NTP server indicated.', 'intropage') . '
' . 'Server: ' . $ntp_server . '
' . 'Timestamp: ' . $timestamp . '
' . __('Please check your configuration.', 'intropage') . '
' . 'Timestamp: ' . $timestamp . '
' . __('Please check your configuration.', 'intropage') . '




' . __('No DNS hostname configured', 'intropage') . '
' . __('No DNS hostname configured', 'intropage') . '
' . __('Wrong DNS hostname configured - %s
Please fix it in settings', $dns_host, 'intropage') . '
' . __('Wrong DNS hostname configured - %s
Please fix it in settings', $dns_host, 'intropage') . '
' . __('DNS hostname (%s) resolving ok.', $dns_host, 'intropage') . '
' . __('DNS resolv time: %s ms', round($total_time,2), 'intropage') . '
' . __('DNS hostname (%s) resolving failed.', $dns_host, 'intropage') . '
' . __('Please check your configuration.', 'intropage') . '
' . __('DNS hostname (%s) resolving failed.', $dns_host, 'intropage') . '
' . __('Please check your configuration.', 'intropage') . '
'; $panel['data'] .= ''; $panel['data'] .= '' . @@ -359,15 +359,15 @@ function webseer($panel, $user_id) { foreach ($logs as $row) { $color = 'grey'; - $text = ''; + $text = ''; if ($row['http_code'] == 200) { - if ($row['secs'] > (time()-($important_period))) { + if ($row['secs'] > (time() - ($important_period))) { $color = 'green'; } $text = __('OK'); } else { - if ($row['secs'] > (time()-($important_period))) { + if ($row['secs'] > (time() - ($important_period))) { $color = 'red'; } $text = __('Failed'); @@ -397,22 +397,23 @@ function webseer($panel, $user_id) { save_panel_result($panel, $user_id); } -//------------------------------------ webseer_plugin ----------------------------------------------------- +// ------------------------------------ webseer_plugin ----------------------------------------------------- function webseer_detail() { global $config, $log; - $important_period = read_user_setting('intropage_important_period', read_config_option('intropage_important_period'), false, $_SESSION['sess_user_id']); - if ($important_period == -1) { - $important_period = time(); - } + $important_period = read_user_setting('intropage_important_period', read_config_option('intropage_important_period'), false, $_SESSION['sess_user_id']); - $panel = array( + if ($important_period == -1) { + $important_period = time(); + } + + $panel = [ 'name' => __('Webseer Plugin - Details', 'intropage'), 'alarm' => 'grey', 'detail' => '', - ); + ]; - $logs = db_fetch_assoc ('SELECT pwul.lastcheck, pwul.result, pwul.http_code, pwul.error, pwu.url, + $logs = db_fetch_assoc('SELECT pwul.lastcheck, pwul.result, pwul.http_code, pwul.error, pwu.url, UNIX_TIMESTAMP(pwul.lastcheck) AS secs FROM plugin_webseer_urls_log AS pwul INNER JOIN plugin_webseer_urls AS pwu @@ -424,14 +425,14 @@ function webseer_detail() { $panel['detail'] = '
' . __('Last log messages', 'intropage') . '
' . __('Date', 'intropage') . '
'; $panel['detail'] .= - '' . - '' . - '' . + '' . + '' . + '' . '' . - '' . + '' . ''; - foreach ($logs as $log) { + foreach ($logs as $log) { $color = 'grey'; $panel['detail'] .= ''; @@ -439,12 +440,12 @@ function webseer_detail() { $panel['detail'] .= ''; if ($log['result'] == 1) { - if ($log['secs'] > (time()-($important_period))) { + if ($log['secs'] > (time() - ($important_period))) { $color = 'green'; } $panel['detail'] .= ''; } else { - if ($log['secs'] > (time()-($important_period))) { + if ($log['secs'] > (time() - ($important_period))) { $color = 'red'; } $panel['detail'] .= ''; @@ -453,7 +454,7 @@ function webseer_detail() { $panel['detail'] .= ''; $panel['detail'] .= ''; - if ($color == 'red') { + if ($color == 'red') { $panel['alarm'] = 'red'; } } @@ -463,7 +464,6 @@ function webseer_detail() { return $panel; } - // -------------------------------------plugin servcheck------------------------------------------- function servcheck($panel, $user_id) { global $config; @@ -473,6 +473,7 @@ function servcheck($panel, $user_id) { $lines = get_panel_lines_count($panel['height'], $user_id); $important_period = read_user_setting('intropage_important_period', read_config_option('intropage_important_period'), false, $user_id); + if ($important_period == -1) { $important_period = time(); } @@ -480,9 +481,10 @@ function servcheck($panel, $user_id) { if (!api_plugin_is_enabled('servcheck')) { $panel['alarm'] = 'yellow'; $panel['data'] = __('Plugin Servcheck isn\'t installed or started', 'intropage'); - $panel['detail'] = FALSE; + $panel['detail'] = false; } else { - $ok = 0; $ko = 0; + $ok = 0; + $ko = 0; $all = db_fetch_cell('SELECT COUNT(*) FROM plugin_servcheck_test'); $disa = db_fetch_cell("SELECT COUNT(*) FROM plugin_servcheck_test WHERE enabled != 'on'"); @@ -498,8 +500,8 @@ function servcheck($panel, $user_id) { foreach ($tests as $test) { $state = db_fetch_cell_prepared('SELECT result FROM plugin_servcheck_log WHERE test_id = ? ORDER BY lastcheck DESC LIMIT 1', - array($test['id'])); - + [$test['id']]); + if ($state == 'ok') { $ok++; } else { @@ -514,7 +516,7 @@ function servcheck($panel, $user_id) { $panel['data'] .= __('Number of checks (all/disabled): ', 'intropage') . $all . ' / ' . $disa . '
'; $panel['data'] .= __('Status (ok/error): ', 'intropage') . $ok . ' / ' . $ko . '

'; - $logs = db_fetch_assoc ('SELECT psl.lastcheck as `lastcheck`, result, error, '. $dncolumn . ' as name, type, + $logs = db_fetch_assoc('SELECT psl.lastcheck as `lastcheck`, result, error, ' . $dncolumn . ' as name, type, UNIX_TIMESTAMP(psl.lastcheck) AS secs FROM plugin_servcheck_log AS psl LEFT JOIN plugin_servcheck_test AS pst @@ -522,7 +524,6 @@ function servcheck($panel, $user_id) { LIMIT ' . ($lines - 4)); if (cacti_sizeof($logs) > 0) { - $panel['data'] .= '
' . __('Date', 'intropage') . '' . __('URL', 'intropage') . '' . __('Result', 'intropage') . '' . __('Date', 'intropage') . '' . __('URL', 'intropage') . '' . __('Result', 'intropage') . '' . __('HTTP code', 'intropage') . '' . __('Error', 'intropage') . '' . __('Error', 'intropage') . '
' . $log['url'] . '' . __('OK') . '' . __('Failed') . '' . $log['http_code'] . '' . $log['error'] . '
'; $panel['data'] .= ''; $panel['data'] .= '' . @@ -532,15 +533,15 @@ function servcheck($panel, $user_id) { foreach ($logs as $row) { $color = 'grey'; - $text = ''; + $text = ''; if ($row['result'] == 'ok') { - if ($row['secs'] > (time()-($important_period))) { + if ($row['secs'] > (time() - ($important_period))) { $color = 'green'; } $text = __('OK'); } else { - if ($row['secs'] > (time()-($important_period))) { + if ($row['secs'] > (time() - ($important_period))) { $color = 'red'; } $text = __('Failed'); @@ -561,7 +562,7 @@ function servcheck($panel, $user_id) { $panel['data'] .= '' . '' . '' . - ''; + ''; } $panel['data'] .= '
' . __('Last log records', 'intropage') . '
' . __('Date', 'intropage') . '' . $row['lastcheck'] . '' . $row['name'] . '' . $row['type'] . '' . $row['result'] .'
' . $row['result'] . '
'; @@ -571,29 +572,31 @@ function servcheck($panel, $user_id) { save_panel_result($panel, $user_id); } -//------------------------------------ servcheck_plugin_detail------------------------------------------------- +// ------------------------------------ servcheck_plugin_detail------------------------------------------------- function servcheck_detail() { global $config, $log; - $important_period = read_user_setting('intropage_important_period', read_config_option('intropage_important_period'), false, $_SESSION['sess_user_id']); - if ($important_period == -1) { - $important_period = time(); - } + $important_period = read_user_setting('intropage_important_period', read_config_option('intropage_important_period'), false, $_SESSION['sess_user_id']); - $panel = array( + if ($important_period == -1) { + $important_period = time(); + } + + $panel = [ 'name' => __('Servcheck Plugin - Details', 'intropage'), 'alarm' => 'grey', 'detail' => '', - ); + ]; $dncolumn = db_fetch_cell("SELECT COLUMN_NAME FROM information_schema.columns WHERE TABLE_NAME = 'plugin_servcheck_test' AND COLUMN_NAME = 'display_name'"); + // servcheck < 0.3 uses another name if (!$dncolumn) { $dncolumn = 'name'; } - $logs = db_fetch_assoc ('SELECT psl.lastcheck as `lastcheck`, result, error, ' . $dncolumn . ', type, + $logs = db_fetch_assoc('SELECT psl.lastcheck as `lastcheck`, result, error, ' . $dncolumn . ', type, UNIX_TIMESTAMP(psl.lastcheck) AS secs FROM plugin_servcheck_log AS psl LEFT JOIN plugin_servcheck_test AS pst @@ -604,14 +607,14 @@ function servcheck_detail() { $panel['detail'] = ''; $panel['detail'] .= - '' . - '' . - '' . + '' . + '' . + '' . '' . '' . ''; - foreach ($logs as $log) { + foreach ($logs as $log) { $color = 'grey'; $panel['detail'] .= ''; @@ -620,13 +623,13 @@ function servcheck_detail() { $panel['detail'] .= ''; if ($log['result'] == 'ok') { - if ($log['secs'] > (time()-($important_period))) { + if ($log['secs'] > (time() - ($important_period))) { $color = 'green'; } $panel['detail'] .= ''; } else { - if ($log['secs'] > (time()-($important_period))) { + if ($log['secs'] > (time() - ($important_period))) { $color = 'red'; } $panel['detail'] .= ''; @@ -635,7 +638,7 @@ function servcheck_detail() { $panel['detail'] .= ''; $panel['detail'] .= ''; - if ($color == 'red') { + if ($color == 'red') { $panel['alarm'] = 'red'; } } @@ -644,4 +647,3 @@ function servcheck_detail() { return $panel; } - diff --git a/panellib/poller.php b/panellib/poller.php index bc3e202..72e94ff 100644 --- a/panellib/poller.php +++ b/panellib/poller.php @@ -27,13 +27,13 @@ function register_poller() { global $registry; - $registry['poller'] = array( + $registry['poller'] = [ 'name' => __('Poller Panels', 'intropage'), 'description' => __('Panels that provide information about Cacti\'s polling process.', 'intropage') - ); + ]; - $panels = array( - 'poller_info' => array( + $panels = [ + 'poller_info' => [ 'name' => __('Poller Information', 'intropage'), 'description' => __('Various information about your Cacti poller.', 'intropage'), 'class' => 'poller', @@ -50,8 +50,8 @@ function register_poller() { 'update_func' => 'poller_info', 'details_func' => 'poller_info_detail', 'trends_func' => 'poller_info_trend' - ), - 'poller_stat' => array( + ], + 'poller_stat' => [ 'name' => __('Poller Statistics', 'intropage'), 'description' => __('Various Cacti poller statistics.', 'intropage'), 'class' => 'poller', @@ -68,8 +68,8 @@ function register_poller() { 'update_func' => 'poller_stat', 'details_func' => false, 'trends_func' => 'poller_stat_trend' - ), - 'poller_output_items' => array( + ], + 'poller_output_items' => [ 'name' => __('Poller Output Items', 'intropage'), 'description' => __('Various Cacti poller statistics.', 'intropage'), 'class' => 'poller', @@ -86,8 +86,8 @@ function register_poller() { 'update_func' => 'poller_output_items', 'details_func' => false, 'trends_func' => 'poller_output_items_trend' - ), - ); + ], + ]; return $panels; } @@ -96,7 +96,7 @@ function poller_info_trend() { // Not yet implemented } -//------------------------------------ poller info ----------------------------------------------------- +// ------------------------------------ poller info ----------------------------------------------------- function poller_info($panel, $user_id) { global $config; @@ -122,14 +122,13 @@ function poller_info($panel, $user_id) { if (cacti_sizeof($sql_pollers)) { $details = '
' . __('Date', 'intropage') . '' . __('Test', 'intropage') . '' . __('Type', 'intropage') . '' . __('Date', 'intropage') . '' . __('Test', 'intropage') . '' . __('Type', 'intropage') . '' . __('Result', 'intropage') . '' . __('Error', 'intropage') . '
' . $log['type'] . '' . __('OK') . '' . __('Failed') . '' . $log['result'] . '' . $log['error'] . '
' . '' . - '' . - '' . - '' . + '' . + '' . + '' . '' . ''; foreach ($sql_pollers as $poller) { - $color = 'green'; if ($poller['status'] == 0 || $poller['status'] == 1 || $poller['status'] == 2 || $poller['status'] == 5) { @@ -144,24 +143,24 @@ function poller_info($panel, $user_id) { $status = __('Idle', 'intropage'); } elseif ($poller['status'] == 3) { $status = __('Unkn/down', 'intropage'); - $color = 'red'; + $color = 'red'; } elseif ($poller['status'] == 4) { $status = __('Disabled', 'intropage'); } elseif ($poller['status'] == 5) { $status = __('Recovering', 'intropage'); - $color = 'yellow'; + $color = 'yellow'; } $details .= '' . - '' . - '' . - ''; + '' . + '' . + ''; $color = 'green'; - if (($poller['total_time']/$poller_interval) > 0.9) { + if (($poller['total_time'] / $poller_interval) > 0.9) { $color = 'red'; - } elseif (($poller['total_time']/$poller_interval) > 0.7) { + } elseif (($poller['total_time'] / $poller_interval) > 0.7) { $color = 'yellow'; } @@ -194,11 +193,11 @@ function poller_stat_trend() { db_execute_prepared("REPLACE INTO plugin_intropage_trends (name, cur_timestamp, value, user_id) VALUES ('poller', ?, ?, ?)", - array($stat['start'], $stat['id'] . ':' . round($stat['total_time']),4)); + [$stat['start'], $stat['id'] . ':' . round($stat['total_time']), 4]); } } -//------------------------------------ poller stat ----------------------------------------------------- +// ------------------------------------ poller stat ----------------------------------------------------- function poller_stat($panel, $user_id, $timespan = 0) { global $config, $run_from_poller; @@ -208,25 +207,25 @@ function poller_stat($panel, $user_id, $timespan = 0) { $panel['alarm'] = 'green'; - $graph = array ( - 'line' => array( + $graph = [ + 'line' => [ 'title1' => '', - 'label1' => array(), - 'data1' => array(), + 'label1' => [], + 'data1' => [], 'title2' => '', - 'label2' => array(), - 'data2' => array(), + 'label2' => [], + 'data2' => [], 'title3' => '', - 'label3' => array(), - 'data3' => array(), + 'label3' => [], + 'data3' => [], 'title4' => '', - 'label4' => array(), - 'data4' => array(), + 'label4' => [], + 'data4' => [], 'title5' => '', - 'label5' => array(), - 'data5' => array(), - ), - ); + 'label5' => [], + 'data5' => [], + ], + ]; if ($timespan == 0) { if (isset($_SESSION['sess_user_id'])) { @@ -240,7 +239,7 @@ function poller_stat($panel, $user_id, $timespan = 0) { $refresh = db_fetch_cell_prepared('SELECT refresh_interval FROM plugin_intropage_panel_data WHERE id = ?', - array($panel['id'])); + [$panel['id']]); } else { $refresh = $panel['refresh_interval']; } @@ -258,6 +257,7 @@ function poller_stat($panel, $user_id, $timespan = 0) { if ($pcount > 0) { $new_index = 1; + foreach ($pollers as $xpoller) { $seconds = floor($timespan / 60); @@ -268,7 +268,7 @@ function poller_stat($panel, $user_id, $timespan = 0) { AND value LIKE ? GROUP BY UNIX_TIMESTAMP(cur_timestamp) DIV $seconds ORDER BY cur_timestamp ASC", - array($timespan, $xpoller['id'] . ':%')); + [$timespan, $xpoller['id'] . ':%']); if ($pcount < 3) { $avg = db_fetch_cell_prepared("SELECT (SUBSTRING_INDEX(value, ':', -1)) AS value @@ -276,7 +276,7 @@ function poller_stat($panel, $user_id, $timespan = 0) { WHERE cur_timestamp > date_sub(NOW(), INTERVAL 24 HOUR) AND name = 'poller' AND value LIKE ?", - array($xpoller['id'] . ':%')); + [$xpoller['id'] . ':%']); $avg_label = []; $avg_data = []; } @@ -288,7 +288,7 @@ function poller_stat($panel, $user_id, $timespan = 0) { // graph data $graph['line']['label' . $new_index][] = $row['date']; - $graph['line']['data' . $new_index][] = round($row['value'], 2); + $graph['line']['data' . $new_index][] = round($row['value'], 2); $graph['line']['title' . $new_index] = __('ID: ', 'intropage') . $xpoller['id']; $graph['line']['unit1']['title'] = __('Seconds', 'intropage'); @@ -302,9 +302,8 @@ function poller_stat($panel, $user_id, $timespan = 0) { // add 24 hours avg if we have enough lines if ($pcount < 3) { - $graph['line']['label' . $new_index] = $avg_label; - $graph['line']['data' . $new_index] = $avg_data; + $graph['line']['data' . $new_index] = $avg_data; $graph['line']['title' . $new_index] = __('24h avg ID: ', 'intropage') . $xpoller['id']; $graph['line']['unit1']['title'] = __('Seconds', 'intropage'); @@ -320,26 +319,26 @@ function poller_stat($panel, $user_id, $timespan = 0) { save_panel_result($panel, $user_id); } -//------------------------------------ poller_info ----------------------------------------------------- +// ------------------------------------ poller_info ----------------------------------------------------- function poller_info_detail() { global $config; $poller_interval = read_config_option('poller_interval'); - $panel = array( + $panel = [ 'name' => __('Poller Details', 'intropage'), 'alarm' => 'green', 'detail' => '', - ); + ]; $row = '
' . __('ID', 'intropage') . '' . __('Name', 'intropage') . '' . __('State', 'intropage') . '' . __('ID', 'intropage') . '' . __('Name', 'intropage') . '' . __('State', 'intropage') . '' . __('Total Time', 'intropage') . '
' . $poller['id'] . '' . html_escape($poller['name']) . '' . $status . '' . $poller['id'] . '' . html_escape($poller['name']) . '' . $status . '
' . '' . - '' . - '' . - '' . - '' . + '' . + '' . + '' . + '' . '' . - '' . + '' . ''; $pollers = db_fetch_assoc('SELECT p.* @@ -369,28 +368,28 @@ function poller_info_detail() { $row .= ''; if ($poller['status'] == 0) { - $row .= ''; + $row .= ''; } elseif ($poller['status'] == 1) { - $row .= ''; + $row .= ''; } elseif ($poller['status'] == 2) { - $row .= ''; + $row .= ''; } elseif ($poller['status'] == 3) { - $row .= ''; + $row .= ''; } elseif ($poller['status'] == 4) { - $row .= ''; + $row .= ''; } elseif ($poller['status'] == 5) { $row .= ''; } - if (($poller['total_time']/$poller_interval) > 0.9) { + if (($poller['total_time'] / $poller_interval) > 0.9) { $color = 'red'; - } elseif (($poller['total_time']/$poller_interval) > 0.7) { + } elseif (($poller['total_time'] / $poller_interval) > 0.7) { $color = 'yellow'; } $row .= ''; - $row .= ''; - $row .= ''; + $row .= ''; + $row .= ''; $row .= ''; } @@ -409,33 +408,32 @@ function poller_info_detail() { return $panel; } -//------------------------------------ poller_output_items ----------------------------------------------------- +// ------------------------------------ poller_output_items ----------------------------------------------------- function poller_output_items_trend() { - - $count = db_fetch_cell("SELECT COUNT(local_data_id) FROM poller_output"); + $count = db_fetch_cell('SELECT COUNT(local_data_id) FROM poller_output'); db_execute_prepared('REPLACE INTO plugin_intropage_trends (name, value, user_id) VALUES (?, ?, 0)', - array('poller_output', $count)); + ['poller_output', $count]); } function poller_output_items($panel, $user_id, $timespan = 0) { global $config, $run_from_poller; $poller_interval = read_config_option('poller_interval'); - $color = read_config_option('intropage_alert_poller_output'); + $color = read_config_option('intropage_alert_poller_output'); $panel['alarm'] = 'green'; - $graph = array ( - 'line' => array( + $graph = [ + 'line' => [ 'title1' => '', - 'label1' => array(), - 'data1' => array(), - ), - ); + 'label1' => [], + 'data1' => [], + ], + ]; if ($timespan == 0) { if (isset($_SESSION['sess_user_id'])) { @@ -449,7 +447,7 @@ function poller_output_items($panel, $user_id, $timespan = 0) { $refresh = db_fetch_cell_prepared('SELECT refresh_interval FROM plugin_intropage_panel_data WHERE id = ?', - array($panel['id'])); + [$panel['id']]); } else { $refresh = $panel['refresh_interval']; } @@ -462,22 +460,22 @@ function poller_output_items($panel, $user_id, $timespan = 0) { AND name = 'poller_output' GROUP BY UNIX_TIMESTAMP(cur_timestamp) DIV $seconds ORDER BY cur_timestamp ASC", - array($timespan)); + [$timespan]); if (cacti_sizeof($rows)) { foreach ($rows as $row) { if ($row['value'] > 0) { if ($color == 'red') { $panel['alarm'] = 'red'; - } elseif ($panel['alarm'] == 'green' && $color == "yellow") { + } elseif ($panel['alarm'] == 'green' && $color == 'yellow') { $panel['alarm'] = 'yellow'; } } // graph data - $graph['line']['label1'][] = $row['date']; - $graph['line']['data1'][] = $row['value']; - $graph['line']['title1'] = __('Poller output items ', 'intropage'); + $graph['line']['label1'][] = $row['date']; + $graph['line']['data1'][] = $row['value']; + $graph['line']['title1'] = __('Poller output items ', 'intropage'); $graph['line']['unit1']['title'] = __('Items', 'intropage'); } @@ -488,4 +486,3 @@ function poller_output_items($panel, $user_id, $timespan = 0) { save_panel_result($panel, $user_id); } - diff --git a/panellib/syslog.php b/panellib/syslog.php index 744da6b..6dd7c5d 100644 --- a/panellib/syslog.php +++ b/panellib/syslog.php @@ -27,13 +27,13 @@ function register_syslog() { global $registry; - $registry['syslog'] = array( + $registry['syslog'] = [ 'name' => __('Syslog Panels', 'intropage'), 'description' => __('Panels that provide information about Cacti\'s Syslog message processing.', 'intropage') - ); + ]; - $panels = array( - 'plugin_syslog' => array( + $panels = [ + 'plugin_syslog' => [ 'name' => __('Syslog Details', 'intropage'), 'description' => __('Various Syslog Plugin statistics.', 'intropage'), 'class' => 'syslog', @@ -50,8 +50,8 @@ function register_syslog() { 'update_func' => 'plugin_syslog', 'details_func' => false, 'trends_func' => 'plugin_syslog_trend' - ), - 'plugin_syslog_devices' => array( + ], + 'plugin_syslog_devices' => [ 'name' => __('Syslog Top Devices', 'intropage'), 'description' => __('Devices with the most messages', 'intropage'), 'class' => 'syslog', @@ -68,8 +68,8 @@ function register_syslog() { 'update_func' => 'plugin_syslog_devices', 'details_func' => 'plugin_syslog_devices_detail', 'trends_func' => false - ), - 'plugin_syslog_levels' => array( + ], + 'plugin_syslog_levels' => [ 'name' => __('Syslog Message levels', 'intropage'), 'description' => __('Messages by level.', 'intropage'), 'class' => 'syslog', @@ -86,8 +86,8 @@ function register_syslog() { 'update_func' => 'plugin_syslog_levels', 'details_func' => false, 'trends_func' => 'plugin_syslog_levels_trend' - ), - ); + ], + ]; return $panels; } @@ -96,7 +96,6 @@ function plugin_syslog_trend() { global $config; if (api_plugin_is_enabled('syslog')) { - include_once($config['base_path'] . '/plugins/syslog/database.php'); // Grab row counts from the information schema, it's faster @@ -111,22 +110,22 @@ function plugin_syslog_trend() { $alert_rows = syslog_db_fetch_cell_prepared('SELECT IFNULL(SUM(count),0) FROM syslog_logs WHERE logtime > DATE_SUB(NOW(), INTERVAL ? SECOND)', - array(read_config_option('poller_interval'))); + [read_config_option('poller_interval')]); db_execute_prepared('INSERT INTO plugin_intropage_trends (name, value, user_id) VALUES ("syslog_incoming", ?, 0)', - array($i_rows)); + [$i_rows]); db_execute_prepared('INSERT INTO plugin_intropage_trends (name, value, user_id) VALUES ("syslog_total", ?, 0)', - array ($total_rows)); + [$total_rows]); db_execute_prepared('INSERT INTO plugin_intropage_trends (name, value, user_id) VALUES ("syslog_alert", ?, 0)', - array ($alert_rows)); + [$alert_rows]); } } @@ -134,10 +133,9 @@ function plugin_syslog_levels_trend() { global $config; if (api_plugin_is_enabled('syslog')) { - include_once($config['base_path'] . '/plugins/syslog/database.php'); - $data = array( + $data = [ 0 => 0, 1 => 0, 2 => 0, @@ -146,7 +144,7 @@ function plugin_syslog_levels_trend() { 5 => 0, 6 => 0, 7 => 0, - ); + ]; $pi = read_config_option('poller_interval'); @@ -155,10 +153,10 @@ function plugin_syslog_levels_trend() { FROM syslog WHERE logtime BETWEEN (DATE_SUB(NOW(),INTERVAL ? SECOND)) AND (DATE_SUB(NOW(),INTERVAL ? SECOND)) GROUP BY priority_id', - array(2*$pi, $pi)); + [2 * $pi, $pi]); foreach ($levels as $level) { - $l = (int) $level['priority_id']; + $l = (int) $level['priority_id']; $data[$l] = $level['mcount']; } @@ -167,27 +165,27 @@ function plugin_syslog_levels_trend() { db_execute_prepared('INSERT INTO plugin_intropage_trends (name, value, user_id) VALUES ("syslog_levels", ?, 0)', - array($insert)); + [$insert]); } } function plugin_syslog($panel, $user_id, $timespan = 0) { $panel['alarm'] = 'green'; - $graph = array ( - 'line' => array( + $graph = [ + 'line' => [ 'title' => $panel['name'], 'title1' => '', - 'label1' => array(), - 'data1' => array(), + 'label1' => [], + 'data1' => [], 'title2' => '', - 'label2' => array(), - 'data2' => array(), + 'label2' => [], + 'data2' => [], 'title3' => '', - 'label3' => array(), - 'data3' => array(), - ), - ); + 'label3' => [], + 'data3' => [], + ], + ]; if ($timespan == 0) { if (isset($_SESSION['sess_user_id'])) { @@ -201,7 +199,7 @@ function plugin_syslog($panel, $user_id, $timespan = 0) { $refresh = db_fetch_cell_prepared('SELECT refresh_interval FROM plugin_intropage_panel_data WHERE id = ?', - array($panel['id'])); + [$panel['id']]); } else { $refresh = $panel['refresh']; } @@ -219,14 +217,14 @@ function plugin_syslog($panel, $user_id, $timespan = 0) { AND name IN ('syslog_total', 'syslog_incoming', 'syslog_alert') GROUP BY UNIX_TIMESTAMP(cur_timestamp) DIV $seconds ORDER BY cur_timestamp ASC", - array($timespan)); + [$timespan]); if (cacti_sizeof($rows)) { // Converted syslog_total to total new rows; - $nrows = array(); + $nrows = []; $last_total = 0; - foreach($rows as $index => $row) { + foreach ($rows as $index => $row) { $total = $row['syslog_total']; $totali = $row['syslog_incoming']; @@ -254,9 +252,9 @@ function plugin_syslog($panel, $user_id, $timespan = 0) { $graph['line']['title3'] = __('Stored', 'intropage'); $graph['line']['unit1']['title'] = __('Messages', 'intropage'); - $graph['line']['unit1']['series'] = array('data1', 'data2', 'data3'); + $graph['line']['unit1']['series'] = ['data1', 'data2', 'data3']; - foreach($nrows as $row) { + foreach ($nrows as $row) { $graph['line']['label1'][] = $row['date']; $graph['line']['data1'][] = $row['syslog_incoming']; $graph['line']['data2'][] = $row['syslog_alert']; @@ -282,35 +280,35 @@ function plugin_syslog($panel, $user_id, $timespan = 0) { function plugin_syslog_levels($panel, $user_id, $timespan = 0) { $panel['alarm'] = 'green'; - $graph = array ( - 'bar' => array( + $graph = [ + 'bar' => [ 'title' => $panel['name'], 'title1' => 'Emergency', - 'label1' => array(), - 'data1' => array(), + 'label1' => [], + 'data1' => [], 'title2' => 'Alert', - 'label2' => array(), - 'data2' => array(), + 'label2' => [], + 'data2' => [], 'title3' => 'Critical', - 'label3' => array(), - 'data3' => array(), + 'label3' => [], + 'data3' => [], 'title4' => 'Error', - 'label4' => array(), - 'data4' => array(), + 'label4' => [], + 'data4' => [], 'title5' => 'Warning', - 'label5' => array(), - 'data5' => array(), + 'label5' => [], + 'data5' => [], 'title6' => 'Notice', - 'label6' => array(), - 'data6' => array(), + 'label6' => [], + 'data6' => [], 'title7' => 'Info', - 'label7' => array(), - 'data7' => array(), + 'label7' => [], + 'data7' => [], 'title8' => 'Debug', - 'label8' => array(), - 'data8' => array(), - ), - ); + 'label8' => [], + 'data8' => [], + ], + ]; if ($timespan == 0) { if (isset($_SESSION['sess_user_id'])) { @@ -324,7 +322,7 @@ function plugin_syslog_levels($panel, $user_id, $timespan = 0) { $refresh = db_fetch_cell_prepared('SELECT refresh_interval FROM plugin_intropage_panel_data WHERE id = ?', - array($panel['id'])); + [$panel['id']]); } else { $refresh = $panel['refresh']; } @@ -338,24 +336,23 @@ function plugin_syslog_levels($panel, $user_id, $timespan = 0) { AND name = 'syslog_levels' GROUP BY UNIX_TIMESTAMP(cur_timestamp) DIV ? ORDER BY cur_timestamp ASC", - array($timespan, $seconds)); + [$timespan, $seconds]); if (cacti_sizeof($rows)) { - - foreach($rows as $row) { + foreach ($rows as $row) { $all = explode('&', $row['value']); $graph['bar']['label1'][] = $row['cur_timestamp']; foreach ($all as $item) { - list($lev, $count) = explode('=', $item); + [$lev, $count] = explode('=', $item); $lev++; $graph['bar']["data$lev"][] = $count; } } $graph['bar']['unit1']['title'] = __('Messages', 'intropage'); - $graph['bar']['unit1']['series'] = array('data1', 'data2', 'data3', 'data4', 'data5', 'data6', 'data7', 'data8'); + $graph['bar']['unit1']['series'] = ['data1', 'data2', 'data3', 'data4', 'data5', 'data6', 'data7', 'data8']; $panel['data'] = intropage_prepare_graph($graph, $user_id); } else { @@ -369,7 +366,6 @@ function plugin_syslog_levels($panel, $user_id, $timespan = 0) { save_panel_result($panel, $user_id); } - function plugin_syslog_devices($panel, $user_id, $timespan = 0) { global $config; @@ -384,7 +380,6 @@ function plugin_syslog_devices($panel, $user_id, $timespan = 0) { } if (api_plugin_is_enabled('syslog')) { - include_once($config['base_path'] . '/plugins/syslog/database.php'); $lines = get_panel_lines_count($panel['height'], $user_id); @@ -397,20 +392,19 @@ function plugin_syslog_devices($panel, $user_id, $timespan = 0) { GROUP BY s.host_id ORDER BY hcount DESC LIMIT ' . $lines, - array($timespan)); + [$timespan]); if (cacti_sizeof($devices)) { - $panel['data'] = '
' . __('ID', 'intropage') . '' . __('Name', 'intropage') . '' . __('State', 'intropage') . '' . __('Total Time', 'intropage') . '' . __('ID', 'intropage') . '' . __('Name', 'intropage') . '' . __('State', 'intropage') . '' . __('Total Time', 'intropage') . '' . __('Average Time', 'intropage') . '' . __('Max Time', 'intropage') . '' . __('Max Time', 'intropage') . '
' . html_escape($poller['name']) . '' . __('New/Idle', 'intropage') . '' . __('New/Idle', 'intropage') . '' . __('Running', 'intropage') . '' . __('Running', 'intropage') . '' . __('Idle', 'intropage') . '' . __('Idle', 'intropage') . '' . __('Unkn/down', 'intropage') . '' . __('Unkn/down', 'intropage') . '' . __('Disabled', 'intropage') . '' . __('Disabled', 'intropage') . '' . __('Recovering', 'intropage') . '' . round($poller['total_time'], 2) . 's ' . round($poller['avg_time'], 2) . 's' . round($poller['max_time'], 2) . 's' . round($poller['avg_time'], 2) . 's' . round($poller['max_time'], 2) . 's
' . '' . - '' . + '' . '' . ''; $i = 0; - foreach ($devices as $device) { - $row = ''; + foreach ($devices as $device) { + $row = ''; $row .= "'; $panel['data'] .= $row; @@ -427,15 +421,14 @@ function plugin_syslog_devices($panel, $user_id, $timespan = 0) { save_panel_result($panel, $user_id); } - function plugin_syslog_devices_detail() { global $config, $console_access; - $panel = array( + $panel = [ 'name' => __('Top 20 Hosts with the most messages', 'intropage'), 'alarm' => 'grey', 'detail' => '', - ); + ]; if (isset($_SESSION['sess_user_id'])) { $timespan = read_user_setting('intropage_timespan', read_config_option('intropage_timespan'), $_SESSION['sess_user_id']); @@ -444,7 +437,6 @@ function plugin_syslog_devices_detail() { } if (api_plugin_is_enabled('syslog')) { - include_once($config['base_path'] . '/plugins/syslog/database.php'); $devices = syslog_db_fetch_assoc_prepared('SELECT sh.host AS ip ,count(*) AS hcount @@ -455,21 +447,20 @@ function plugin_syslog_devices_detail() { GROUP BY s.host_id ORDER BY hcount desc LIMIT 20', - array($timespan)); + [$timespan]); if (cacti_sizeof($devices)) { - $panel['detail'] = '
' . __('Device', 'intropage') . '' . __('Device', 'intropage') . '' . __('Messages', read_config_option('poller_interval'), 'intropage') . '
' . html_escape(substr($device['ip'],0,37)) . '
' . html_escape(substr($device['ip'],0,37)) . '" . $device['hcount'] . '
' . '' . - '' . + '' . '' . ''; $i = 0; - foreach ($devices as $device) { - $row = ''; - $row .= ''; + foreach ($devices as $device) { + $row = ''; + $row .= ''; $panel['detail'] .= $row; $i++; @@ -480,8 +471,8 @@ function plugin_syslog_devices_detail() { $panel['detail'] = __('No messages', 'intropage'); } } else { - $panel['detail'] = __('Syslog plugin is not enabled', 'intropage'); + $panel['detail'] = __('Syslog plugin is not enabled', 'intropage'); } + return $panel; } - diff --git a/panellib/system.php b/panellib/system.php index 31f3157..5cde971 100644 --- a/panellib/system.php +++ b/panellib/system.php @@ -27,13 +27,13 @@ function register_system() { global $registry; - $registry['system'] = array( + $registry['system'] = [ 'name' => __('System Panels', 'intropage'), 'description' => __('Panels that provide information about Cacti system performance.', 'intropage') - ); + ]; - $panels = array( - 'info' => array( + $panels = [ + 'info' => [ 'name' => __('Information', 'intropage'), 'description' => __('Various system information about the Cacti system itself.', 'intropage'), 'class' => 'system', @@ -50,8 +50,8 @@ function register_system() { 'update_func' => 'info', 'details_func' => false, 'trends_func' => false - ), - 'admin_alert' => array( + ], + 'admin_alert' => [ 'name' => __('Administrative Alerts', 'intropage'), 'description' => __('Extra admin notify panel for all users', 'intropage'), 'class' => 'system', @@ -68,8 +68,8 @@ function register_system() { 'update_func' => 'admin_alert', 'details_func' => false, 'trends_func' => false - ), - 'boost' => array( + ], + 'boost' => [ 'name' => __('Boost Statistics', 'intropage'), 'description' => __('Information about Cacti\'s performance boost process.', 'intropage'), 'class' => 'system', @@ -86,8 +86,8 @@ function register_system() { 'update_func' => 'boost', 'details_func' => false, 'trends_func' => false - ), - 'boost_history' => array( + ], + 'boost_history' => [ 'name' => __('Boost History', 'intropage'), 'description' => __('Information about boost process history.', 'intropage'), 'class' => 'system', @@ -104,8 +104,8 @@ function register_system() { 'update_func' => 'boost_history', 'details_func' => false, 'trends_func' => 'boost_history_trend' - ), - 'extrem' => array( + ], + 'extrem' => [ 'name' => __('24 Hour Extremes', 'intropage'), 'description' => __('Table with 24 hours of Polling Extremes (longest poller run, down hosts)', 'intropage'), 'class' => 'system', @@ -122,8 +122,8 @@ function register_system() { 'update_func' => 'extrem', 'details_func' => 'extrem_detail', 'trends_func' => 'extrem_trend' - ), - 'cpuload' => array( + ], + 'cpuload' => [ 'name' => __('CPU Utilization', 'intropage'), 'description' => __('CPU utilization Graph (only Linux).', 'intropage'), 'class' => 'system', @@ -140,8 +140,8 @@ function register_system() { 'update_func' => 'cpuload', 'details_func' => false, 'trends_func' => 'cpuload_trend' - ) - ); + ] + ]; return $panels; } @@ -154,24 +154,23 @@ function cpuload_trend() { db_execute_prepared("REPLACE INTO plugin_intropage_trends (name, value, user_id) VALUES ('cpuload', ?, 0)", - array($load[0])); + [$load[0]]); } } - -//------------------------------------ cpuload ----------------------------------------------------- +// ------------------------------------ cpuload ----------------------------------------------------- function cpuload($panel, $user_id, $timespan = 0) { global $config; $panel['alarm'] = 'green'; - $graph = array ( - 'line' => array( + $graph = [ + 'line' => [ 'title' => __('CPU Load: ', 'intropage'), - 'label1' => array(), - 'data1' => array(), - ), - ); + 'label1' => [], + 'data1' => [], + ], + ]; if ($timespan == 0) { if (isset($_SESSION['sess_user_id'])) { @@ -185,7 +184,7 @@ function cpuload($panel, $user_id, $timespan = 0) { $refresh = db_fetch_cell_prepared('SELECT refresh_interval FROM plugin_intropage_panel_data WHERE id = ?', - array($panel['id'])); + [$panel['id']]); } else { $refresh = $panel['refresh']; } @@ -202,7 +201,7 @@ function cpuload($panel, $user_id, $timespan = 0) { AND name = 'cpuload' GROUP BY UNIX_TIMESTAMP(cur_timestamp) DIV $seconds ORDER BY cur_timestamp ASC", - array($timespan)); + [$timespan]); if (cacti_sizeof($rows)) { $graph['line']['title1'] = __('Avg CPU', 'intropage'); @@ -238,7 +237,7 @@ function cpuload($panel, $user_id, $timespan = 0) { save_panel_result($panel, $user_id); } -//------------------------- info------------------------- +// ------------------------- info------------------------- function info($panel, $user_id) { global $config, $poller_options; @@ -259,7 +258,7 @@ function info($panel, $user_id) { $spine_version = $out_array[0]; } - $panel['data'] .= ''; + $panel['data'] .= ''; $panel['data'] .= ''; @@ -267,9 +266,8 @@ function info($panel, $user_id) { $panel['data'] .= ''; $panel['alarm'] = 'red'; } - } else { - $panel['data'] .= ''; + $panel['data'] .= ''; } if (function_exists('php_uname')) { @@ -285,7 +283,7 @@ function info($panel, $user_id) { save_panel_result($panel, $user_id); } -//---------------------------admin alert-------------------- +// ---------------------------admin alert-------------------- function admin_alert($panel, $user_id) { global $config; @@ -294,9 +292,7 @@ function admin_alert($panel, $user_id) { save_panel_result($panel, $user_id); } - function boost_history_trend() { - $data_length = db_fetch_cell("SELECT data_length FROM INFORMATION_SCHEMA.TABLES WHERE table_schema=SCHEMA() AND (table_name LIKE 'poller_output_boost_arch_%' OR table_name LIKE 'poller_output_boost')"); @@ -304,7 +300,7 @@ function boost_history_trend() { db_execute_prepared('INSERT INTO plugin_intropage_trends (name, value, user_id) VALUES ("boost_mem_size", ?, 0)', - array($data_length)); + [$data_length]); $boost_table_status = db_fetch_assoc("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE table_schema=SCHEMA() @@ -326,24 +322,23 @@ function boost_history_trend() { db_execute_prepared('INSERT INTO plugin_intropage_trends (name, value, user_id) VALUES ("boost_pending", ?, 0)', - array($pending_records)); + [$pending_records]); } - function boost_history($panel, $user_id, $timespan = 0) { global $config; $panel['alarm'] = 'green'; - $graph = array ( - 'line' => array( + $graph = [ + 'line' => [ 'title' => __('Boost history: ', 'intropage'), - 'label1' => array(), - 'data1' => array(), - 'label2' => array(), - 'data2' => array(), - ), - ); + 'label1' => [], + 'data1' => [], + 'label2' => [], + 'data2' => [], + ], + ]; if ($timespan == 0) { if (isset($_SESSION['sess_user_id'])) { @@ -357,7 +352,7 @@ function boost_history($panel, $user_id, $timespan = 0) { $refresh = db_fetch_cell_prepared('SELECT refresh_interval FROM plugin_intropage_panel_data WHERE id = ?', - array($panel['id'])); + [$panel['id']]); } else { $refresh = $panel['refresh']; } @@ -367,15 +362,15 @@ function boost_history($panel, $user_id, $timespan = 0) { WHERE cur_timestamp > date_sub(NOW(), INTERVAL ? SECOND) AND name = 'boost_mem_size' ORDER BY cur_timestamp ASC", - array($timespan)); + [$timespan]); if (cacti_sizeof($rows)) { - $graph['line']['title1'] = __('Mem ', 'intropage'); + $graph['line']['title1'] = __('Mem ', 'intropage'); $graph['line']['unit1']['title'] = 'Used mem [KB]'; foreach ($rows as $row) { $graph['line']['label1'][] = $row['date']; - $graph['line']['data1'][] = $row['value']/1024; + $graph['line']['data1'][] = $row['value'] / 1024; } $rows = db_fetch_assoc_prepared("SELECT cur_timestamp AS `date`, value @@ -383,10 +378,10 @@ function boost_history($panel, $user_id, $timespan = 0) { WHERE cur_timestamp > date_sub(NOW(), INTERVAL ? SECOND) AND name = 'boost_pending' ORDER BY cur_timestamp ASC", - array($timespan)); + [$timespan]); if (cacti_sizeof($rows)) { - $graph['line']['title2'] = __('Pending records ', 'intropage'); + $graph['line']['title2'] = __('Pending records ', 'intropage'); $graph['line']['unit2']['title'] = 'Records'; foreach ($rows as $row) { @@ -409,8 +404,7 @@ function boost_history($panel, $user_id, $timespan = 0) { save_panel_result($panel, $user_id); } - -//--------------------------------boost-------------------------------- +// --------------------------------boost-------------------------------- function boost($panel, $user_id) { global $config, $boost_refresh_interval, $boost_max_runtime; @@ -427,7 +421,7 @@ function boost($panel, $user_id) { $parallel = read_config_option('boost_parallel', true); $detail_stats = read_config_option('stats_detail_boost', true); - /* get the boost table status */ + // get the boost table status $boost_table_status = db_fetch_assoc("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE table_schema=SCHEMA() AND (table_name LIKE 'poller_output_boost_arch_%' OR table_name LIKE 'poller_output_boost')"); @@ -437,7 +431,7 @@ function boost($panel, $user_id) { $data_length = 0; $engine = ''; $max_data_length = 0; - $total_records = 0; + $total_records = 0; if (cacti_sizeof($boost_table_status)) { foreach ($boost_table_status as $table) { @@ -474,10 +468,10 @@ function boost($panel, $user_id) { $boost_status_text = __('Running', 'intropage'); } elseif (substr_count($boost_status_array[0], 'overrun')) { $boost_status_text = __('Overrun Warning', 'intropage'); - $panel['alarm'] = 'red'; + $panel['alarm'] = 'red'; } elseif (substr_count($boost_status_array[0], 'timeout')) { $boost_status_text = __('Timed Out', 'intropage'); - $panel['alarm'] = 'red'; + $panel['alarm'] = 'red'; } else { $boost_status_text = __('Other'); } @@ -531,10 +525,10 @@ function boost($panel, $user_id) { $panel['data'] .= ''; - /* tell the user how big the table is */ + // tell the user how big the table is $panel['data'] .= ''; - /* tell the user about the average size/record */ + // tell the user about the average size/record $panel['data'] .= ''; if (is_numeric($boost_last_run_duration)) { @@ -558,15 +552,14 @@ function extrem_trend() { foreach ($users as $user) { if (is_panel_allowed('extrem', $user['id'])) { - $simple_perms = get_simple_device_perms($user['id']); if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user['id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -581,7 +574,7 @@ function extrem_trend() { db_execute_prepared('INSERT INTO plugin_intropage_trends (name, value, user_id) VALUES (?, ?, ?)', - array('failed_polls', $count, $user['id'])); + ['failed_polls', $count, $user['id']]); } if (db_table_exists('host_errors')) { @@ -592,13 +585,13 @@ function extrem_trend() { db_execute_prepared('INSERT INTO plugin_intropage_trends (name, value, user_id) VALUES (?, ?, ?)', - array('host_errors', $count, $user['id'])); + ['host_errors', $count, $user['id']]); } } } } -//------------------------------------ extrem ----------------------------------------------------- +// ------------------------------------ extrem ----------------------------------------------------- function extrem($panel, $user_id) { global $config; @@ -608,9 +601,9 @@ function extrem($panel, $user_id) { $panel['alarm'] = 'grey'; - $columns = array(); - $data = array(); - $fin_data = array(); + $columns = []; + $data = []; + $fin_data = []; $console_access = get_console_access($user_id); @@ -627,9 +620,9 @@ function extrem($panel, $user_id) { if (cacti_sizeof($data)) { foreach ($data as $key => $row) { - if (($row['xvalue']/$poller_interval) > 0.9) { + if (($row['xvalue'] / $poller_interval) > 0.9) { $color = 'red'; - } elseif (($row['xvalue']/$poller_interval) > 0.7) { + } elseif (($row['xvalue'] / $poller_interval) > 0.7) { $color = 'yellow'; } else { $color = 'green'; @@ -650,11 +643,10 @@ function extrem($panel, $user_id) { AND cur_timestamp > date_sub(now(),interval 1 day) ORDER BY value desc,cur_timestamp LIMIT $lines", - array($user_id)); + [$user_id]); if (cacti_sizeof($data)) { foreach ($data as $key => $row) { - if ($row['value'] > 0) { $color = 'red'; } else { @@ -676,7 +668,7 @@ function extrem($panel, $user_id) { AND cur_timestamp > date_sub(now(),interval 1 day) ORDER BY value desc,cur_timestamp LIMIT $lines", - array($user_id)); + [$user_id]); if (cacti_sizeof($data)) { foreach ($data as $key => $row) { @@ -711,7 +703,6 @@ function extrem($panel, $user_id) { } $fin_data[$key]['pout'] = $row['date'] . ' ' . $row['value'] . ' '; - } } } @@ -764,18 +755,19 @@ function extrem($panel, $user_id) { // Create table from data $panel['data'] = '
' . __('Device', 'intropage') . '' . __('Device', 'intropage') . '' . __('Messages', 'intropage') . '
' . html_escape($device['ip']) . '' . $device['hcount']. '
' . html_escape($device['ip']) . '' . $device['hcount'] . '
' . __('Poller Type:', 'intropage') .' ' . __('Spine', 'intropage') . '
' . __('Poller Type:', 'intropage') . ' ' . __('Spine', 'intropage') . '
' . __('Spine version: ', 'intropage') . $spine_version . '
' . __('You are using incorrect spine version!', 'intropage') . '
' . __('Poller Type: ', 'intropage') . ' ' . $poller_options[read_config_option('poller_type')] . '
' . __('Poller Type: ', 'intropage') . ' ' . $poller_options[read_config_option('poller_type')] . '

' . __('Current Boost Table(s) Size: %s', human_filesize($data_length), 'intropage') . '
' . __('Avg Bytes/Record: %s', human_filesize($avg_row_length), 'intropage') . '
'; - foreach($columns as $col) { + foreach ($columns as $col) { $panel['data'] .= ''; } $panel['data'] .= ''; $i = 0; - foreach($fin_data as $key => $rdata) { - $panel['data'] .= ''; - foreach($columns as $index => $col) { - $panel['data'] .= ''; + foreach ($fin_data as $key => $rdata) { + $panel['data'] .= ''; + + foreach ($columns as $index => $col) { + $panel['data'] .= ''; } $panel['data'] .= ''; @@ -785,26 +777,26 @@ function extrem($panel, $user_id) { $panel['data'] .= '
' . $col . '
' . (isset($rdata[$index]) ? $rdata[$index]:'-') . '
' . (isset($rdata[$index]) ? $rdata[$index] : '-') . '
'; } else { - $panel['data'] .= __('Waiting for data', 'intropage'); + $panel['data'] .= __('Waiting for data', 'intropage'); } save_panel_result($panel, $user_id); } -//------------------------------------ extrem ----------------------------------------------------- +// ------------------------------------ extrem ----------------------------------------------------- function extrem_detail() { global $config, $console_access; $poller_interval = read_config_option('poller_interval'); - $panel = array( + $panel = [ 'name' => __('48 Hour Extreme Polling', 'intropage'), 'alarm' => 'grey', 'detail' => '', - ); + ]; - $trows = array(); - $header = array(); + $trows = []; + $header = []; $panel['detail'] .= '' . ''; @@ -820,14 +812,15 @@ function extrem_detail() { LIMIT 25"); if (cacti_sizeof($data)) { - $j = 0; + $j = 0; $header[] = __('Long Running Poller', 'intropage'); $i = 0; + foreach ($data as $row) { - if (($row['xvalue']/$poller_interval) > 0.9) { + if (($row['xvalue'] / $poller_interval) > 0.9) { $color = 'red'; - } elseif (($row['xvalue']/$poller_interval) > 0.7) { + } elseif (($row['xvalue'] / $poller_interval) > 0.7) { $color = 'yellow'; } else { $color = 'green'; @@ -840,14 +833,14 @@ function extrem_detail() { } // max host down - $data = db_fetch_assoc_prepared ("SELECT date_format(cur_timestamp,'%d.%m. %H:%i') AS `date`, value + $data = db_fetch_assoc_prepared("SELECT date_format(cur_timestamp,'%d.%m. %H:%i') AS `date`, value FROM plugin_intropage_trends WHERE name='host_down' AND user_id = ? AND cur_timestamp > date_sub(now(),interval 2 day) ORDER BY value desc,cur_timestamp LIMIT 25", - array($_SESSION['sess_user_id'])); + [$_SESSION['sess_user_id']]); if (cacti_sizeof($data)) { $j++; @@ -855,6 +848,7 @@ function extrem_detail() { $header[] = __('Max Device Down', 'intropage'); $i = 0; + foreach ($data as $row) { if ($row['value'] > 0) { $color = 'red'; @@ -869,7 +863,6 @@ function extrem_detail() { } if (api_plugin_is_enabled('thold')) { - $data = db_fetch_assoc_prepared("SELECT date_format(cur_timestamp,'%d.%m. %H:%i') AS `date`, value FROM plugin_intropage_trends WHERE name='thold_trig' @@ -877,7 +870,7 @@ function extrem_detail() { AND cur_timestamp > date_sub(now(), interval 2 day) ORDER BY value desc,cur_timestamp LIMIT 25", - array($_SESSION['sess_user_id'])); + [$_SESSION['sess_user_id']]); if (cacti_sizeof($data)) { $j++; @@ -885,6 +878,7 @@ function extrem_detail() { $header[] = __('Max Thold Triggered', 'intropage'); $i = 0; + foreach ($data as $row) { if ($row['value'] > 0) { $color = 'red'; @@ -914,6 +908,7 @@ function extrem_detail() { $header[] = __('Poller Output Item', 'intropage'); $i = 0; + foreach ($data as $row) { if ($row['value'] > 0) { $color = 'red'; @@ -921,7 +916,7 @@ function extrem_detail() { $color = 'green'; } - $trows[$i][$j] = $row['date'] . ' ' . $row['value'] . ' '; + $trows[$i][$j] = $row['date'] . ' ' . $row['value'] . ' '; $i++; } } @@ -934,7 +929,7 @@ function extrem_detail() { AND cur_timestamp > date_sub(now(),interval 2 day) ORDER BY value desc,cur_timestamp LIMIT 25", - array($_SESSION['sess_user_id'])); + [$_SESSION['sess_user_id']]); if (cacti_sizeof($data)) { $j++; @@ -942,15 +937,15 @@ function extrem_detail() { $header[] = __('Failed Polls', 'intropage'); $i = 0; + foreach ($data as $row) { $trows[$i][$j] = $row['date'] . ' ' . $row['value']; $i++; } } - + // host poller errros if (db_table_exists('host_errors')) { - $data = db_fetch_assoc("SELECT date_format(time(cur_timestamp),'%H:%i') AS `date`, value FROM plugin_intropage_trends WHERE name = 'host_errors' @@ -964,6 +959,7 @@ function extrem_detail() { $header[] = __('Host errors', 'intropage'); $i = 0; + foreach ($data as $row) { if ($row['value'] > 0) { $color = 'red'; @@ -971,23 +967,24 @@ function extrem_detail() { $color = 'green'; } - $trows[$i][$j] = $row['date'] . ' ' . $row['value'] . ' '; + $trows[$i][$j] = $row['date'] . ' ' . $row['value'] . ' '; $i++; } } } } - foreach($header as $h) { + foreach ($header as $h) { $panel['detail'] .= ''; } $panel['detail'] .= ''; - for($k = 0; $k < $i; $k++) { + for ($k = 0; $k < $i; $k++) { $panel['detail'] .= ''; - for($l = 0; $l <= $j; $l++) { - $panel['detail'] .= ''; + + for ($l = 0; $l <= $j; $l++) { + $panel['detail'] .= ''; } $panel['detail'] .= ''; @@ -997,4 +994,3 @@ function extrem_detail() { return $panel; } - diff --git a/panellib/thold.php b/panellib/thold.php index 7b3680b..b736d9f 100644 --- a/panellib/thold.php +++ b/panellib/thold.php @@ -27,13 +27,13 @@ function register_thold() { global $registry; - $registry['thold'] = array( + $registry['thold'] = [ 'name' => __('Threshold Panels', 'intropage'), 'description' => __('Panels that provide information about Cacti Thresholding Plugin.', 'intropage') - ); + ]; - $panels = array( - 'thold_event' => array( + $panels = [ + 'thold_event' => [ 'name' => __('Last Threshold Events', 'intropage'), 'description' => __('Threshold Plugin Latest Events', 'intropage'), 'class' => 'thold', @@ -50,8 +50,8 @@ function register_thold() { 'update_func' => 'thold_event', 'details_func' => 'thold_event_detail', 'trends_func' => false - ), - 'graph_thold' => array( + ], + 'graph_thold' => [ 'name' => __('Threshold', 'intropage'), 'description' => __('Threshold Plugin Graph (all, triggered, ...)', 'intropage'), 'class' => 'thold', @@ -68,19 +68,20 @@ function register_thold() { 'update_func' => 'graph_thold', 'details_func' => 'graph_thold_detail', 'trends_func' => 'thold_collect' - ), - ); + ], + ]; return $panels; } -//------------------------------------ thold event ----------------------------------------------------- +// ------------------------------------ thold event ----------------------------------------------------- function thold_event($panel, $user_id) { global $config; $lines = get_panel_lines_count($panel['height'], $user_id); $important_period = read_user_setting('intropage_important_period', read_config_option('intropage_important_period'), false, $user_id); + if ($important_period == -1) { $important_period = time(); } @@ -88,18 +89,18 @@ function thold_event($panel, $user_id) { $panel['alarm'] = 'green'; if (!api_plugin_is_enabled('thold')) { - $panel['alarm'] = 'yellow'; - $panel['data'] = __('Plugin Thold isn\'t installed or started', 'intropage'); - $panel['detail'] = FALSE; + $panel['alarm'] = 'yellow'; + $panel['data'] = __('Plugin Thold isn\'t installed or started', 'intropage'); + $panel['detail'] = false; } else { $simple_perms = get_simple_device_perms($user_id); if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -131,11 +132,10 @@ function thold_event($panel, $user_id) { ORDER BY `time` DESC LIMIT " . $lines); } else { - $data = array(); + $data = []; } if (cacti_sizeof($data)) { - $panel['data'] .= '
' . $h . '
' . (isset($trows[$k][$l]) ? $trows[$k][$l]:__('N/A', 'intropage')) . '' . (isset($trows[$k][$l]) ? $trows[$k][$l] : __('N/A', 'intropage')) . '
'; foreach ($data as $row) { @@ -143,7 +143,7 @@ function thold_event($panel, $user_id) { $color = 'grey'; - if ($row['time'] > (time()-($important_period))) { + if ($row['time'] > (time() - ($important_period))) { if (preg_match('/(NORMAL)/i', $row['description'])) { $color = 'green'; } elseif (preg_match('/(ALERT|ERROR)/i', $row['description'])) { @@ -178,7 +178,7 @@ function thold_event($panel, $user_id) { $panel['alarm'] == 'yellow'; } } - + $panel['data'] .= '
'; } else { $panel['data'] = __('Without events yet', 'intropage'); @@ -188,7 +188,7 @@ function thold_event($panel, $user_id) { save_panel_result($panel, $user_id); } -//------------------------------------ graph_thold ----------------------------------------------------- +// ------------------------------------ graph_thold ----------------------------------------------------- function graph_thold($panel, $user_id, $timespan = 0) { global $config; @@ -196,26 +196,24 @@ function graph_thold($panel, $user_id, $timespan = 0) { include_once($config['base_path'] . '/plugins/thold/thold_functions.php'); - $graph = array ( - 'line' => array( + $graph = [ + 'line' => [ 'title' => __('Thresholds: ', 'intropage'), - 'label1' => array(), - 'data1' => array(), - 'label2' => array(), - 'data2' => array(), - 'label3' => array(), - 'data3' => array(), - ), - ); + 'label1' => [], + 'data1' => [], + 'label2' => [], + 'data2' => [], + 'label3' => [], + 'data3' => [], + ], + ]; if (!api_plugin_is_enabled('thold')) { $panel['alarm'] = 'grey'; $panel['data'] = __('Thold plugin not installed/running', 'intropage'); } elseif (api_plugin_user_realm_auth('thold_graph.php')) { - - if ($timespan == 0) { - if (isset($_SESSION['sess_user_id'])) { + if (isset($_SESSION['sess_user_id'])) { $timespan = read_user_setting('intropage_timespan', read_config_option('intropage_timespan'), $_SESSION['sess_user_id']); } else { $timespan = $panel['refresh']; @@ -226,7 +224,7 @@ function graph_thold($panel, $user_id, $timespan = 0) { $refresh = db_fetch_cell_prepared('SELECT refresh_interval FROM plugin_intropage_panel_data WHERE id = ?', - array($panel['id'])); + [$panel['id']]); } else { $refresh = $panel['refresh']; } @@ -236,24 +234,21 @@ function graph_thold($panel, $user_id, $timespan = 0) { WHERE cur_timestamp > date_sub(NOW(), INTERVAL ? SECOND) AND name = 'thold_trig' ORDER BY cur_timestamp ASC", - array($timespan)); + [$timespan]); if (cacti_sizeof($rows)) { - - $graph['line']['title1'] = __('Triggered', 'intropage'); + $graph['line']['title1'] = __('Triggered', 'intropage'); $graph['line']['unit1']['title'] = 'Triggered'; foreach ($rows as $row) { - $graph['line']['label1'][] = $row['date']; $graph['line']['data1'][] = $row['value']; - $last = $row['value']; + $last = $row['value']; } if ($last > 0) { $panel['alarm'] = 'red'; } - } else { unset($graph['line']['label1']); unset($graph['line']['data1']); @@ -264,23 +259,21 @@ function graph_thold($panel, $user_id, $timespan = 0) { WHERE cur_timestamp > date_sub(NOW(), INTERVAL ? SECOND) AND name = 'thold_brea' ORDER BY cur_timestamp ASC", - array($timespan)); + [$timespan]); if (cacti_sizeof($rows)) { - - $graph['line']['title2'] = __('Breached', 'intropage'); + $graph['line']['title2'] = __('Breached', 'intropage'); $graph['line']['unit2']['title'] = 'Breached'; foreach ($rows as $row) { $graph['line']['label2'][] = $row['date']; $graph['line']['data2'][] = $row['value']; - $last = $row['value']; + $last = $row['value']; } if ($last > 0 && $panel['alarm'] == 'green') { $panel['alarm'] = 'yellow'; } - } else { unset($graph['line']['label2']); unset($graph['line']['data2']); @@ -291,17 +284,16 @@ function graph_thold($panel, $user_id, $timespan = 0) { WHERE cur_timestamp > date_sub(NOW(), INTERVAL ? SECOND) AND name = 'thold_disa' ORDER BY cur_timestamp ASC", - array($timespan)); + [$timespan]); if (cacti_sizeof($rows)) { - - $graph['line']['title3'] = __('Disabled', 'intropage'); + $graph['line']['title3'] = __('Disabled', 'intropage'); $graph['line']['unit3']['title'] = 'Disabled'; foreach ($rows as $row) { $graph['line']['label3'][] = $row['date']; $graph['line']['data3'][] = $row['value']; - } + } } else { unset($graph['line']['label3']); unset($graph['line']['data3']); @@ -320,20 +312,20 @@ function graph_thold($panel, $user_id, $timespan = 0) { save_panel_result($panel, $user_id); } -//------------------------------------ graph_thold ----------------------------------------------------- +// ------------------------------------ graph_thold ----------------------------------------------------- function graph_thold_detail() { global $config, $sql_where; include_once($config['base_path'] . '/plugins/thold/thold_functions.php'); - $panel = array( + $panel = [ 'name' => __('Threshold Details', 'intropage'), 'alarm' => 'green', 'detail' => '', - ); + ]; if (!api_plugin_is_enabled('thold')) { - $panel['alarm'] = 'grey'; + $panel['alarm'] = 'grey'; $panel['detail'] = __('Thold plugin not installed/running', 'intropage'); unset($panel['pie']); } elseif (api_plugin_user_realm_auth('thold_graph.php')) { @@ -343,25 +335,25 @@ function graph_thold_detail() { $t_disa = 0; $sql_where = ''; - $x = get_allowed_thresholds($sql_where, 'null', 1, $t_all, $_SESSION['sess_user_id']); + $x = get_allowed_thresholds($sql_where, 'null', 1, $t_all, $_SESSION['sess_user_id']); if (db_column_exists('thold_data', 'thold_per_enabled')) { - $cond_ena = "(td.thold_enabled = 'on' AND td.thold_per_enabled = 'on')"; + $cond_ena = "(td.thold_enabled = 'on' AND td.thold_per_enabled = 'on')"; $cond_disa = "(td.thold_per_enabled = '' OR td.thold_enabled = '')"; } else { - $cond_ena = "td.thold_enabled = 'on'"; + $cond_ena = "td.thold_enabled = 'on'"; $cond_disa = "td.thold_enabled = ''"; } - $sql_where = "( h.status = 3 AND ( " . $cond_ena . " AND (td.thold_alert != 0 OR td.bl_alert > 0)))"; + $sql_where = '( h.status = 3 AND ( ' . $cond_ena . ' AND (td.thold_alert != 0 OR td.bl_alert > 0)))'; $t_brea_result = get_allowed_thresholds($sql_where, 'null', '', $t_brea, $_SESSION['sess_user_id']); - $sql_where = " h.status = 3 AND " . $cond_ena . " AND ((td.thold_alert != 0 AND td.thold_fail_count >= td.thold_fail_trigger) - OR (td.bl_alert > 0 AND td.bl_fail_count >= td.bl_fail_trigger))"; + $sql_where = ' h.status = 3 AND ' . $cond_ena . ' AND ((td.thold_alert != 0 AND td.thold_fail_count >= td.thold_fail_trigger) + OR (td.bl_alert > 0 AND td.bl_fail_count >= td.bl_fail_trigger))'; $t_trig_result = get_allowed_thresholds($sql_where, 'null', '', $t_trig, $_SESSION['sess_user_id']); - $sql_where = " h.status = 3 AND " . $cond_disa; - $x = get_allowed_thresholds($sql_where, 'null', 1, $t_disa, $_SESSION['sess_user_id']); + $sql_where = ' h.status = 3 AND ' . $cond_disa; + $x = get_allowed_thresholds($sql_where, 'null', 1, $t_disa, $_SESSION['sess_user_id']); $count = $t_all + $t_brea + $t_trig + $t_disa; @@ -374,35 +366,35 @@ function graph_thold_detail() { $url_prefix = ''; $panel['detail'] .= ' - ' . sprintf($url_prefix, '-1') . __('All', 'intropage') . ' + ' . sprintf($url_prefix, '-1') . __('All', 'intropage') . ' ' . number_format_i18n($t_all, -1) . ''; $panel['detail'] .= ' - ' . sprintf($url_prefix, '1') . __('Breached', 'intropage') . ' + ' . sprintf($url_prefix, '1') . __('Breached', 'intropage') . ' ' . number_format_i18n($t_brea, -1) . ''; $panel['detail'] .= ' - ' . sprintf($url_prefix, '3') . __('Triggered', 'intropage') . ' + ' . sprintf($url_prefix, '3') . __('Triggered', 'intropage') . ' ' . number_format_i18n($t_trig, -1) . ''; $panel['detail'] .= ' - ' . sprintf($url_prefix, '0') . __('Disabled', 'intropage') . ' + ' . sprintf($url_prefix, '0') . __('Disabled', 'intropage') . ' ' . number_format_i18n($t_disa, -1) . ''; } else { $panel['detail'] .= ' - ' . __('All', 'intropage') . ' + ' . __('All', 'intropage') . ' ' . number_format_i18n($t_all, -1) . ''; $panel['detail'] .= ' - ' . __('Breached', 'intropage') . ' + ' . __('Breached', 'intropage') . ' ' . number_format_i18n($t_brea, -1) . ''; $panel['detail'] .= ' - ' . __('Triggered', 'intropage') . ' + ' . __('Triggered', 'intropage') . ' ' . number_format_i18n($t_trig, -1) . ''; $panel['detail'] .= ' - ' . __('Disabled', 'intropage') . ' + ' . __('Disabled', 'intropage') . ' ' . number_format_i18n($t_disa, -1) . ''; } @@ -422,7 +414,7 @@ function graph_thold_detail() { if ($t_trig > 0) { $panel['alarm'] = 'red'; - $panel['detail'] .= '' . __('Triggered: ', 'intropage') .'
'; + $panel['detail'] .= '' . __('Triggered: ', 'intropage') . '
'; foreach ($t_trig_result as $host) { $panel['detail'] .= html_escape($host['name_cache']) . '
'; @@ -436,33 +428,32 @@ function graph_thold_detail() { return $panel; } -//------------------------------------ thold_events ----------------------------------------------------- +// ------------------------------------ thold_events ----------------------------------------------------- function thold_event_detail() { global $config; include_once($config['base_path'] . '/plugins/thold/thold_functions.php'); - $panel = array( + $panel = [ 'name' => __('Last Threshold Events', 'intropage'), 'alarm' => 'green', 'detail' => '', - ); + ]; if (!api_plugin_is_enabled('thold')) { $panel['alarm'] = 'yellow'; $panel['detail'] = __('Plugin Thold isn\'t installed or started', 'intropage'); } else { - $simple_perms = get_simple_device_perms($_SESSION['sess_user_id']); if (!$simple_perms) { - $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; - $q_host_cond = 'WHERE td.host_id ' . $host_cond; - } else { - $allowed_devices = false; - $q_host_cond = ''; - } + $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); + $host_cond = 'IN (' . $allowed_devices . ')'; + $q_host_cond = 'WHERE td.host_id ' . $host_cond; + } else { + $allowed_devices = false; + $q_host_cond = ''; + } $data = db_fetch_assoc("SELECT tl.description as description,tl.time as time, tl.status as status, uap0.user_id AS user0, uap1.user_id AS user1, uap2.user_id AS user2 @@ -494,10 +485,11 @@ function thold_event_detail() { ' . __('Date', 'intropage') . ''; $i = 0; + foreach ($data as $row) { - $class = ($i % 2 == 0 ? 'odd':'even'); + $class = ($i % 2 == 0 ? 'odd' : 'even'); $panel['detail'] .= ' - ' . html_escape($row['description']) . ' + ' . html_escape($row['description']) . ' ' . date('Y-m-d H:i:s', $row['time']) . ' '; @@ -536,10 +528,10 @@ function thold_collect() { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user['id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -547,58 +539,56 @@ function thold_collect() { } if ($allowed_devices !== false || $simple_perms) { - - $x = ''; + $x = ''; $sql_where = ''; if (db_column_exists('thold_data', 'thold_per_enabled')) { - $cond_ena = "(td.thold_enabled = 'on' AND td.thold_per_enabled = 'on')"; + $cond_ena = "(td.thold_enabled = 'on' AND td.thold_per_enabled = 'on')"; $cond_disa = "(td.thold_per_enabled = '' OR td.thold_enabled = '')"; } else { - $cond_ena = "td.thold_enabled = 'on'"; + $cond_ena = "td.thold_enabled = 'on'"; $cond_disa = "td.thold_enabled = ''"; } - $sql_where = "( h.status = 3 AND ( " . $cond_ena . " AND (td.thold_alert != 0 OR td.bl_alert > 0)))"; + $sql_where = '( h.status = 3 AND ( ' . $cond_ena . ' AND (td.thold_alert != 0 OR td.bl_alert > 0)))'; $t_brea_result = get_allowed_thresholds($sql_where, 'null', 1, $t_brea, $user['id']); - $sql_where = " h.status = 3 AND " . $cond_ena . " AND ((td.thold_alert != 0 AND td.thold_fail_count >= td.thold_fail_trigger) - OR (td.bl_alert > 0 AND td.bl_fail_count >= td.bl_fail_trigger))"; + $sql_where = ' h.status = 3 AND ' . $cond_ena . ' AND ((td.thold_alert != 0 AND td.thold_fail_count >= td.thold_fail_trigger) + OR (td.bl_alert > 0 AND td.bl_fail_count >= td.bl_fail_trigger))'; $t_trig_result = get_allowed_thresholds($sql_where, 'null', 1, $t_trig, $user['id']); - $sql_where = " h.status = 3 AND " . $cond_disa; - $x = get_allowed_thresholds($sql_where, 'null', 1, $t_disa, $user['id']); + $sql_where = ' h.status = 3 AND ' . $cond_disa; + $x = get_allowed_thresholds($sql_where, 'null', 1, $t_disa, $user['id']); db_execute_prepared("INSERT INTO plugin_intropage_trends (name,value,user_id) VALUES ('thold_brea', ?, ?)", - array($t_brea, $user['id'])); + [$t_brea, $user['id']]); db_execute_prepared("INSERT INTO plugin_intropage_trends (name,value,user_id) VALUES ('thold_disa', ?, ?)", - array($t_disa, $user['id'])); + [$t_disa, $user['id']]); db_execute_prepared("INSERT INTO plugin_intropage_trends (name,value,user_id) VALUES ('thold_trig', ?, ?)", - array($t_trig, $user['id'])); + [$t_trig, $user['id']]); } else { db_execute_prepared("INSERT INTO plugin_intropage_trends (name,value,user_id) VALUES ('thold_brea', 0, ?)", - array($user['id'])); + [$user['id']]); db_execute_prepared("INSERT INTO plugin_intropage_trends (name,value,user_id) VALUES ('thold_disa', 0, ?)", - array($user['id'])); + [$user['id']]); db_execute_prepared("INSERT INTO plugin_intropage_trends (name,value,user_id) VALUES ('thold_trig', 0, ?)", - array($user['id'])); + [$user['id']]); } } } - diff --git a/panellib/top5.php b/panellib/top5.php index 8ac156c..29e2411 100644 --- a/panellib/top5.php +++ b/panellib/top5.php @@ -27,13 +27,13 @@ function register_top5() { global $registry; - $registry['top5'] = array( + $registry['top5'] = [ 'name' => __('Top/Bottom 5 Panels', 'intropage'), 'description' => __('Panels that provide information trending information about Cacti data collection.', 'intropage') - ); + ]; - $panels = array( - 'top5_ping' => array( + $panels = [ + 'top5_ping' => [ 'name' => __('Bottom Ping', 'intropage'), 'description' => __('Devices with the worst ping response', 'intropage'), 'class' => 'top5', @@ -50,8 +50,8 @@ function register_top5() { 'update_func' => 'top5_ping', 'details_func' => 'top5_ping_detail', 'trends_func' => false - ), - 'top5_availability' => array( + ], + 'top5_availability' => [ 'name' => __('Bottom Availability', 'intropage'), 'description' => __('Devices with the worst availability/reachability', 'intropage'), 'class' => 'top5', @@ -68,8 +68,8 @@ function register_top5() { 'update_func' => 'top5_availability', 'details_func' => 'top5_availability_detail', 'trends_func' => false - ), - 'top5_polltime' => array( + ], + 'top5_polltime' => [ 'name' => __('Bottom Polling Time', 'intropage'), 'description' => __('Devices with the worst polling time', 'intropage'), 'class' => 'top5', @@ -86,8 +86,8 @@ function register_top5() { 'update_func' => 'top5_polltime', 'details_func' => 'top5_polltime_detail', 'trends_func' => false - ), - 'top5_pollratio' => array( + ], + 'top5_pollratio' => [ 'name' => __('Bottom Polling Ratio', 'intropage'), 'description' => __('Devices with the worst polling ratio', 'intropage'), 'class' => 'top5', @@ -104,13 +104,13 @@ function register_top5() { 'update_func' => 'top5_pollratio', 'details_func' => 'top5_pollratio_detail', 'trends_func' => false - ), - ); + ], + ]; return $panels; } -//------------------------------------ top5_worst_ping ----------------------------------------------------- +// ------------------------------------ top5_worst_ping ----------------------------------------------------- function top5_ping($panel, $user_id) { global $config; @@ -122,10 +122,10 @@ function top5_ping($panel, $user_id) { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -143,21 +143,22 @@ function top5_ping($panel, $user_id) { LIMIT " . $lines); if (cacti_sizeof($sql_worst_host)) { - $color = read_config_option('intropage_alert_worst_ping'); - list($red, $yellow) = explode ('/', $color); + $color = read_config_option('intropage_alert_worst_ping'); + [$red, $yellow] = explode('/', $color); $panel['data'] = '' . '' . - '' . + '' . '' . '' . ''; $i = 0; + foreach ($sql_worst_host as $host) { if ($host['cur_time'] > $red) { $panel['alarm'] = 'red'; - $color = 'red'; + $color = 'red'; } elseif ($host['cur_time'] > $yellow) { if ($panel['alarm'] == 'green') { $panel['alarm'] = 'yellow'; @@ -168,9 +169,9 @@ function top5_ping($panel, $user_id) { } if ($console_access) { - $row = ''; + $row = ''; } else { - $row = ''; + $row = ''; } $row .= "'; @@ -192,7 +193,7 @@ function top5_ping($panel, $user_id) { save_panel_result($panel, $user_id); } -//------------------------------------ top5_availability ----------------------------------------------------- +// ------------------------------------ top5_availability ----------------------------------------------------- function top5_availability($panel, $user_id) { global $config; @@ -204,10 +205,10 @@ function top5_availability($panel, $user_id) { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -225,20 +226,21 @@ function top5_availability($panel, $user_id) { LIMIT " . $lines); if (cacti_sizeof($sql_worst_host)) { - $color = read_config_option('intropage_alert_worst_availability'); - list($red, $yellow) = explode ('/', $color); + $color = read_config_option('intropage_alert_worst_availability'); + [$red, $yellow] = explode('/', $color); $panel['data'] = '
' . __('Host', 'intropage') . '' . __('Host', 'intropage') . '' . __('Average', 'intropage') . '' . __('Current', 'intropage') . '
' . html_escape(substr($host['description'],0,37)) . '
' . html_escape(substr($host['description'],0,37)) . '
' . html_escape(substr($host['description'],0,37)) . '
' . html_escape(substr($host['description'],0,37)) . '" . round($host['avg_time'], 2) . ' ms
' . '' . - '' . + '' . '' . ''; $i = 0; + foreach ($sql_worst_host as $host) { if ($host['availability'] < $red) { $panel['alarm'] = 'red'; - $color = 'red'; + $color = 'red'; } elseif ($host['availability'] < $yellow) { if ($panel['alarm'] == 'green') { $panel['alarm'] = 'yellow'; @@ -249,9 +251,9 @@ function top5_availability($panel, $user_id) { } if ($console_access) { - $row = ''; + $row = ''; } else { - $row = ''; + $row = ''; } $row .= ""; @@ -272,7 +274,7 @@ function top5_availability($panel, $user_id) { save_panel_result($panel, $user_id); } -//------------------------------------ top5_worst_polltime ----------------------------------------------------- +// ------------------------------------ top5_worst_polltime ----------------------------------------------------- function top5_polltime($panel, $user_id) { global $config; @@ -284,10 +286,10 @@ function top5_polltime($panel, $user_id) { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -305,20 +307,21 @@ function top5_polltime($panel, $user_id) { LIMIT " . $lines); if (cacti_sizeof($sql_worst_host)) { - $color = read_config_option('intropage_alert_worst_polling_time'); - list($red, $yellow) = explode ('/', $color); + $color = read_config_option('intropage_alert_worst_polling_time'); + [$red, $yellow] = explode('/', $color); $panel['data'] = '
' . __('Hostname', 'intropage') . '' . __('Hostname', 'intropage') . '' . __('Availability/Reachability', 'intropage') . '
' . html_escape(substr($host['description'], 0, 37)) . '
' . html_escape(substr($host['description'], 0, 37)) . '
' . html_escape(substr($host['description'], 0, 37)) . '
' . html_escape(substr($host['description'], 0, 37)) . '" . round($host['availability'],2) . " %
' . '' . - '' . + '' . '' . ''; $i = 0; + foreach ($sql_worst_host as $host) { if ($host['polling_time'] > $red) { $panel['alarm'] = 'red'; - $color = 'red'; + $color = 'red'; } elseif ($host['polling_time'] > $yellow) { if ($panel['alarm'] == 'green') { $panel['alarm'] = 'yellow'; @@ -329,9 +332,9 @@ function top5_polltime($panel, $user_id) { } if ($console_access) { - $row = ''; + $row = ''; } else { - $row = ''; + $row = ''; } $row .= ""; @@ -352,7 +355,7 @@ function top5_polltime($panel, $user_id) { save_panel_result($panel, $user_id); } -//------------------------------------ top5_worst_pollratio ----------------------------------------------------- +// ------------------------------------ top5_worst_pollratio ----------------------------------------------------- function top5_pollratio($panel, $user_id) { global $config; @@ -364,10 +367,10 @@ function top5_pollratio($panel, $user_id) { if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($user_id); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -386,23 +389,24 @@ function top5_pollratio($panel, $user_id) { LIMIT " . $lines); if (cacti_sizeof($sql_worst_host)) { - $color = read_config_option('intropage_alert_worst_polling_ratio'); - list($red, $yellow) = explode ('/', $color); + $color = read_config_option('intropage_alert_worst_polling_ratio'); + [$red, $yellow] = explode('/', $color); $panel['data'] = '
' . __('Host', 'intropage') . '' . __('Host', 'intropage') . '' . __('Polling Time', 'intropage') . '
' . html_escape(substr($host['description'], 0, 37)) . '
' . html_escape(substr($host['description'], 0, 37)) . '
' . html_escape(substr($host['description'], 0, 37)) . '
' . html_escape(substr($host['description'], 0, 37)) . '" . __('%s Secs', round($host['polling_time'], 2), 'intropage') . "
' . '' . - '' . + '' . '' . - '' . - '' . + '' . + '' . ''; $i = 0; + foreach ($sql_worst_host as $host) { if ($host['ratio'] > $red) { $panel['alarm'] = 'red'; - $color = 'red'; - } elseif ( $host['ratio'] > $yellow) { + $color = 'red'; + } elseif ($host['ratio'] > $yellow) { if ($panel['alarm'] == 'green') { $panel['alarm'] = 'yellow'; } @@ -412,14 +416,14 @@ function top5_pollratio($panel, $user_id) { } if ($console_access) { - $row = ''; + $row = ''; } else { - $row = ''; + $row = ''; } $row .= "'; - $row .= "'; - $row .= ""; + $row .= "'; + $row .= ""; $panel['data'] .= $row; @@ -437,24 +441,24 @@ function top5_pollratio($panel, $user_id) { save_panel_result($panel, $user_id); } -//------------------------------------ top5_worst_ping ----------------------------------------------------- +// ------------------------------------ top5_worst_ping ----------------------------------------------------- function top5_ping_detail() { global $config, $console_access; - $panel = array( + $panel = [ 'name' => __('Top 20 Hosts with Worst Ping', 'intropage'), 'alarm' => 'green', 'detail' => '', - ); + ]; $simple_perms = get_simple_device_perms($_SESSION['sess_user_id']); if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -469,26 +473,27 @@ function top5_ping_detail() { ORDER BY cur_time desc LIMIT 40"); } else { - $sql_worst_host = array(); + $sql_worst_host = []; } if (cacti_sizeof($sql_worst_host)) { - $color = read_config_option('intropage_alert_worst_ping'); - list($red, $yellow) = explode ('/', $color); + $color = read_config_option('intropage_alert_worst_ping'); + [$red, $yellow] = explode('/', $color); $panel['detail'] = '
' . __('Host', 'intropage') . '' . __('Host', 'intropage') . '' . __('Failed', 'intropage') . '' . __('Total', 'intropage') . '' . __('Ratio', 'intropage') . '' . __('Total', 'intropage') . '' . __('Ratio', 'intropage') . '
' . html_escape(substr($host['description'], 0, 37)) . '
' . html_escape(substr($host['description'], 0, 37)) . '
' . html_escape(substr($host['description'], 0, 37)) . '
' . html_escape(substr($host['description'], 0, 37)) . '" . number_format_i18n($host['failed_polls'], 0) . '" . number_format_i18n($host['total_polls'], 0) . '" . round($host['ratio'] * 100, 3) . " %
" . number_format_i18n($host['total_polls'], 0) . '" . round($host['ratio'] * 100, 3) . " %
' . '' . - '' . + '' . '' . '' . ''; $i = 0; + foreach ($sql_worst_host as $host) { if ($host['cur_time'] > $red) { $panel['alarm'] = 'red'; - $color = 'red'; - } elseif ($host['cur_time'] > $yellow) { + $color = 'red'; + } elseif ($host['cur_time'] > $yellow) { if ($panel['alarm'] == 'green') { $panel['alarm'] = 'yellow'; } @@ -498,9 +503,9 @@ function top5_ping_detail() { } if ($console_access) { - $row = ''; + $row = ''; } else { - $row = ''; + $row = ''; } $row .= ''; @@ -519,24 +524,24 @@ function top5_ping_detail() { return $panel; } -//------------------------------------ top5_availability ----------------------------------------------------- +// ------------------------------------ top5_availability ----------------------------------------------------- function top5_availability_detail() { global $config, $console_access; - $panel = array( + $panel = [ 'name' => __('Top 20 Hosts with the Worst Availability', 'intropage'), 'alarm' => 'green', 'detail' => '', - ); + ]; $simple_perms = get_simple_device_perms($_SESSION['sess_user_id']); if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -544,7 +549,6 @@ function top5_availability_detail() { } if ($allowed_devices !== false || $simple_perms) { - $sql_worst_host = db_fetch_assoc("SELECT description, id, availability FROM host WHERE disabled != 'on' @@ -552,24 +556,25 @@ function top5_availability_detail() { ORDER BY availability LIMIT 40"); } else { - $sql_worst_host = array(); + $sql_worst_host = []; } if (cacti_sizeof($sql_worst_host)) { - $color = read_config_option('intropage_alert_worst_availability'); - list($red, $yellow) = explode ('/', $color); + $color = read_config_option('intropage_alert_worst_availability'); + [$red, $yellow] = explode('/', $color); $panel['detail'] = '
' . __('Host', 'intropage') . '' . __('Host', 'intropage') . '' . __('Average', 'intropage') . '' . __('Current', 'intropage') . '
' . html_escape($host['description']) . '
' . html_escape($host['description']) . '
' . html_escape($host['description']) . '
' . html_escape($host['description']) . '' . round($host['avg_time'], 2) . ' ms
' . '' . - '' . + '' . '' . ''; $i = 0; + foreach ($sql_worst_host as $host) { if ($host['availability'] < $red) { $panel['alarm'] = 'red'; - $color = 'red'; + $color = 'red'; } elseif ($host['availability'] < $yellow) { if ($panel['alarm'] == 'green') { $panel['alarm'] = 'yellow'; @@ -580,9 +585,9 @@ function top5_availability_detail() { } if ($console_access) { - $row = ''; + $row = ''; } else { - $row = ''; + $row = ''; } $row .= ""; @@ -600,24 +605,24 @@ function top5_availability_detail() { return $panel; } -//------------------------------------ top5_polltime ----------------------------------------------------- +// ------------------------------------ top5_polltime ----------------------------------------------------- function top5_polltime_detail() { global $config, $console_access; - $panel = array( + $panel = [ 'name' => __('Top 20 Hosts Worst Polling Time', 'intropage'), 'alarm' => 'green', 'detail' => '', - ); + ]; $simple_perms = get_simple_device_perms($_SESSION['sess_user_id']); if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -632,24 +637,25 @@ function top5_polltime_detail() { ORDER BY polling_time DESC LIMIT 40"); } else { - $sql_worst_host = array(); + $sql_worst_host = []; } if (cacti_sizeof($sql_worst_host)) { - $color = read_config_option('intropage_alert_worst_polling_time'); - list($red,$yellow) = explode ('/',$color); + $color = read_config_option('intropage_alert_worst_polling_time'); + [$red,$yellow] = explode('/',$color); $panel['detail'] = '
' . __('Host', 'intropage') . '' . __('Host', 'intropage') . '' . __('Availability', 'intropage') . '
' . html_escape($host['description']) . '
' . html_escape($host['description']) . '
' . html_escape($host['description']) . '
' . html_escape($host['description']) . '" . round($host['availability'], 2) . " %
' . '' . - '' . + '' . '' . ''; $i = 0; + foreach ($sql_worst_host as $host) { if ($host['polling_time'] > $red) { $panel['alarm'] = 'red'; - $color = 'red'; + $color = 'red'; } elseif ($host['polling_time'] > $yellow) { if ($panel['alarm'] == 'green') { $panel['alarm'] = 'yellow'; @@ -660,9 +666,9 @@ function top5_polltime_detail() { } if ($console_access) { - $row = ''; + $row = ''; } else { - $row = ''; + $row = ''; } $row .= ""; @@ -680,24 +686,24 @@ function top5_polltime_detail() { return $panel; } -//------------------------------------ top5_pollratio ----------------------------------------------------- +// ------------------------------------ top5_pollratio ----------------------------------------------------- function top5_pollratio_detail() { global $config, $console_access; - $panel = array( + $panel = [ 'name' => __('Top 20 Hosts with the Worst Polling Ratio', 'intropage'), 'alarm' => 'grey', 'detail' => '', - ); + ]; $simple_perms = get_simple_device_perms($_SESSION['sess_user_id']); if (!$simple_perms) { $allowed_devices = intropage_get_allowed_devices($_SESSION['sess_user_id']); - $host_cond = 'IN (' . $allowed_devices . ')'; + $host_cond = 'IN (' . $allowed_devices . ')'; } else { $allowed_devices = false; - $q_host_cond = ''; + $q_host_cond = ''; } if (!$simple_perms) { @@ -705,7 +711,6 @@ function top5_pollratio_detail() { } if ($allowed_devices !== false || $simple_perms) { - $sql_worst_host = db_fetch_assoc("SELECT id, description, failed_polls, total_polls, CAST(failed_polls/total_polls AS DECIMAL(5,4)) AS ratio FROM host @@ -714,27 +719,28 @@ function top5_pollratio_detail() { ORDER BY ratio DESC LIMIT 40"); } else { - $sql_worst_host = array(); + $sql_worst_host = []; } if (cacti_sizeof($sql_worst_host)) { - $color = read_config_option('intropage_alert_worst_polling_ratio'); - list($red,$yellow) = explode ('/',$color); + $color = read_config_option('intropage_alert_worst_polling_ratio'); + [$red,$yellow] = explode('/',$color); $panel['detail'] = '
' . __('Host', 'intropage') . '' . __('Host', 'intropage') . '' . __('Polling Time', 'intropage') . '
' . html_escape($host['description']) . '
' . html_escape($host['description']) . '
' . html_escape($host['description']) . '
' . html_escape($host['description']) . '" . __('%s Secs', round($host['polling_time'], 2), 'intropage') . "
' . '' . - '' . + '' . '' . - '' . - '' . + '' . + '' . ''; $i = 0; + foreach ($sql_worst_host as $host) { if ($host['ratio'] > $red) { $panel['alarm'] = 'red'; - $color = 'red'; - } elseif ($host['ratio'] > $yellow) { + $color = 'red'; + } elseif ($host['ratio'] > $yellow) { if ($panel['alarm'] == 'green') { $panel['alarm'] = 'yellow'; } @@ -744,14 +750,14 @@ function top5_pollratio_detail() { } if ($console_access) { - $row = ''; + $row = ''; } else { - $row = ''; + $row = ''; } $row .= "'; - $row .= "'; - $row .= ""; + $row .= "'; + $row .= ""; $panel['detail'] .= $row; diff --git a/poller_intropage.php b/poller_intropage.php index 3b7d893..f9de4df 100644 --- a/poller_intropage.php +++ b/poller_intropage.php @@ -24,19 +24,19 @@ +-------------------------------------------------------------------------+ */ -$dir = dirname(__FILE__); +$dir = __DIR__; chdir($dir); include('../../include/cli_check.php'); include_once($config['base_path'] . '/lib/reports.php'); include_once($config['base_path'] . '/plugins/intropage/include/functions.php'); -/* let PHP run just as long as it has to */ +// let PHP run just as long as it has to ini_set('max_execution_time', '0'); error_reporting(E_ALL); -/* record the start time */ +// record the start time $poller_start = microtime(true); $start_date = date('Y-m-d H:i:s'); $force = false; @@ -47,53 +47,53 @@ $run_from_poller = true; -/* process calling arguments */ +// process calling arguments $parms = $_SERVER['argv']; array_shift($parms); if (cacti_sizeof($parms)) { $shortopts = 'VvHh'; - $longopts = array( + $longopts = [ 'force', 'debug', 'version', 'help' - ); + ]; $options = getopt($shortopts, $longopts); - foreach($options as $arg => $value) { + foreach ($options as $arg => $value) { switch($arg) { - case 'force': - $force = true; - - break; - case 'debug': - $debug = true; - - break; - case 'version': - case 'V': - case 'v': - display_version(); - exit(0); - case 'help': - case 'H': - case 'h': - display_help(); - exit(0); - default: - print "ERROR: Invalid Argument: ($arg)" . PHP_EOL . PHP_EOL; - display_help(); - exit(1); + case 'force': + $force = true; + + break; + case 'debug': + $debug = true; + + break; + case 'version': + case 'V': + case 'v': + display_version(); + exit(0); + case 'help': + case 'H': + case 'h': + display_help(); + exit(0); + default: + print "ERROR: Invalid Argument: ($arg)" . PHP_EOL . PHP_EOL; + display_help(); + exit(1); } } } intropage_debug('Intropage Starting Checks'); -/* silently end if the registered process is still running, or process table missing */ +// silently end if the registered process is still running, or process table missing if (function_exists('register_process_start')) { if (!register_process_start('intropage', 'master', $config['poller_id'], read_config_option('intropage_timeout'))) { intropage_debug('Another Intropage Process Still Running'); @@ -108,7 +108,7 @@ $poller_end = microtime(true); -$pstats = 'Time:' . round($poller_end-$poller_start, 2) . ', Checks:' . $stats['checks'] . ', Panels:' . $stats['panels'] . ', Trends:' . $stats['trends']; +$pstats = 'Time:' . round($poller_end - $poller_start, 2) . ', Checks:' . $stats['checks'] . ', Panels:' . $stats['panels'] . ', Trends:' . $stats['trends']; cacti_log('INTROPAGE STATS: ' . $pstats, false, 'SYSTEM'); set_config_option('stats_intropage', $pstats); @@ -136,7 +136,7 @@ function intropage_gather_stats() { $logging = read_config_option('log_verbosity', true); $trends = 0; - $pdata = 0; + $pdata = 0; $checks = 0; $panels = initialize_panel_library(); @@ -159,13 +159,12 @@ function intropage_gather_stats() { OR (last_update IS NULL AND level = 0)'); if (cacti_sizeof($tpanels)) { + $done_trends = []; - $done_trends = array(); + foreach ($tpanels as $panel) { + $start = microtime(true); - foreach($tpanels as $panel) { - $start = microtime(true); - - /* Get trends next */ + // Get trends next if (isset($panel['trends_func']) && $panel['trends_func'] != '' && is_panel_enabled($panel['panel_id'])) { $function = $panel['trends_func']; @@ -173,9 +172,9 @@ function intropage_gather_stats() { db_execute_prepared('UPDATE plugin_intropage_panel_data SET last_trend_update = NOW() WHERE id = ?', - array($panel['id'])); + [$panel['id']]); - /* we need run it only once. Example - graph host panel gathers data for all users */ + // we need run it only once. Example - graph host panel gathers data for all users if (!array_key_exists($panel['panel_id'], $done_trends)) { $function(); $trends++; @@ -188,7 +187,6 @@ function intropage_gather_stats() { } intropage_debug(sprintf('gathering trend function:%s, duration:%4.3f', $function, microtime(true) - $start)); - } else { cacti_log('WARNING: Unable to find update function ' . $function . ' for panel ' . $panel['name'], false, 'INTROPAGE'); } @@ -215,7 +213,7 @@ function intropage_gather_stats() { db_execute_prepared('UPDATE plugin_intropage_panel_data SET refresh_interval = ? WHERE id = ?', - array($panel['refresh'], $upanel['id'])); + [$panel['refresh'], $upanel['id']]); $upanel['refresh_interval'] = $panel['refresh']; } @@ -272,7 +270,7 @@ function intropage_gather_stats() { SET cur_timestamp = now() WHERE name = 'ar_poller_finish'"); - return array('checks' => $checks, 'panels' => $pdata, 'trends' => $trends); + return ['checks' => $checks, 'panels' => $pdata, 'trends' => $trends]; } function intropage_debug($message) { @@ -306,4 +304,3 @@ function display_help() { print ' --force - force execution, e.g. for testing' . PHP_EOL; print ' --debug - debug execution, e.g. for testing' . PHP_EOL . PHP_EOL; } - diff --git a/setup.php b/setup.php index 24eea05..a7a24ff 100644 --- a/setup.php +++ b/setup.php @@ -59,10 +59,10 @@ function plugin_intropage_install() { api_plugin_register_realm('intropage', 'intropage.php', 'Intropage Viewer', 1); api_plugin_register_realm('intropage', 'intropage_admin.php', 'Intropage Administration', 1); - $realms = array( + $realms = [ __('Intropage Viewer', 'intropage'), __('Intropage Administration', 'intropage') - ); + ]; intropage_setup_database(); } @@ -78,10 +78,10 @@ function plugin_intropage_uninstall() { function intropage_config_arrays() { global $intropage_intervals, $trend_timespans, $panel_lines; - auth_augment_roles(__('Normal User'), array('intropage.php')); - auth_augment_roles(__('System Administration'), array('intropage_admin.php')); + auth_augment_roles(__('Normal User'), ['intropage.php']); + auth_augment_roles(__('System Administration'), ['intropage_admin.php']); - $trend_timespans = array( + $trend_timespans = [ 3600 => __('Timespan Last 1 Hour', 'intropage'), 7200 => __('Timespan Last %d Hours', 2, 'intropage'), 10800 => __('Timespan Last %d Hours', 3, 'intropage'), @@ -90,11 +90,11 @@ function intropage_config_arrays() { 43200 => __('Timespan Last %d Hours', 12, 'intropage'), 86400 => __('Timespan Last 1 Day', 'intropage'), 172800 => __('Timespan Last 2 Days', 'intropage') - ); + ]; $poller_interval = read_config_option('poller_interval'); - $intropage_intervals = array( + $intropage_intervals = [ '10' => __('%d Seconds', 10, 'intropage'), '15' => __('%d Seconds', 15, 'intropage'), '20' => __('%d Seconds', 20, 'intropage'), @@ -114,9 +114,9 @@ function intropage_config_arrays() { '28800' => __('%d Hours', 8, 'intropage'), '43200' => __('%d Hours', 12, 'intropage'), '86400' => __('%d Day', 1, 'intropage') - ); + ]; - foreach($intropage_intervals as $key => $name) { + foreach ($intropage_intervals as $key => $name) { if ($key < $poller_interval) { unset($intropage_intervals[$key]); } @@ -199,12 +199,12 @@ function intropage_poller_bottom() { // refresh_interval - in second, min is 60 // priority - for displaying // description - small description, it is visible in user auth settings -function intropage_add_panel($panel_id, $file, $has_detail, $refresh_interval, $priority=20, $description='') { +function intropage_add_panel($panel_id, $file, $has_detail, $refresh_interval, $priority = 20, $description = '') { if (db_execute_prepared('REPLACE INTO plugin_intropage_panel_definition (panel_id,file,has_detail,refresh_interval, priority, description) - VALUES (?,?,?,?,?,?)', array($panel_id,$file,$has_detail,$refresh_interval,$priority,$description)) == 1) { + VALUES (?,?,?,?,?,?)', [$panel_id, $file, $has_detail, $refresh_interval, $priority, $description]) == 1) { + api_plugin_db_add_column('intropage', 'plugin_intropage_user_auth', ['name' => $panel_id, 'type' => 'char(2)', 'NULL' => false, 'default' => 'on']); - api_plugin_db_add_column('intropage', 'plugin_intropage_user_auth', array('name' => $panel_id, 'type' => 'char(2)', 'NULL' => false, 'default' => 'on')); return ('1'); } else { return db_error(); @@ -213,21 +213,20 @@ function intropage_add_panel($panel_id, $file, $has_detail, $refresh_interval, $ // remove third party panel function intropage_remove_panel($panel_id) { - db_execute_prepared('DELETE FROM plugin_intropage_panel_data WHERE panel_id = ?', array($panel_id)); - db_execute_prepared('DELETE FROM plugin_intropage_panel_definition WHERE panel_id = ?', array($panel_id)); - db_execute_prepared('ALTER TABLE plugin_intropage_user_auth DROP ?',array($panel_id)); + db_execute_prepared('DELETE FROM plugin_intropage_panel_data WHERE panel_id = ?', [$panel_id]); + db_execute_prepared('DELETE FROM plugin_intropage_panel_definition WHERE panel_id = ?', [$panel_id]); + db_execute_prepared('ALTER TABLE plugin_intropage_user_auth DROP ?',[$panel_id]); return ('1'); } function intropage_user_remove($user_id) { - db_execute_prepared('DELETE FROM plugin_intropage_panel_data WHERE user_id = ?', array($user_id)); - db_execute_prepared('DELETE FROM plugin_intropage_panel_dashboard WHERE user_id = ?', array($user_id)); - db_execute_prepared('DELETE FROM settings_user WHERE user_id = ?', array($user_id)); - db_execute_prepared('DELETE FROM plugin_intropage_user_auth WHERE user_id = ?', array($user_id)); + db_execute_prepared('DELETE FROM plugin_intropage_panel_data WHERE user_id = ?', [$user_id]); + db_execute_prepared('DELETE FROM plugin_intropage_panel_dashboard WHERE user_id = ?', [$user_id]); + db_execute_prepared('DELETE FROM settings_user WHERE user_id = ?', [$user_id]); + db_execute_prepared('DELETE FROM plugin_intropage_user_auth WHERE user_id = ?', [$user_id]); } function intropage_user_group_remove($group_id) { - db_execute_prepared('DELETE FROM plugin_intropage_user_group_auth WHERE id = ?', array($group_id)); + db_execute_prepared('DELETE FROM plugin_intropage_user_group_auth WHERE id = ?', [$group_id]); } -
' . __('Host', 'intropage') . '' . __('Host', 'intropage') . '' . __('Failed', 'intropage') . '' . __('Total', 'intropage') . '' . __('Ratio', 'intropage') . '' . __('Total', 'intropage') . '' . __('Ratio', 'intropage') . '
' . html_escape($host['description']) . '
' . html_escape($host['description']) . '
' . html_escape($host['description']) . '
' . html_escape($host['description']) . '" . number_format_i18n($host['failed_polls'], 0) . '" . number_format_i18n($host['total_polls'], 0) . '" . round($host['ratio']* 100, 3) . " %
" . number_format_i18n($host['total_polls'], 0) . '" . round($host['ratio'] * 100, 3) . " %