function host_edit() { global $colors, $fields_host_edit, $reindex_types; display_output_messages(); if (!empty($_GET["id"])) { $host = db_fetch_row("select * from host where id=" . $_GET["id"]); $header_label = "[edit: " . $host["description"] . "]"; }else{ $header_label = "[new]"; } if (!empty($host["id"])) { ?> <table width="98%" align="center"> <tr> <td class="textInfo" colspan="2"> <?php print $host["description"];?> (<?php print $host["hostname"];?>) </td> </tr> <tr> <td class="textHeader"> SNMP Information<br> <span style="font-size: 10px; font-weight: normal; font-family: monospace;"> <?php if (($host["snmp_community"] == "") && ($host["snmp_username"] == "")) { print "<span style='color: #ab3f1e; font-weight: bold;'>SNMP not in use</span>\n"; }else{ $snmp_system = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.1.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"], SNMP_WEBUI); if ($snmp_system == "") { print "<span style='color: #ff0000; font-weight: bold;'>SNMP error</span>\n"; }else{ $snmp_uptime = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.3.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"], SNMP_WEBUI); $snmp_hostname = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.5.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"], SNMP_WEBUI); print "<strong>System:</strong> $snmp_system<br>\n"; print "<strong>Uptime:</strong> $snmp_uptime<br>\n"; print "<strong>Hostname:</strong> $snmp_hostname<br>\n"; } } ?> </span> </td> <td class="textInfo" valign="top"> <span style="color: #c16921;">*</span><a href="graphs_new.php?host_id=<?php print $host["id"];?>">Create Graphs for this Host</a> </td> </tr> </table> <br> <?php } html_start_box("<strong>Devices</strong> $header_label", "98%", $colors["header"], "3", "center", ""); /* preserve the host template id if passed in via a GET variable */ if (!empty($_GET["host_template_id"])) { $fields_host_edit["host_template_id"]["value"] = $_GET["host_template_id"]; } draw_edit_form(array( "config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_host_edit, (isset($host) ? $host : array())) )); html_end_box(); if ((isset($_GET["display_dq_details"])) && (isset($_SESSION["debug_log"]["data_query"]))) { html_start_box("<strong>Data Query Debug Information</strong>", "98%", $colors["header"], "3", "center", ""); print "<tr><td><span style='font-family: monospace;'>" . debug_log_return("data_query") . "</span></td></tr>"; html_end_box(); } if (!empty($host["id"])) { html_start_box("<strong>Associated Graph Templates</strong>", "98%", $colors["header"], "3", "center", ""); html_header(array("Graph Template Name", "Status"), 2); $selected_graph_templates = db_fetch_assoc("select graph_templates.id, graph_templates.name from graph_templates,host_graph where graph_templates.id=host_graph.graph_template_id and host_graph.host_id=" . $_GET["id"] . " order by graph_templates.name"); $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"); $i = 0; if (sizeof($selected_graph_templates) > 0) { foreach ($selected_graph_templates as $item) { $i++; /* get status information for this graph template */ $is_being_graphed = (sizeof(db_fetch_assoc("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"])) > 0) ? true : false; ?> <tr> <td style="padding: 4px;"> <strong><?php print $i;?>)</strong> <?php print $item["name"];?> </td> <td> <?php print (($is_being_graphed == true) ? "<span style='color: green;'>Is Being Graphed</span> (<a href='graphs.php?action=graph_edit&id=" . db_fetch_cell("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"] . " limit 0,1") . "'>Edit</a>)" : "<span style='color: #484848;'>Not Being Graphed</span>");?> </td> <td align='right' nowrap> <a href='host.php?action=gt_remove&id=<?php print $item["id"];?>&host_id=<?php print $_GET["id"];?>'><img src='images/delete_icon_large.gif' alt='Delete Graph Template Association' border='0' align='absmiddle'></a> </td> </tr> <?php } }else{ print "<tr><td><em>No associated graph templates.</em></td></tr>"; } ?> <tr bgcolor="#<?php print $colors["form_alternate1"];?>"> <td colspan="4"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Graph Template: <?php form_dropdown("graph_template_id",$available_graph_templates,"name","id","","","");?> </td> <td align="right"> <input type="image" src="images/button_add.gif" alt="Add" name="add_gt" align="absmiddle"> </td> </table> </td> </tr> <?php html_end_box(); html_start_box("<strong>Associated Data Queries</strong>", "98%", $colors["header"], "3", "center", ""); html_header(array("Data Query Name", "Debugging", "Re-Index Method", "Status"), 2); $selected_data_queries = db_fetch_assoc("select snmp_query.id, snmp_query.name, host_snmp_query.reindex_method from snmp_query,host_snmp_query where snmp_query.id=host_snmp_query.snmp_query_id and host_snmp_query.host_id=" . $_GET["id"] . " order by snmp_query.name"); $available_data_queries = db_fetch_assoc("select snmp_query.id, snmp_query.name from snmp_query order by snmp_query.name"); $keeper = array(); foreach ($available_data_queries as $item) { if (sizeof(db_fetch_assoc("SELECT snmp_query_id FROM host_snmp_query " . " WHERE ((host_id=" . $_GET["id"] . ")" . " and (snmp_query_id=" . $item["id"] ."))")) > 0) { /* do nothing */ } else { array_push($keeper, $item); } } $available_data_queries = $keeper; $i = 0; if (sizeof($selected_data_queries) > 0) { foreach ($selected_data_queries as $item) { $i++; /* get status information for this data query */ $num_dq_items = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"])); $num_dq_rows = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"] . " group by snmp_index")); $status = "success"; ?> <tr> <td style="padding: 4px;"> <strong><?php print $i;?>)</strong> <?php print $item["name"];?> </td> <td> (<a href="host.php?action=query_verbose&id=<?php print $item["id"];?>&host_id=<?php print $_GET["id"];?>">Verbose Query</a>) </td> <td> <?php print $reindex_types{$item["reindex_method"]};?> </td> <td> <?php print (($status == "success") ? "<span style='color: green;'>Success</span>" : "<span style='color: green;'>Fail</span>");?> [<?php print $num_dq_items;?> Item<?php print ($num_dq_items == 1 ? "" : "s");?>, <?php print $num_dq_rows;?> Row<?php print ($num_dq_rows == 1 ? "" : "s");?>] </td> <td align='right' nowrap> <a href='host.php?action=query_reload&id=<?php print $item["id"];?>&host_id=<?php print $_GET["id"];?>'><img src='images/reload_icon_small.gif' alt='Reload Data Query' border='0' align='absmiddle'></a> <a href='host.php?action=query_remove&id=<?php print $item["id"];?>&host_id=<?php print $_GET["id"];?>'><img src='images/delete_icon_large.gif' alt='Delete Data Query Association' border='0' align='absmiddle'></a> </td> </tr> <?php } }else{ print "<tr><td><em>No associated data queries.</em></td></tr>"; } ?> <tr bgcolor="#<?php print $colors["form_alternate1"];?>"> <td colspan="5"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Data Query: <?php form_dropdown("snmp_query_id",$available_data_queries,"name","id","","","");?> </td> <td nowrap>Re-Index Method: <?php form_dropdown("reindex_method",$reindex_types,"","","1","","");?> </td> <td align="right"> <input type="image" src="images/button_add.gif" alt="Add" name="add_dq" align="absmiddle"> </td> </table> </td> </tr> <?php html_end_box(); } form_save_button("host.php"); }
function host_edit() { global $fields_host_edit, $reindex_types; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('id')); /* ==================================================== */ api_plugin_hook('host_edit_top'); if (!empty($_REQUEST['id'])) { $host = db_fetch_row_prepared('SELECT * FROM host WHERE id = ?', array($_REQUEST['id'])); $header_label = '[edit: ' . htmlspecialchars($host['description']) . ']'; } else { $header_label = '[new]'; } if (!empty($host['id'])) { ?> <table width='100%' align='center'> <tr> <td class='textInfo' colspan='2'> <?php print htmlspecialchars($host['description']); ?> (<?php print htmlspecialchars($host['hostname']); ?> ) </td> <td rowspan='2' class='textInfo' valign='top' align='right'> <span class='linkMarker'>*</span><a class='hyperLink' href='<?php print htmlspecialchars('graphs_new.php?host_id=' . $host['id']); ?> '>Create Graphs for this Device</a><br> <span class='linkMarker'>*</span><a class='hyperLink' href='<?php print htmlspecialchars('data_sources.php?host_id=' . $host['id'] . '&ds_rows=30&filter=&template_id=-1&method_id=-1&page=1'); ?> '>Data Source List</a><br> <span class='linkMarker'>*</span><a class='hyperLink' href='<?php print htmlspecialchars('graphs.php?host_id=' . $host['id'] . '&graph_rows=30&filter=&template_id=-1&page=1'); ?> '>Graph List</a> <?php api_plugin_hook('device_edit_top_links'); ?> </td> </tr> <tr> <td valign='top' class='textHeader'> <div id='ping_results'>Pinging Device <i style='font-size:12px;' class='fa fa-spin fa-spinner'></i><br><br></div> </td> </tr> </table> <?php } html_start_box("<strong>Device</strong> {$header_label}", '100%', '', '3', 'center', ''); /* preserve the host template id if passed in via a GET variable */ if (!empty($_REQUEST['host_template_id'])) { $fields_host_edit['host_template_id']['value'] = $_REQUEST['host_template_id']; } draw_edit_form(array('config' => array('form_name' => 'chk'), 'fields' => inject_form_variables($fields_host_edit, isset($host) ? $host : array()))); /* we have to hide this button to make a form change in the main form trigger the correct * submit action */ echo "<div style='display:none;'><input type='submit' value='Default Submit Button'></div>"; html_end_box(); ?> <script type="text/javascript"> <!-- // default snmp information var snmp_community = $('#snmp_community').val(); var snmp_username = $('#snmp_username').val(); var snmp_password = $('#snmp_password').val(); var snmp_auth_protocol = $('#snmp_auth_protocol').val(); var snmp_priv_passphrase = $('#snmp_priv_passphrase').val(); var snmp_priv_protocol = $('#snmp_priv_protocol').val(); var snmp_context = $('#snmp_context').val(); var snmp_port = $('#snmp_port').val(); var snmp_timeout = $('#snmp_timeout').val(); var max_oids = $('#max_oids').val(); // default ping methods var ping_method = $('#ping_method').val(); var ping_port = $('#ping_port').val(); var ping_timeout = $('#ping_timeout').val(); var ping_retries = $('#ping_retries').val(); function setPing() { availability_method = $('#availability_method').val(); ping_method = $('#ping_method').val(); switch(availability_method) { case '0': // none $('#row_ping_method').css('display', 'none'); $('#row_ping_port').css('display', 'none'); $('#row_ping_timeout').css('display', 'none'); $('#row_ping_retries').css('display', 'none'); break; case '2': // snmp case '5': // snmp sysDesc case '6': // snmp getNext $('#row_ping_method').css('display', 'none'); $('#row_ping_port').css('display', 'none'); $('#row_ping_timeout').css('display', ''); $('#row_ping_retries').css('display', ''); break; default: // ping ok switch(ping_method) { case '1': // ping icmp $('#row_ping_method').css('display', ''); $('#row_ping_port').css('display', 'none'); $('#row_ping_timeout').css('display', ''); $('#row_ping_retries').css('display', ''); break; case '2': // ping udp case '3': // ping tcp $('#row_ping_method').css('display', ''); $('#row_ping_port').css('display', ''); $('#row_ping_timeout').css('display', ''); $('#row_ping_retries').css('display', ''); break; } break; } } function setAvailability() { if ($('#snmp_version').val() == '0') { methods = [ { value: '0', text: 'None' }, { value: '3', text: 'Ping' } ]; if ($('#availability_method').val() != '3' && $('#availability_method').val() != '0') { $('#availability_method').val('3'); } $('#availability_method').replaceOptions(methods, $('#availability_method').val()); }else{ methods = [ { value: '0', text: 'None' }, { value: '1', text: 'Ping and SNMP Uptime' }, { value: '2', text: 'SNMP Uptime' }, { value: '3', text: 'Ping' }, { value: '4', text: 'Ping or SNMP Uptime' }, { value: '5', text: 'SNMP Desc' }, { value: '6', text: 'SNMP GetNext' } ]; $('#availability_method').replaceOptions(methods, $('#availability_method').val()); } switch($('#availibility_method').val()) { case '0': // availability none $('#row_ping_method').hide(); $('#ping_method').val(0); $('#row_ping_timeout').hide(); $('#row_ping_port').hide(); $('#row_ping_timeout').hide(); $('#row_ping_retrie').hide(); break; case '1': // ping and snmp sysUptime case '3': // ping case '4': // ping or snmp sysUptime if (($('#row_ping_method').css('display', 'none')) || ($('#row_ping_method').css('display') == undefined)) { $('#ping_method').val(ping_method); $('#row_ping_method').css('display', ''); } break; case '2': // snmp sysUptime case '5': // snmp sysDesc case '6': // snmp getNext $('#row_ping_method').css('display', 'none'); $('#ping_method').val(0); break; } if ($('#availability_method-button').length) { $('#availability_method').selectmenu('refresh'); } } function changeHostForm() { setSNMP(); setAvailability(); setPing(); } function setSNMP() { snmp_version = $('#snmp_version').val(); switch(snmp_version) { case '0': // No SNMP $('#row_snmp_username').hide(); $('#row_snmp_password').hide(); $('#row_snmp_community').hide(); $('#row_snmp_auth_protocol').hide(); $('#row_snmp_priv_passphrase').hide(); $('#row_snmp_priv_protocol').hide(); $('#row_snmp_context').hide(); $('#row_snmp_port').hide(); $('#row_snmp_timeout').hide(); $('#row_max_oids').hide(); break; case '1': // SNMP v1 case '2': // SNMP v2c $('#row_snmp_username').hide(); $('#row_snmp_password').hide(); $('#row_snmp_community').show(); $('#row_snmp_auth_protocol').hide(); $('#row_snmp_priv_passphrase').hide(); $('#row_snmp_priv_protocol').hide(); $('#row_snmp_context').hide(); $('#row_snmp_port').show(); $('#row_snmp_timeout').show(); $('#row_max_oids').show(); break; case '3': // SNMP v3 $('#row_snmp_username').show(); $('#row_snmp_password').show(); $('#row_snmp_community').hide(); $('#row_snmp_auth_protocol').show(); $('#row_snmp_priv_passphrase').show(); $('#row_snmp_priv_protocol').show(); $('#row_snmp_context').show(); $('#row_snmp_port').show(); $('#row_snmp_timeout').show(); $('#row_max_oids').show(); break; } } $(function() { changeHostForm(); $('#dbghide').click(function(data) { $('#dqdebug').fadeOut('fast'); }); $.get('host.php?action=ping_host&id='+$('#id').val(), function(data) { $('#ping_results').html(data); }); }); --> </script> <?php if (isset($_REQUEST['display_dq_details']) && isset($_SESSION['debug_log']['data_query'])) { print "<table id='dqdebug' width='100%' class='cactiDebugTable' cellpadding='0' cellspacing='0' border='0' align='center'><tr><td>\n"; print "<table width='100%' class='cactiTableTitle' cellspacing='0' cellpadding='3' border='0'>\n"; print "<tr><td class='textHeaderDark'><a name='dqdbg'></a><strong>Data Query Debug Information</strong></td><td class='textHeaderDark' align='right'><a style='cursor:pointer;' id='dbghide' class='linkOverDark'>Hide</a></td></tr>\n"; print "</table>\n"; print "<table width='100%' class='cactiTable' cellspacing='0' cellpadding='3' border='0'>\n"; print "<tr><td class='odd'><span style='font-family: monospace;'>" . debug_log_return('data_query') . "</span></td></tr>"; print "</table>\n"; print "</table>\n"; } if (!empty($host['id'])) { html_start_box('<strong>Associated Graph Templates</strong>', '100%', '', '3', 'center', ''); html_header(array('Graph Template Name', 'Status'), 2); $selected_graph_templates = db_fetch_assoc_prepared('SELECT graph_templates.id, graph_templates.name FROM (graph_templates, host_graph) WHERE graph_templates.id = host_graph.graph_template_id AND host_graph.host_id = ? ORDER BY graph_templates.name', array($_REQUEST['id'])); $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'); $i = 0; if (sizeof($selected_graph_templates) > 0) { foreach ($selected_graph_templates as $item) { form_alternate_row('', true); /* get status information for this graph template */ $is_being_graphed = sizeof(db_fetch_assoc_prepared('SELECT id FROM graph_local WHERE graph_template_id = ? AND host_id = ?', array($item['id'], $_REQUEST['id']))) > 0 ? true : false; ?> <td style="padding: 4px;"> <strong><?php print $i; ?> )</strong> <?php print htmlspecialchars($item['name']); ?> </td> <td> <?php print $is_being_graphed == true ? "<span style='color: green;'>Is Being Graphed</span> (<a href='" . htmlspecialchars('graphs.php?action=graph_edit&id=' . db_fetch_cell_prepared('SELECT id FROM graph_local WHERE graph_template_id = ? AND host_id = ? LIMIT 0,1', array($item['id'], $_REQUEST['id']))) . "'>Edit</a>)" : "<span style='color: #484848;'>Not Being Graphed</span>"; ?> </td> <td align='right' nowrap> <a href='<?php print htmlspecialchars('host.php?action=gt_remove&id=' . $item['id'] . '&host_id=' . $_REQUEST['id']); ?> '><img src='images/delete_icon_large.gif' title='Delete Graph Template Association' alt='Delete Graph Template Association' border='0' align='middle'></a> </td> <?php form_end_row(); $i++; } } else { print "<tr class='tableRow'><td colspan='2'><em>No associated graph templates.</em></td></tr>"; } ?> <tr class='odd'> <td class='saveRow' colspan="4"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Graph Template: <?php form_dropdown('graph_template_id', $available_graph_templates, 'name', 'id', '', '', ''); ?> </td> <td align="right"> <input type="submit" value="Add" name="add_gt_x" title="Add Graph Template to Device"> </td> </table> </td> </tr> <?php html_end_box(); html_start_box('<strong>Associated Data Queries</strong>', '100%', '', '3', 'center', ''); html_header(array('Data Query Name', 'Debugging', 'Re-Index Method', 'Status'), 2); $selected_data_queries = db_fetch_assoc_prepared('SELECT snmp_query.id, snmp_query.name, host_snmp_query.reindex_method FROM (snmp_query, host_snmp_query) WHERE snmp_query.id = host_snmp_query.snmp_query_id AND host_snmp_query.host_id = ? ORDER BY snmp_query.name', array($_REQUEST['id'])); $available_data_queries = db_fetch_assoc('SELECT snmp_query.id, snmp_query.name FROM snmp_query ORDER BY snmp_query.name'); $keeper = array(); foreach ($available_data_queries as $item) { if (sizeof(db_fetch_assoc_prepared('SELECT snmp_query_id FROM host_snmp_query WHERE host_id = ? AND snmp_query_id = ?', array($_REQUEST['id'], $item['id']))) > 0) { /* do nothing */ } else { array_push($keeper, $item); } } $available_data_queries = $keeper; $i = 0; if (sizeof($selected_data_queries) > 0) { foreach ($selected_data_queries as $item) { form_alternate_row('', true); /* get status information for this data query */ $num_dq_items = sizeof(db_fetch_assoc_prepared('SELECT snmp_index FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ?', array($_REQUEST['id'], $item['id']))); $num_dq_rows = sizeof(db_fetch_assoc_prepared('SELECT snmp_index FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ? GROUP BY snmp_index', array($_REQUEST['id'], $item['id']))); $status = 'success'; ?> <td style="padding: 4px;"> <strong><?php print $i; ?> )</strong> <?php print htmlspecialchars($item['name']); ?> </td> <td> (<a href="<?php print htmlspecialchars('host.php?action=query_verbose&id=' . $item['id'] . '&host_id=' . $_REQUEST['id']); ?> ">Verbose Query</a>) </td> <td> <?php print $reindex_types[$item['reindex_method']]; ?> </td> <td> <?php print $status == 'success' ? "<span style='color: green;'>Success</span>" : "<span style='color: green;'>Fail</span>"; ?> [<?php print $num_dq_items; ?> Item<?php print $num_dq_items == 1 ? '' : 's'; ?> , <?php print $num_dq_rows; ?> Row<?php print $num_dq_rows == 1 ? '' : 's'; ?> ] </td> <td align='right' nowrap> <a href='<?php print htmlspecialchars('host.php?action=query_reload&id=' . $item['id'] . '&host_id=' . $_REQUEST['id']); ?> '><img src='images/reload_icon_small.gif' title='Reload Data Query' alt='Reload Data Query' border='0' align='middle'></a> <a href='<?php print htmlspecialchars('host.php?action=query_remove&id=' . $item['id'] . '&host_id=' . $_REQUEST['id']); ?> '><img src='images/delete_icon_large.gif' title='Delete Data Query Association' alt='Delete Data Query Association' border='0' align='middle'></a> </td> <?php form_end_row(); $i++; } } else { print "<tr class='tableRow'><td colspan='4'><em>No associated data queries.</em></td></tr>"; } ?> <tr class='odd'> <td class='saveRow' colspan="5"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Data Query: <?php form_dropdown('snmp_query_id', $available_data_queries, 'name', 'id', '', '', ''); ?> </td> <td nowrap>Re-Index Method: <?php form_dropdown('reindex_method', $reindex_types, '', '', read_config_option('reindex_method'), '', ''); ?> </td> <td align="right"> <input type="submit" value="Add" name="add_dq_x" title="Add Data Query to Device"> </td> </table> <a name='dqtop'></a> </td> </tr> <?php html_end_box(); } form_save_button('host.php', 'return'); api_plugin_hook('host_edit_bottom'); }
function poller_edit() { global $colors; require_once(CACTI_BASE_PATH . "/lib/poller/poller_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ /* remember if there's something we want to show to the user */ $debug_log = debug_log_return("poller"); if (!empty($debug_log)) { debug_log_clear("poller"); ?> <table class='topBoxAlt'> <tr bgcolor="<?php print $colors["light"];?>"> <td class='mono'> <?php print $debug_log;?> </td> </tr> </table> <br> <?php } if (!empty($_GET["id"])) { $poller = db_fetch_row("select * from poller where id=" . $_GET["id"]); $header_label = __("[edit: ") . $poller["description"] . "]"; }else{ $header_label = __("[new]"); $_GET["id"] = 0; } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='poller_edit'>\n"; html_start_box("<strong>" . __("Pollers") . "</strong> $header_label", "100", $colors["header"], 0, "center", "", true); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, true, 'poller_edit'); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables(poller_form_list(), (isset($poller) ? $poller : array())) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(); form_save_button_alt(); }
function host_edit() { global $colors, $fields_host_edit, $reindex_types; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ display_output_messages(); if (!empty($_GET["id"])) { $host = db_fetch_row("select * from host where id=" . $_GET["id"]); $header_label = "[edit: " . $host["description"] . "]"; } else { $header_label = "[new]"; } if (!empty($host["id"])) { ?> <table width="100%" align="center"> <tr> <td class="textInfo" colspan="2"> <?php print $host["description"]; ?> (<?php print $host["hostname"]; ?> ) </td> </tr> <tr> <td class="textHeader"> <?php if ($host["availability_method"] == AVAIL_SNMP || $host["availability_method"] == AVAIL_SNMP_AND_PING || $host["availability_method"] == AVAIL_SNMP_OR_PING) { ?> SNMP Information<br> <span style="font-size: 10px; font-weight: normal; font-family: monospace;"> <?php if ($host["snmp_community"] == "" && $host["snmp_username"] == "" || $host["snmp_version"] == 0) { print "<span style='color: #ab3f1e; font-weight: bold;'>SNMP not in use</span>\n"; } else { $snmp_system = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.1.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); /* modify for some system descriptions */ /* 0000937: System output in hosts.php poor for Alcatel */ if (substr_count($snmp_system, "00:")) { $snmp_system = str_replace("00:", "", $snmp_system); $snmp_system = str_replace(":", " ", $snmp_system); } if ($snmp_system == "") { print "<span style='color: #ff0000; font-weight: bold;'>SNMP error</span>\n"; } else { $snmp_uptime = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.3.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); $snmp_hostname = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.5.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); $snmp_location = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.6.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); $snmp_contact = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.4.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); print "<strong>System:</strong>" . html_split_string($snmp_system) . "<br>\n"; $days = intval($snmp_uptime / (60 * 60 * 24 * 100)); $remainder = $snmp_uptime % (60 * 60 * 24 * 100); $hours = intval($remainder / (60 * 60 * 100)); $remainder = $remainder % (60 * 60 * 100); $minutes = intval($remainder / (60 * 100)); print "<strong>Uptime:</strong> {$snmp_uptime}"; print " ({$days} days, {$hours} hours, {$minutes} minutes)<br>\n"; print "<strong>Hostname:</strong> {$snmp_hostname}<br>\n"; print "<strong>Location:</strong> {$snmp_location}<br>\n"; print "<strong>Contact:</strong> {$snmp_contact}<br>\n"; } } ?> </span> <?php } if ($host["availability_method"] == AVAIL_PING || $host["availability_method"] == AVAIL_SNMP_AND_PING || $host["availability_method"] == AVAIL_SNMP_OR_PING) { /* create new ping socket for host pinging */ $ping = new Net_Ping(); $ping->host = $host; $ping->port = $host["ping_port"]; /* perform the appropriate ping check of the host */ if ($ping->ping($host["availability_method"], $host["ping_method"], $host["ping_timeout"], $host["ping_retries"])) { $host_down = false; $color = "#000000"; } else { $host_down = true; $color = "#ff0000"; } ?> <br>Ping Results<br> <span style="font-size: 10px; font-weight: normal; color: <?php print $color; ?> ; font-family: monospace;"> <?php print $ping->ping_response; ?> </span> <?php } else { if ($host["availability_method"] == AVAIL_NONE) { ?> No Availability Check In Use<br> <?php } } ?> </td> <td class="textInfo" valign="top"> <span style="color: #c16921;">*</span><a href="graphs_new.php?host_id=<?php print $host["id"]; ?> ">Create Graphs for this Host</a><br> <span style="color: #c16921;">*</span><a href="data_sources.php?host_id=<?php print $host["id"]; ?> &ds_rows=30&filter=&template_id=-1&method_id=-1&page=1">Data Source List</a><br> <span style="color: #c16921;">*</span><a href="graphs.php?host_id=<?php print $host["id"]; ?> &graph_rows=30&filter=&template_id=-1&page=1">Graph List</a> </td> </tr> </table> <?php } html_start_box("<strong>Devices</strong> {$header_label}", "100%", $colors["header"], "3", "center", ""); /* preserve the host template id if passed in via a GET variable */ if (!empty($_GET["host_template_id"])) { $fields_host_edit["host_template_id"]["value"] = $_GET["host_template_id"]; } draw_edit_form(array("config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_host_edit, isset($host) ? $host : array()))); html_end_box(); ?> <script type="text/javascript"> <!-- // default snmp information var snmp_community = document.getElementById('snmp_community').value; var snmp_username = document.getElementById('snmp_username').value; var snmp_password = document.getElementById('snmp_password').value; var snmp_auth_protocol = document.getElementById('snmp_auth_protocol').value; var snmp_priv_passphrase = document.getElementById('snmp_priv_passphrase').value; var snmp_priv_protocol = document.getElementById('snmp_priv_protocol').value; var snmp_context = document.getElementById('snmp_context').value; var snmp_port = document.getElementById('snmp_port').value; var snmp_timeout = document.getElementById('snmp_timeout').value; var max_oids = document.getElementById('max_oids').value; // default ping methods var ping_method = document.getElementById('ping_method').value; var ping_port = document.getElementById('ping_port').value; var ping_timeout = document.getElementById('ping_timeout').value; var ping_retries = document.getElementById('ping_retries').value; var availability_methods = document.getElementById('availability_method').options; var num_methods = document.getElementById('availability_method').length; var selectedIndex = document.getElementById('availability_method').selectedIndex; var agent = navigator.userAgent; agent = agent.match("MSIE"); function setPingVisibility() { availability_method = document.getElementById('availability_method').value; ping_method = document.getElementById('ping_method').value; /* debugging, uncomment as required */ //alert("The availability method is '" + availability_method + "'"); //alert("The ping method is '" + ping_method + "'"); switch(availability_method) { case "0": // none document.getElementById('row_ping_method').style.display = "none"; document.getElementById('row_ping_port').style.display = "none"; document.getElementById('row_ping_timeout').style.display = "none"; document.getElementById('row_ping_retries').style.display = "none"; break; case "2": // snmp document.getElementById('row_ping_method').style.display = "none"; document.getElementById('row_ping_port').style.display = "none"; document.getElementById('row_ping_timeout').style.display = ""; document.getElementById('row_ping_retries').style.display = ""; break; default: // ping ok switch(ping_method) { case "1": // ping icmp document.getElementById('row_ping_method').style.display = ""; document.getElementById('row_ping_port').style.display = "none"; document.getElementById('row_ping_timeout').style.display = ""; document.getElementById('row_ping_retries').style.display = ""; break; case "2": // ping udp case "3": // ping tcp document.getElementById('row_ping_method').style.display = ""; document.getElementById('row_ping_port').style.display = ""; document.getElementById('row_ping_timeout').style.display = ""; document.getElementById('row_ping_retries').style.display = ""; break; } break; } } function addSelectItem(item, formObj) { if (agent != "MSIE") { formObj.add(item,null); // standards compliant }else{ formObj.add(item); // IE only } } function setAvailability(type) { /* get the availability structure */ var am=document.getElementById('availability_method'); /* get current selectedIndex */ selectedIndex = document.getElementById('availability_method').selectedIndex; /* debugging uncomment as required */ //alert("The selectedIndex is '" + selectedIndex + "'"); //alert("The array length is '" + am.length + "'"); switch(type) { case "NoSNMP": /* remove snmp options */ if (am.length == 5) { am.remove(1); am.remove(1); am.remove(1); } /* set the index to something valid, like "ping" */ if (selectedIndex > 1) { am.selectedIndex=1; } break; case "All": /* restore all options */ if (am.length == 2) { am.remove(0); am.remove(0); var a=document.createElement('option'); var b=document.createElement('option'); var c=document.createElement('option'); var d=document.createElement('option'); var e=document.createElement('option'); a.value="0"; a.text="None"; addSelectItem(a,am); b.value="1"; b.text="Ping and SNMP"; addSelectItem(b,am); e.value="4"; e.text="Ping or SNMP"; addSelectItem(e,am); c.value="2"; c.text="SNMP"; addSelectItem(c,am); d.value="3"; d.text="Ping"; addSelectItem(d,am); /* restore the correct index number */ if (selectedIndex == 0) { am.selectedIndex = 0; }else{ am.selectedIndex = 3; } } break; } setAvailabilityVisibility(type, am.selectedIndex); setPingVisibility(); } function setAvailabilityVisibility(type, selectedIndex) { switch(type) { case "NoSNMP": switch(selectedIndex) { case "0": // availability none document.getElementById('row_ping_method').style.display="none"; document.getElementById('ping_method').value=0; break; case "1": // ping document.getElementById('row_ping_method').style.display=""; document.getElementById('ping_method').value=ping_method; break; } case "All": switch(selectedIndex) { case "0": // availability none document.getElementById('row_ping_method').style.display="none"; document.getElementById('ping_method').value=0; break; case "1": // ping and snmp case "3": // ping case "4": // ping or snmp if ((document.getElementById('row_ping_method').style.display == "none") || (document.getElementById('row_ping_method').style.display == undefined)) { document.getElementById('ping_method').value=ping_method; document.getElementById('row_ping_method').style.display=""; } break; case "2": // snmp document.getElementById('row_ping_method').style.display="none"; document.getElementById('ping_method').value="0"; break; } } } function changeHostForm() { snmp_version = document.getElementById('snmp_version').value; switch(snmp_version) { case "0": setAvailability("NoSNMP"); setSNMP("None"); break; case "1": case "2": setAvailability("All"); setSNMP("v1v2"); break; case "3": setAvailability("All"); setSNMP("v3"); break; } } function setSNMP(snmp_type) { switch(snmp_type) { case "None": document.getElementById('row_snmp_username').style.display = "none"; document.getElementById('row_snmp_password').style.display = "none"; document.getElementById('row_snmp_community').style.display = "none"; document.getElementById('row_snmp_auth_protocol').style.display = "none"; document.getElementById('row_snmp_priv_passphrase').style.display = "none"; document.getElementById('row_snmp_priv_protocol').style.display = "none"; document.getElementById('row_snmp_context').style.display = "none"; document.getElementById('row_snmp_port').style.display = "none"; document.getElementById('row_snmp_timeout').style.display = "none"; document.getElementById('row_max_oids').style.display = "none"; break; case "v1v2": document.getElementById('row_snmp_username').style.display = "none"; document.getElementById('row_snmp_password').style.display = "none"; document.getElementById('row_snmp_community').style.display = ""; document.getElementById('row_snmp_auth_protocol').style.display = "none"; document.getElementById('row_snmp_priv_passphrase').style.display = "none"; document.getElementById('row_snmp_priv_protocol').style.display = "none"; document.getElementById('row_snmp_context').style.display = "none"; document.getElementById('row_snmp_port').style.display = ""; document.getElementById('row_snmp_timeout').style.display = ""; document.getElementById('row_max_oids').style.display = ""; break; case "v3": document.getElementById('row_snmp_username').style.display = ""; document.getElementById('row_snmp_password').style.display = ""; document.getElementById('row_snmp_community').style.display = "none"; document.getElementById('row_snmp_auth_protocol').style.display = ""; document.getElementById('row_snmp_priv_passphrase').style.display = ""; document.getElementById('row_snmp_priv_protocol').style.display = ""; document.getElementById('row_snmp_context').style.display = ""; document.getElementById('row_snmp_port').style.display = ""; document.getElementById('row_snmp_timeout').style.display = ""; document.getElementById('row_max_oids').style.display = ""; break; } } function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); } } } addLoadEvent(changeHostForm); --> </script> <?php if (isset($_GET["display_dq_details"]) && isset($_SESSION["debug_log"]["data_query"])) { html_start_box("<strong>Data Query Debug Information</strong>", "100%", $colors["header"], "3", "center", ""); print "<tr><td><span style='font-family: monospace;'>" . debug_log_return("data_query") . "</span></td></tr>"; html_end_box(); } if (!empty($host["id"])) { html_start_box("<strong>Associated Graph Templates</strong>", "100%", $colors["header"], "3", "center", ""); html_header(array("Graph Template Name", "Status"), 2); $selected_graph_templates = db_fetch_assoc("select\n\t\t\tgraph_templates.id,\n\t\t\tgraph_templates.name\n\t\t\tfrom (graph_templates,host_graph)\n\t\t\twhere graph_templates.id=host_graph.graph_template_id\n\t\t\tand host_graph.host_id=" . $_GET["id"] . "\n\t\t\torder by graph_templates.name"); $available_graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id, graph_templates.name\n\t\t\tFROM snmp_query_graph RIGHT JOIN graph_templates\n\t\t\tON (snmp_query_graph.graph_template_id = graph_templates.id)\n\t\t\tWHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name"); $i = 0; if (sizeof($selected_graph_templates) > 0) { foreach ($selected_graph_templates as $item) { $i++; /* get status information for this graph template */ $is_being_graphed = sizeof(db_fetch_assoc("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"])) > 0 ? true : false; ?> <tr> <td style="padding: 4px;"> <strong><?php print $i; ?> )</strong> <?php print $item["name"]; ?> </td> <td> <?php print $is_being_graphed == true ? "<span style='color: green;'>Is Being Graphed</span> (<a href='graphs.php?action=graph_edit&id=" . db_fetch_cell("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"] . " limit 0,1") . "'>Edit</a>)" : "<span style='color: #484848;'>Not Being Graphed</span>"; ?> </td> <td align='right' nowrap> <a href='host.php?action=gt_remove&id=<?php print $item["id"]; ?> &host_id=<?php print $_GET["id"]; ?> '><img src='images/delete_icon_large.gif' title='Delete Graph Template Association' alt='Delete Graph Template Association' border='0' align='absmiddle'></a> </td> </tr> <?php } } else { print "<tr><td><em>No associated graph templates.</em></td></tr>"; } ?> <tr bgcolor="#<?php print $colors["form_alternate1"]; ?> "> <td colspan="4"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Graph Template: <?php form_dropdown("graph_template_id", $available_graph_templates, "name", "id", "", "", ""); ?> </td> <td align="right"> <input type="image" src="images/button_add.gif" alt="Add" name="add_gt" align="absmiddle"> </td> </table> </td> </tr> <?php html_end_box(); html_start_box("<strong>Associated Data Queries</strong>", "100%", $colors["header"], "3", "center", ""); html_header(array("Data Query Name", "Debugging", "Re-Index Method", "Status"), 2); $selected_data_queries = db_fetch_assoc("select\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name,\n\t\t\thost_snmp_query.reindex_method\n\t\t\tfrom (snmp_query,host_snmp_query)\n\t\t\twhere snmp_query.id=host_snmp_query.snmp_query_id\n\t\t\tand host_snmp_query.host_id=" . $_GET["id"] . "\n\t\t\torder by snmp_query.name"); $available_data_queries = db_fetch_assoc("select\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name\n\t\t\tfrom snmp_query\n\t\t\torder by snmp_query.name"); $keeper = array(); foreach ($available_data_queries as $item) { if (sizeof(db_fetch_assoc("SELECT snmp_query_id FROM host_snmp_query " . " WHERE ((host_id=" . $_GET["id"] . ")" . " and (snmp_query_id=" . $item["id"] . "))")) > 0) { /* do nothing */ } else { array_push($keeper, $item); } } $available_data_queries = $keeper; $i = 0; if (sizeof($selected_data_queries) > 0) { foreach ($selected_data_queries as $item) { $i++; /* get status information for this data query */ $num_dq_items = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"])); $num_dq_rows = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"] . " group by snmp_index")); $status = "success"; ?> <tr> <td style="padding: 4px;"> <strong><?php print $i; ?> )</strong> <?php print $item["name"]; ?> </td> <td> (<a href="host.php?action=query_verbose&id=<?php print $item["id"]; ?> &host_id=<?php print $_GET["id"]; ?> ">Verbose Query</a>) </td> <td> <?php print $reindex_types[$item["reindex_method"]]; ?> </td> <td> <?php print $status == "success" ? "<span style='color: green;'>Success</span>" : "<span style='color: green;'>Fail</span>"; ?> [<?php print $num_dq_items; ?> Item<?php print $num_dq_items == 1 ? "" : "s"; ?> , <?php print $num_dq_rows; ?> Row<?php print $num_dq_rows == 1 ? "" : "s"; ?> ] </td> <td align='right' nowrap> <a href='host.php?action=query_reload&id=<?php print $item["id"]; ?> &host_id=<?php print $_GET["id"]; ?> '><img src='images/reload_icon_small.gif' title='Reload Data Query' alt='Reload Data Query' border='0' align='absmiddle'></a> <a href='host.php?action=query_remove&id=<?php print $item["id"]; ?> &host_id=<?php print $_GET["id"]; ?> '><img src='images/delete_icon_large.gif' title='Delete Data Query Association' alt='Delete Data Query Association' border='0' align='absmiddle'></a> </td> </tr> <?php } } else { print "<tr><td><em>No associated data queries.</em></td></tr>"; } ?> <tr bgcolor="#<?php print $colors["form_alternate1"]; ?> "> <td colspan="5"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Data Query: <?php form_dropdown("snmp_query_id", $available_data_queries, "name", "id", "", "", ""); ?> </td> <td nowrap>Re-Index Method: <?php form_dropdown("reindex_method", $reindex_types, "", "", read_config_option("reindex_method"), "", ""); ?> </td> <td align="right"> <input type="image" src="images/button_add.gif" alt="Add" name="add_dq" align="absmiddle"> </td> </table> </td> </tr> <?php html_end_box(); } form_save_button("host.php"); }
function graphs() { global $colors; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("graph_type")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_graphs_new_host_id"); kill_session_var("sess_graphs_new_graph_type"); kill_session_var("sess_graphs_new_filter"); unset($_REQUEST["host_id"]); unset($_REQUEST["graph_type"]); unset($_REQUEST["filter"]); $changed = true; } else { /* if any of the settings changed, reset the page number */ $changed = 0; $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"); } 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", ""); $host = db_fetch_row("select id,description,hostname,host_template_id from host where id=" . $_REQUEST["host_id"]); $row_limit = read_config_option("num_rows_data_query"); $debug_log = debug_log_return("new_graphs"); ?> <script type="text/javascript"> <!-- function applyGraphsNewFilterChange(objForm) { strURL = '?graph_type=' + objForm.graph_type.value; strURL = strURL + '&host_id=' + objForm.host_id.value; strURL = strURL + '&filter=' + objForm.filter.value;; document.location = strURL; } --> </script> <?php if (!empty($debug_log)) { debug_log_clear("new_graphs"); ?> <table width='100%' style='background-color: #f5f5f5; border: 1px solid #bbbbbb;' align='center'> <tr bgcolor="<?php print $colors["light"]; ?> "> <td style="padding: 3px; font-family: monospace;"> <?php print $debug_log; ?> </td> </tr> </table> <br> <?php } ?> <form name="form_graphs_new"> <table width="100%" cellpadding="4" align="center"> <tr> <td nowrap style='white-space: nowrap;' width="30%" class="textInfo"> <?php print $host["description"]; ?> (<?php print $host["hostname"]; ?> ) </td> <td align="left" class="textInfo" colspan="2" style="color: #aaaaaa;"> <?php if (!empty($host["host_template_id"])) { print db_fetch_cell("select name from host_template where id=" . $host["host_template_id"]); } ?> </td> </tr> </table> <table width="100%" cellpadding="0" align="center"> <tr> <td nowrap style='white-space: nowrap;' width="55" class="textArea"> Host: </td> <td width="1"> <select name="host_id" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <?php $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"); if (sizeof($hosts) > 0) { foreach ($hosts as $item) { print "<option value='" . $item["id"] . "'"; if ($_REQUEST["host_id"] == $item["id"]) { print " selected"; } print ">" . $item["name"] . "</option>\n"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;' width="100" class="textArea"> Graph Types: </td> <td width="1"> <select name="graph_type" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <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("SELECT\n\t\t\t\t\tsnmp_query.id,\n\t\t\t\t\tsnmp_query.name,\n\t\t\t\t\tsnmp_query.xml_path\n\t\t\t\t\tFROM (snmp_query,host_snmp_query)\n\t\t\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\n\t\t\t\t\tAND host_snmp_query.host_id=" . $host["id"] . "\n\t\t\t\t\tORDER BY snmp_query.name"); 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 nowrap style='white-space: nowrap;' class="textInfo" align="center" valign="top"> <span style="white-space: nowrap; color: #c16921;">*</span><a href="host.php?action=edit&id=<?php print $_REQUEST["host_id"]; ?> ">Edit this Host</a><br> <span style="white-space: nowrap; color: #c16921;">*</span><a href="host.php?action=edit">Create New Host</a> </td> </tr> </table> <?php if ($_REQUEST["graph_type"] > 0) { ?> <table width="100%" cellpadding="0" align="center"> <tr> <td nowrap style='white-space: nowrap;' width="55" class="textArea"> Search: </td> <td nowrap style='white-space: nowrap;' width="200"> <input type="text" name="filter" size="30" width="200" value="<?php print $_REQUEST["filter"]; ?> "> </td> <td align="left" nowrap style='white-space: nowrap;'> <input type="image" src="images/button_go.gif" name="go" alt="Go" border="0" align="absmiddle"> <input type="image" src="images/button_clear.gif" name="clear" alt="Clear" border="0" align="absmiddle"> </td> </tr> </table> <?php } else { form_hidden_box("filter", $_REQUEST["filter"], ""); } ?> </form> <form name="chk" method="post" action="graphs_new.php"> <?php $total_rows = sizeof(db_fetch_assoc("select graph_template_id from host_graph where host_id=" . $_REQUEST["host_id"])); $i = 0; 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"); } } } if ($_REQUEST["graph_type"] < 0) { html_start_box("<strong>Graph Templates</strong>", "100%", $colors["header"], "3", "center", ""); print "\t<tr bgcolor='#" . $colors["header_panel"] . "'>\n\t\t\t\t<td class='textSubHeaderDark'>Graph Template Name</td>\n\t\t\t\t<td width='1%' align='center' bgcolor='#819bc0' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='Select All' onClick='SelectAll(\"cg\",this.checked);gt_update_selection_indicators();'></td>\n\n\t\t\t</tr>\n"; $graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id AS graph_template_id,\n\t\t\tgraph_templates.name AS graph_template_name\n\t\t\tFROM (host_graph,graph_templates)\n\t\t\tWHERE host_graph.graph_template_id=graph_templates.id\n\t\t\tAND host_graph.host_id=" . $_REQUEST["host_id"] . "\n\t\t\tORDER BY graph_templates.name"); $template_graphs = db_fetch_assoc("SELECT\n\t\t\tgraph_local.graph_template_id\n\t\t\tFROM (graph_local,host_graph)\n\t\t\tWHERE graph_local.graph_template_id=host_graph.graph_template_id\n\t\t\tAND graph_local.host_id=host_graph.host_id\n\t\t\tAND graph_local.host_id=" . $host["id"] . "\n\t\t\tGROUP BY graph_local.graph_template_id"); print "<script type='text/javascript'>\nvar gt_created_graphs = new Array()\n</script>\n"; if (sizeof($template_graphs) > 0) { print "<script type='text/javascript'>\n<!--\n"; print "var gt_created_graphs = new Array("; $cg_ctr = 0; foreach ($template_graphs as $template_graph) { print ($cg_ctr > 0 ? "," : "") . "'" . $template_graph["graph_template_id"] . "'"; $cg_ctr++; } print ")\n"; print "//-->\n</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}' bgcolor='#" . ($i % 2 == 0 ? "ffffff" : $colors["light"]) . "'>"; $i++; print "\t\t<td onClick='gt_select_line(" . $graph_template["graph_template_id"] . ");'><span id='gt_text{$query_row}" . "_0'>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'><strong>Create:</strong> " . $graph_template["graph_template_name"] . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}' onClick='gt_update_selection_indicators();'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>"; } } print "<script type='text/javascript'>gt_update_deps(1);</script>\n"; $available_graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id, graph_templates.name\n\t\t\tFROM snmp_query_graph RIGHT JOIN graph_templates\n\t\t\tON (snmp_query_graph.graph_template_id = graph_templates.id)\n\t\t\tWHERE (((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 bgcolor='#" . ($i % 2 == 0 ? "ffffff" : $colors["light"]) . "'>\n\t\t\t\t<td colspan='2' width='60' nowrap>\n\t\t\t\t\t<strong>Create:</strong> "; form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(Select a graph type to create)", "", "textArea"); print "\t\t</td>\n\t\t\t</tr>"; html_end_box(); } if ($_REQUEST["graph_type"] != -1) { $snmp_queries = db_fetch_assoc("SELECT\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name,\n\t\t\tsnmp_query.xml_path\n\t\t\tFROM (snmp_query,host_snmp_query)\n\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\n\t\t\tAND host_snmp_query.host_id=" . $host["id"] . ($_REQUEST["graph_type"] != -2 ? " AND snmp_query.id=" . $_REQUEST["graph_type"] : '') . "\n\t\t\tORDER BY snmp_query.name"); print "<script type='text/javascript'>\nvar created_graphs = new Array()\n</script>\n"; 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("SELECT count(*) FROM host_snmp_cache WHERE host_id=" . $host["id"] . " and snmp_query_id=" . $snmp_query["id"] . " AND field_name='{$field_name}'"); } } } } if (!isset($total_rows)) { $total_rows = 0; } $snmp_query_graphs = db_fetch_assoc("SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " ORDER BY snmp_query_graph.name"); if (sizeof($snmp_query_graphs) > 0) { print "<script type='text/javascript'>\n<!--\n"; foreach ($snmp_query_graphs as $snmp_query_graph) { $created_graphs = db_fetch_assoc("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='" . $snmp_query_graph["id"] . "'\n\t\t\t\t\t\tAND data_local.host_id=" . $host["id"]); print "created_graphs[" . $snmp_query_graph["id"] . "] = new Array("; $cg_ctr = 0; if (sizeof($created_graphs) > 0) { foreach ($created_graphs as $created_graph) { print ($cg_ctr > 0 ? "," : "") . "'" . encode_data_query_index($created_graph["snmp_index"]) . "'"; $cg_ctr++; } } print ")\n"; } print "//-->\n</script>\n"; } print "\t<table width='100%' style='background-color: #" . $colors["form_alternate2"] . "; border: 1px solid #" . $colors["header"] . ";' align='center' cellpadding='3' cellspacing='0'>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td bgcolor='#" . $colors["header"] . "' 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='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='Reload Associated Query' 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("SELECT DISTINCT field_name\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND snmp_query_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\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND 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\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND 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"); } if ($total_rows > $row_limit) { /* generate page list */ $url_page_select = get_page_list($page, MAX_DISPLAY_PAGES, $row_limit, $total_rows, "graphs_new.php?", "page" . $snmp_query["id"]); $nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'>\n\t\t\t\t\t\t\t\t\t<td colspan='15'>\n\t\t\t\t\t\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<strong><< "; if ($page > 1) { $nav .= "<a class='linkOverDark' href='graphs_new.php?page" . $snmp_query["id"] . "=" . ($page - 1) . "'>"; } $nav .= "Previous"; if ($page > 1) { $nav .= "</a>"; } $nav .= "</strong>\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t\t\t\tShowing Rows " . ($row_limit * ($page - 1) + 1) . " to " . ($total_rows < $row_limit || $total_rows < $row_limit * $page ? $total_rows : $row_limit * $page) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<strong>"; if ($page * $row_limit < $total_rows) { $nav .= "<a class='linkOverDark' href='graphs_new.php?page" . $snmp_query["id"] . "=" . ($page + 1) . "'>"; } $nav .= "Next"; if ($page * $row_limit < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n"; print $nav; } while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { foreach ($field_names as $row) { if ($row["field_name"] == $field_name) { $html_dq_header .= "<td height='1'><strong><font color='#" . $colors["header_text"] . "'>" . $field_array["name"] . "</font></strong></td>\n"; break; } } } } if (!sizeof($snmp_query_indexes)) { print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><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='host.php?action=query_verbose&id=" . $snmp_query["id"] . "&host_id=" . $host["id"] . "'>run this data\n\t\t\t\t\t\t\tquery in debug mode</a> to get more information.</td></tr>\n"; } else { print "\t<tr bgcolor='#" . $colors["header_panel"] . "'>\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' bgcolor='#819bc0' 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);dq_update_selection_indicators();'></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}' bgcolor='#" . ($row_counter % 2 == 0 ? "ffffff" : $colors["light"]) . "'>"; $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 onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'>" . (strlen($_REQUEST["filter"]) ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $row[$field_name]) : $row[$field_name]) . "</span></td>"; } else { print "<td onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'></span></td>"; } $column_counter++; } } } print "<td align='right'>"; print "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}' onClick='dq_update_selection_indicators();'>"; print "</td>"; print "</tr>\n"; $row_counter++; } } if ($total_rows > $row_limit) { print $nav; } } else { print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Search Returned no Rows.</td></tr>\n"; } } else { print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Error in data query.</td></tr>\n"; } print "</table>"; /* draw the graph template drop down here */ $data_query_graphs = db_fetch_assoc("select snmp_query_graph.id,snmp_query_graph.name from snmp_query_graph where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " order by snmp_query_graph.name"); if (sizeof($data_query_graphs) == 1) { form_hidden_box("sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"], $data_query_graphs[0]["id"], ""); } 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='1' valign='top'>\n\t\t\t\t\t\t\t\t<img src='images/arrow.gif' alt='' align='absmiddle'> \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<span style='font-size: 12px; font-style: italic;'>Select a graph type:</span> \n\t\t\t\t\t\t\t\t<select name='sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"] . "' onChange='dq_update_deps(" . $snmp_query["id"] . "," . $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>"; } print "<br>"; print "<script type='text/javascript'>dq_update_deps(" . $snmp_query["id"] . "," . $num_visible_fields . ");</script>\n"; } } } form_hidden_box("save_component_graph", "1", ""); form_hidden_box("host_id", $host["id"], "0"); form_hidden_box("host_template_id", $host["host_template_id"], "0"); form_save_button(isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "index.php"); print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n"; print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n"; }
function graphs() { /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("graph_type")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_graphs_new_filter"); unset($_REQUEST["filter"]); $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"); } 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", ""); $host = db_fetch_row("select id,description,hostname,host_template_id from host where id=" . $_REQUEST["host_id"]); $row_limit = read_config_option("num_rows_data_query"); $debug_log = debug_log_return("new_graphs"); $header = " [ " . htmlspecialchars($host["description"]) . " (" . htmlspecialchars($host["hostname"]) . ") " . (!empty($host["host_template_id"]) ? htmlspecialchars(db_fetch_cell("select name from host_template where id=" . $host["host_template_id"])) : '') . " ]"; html_start_box("<strong>New Graphs for</strong> {$header}", "100%", "", "3", "center", ""); form_alternate_row(); print "<td>"; if (!empty($debug_log)) { debug_log_clear("new_graphs"); if (read_config_option("cacti_popup_messages") == "on") { ?> <div id='message'> <?php print "<table align='center' class='cactiTable' width='100%'><tr><td style='align:center;padding:3px;font-weight:bold;font-size:10pt;text-align:center;'>Graphs Created</td><td style='width:1px;align:right;'><input type='button' value='Clear' onClick='javascript:document.getElementById(\"message\").style.display=\"none\"' style='align=right;'></td></tr></table>"; ?> <?php print "<table align='left' style='width:100%;'><tr><td><ul style='text-align:left;white-space:nowrap;color:#000000;padding:2px 10px;margin:10px;'>" . $debug_log . "</ul></td></tr></table>"; ?> </div> <?php } else { ?> <table width='100%' class='textArea' align='center'> <tr class='even'> <td style="padding: 3px; font-family: monospace;"> <ul style='margin:0px 5px;padding-left:10px'><?php print $debug_log; ?> </ul> </td> </tr> </table> <br><?php } } ?> <script type="text/javascript"> <!-- <?php if (read_config_option("cacti_popup_messages") == "on") { ?> var obj = document.getElementById('message'); if (obj) { if (window.innerHeight) { height = window.innerHeight; width = window.innerWidth; }else{ height = document.body.clientHeight; width = document.body.clientWidth; } obj.style.class = "popupBox"; cw = obj.offsetWidth; // Adjust for IE6 if (!cw) cw = 150; ch = obj.offsetHeight; obj.style.top = '65px'; obj.style.left = ((width/2) - (cw/2) - 88)+'px'; } <?php } ?> function applyGraphsNewFilterChange(objForm) { strURL = '?graph_type=' + objForm.graph_type.value; strURL = strURL + '&host_id=' + objForm.host_id.value; strURL = strURL + '&filter=' + objForm.filter.value;; document.location = strURL; } --> </script> <form name="form_graphs_new" action="graphs_new.php"> <table width="100%" class="textHeader" cellpadding="2" align="left"> <tr> <td width="55" valign='top'> Host: </td> <td width="1" valign='top'> <select name="host_id" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <?php $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"); if (sizeof($hosts) > 0) { foreach ($hosts as $item) { print "<option value='" . $item["id"] . "'"; if ($_REQUEST["host_id"] == $item["id"]) { print " selected"; } print ">" . htmlspecialchars($item["name"]) . "</option>\n"; } } ?> </select> </td> <td style='white-space:nowrap;' valign='top' width="100"> Graph Types: </td> <td width="1" valign='top'> <select name="graph_type" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <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("SELECT\n\t\t\t\t\tsnmp_query.id,\n\t\t\t\t\tsnmp_query.name,\n\t\t\t\t\tsnmp_query.xml_path\n\t\t\t\t\tFROM (snmp_query,host_snmp_query)\n\t\t\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\n\t\t\t\t\tAND host_snmp_query.host_id=" . $host["id"] . "\n\t\t\t\t\tORDER BY snmp_query.name"); 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 rowspan="2" class="textInfo" align="right" valign="top"> <span class="linkMarker">*</span><a href="<?php print htmlspecialchars("host.php?action=edit&id=" . $_REQUEST["host_id"]); ?> ">Edit this Host</a><br> <span class="linkMarker">*</span><a href="<?php print htmlspecialchars("host.php?action=edit"); ?> ">Create New Host</a><br> <?php api_plugin_hook('graphs_new_top_links'); ?> </td> </tr> <?php if ($_REQUEST["graph_type"] > 0) { ?> <tr> <td width="55" valign='top'> Search: </td> <td valign='top'> <input type="text" name="filter" size="30" value="<?php print htmlspecialchars(get_request_var_request("filter")); ?> "> </td> <td colspan='2' valign='top'> <input type="submit" value="Go" title="Set/Refresh Filters"> <input type="submit" name="clear_x" value="Clear" title="Clear Filters"> </td> </tr> <?php } else { form_hidden_box("filter", $_REQUEST["filter"], ""); } ?> </table> </form> </td> </tr> <?php html_end_box(); ?> <form name="chk" method="post" action="graphs_new.php"> <?php $total_rows = sizeof(db_fetch_assoc("select graph_template_id from host_graph where host_id=" . $_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(\"cg\",this.checked);gt_update_selection_indicators();'></td>\n\n\t\t\t</tr>\n"; $graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id AS graph_template_id,\n\t\t\tgraph_templates.name AS graph_template_name\n\t\t\tFROM (host_graph,graph_templates)\n\t\t\tWHERE host_graph.graph_template_id=graph_templates.id\n\t\t\tAND host_graph.host_id=" . $_REQUEST["host_id"] . "\n\t\t\tORDER BY graph_templates.name"); $template_graphs = db_fetch_assoc("SELECT\n\t\t\tgraph_local.graph_template_id\n\t\t\tFROM (graph_local,host_graph)\n\t\t\tWHERE graph_local.graph_template_id=host_graph.graph_template_id\n\t\t\tAND graph_local.host_id=host_graph.host_id\n\t\t\tAND graph_local.host_id=" . $host["id"] . "\n\t\t\tGROUP BY graph_local.graph_template_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='" . ($i % 2 == 0 ? "odd" : "even") . "'>"; $i++; print "\t\t<td onClick='gt_select_line(" . $graph_template["graph_template_id"] . ");'>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'><strong>Create:</strong> " . htmlspecialchars($graph_template["graph_template_name"]) . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}' onClick='gt_update_selection_indicators();'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>"; } } $script .= "gt_update_deps(1);\n"; $available_graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id, graph_templates.name\n\t\t\tFROM snmp_query_graph RIGHT JOIN graph_templates\n\t\t\tON (snmp_query_graph.graph_template_id = graph_templates.id)\n\t\t\tWHERE (((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='" . ($i % 2 == 0 ? "odd" : "even") . "'>\n\t\t\t\t<td colspan='2' width='60' nowrap>\n\t\t\t\t\t<strong>Create:</strong> "; form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(Select a graph type to create)", "", "textArea"); print "\t\t</td>\n\t\t\t</tr>"; html_end_box(); } if ($_REQUEST["graph_type"] != -1) { $snmp_queries = db_fetch_assoc("SELECT\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name,\n\t\t\tsnmp_query.xml_path\n\t\t\tFROM (snmp_query,host_snmp_query)\n\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\n\t\t\tAND host_snmp_query.host_id=" . $host["id"] . ($_REQUEST["graph_type"] != -2 ? " AND snmp_query.id=" . $_REQUEST["graph_type"] : '') . "\n\t\t\tORDER 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("SELECT count(*) FROM host_snmp_cache WHERE host_id=" . $host["id"] . " and snmp_query_id=" . $snmp_query["id"] . " AND field_name='{$field_name}'"); } } } } if (!isset($total_rows)) { $total_rows = 0; } $snmp_query_graphs = db_fetch_assoc("SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " ORDER BY snmp_query_graph.name"); if (sizeof($snmp_query_graphs) > 0) { foreach ($snmp_query_graphs as $snmp_query_graph) { $created_graphs = db_fetch_assoc("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='" . $snmp_query_graph["id"] . "'\n\t\t\t\t\t\tAND data_local.host_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>\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='middle'></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("SELECT DISTINCT field_name\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND snmp_query_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\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND 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\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND 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") { 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\n\t\t\t\t\t\t\tquery 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);dq_update_selection_indicators();'></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='" . ($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 onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $row[$field_name]) : $row[$field_name]) . "</span></td>"; } else { print "<td onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'></span></td>"; } $column_counter++; } } } print "<td align='right'>"; print "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}' onClick='dq_update_selection_indicators();'>"; print "</td>"; print "</tr>\n"; $row_counter++; } } if ($total_rows > $row_limit) { print $nav; } } else { print "<tr class='odd'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Search Returned no Rows.</td></tr>\n"; } } else { print "<tr class='odd'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Error in data query.</td></tr>\n"; } print "</table>"; /* draw the graph template drop down here */ $data_query_graphs = db_fetch_assoc("select snmp_query_graph.id,snmp_query_graph.name from snmp_query_graph where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " order by snmp_query_graph.name"); 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='1' valign='top'>\n\t\t\t\t\t\t\t\t<img src='images/arrow.gif' alt=''> \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<span style='font-size: 12px; font-style: italic;'>Select a graph type:</span> \n\t\t\t\t\t\t\t\t<select name='sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"] . "' onChange='dq_update_deps(" . $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>"; } print "<br>"; $script .= "dq_update_deps(" . $snmp_query["id"] . "," . $num_visible_fields . ");\n"; } } } if (strlen($script)) { $script .= "</script>\n"; print $script; } form_hidden_box("save_component_graph", "1", ""); 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"]); print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n"; print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n"; }
function graphs() { global $colors; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_id")); /* ==================================================== */ /* use the first host in the list as the default */ if ((!isset($_SESSION["sess_graphs_new_host_id"])) && (empty($_REQUEST["host_id"]))) { $_REQUEST["host_id"] = db_fetch_cell("select id from host order by description,hostname limit 1"); } /* remember these search fields in session vars so we don't have to keep passing them around */ if (isset($_REQUEST["host_id"])) { $_SESSION["sess_graphs_new_host_id"] = $_REQUEST["host_id"]; }else{ $_REQUEST["host_id"] = $_SESSION["sess_graphs_new_host_id"]; } $host = db_fetch_row("select id,description,hostname,host_template_id from host where id=" . $_REQUEST["host_id"]); $debug_log = debug_log_return("new_graphs"); if (!empty($debug_log)) { debug_log_clear("new_graphs"); ?> <table width='98%' style='background-color: #f5f5f5; border: 1px solid #bbbbbb;' align='center'> <tr bgcolor="<?php print $colors["light"];?>"> <td style="padding: 3px; font-family: monospace;"> <?php print $debug_log;?> </td> </tr> </table> <br> <?php } ?> <form name="form_graph_id"> <table width="98%" align="center"> <tr> <td class="textInfo" colspan="2"> <?php print $host["description"];?> (<?php print $host["hostname"];?>) </td> <td align="right" class="textInfo" style="color: #aaaaaa;"> <?php if (!empty($host["host_template_id"])) { print db_fetch_cell("select name from host_template where id=" . $host["host_template_id"]); } ?> </td> </tr> <tr> <td> </td> </tr> <tr> <td class="textArea" style="padding: 3px;" width="300" nowrap> Create new graphs for the following host: </td> <td class="textInfo" rowspan="2" valign="top"> <span style="color: #c16921;">*</span><a href="host.php?action=edit&id=<?php print $_REQUEST["host_id"];?>">Edit this Host</a><br> <span style="color: #c16921;">*</span><a href="host.php?action=edit">Create New Host</a> </td> </tr> <td> <select name="cbo_graph_id" onChange="window.location=document.form_graph_id.cbo_graph_id.options[document.form_graph_id.cbo_graph_id.selectedIndex].value"> <?php $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"); if (sizeof($hosts) > 0) { foreach ($hosts as $item) { print "<option value='graphs_new.php?host_id=" . $item["id"] . "'"; if ($_REQUEST["host_id"] == $item["id"]) { print " selected"; } print ">" . $item["name"] . "</option>\n"; } } ?> </select> </td> </tr> </table> </form> <form name="chk" method="post" action="graphs_new.php"> <?php $total_rows = sizeof(db_fetch_assoc("select graph_template_id from host_graph where host_id=" . $_REQUEST["host_id"])); /* we give users the option to turn off the javascript features for data queries with lots of rows */ if (read_config_option("max_data_query_javascript_rows") >= $total_rows) { $use_javascript = true; }else{ $use_javascript = false; } html_start_box("<strong>Graph Templates</strong>", "98%", $colors["header"], "3", "center", ""); print " <tr bgcolor='#" . $colors["header_panel"] . "'> <td class='textSubHeaderDark'>Graph Template Name</td> <td width='1%' align='center' bgcolor='#819bc0' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='Select All' onClick='SelectAll(\"cg\",this.checked);gt_update_selection_indicators();'></td>\n </tr>\n"; $graph_templates = db_fetch_assoc("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=" . $_REQUEST["host_id"] . " order by graph_templates.name"); $template_graphs = db_fetch_assoc("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=" . $host["id"] . " group by graph_local.graph_template_id"); print "<script type='text/javascript'>\nvar gt_created_graphs = new Array()\n</script>\n"; if ((sizeof($template_graphs) > 0) && ($use_javascript == true)) { print "<script type='text/javascript'>\n<!--\n"; print "var gt_created_graphs = new Array("; $cg_ctr = 0; foreach ($template_graphs as $template_graph) { print (($cg_ctr > 0) ? "," : "") . "'" . $template_graph["graph_template_id"] . "'"; $cg_ctr++; } print ")\n"; print "//-->\n</script>\n"; } /* create a row for each graph template associated with the host template */ $i = 0; 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' bgcolor='#" . (($i % 2 == 0) ? "ffffff" : $colors["light"]) . "'>"; $i++; print " <td" . (($use_javascript == true) ? " onClick='gt_select_line(" . $graph_template["graph_template_id"] . ");'" : "") . "><span id='gt_text$query_row" . "_0'> <span id='gt_text$query_row" . "_0'><strong>Create:</strong> " . $graph_template["graph_template_name"] . "</span> </td> <td align='right'> <input type='checkbox' name='cg_$query_row' id='cg_$query_row'" . (($use_javascript == true) ? " onClick='gt_update_selection_indicators();'" : "") . "> </td> </tr>"; } } if ($use_javascript == true) { print "<script type='text/javascript'>gt_update_deps(1);</script>\n"; } $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 " <tr bgcolor='#" . (($i % 2 == 0) ? "ffffff" : $colors["light"]) . "'> <td colspan='2' width='60' nowrap> <strong>Create:</strong> "; form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(Select a graph type to create)", "", "font-size: 10px;"); print " </td> </tr>"; html_end_box(); $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"] . " order by snmp_query.name"); print "<script type='text/javascript'>\nvar created_graphs = new Array()\n</script>\n"; if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $snmp_query) { unset($total_rows); $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("select count(*) from host_snmp_cache where host_id=" . $host["id"] . " and snmp_query_id=" . $snmp_query["id"] . " and field_name='$field_name'"); } } } } if (!isset($total_rows)) { $total_rows = 0; } /* we give users the option to turn off the javascript features for data queries with lots of rows */ if (read_config_option("max_data_query_javascript_rows") >= $total_rows) { $use_javascript = true; }else{ $use_javascript = false; } $snmp_query_graphs = db_fetch_assoc("select snmp_query_graph.id,snmp_query_graph.name from snmp_query_graph where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " order by snmp_query_graph.name"); if ((sizeof($snmp_query_graphs) > 0) && ($use_javascript == true)) { print "<script type='text/javascript'>\n<!--\n"; foreach ($snmp_query_graphs as $snmp_query_graph) { $created_graphs = db_fetch_assoc("select distinct data_local.snmp_index from (data_local,data_template_data) left join data_input_data on (data_template_data.id=data_input_data.data_template_data_id) left join data_input_fields on (data_input_data.data_input_field_id=data_input_fields.id) where data_local.id=data_template_data.local_data_id and data_input_fields.type_code='output_type' and data_input_data.value='" . $snmp_query_graph["id"] . "' and data_local.host_id=" . $host["id"]); print "created_graphs[" . $snmp_query_graph["id"] . "] = new Array("; $cg_ctr = 0; if (sizeof($created_graphs) > 0) { foreach ($created_graphs as $created_graph) { print (($cg_ctr > 0) ? "," : "") . "'" . encode_data_query_index($created_graph["snmp_index"]) . "'"; $cg_ctr++; } } print ")\n"; } print "//-->\n</script>\n"; } print " <table width='98%' style='background-color: #" . $colors["form_alternate2"] . "; border: 1px solid #" . $colors["header"] . ";' align='center' cellpadding='3' cellspacing='0'>\n <tr> <td bgcolor='#" . $colors["header"] . "' colspan='" . ($num_input_fields+1) . "'> <table cellspacing='0' cellpadding='0' width='100%' > <tr> <td class='textHeaderDark'> <strong>Data Query</strong> [" . $snmp_query["name"] . "] </td> <td align='right' nowrap> <a href='graphs_new.php?action=query_reload&id=" . $snmp_query["id"] . "&host_id=" . $host["id"] . "'><img src='images/reload_icon_small.gif' alt='Reload Associated Query' border='0' align='absmiddle'></a> </td> </tr> </table> </td> </tr>"; if ($xml_array != false) { $html_dq_header = ""; $snmp_query_indexes = array(); reset($xml_array["fields"]); while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { $raw_data = db_fetch_assoc("select field_value,snmp_index from host_snmp_cache where host_id=" . $host["id"] . " and field_name='$field_name' and snmp_query_id=" . $snmp_query["id"]); /* don't even both to display the column if it has no data */ if (sizeof($raw_data) > 0) { /* draw each header item <TD> */ $html_dq_header .= "<td height='1'><strong><font color='#" . $colors["header_text"] . "'>" . $field_array["name"] . "</font></strong></td>\n"; foreach ($raw_data as $data) { $snmp_query_data[$field_name]{$data["snmp_index"]} = $data["field_value"]; if (!in_array($data["snmp_index"], $snmp_query_indexes,TRUE)) { array_push($snmp_query_indexes, $data["snmp_index"]); } } $num_visible_fields++; }elseif (sizeof($raw_data) == 0) { /* we are choosing to not display this column, so unset the associated field in the xml array so it is not drawn */ unset($xml_array["fields"][$field_name]); } } } /* if the user specified a prefered sort order; sort the list of indexes before displaying them */ if (isset($xml_array["index_order_type"])) { if ($xml_array["index_order_type"] == "numeric") { usort($snmp_query_indexes, "usort_numeric"); }else if ($xml_array["index_order_type"] == "alphabetic") { usort($snmp_query_indexes, "usort_alphabetic"); }else if ($xml_array["index_order_type"] == "natural") { usort($snmp_query_indexes, "usort_natural"); } } if ($num_visible_fields == 0) { print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td>This data query returned 0 rows, perhaps there was a problem executing this data query. You can <a href='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 bgcolor='#" . $colors["header_panel"] . "'> $html_dq_header <td width='1%' align='center' bgcolor='#819bc0' 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);" . (($use_javascript == true) ? "dq_update_selection_indicators();" : "") . "'></td>\n </tr>\n"; } $row_counter = 0; if (sizeof($snmp_query_indexes) > 0) { while (list($id, $snmp_index) = each($snmp_query_indexes)) { $query_row = $snmp_query["id"] . "_" . encode_data_query_index($snmp_index); print "<tr id='line$query_row' bgcolor='#" . (($row_counter % 2 == 0) ? "ffffff" : $colors["light"]) . "'>"; $i++; $column_counter = 0; reset($xml_array["fields"]); while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { if (isset($snmp_query_data[$field_name][$snmp_index])) { print "<td " . (($use_javascript == true) ? "onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($snmp_index) . "\");'" : "") ."><span id='text$query_row" . "_" . $column_counter . "'>" . $snmp_query_data[$field_name][$snmp_index] . "</span></td>"; }else{ print "<td " . (($use_javascript == true) ? "onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($snmp_index) . "\");'" : "") . "><span id='text$query_row" . "_" . $column_counter . "'></span></td>"; } $column_counter++; } } print "<td align='right'>"; print "<input type='checkbox' name='sg_$query_row' id='sg_$query_row' " . (($use_javascript == true) ? "onClick='dq_update_selection_indicators();'" : "") . ">"; print "</td>"; print "</tr>\n"; $row_counter++; } } }else{ print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Error in data query.</td></tr>\n"; } print "</table>"; /* draw the graph template drop down here */ $data_query_graphs = db_fetch_assoc("select snmp_query_graph.id,snmp_query_graph.name from snmp_query_graph where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " order by snmp_query_graph.name"); if (sizeof($data_query_graphs) == 1) { form_hidden_box("sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"], $data_query_graphs[0]["id"], ""); }elseif (sizeof($data_query_graphs) > 1) { print " <table align='center' width='98%'> <tr> <td width='1' valign='top'> <img src='images/arrow.gif' alt='' align='absmiddle'> </td> <td align='right'> <span style='font-size: 12px; font-style: italic;'>Select a graph type:</span> <select name='sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"] . "' " . (($use_javascript == true) ? "onChange='dq_update_deps(" . $snmp_query["id"] . "," . $num_visible_fields . ");'" : "") . "> "; html_create_list($data_query_graphs,"name","id","0"); print " </select> </td> </tr> </table>"; } print "<br>"; if ($use_javascript == true) { print "<script type='text/javascript'>dq_update_deps(" . $snmp_query["id"] . "," . ($num_visible_fields) . ");</script>\n"; } } } form_hidden_box("save_component_graph", "1", ""); form_hidden_box("host_id", $host["id"], "0"); form_hidden_box("host_template_id", $host["host_template_id"], "0"); form_save_button((isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "index.php")); print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n"; print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n"; }
function display_output_messages() { global $config, $messages; $debug_message = debug_log_return('new_graphs'); if ($debug_message != '') { print "<div id='message' class='textInfo messageBox'>"; print $debug_message; print '</div>'; debug_log_clear('new_graphs'); } elseif (isset($_SESSION['sess_messages'])) { $error_message = is_error_message(); if (is_array($_SESSION['sess_messages'])) { foreach (array_keys($_SESSION['sess_messages']) as $current_message_id) { if (isset($messages[$current_message_id]['message'])) { eval('$message = "' . $messages[$current_message_id]['message'] . '";'); switch ($messages[$current_message_id]['type']) { case 'info': if ($error_message == false) { print "<div id='message' class='textInfo messageBox'>"; print $message; print '</div>'; /* we don't need these if there are no error messages */ kill_session_var('sess_field_values'); } break; case 'error': print "<div id='message' class='textError messageBox'>"; print "Error: {$message}"; print '</div>'; break; } } else { cacti_log("ERROR: Cacti Error Message Id '{$current_message_id}' Not Defined", false, 'WEBUI'); } } } else { display_custom_error_message($_SESSION['sess_messages']); } } kill_session_var('sess_messages'); }
function host_edit() { $_device_id = get_get_var_number("id"); if (empty($_device_id)) { $header_label = "[new]"; } else { $device = api_device_get($_device_id); /* get a list of each package that is associated with this device */ $packages = api_device_package_list($_device_id); $header_label = "[edit: " . $device["description"] . "]"; } if (!empty($device["id"])) { echo "<div>\n"; echo $device["description"] . " (" . $device["hostname"] . ")<br />\n"; echo _("SNMP Information") . "\n"; if ($device["snmp_community"] == "" && $device["snmpv3_auth_username"] == "") { echo "<span style='color: #ab3f1e; font-weight: bold;'>" . _("SNMP not in use") . "</span>\n"; } else { $snmp_system = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.1.0", $device["snmp_version"], $device["snmpv3_auth_username"], $device["snmpv3_auth_password"], $device["snmpv3_auth_protocol"], $device["snmpv3_priv_passphrase"], $device["snmpv3_priv_protocol"], $device["snmp_port"], $device["snmp_timeout"], SNMP_WEBUI); if ($snmp_system == "") { echo "<span style='color: #ff0000; font-weight: bold;'>" . _("SNMP error") . "</span>\n"; } else { $snmp_uptime = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.3.0", $device["snmp_version"], $device["snmpv3_auth_username"], $device["snmpv3_auth_password"], $device["snmpv3_auth_protocol"], $device["snmpv3_priv_passphrase"], $device["snmpv3_priv_protocol"], $device["snmp_port"], $device["snmp_timeout"], SNMP_WEBUI); $snmp_hostname = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.5.0", $device["snmp_version"], $device["snmpv3_auth_username"], $device["snmpv3_auth_password"], $device["snmpv3_auth_protocol"], $device["snmpv3_priv_passphrase"], $device["snmpv3_priv_protocol"], $device["snmp_port"], $device["snmp_timeout"], SNMP_WEBUI); $snmp_location = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.6.0", $device["snmp_version"], $device["snmpv3_auth_username"], $device["snmpv3_auth_password"], $device["snmpv3_auth_protocol"], $device["snmpv3_priv_passphrase"], $device["snmpv3_priv_protocol"], $device["snmp_port"], $device["snmp_timeout"], SNMP_WEBUI); $snmp_contact = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.4.0", $device["snmp_version"], $device["snmpv3_auth_username"], $device["snmpv3_auth_password"], $device["snmpv3_auth_protocol"], $device["snmpv3_priv_passphrase"], $device["snmpv3_priv_protocol"], $device["snmp_port"], $device["snmp_timeout"], SNMP_WEBUI); echo "<strong>System:</strong> {$snmp_system}<br>\n"; $days = intval($snmp_uptime / (60 * 60 * 24 * 100)); $remainder = $snmp_uptime % (60 * 60 * 24 * 100); $hours = intval($remainder / (60 * 60 * 100)); $remainder = $remainder % (60 * 60 * 100); $minutes = intval($remainder / (60 * 100)); echo "<strong>" . _("Uptime:") . "</strong> {$snmp_uptime}"; echo " ({$days} days, {$hours} hours, {$minutes} minutes)<br>\n"; echo "<strong>" . _("Hostname:") . "</strong> {$snmp_hostname}<br>\n"; echo "<strong>" . _("Location:") . "</strong> {$snmp_location}<br>\n"; echo "<strong>" . _("Contact:") . "</strong> {$snmp_contact}<br>\n"; } } ?> </span> </div> <div> <span style="color: #c16921;">*</span><a href="graphs_new.php?host_id=<?php print $host["id"]; ?> "><?php echo _("Create Graphs for this Host"); ?> </a> </div> <br /> <?php } form_start("devices.php", "form_device"); html_start_box("<strong>" . _("Devices") . "</strong> {$header_label}"); _device_field__description("description", isset($device["description"]) ? $device["description"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__hostname("hostname", isset($device["hostname"]) ? $device["hostname"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__host_template_id("host_template_id", isset($device["host_template_id"]) ? $device["host_template_id"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__poller_id("poller_id", isset($device["poller_id"]) ? $device["poller_id"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__disabled("disabled", isset($device["disabled"]) ? $device["disabled"] : "", isset($device["id"]) ? $device["id"] : "0"); echo ui_html_box_heading_make("SNMP Options"); _device_field__snmp_version("snmp_version", isset($device["snmp_version"]) ? $device["snmp_version"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__snmp_community("snmp_community", isset($device["snmp_community"]) ? $device["snmp_community"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__snmp_port("snmp_port", isset($device["snmp_port"]) ? $device["snmp_port"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__snmp_timeout("snmp_timeout", isset($device["snmp_timeout"]) ? $device["snmp_timeout"] : "", isset($device["id"]) ? $device["id"] : "0"); echo ui_html_box_heading_make("SNMPv3 Authentication"); _device_field__snmpv3_auth_username("snmpv3_auth_username", isset($device["snmpv3_auth_username"]) ? $device["snmpv3_auth_username"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__snmpv3_auth_password("snmpv3_auth_password", isset($device["snmpv3_auth_password"]) ? $device["snmpv3_auth_password"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__snmpv3_auth_protocol("snmpv3_auth_protocol", isset($device["snmpv3_auth_protocol"]) ? $device["snmpv3_auth_protocol"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__snmpv3_priv_passphrase("snmpv3_priv_passphrase", isset($device["snmpv3_priv_passphrase"]) ? $device["snmpv3_priv_passphrase"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__snmpv3_priv_protocol("snmpv3_priv_protocol", isset($device["snmpv3_priv_protocol"]) ? $device["snmpv3_priv_protocol"] : "", isset($device["id"]) ? $device["id"] : "0"); html_end_box(); if (isset($_GET["display_dq_details"]) && isset($_SESSION["debug_log"]["data_query"])) { html_start_box("<strong>" . _("Data Query Debug Information") . "</strong>"); echo "<tr><td><span style='font-family: monospace;'>" . debug_log_return("data_query") . "</span></td></tr>"; html_end_box(); } if (!empty($_device_id)) { html_start_box("<strong>" . _("Assigned Packages") . "</strong>"); html_header(array(_("Package Name")), 2); if (sizeof($packages) > 0) { foreach ($packages as $package) { ?> <tr class="item"> <td style="padding: 4px;"> <?php echo $package["name"]; ?> </td> <td align="right" style="padding: 4px;"> <a href="devices.php?action=remove_package&id=<?php echo $_device_id; ?> &package_id=<?php echo $package["id"]; ?> "><img src="<?php echo html_get_theme_images_path("delete_icon_large.gif"); ?> " alt="<?php echo _("Delete Package Assignment"); ?> " border="0" align="absmiddle"></a> </td> </tr> <?php } } else { ?> <tr class="empty"> <td colspan="2"> No packages have been assigned to this device. </td> </tr> <?php } ?> <tr> <td style="border-top: 1px solid #b5b5b5; padding: 1px;" colspan="2"> <table width="100%" cellpadding="2" cellspacing="0"> <tr> <td> Add package: <?php form_dropdown("assoc_package_id", api_package_list(), "name", "id", "", "", ""); ?> </td> <td align="right"> <input type="image" src="<?php echo html_get_theme_images_path('button_add.gif'); ?> " alt="<?php echo _('Add'); ?> " name="assoc_package_add" align="absmiddle"> </td> </tr> </table> </td> </tr> <?php html_end_box(); } form_hidden_box("id", $_device_id); form_hidden_box("action_post", "device_edit"); form_save_button("devices.php", "save_device"); }
function graphs_new() { global $colors; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("device_id")); input_validate_input_number(get_request_var_request("graph_type")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { if (!substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { kill_session_var("sess_graphs_new_device_id"); } kill_session_var("sess_graphs_new_graph_type"); kill_session_var("sess_graphs_new_filter"); if (!substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { unset($_REQUEST["device_id"]); } unset($_REQUEST["graph_type"]); unset($_REQUEST["filter"]); $changed = true; }else{ /* if any of the settings changed, reset the page number */ $changed = 0; $changed += check_changed("device_id", "sess_graphs_new_device_id"); $changed += check_changed("graph_type", "sess_graphs_new_graph_type"); $changed += check_changed("filter", "sess_graphs_new_filter"); } load_current_session_value("device_id", "sess_graphs_new_device_id", db_fetch_cell("select id from device 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", ""); if (substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { $file = "devices.php?action=edit&tab=newgraphs&id=" . $_REQUEST["device_id"]; $file2 = "devices.php"; }else{ $file = "graphs_new.php?device_id=". $_REQUEST["device_id"]; $file2 = "graphs_new.php"; } $device = db_fetch_row("select id,description,hostname,device_template_id from device where id=" . $_REQUEST["device_id"]); $row_limit = read_config_option("num_rows_data_query"); $debug_log = debug_log_return("new_graphs"); ?> <script type="text/javascript"> <!-- function applyGraphsNewFilterChange(objForm) { strURL = '?action=edit&tab=newgraphs'; strURL = strURL + '&graph_type=' + objForm.graph_type.value; strURL = strURL + '&device_id=' + objForm.device_id.value; strURL = strURL + '&filter=' + objForm.filter.value;; document.location = strURL; } --> </script> <?php html_start_box("<strong>" . $device["description"] . "(" . $device["hostname"] . ")</strong> " . db_fetch_cell("select name from device_template where id=" . $device["device_template_id"]), "100", $colors["header"], "3", "center", ""); ?> <tr class='rowAlternate2'> <td> <form name="form_graphs_new" method="post" action="<?php print $file2;?>"> <table cellpadding="0" align="left"> <tr> <?php if (!isset($_REQUEST["tab"])) { ?> <td class="nw50 textGraphFilter"> Host: </td> <td width="1"> <select name="device_id" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <?php $devices = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from device order by description,hostname"); if (sizeof($devices) > 0) { foreach ($devices as $item) { print "<option value='" . $item["id"] . "'"; if (get_request_var_request("device_id") == $item["id"]) { print " selected"; } print ">" . $item["name"] . "</option>\n"; } } ?> </select> </td> <?php } ?> <td class="nw50 textGraphFilter"> <?php print __("Type:");?> </td> <td width="1"> <select name="graph_type" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <option value="-2"<?php if (get_request_var_request("graph_type") == "-2") {?> selected<?php }?>><?php print __("All");?></option> <option value="-1"<?php if (get_request_var_request("graph_type") == "-1") {?> selected<?php }?>><?php print __("Graph Template Based");?></option> <?php $snmp_queries = db_fetch_assoc("SELECT snmp_query.id, snmp_query.name, snmp_query.xml_path FROM (snmp_query,device_snmp_query) WHERE device_snmp_query.snmp_query_id=snmp_query.id AND device_snmp_query.device_id=" . $device["id"] . " ORDER BY snmp_query.name"); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $query) { print "<option value='" . $query["id"] . "'"; if (get_request_var_request("graph_type") == $query["id"]) { print " selected"; } print ">" . $query["name"] . "</option>\n"; } } ?> </select> </td> <td style="white-space:nowrap;width:1%;" class="textInfo" align="center" valign="top"> <?php if (!isset($_REQUEST["tab"])) { ?><span class="tabedit">*</span><a href="devices.php?action=edit&id=<?php print $_REQUEST["device_id"];?>"><?php print __("Edit this Host");?></a><br><?php } ?> <?php api_plugin_hook('graphs_new_top_links'); ?> </td> </tr> </table> <?php if (get_request_var_request("graph_type") > 0) {?> <table cellpadding="0" align="left"> <tr> <td class="nw50 textGraphFilter"> Search: </td> <td class="nw200"> <input type="text" name="filter" size="30" width="200" value="<?php print $_REQUEST["filter"];?>"> </td> <td align="left" class="nw120"> <input type="submit" name="go" value="<?php print __("Go");?>" align="middle"> <input type="submit" name="clear_x" value="<?php print __("Clear");?>" align="middle"> <input type="hidden" name="action" value="edit"> <input type="hidden" name="tab" value="newgraphs"> </td> </tr> </table> <?php }else{ form_hidden_box("filter", get_request_var_request("filter"), ""); }?> </form> </td> </tr> <?php html_end_box(false); $total_rows = sizeof(db_fetch_assoc("select graph_template_id from device_graph where device_id=" . $_REQUEST["device_id"])); $i = 0; if (get_request_var_request("graph_type") > 0) { load_current_session_value("page" . get_request_var_request("graph_type"), "sess_graphs_new_page" . get_request_var_request("graph_type"), "1"); }else if (get_request_var_request("graph_type") == -2) { foreach($snmp_queries as $query) { load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1"); } } print "<form name='chk' method='post' action='" . $file2 . "'>"; if (get_request_var_request("graph_type") < 0) { $graph_templates = db_fetch_assoc("SELECT graph_templates.id AS graph_template_id, graph_templates.name AS graph_template_name FROM (device_graph,graph_templates) WHERE device_graph.graph_template_id=graph_templates.id AND device_graph.device_id=" . $_REQUEST["device_id"] . " ORDER BY graph_templates.name"); $template_graphs = db_fetch_assoc("SELECT graph_local.graph_template_id FROM (graph_local,device_graph) WHERE graph_local.graph_template_id=device_graph.graph_template_id AND graph_local.device_id=device_graph.device_id AND graph_local.device_id=" . $device["id"] . " GROUP BY graph_local.graph_template_id"); if (sizeof($template_graphs) > 0) { print "<script type='text/javascript'>\n<!--\n"; print "var gt_created_graphs = new Array("; $cg_ctr = 0; foreach ($template_graphs as $template_graph) { print (($cg_ctr > 0) ? "," : "") . "'" . $template_graph["graph_template_id"] . "'"; $cg_ctr++; } print ")\n"; print "//-->\n</script>\n"; } else { print "<script type='text/javascript'>\nvar gt_created_graphs = new Array()\n</script>\n"; } print "<script type='text/javascript'>gt_update_deps(1);</script>\n"; print "<script type='text/javascript'>\nvar created_graphs = new Array()\n</script>\n"; html_start_box("<strong>" . __("Graph Templates") . "</strong>", "100", $colors["header"], "3", "center", ""); print " <tr class='rowSubHeader'> <td class='textSubHeaderDark'>" . __("Graph Template Name") . "</td> <td class='rowSubHeader' width='1%' align='center' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='" . __("Select All") . "' onClick='SelectAll(\"cg\",this.checked);gt_update_selection_indicators();'></td>\n </tr>\n"; /* create a row for each graph template associated with the device 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' bgcolor='#" . (($i % 2 == 0) ? "ffffff" : $colors["light"]) . "'>"; $i++; print " <td onClick='gt_select_line(" . $graph_template["graph_template_id"] . ");'><span id='gt_text$query_row" . "_0'> <strong>" . __("Create:") . "</strong> " . $graph_template["graph_template_name"] . "</span> </td> <td align='right'> <input type='checkbox' name='cg_$query_row' id='cg_$query_row' onClick='gt_update_selection_indicators();'> </td> </tr>"; } } $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 " <tr bgcolor='#" . (($i % 2 == 0) ? "ffffff" : $colors["light"]) . "'> <td colspan='2' width='60' nowrap> <strong>" . __("Create:") . "</strong> "; 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) { $snmp_queries = db_fetch_assoc("SELECT snmp_query.id, snmp_query.name, snmp_query.xml_path FROM (snmp_query,device_snmp_query) WHERE device_snmp_query.snmp_query_id=snmp_query.id AND device_snmp_query.device_id=" . $device["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 (isset($_REQUEST["page" . $snmp_query["id"]])) { $page = $_REQUEST["page" . $snmp_query["id"]]; }elseif (!$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("SELECT count(*) FROM device_snmp_cache WHERE device_id=" . $device["id"] . " and snmp_query_id=" . $snmp_query["id"] . " AND field_name='$field_name'"); } } } } if (!isset($total_rows)) { $total_rows = 0; } $snmp_query_graphs = db_fetch_assoc("SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " ORDER BY snmp_query_graph.name"); if (sizeof($snmp_query_graphs) > 0) { print "<script type='text/javascript'>\n<!--\n"; foreach ($snmp_query_graphs as $snmp_query_graph) { $created_graphs = db_fetch_assoc("SELECT DISTINCT data_local.snmp_index FROM (data_local,data_template_data) LEFT JOIN data_input_data ON (data_template_data.id=data_input_data.data_template_data_id) LEFT JOIN data_input_fields ON (data_input_data.data_input_field_id=data_input_fields.id) WHERE data_local.id=data_template_data.local_data_id AND data_input_fields.type_code='output_type' AND data_input_data.value='" . $snmp_query_graph["id"] . "' AND data_local.device_id=" . $device["id"]); print "created_graphs[" . $snmp_query_graph["id"] . "] = new Array("; $cg_ctr = 0; if (sizeof($created_graphs) > 0) { foreach ($created_graphs as $created_graph) { print (($cg_ctr > 0) ? "," : "") . "'" . encode_data_query_index($created_graph["snmp_index"]) . "'"; $cg_ctr++; } } print ")\n"; } print "//-->\n</script>\n"; } html_start_box_dq($snmp_query["name"], $snmp_query["id"], $device["id"], $num_input_fields+1, "100", $colors["header"], "0", "center"); 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(get_request_var_request("filter"))) { $sql_where = ""; $indexes = db_fetch_assoc("SELECT DISTINCT snmp_index FROM device_snmp_cache WHERE field_value LIKE '%%" . get_request_var_request("filter") . "%%' AND snmp_query_id=" . $snmp_query["id"] . " AND device_id=" . $device["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(get_request_var_request("filter")) == 0) || ((strlen(get_request_var_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("SELECT DISTINCT field_name FROM device_snmp_cache WHERE device_id=" . $device["id"] . " AND snmp_query_id=" . $snmp_query["id"]); /* build magic query */ $sql_query = "SELECT device_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 device_snmp_cache WHERE device_id=" . $device["id"] . " AND snmp_query_id=" . $snmp_query["id"] . " $sql_where GROUP BY device_id, snmp_query_id, snmp_index $sql_order LIMIT " . ($row_limit*($page-1)) . "," . $row_limit; $rows_query = "SELECT device_id, snmp_query_id, snmp_index FROM device_snmp_cache WHERE device_id=" . $device["id"] . " AND snmp_query_id=" . $snmp_query["id"] . " $sql_where GROUP BY device_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"); } if (substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { $file = "devices.php?action=edit&tab=newgraphs&id=" . $_REQUEST["device_id"]; $file2 = "devices.php"; }else{ $file = "graphs_new.php?device_id=". $_REQUEST["device_id"]; $file2 = "graphs_new.php"; } if ($total_rows > $row_limit) { /* generate page list navigation */ $nav = html_create_nav($page, MAX_DISPLAY_PAGES, $row_limit, $total_rows, 40, $file, "page" . $snmp_query["id"]); print $nav; } while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { foreach($field_names as $row) { if ($row["field_name"] == $field_name) { # $html_dq_header .= "<td height='1' style='padding:0px 5px 0px 5px;' onMousemove='doColResize(this,event)' onMouseover='doColResize(this,event)' onMouseup='doneColResize()'><strong><font color='#" . $colors["header_text"] . "'>" . $field_array["name"] . "</font></strong></td>\n"; $html_dq_header .= "<th style='padding:0px 5px 0px 5px;' onMousemove='doColResize(this,event)' onMouseover='doColResize(this,event)' onMouseup='doneColResize()' class='textSubHeaderDark'><strong><font color='#" . $colors["header_text"] . "'>" . $field_array["name"] . "</font></strong></th>\n"; break; } } } } if (!sizeof($snmp_query_indexes)) { print "<tr class='rowAlternate1'><td>" . __("This data query returned 0 rows, perhaps there was a problem executing this data query. You can %s run this data query in debug mode %s to get more information.", "<a href='" . htmlspecialchars("devices.php?action=query_verbose&id=" . $snmp_query["id"] . "&device_id=" . $device["id"]) . "'>", "</a>") . "</td></tr>\n"; }else{ print "<tr class='rowSubHeader'> $html_dq_header <td class='rowSubHeader' width='1%' align='center' 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);dq_update_selection_indicators();'></td>\n </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"]); form_alternate_row_color("line" . $query_row, true); $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 style='line-height: 1.5em;padding:0px 5px 0px 5px;' onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text$query_row" . "_" . $column_counter . "'>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $row[$field_name]) : $row[$field_name]) . "</span></td>"; }else{ print "<td style='line-height: 1.5em;padding:0px 5px 0px 5px;' onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text$query_row" . "_" . $column_counter . "'></span></td>"; } $column_counter++; } } } print "<td style='padding-right: 4px;' align='right'>"; print "<input type='checkbox' name='sg_$query_row' id='sg_$query_row' onClick='dq_update_selection_indicators();'>"; print "</td>"; print "</tr>\n"; $row_counter++; } } if ($total_rows > $row_limit) { print $nav; } }else{ print "<tr class='rowAlternate1'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>" . __("Search Returned no Rows.") . "</td></tr>\n"; } }else{ print "<tr class='rowAlternate1'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>" . __("Error in data query.") . "</td></tr>\n"; } /* draw the graph template drop down here */ $data_query_graphs = db_fetch_assoc("select snmp_query_graph.id,snmp_query_graph.name from snmp_query_graph where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " order by snmp_query_graph.name"); if (sizeof($data_query_graphs) == 1) { html_end_box(); form_hidden_box("sgg_" . $snmp_query["id"], $data_query_graphs[0]["id"], ""); }elseif (sizeof($data_query_graphs) > 1) { html_end_box(FALSE); print "<table align='center' width='100%'> <tr> <td width='1' valign='top'> <img src='images/arrow.gif' alt='' align='middle'> </td> <td align='right'> <span class=\"italic\">" . __("Select a graph type:") . "</span> <select name='sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"] . "' onChange='dq_update_deps(" . $snmp_query["id"] . "," . $column_counter . ");'> "; html_create_list($data_query_graphs,"name","id","0"); print " </select> </td> </tr> </table>"; } print "<script type='text/javascript'>dq_update_deps(" . $snmp_query["id"] . "," . ($num_visible_fields) . ");</script>\n"; } } } form_hidden_box("save_component_graph", "1", ""); form_hidden_box("device_id", $device["id"], "0"); form_hidden_box("device_template_id", $device["device_template_id"], "0"); form_save_button_alt("url!" . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "")); if (!empty($debug_log)) { debug_log_clear("new_graphs"); ?> <table class='topBoxAlt'> <tr> <td class='mono'> <?php print $debug_log;?> </td> </tr> </table> <br> <?php } print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n"; print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n"; }
function device_display_general($device, $device_text) { global $colors; require(CACTI_BASE_PATH . "/include/data_query/data_query_arrays.php"); require_once(CACTI_BASE_PATH . "/lib/device/device_info.php"); if (isset($device["id"])) { html_start_box($device_text, "100", $colors["header"], "3", "center", "", true); ?> <tr> <?php if (($device["availability_method"] == AVAIL_SNMP) || ($device["availability_method"] == AVAIL_SNMP_AND_PING) || ($device["availability_method"] == AVAIL_SNMP_OR_PING)) { ?> <td class="textInfo"> <?php print __("SNMP Information");?><br> <span class="normal"> <?php if ((($device["snmp_community"] == "") && ($device["snmp_username"] == "")) || ($device["snmp_version"] == 0)) { print "<span class=\"info\">SNMP not in use</span>\n"; }else{ $snmp_system = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.1.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], read_config_option("snmp_retries"),SNMP_WEBUI); /* modify for some system descriptions */ /* 0000937: System output in devices.php poor for Alcatel */ if (substr_count($snmp_system, "00:")) { $snmp_system = str_replace("00:", "", $snmp_system); $snmp_system = str_replace(":", " ", $snmp_system); } if ($snmp_system == "") { print "<span class=\"warning\">SNMP error</span>\n"; }else{ $snmp_uptime = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.3.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); $snmp_hostname = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.5.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); $snmp_location = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.6.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); $snmp_contact = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.4.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); print "<strong>System:</strong> " . html_split_string($snmp_system,200) . "<br>\n"; $days = intval($snmp_uptime / (60*60*24*100)); $remainder = $snmp_uptime % (60*60*24*100); $hours = intval($remainder / (60*60*100)); $remainder = $remainder % (60*60*100); $minutes = intval($remainder / (60*100)); print "<strong>" . __("Uptime:") . " </strong> $snmp_uptime"; print " ($days days, $hours hours, $minutes minutes)<br>\n"; print "<strong>" . __("Hostname:") . " </strong> $snmp_hostname<br>\n"; print "<strong>" . __("Location:") . " </strong> $snmp_location<br>\n"; print "<strong>" . __("Contact:") . " </strong> $snmp_contact<br>\n"; } } ?> </span> </td> <?php } if (($device["availability_method"] == AVAIL_PING) || ($device["availability_method"] == AVAIL_SNMP_AND_PING) || ($device["availability_method"] == AVAIL_SNMP_OR_PING)) { /* create new ping socket for device pinging */ $ping = new Net_Ping; $ping->device = $device; $ping->port = $device["ping_port"]; /* perform the appropriate ping check of the device */ if ($ping->ping($device["availability_method"], $device["ping_method"], $device["ping_timeout"], $device["ping_retries"])) { $device_down = false; $ping_class = "ping"; }else{ $device_down = true; $ping_class = "ping_warning"; } ?> <td class="textInfo" style="vertical-align:top;"> <?php print __("Ping Results");?><br> <span class="<?php $ping_class ?>"> <?php print $ping->ping_response; ?> </span> </td> <?php }else if ($device["availability_method"] == AVAIL_NONE) { ?> <td class="textInfo"> <?php print __("No Availability Check In Use");?><br> </td> <?php } ?> </tr> <?php }else{ html_start_box($device_text, "100", $colors["header"], "3", "center", "", false); } html_end_box(FALSE); print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='device_edit_settings'>\n"; html_start_box("<strong>" . __("General Settings") . "</strong>", "100", $colors["header"], 0, "center", "", true); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, true, 'device'); /* preserve the device template id if passed in via a GET variable */ $fields_device_edit = device_form_list(); if (!empty($_GET["template_id"])) { // $fields_device_edit["device_template_id"]["value"] = $_GET["template_id"]; // $fields_device_edit["device_template_id"]["method"] = "hidden"; } /* if we are creating a device and have changed templates set that value */ if (!isset($device["id"])) { if (!empty($_GET["template_id"])) { $device["device_template_id"] = $_GET["template_id"]; } } /* draw basic fields only on first run for a new device */ draw_edit_form(array( "config" => array("form_name" => "chk", "no_form_tag" => true), "fields" => inject_form_variables($fields_device_edit, (is_array($device) ? $device : array())) )); /* if the device is new, check/set the $device array with some template values */ $override_permitted = true; $propagation_allowed = false; if (!isset($device["id"])) { $template_settings = db_fetch_row("SELECT * FROM device_template WHERE id=" . $_REQUEST["template_id"]); if (sizeof($template_settings)) { foreach($template_settings as $key => $value) { switch($key) { case "id": case "name": case "description": case "hash": case "image": unset($template_settings[$key]); break; case "override_defaults": if ($value == CHECKED) { $propagation_allowed = true; } unset($template_settings[$key]); break; case "override_permitted": if ($value != CHECKED) { $override_permitted = false; } break; default: break; } } } }else{ if (db_fetch_cell("SELECT override_defaults FROM device_template WHERE id=" . $device["device_template_id"]) == CHECKED) { $propagation_allowed = true; } } /* for a given device, display all availability options as well */ draw_edit_form(array( "config" => array("form_name" => "chk", "no_form_tag" => true), "fields" => inject_form_variables(device_availability_form_list(), (isset($template_settings) ? $template_settings : $device)) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(!isset($device["id"])); form_hidden_box("id", (isset($device["id"]) ? $device["id"] : "0"), ""); form_hidden_box("hidden_device_template_id", (isset($device["device_template_id"]) ? $device["device_template_id"] : "0"), ""); form_hidden_box("save_basic_device", "1", ""); form_hidden_box("save_component_device", "1", ""); form_hidden_box("override_permitted", ($override_permitted ? "true":"false"), ""); form_hidden_box("propagation_allowed", ($propagation_allowed ? "true":"false"), ""); /* javascript relates to availability options, so include it only for existing devices */ ?> <script type="text/javascript"> <!-- // default snmp information var snmp_community = document.getElementById('snmp_community').value; var snmp_username = document.getElementById('snmp_username').value; var snmp_password = document.getElementById('snmp_password').value; var snmp_auth_protocol = document.getElementById('snmp_auth_protocol').value; var snmp_priv_passphrase = document.getElementById('snmp_priv_passphrase').value; var snmp_priv_protocol = document.getElementById('snmp_priv_protocol').value; var snmp_context = document.getElementById('snmp_context').value; var snmp_port = document.getElementById('snmp_port').value; var snmp_timeout = document.getElementById('snmp_timeout').value; var max_oids = document.getElementById('max_oids').value; // default ping methods var ping_method = document.getElementById('ping_method').value; var ping_port = document.getElementById('ping_port').value; var ping_timeout = document.getElementById('ping_timeout').value; var ping_retries = document.getElementById('ping_retries').value; var availability_methods = document.getElementById('availability_method').options; var num_methods = document.getElementById('availability_method').length; var selectedIndex = document.getElementById('availability_method').selectedIndex; var agent = navigator.userAgent; agent = agent.match("MSIE"); function setPingVisibility() { availability_method = document.getElementById('availability_method').value; ping_method = document.getElementById('ping_method').value; /* debugging, uncomment as required */ //alert("The availability method is '" + availability_method + "'"); //alert("The ping method is '" + ping_method + "'"); switch(availability_method) { case "0": // none document.getElementById('row_ping_method').style.display = "none"; document.getElementById('row_ping_port').style.display = "none"; document.getElementById('row_ping_timeout').style.display = "none"; document.getElementById('row_ping_retries').style.display = "none"; break; case "2": // snmp document.getElementById('row_ping_method').style.display = "none"; document.getElementById('row_ping_port').style.display = "none"; document.getElementById('row_ping_timeout').style.display = ""; document.getElementById('row_ping_retries').style.display = ""; break; default: // ping ok switch(ping_method) { case "1": // ping icmp document.getElementById('row_ping_method').style.display = ""; document.getElementById('row_ping_port').style.display = "none"; document.getElementById('row_ping_timeout').style.display = ""; document.getElementById('row_ping_retries').style.display = ""; break; case "2": // ping udp case "3": // ping tcp document.getElementById('row_ping_method').style.display = ""; document.getElementById('row_ping_port').style.display = ""; document.getElementById('row_ping_timeout').style.display = ""; document.getElementById('row_ping_retries').style.display = ""; break; } break; } } function addSelectItem(item, formObj) { if (agent != "MSIE") { formObj.add(item,null); // standards compliant }else{ formObj.add(item); // IE only } } function setAvailability(type) { /* get the availability structure */ var am=document.getElementById('availability_method'); /* get current selectedIndex */ selectedIndex = document.getElementById('availability_method').selectedIndex; /* debugging uncomment as required */ //alert("The selectedIndex is '" + selectedIndex + "'"); //alert("The array length is '" + am.length + "'"); switch(type) { case "NoSNMP": /* remove snmp options */ if (am.length == 4) { am.remove(1); am.remove(1); am.remove(1); } /* set the index to something valid, like "ping" */ if (selectedIndex > 1) { am.selectedIndex=1; } break; case "All": /* restore all options */ if (am.length == 2) { am.remove(0); am.remove(0); var a=document.createElement('option'); var b=document.createElement('option'); var c=document.createElement('option'); var d=document.createElement('option'); var e=document.createElement('option'); a.value="0"; a.text="None"; addSelectItem(a,am); b.value="1"; b.text="Ping and SNMP"; addSelectItem(b,am); e.value="4"; e.text="Ping or SNMP"; addSelectItem(e,am); c.value="2"; c.text="SNMP"; addSelectItem(c,am); d.value="3"; d.text="Ping"; addSelectItem(d,am); /* restore the correct index number */ if (selectedIndex == 0) { am.selectedIndex = 0; }else{ am.selectedIndex = 3; } } break; } setAvailabilityVisibility(type, am.selectedIndex); setPingVisibility(); } function setAvailabilityVisibility(type, selectedIndex) { switch(type) { case "NoSNMP": switch(selectedIndex) { case "0": // availability none document.getElementById('row_ping_method').style.display="none"; document.getElementById('ping_method').value=0; break; case "1": // ping document.getElementById('row_ping_method').style.display=""; document.getElementById('ping_method').value=ping_method; break; } case "All": switch(selectedIndex) { case "0": // availability none document.getElementById('row_ping_method').style.display="none"; document.getElementById('ping_method').value=0; break; case "1": // ping and snmp case "3": // ping case "4": // ping or snmp if ((document.getElementById('row_ping_method').style.display == "none") || (document.getElementById('row_ping_method').style.display == undefined)) { document.getElementById('ping_method').value=ping_method; document.getElementById('row_ping_method').style.display=""; } break; case "2": // snmp document.getElementById('row_ping_method').style.display="none"; document.getElementById('ping_method').value="0"; break; } } } function changeHostForm() { snmp_version = document.getElementById('snmp_version').value; switch(snmp_version) { case "0": setAvailability("NoSNMP"); setSNMP("None"); break; case "1": case "2": setAvailability("All"); setSNMP("v1v2"); break; case "3": setAvailability("All"); setSNMP("v3"); break; } } function setSNMP(snmp_type) { switch(snmp_type) { case "None": document.getElementById('row_snmp_username').style.display = "none"; document.getElementById('row_snmp_password').style.display = "none"; document.getElementById('row_snmp_community').style.display = "none"; document.getElementById('row_snmp_auth_protocol').style.display = "none"; document.getElementById('row_snmp_priv_passphrase').style.display = "none"; document.getElementById('row_snmp_priv_protocol').style.display = "none"; document.getElementById('row_snmp_context').style.display = "none"; document.getElementById('row_snmp_port').style.display = "none"; document.getElementById('row_snmp_timeout').style.display = "none"; document.getElementById('row_max_oids').style.display = "none"; break; case "v1v2": document.getElementById('row_snmp_username').style.display = "none"; document.getElementById('row_snmp_password').style.display = "none"; document.getElementById('row_snmp_community').style.display = ""; document.getElementById('row_snmp_auth_protocol').style.display = "none"; document.getElementById('row_snmp_priv_passphrase').style.display = "none"; document.getElementById('row_snmp_priv_protocol').style.display = "none"; document.getElementById('row_snmp_context').style.display = "none"; document.getElementById('row_snmp_port').style.display = ""; document.getElementById('row_snmp_timeout').style.display = ""; document.getElementById('row_max_oids').style.display = ""; break; case "v3": document.getElementById('row_snmp_username').style.display = ""; document.getElementById('row_snmp_password').style.display = ""; document.getElementById('row_snmp_community').style.display = "none"; document.getElementById('row_snmp_auth_protocol').style.display = ""; document.getElementById('row_snmp_priv_passphrase').style.display = ""; document.getElementById('row_snmp_priv_protocol').style.display = ""; document.getElementById('row_snmp_context').style.display = ""; document.getElementById('row_snmp_port').style.display = ""; document.getElementById('row_snmp_timeout').style.display = ""; document.getElementById('row_max_oids').style.display = ""; break; } } function toggleAvailabilityAndSnmp(template_enabled) { if (!template_enabled && $('#override_permitted').val() == 'true') { $('#override_permitted').removeAttr("disabled"); $('#availability_header').removeAttr("disabled"); $('#availability_method').removeAttr("disabled"); $('#ping_method').removeAttr("disabled"); $('#ping_port').removeAttr("disabled"); $('#ping_timeout').removeAttr("disabled"); $('#ping_retries').removeAttr("disabled"); $('#snmp_spacer').removeAttr("disabled"); $('#snmp_version').removeAttr("disabled"); $('#snmp_username').removeAttr("disabled"); $('#snmp_password').removeAttr("disabled"); $('#snmp_password_confirm').removeAttr("disabled"); $('#snmp_community').removeAttr("disabled"); $('#snmp_auth_protocol').removeAttr("disabled"); $('#snmp_priv_passphrase').removeAttr("disabled"); $('#snmp_priv_protocol').removeAttr("disabled"); $('#snmp_context').removeAttr("disabled"); $('#snmp_port').removeAttr("disabled"); $('#snmp_timeout').removeAttr("disabled"); $('#max_oids').removeAttr("disabled"); $('#device_threads').removeAttr("disabled"); }else{ $('#override_permitted').attr("disabled","disabled"); $('#availability_header').attr("disabled","disabled"); $('#availability_method').attr("disabled","disabled"); $('#ping_method').attr("disabled","disabled"); $('#ping_port').attr("disabled","disabled"); $('#ping_timeout').attr("disabled","disabled"); $('#ping_retries').attr("disabled","disabled"); $('#snmp_spacer').attr("disabled","disabled"); $('#snmp_version').attr("disabled","disabled"); $('#snmp_username').attr("disabled","disabled"); $('#snmp_password').attr("disabled","disabled"); $('#snmp_password_confirm').attr("disabled","disabled"); $('#snmp_community').attr("disabled","disabled"); $('#snmp_auth_protocol').attr("disabled","disabled"); $('#snmp_priv_passphrase').attr("disabled","disabled"); $('#snmp_priv_protocol').attr("disabled","disabled"); $('#snmp_context').attr("disabled","disabled"); $('#snmp_port').attr("disabled","disabled"); $('#snmp_timeout').attr("disabled","disabled"); $('#max_oids').attr("disabled","disabled"); $('#device_threads').attr("disabled","disabled"); } changeHostForm(); if ($('#override_permitted').val() == 'false') { $('#template_enabled').attr("checked","checked"); $('#template_enabled').attr("disabled","disabled"); } if ($('#propagation_allowed').val() == 'false') { $('#row_template_enabled').hide(); }else{ $('#row_template_enabled').show(); } } $().ready(function() { toggleAvailabilityAndSnmp(document.getElementById('template_enabled').checked); /* Hide options when override is turned off */ $("#template_enabled").change(function () { toggleAvailabilityAndSnmp(this.checked); }); if ($('#id').val() == 0) { $('#device_template_id').change(function() { document.location='devices.php?action=edit&template_id='+this.value+'&status=-1' }); } }); --> </script> <?php if ((isset($_GET["display_dq_details"])) && (isset($_SESSION["debug_log"]["data_query"]))) { html_start_box("<strong>" . __("Data Query Debug Information") . "</strong>", "100", $colors["header"], "3", "center", "", true); print "<tr><td><span class=\"log\">" . debug_log_return("data_query") . "</span></td></tr>"; html_end_box(false); } if (isset($device["id"])) { html_start_box("<strong>". __("Associated Graph Templates") . "</strong>", "100", $colors["header"], 0, "center", "", true); print "<tr><td>"; html_header(array(__("Graph Template Name"), __("Status")), 2); $selected_graph_templates = db_fetch_assoc("select graph_templates.id, graph_templates.name from (graph_templates,device_graph) where graph_templates.id=device_graph.graph_template_id and device_graph.device_id=" . $_GET["id"] . " order by graph_templates.name"); $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"); /* omit those graph_templates, that have already been associated */ $keeper = array(); foreach ($available_graph_templates as $item) { if (sizeof(db_fetch_assoc("SELECT graph_template_id FROM device_graph " . " WHERE ((device_id=" . $_GET["id"] . ")" . " AND (graph_template_id=" . $item["id"] ."))")) > 0) { /* do nothing */ } else { array_push($keeper, $item); } } $available_graph_templates = $keeper; $i = 0; if (sizeof($selected_graph_templates) > 0) { foreach ($selected_graph_templates as $item) { $i++; form_alternate_row_color("graph_template" . $i); /* get status information for this graph template */ $is_being_graphed = (sizeof(db_fetch_assoc("select id from graph_local where graph_template_id=" . $item["id"] . " and device_id=" . $_GET["id"])) > 0) ? true : false; ?> <td style="padding: 4px;"> <strong><?php print $i;?>)</strong> <?php print $item["name"];?> </td> <td> <?php print (($is_being_graphed == true) ? "<span class=\"success\">" . __("Is Being Graphed") . "</span> (<a href='" . htmlspecialchars("graphs.php?action=graph_edit&id=" . db_fetch_cell("select id from graph_local where graph_template_id=" . $item["id"] . " and device_id=" . get_request_var("id") . " limit 0,1")) . "'>" . __("Edit") . "</a>)" : "<span class=\"unknown\">" . __("Not Being Graphed") . "</span>");?> </td> <td align='right' nowrap> <a href='devices.php?action=gt_remove&id=<?php print $item["id"];?>&device_id=<?php print $_GET["id"];?>'><img align='middle' class='buttonSmall' src='images/delete_icon_large.gif' title='<?php print __("Delete Graph Template Association");?>' alt='<?php print __("Delete");?>'></a> </td> <?php form_end_row(); } }else{ print "<tr><td><em>" . __("No Associated Graph Templates.") . "</em></td></tr>"; } form_alternate_row_color("gt_device" . $device["id"]); ?> <td colspan="4"> <table cellspacing="0" cellpadding="1" width="100%"> <tr> <td nowrap><?php print __("Add Graph Template:");?> <?php form_dropdown("graph_template_id",$available_graph_templates,"name","id","","","");?> </td> <td align="right"> <input type="submit" value="<?php print __("Add");?>" name="add_gt_y" align="middle"> </td> </tr> </table> </td> <?php form_end_row(); print "</table></td></tr>"; /* end of html_header */ html_end_box(FALSE); html_start_box("<strong>" . __("Associated Data Queries") . "</strong>", "100", $colors["header"], 0, "center", "", true); print "<tr><td>"; html_header(array(__("Data Query Name"), __("Debugging"), __("Re-Index Method"), __("Status")), 2); $selected_data_queries = db_fetch_assoc("select snmp_query.id, snmp_query.name, device_snmp_query.reindex_method from (snmp_query,device_snmp_query) where snmp_query.id=device_snmp_query.snmp_query_id and device_snmp_query.device_id=" . $_GET["id"] . " order by snmp_query.name"); $available_data_queries = db_fetch_assoc("select snmp_query.id, snmp_query.name from snmp_query order by snmp_query.name"); $keeper = array(); foreach ($available_data_queries as $item) { if (sizeof(db_fetch_assoc("SELECT snmp_query_id FROM device_snmp_query " . " WHERE ((device_id=" . $_GET["id"] . ")" . " and (snmp_query_id=" . $item["id"] ."))")) > 0) { /* do nothing */ } else { array_push($keeper, $item); } } $available_data_queries = $keeper; $i = 0; if (sizeof($selected_data_queries) > 0) { foreach ($selected_data_queries as $item) { $i++; form_alternate_row_color("selected_data_queries" . $i); /* get status information for this data query */ $num_dq_items = sizeof(db_fetch_assoc("select snmp_index from device_snmp_cache where device_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"])); $num_dq_rows = sizeof(db_fetch_assoc("select snmp_index from device_snmp_cache where device_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"] . " group by snmp_index")); $status = "success"; ?> <td style="padding: 4px;"> <strong><?php print $i;?>)</strong> <?php print $item["name"];?> </td> <td> (<a href="devices.php?action=query_verbose&id=<?php print $item["id"];?>&device_id=<?php print $_GET["id"];?>"><?php print __("Verbose Query");?></a>) </td> <td> <?php form_dropdown("reindex_method_device_".get_request_var("id")."_query_".$item["id"]."_method_".$item["reindex_method"],$reindex_types,"","",$item["reindex_method"],"","","","");?> </td> <td> <?php print (($status == "success") ? "<span class=\"success\">" . __("Success") . "</span>" : "<span class=\"fail\">" . __("Fail") . "</span>");?> [<?php print $num_dq_items;?> <?php print __("Item", $num_dq_items);?>, <?php print $num_dq_rows;?> <?php print __("Row", $num_dq_rows);?>] </td> <td align='right' nowrap> <a href='devices.php?action=query_reload&id=<?php print $item["id"];?>&device_id=<?php print $_GET["id"];?>'><img align='middle' class='buttonSmall' src='images/reload_icon_small.gif' title='<?php print __("Reload Data Query");?>' alt='<?php print __("Reload");?>'></a> <a href='devices.php?action=query_remove&id=<?php print $item["id"];?>&device_id=<?php print $_GET["id"];?>'><img align='middle' class='buttonSmall' src='images/delete_icon_large.gif' title='<?php print __("Delete Data Query Association");?>' alt='<?php print __("Delete");?>'></a> </td> <?php form_end_row(); } }else{ print "<tr><td><em>". __("No associated data queries.") . "</em></td></tr>"; } form_alternate_row_color("dq_device" . $device["id"]); ?> <td colspan="5"> <table cellspacing="0" cellpadding="1" width="100%"> <tr> <td nowrap><?php print __("Add Data Query:");?> <?php form_dropdown("snmp_query_id",$available_data_queries,"name","id","","","");?> </td> <td nowrap><?php print __("Re-Index Method:");?> <?php form_dropdown("reindex_method",$reindex_types,"","","1","","");?> </td> <td align="right"> <input type="submit" value="<?php print __("Add");?>" name="add_dq_y" align="middle"> </td> </tr> </table> </td> <?php form_end_row(); print "</table></td></tr>"; /* end of html_header */ html_end_box(); } form_save_button_alt(); }