';
$ds_array[$i] = $matches[1];
$i++;
}
}
top_header();
form_start('data_sources.php');
html_start_box($ds_actions[get_nfilter_request_var('drp_action')], '60%', '', '3', 'center', '');
if (isset($ds_array) && cacti_sizeof($ds_array)) {
if (get_nfilter_request_var('drp_action') == '1') { /* delete */
$graphs = array();
/* find out which (if any) graphs are using this data source, so we can tell the user */
if (isset($ds_array)) {
$graphs = db_fetch_assoc('SELECT
graph_templates_graph.local_graph_id,
graph_templates_graph.title_cache
FROM (data_template_rrd,graph_templates_item,graph_templates_graph)
WHERE graph_templates_item.task_item_id=data_template_rrd.id
AND graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id
AND ' . array_to_sql_or($ds_array, 'data_template_rrd.local_data_id') . '
AND graph_templates_graph.local_graph_id > 0
GROUP BY graph_templates_graph.local_graph_id
ORDER BY graph_templates_graph.title_cache');
}
print "
" . __n('Click \'Continue\' to delete the following Data Source', 'Click \'Continue\' to delete following Data Sources', cacti_sizeof($ds_array)) . "
$ds_list
";
if (cacti_sizeof($graphs)) {
print "
" . __n('The following graph is using these data sources:', 'The following graphs are using these data sources:', cacti_sizeof($graphs)) . '
';
print '
';
foreach ($graphs as $graph) {
print '
' . html_escape($graph['title_cache']) . '
';
}
print '
';
print ' ';
form_radio_button('delete_type', '3', '1', __n('Leave the Graph untouched.', 'Leave all Graphs untouched.', cacti_sizeof($graphs)), '1');
print ' ';
form_radio_button('delete_type', '3', '2', __n('Delete all Graph Items that reference this Data Source.', 'Delete all Graph Items that reference these Data Sources.', cacti_sizeof($ds_array)), '1');
print ' ';
form_radio_button('delete_type', '3', '3', __n('Delete all Graphs that reference this Data Source.', 'Delete all Graphs that reference these Data Sources.', cacti_sizeof($ds_array)), '1');
print ' ';
print '
" . __n('Choose a new Device for this Data Source and click \'Continue\'.', 'Choose a new Device for these Data Sources and click \'Continue\'', cacti_sizeof($ds_array)) . "
$ds_list
" . __('New Device:') . ' ';
form_dropdown('host_id', db_fetch_assoc("SELECT id, CONCAT_WS('',description,' (',hostname,')') AS name FROM host ORDER BY description, hostname"),'name','id','','','0');
print '
" . __n('Click \'Continue\' to enable the following Data Source.', 'Click \'Continue\' to enable all following Data Sources.', cacti_sizeof($ds_array)) . "
" . __n('Click \'Continue\' to disable the following Data Source.', 'Click \'Continue\' to disable all following Data Sources.', cacti_sizeof($ds_array)) . "
" . __n('Click \'Continue\' to re-apply the suggested name to the following Data Source.', 'Click \'Continue\' to re-apply the suggested names to all following Data Sources.', cacti_sizeof($ds_array)) . "
";
html_end_box();
form_end();
bottom_footer();
}
/* ----------------------------
data - Custom Data
---------------------------- */
function data_edit($incform = true) {
/* ================= input validation ================= */
get_filter_request_var('id');
/* ==================================================== */
if (!isempty_request_var('id')) {
$data = db_fetch_row_prepared('SELECT id, data_input_id, data_template_id, name, local_data_id
FROM data_template_data
WHERE local_data_id = ?',
array(get_request_var('id')));
$template_data = db_fetch_row_prepared('SELECT id, data_input_id
FROM data_template_data
WHERE data_template_id = ?
AND local_data_id = 0',
array($data['data_template_id']));
$host = db_fetch_row_prepared('SELECT host.id, host.hostname
FROM (data_local, host)
WHERE data_local.host_id = host.id
AND data_local.id = ?',
array(get_request_var('id')));
}
if ($incform) {
form_start('data_sources.php', 'data_source_edit');
}
$i = 0;
if (!empty($data['data_input_id'])) {
/* get each INPUT field for this data input source */
$fields = db_fetch_assoc_prepared('SELECT *
FROM data_input_fields
WHERE data_input_id = ?
AND input_output = "in"
ORDER BY name',
array($data['data_input_id'])
);
$data_input_name = db_fetch_cell_prepared('SELECT name
FROM data_input
WHERE id = ?',
array($data['data_input_id']));
html_start_box(__('Custom Data [data input: %s]', html_escape($data_input_name)), '100%', '', '3', 'center', '');
/* loop through each field found */
if (cacti_sizeof($fields) > 0) {
foreach ($fields as $field) {
$data_input_data = db_fetch_row_prepared('SELECT *
FROM data_input_data
WHERE data_template_data_id = ?
AND data_input_field_id = ?',
array($data['id'], $field['id'])
);
if (cacti_sizeof($data_input_data) > 0) {
$old_value = $data_input_data['value'];
} else {
$old_value = '';
}
/* if data template then get t_value FROM template, else always allow user input */
if (empty($data['data_template_id'])) {
$can_template = 'on';
} else {
$can_template = db_fetch_cell_prepared('SELECT t_value
FROM data_input_data
WHERE data_template_data_id = ?
AND data_input_field_id = ?',
array($template_data['id'], $field['id'])
);
}
form_alternate_row();
if ((!empty($host['id'])) && (preg_match('/^' . VALID_HOST_FIELDS . '$/i', $field['type_code']))) {
print "
0)';
}
$sql_order = get_order_string();
$sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows;
if (get_request_var('orphans') == 'true') {
$sql_where1 .= ($sql_where1 != '' ? ' AND ':'WHERE ') . '((dl.snmp_index = "" AND dl.snmp_query_id > 0) OR graph_items = 0 IS NULL OR dl.orphan = 1)';
$orphan_join = "LEFT JOIN (
SELECT dtr.local_data_id, COUNT(DISTINCT gti.task_item_id) AS graph_items
FROM data_template_rrd AS dtr
LEFT JOIN graph_templates_item AS gti
ON dtr.id = gti.task_item_id
INNER JOIN graph_local AS gl
ON gl.id = gti.local_graph_id
LEFT JOIN host AS h
ON h.id = gl.host_id
WHERE dtr.local_data_id > 0
$sql_where2
GROUP BY local_data_id
) AS dtr
ON dl.id = dtr.local_data_id";
$sql = "SELECT COUNT(*)
FROM data_local AS dl
INNER JOIN data_template_data AS dtd
ON dl.id = dtd.local_data_id
INNER JOIN data_template AS dt
ON dt.id = dl.data_template_id
LEFT JOIN host AS h
ON h.id = dl.host_id
$orphan_join
$sql_where1";
$total_rows = get_total_row_data($_SESSION[SESS_USER_ID], $sql, array(), 'data_source');
$data_sources = db_fetch_assoc("SELECT dtd.local_data_id,
dtd.name_cache, dtd.active, dtd.rrd_step, dt.name AS data_template_name,
dl.host_id, dtd.data_source_profile_id
FROM data_local AS dl
INNER JOIN data_template_data AS dtd
ON dl.id = dtd.local_data_id
INNER JOIN data_template AS dt
ON dt.id = dl.data_template_id
LEFT JOIN host AS h
ON h.id = dl.host_id
$orphan_join
$sql_where1
$sql_order
$sql_limit");
} else {
$sql = "SELECT COUNT(*)
FROM data_local AS dl
INNER JOIN data_template_data AS dtd
ON dl.id=dtd.local_data_id
LEFT JOIN data_template AS dt
ON dt.id = dl.data_template_id
LEFT JOIN host AS h
ON h.id = dl.host_id
$sql_where1";
$total_rows = get_total_row_data($_SESSION[SESS_USER_ID], $sql, array(), 'data_source');
$data_sources = db_fetch_assoc("SELECT dtd.local_data_id, dtd.name_cache, dtd.active,
dtd.rrd_step, dt.name AS data_template_name, dl.host_id, dtd.data_source_profile_id
FROM data_local AS dl
INNER JOIN data_template_data AS dtd
ON dl.id=dtd.local_data_id
LEFT JOIN data_template AS dt
ON dt.id = dl.data_template_id
LEFT JOIN host AS h
ON h.id = dl.host_id
$sql_where1
$sql_order
$sql_limit");
}
$nav = html_nav_bar('data_sources.php', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 7, __('Data Sources'), 'page', 'main');
form_start('data_sources.php', 'chk');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
$display_text = array(
'name_cache' => array(
'display' => __('Data Source Name'),
'align' => 'left',
'sort' => 'ASC',
'tip' => __('The name of this Data Source. Generally programmatically generated from the Data Template definition.')
),
'local_data_id' => array(
'display' => __('ID'),
'align' => 'right',
'sort' => 'ASC',
'tip' => __('The internal database ID for this Data Source. Useful when performing automation or debugging.')
),
'nosort0' => array(
'display' => __('Graphs'),
'align' => 'center',
'sort' => '',
'tip' => __('The number of Graphs and Aggregate Graphs that are using the Data Source.')
),
'nosort1' => array(
'display' => __('Poller Interval'),
'align' => 'left',
'sort' => 'ASC',
'tip' => __('The frequency that data is collected for this Data Source.')
),
'nosort2' => array(
'display' => __('Deletable'),
'align' => 'left',
'sort' => 'ASC',
'tip' => __('If this Data Source is no long in use by Graphs, it can be Deleted.')
),
'active' => array(
'display' => __('Active'),
'align' => 'left',
'sort' => 'ASC',
'tip' => __('Whether or not data will be collected for this Data Source. Controlled at the Data Template level.')
),
'data_template_name' => array(
'display' => __('Template Name'),
'align' => 'left',
'sort' => 'ASC',
'tip' => __('The Data Template that this Data Source was based upon.')
)
);
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
$i = 0;
if (cacti_sizeof($data_sources)) {
foreach ($data_sources as $data_source) {
if (api_data_source_deletable($data_source['local_data_id'])) {
$disabled = false;
} else {
$disabled = true;
}
$data_source['data_template_name'] = html_escape($data_source['data_template_name']);
$data_name_cache = title_trim(html_escape($data_source['name_cache']), read_config_option('max_title_length'));
if (get_request_var('rfilter') != '') {
$data_name_cache = filter_value($data_name_cache, get_request_var('rfilter'));
}
/* keep copy of data source for comparison */
$data_source_orig = $data_source;
$data_source = api_plugin_hook_function('data_sources_table', $data_source);
/* we're escaping strings here, so no need to escape them on form_selectable_cell */
if (empty($data_source['data_template_name'])) {
$data_template_name = '' . __('None') . '';
} elseif ($data_source_orig['data_template_name'] != $data_source['data_template_name']) {
/* was changed by plugin, plugin has to take care for html-escaping */
$data_template_name = $data_source['data_template_name'];
} elseif (get_request_var('rfilter') != '') {
$data_template_name = filter_value($data_source['data_template_name'], get_request_var('rfilter'));
} else {
$data_template_name = html_escape($data_source['data_template_name']);
}
$graphs_aggregates_url = get_graphs_aggregates_url($data_source['local_data_id']);
if ($data_source['name_cache'] == '') {
$name = __('Damaged Data Source Name');
} else {
$name = $data_source['name_cache'];
}
form_alternate_row('line' . $data_source['local_data_id'], true, $disabled);
form_selectable_cell(filter_value(title_trim($name, read_config_option('max_title_length')), get_request_var('rfilter'), 'data_sources.php?action=ds_edit&id=' . $data_source['local_data_id']), $data_source['local_data_id']);
form_selectable_cell($data_source['local_data_id'], $data_source['local_data_id'], '', 'right');
// Show link to Graphs and Aggregates
form_selectable_cell($graphs_aggregates_url, $data_source['local_data_id'], '', 'center');
form_selectable_cell(get_poller_interval($data_source['rrd_step'], $data_source['data_source_profile_id']), $data_source['local_data_id']);
form_selectable_cell(api_data_source_deletable($data_source['local_data_id']) ? __('Yes') : __('No'), $data_source['local_data_id']);
form_selectable_cell(($data_source['active'] == 'on' ? __('Yes'):__('No')), $data_source['local_data_id']);
form_selectable_cell($data_template_name, $data_source['local_data_id']);
form_checkbox_cell($name, $data_source['local_data_id'], $disabled);
form_end_row();
}
} else {
print "
" . __('No Data Sources Found') . '
';
}
html_end_box(false);
if (cacti_sizeof($data_sources)) {
print $nav;
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($ds_actions);
form_end();
}
function get_graphs_aggregates_url($local_data_id) {
$graphs = db_fetch_row_prepared('SELECT GROUP_CONCAT(DISTINCT gl.id) AS graphs, COUNT(DISTINCT gl.id) AS total
FROM data_local AS dl
INNER JOIN data_template_rrd AS dtr
ON dl.id = dtr.local_data_id
INNER JOIN graph_templates_item AS gti
ON gti.task_item_id = dtr.id
INNER JOIN graph_local AS gl
ON gl.id = gti.local_graph_id
LEFT JOIN aggregate_graphs AS ag
ON ag.local_graph_id = gl.id
WHERE dl.id = ?
AND ag.local_graph_id IS NULL',
array($local_data_id));
$aggregates = db_fetch_row_prepared('SELECT GROUP_CONCAT(DISTINCT gl.id) AS graphs, COUNT(DISTINCT gl.id) AS total
FROM data_local AS dl
INNER JOIN data_template_rrd AS dtr
ON dl.id = dtr.local_data_id
INNER JOIN graph_templates_item AS gti
ON gti.task_item_id = dtr.id
INNER JOIN graph_local AS gl
ON gl.id = gti.local_graph_id
INNER JOIN aggregate_graphs AS ag
ON ag.local_graph_id = gl.id
WHERE dl.id = ?',
array($local_data_id));
$url = '';
if (cacti_sizeof($graphs) && $graphs['total'] > 0) {
$url .= '' . $graphs['total'] . '';
} else {
$url .= '0';
}
if (cacti_sizeof($aggregates) && $aggregates['total'] > 0) {
$url .= ' / ' . $aggregates['total'] . '';
} else {
$url .= ' / 0';
}
return $url;
}