" . __('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.') . "
" . __('Click \'Continue\' to delete the following Device(s).') . "
$host_list
";
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 "
";
$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.') . "
" . __('Click \'Continue\' to apply Automation Rules to the following Devices(s).'). "
$host_list
";
$save_html = " ";
} elseif (get_request_var('drp_action') == '8') {
global $alignment, $graph_timespans;
$reports = db_fetch_assoc_prepared('SELECT id, name
FROM reports
WHERE user_id = ?
ORDER BY name',
array($_SESSION['sess_user_id']));
if (cacti_sizeof($reports)) {
print "
" . __('Click \'Continue\' to add the selected Graphs to the Report below.') . "
array('no_form_tag' => true),
'fields' => inject_form_variables($fields_host_edit, (isset($host) ? $host : array()))
)
);
html_end_box(true, true);
device_javascript();
if (!empty($host['id'])) {
html_start_box(__('Associated Graph Templates'), '100%', '', '3', 'center', '');
html_header(
array(
array('display' => __('Graph Template Name'), 'align' => 'left', 'nohide' => true),
array('display' => __('Status'), 'align' => 'left', 'nohide' => true)
), 2);
$selected_graph_templates = db_fetch_assoc_prepared("
SELECT result.id, result.name, graph_local.id AS graph_local_id
FROM (
SELECT DISTINCT gt.id, gt.name
FROM graph_templates AS gt
INNER JOIN host_graph AS hg
ON gt.id = hg.graph_template_id
WHERE hg.host_id = ?
) AS result
LEFT JOIN graph_local
ON graph_local.graph_template_id = result.id
AND graph_local.host_id = ?
ORDER BY result.name",
array(get_request_var('id'), get_request_var('id'))
);
$available_graph_templates = db_fetch_assoc_prepared("SELECT DISTINCT gt.id, gt.name
FROM graph_templates AS gt
LEFT JOIN snmp_query_graph AS sqg
ON sqg.graph_template_id = gt.id
INNER JOIN graph_templates_item AS gti
ON gti.graph_template_id = gt.id
INNER JOIN data_template_rrd AS dtr
ON gti.task_item_id = dtr.id
INNER JOIN data_template_data AS dtd
ON dtd.data_template_id = dtr.data_template_id
WHERE sqg.name IS NULL
AND gti.local_graph_id = 0
AND dtr.local_data_id = 0
AND gt.id NOT IN (SELECT graph_template_id FROM host_graph WHERE host_id = ?)
ORDER BY gt.name",
array(get_request_var('id'))
);
$i = 0;
$displayed_templates = array();
if (cacti_sizeof($selected_graph_templates)) {
foreach ($selected_graph_templates as $item) {
if (isset($displayed_templates[$item['id']])) {
continue;
} else {
$displayed_templates[$item['id']] = true;
}
$i++;
form_alternate_row("gt$i", true);
/* get status information for this graph template */
$is_being_graphed = $item['graph_local_id'] > 0;
?>
)
" . __('Is Being Graphed') . " (" . __('Edit') . ")" : "" . __('Not Being Graphed') ."");?>
' class='deletequery fa fa-times' id='gtremove' data-id=''>
" . __('No associated graph templates.') . "
";
}
?>
' id='add_gt' title=''>
__('Data Query Name'), 'align' => 'left', 'nohide' => true),
array('display' => __('Re-Index Method'), 'align' => 'left', 'nohide' => true),
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 AND';
} else {
$sql_where1 = '';
$sql_where2 = ' WHERE';
}
$sql_where2 .= ' snmp_query.id NOT IN(SELECT snmp_query_id FROM host_snmp_query WHERE host_id = ' . get_request_var('id') . ')';
$selected_data_queries = db_fetch_assoc_prepared("SELECT snmp_query.id,
snmp_query.name, host_snmp_query.reindex_method, IFNULL(`items`.`itemCount`, 0) AS itemCount, IFNULL(`rows`.`rowCount`, 0) AS rowCount
FROM snmp_query
INNER JOIN host_snmp_query
ON snmp_query.id = host_snmp_query.snmp_query_id
AND host_snmp_query.host_id = ?
LEFT JOIN (
SELECT snmp_query_id, COUNT(*) AS `itemCount`
FROM host_snmp_cache
WHERE host_id = ?
GROUP BY snmp_query_id
) AS `items`
ON items.snmp_query_id = snmp_query.id
LEFT JOIN (
SELECT snmp_query_id, COUNT(DISTINCT snmp_index) AS `rowCount`
FROM host_snmp_cache
WHERE host_id = ?
GROUP BY snmp_query_id
) AS `rows`
ON rows.snmp_query_id = snmp_query.id
$sql_where1
ORDER BY snmp_query.name",
array(get_request_var('id'), get_request_var('id'), 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");
$i = 0;
if (cacti_sizeof($selected_data_queries)) {
foreach ($selected_data_queries as $item) {
$i++;
form_alternate_row("dg$i", true);
$status = 'success';
?>
$type) {
if ($selectedTheme != 'classic') {
if ($i == 0) {
print "";
}
}
function device_change_javascript() {
?>
array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_DEFAULT,
'pageset' => true,
'default' => ''
),
'location' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '-1',
'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 ================= */
}
function get_device_records(&$total_rows, $rows) {
$sql_where = '';
/* form the 'where' clause for our main sql query */
if (get_request_var('filter') != '') {
$sql_where = 'WHERE (deleted = "" AND (
host.hostname LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . '
OR host.description LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . '
OR host.id = ' . db_qstr(get_request_var('filter')) . '))';
} else {
$sql_where = "WHERE deleted = ''";
}
if (get_request_var('location') == __('Undefined') || get_request_var('location') == '') {
$sql_where .= ($sql_where != '' ? ' AND':' WHERE') . ' IFNULL(host.location,"") = ""';
} elseif (get_request_var('location') != '-1') {
$sql_where .= ($sql_where != '' ? ' AND':' WHERE') . ' host.location = ' . db_qstr(get_request_var('location'));;
}
if (get_request_var('host_status') == '-1') {
/* Show all items */
} elseif (get_request_var('host_status') == '-2') {
$sql_where .= ($sql_where != '' ? " AND host.disabled='on'" : " WHERE host.disabled='on'");
} elseif (get_request_var('host_status') == '-3') {
$sql_where .= ($sql_where != '' ? " AND host.disabled=''" : " WHERE host.disabled=''");
} elseif (get_request_var('host_status') == '-4') {
$sql_where .= ($sql_where != '' ? " AND (host.status!='3' OR host.disabled='on')" : " WHERE (host.status!='3' OR host.disabled='on')");
} else {
$sql_where .= ($sql_where != '' ? ' AND (host.status=' . get_request_var('host_status') . " AND host.disabled = '')" : 'where (host.status=' . get_request_var('host_status') . " AND host.disabled = '')");
}
if (get_request_var('host_template_id') == '-1') {
/* Show all items */
} elseif (get_request_var('host_template_id') == '0') {
$sql_where .= ($sql_where != '' ? ' AND host.host_template_id=0' : ' WHERE host.host_template_id=0');
} elseif (!isempty_request_var('host_template_id')) {
$sql_where .= ($sql_where != '' ? ' AND host.host_template_id=' . get_request_var('host_template_id') : ' WHERE host.host_template_id=' . get_request_var('host_template_id'));
}
if (get_request_var('site_id') == '-1') {
/* Show all items */
} elseif (get_request_var('site_id') == '0') {
$sql_where .= ($sql_where != '' ? ' AND host.site_id=0' : ' WHERE host.site_id=0');
} elseif (!isempty_request_var('site_id')) {
$sql_where .= ($sql_where != '' ? ' AND host.site_id=' . get_request_var('site_id') : ' WHERE host.site_id=' . get_request_var('site_id'));
}
if (get_request_var('poller_id') == '-1') {
/* Show all items */
} else {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' host.poller_id=' . get_request_var('poller_id');
}
$sql_where = api_plugin_hook_function('device_sql_where', $sql_where);
$sql = "SELECT COUNT(host.id) FROM host $sql_where";
$total_rows = get_total_row_data($_SESSION['sess_user_id'], $sql, array(), 'device');
$poller_interval = read_config_option('poller_interval');
$sql_order = get_order_string();
$sql_limit = 'LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows;
$sql_query = "SELECT host.*, graphs, data_sources,
CAST(IF(availability_method = 0, '0',
IF(status_event_count > 0 AND status IN (1, 2), status_event_count*$poller_interval,
IF(UNIX_TIMESTAMP(status_rec_date) < 943916400 AND status IN (0, 3), total_polls*$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/100, UNIX_TIMESTAMP()
))))) AS unsigned) 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
$sql_order
$sql_limit";
return db_fetch_assoc($sql_query);
}
function host() {
global $device_actions, $item_rows, $config;
if ((!empty($_SESSION['sess_host_status'])) && (!isempty_request_var('host_status'))) {
if ($_SESSION['sess_host_status'] != get_nfilter_request_var('host_status')) {
set_request_var('page', '1');
}
}
host_validate_vars();
/* 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');
}
if (get_request_var('host_template_id') > 0) {
$url = 'host.php?action=edit&host_template_id=' . get_request_var('host_template_id');
} else {
$url = 'host.php?action=edit';
}
html_start_box(__('Devices'), '100%', '', '3', 'center', $url);
?>
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.')
)
);
$display_text_size = sizeof($display_text);
$display_text = api_plugin_hook_function('device_display_text', $display_text);
$hosts = get_device_records($total_rows, $rows);
$nav = html_nav_bar('host.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, cacti_sizeof($display_text) + 1, __('Devices'), 'page', 'main');
form_start('host.php', 'chk');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
if (sizeof($display_text) != $display_text_size && cacti_sizeof($hosts)) {//display_text changed
api_plugin_hook_function('device_table_replace', $hosts);
} else if (cacti_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)) {
$uptime = get_uptime($host);
} else {
$uptime = __('N/A');
}
$graphs_url = $config['url_path'] . 'graphs.php?reset=1&host_id=' . $host['id'];
$data_source_url = $config['url_path'] . 'data_sources.php?reset=1&host_id=' . $host['id'];
if (empty($host['graphs'])) {
$host['graphs'] = 0;
}
if (empty($host['data_sources'])) {
$host['data_sources'] = 0;
}
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(filter_value($host['id'], get_request_var('filter')), $host['id'], '', 'right');
form_selectable_cell('' . number_format_i18n($host['graphs'], '-1') . '', $host['id'], '', 'right');
form_selectable_cell('' . number_format_i18n($host['data_sources'], '-1') . '', $host['id'], '', 'right');
form_selectable_cell(get_colored_device_status(($host['disabled'] == 'on' ? true : false), $host['status']), $host['id'], '', 'center');
form_selectable_cell(get_timeinstate($host), $host['id'], '', 'right');
form_selectable_cell($uptime, $host['id'], '', 'right');
form_selectable_cell(round($host['polling_time'],2), $host['id'], '', 'right');
form_selectable_cell(round(($host['cur_time']), 2), $host['id'], '', 'right');
form_selectable_cell(round(($host['avg_time']), 2), $host['id'], '', 'right');
form_selectable_cell(round($host['availability'], 2) . ' %', $host['id'], '', 'right');
form_checkbox_cell($host['description'], $host['id']);
form_end_row();
}
} else {
print "
" . __('No Devices Found') . "
";
}
html_end_box(false);
if (cacti_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');
}