__('Delete'), 2 => __('Enable'), 3 => __('Disable'), 4 => __('Change Device Settings'), 5 => __('Clear Statistics'), 6 => __('Apply Automation Rules'), 7 => __('Sync to Device Template') ); $device_actions = api_plugin_hook_function('device_action_array', $device_actions); /* set default action */ set_default_action(); switch (get_request_var('action')) { case 'save': form_save(); break; case 'actions': form_actions(); break; case 'gt_add': get_filter_request_var('host_id'); host_add_gt(); header('Location: host.php?header=false&action=edit&id=' . get_request_var('host_id')); break; case 'gt_remove': get_filter_request_var('host_id'); host_remove_gt(); header('Location: host.php?header=false&action=edit&id=' . get_request_var('host_id')); break; case 'query_add': get_filter_request_var('host_id'); host_add_query(); header('Location: host.php?header=false&action=edit&id=' . get_request_var('host_id')); break; case 'query_remove': get_filter_request_var('host_id'); host_remove_query(); header('Location: host.php?header=false&action=edit&id=' . get_request_var('host_id')); break; case 'query_change': get_filter_request_var('host_id'); host_change_query(); header('Location: host.php?header=false&action=edit&id=' . get_request_var('host_id')); break; case 'query_reload': get_filter_request_var('host_id'); host_reload_query(); header('Location: host.php?header=false&action=edit&id=' . get_request_var('host_id')); break; case 'query_verbose': get_filter_request_var('host_id'); host_reload_query(); header('Location: host.php?header=' . (isset_request_var('header') && get_nfilter_request_var('header') == 'true' ? 'true':'false') . '&action=edit&id=' . get_request_var('host_id') . '&display_dq_details=true#dqdbg'); break; case 'edit': top_header(); host_edit(); bottom_footer(); break; case 'ping_host': $host_id = get_filter_request_var('id'); api_device_ping_device($host_id); break; case 'enable_debug': enable_device_debug(get_filter_request_var('host_id')); header('Location: host.php?header=false&action=edit&id=' . get_request_var('host_id')); break; case 'disable_debug': disable_device_debug(get_filter_request_var('host_id')); header('Location: host.php?header=false&action=edit&id=' . get_request_var('host_id')); break; default: top_header(); host(); bottom_footer(); break; } /* -------------------------- Global Form Functions -------------------------- */ function add_tree_names_to_actions_array() { global $device_actions; /* add a list of tree names to the actions dropdown */ $trees = db_fetch_assoc('SELECT id, name FROM graph_tree ORDER BY name'); if (sizeof($trees)) { foreach ($trees as $tree) { $device_actions{'tr_' . $tree['id']} = 'Place on a Tree (' . $tree['name'] . ')'; } } } /* -------------------------- The Save Function -------------------------- */ function form_save() { if (isset_request_var('save_component_host')) { if (get_nfilter_request_var('snmp_version') == 3 && (get_nfilter_request_var('snmp_password') != get_nfilter_request_var('snmp_password_confirm'))) { raise_message(4); }else{ get_filter_request_var('id'); get_filter_request_var('host_template_id'); $host_id = api_device_save(get_nfilter_request_var('id'), get_nfilter_request_var('host_template_id'), get_nfilter_request_var('description'), trim(get_nfilter_request_var('hostname')), get_nfilter_request_var('snmp_community'), get_nfilter_request_var('snmp_version'), get_nfilter_request_var('snmp_username'), get_nfilter_request_var('snmp_password'), get_nfilter_request_var('snmp_port'), get_nfilter_request_var('snmp_timeout'), (isset_request_var('disabled') ? get_nfilter_request_var('disabled') : ''), get_nfilter_request_var('availability_method'), get_nfilter_request_var('ping_method'), get_nfilter_request_var('ping_port'), get_nfilter_request_var('ping_timeout'), get_nfilter_request_var('ping_retries'), get_nfilter_request_var('notes'), get_nfilter_request_var('snmp_auth_protocol'), get_nfilter_request_var('snmp_priv_passphrase'), get_nfilter_request_var('snmp_priv_protocol'), get_nfilter_request_var('snmp_context'), get_nfilter_request_var('snmp_engine_id'), get_nfilter_request_var('max_oids'), get_nfilter_request_var('device_threads'), get_nfilter_request_var('poller_id'), get_nfilter_request_var('site_id'), get_nfilter_request_var('external_id')); if ($host_id !== false) { api_plugin_hook_function('host_save', array('host_id' => $host_id)); } } header('Location: host.php?header=false&action=edit&id=' . (empty($host_id) ? get_nfilter_request_var('id') : $host_id)); } } /* ------------------------ The "actions" function ------------------------ */ function form_actions() { global $device_actions, $fields_host_edit; /* ================= input validation ================= */ get_filter_request_var('drp_action', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-zA-Z0-9_]+)$/'))); /* ==================================================== */ /* if we are to save this form, instead of display it */ if (isset_request_var('selected_items')) { $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items')); if ($selected_items != false) { if (get_request_var('drp_action') == '2') { /* Enable Selected Devices */ for ($i=0;($i 0) { api_device_update_host_template($selected_items[$i], $device_template_id); } } }elseif (get_request_var('drp_action') == '1') { /* delete */ if (!isset_request_var('delete_type')) { set_request_var('delete_type', 2); } $data_sources_to_act_on = array(); $graphs_to_act_on = array(); $devices_to_act_on = array(); for ($i=0; $i'; $host_array[$i] = $matches[1]; $i++; } } top_header(); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); form_start('host.php'); html_start_box($device_actions[get_request_var('drp_action')], '60%', '', '3', 'center', ''); if (isset($host_array) && sizeof($host_array)) { if (get_request_var('drp_action') == '2') { /* Enable Devices */ print "

" . __('Click \'Continue\' to enable the following Device(s).') . "

    $host_list
\n"; $save_html = " "; }elseif (get_nfilter_request_var('drp_action') == '3') { /* Disable Devices */ print "

" . __('Click \'Continue\' to disable the following Device(s).') . "

    $host_list
\n"; $save_html = " "; }elseif (get_nfilter_request_var('drp_action') == '4') { /* Change Device options */ print "

" . __('Click \'Continue\' to change the Device options below for multiple Device(s). Please check the box next to the fields you want to update, and then fill in the new value.') . "

    $host_list
\n"; $form_array = array(); while (list($field_name, $field_array) = each($fields_host_edit)) { if ((preg_match('/^snmp_/', $field_name)) || (preg_match('/^ping_/', $field_name)) || ($field_name == 'poller_id') || ($field_name == 'site_id') || ($field_name == 'host_template_id') || ($field_name == 'availability_method') || ($field_name == 'device_threads') || ($field_name == 'max_oids')) { $form_array += array($field_name => $fields_host_edit[$field_name]); $form_array[$field_name]['value'] = ''; $form_array[$field_name]['description'] = ''; $form_array[$field_name]['form_id'] = 0; $form_array[$field_name]['sub_checkbox'] = array( 'name' => 't_' . $field_name, 'friendly_name' => __('Update this Field'), 'value' => '' ); } } draw_edit_form( array( 'config' => array('no_form_tag' => true), 'fields' => $form_array ) ); device_javascript(); $save_html = " "; }elseif (get_request_var('drp_action') == '5') { /* Clear Statisitics for Selected Devices */ print "

" . __('Click \'Continue\' to clear the counters for the following Device(s).') . "

    $host_list
\n"; $save_html = " "; }elseif (get_nfilter_request_var('drp_action') == '7') { /* sync device template */ print "

" . __('Click \'Continue\' to Synchronize the following Device(s) to their Device Template.') . "

    $host_list
\n"; $save_html = " "; }elseif (get_request_var('drp_action') == '1') { /* Delete */ print "

" . __('Click \'Continue\' to delete the following Device(s).') . "

    $host_list
\n"; form_radio_button('delete_type', '2', '1', __('Leave all Graph(s) and Data Source(s) untouched. Data Source(s) will be disabled however.'), '1'); print '
'; form_radio_button('delete_type', '2', '2', __('Delete all associated Graph(s) and Data Source(s).'), '1'); print '
'; print " \n"; $save_html = " "; }elseif (preg_match('/^tr_([0-9]+)$/', get_request_var('drp_action'), $matches)) { /* place on tree */ print "

" . __('Click \'Continue\' to place the following Device(s) under the branch selected below.') . "

    $host_list

" . __('Destination Branch:') . "
\n"; grow_dropdown_tree($matches[1], '0', 'tree_item_id', '0'); print "

\n"; $save_html = " "; }elseif (get_request_var('drp_action') == 6) { /* automation */ print "

" . __('Click \'Continue\' to apply Automation Rules to the following Devices(s).'). "

    $host_list
\n"; $save_html = " "; } else { $save['drp_action'] = get_request_var('drp_action'); $save['host_list'] = $host_list; $save['host_array'] = (isset($host_array)? $host_array : array()); api_plugin_hook_function('device_action_prepare', $save); $save_html = " "; } }else{ print "" . __('You must select at least one device.') . "\n"; $save_html = ""; } print " $save_html \n"; html_end_box(); form_end(); bottom_footer(); } /* ------------------- Data Query Functions ------------------- */ function host_add_query() { /* ================= input validation ================= */ get_filter_request_var('host_id'); get_filter_request_var('snmp_query_id'); get_filter_request_var('reindex_method'); /* ==================================================== */ api_device_dq_add(get_request_var('host_id'), get_request_var('snmp_query_id'), get_request_var('reindex_method')); } function host_reload_query() { /* ================= input validation ================= */ get_filter_request_var('id'); get_filter_request_var('host_id'); /* ==================================================== */ run_data_query(get_request_var('host_id'), get_request_var('id')); } function host_remove_query() { /* ================= input validation ================= */ get_filter_request_var('id'); get_filter_request_var('host_id'); /* ==================================================== */ api_device_dq_remove(get_request_var('host_id'), get_request_var('id')); } function host_change_query() { /* ================= input validation ================= */ get_filter_request_var('data_query_id'); get_filter_request_var('host_id'); get_filter_request_var('reindex_method'); /* ==================================================== */ api_device_dq_change(get_request_var('host_id'), get_request_var('data_query_id'), get_request_var('reindex_method')); } function host_add_gt() { /* ================= input validation ================= */ get_filter_request_var('host_id'); get_filter_request_var('graph_template_id'); /* ==================================================== */ db_execute_prepared('REPLACE INTO host_graph (host_id, graph_template_id) VALUES (?, ?)', array(get_nfilter_request_var('host_id'), get_nfilter_request_var('graph_template_id'))); automation_hook_graph_template(get_nfilter_request_var('host_id'), get_nfilter_request_var('graph_template_id')); api_plugin_hook_function('add_graph_template_to_host', array('host_id' => get_nfilter_request_var('host_id'), 'graph_template_id' => get_nfilter_request_var('graph_template_id'))); } function host_remove_gt() { /* ================= input validation ================= */ get_filter_request_var('id'); get_filter_request_var('host_id'); /* ==================================================== */ api_device_gt_remove(get_request_var('host_id'), get_request_var('id')); } /* --------------------- Device Functions --------------------- */ function host_edit() { global $fields_host_edit, $reindex_types; /* ================= input validation ================= */ get_filter_request_var('id'); /* ==================================================== */ api_plugin_hook('host_edit_top'); $header_label = __('Device [new]'); $debug_link = ''; if (!isempty_request_var('id')) { $host = db_fetch_row_prepared('SELECT * FROM host WHERE id = ?', array(get_request_var('id'))); if (sizeof($host)) { $header_label = __('Device [edit: %s]', htmlspecialchars($host['description'])); if (is_device_debug_enabled($host['id'])) { $debug_link = "*" . __('Disable Device Debug') . "
"; }else{ $debug_link = "*" . __('Enable Device Debug') . "
"; } } } if (!empty($host['id'])) { ?>
() *'>
*'>
*'>
 

array('no_form_tag' => true), 'fields' => inject_form_variables($fields_host_edit, (isset($host) ? $host : array())) )); html_end_box(); device_javascript(); if ((isset_request_var('display_dq_details')) && (isset($_SESSION['debug_log']['data_query']))) { ?>
0) ? true : false; ?> ) " . __('Is Being Graphed') . " (" . __('Edit') . ")" : "" . __('Not Being Graphed') ."");?> ' class='deletequery fa fa-remove' id='gtremove' data-id=''> " . __('No associated graph templates.') . ""; } ?>
' id='add_gt' title=''>
__('Data Query Name'), 'align' => 'left'), array('display' => __('Re-Index Method'), 'align' => 'left'), array('display' => __('Status'), 'align' => 'left'), array('display' => __('Actions'), 'align' => 'right') ) ); if ($host['snmp_version'] == 0) { $sql_where1 = ' AND snmp_query.data_input_id != 2'; $sql_where2 = ' WHERE snmp_query.data_input_id != 2'; }else{ $sql_where1 = ''; $sql_where2 = ''; } $selected_data_queries = db_fetch_assoc_prepared("SELECT snmp_query.id, snmp_query.name, host_snmp_query.reindex_method FROM (snmp_query, host_snmp_query) WHERE snmp_query.id = host_snmp_query.snmp_query_id AND host_snmp_query.host_id = ? $sql_where1 ORDER BY snmp_query.name", array(get_request_var('id'))); $available_data_queries = db_fetch_assoc("SELECT snmp_query.id, snmp_query.name FROM snmp_query $sql_where2 ORDER BY snmp_query.name"); $keeper = array(); if (sizeof($available_data_queries)) { foreach ($available_data_queries as $item) { if (sizeof(db_fetch_assoc_prepared('SELECT snmp_query_id FROM host_snmp_query WHERE host_id = ? AND snmp_query_id = ?', array(get_request_var('id'), $item['id']))) > 0) { /* do nothing */ } else { array_push($keeper, $item); } } } $available_data_queries = $keeper; $i = 0; if (sizeof($selected_data_queries)) { foreach ($selected_data_queries as $item) { $i++; form_alternate_row("dg$i", true); /* get status information for this data query */ $num_dq_items = sizeof(db_fetch_assoc_prepared('SELECT snmp_index FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ?', array(get_request_var('id'), $item['id']))); $num_dq_rows = sizeof(db_fetch_assoc_prepared('SELECT snmp_index FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ? GROUP BY snmp_index', array(get_request_var('id'), $item['id']))); $status = 'success'; ?> ) " . __('Success') . "" : "" . __('Fail') . "");?> [ Item, Row] ' title='' data-id=''> ' title='' id='reload' data-id=''> ' title='' data-id=''> " . __('No Associated Data Queries.') . ""; } if ($host['snmp_version'] == 0) { unset($reindex_types[1]); $default = 0; }else{ $default = read_config_option('reindex_method'); } ?>
' id='add_dq' title=''>
$type) { if (get_selected_theme() != 'classic') { if ($i == 0) { print "
\n"; } print "\n"; print "\n"; }else{ print $reindex_types[$item['reindex_method']]; break; } $i++; } if (get_selected_theme() != 'classic') { print "
\n"; } } function device_javascript() { ?> array( 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ), 'page' => array( 'filter' => FILTER_VALIDATE_INT, 'default' => '1' ), 'filter' => array( 'filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string') ), 'sort_column' => array( 'filter' => FILTER_CALLBACK, 'default' => 'description', 'options' => array('options' => 'sanitize_search_string') ), 'sort_direction' => array( 'filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string') ), 'host_status' => array( 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ), 'host_template_id' => array( 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ), 'site_id' => array( 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ), 'poller_id' => array( 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ) ); $filters = api_plugin_hook_function('device_filters', $filters); validate_store_request_vars($filters, 'sess_host'); /* ================= input validation ================= */ /* if the number of rows is -1, set it to the default */ if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); }else{ $rows = get_request_var('rows'); } ?>
' title=''> ' title=''>
' onChange='applyFilter()'>
'>
0, status_event_count*$poller_interval, IF(UNIX_TIMESTAMP(status_rec_date)>943916400,UNIX_TIMESTAMP()-UNIX_TIMESTAMP(status_rec_date), IF(snmp_sysUptimeInstance>0 AND snmp_version > 0, snmp_sysUptimeInstance,UNIX_TIMESTAMP()))) AS instate FROM host LEFT JOIN (SELECT host_id, COUNT(*) AS graphs FROM graph_local GROUP BY host_id) AS gl ON host.id=gl.host_id LEFT JOIN (SELECT host_id, COUNT(*) AS data_sources FROM data_local GROUP BY host_id) AS dl ON host.id=dl.host_id $sql_where GROUP BY host.id $sql_order $sql_limit"; $hosts = db_fetch_assoc($sql_query); $nav = html_nav_bar('host.php?filter=' . get_request_var('filter') . '&host_template_id=' . get_request_var('host_template_id') . '&host_status=' . get_request_var('host_status'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 13, __('Devices'), 'page', 'main'); form_start('host.php', 'chk'); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array( 'description' => array('display' => __('Device Description'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __('The name by which this Device will be referred to.')), 'hostname' => array('display' => __('Hostname'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __('Either an IP address, or hostname. If a hostname, it must be resolvable by either DNS, or from your hosts file.')), 'id' => array('display' => __('ID'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The internal database ID for this Device. Useful when performing automation or debugging.')), 'graphs' => array('display' => __('Graphs'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The total number of Graphs generated from this Device.')), 'data_sources' => array('display' => __('Data Sources'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The total number of Data Sources generated from this Device.')), 'status' => array('display' => __('Status'), 'align' => 'center', 'sort' => 'ASC', 'tip' => __('The monitoring status of the Device based upon ping results. If this Device is a special type Device, by using the hostname "localhost", or due to the setting to not perform an Availability Check, it will always remain Up. When using cmd.php data collector, a Device with no Graphs, is not pinged by the data collector and will remain in an "Unknown" state.')), 'instate' => array('display' => __('In State'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The amount of time that this Device has been in its current state.')), 'snmp_sysUpTimeInstance' => array('display' => __('Uptime'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The current amount of time that the host has been up.')), 'polling_time' => array('display' => __('Poll Time'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The amount of time it takes to collect data from this Device.')), 'cur_time' => array('display' => __('Current (ms)'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The current ping time in milliseconds to reach the Device.')), 'avg_time' => array('display' => __('Average (ms)'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The average ping time in milliseconds to reach the Device since the counters were cleared for this Device.')), 'availability' => array('display' => __('Availability'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The availability percentage based upon ping results since the counters were cleared for this Device.')) ); html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false); $i = 0; if (sizeof($hosts)) { foreach ($hosts as $host) { if ($host['disabled'] == '' && ($host['status'] == HOST_RECOVERING || $host['status'] == HOST_UP) && ($host['availability_method'] != AVAIL_NONE && $host['availability_method'] != AVAIL_PING)) { $snmp_uptime = $host['snmp_sysUpTimeInstance']; $days = intval($snmp_uptime / (60*60*24*100)); $remainder = $snmp_uptime % (60*60*24*100); $hours = intval($remainder / (60*60*100)); $remainder = $remainder % (60*60*100); $minutes = intval($remainder / (60*100)); $uptime = $days . 'd:' . $hours . 'h:' . $minutes . 'm'; }else{ $uptime = "N/A"; } form_alternate_row('line' . $host['id'], true); form_selectable_cell(filter_value($host['description'], get_request_var('filter'), 'host.php?action=edit&id=' . $host['id']), $host['id']); form_selectable_cell(filter_value($host['hostname'], get_request_var('filter')), $host['id']); form_selectable_cell($host['id'], $host['id'], '', 'text-align:right'); form_selectable_cell(number_format_i18n($host['graphs']), $host['id'], '', 'text-align:right'); form_selectable_cell(number_format_i18n($host['data_sources']), $host['id'], '', 'text-align:right'); form_selectable_cell(get_colored_device_status(($host['disabled'] == 'on' ? true : false), $host['status']), $host['id'], '', 'text-align:center'); form_selectable_cell(get_timeinstate($host), $host['id'], '', 'text-align:right'); form_selectable_cell($uptime, $host['id'], '', 'text-align:right'); form_selectable_cell(round($host['polling_time'],2), $host['id'], '', 'text-align:right'); form_selectable_cell(round(($host['cur_time']), 2), $host['id'], '', 'text-align:right'); form_selectable_cell(round(($host['avg_time']), 2), $host['id'], '', 'text-align:right'); form_selectable_cell(round($host['availability'], 2) . ' %', $host['id'], '', 'text-align:right'); form_checkbox_cell($host['description'], $host['id']); form_end_row(); } }else{ print "" . __('No Devices Found') . ""; } html_end_box(false); if (sizeof($hosts)) { print $nav; } /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($device_actions); form_end(); api_plugin_hook('device_table_bottom'); }