function graphs() { global $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('host_id')); input_validate_input_number(get_request_var_request('graph_type')); input_validate_input_number(get_request_var_request('rows')); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST['filter'])) { $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter')); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST['clear_x'])) { kill_session_var('sess_graphs_new_filter'); kill_session_var('sess_default_rows'); unset($_REQUEST['filter']); unset($_REQUEST['rows']); $changed = true; } else { /* if any of the settings changed, reset the page number */ $changed = false; $changed += check_changed('host_id', 'sess_graphs_new_host_id'); $changed += check_changed('graph_type', 'sess_graphs_new_graph_type'); $changed += check_changed('filter', 'sess_graphs_new_filter'); $changed += check_changed('rows', 'sess_default_rows'); } load_current_session_value('host_id', 'sess_graphs_new_host_id', db_fetch_cell('SELECT id FROM host ORDER BY description, hostname LIMIT 1')); load_current_session_value('graph_type', 'sess_graphs_new_graph_type', read_config_option('default_graphs_new_dropdown')); load_current_session_value('filter', 'sess_graphs_new_filter', ''); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); if (!empty($_REQUEST['host_id'])) { $host = db_fetch_row_prepared('SELECT id, description, hostname, host_template_id FROM host WHERE id = ?', array($_REQUEST['host_id'])); $header = ' [ ' . htmlspecialchars($host['description']) . ' (' . htmlspecialchars($host['hostname']) . ') ' . (!empty($host['host_template_id']) ? htmlspecialchars(db_fetch_cell_prepared('SELECT name FROM host_template WHERE id = ?', array($host['host_template_id']))) : '') . ' ]'; } else { $host = array(); $header = 'None Host Type'; } $row_limit = get_request_var_request('rows'); html_start_box("<strong>New Graphs for</strong> {$header}", '100%', '', '3', 'center', ''); form_alternate_row(); print '<td class="even">'; ?> <script type='text/javascript'> <!-- function applyFilter() { strURL = '?graph_type=' + $('#graph_type').val(); strURL = strURL + '&host_id=' + $('#host_id').val(); strURL = strURL + '&filter=' + $('#filter').val();; strURL = strURL + '&rows=' + $('#rows').val();; document.location = strURL; } --> </script> <form name='form_graphs_new' action='graphs_new.php'> <table width='100%' cellpadding='2' cellspacing='0' border='0' align='left'> <tr> <?php print html_host_filter($_REQUEST['host_id']); ?> <td style='white-space:nowrap;' width='1'> Graph Types </td> <td width='1'> <select id='graph_type' name='graph_type' onChange='applyFilter()'> <option value='-2'<?php if ($_REQUEST['graph_type'] == '-2') { ?> selected<?php } ?> >All</option> <option value='-1'<?php if ($_REQUEST['graph_type'] == '-1') { ?> selected<?php } ?> >Graph Template Based</option> <?php $snmp_queries = db_fetch_assoc_prepared('SELECT snmp_query.id, snmp_query.name, snmp_query.xml_path FROM (snmp_query, host_snmp_query) WHERE host_snmp_query.snmp_query_id = snmp_query.id AND host_snmp_query.host_id = ? ORDER BY snmp_query.name', array($host['id'])); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $query) { print "<option value='" . $query['id'] . "'"; if ($_REQUEST['graph_type'] == $query['id']) { print ' selected'; } print '>' . $query['name'] . "</option>\n"; } } ?> </select> </td> <td width='50'> Rows </td> <td> <select id='rows' name='rows' onChange='applyFilter()'> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> <td rowspan='3' class='textInfo' align='right' valign='top'> <span class='linkMarker'>*</span><a class='hyperLink' href='<?php print htmlspecialchars('host.php?action=edit&id=' . $_REQUEST['host_id']); ?> '>Edit this Device</a><br> <span class='linkMarker'>*</span><a class='hyperLink' href='<?php print htmlspecialchars('host.php?action=edit'); ?> '>Create New Device</a><br> <?php api_plugin_hook('graphs_new_top_links'); ?> </td> </tr> <tr style='<?php if ($_REQUEST['graph_type'] <= 0) { ?> display:none;<?php } ?> '> <td width='50'> Search </td> <td style='white-space:nowrap;'> <input id='filter' type='text' name='filter' size='25' value='<?php print htmlspecialchars(get_request_var_request('filter')); ?> '> </td> <td colspan='3' style='white-space:nowrap;'> <input type='submit' value='Go' title='Set/Refresh Filters'> <input type='submit' name='clear_x' value='Clear' title='Clear Filters'> </td> </tr> </table> </form> </td> </tr> <?php html_end_box(); ?> <form name='chk' method='post' action='graphs_new.php'> <?php $total_rows = sizeof(db_fetch_assoc_prepared('SELECT graph_template_id FROM host_graph WHERE host_id = ?', array($_REQUEST['host_id']))); $i = 0; if ($changed) { foreach ($snmp_queries as $query) { kill_session_var('sess_graphs_new_page' . $query['id']); unset($_REQUEST['page' . $query['id']]); load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1'); } } if ($_REQUEST['graph_type'] > 0) { load_current_session_value('page' . $_REQUEST['graph_type'], 'sess_graphs_new_page' . $_REQUEST['graph_type'], '1'); } else { if ($_REQUEST['graph_type'] == -2) { foreach ($snmp_queries as $query) { load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1'); } } } $script = "<script type='text/javascript'>\nvar gt_created_graphs = new Array();\nvar created_graphs = new Array()\n"; if ($_REQUEST['graph_type'] < 0) { html_start_box('<strong>Graph Templates</strong>', '100%', '', '3', 'center', ''); print "<tr class='tableHeader'>\n\t\t\t\t<td class='tableSubHeaderColumn'>Graph Template Name</td>\n\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='Select All' onClick='SelectAll(\"sg\",this.checked);'></td>\n\n\t\t\t</tr>\n"; $graph_templates = db_fetch_assoc_prepared('SELECT graph_templates.id AS graph_template_id, graph_templates.name AS graph_template_name FROM (host_graph, graph_templates) WHERE host_graph.graph_template_id = graph_templates.id AND host_graph.host_id = ? ORDER BY graph_templates.name', array($_REQUEST['host_id'])); if (!empty($_REQUEST['host_id'])) { $template_graphs = db_fetch_assoc_prepared('SELECT graph_local.graph_template_id FROM (graph_local, host_graph) WHERE graph_local.graph_template_id = host_graph.graph_template_id AND graph_local.host_id = host_graph.host_id AND graph_local.host_id = ? GROUP BY graph_local.graph_template_id', array($host['id'])); if (sizeof($template_graphs) > 0) { $script .= 'var gt_created_graphs = new Array('; $cg_ctr = 0; foreach ($template_graphs as $template_graph) { $script .= ($cg_ctr > 0 ? ',' : '') . "'" . $template_graph['graph_template_id'] . "'"; $cg_ctr++; } $script .= ")\n"; } } /* create a row for each graph template associated with the host template */ if (sizeof($graph_templates) > 0) { foreach ($graph_templates as $graph_template) { $query_row = $graph_template['graph_template_id']; print "<tr id='gt_line{$query_row}' class='selectable " . ($i % 2 == 0 ? 'odd' : 'even') . "'>"; $i++; print "<td>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'>" . htmlspecialchars($graph_template['graph_template_name']) . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right' class='checkbox'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>"; } } html_end_box(); html_start_box('', '100%', '', '3', 'center', ''); $available_graph_templates = db_fetch_assoc('SELECT graph_templates.id, graph_templates.name FROM snmp_query_graph RIGHT JOIN graph_templates ON (snmp_query_graph.graph_template_id = graph_templates.id) WHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name'); /* create a row at the bottom that lets the user create any graph they choose */ print "\t<tr class='even'>\n\t\t\t\t<td width='1'><i>Create</i></td>\n\t\t\t\t<td align='left'>"; form_dropdown('cg_g', $available_graph_templates, 'name', 'id', '', '(Select a graph type to create)', '', 'textArea'); print '</td> </tr>'; html_end_box(); } if ($_REQUEST['graph_type'] != -1 && !empty($_REQUEST['host_id'])) { $snmp_queries = db_fetch_assoc('SELECT snmp_query.id, snmp_query.name, snmp_query.xml_path FROM (snmp_query,host_snmp_query) WHERE host_snmp_query.snmp_query_id=snmp_query.id AND host_snmp_query.host_id=' . $host['id'] . ($_REQUEST['graph_type'] != -2 ? ' AND snmp_query.id=' . $_REQUEST['graph_type'] : '') . ' ORDER BY snmp_query.name'); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $snmp_query) { unset($total_rows); if (!$changed) { $page = $_REQUEST['page' . $snmp_query['id']]; } else { $page = 1; } $xml_array = get_data_query_array($snmp_query['id']); $num_input_fields = 0; $num_visible_fields = 0; if ($xml_array != false) { /* loop through once so we can find out how many input fields there are */ reset($xml_array['fields']); while (list($field_name, $field_array) = each($xml_array['fields'])) { if ($field_array['direction'] == 'input') { $num_input_fields++; if (!isset($total_rows)) { $total_rows = db_fetch_cell_prepared('SELECT count(*) FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ? AND field_name = ?', array($host['id'], $snmp_query['id'], $field_name)); } } } } if (!isset($total_rows)) { $total_rows = 0; } $snmp_query_graphs = db_fetch_assoc_prepared('SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id = ? ORDER BY snmp_query_graph.name', array($snmp_query['id'])); if (sizeof($snmp_query_graphs) > 0) { foreach ($snmp_query_graphs as $snmp_query_graph) { $created_graphs = db_fetch_assoc_prepared("SELECT DISTINCT\n\t\t\t\t\t\tdata_local. snmp_index\n\t\t\t\t\t\tFROM (data_local, data_template_data)\n\t\t\t\t\t\tLEFT JOIN data_input_data ON (data_template_data.id = data_input_data.data_template_data_id)\n\t\t\t\t\t\tLEFT JOIN data_input_fields ON (data_input_data.data_input_field_id = data_input_fields.id)\n\t\t\t\t\t\tWHERE data_local.id = data_template_data.local_data_id\n\t\t\t\t\t\tAND data_input_fields.type_code = 'output_type'\n\t\t\t\t\t\tAND data_input_data.value = ?\n\t\t\t\t\t\tAND data_local.host_id = ?", array($snmp_query_graph['id'], $host['id'])); $script .= 'created_graphs[' . $snmp_query_graph['id'] . '] = new Array('; $cg_ctr = 0; if (sizeof($created_graphs) > 0) { foreach ($created_graphs as $created_graph) { $script .= ($cg_ctr > 0 ? ',' : '') . "'" . encode_data_query_index($created_graph['snmp_index']) . "'"; $cg_ctr++; } } $script .= ")\n"; } } print "\t<table width='100%' class='cactiTable' align='center' cellpadding='3' cellspacing='0'>\n\n\t\t\t\t\t<tr class='cactiTableTitle'>\n\t\t\t\t\t\t<td colspan='" . ($num_input_fields + 1) . "'>\n\t\t\t\t\t\t\t<table cellspacing='0' cellpadding='0' width='100%' >\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t<strong>Data Query</strong> [" . $snmp_query['name'] . "]\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t<td align='right' nowrap>\n\t\t\t\t\t\t\t\t\t\t<a href='" . htmlspecialchars('graphs_new.php?action=query_reload&id=' . $snmp_query['id'] . '&host_id=' . $host['id']) . "'><img src='images/reload_icon_small.gif' title='Reload Associated Query' alt='' border='0' align='absmiddle'></a>\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>"; if ($xml_array != false) { $html_dq_header = ''; $snmp_query_indexes = array(); reset($xml_array['fields']); /* if there is a where clause, get the matching snmp_indexes */ $sql_where = ''; if (strlen($_REQUEST['filter'])) { $sql_where = ''; $indexes = db_fetch_assoc("SELECT DISTINCT snmp_index\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE field_value LIKE '%%" . $_REQUEST['filter'] . "%%'\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query['id'] . "\n\t\t\t\t\t\tAND host_id=" . $host['id']); if (sizeof($indexes)) { foreach ($indexes as $index) { if (strlen($sql_where)) { $sql_where .= ", '" . $index['snmp_index'] . "'"; } else { $sql_where .= " AND snmp_index IN('" . $index['snmp_index'] . "'"; } } $sql_where .= ')'; } } if (strlen($_REQUEST['filter']) == 0 || strlen($_REQUEST['filter']) && sizeof($indexes)) { /* determine the sort order */ if (isset($xml_array['index_order_type'])) { if ($xml_array['index_order_type'] == 'numeric') { $sql_order = 'ORDER BY CAST(snmp_index AS unsigned)'; } else { if ($xml_array['index_order_type'] == 'alphabetic') { $sql_order = 'ORDER BY snmp_index'; } else { if ($xml_array['index_order_type'] == 'natural') { $sql_order = 'ORDER BY INET_ATON(snmp_index)'; } else { $sql_order = ''; } } } } else { $sql_order = ''; } /* get the unique field values from the database */ $field_names = db_fetch_assoc_prepared('SELECT DISTINCT field_name FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ?', array($host['id'], $snmp_query['id'])); /* build magic query */ $sql_query = 'SELECT host_id, snmp_query_id, snmp_index'; $num_visible_fields = sizeof($field_names); $i = 0; if (sizeof($field_names) > 0) { foreach ($field_names as $column) { $field_name = $column['field_name']; $sql_query .= ", MAX(CASE WHEN field_name='{$field_name}' THEN field_value ELSE NULL END) AS '{$field_name}'"; $i++; } } $sql_query .= ' FROM host_snmp_cache WHERE host_id=' . $host['id'] . ' AND snmp_query_id=' . $snmp_query['id'] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index\n\t\t\t\t\t\t{$sql_order}\n\t\t\t\t\t\tLIMIT " . $row_limit * ($page - 1) . ',' . $row_limit; $rows_query = 'SELECT host_id, snmp_query_id, snmp_index FROM host_snmp_cache WHERE host_id=' . $host['id'] . ' AND snmp_query_id=' . $snmp_query['id'] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index"; $snmp_query_indexes = db_fetch_assoc($sql_query); $total_rows = sizeof(db_fetch_assoc($rows_query)); if (($page - 1) * $row_limit > $total_rows) { $page = 1; $_REQUEST['page' . $query['id']] = $page; load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1'); } $nav = html_nav_bar('graphs_new.php', MAX_DISPLAY_PAGES, $page, $row_limit, $total_rows, 15, 'Items', 'page' . $snmp_query['id']); print $nav; while (list($field_name, $field_array) = each($xml_array['fields'])) { if ($field_array['direction'] == 'input' && sizeof($field_names)) { foreach ($field_names as $row) { if ($row['field_name'] == $field_name) { $html_dq_header .= "<td class='tableSubHeaderColumn'>" . $field_array['name'] . "</td>\n"; break; } } } } if (!sizeof($snmp_query_indexes)) { print "<tr class='odd'><td>This Data Query returned 0 rows, perhaps there was a problem executing this\n\t\t\t\t\t\t\tData Query. You can <a href='" . htmlspecialchars('host.php?action=query_verbose&id=' . $snmp_query['id'] . '&host_id=' . $host['id']) . "'>run this Data Query in debug mode</a> to get more information.</td></tr>\n"; } else { print "<tr class='tableHeader'>\n\t\t\t\t\t\t\t\t{$html_dq_header}\n\t\t\t\t\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $snmp_query['id'] . "' title='Select All' onClick='SelectAll(\"sg_" . $snmp_query['id'] . "\",this.checked)'></td>\n\n\t\t\t\t\t\t\t</tr>\n"; } $row_counter = 0; $column_counter = 0; $fields = array_rekey($field_names, 'field_name', 'field_name'); if (sizeof($snmp_query_indexes) > 0) { foreach ($snmp_query_indexes as $row) { $query_row = $snmp_query['id'] . '_' . encode_data_query_index($row['snmp_index']); print "<tr id='line{$query_row}' class='selectable " . ($row_counter % 2 == 0 ? 'odd' : 'even') . "'>"; $i++; $column_counter = 0; reset($xml_array['fields']); while (list($field_name, $field_array) = each($xml_array['fields'])) { if ($field_array['direction'] == 'input') { if (in_array($field_name, $fields)) { if (isset($row[$field_name])) { print "<td><span id='text{$query_row}" . '_' . $column_counter . "'>" . (strlen($_REQUEST['filter']) ? preg_replace('/(' . preg_quote($_REQUEST['filter']) . ')/i', "<span class='filteredValue'>\\1</span>", $row[$field_name]) : $row[$field_name]) . '</span></td>'; } else { print "<td><span id='text{$query_row}" . '_' . $column_counter . "'></span></td>"; } $column_counter++; } } } print "<td class='checkbox' align='right'>"; print "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}'>"; print '</td>'; print "</tr>\n"; $row_counter++; } } if ($total_rows > $row_limit) { print $nav; } } else { print "<tr class='odd'><td class='textError'>Search Returned no Rows.</td></tr>\n"; } } else { print "<tr class='odd'><td class='textError'>Error in data query.</td></tr>\n"; } print '</table>'; /* draw the graph template drop down here */ $data_query_graphs = db_fetch_assoc_prepared('SELECT snmp_query_graph.id, snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id = ? ORDER BY snmp_query_graph.name', array($snmp_query['id'])); if (sizeof($data_query_graphs) == 1) { echo "<input type='hidden' id='sgg_" . $snmp_query['id'] . "' name='sgg_" . $snmp_query['id'] . "' value='" . $data_query_graphs[0]['id'] . "'>\n"; } elseif (sizeof($data_query_graphs) > 1) { print "\t<table align='center' width='100%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td width='100%' valign='middle'>\n\t\t\t\t\t\t\t\t<img src='images/arrow.gif' align='absmiddle' alt=''>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td style='white-space:nowrap;font-style: italic;'' align='right'>\n\t\t\t\t\t\t\t\tSelect a Graph Type to Create\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t\t\t<select name='sgg_" . $snmp_query['id'] . "' id='sgg_" . $snmp_query['id'] . "' onChange='dqUpdateDeps(" . $snmp_query['id'] . ',' . (isset($column_counter) ? $column_counter : '') . ");'>\n\t\t\t\t\t\t\t\t\t"; html_create_list($data_query_graphs, 'name', 'id', '0'); print "\n\t\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n"; } print '<br>'; $script .= 'dqUpdateDeps(' . $snmp_query['id'] . ',' . $num_visible_fields . ");\n"; } } } if (strlen($script)) { $script .= "</script>\n"; print $script; } form_hidden_box('save_component_graph', '1', ''); if (!empty($_REQUEST['host_id'])) { form_hidden_box('host_id', $host['id'], '0'); form_hidden_box('host_template_id', $host['host_template_id'], '0'); } if (isset($_SERVER['HTTP_REFERER']) && !substr_count($_SERVER['HTTP_REFERER'], 'graphs_new')) { $_REQUEST['returnto'] = basename($_SERVER['HTTP_REFERER']); } load_current_session_value('returnto', 'sess_graphs_new_returnto', ''); form_save_button($_REQUEST['returnto']); }
function thold_add_select_host() { global $config; $host_id = get_filter_request_var('host_id'); $local_graph_id = get_filter_request_var('local_graph_id'); $data_template_rrd_id = get_filter_request_var('data_template_rrd_id'); $hosts = get_allowed_devices(); top_header(); form_start('thold.php?action=save', 'tholdform'); html_start_box(__('Threshold Creation Wizard'), '50%', '', '3', 'center', ''); if ($host_id == '') { print '<tr><td class="center">' . __('Please select a Device') . '</td></tr>'; } else { if ($local_graph_id == '') { print '<tr><td class="center">' . __('Please select a Graph') . '</td></tr>'; } else { if ($data_template_rrd_id == '') { print '<tr><td class="center">' . __('Please select a Data Source') . '</td></tr>'; } else { print '<tr><td class="center">' . __('Please press \'Create\' to activate your Threshold') . '</td></tr>'; } } } html_end_box(); html_start_box('', '50%', '', '3', 'center', ''); /* display the host dropdown */ ?> <tr><td><table class='filterTable' align='center'> <tr> <?php print html_host_filter(get_request_var('host_id')); ?> </tr><?php if ($host_id != '') { $graphs = get_allowed_graphs('gl.host_id=' . $host_id); ?> <tr> <td> <?php print __('Graph'); ?> </td> <td> <select id='local_graph_id' name='local_graph_id' onChange='applyFilter("graph")'> <option value=''></option><?php foreach ($graphs as $row) { echo "<option value='" . $row['local_graph_id'] . "'" . ($row['local_graph_id'] == $local_graph_id ? ' selected' : '') . '>' . htmlspecialchars($row['title_cache'], ENT_QUOTES) . '</option>'; } ?> </select> </td> </tr><?php } else { ?> <tr> <td> <input type='hidden' id='local_graph_id' name='local_graph_id' value=''> </td> </tr><?php } if ($local_graph_id != '') { $dt_sql = 'SELECT DISTINCT dtr.local_data_id FROM data_template_rrd AS dtr LEFT JOIN graph_templates_item AS gti ON gti.task_item_id=dtr.id LEFT JOIN graph_local AS gl ON gl.id=gti.local_graph_id WHERE gl.id = ' . $local_graph_id; $local_data_id = db_fetch_cell($dt_sql); $dss = db_fetch_assoc('SELECT DISTINCT id, data_source_name FROM data_template_rrd WHERE local_data_id IN (' . $dt_sql . ') ORDER BY data_source_name'); /* show the data source options */ ?> <tr> <td> <?php print __('Data Source'); ?> </td> <td> <input type='hidden' id='local_data_id' name='local_data_id' value='<?php print $local_data_id; ?> '> <select id='data_template_rrd_id' name='data_template_rrd_id' onChange='applyFilter("ds")'> <option value=''></option><?php foreach ($dss as $row) { echo "<option value='" . $row['id'] . "'" . ($row['id'] == $data_template_rrd_id ? ' selected' : '') . '>' . htmlspecialchars($row['data_source_name'], ENT_QUOTES) . '</option>'; } ?> </select> </td> </tr></table></td></tr><?php } else { ?> <tr> <td> <input type='hidden' id='data_template_rrd_id' name='data_template_rrd_id' value=''> </td> </tr></table></td></tr><?php } if ($data_template_rrd_id != '') { echo "<tr><td class='center' colspan='2'><input type='hidden' name='save' id='save' value='save'><input id='go' type='button' value='" . __('Create') . "' title='" . __('Create Threshold') . "'></td></tr>"; } else { echo "<tr><td class='center' colspan='2'></td></tr>"; } html_end_box(); form_end(); html_start_box('', '50%', '', '3', 'center', ''); if ($local_graph_id != '') { print "<tr><td style='text-align:center'><img id='graphi' src='../../graph_image.php?local_graph_id={$local_graph_id}&rra_id=0'></td></tr>"; } html_end_box(); ?> <script type='text/javascript'> function applyFilter(target) { strURL = 'thold.php?action=add&header=false&host_id=' + $('#host_id').val(); if (target != 'host_id') { strURL += '&local_graph_id=' + $('#local_graph_id').val(); } if (target == 'ds') { strURL += '&data_template_rrd_id=' + $('#data_template_rrd_id').val(); } loadPageNoHeader(strURL); } $(function() { $('#go').button().click(function() { strURL = $('#tholdform').attr('action'); json = $('input, select').serializeObject(); $.post(strURL, json).done(function(data) { $('#main').html(data); applySkin(); window.scrollTo(0, 0); }); }); }); </script> <?php }
function form_thold_log_filter() { global $item_rows, $thold_log_states, $config; ?> <tr class='even'> <td> <form id='form_log' action='thold_graph.php?action=log'> <table class='filterTable'> <tr> <td> <?php print __('Search'); ?> </td> <td> <input type='text' id='filter' size='25' value='<?php print get_request_var('filter'); ?> '> </td> <?php print html_host_filter(get_request_var('host_id')); ?> <td> <?php print __('Threshold'); ?> </td> <td> <select id='threshold_id' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('threshold_id') == '-1') { ?> selected<?php } ?> ><?php print __('All'); ?> </option> <?php $tholds = db_fetch_assoc('SELECT DISTINCT thold_data.id, thold_data.name FROM thold_data INNER JOIN plugin_thold_log ON thold_data.id=plugin_thold_log.threshold_id ' . (get_request_var('host_id') > 0 ? 'WHERE thold_data.host_id=' . get_request_var('host_id') : '') . ' ORDER by thold_data.name'); if (sizeof($tholds)) { foreach ($tholds as $thold) { print "<option value='" . $thold['id'] . "'"; if (get_request_var('threshold_id') == $thold['id']) { print ' selected'; } print '>' . $thold['name'] . "</option>\n"; } } ?> </select> </td> <td> <?php print __('Status'); ?> </td> <td> <select id='status' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('status') == '-1') { ?> selected<?php } ?> ><?php print __('All'); ?> </option> <?php if (sizeof($thold_log_states)) { foreach ($thold_log_states as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var('status') == $key) { print " selected"; } print ">" . $value['display'] . "</option>\n"; } } ?> </select> </td> <td> <?php print __('Entries'); ?> </td> <td> <select id='rows' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('rows') == '-1') { ?> selected<?php } ?> ><?php print __('Default'); ?> </option> <?php if (sizeof($item_rows)) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var('rows') == $key) { print " selected"; } print ">" . $value . "</option>\n"; } } ?> </select> </td> <td> <input id='refresh' type='button' value='<?php print __('Go'); ?> ' onClick='applyFilter()'> </td> <td> <input id='clear' type='button' value='<?php print __('Clear'); ?> ' onClick='clearFilter()'> </td> </tr> </table> <input type='hidden' name='page' value='<?php print get_request_var('filter'); ?> '> <input type='hidden' name='tab' value='log'> </form> <script type='text/javascript'> function applyFilter() { strURL = 'thold_graph.php?header=false&action=log&status=' + $('#status').val(); strURL += '&threshold_id=' + $('#threshold_id').val(); strURL += '&host_id=' + $('#host_id').val(); strURL += '&rows=' + $('#rows').val(); strURL += '&filter=' + $('#filter').val(); loadPageNoHeader(strURL); } function clearFilter() { strURL = 'thold_graph.php?header=false&action=log&clear=1'; loadPageNoHeader(strURL); } $(function() { $('#form_log').submit(function(event) { event.preventDefault(); applyFilter(); }); }); </script> </td> </tr> <?php }
function list_tholds() { global $thold_states, $config, $host_id, $timearray, $thold_types; $thold_actions = array(1 => __('Delete'), 2 => __('Disable'), 3 => __('Enable'), 4 => __('Reapply Suggested Names'), 5 => __('Propagate Template')); thold_request_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'); } $statefilter = ''; if (isset_request_var('state')) { if (get_request_var('state') == '-1') { $statefilter = ''; } else { if (get_request_var('state') == '0') { $statefilter = "thold_data.thold_enabled='off'"; } if (get_request_var('state') == '2') { $statefilter = "thold_data.thold_enabled='on'"; } if (get_request_var('state') == '1') { $statefilter = '(thold_data.thold_alert!=0 OR thold_data.bl_alert>0)'; } if (get_request_var('state') == '3') { $statefilter = '((thold_data.thold_alert!=0 AND thold_data.thold_fail_count >= thold_data.thold_fail_trigger) OR (thold_data.bl_alert>0 AND thold_data.bl_fail_count >= thold_data.bl_fail_trigger))'; } } } top_header(); $sql_where = ''; $sort = get_request_var('sort_column'); $limit = ' LIMIT ' . $rows * (get_request_var('page') - 1) . ", {$rows}"; if (!isempty_request_var('host_id') && get_request_var('host_id') != '-1') { $sql_where .= (!strlen($sql_where) ? '(' : ' AND ') . "td.host_id = " . get_request_var('host_id'); } if (!isempty_request_var('data_template_id') && get_request_var('data_template_id') != '-1') { $sql_where .= (!strlen($sql_where) ? '(' : ' AND ') . "td.data_template_id = " . get_request_var('data_template_id'); } if ($statefilter != '') { $sql_where .= (!strlen($sql_where) ? '(' : ' AND ') . "{$statefilter}"; } if ($sql_where != '') { $sql_where .= ')'; } $tholds = get_allowed_thresholds($sql_where, $sort . ' ' . get_request_var('sort_direction'), $rows * (get_request_var('page') - 1) . ", {$rows}", $total_rows); $data_templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name\n\t\tFROM data_template\n\t\tINNER JOIN thold_data \n\t\tON thold_data.data_template_id = data_template.id\n\t\tORDER BY data_template.name"); html_start_box(__('Threshold Management'), '100%', '', '3', 'center', 'thold.php?action=add'); ?> <tr class='even'> <td> <form id='listthold' action='thold.php' method='post'> <table class='filterTable'> <tr> <td> <?php print __('Search'); ?> </td> <td> <input type='text' id='filter' size='25' value='<?php print get_request_var('filter'); ?> '> </td> <?php print html_host_filter(get_request_var('host_id')); ?> <td> <?php print __('Template'); ?> </td> <td> <select id='data_template_id' onChange='applyFilter()'> <option value='-1'><?php print __('Any'); ?> </option> <?php foreach ($data_templates as $row) { echo "<option value='" . $row['id'] . "'" . (isset_request_var('data_template_id') && $row['id'] == get_request_var('data_template_id') ? ' selected' : '') . '>' . $row['name'] . '</option>'; } ?> </select> </td> <td> <?php print __('State'); ?> </td> <td> <select id='state' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('state') == '-1') { ?> selected<?php } ?> ><?php print __('All'); ?> </option> <option value='1'<?php if (get_request_var('state') == '1') { ?> selected<?php } ?> ><?php print __('Breached'); ?> </option> <option value='3'<?php if (get_request_var('state') == '3') { ?> selected<?php } ?> ><?php print __('Triggered'); ?> </option> <option value='2'<?php if (get_request_var('state') == '2') { ?> selected<?php } ?> ><?php print __('Enabled'); ?> </option> <option value='0'<?php if (get_request_var('state') == '0') { ?> selected<?php } ?> ><?php print __('Disabled'); ?> </option> </select> </td> <td> <input type='button' id='refresh' value='<?php print __('Go'); ?> ' title='<?php print __('Apply Filters'); ?> ' onClick='applyFilter()'> </td> <td> <input type='button' id='clear' value='<?php print __('Clear'); ?> ' title='<?php print __('Return to Defaults'); ?> ' onClick='clearFilter()'> </td> </tr> </table> <input type='hidden' name='search' value='search'> <input type='hidden' id='page' value='<?php print get_filter_request_var('page'); ?> '> </form> <script type='text/javascript'> function applyFilter() { strURL = 'thold.php?header=false&host_id=' + $('#host_id').val(); strURL += '&state=' + $('#state').val(); strURL += '&data_template_id=' + $('#data_template_id').val(); strURL += '&filter=' + $('#filter').val(); loadPageNoHeader(strURL); } function clearFilter() { strURL = 'thold.php?header=false&clear=1'; loadPageNoHeader(strURL); } $(function() { $('#listthold').submit(function(event) { event.preventDefault(); applyFilter(); }); }); </script> </td> </tr> <?php html_end_box(); $nav = html_nav_bar('thold.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 14, __('Thresholds'), 'page', 'main'); form_start('thold.php', 'chk'); print $nav; html_start_box('', '100%', '', '4', 'center', ''); $display_text = array('name' => array('display' => __('Name'), 'sort' => 'ASC', 'align' => 'left'), 'id' => array('display' => __('ID'), 'sort' => 'ASC', 'align' => 'right'), 'thold_type' => array('display' => __('Type'), 'sort' => 'ASC', 'align' => 'right'), 'data_source' => array('display' => __('DSName'), 'sort' => 'ASC', 'align' => 'right'), 'lastread' => array('display' => __('Current'), 'sort' => 'ASC', 'align' => 'right', 'tip' => __('The last measured value for the Data Source')), 'thold_hi' => array('display' => __('High'), 'sort' => 'ASC', 'align' => 'right', 'tip' => __('High Threshold values for Warning/Alert')), 'thold_low' => array('display' => __('Low'), 'sort' => 'ASC', 'align' => 'right', 'tip' => __('Low Threshold values for Warning/Alert')), 'nosort3' => array('display' => __('Trigger'), 'sort' => '', 'align' => 'right'), 'nosort4' => array('display' => __('Duration'), 'sort' => '', 'align' => 'right'), 'repeat_alert' => array('display' => __('Repeat'), 'sort' => 'ASC', 'align' => 'right'), 'thold_alert' => array('display' => __('Triggered'), 'sort' => 'ASC', 'align' => 'right'), 'template_enabled' => array('display' => __('Templated'), 'sort' => 'ASC', 'align' => 'right')); html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false); $c = 0; $i = 0; if (sizeof($tholds)) { foreach ($tholds as $thold_data) { $c++; $grapharr = db_fetch_row('SELECT DISTINCT graph_templates_item.local_graph_id FROM graph_templates_item, data_template_rrd WHERE (data_template_rrd.local_data_id=' . $thold_data['local_data_id'] . ' AND data_template_rrd.id=graph_templates_item.task_item_id)'); $local_graph_id = $grapharr['local_graph_id']; $alertstat = __('No'); $bgcolor = 'green'; if ($thold_data['thold_type'] == 0) { if ($thold_data['thold_alert'] != 0) { $alertstat = __('Yes'); if ($thold_data['thold_fail_count'] >= $thold_data['thold_fail_trigger']) { $bgcolor = 'red'; } elseif ($thold_data['thold_warning_fail_count'] >= $thold_data['thold_warning_fail_trigger']) { $bgcolor = 'warning'; } else { $bgcolor = 'yellow'; } } } elseif ($thold_data['thold_type'] == 2) { if ($thold_data['thold_alert'] != 0) { $alertstat = __('Yes'); if ($thold_data['thold_fail_count'] >= $thold_data['time_fail_trigger']) { $bgcolor = 'red'; } elseif ($thold_data['thold_warning_fail_count'] >= $thold_data['time_warning_fail_trigger']) { $bgcolor = 'warning'; } else { $bgcolor = 'yellow'; } } } else { if ($thold_data['bl_alert'] == 1) { $alertstat = __('baseline-LOW'); $bgcolor = $thold_data['bl_fail_count'] >= $thold_data['bl_fail_trigger'] ? 'orange' : 'yellow'; } elseif ($thold_data['bl_alert'] == 2) { $alertstat = __('baseline-HIGH'); $bgcolor = $thold_data['bl_fail_count'] >= $thold_data['bl_fail_trigger'] ? 'orange' : 'yellow'; } } $data_source = db_fetch_cell_prepared('SELECT data_source_name FROM data_template_rrd WHERE id = ?', array($thold_data['data_template_rrd_id'])); if ($thold_data['thold_enabled'] == 'off') { print "<tr class='selectable " . $thold_states['grey']['class'] . "' id='line" . $thold_data['id'] . "'>\n"; } else { print "<tr class='selectable " . $thold_states[$bgcolor]['class'] . "' id='line" . $thold_data['id'] . "'>\n"; } form_selectable_cell(filter_value($thold_data['name'] != '' ? $thold_data['name'] : $thold_data['name_cache'] . ' [' . $thold_data['data_source_name'] . ']', get_request_var('filter'), 'thold.php?action=edit&id=' . $thold_data['id']) . '</a>', $thold_data['id'], '', 'text-align:left'); form_selectable_cell($thold_data['id'], $thold_data['id'], '', 'text-align:right'); form_selectable_cell($thold_types[$thold_data['thold_type']], $thold_data['id'], '', 'text-align:right'); form_selectable_cell($data_source, $thold_data['id'], '', 'text-align:right'); switch ($thold_data['thold_type']) { case 0: form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['thold_warning_hi']) . ' / ' . thold_format_number($thold_data['thold_hi']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['thold_warning_low']) . ' / ' . thold_format_number($thold_data['thold_low']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell('<i>' . plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['thold_fail_trigger'], 'alert') . '</i>', $thold_data['id'], '', 'text-align:right'); form_selectable_cell(__('N/A'), $thold_data['id'], '', 'text-align:right'); break; case 1: form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['thold_warning_hi']) . ' / ' . thold_format_number($thold_data['thold_hi']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['thold_warning_low']) . ' / ' . thold_format_number($thold_data['thold_low']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell('<i>' . plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['bl_fail_trigger'], 'alert') . '</i>', $thold_data['id'], '', 'text-align:right'); form_selectable_cell($timearray[$thold_data['bl_ref_time_range'] / 300], $thold_data['id'], '', 'text-align:right'); break; case 2: form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['time_warning_hi']) . ' / ' . thold_format_number($thold_data['time_hi']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['time_warning_low']) . ' / ' . thold_format_number($thold_data['time_low']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell('<i>' . __('%d Triggers', $thold_data['time_fail_trigger']) . '</i>', $thold_data['id'], '', 'text-align:right'); form_selectable_cell('<i>' . plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['time_fail_length'], 'time') . '</i>', $thold_data['id'], '', 'text-align:right'); break; default: form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell('- / -', $thold_data['id'], '', 'text-align:right'); form_selectable_cell('- / -', $thold_data['id'], '', 'text-align:right'); form_selectable_cell(__('N/A'), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(__('N/A'), $thold_data['id'], '', 'text-align:right'); } form_selectable_cell($thold_data['repeat_alert'] == '' ? '' : plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['repeat_alert'], 'repeat'), $thold_data['id'], '', 'text-align:right'); form_selectable_cell($alertstat, $thold_data['id'], '', 'text-align:right'); if ($thold_data['thold_template_id'] != 0) { form_selectable_cell($thold_data['template_enabled'] == '' ? __('No') : __('Yes'), $thold_data['id'], '', 'text-align:right'); } else { form_selectable_cell(__('No'), $thold_data['id'], '', 'text-align:right'); } form_checkbox_cell($thold_data['name'], $thold_data['id'], '', 'text-align:left'); form_end_row(); } } else { print "<tr class='even'><td colspan='14'><center>" . __('No Thresholds') . "</center></td></tr>\n"; } html_end_box(false); if (sizeof($tholds)) { print $nav; } thold_legend(); draw_actions_dropdown($thold_actions); if (isset($host_id) && $host_id != '') { print "<input type='hidden' name='host_id' value='{$host_id}'>"; } form_end(); bottom_footer(); }
function ds() { global $ds_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('rows')); input_validate_input_number(get_request_var_request('host_id')); input_validate_input_number(get_request_var_request('template_id')); input_validate_input_number(get_request_var_request('method_id')); input_validate_input_number(get_request_var_request('page')); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST['filter'])) { $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter')); } /* clean up sort_column string */ if (isset($_REQUEST['sort_column'])) { $_REQUEST['sort_column'] = sanitize_search_string(get_request_var_request('sort_column')); } /* clean up sort_direction string */ if (isset($_REQUEST['sort_direction'])) { $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var_request('sort_direction')); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST['clear_x'])) { kill_session_var('sess_ds_current_page'); kill_session_var('sess_ds_filter'); kill_session_var('sess_ds_sort_column'); kill_session_var('sess_ds_sort_direction'); kill_session_var('sess_default_rows'); kill_session_var('sess_ds_host_id'); kill_session_var('sess_ds_template_id'); kill_session_var('sess_ds_method_id'); unset($_REQUEST['page']); unset($_REQUEST['filter']); unset($_REQUEST['sort_column']); unset($_REQUEST['sort_direction']); unset($_REQUEST['rows']); unset($_REQUEST['host_id']); unset($_REQUEST['template_id']); unset($_REQUEST['method_id']); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('page', 'sess_ds_current_page', '1'); load_current_session_value('filter', 'sess_ds_filter', ''); load_current_session_value('sort_column', 'sess_ds_sort_column', 'name_cache'); load_current_session_value('sort_direction', 'sess_ds_sort_direction', 'ASC'); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); load_current_session_value('host_id', 'sess_ds_host_id', '-1'); load_current_session_value('template_id', 'sess_ds_template_id', '-1'); load_current_session_value('method_id', 'sess_ds_method_id', '-1'); $host = db_fetch_row_prepared('SELECT hostname FROM host WHERE id = ?', array(get_request_var_request('host_id'))); /* if the number of rows is -1, set it to the default */ if (get_request_var_request('rows') == -1) { $_REQUEST['rows'] = read_config_option('num_rows_table'); } ?> <script type='text/javascript'> <!-- function applyFilter() { strURL = 'data_sources.php?host_id=' + $('#host_id').val(); strURL = strURL + '&filter=' + $('#filter').val(); strURL = strURL + '&rows=' + $('#rows').val(); strURL = strURL + '&template_id=' + $('#template_id').val(); strURL = strURL + '&method_id=' + $('#method_id').val(); strURL = strURL + '&page=' + $('#page').val(); strURL = strURL + '&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } function clearFilter() { strURL = 'data_sources.php?clear_x=1&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } $(function() { $('#refresh').click(function() { applyFilter() }); $('#clear').click(function() { clearFilter() }); $('#form_data_sources').submit(function(event) { event.preventDefault(); applyFilter(); }); }); --> </script> <?php if (read_config_option('grds_creation_method') == 1) { $add_url = htmlspecialchars('data_sources.php?action=ds_edit&host_id=' . get_request_var_request('host_id')); } else { $add_url = ''; } html_start_box('<strong>Data Sources</strong> [host: ' . (empty($host['hostname']) ? 'No Device' : htmlspecialchars($host['hostname'])) . ']', '100%', '', '3', 'center', $add_url); ?> <tr class='even noprint'> <td> <form id='form_data_sources' name='form_data_sources' action='data_sources.php'> <table cellpadding='2' cellspacing='0' border='0'> <tr> <?php print html_host_filter($_REQUEST['host_id']); ?> <td width='50'> Template </td> <td> <select id='template_id' name='template_id' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var_request('template_id') == '-1') { ?> selected<?php } ?> >Any</option> <option value='0'<?php if (get_request_var_request('template_id') == '0') { ?> selected<?php } ?> >None</option> <?php $templates = db_fetch_assoc('SELECT DISTINCT data_template.id, data_template.name FROM data_template INNER JOIN data_template_data ON data_template.id = data_template_data.data_template_id WHERE data_template_data.local_data_id > 0 ORDER BY data_template.name'); if (sizeof($templates) > 0) { foreach ($templates as $template) { print "<option value='" . $template['id'] . "'"; if (get_request_var_request('template_id') == $template['id']) { print ' selected'; } print '>' . title_trim(htmlspecialchars($template['name']), 40) . "</option>\n"; } } ?> </select> </td> <td> <input type='button' id='refresh' value='Go' title='Set/Refresh Filters'> </td> <td> <input type='button' id='clear' name='clear_x' value='Clear' title='Clear Filters'> </td> </tr> <tr> <td width='50'> Method </td> <td> <select id='method_id' name='method_id' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var_request('method_id') == '-1') { ?> selected<?php } ?> >Any</option> <option value='0'<?php if (get_request_var_request('method_id') == '0') { ?> selected<?php } ?> >None</option> <?php $methods = db_fetch_assoc('SELECT DISTINCT data_input.id, data_input.name FROM data_input INNER JOIN data_template_data ON data_input.id = data_template_data.data_input_id WHERE data_template_data.local_data_id > 0 ORDER BY data_input.name'); if (sizeof($methods) > 0) { foreach ($methods as $method) { print "<option value='" . $method['id'] . "'"; if (get_request_var_request('method_id') == $method['id']) { print ' selected'; } print '>' . title_trim(htmlspecialchars($method['name']), 40) . "</option>\n"; } } ?> </select> </td> <td style='white-space:nowrap;'> Data Sources </td> <td> <select id='rows' name='rows' onChange='applyFilter()'> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> </tr> </table> <table cellpadding='2' cellspacing='0' border='0'> <tr> <td width='50'> Search </td> <td> <input id='filter' type='text' size='25' value='<?php print htmlspecialchars(get_request_var_request('filter')); ?> ' onChange='applyFilter()'> </td> </tr> </table> <input type='hidden' id='page' name='page' value='<?php print $_REQUEST['page']; ?> '> </form> </td> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request('filter'))) { $sql_where1 = "AND (data_template_data.name_cache like '%" . get_request_var_request('filter') . "%'" . " OR data_template_data.local_data_id like '%" . get_request_var_request('filter') . "%'" . " OR data_template.name like '%" . get_request_var_request('filter') . "%'" . " OR data_input.name like '%" . get_request_var_request('filter') . "%')"; $sql_where2 = "AND (data_template_data.name_cache like '%" . get_request_var_request('filter') . "%'" . " OR data_template.name like '%" . get_request_var_request('filter') . "%')"; } else { $sql_where1 = ''; $sql_where2 = ''; } if (get_request_var_request('host_id') == '-1') { /* Show all items */ } elseif (get_request_var_request('host_id') == '0') { $sql_where1 .= ' AND data_local.host_id=0'; $sql_where2 .= ' AND data_local.host_id=0'; } elseif (!empty($_REQUEST['host_id'])) { $sql_where1 .= ' AND data_local.host_id=' . get_request_var_request('host_id'); $sql_where2 .= ' AND data_local.host_id=' . get_request_var_request('host_id'); } if (get_request_var_request('template_id') == '-1') { /* Show all items */ } elseif (get_request_var_request('template_id') == '0') { $sql_where1 .= ' AND data_template_data.data_template_id=0'; $sql_where2 .= ' AND data_template_data.data_template_id=0'; } elseif (!empty($_REQUEST['host_id'])) { $sql_where1 .= ' AND data_template_data.data_template_id=' . get_request_var_request('template_id'); $sql_where2 .= ' AND data_template_data.data_template_id=' . get_request_var_request('template_id'); } if (get_request_var_request('method_id') == '-1') { /* Show all items */ } elseif (get_request_var_request('method_id') == '0') { $sql_where1 .= ' AND data_template_data.data_input_id=0'; $sql_where2 .= ' AND data_template_data.data_input_id=0'; } elseif (!empty($_REQUEST['method_id'])) { $sql_where1 .= ' AND data_template_data.data_input_id=' . get_request_var_request('method_id'); $sql_where2 .= ' AND data_template_data.data_input_id=' . get_request_var_request('method_id'); } $total_rows = sizeof(db_fetch_assoc("SELECT\n\t\tdata_local.id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where1}")); $poller_intervals = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id AS id,\n\t\tMin(data_template_data.rrd_step*rra.steps) AS poller_interval\n\t\tFROM data_template\n\t\tINNER JOIN (data_local\n\t\tINNER JOIN ((data_template_data_rra\n\t\tINNER JOIN data_template_data ON data_template_data_rra.data_template_data_id=data_template_data.id)\n\t\tINNER JOIN rra ON data_template_data_rra.rra_id = rra.id) ON data_local.id = data_template_data.local_data_id) ON data_template.id = data_template_data.data_template_id\n\t\t{$sql_where2}\n\t\tGROUP BY data_template_data.local_data_id"), 'id', 'poller_interval'); $data_sources = db_fetch_assoc("SELECT\n\t\tdata_template_data.local_data_id,\n\t\tdata_template_data.name_cache,\n\t\tdata_template_data.active,\n\t\tdata_input.name as data_input_name,\n\t\tdata_template.name as data_template_name,\n\t\tdata_local.host_id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where1}\n\t\tORDER BY " . get_request_var_request('sort_column') . ' ' . get_request_var_request('sort_direction') . ' LIMIT ' . get_request_var_request('rows') * (get_request_var_request('page') - 1) . ',' . get_request_var_request('rows')); print "<form name='chk' method='post' action='data_sources.php'>\n"; html_start_box('', '100%', '', '3', 'center', ''); $nav = html_nav_bar('data_sources.php?filter=' . get_request_var_request('filter') . '&host_id=' . get_request_var_request('host_id'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 7, 'Data Sources', 'page', 'main'); print $nav; $display_text = array('name_cache' => array('display' => 'Data Source Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The name of this Data Source. Generally programtically 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.'), 'data_input_name' => array('display' => 'Data Input Method', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The method by which data is gathered for this Data Source.'), 'nosort' => array('display' => 'Poller Interval', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The frequency that data is collected for this Data Source.'), '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_request('sort_column'), get_request_var_request('sort_direction'), false); $i = 0; if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { $data_source['data_template_name'] = htmlspecialchars($data_source['data_template_name']); $data_name_cache = title_trim(htmlspecialchars($data_source['name_cache']), read_config_option('max_title_length')); if (trim(get_request_var_request('filter') != '')) { $data_name_cache = preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", $data_name_cache); } /* 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 = '<em>None</em>'; } 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 = empty($data_source['data_template_name']) ? '<em>None</em>' : $data_source['data_template_name']; } elseif (trim(get_request_var_request('filter') != '')) { /* we take care of html-escaping */ $data_template_name = preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($data_source['data_template_name'])); } else { $data_template_name = htmlspecialchars($data_source['data_template_name']); } if (empty($data_source['data_input_name'])) { $data_input_name = '<em>None</em>'; } elseif ($data_source_orig['data_input_name'] != $data_source['data_input_name']) { /* was changed by plugin, plugin has to take care for html-escaping */ $data_input_name = empty($data_source['data_input_name']) ? '<em>None</em>' : $data_source['data_input_name']; } elseif (trim(get_request_var_request('filter') != '')) { /* we take care of html-escaping */ $data_input_name = preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($data_source['data_input_name'])); } else { $data_input_name = htmlspecialchars($data_source['data_input_name']); } $poller_interval = isset($poller_intervals[$data_source['local_data_id']]) ? $poller_intervals[$data_source['local_data_id']] : 0; form_alternate_row('line' . $data_source['local_data_id'], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('data_sources.php?action=ds_edit&id=' . $data_source['local_data_id']) . "' title='" . htmlspecialchars($data_source['name_cache'], ENT_QUOTES) . "'>" . (get_request_var_request('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", title_trim(htmlspecialchars($data_source['name_cache']), read_config_option('max_title_length'))) : title_trim(htmlspecialchars($data_source['name_cache']), read_config_option('max_title_length'))) . '</a>', $data_source['local_data_id']); form_selectable_cell($data_source['local_data_id'], $data_source['local_data_id'], '', 'text-align:right'); form_selectable_cell($data_input_name, $data_source['local_data_id']); form_selectable_cell(get_poller_interval($poller_interval), $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($data_source['name_cache'], $data_source['local_data_id']); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr class='tableRow'><td colspan='7'><em>No Data Sources</em></td></tr>"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($ds_actions); print "</form>\n"; }
function graph() { global $colors, $graph_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('host_id')); input_validate_input_number(get_request_var_request('rows')); input_validate_input_number(get_request_var_request('template_id')); input_validate_input_number(get_request_var_request('page')); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST['filter'])) { $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter')); } /* clean up sort_column string */ if (isset($_REQUEST['sort_column'])) { $_REQUEST['sort_column'] = sanitize_search_string(get_request_var_request('sort_column')); } /* clean up sort_direction string */ if (isset($_REQUEST['sort_direction'])) { $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var_request('sort_direction')); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST['clear_x'])) { kill_session_var('sess_graph_current_page'); kill_session_var('sess_graph_filter'); kill_session_var('sess_graph_sort_column'); kill_session_var('sess_graph_sort_direction'); kill_session_var('sess_graph_host_id'); kill_session_var('sess_default_rows'); kill_session_var('sess_graph_template_id'); unset($_REQUEST['page']); unset($_REQUEST['filter']); unset($_REQUEST['sort_column']); unset($_REQUEST['sort_direction']); unset($_REQUEST['host_id']); unset($_REQUEST['rows']); unset($_REQUEST['template_id']); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('page', 'sess_graph_current_page', '1'); load_current_session_value('filter', 'sess_graph_filter', ''); load_current_session_value('sort_column', 'sess_graph_sort_column', 'title_cache'); load_current_session_value('sort_direction', 'sess_graph_sort_direction', 'ASC'); load_current_session_value('host_id', 'sess_graph_host_id', '-1'); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); load_current_session_value('template_id', 'sess_graph_template_id', '-1'); /* if the number of rows is -1, set it to the default */ if (get_request_var_request('rows') == -1) { $_REQUEST['rows'] = read_config_option('num_rows_table'); } ?> <script type="text/javascript"> <!-- function applyFilter() { strURL = 'graphs.php?host_id=' + $('#host_id').val(); strURL = strURL + '&rows=' + $('#rows').val(); strURL = strURL + '&page=' + $('#page').val(); strURL = strURL + '&filter=' + $('#filter').val(); strURL = strURL + '&template_id=' + $('#template_id').val(); strURL = strURL + '&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } function clearFilter() { strURL = 'graphs.php?clear_x=1&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } $(function() { $('#refresh').click(function() { applyFilter(); }); $('#clear').click(function() { clearFilter(); }); $('#filter').change(function() { applyFilter(); }); $('#form_graphs').submit(function(event) { event.preventDefault(); applyFilter(); }); }); --> </script> <?php if (read_config_option('grds_creation_method') == 1) { $add_url = htmlspecialchars('graphs.php?action=graph_edit&host_id=' . get_request_var_request('host_id')); } else { $add_url = ''; } html_start_box('<strong>Graph Management</strong>', '100%', '', '3', 'center', $add_url); ?> <tr class='even noprint'> <td> <form id='form_graphs' name='form_graphs' action='graphs.php'> <table cellpadding='2' cellspacing='0' border='0'> <tr> <?php print html_host_filter($_REQUEST['host_id']); ?> <td> Template </td> <td> <select id='template_id' name='template_id' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var_request('template_id') == '-1') { ?> selected<?php } ?> >Any</option> <option value='0'<?php if (get_request_var_request('template_id') == '0') { ?> selected<?php } ?> >None</option> <?php $templates = get_allowed_graph_templates(); if (sizeof($templates) > 0) { foreach ($templates as $template) { print "<option value='" . $template['id'] . "'"; if (get_request_var_request('template_id') == $template['id']) { print ' selected'; } print '>' . title_trim(htmlspecialchars($template['name']), 40) . "</option>\n"; } } ?> </select> </td> <td> <input type='button' id='refresh' value='Go' title='Set/Refresh Filters'> </td> <td> <input type='button' id='clear' name='clear_x' value='Clear' title='Clear Filters'> </td> </tr> </table> <table cellpadding='2' cellspacing='0' border='0'> <tr> <td width='50'> Search </td> <td> <input id='filter' type='text' name='filter' size='25' value='<?php print htmlspecialchars(get_request_var_request('filter')); ?> '> </td> <td> Graphs </td> <td> <select id='rows' name='rows' onChange='applyFilter()'> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> </tr> </table> <input type='hidden' id='page' name='page' value='<?php print $_REQUEST['page']; ?> '> </form> </td> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request('filter'))) { $sql_where = " AND (graph_templates_graph.title_cache like '%%" . get_request_var_request('filter') . "%%'" . " OR graph_templates.name like '%%" . get_request_var_request('filter') . "%%')"; } else { $sql_where = ''; } if (get_request_var_request('host_id') == '-1') { /* Show all items */ } elseif (get_request_var_request('host_id') == '0') { $sql_where .= ' AND graph_local.host_id=0'; } elseif (!empty($_REQUEST['host_id'])) { $sql_where .= ' AND graph_local.host_id=' . get_request_var_request('host_id'); } if (get_request_var_request('template_id') == '-1') { /* Show all items */ } elseif (get_request_var_request('template_id') == '0') { $sql_where .= ' AND graph_templates_graph.graph_template_id=0'; } elseif (!empty($_REQUEST['template_id'])) { $sql_where .= ' AND graph_templates_graph.graph_template_id=' . get_request_var_request('template_id'); } /* allow plugins to modify sql_where */ $sql_where .= api_plugin_hook_function('graphs_sql_where', $sql_where); /* print checkbox form for validation */ print "<form name='chk' method='post' action='graphs.php'>\n"; html_start_box('', '100%', '', '3', 'center', ''); $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(graph_templates_graph.id)\n\t\tFROM (graph_local, graph_templates_graph)\n\t\tLEFT JOIN graph_templates ON (graph_local.graph_template_id = graph_templates.id)\n\t\tWHERE graph_local.id = graph_templates_graph.local_graph_id\n\t\t{$sql_where}"); $graph_list = db_fetch_assoc("SELECT\n\t\tgraph_templates_graph.id,\n\t\tgraph_templates_graph.local_graph_id,\n\t\tgraph_templates_graph.height,\n\t\tgraph_templates_graph.width,\n\t\tgraph_templates_graph.title_cache,\n\t\tgraph_templates.name,\n\t\tgraph_local.host_id\n\t\tFROM (graph_local, graph_templates_graph)\n\t\tLEFT JOIN graph_templates ON (graph_local.graph_template_id = graph_templates.id)\n\t\tWHERE graph_local.id = graph_templates_graph.local_graph_id\n\t\t{$sql_where}\n\t\tORDER BY " . $_REQUEST['sort_column'] . ' ' . get_request_var_request('sort_direction') . ' LIMIT ' . get_request_var_request('rows') * (get_request_var_request('page') - 1) . ',' . get_request_var_request('rows')); $nav = html_nav_bar('graphs.php?filter=' . get_request_var_request('filter') . '&host_id=' . get_request_var_request('host_id'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 5, 'Graphs', 'page', 'main'); print $nav; $display_text = array('title_cache' => array('display' => 'Graph Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The Title of this Graph. Generally programatically generated from the Graph Template defition or Suggested Naming rules. The max length of the Title is controlled under Settings->Visual.'), 'local_graph_id' => array('display' => 'ID', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The internal database ID fro this Graph. Useful when performing automation or debugging.'), 'name' => array('display' => 'Template Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The Graph Template that this Graph was based upon.'), 'height' => array('display' => 'Size', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The size of this Graph when not in Preview mode.')); html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false); $i = 0; if (sizeof($graph_list) > 0) { foreach ($graph_list as $graph) { /* we're escaping strings here, so no need to escape them on form_selectable_cell */ $template_name = empty($graph['name']) ? '<em>None</em>' : htmlspecialchars($graph['name']); form_alternate_row('line' . $graph['local_graph_id'], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('graphs.php?action=graph_edit&id=' . $graph['local_graph_id']) . "' title='" . htmlspecialchars($graph['title_cache']) . "'>" . (get_request_var_request('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", title_trim(htmlspecialchars($graph['title_cache']), read_config_option('max_title_length'))) : title_trim(htmlspecialchars($graph['title_cache']), read_config_option('max_title_length'))) . '</a>', $graph['local_graph_id']); form_selectable_cell($graph['local_graph_id'], $graph['local_graph_id'], '', 'text-align:right'); form_selectable_cell(get_request_var_request('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", $template_name) : $template_name, $graph['local_graph_id']); form_selectable_cell($graph['height'] . 'x' . $graph['width'], $graph['local_graph_id']); form_checkbox_cell($graph['title_cache'], $graph['local_graph_id']); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr class='tableRow'><td colspan='5'><em>No Graphs Found</em></td></tr>"; } html_end_box(false); /* 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($graph_actions); print "</form>\n"; }