1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
|
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004 Ian Berry |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| cacti: a php-based graphing solution |
+-------------------------------------------------------------------------+
| Most of this code has been designed, written and is maintained by |
| Ian Berry. See about.php for specific developer credit. Any questions |
| or comments regarding this code should be directed to: |
| - iberry@raxnet.net |
+-------------------------------------------------------------------------+
| - raXnet - http://www.raxnet.net/ |
+-------------------------------------------------------------------------+
*/
include("./include/auth.php");
include_once("./lib/data_query.php");
/* set default action */
if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
switch ($_REQUEST["action"]) {
case 'save':
form_save();
break;
case 'item_moveup_dssv':
data_query_item_moveup_dssv();
header("Location: data_queries.php?action=item_edit&id=" . $_GET["snmp_query_graph_id"] . "&snmp_query_id=" . $_GET["snmp_query_id"]);
break;
case 'item_movedown_dssv':
data_query_item_movedown_dssv();
header("Location: data_queries.php?action=item_edit&id=" . $_GET["snmp_query_graph_id"] . "&snmp_query_id=" . $_GET["snmp_query_id"]);
break;
case 'item_remove_dssv':
data_query_item_remove_dssv();
header("Location: data_queries.php?action=item_edit&id=" . $_GET["snmp_query_graph_id"] . "&snmp_query_id=" . $_GET["snmp_query_id"]);
break;
case 'item_moveup_gsv':
data_query_item_moveup_gsv();
header("Location: data_queries.php?action=item_edit&id=" . $_GET["snmp_query_graph_id"] . "&snmp_query_id=" . $_GET["snmp_query_id"]);
break;
case 'item_movedown_gsv':
data_query_item_movedown_gsv();
header("Location: data_queries.php?action=item_edit&id=" . $_GET["snmp_query_graph_id"] . "&snmp_query_id=" . $_GET["snmp_query_id"]);
break;
case 'item_remove_gsv':
data_query_item_remove_gsv();
header("Location: data_queries.php?action=item_edit&id=" . $_GET["snmp_query_graph_id"] . "&snmp_query_id=" . $_GET["snmp_query_id"]);
break;
case 'item_remove':
data_query_item_remove();
header("Location: data_queries.php?action=edit&id=" . $_GET["snmp_query_id"]);
break;
case 'item_edit':
include_once("./include/top_header.php");
data_query_item_edit();
include_once("./include/bottom_footer.php");
break;
case 'remove':
data_query_remove();
header ("Location: data_queries.php");
break;
case 'edit':
include_once("./include/top_header.php");
data_query_edit();
include_once("./include/bottom_footer.php");
break;
default:
include_once("./include/top_header.php");
data_query();
include_once("./include/bottom_footer.php");
break;
}
/* --------------------------
The Save Function
-------------------------- */
function form_save() {
if (isset($_POST["save_component_snmp_query"])) {
$save["id"] = $_POST["id"];
$save["hash"] = get_hash_data_query($_POST["id"]);
$save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
$save["description"] = form_input_validate($_POST["description"], "description", "", true, 3);
$save["xml_path"] = form_input_validate($_POST["xml_path"], "xml_path", "", false, 3);
$save["data_input_id"] = $_POST["data_input_id"];
if (!is_error_message()) {
$snmp_query_id = sql_save($save, "snmp_query");
if ($snmp_query_id) {
raise_message(1);
}else{
raise_message(2);
}
}
if ((is_error_message()) || (empty($_POST["id"]))) {
header("Location: data_queries.php?action=edit&id=" . (empty($snmp_query_id) ? $_POST["id"] : $snmp_query_id));
}else{
header("Location: data_queries.php");
}
}elseif (isset($_POST["save_component_snmp_query_item"])) {
/* ================= input validation ================= */
input_validate_input_number(get_request_var_post("id"));
/* ==================================================== */
$redirect_back = false;
$save["id"] = $_POST["id"];
$save["hash"] = get_hash_data_query($_POST["id"], "data_query_graph");
$save["snmp_query_id"] = $_POST["snmp_query_id"];
$save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
$save["graph_template_id"] = $_POST["graph_template_id"];
if (!is_error_message()) {
$snmp_query_graph_id = sql_save($save, "snmp_query_graph");
if ($snmp_query_graph_id) {
raise_message(1);
/* if the user changed the graph template, go through and delete everything that
was associated with the old graph template */
if ($_POST["graph_template_id"] != $_POST["_graph_template_id"]) {
db_execute("delete from snmp_query_graph_rrd_sv where snmp_query_graph_id=$snmp_query_graph_id");
db_execute("delete from snmp_query_graph_sv where snmp_query_graph_id=$snmp_query_graph_id");
$redirect_back = true;
}
db_execute("delete from snmp_query_graph_rrd where snmp_query_graph_id=$snmp_query_graph_id");
while (list($var, $val) = each($_POST)) {
if (eregi("^dsdt_([0-9]+)_([0-9]+)_check", $var)) {
$data_template_id = ereg_replace("^dsdt_([0-9]+)_([0-9]+).+", "\\1", $var);
$data_template_rrd_id = ereg_replace("^dsdt_([0-9]+)_([0-9]+).+", "\\2", $var);
db_execute ("replace into snmp_query_graph_rrd (snmp_query_graph_id,data_template_id,data_template_rrd_id,snmp_field_name) values($snmp_query_graph_id,$data_template_id,$data_template_rrd_id,'" . $_POST{"dsdt_" . $data_template_id . "_" . $data_template_rrd_id . "_snmp_field_output"} . "')");
}elseif ((eregi("^svds_([0-9]+)_x", $var, $matches)) && (!empty($_POST{"svds_" . $matches[1] . "_text"})) && (!empty($_POST{"svds_" . $matches[1] . "_field"}))) {
/* suggested values -- data templates */
$sequence = get_sequence(0, "sequence", "snmp_query_graph_rrd_sv", "snmp_query_graph_id=" . $_POST["id"] . " and data_template_id=" . $matches[1] . " and field_name='" . $_POST{"svds_" . $matches[1] . "_field"} . "'");
$hash = get_hash_data_query(0, "data_query_sv_data_source");
db_execute("insert into snmp_query_graph_rrd_sv (hash,snmp_query_graph_id,data_template_id,sequence,field_name,text) values ('$hash'," . $_POST["id"] . "," . $matches[1] . ",$sequence,'" . $_POST{"svds_" . $matches[1] . "_field"} . "','" . $_POST{"svds_" . $matches[1] . "_text"} . "')");
$redirect_back = true;
clear_messages();
}elseif ((eregi("^svg_x", $var)) && (!empty($_POST{"svg_text"})) && (!empty($_POST{"svg_field"}))) {
/* suggested values -- graph templates */
$sequence = get_sequence(0, "sequence", "snmp_query_graph_sv", "snmp_query_graph_id=" . $_POST["id"] . " and field_name='" . $_POST{"svg_field"} . "'");
$hash = get_hash_data_query(0, "data_query_sv_graph");
db_execute("insert into snmp_query_graph_sv (hash,snmp_query_graph_id,sequence,field_name,text) values ('$hash'," . $_POST["id"] . ",$sequence,'" . $_POST{"svg_field"} . "','" . $_POST{"svg_text"} . "')");
$redirect_back = true;
clear_messages();
}
}
}else{
raise_message(2);
}
}
if ((is_error_message()) || (empty($_POST["id"])) || ($redirect_back == true)) {
header("Location: data_queries.php?action=item_edit&id=" . (empty($snmp_query_graph_id) ? $_POST["id"] : $snmp_query_graph_id) . "&snmp_query_id=" . $_POST["snmp_query_id"]);
}else{
header("Location: data_queries.php?action=edit&id=" . $_POST["snmp_query_id"]);
}
}
}
/* ----------------------------
Data Query Graph Functions
---------------------------- */
function data_query_item_movedown_gsv() {
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
input_validate_input_number(get_request_var("snmp_query_graph_id"));
/* ==================================================== */
move_item_down("snmp_query_graph_sv", $_GET["id"], "snmp_query_graph_id=" . $_GET["snmp_query_graph_id"] . " and field_name='" . $_GET["field_name"] . "'");
}
function data_query_item_moveup_gsv() {
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
input_validate_input_number(get_request_var("snmp_query_graph_id"));
/* ==================================================== */
move_item_up("snmp_query_graph_sv", $_GET["id"], "snmp_query_graph_id=" . $_GET["snmp_query_graph_id"] . " and field_name='" . $_GET["field_name"] . "'");
}
function data_query_item_remove_gsv() {
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
/* ==================================================== */
db_execute("delete from snmp_query_graph_sv where id=" . $_GET["id"]);
}
function data_query_item_movedown_dssv() {
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
input_validate_input_number(get_request_var("data_template_id"));
input_validate_input_number(get_request_var("snmp_query_graph_id"));
/* ==================================================== */
move_item_down("snmp_query_graph_rrd_sv", $_GET["id"], "data_template_id=" . $_GET["data_template_id"] . " and snmp_query_graph_id=" . $_GET["snmp_query_graph_id"] . " and field_name='" . $_GET["field_name"] . "'");
}
function data_query_item_moveup_dssv() {
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
input_validate_input_number(get_request_var("data_template_id"));
input_validate_input_number(get_request_var("snmp_query_graph_id"));
/* ==================================================== */
move_item_up("snmp_query_graph_rrd_sv", $_GET["id"], "data_template_id=" . $_GET["data_template_id"] . " and snmp_query_graph_id=" . $_GET["snmp_query_graph_id"] . " and field_name='" . $_GET["field_name"] . "'");
}
function data_query_item_remove_dssv() {
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
/* ==================================================== */
db_execute("delete from snmp_query_graph_rrd_sv where id=" . $_GET["id"]);
}
function data_query_item_remove() {
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
input_validate_input_number(get_request_var("snmp_query_id"));
/* ==================================================== */
if ((read_config_option("remove_verification") == "on") && (!isset($_GET["confirm"]))) {
include("./include/top_header.php");
form_confirm("Are You Sure?", "Are you sure you want to delete the Data Query Graph <strong>'" . db_fetch_cell("select name from snmp_query_graph where id=" . $_GET["id"]) . "'</strong>?", "data_queries.php?action=edit&id=" . $_GET["snmp_query_id"], "data_queries.php?action=item_remove&id=" . $_GET["id"] . "&snmp_query_id=" . $_GET["snmp_query_id"]);
include("./include/bottom_footer.php");
exit;
}
if ((read_config_option("remove_verification") == "") || (isset($_GET["confirm"]))) {
db_execute("delete from snmp_query_graph where id=" . $_GET["id"]);
db_execute("delete from snmp_query_graph_rrd where snmp_query_graph_id=" . $_GET["id"]);
db_execute("delete from snmp_query_graph_rrd_sv where snmp_query_graph_id=" . $_GET["id"]);
db_execute("delete from snmp_query_graph_sv where snmp_query_graph_id=" . $_GET["id"]);
}
}
function data_query_item_edit() {
global $colors, $fields_data_query_item_edit;
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
input_validate_input_number(get_request_var("snmp_query_id"));
/* ==================================================== */
if (!empty($_GET["id"])) {
$snmp_query_item = db_fetch_row("select * from snmp_query_graph where id=" . $_GET["id"]);
}
$snmp_query = db_fetch_row("select name,xml_path from snmp_query where id=" . $_GET["snmp_query_id"]);
$header_label = "[edit: " . $snmp_query["name"] . "]";
html_start_box("<strong>Associated Graph/Data Templates</strong> $header_label", "98%", $colors["header"], "3", "center", "");
draw_edit_form(array(
"config" => array(),
"fields" => inject_form_variables($fields_data_query_item_edit, (isset($snmp_query_item) ? $snmp_query_item : array()), $_GET)
));
html_end_box();
if (!empty($snmp_query_item["id"])) {
html_start_box("<strong>Associated Data Templates</strong>", "98%", $colors["header"], "3", "center", "");
$data_templates = db_fetch_assoc("select
data_template.id,
data_template.name
from (data_template, data_template_rrd, graph_templates_item)
where graph_templates_item.task_item_id=data_template_rrd.id
and data_template_rrd.data_template_id=data_template.id
and data_template_rrd.local_data_id=0
and graph_templates_item.local_graph_id=0
and graph_templates_item.graph_template_id=" . $snmp_query_item["graph_template_id"] . "
group by data_template.id
order by data_template.name");
$i = 0;
if (sizeof($data_templates) > 0) {
foreach ($data_templates as $data_template) {
print " <tr bgcolor='#" . $colors["header_panel"] . "'>
<td><span style='color: white; font-weight: bold;'>Data Template - " . $data_template["name"] . "</span></td>
</tr>";
$data_template_rrds = db_fetch_assoc("select
data_template_rrd.id,
data_template_rrd.data_source_name,
snmp_query_graph_rrd.snmp_field_name,
snmp_query_graph_rrd.snmp_query_graph_id
from data_template_rrd
left join snmp_query_graph_rrd on (snmp_query_graph_rrd.data_template_rrd_id=data_template_rrd.id and snmp_query_graph_rrd.snmp_query_graph_id=" . $_GET["id"] . " and snmp_query_graph_rrd.data_template_id=" . $data_template["id"] . ")
where data_template_rrd.data_template_id=" . $data_template["id"] . "
and data_template_rrd.local_data_id=0
order by data_template_rrd.data_source_name");
$i = 0;
if (sizeof($data_template_rrds) > 0) {
foreach ($data_template_rrds as $data_template_rrd) {
if (empty($data_template_rrd["snmp_query_graph_id"])) {
$old_value = "";
}else{
$old_value = "on";
}
form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++;
?>
<td>
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td width="200">
<strong>Data Source:</strong>
</td>
<td width="200">
<?php print $data_template_rrd["data_source_name"];?>
</td>
<td width="1">
<?php
$snmp_queries = get_data_query_array($_GET["snmp_query_id"]);
$xml_outputs = array();
while (list($field_name, $field_array) = each($snmp_queries["fields"])) {
if ($field_array["direction"] == "output") {
$xml_outputs[$field_name] = $field_name . " (" . $field_array["name"] . ")";;
}
}
form_dropdown("dsdt_" . $data_template["id"] . "_" . $data_template_rrd["id"] . "_snmp_field_output",$xml_outputs,"","",$data_template_rrd["snmp_field_name"],"","");?>
</td>
<td align="right">
<?php form_checkbox("dsdt_" . $data_template["id"] . "_" . $data_template_rrd["id"] . "_check", $old_value, "", "",$_GET["id"]); print "<br>";?>
</td>
</tr>
</table>
</td>
</tr>
<?php
}
}
}
}
html_end_box();
html_start_box("<strong>Suggested Values</strong>", "98%", $colors["header"], "0", "center", "");
reset($data_templates);
/* suggested values for data templates */
if (sizeof($data_templates) > 0) {
foreach ($data_templates as $data_template) {
$suggested_values = db_fetch_assoc("select
text,
field_name,
id
from snmp_query_graph_rrd_sv
where snmp_query_graph_id=" . $_GET["id"] . "
and data_template_id=" . $data_template["id"] . "
order by field_name,sequence");
print " <tr bgcolor='#" . $colors["header_panel"] . "'>
<td style='padding: 3px;'><span style='color: white; font-weight: bold;'>Data Template - " . $data_template["name"] . "</span></td>
</tr>";
$i = 0;
if (sizeof($suggested_values) > 0) {
print "<tr><td><table cellspacing='0' cellpadding='3' border='0' width='100%'>\n";
foreach ($suggested_values as $suggested_value) {
form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++;
?>
<td width="120">
<strong><?php print $suggested_value["field_name"];?></strong>
</td>
<td>
<?php print $suggested_value["text"];?>
</td>
<td width="70">
<a href="data_queries.php?action=item_movedown_dssv&snmp_query_graph_id=<?php print $_GET["id"];?>&id=<?php print $suggested_value["id"];?>&snmp_query_id=<?php print $_GET["snmp_query_id"];?>&data_template_id=<?php print $data_template["id"];?>&field_name=<?php print $suggested_value["field_name"];?>"><img src="images/move_down.gif" border="0" alt="Move Down"></a>
<a href="data_queries.php?action=item_moveup_dssv&snmp_query_graph_id=<?php print $_GET["id"];?>&id=<?php print $suggested_value["id"];?>&snmp_query_id=<?php print $_GET["snmp_query_id"];?>&data_template_id=<?php print $data_template["id"];?>&field_name=<?php print $suggested_value["field_name"];?>"><img src="images/move_up.gif" border="0" alt="Move Up"></a>
</td>
<td align="right">
<a href="data_queries.php?action=item_remove_dssv&snmp_query_graph_id=<?php print $_GET["id"];?>&id=<?php print $suggested_value["id"];?>&snmp_query_id=<?php print $_GET["snmp_query_id"];?>&data_template_id=<?php print $data_template["id"];?>"><img src="images/delete_icon.gif" width="10" height="10" border="0" alt="Delete"></a>
</td>
</tr>
<?php
}
print "</table></td></tr>\n";
}
form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i);
?>
<td>
<table cellspacing="0" cellpadding="3" border="0" width="100%">
<tr>
<td width="1">
<input type="text" name="svds_<?php print $data_template["id"];?>_text" size="30">
</td>
<td width="220" nowrap>
Field Name: <input type="text" name="svds_<?php print $data_template["id"];?>_field" size="15">
</td>
<td>
<input type="image" src="images/button_add.gif" name="svds_<?php print $data_template["id"];?>" alt="Add" align="absmiddle">
</td>
</tr>
</table>
</td>
</tr>
<?php
}
}
/* suggested values for graphs templates */
$suggested_values = db_fetch_assoc("select
text,
field_name,
id
from snmp_query_graph_sv
where snmp_query_graph_id=" . $_GET["id"] . "
order by field_name,sequence");
print " <tr bgcolor='#" . $colors["header_panel"] . "'>
<td style='padding: 3px;'><span style='color: white; font-weight: bold;'>Graph Template - " . db_fetch_cell("select name from graph_templates where id=" . $snmp_query_item["graph_template_id"]) . "</span></td>
</tr>";
$i = 0;
if (sizeof($suggested_values) > 0) {
print "<tr><td><table cellspacing='0' cellpadding='3' border='0' width='100%'>\n";
foreach ($suggested_values as $suggested_value) {
form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++;
?>
<td width="120">
<strong><?php print $suggested_value["field_name"];?></strong>
</td>
<td>
<?php print $suggested_value["text"];?>
</td>
<td width="70">
<a href="data_queries.php?action=item_movedown_gsv&snmp_query_graph_id=<?php print $_GET["id"];?>&id=<?php print $suggested_value["id"];?>&snmp_query_id=<?php print $_GET["snmp_query_id"];?>&field_name=<?php print $suggested_value["field_name"];?>"><img src="images/move_down.gif" border="0" alt="Move Down"></a>
<a href="data_queries.php?action=item_moveup_gsv&snmp_query_graph_id=<?php print $_GET["id"];?>&id=<?php print $suggested_value["id"];?>&snmp_query_id=<?php print $_GET["snmp_query_id"];?>&field_name=<?php print $suggested_value["field_name"];?>"><img src="images/move_up.gif" border="0" alt="Move Up"></a>
</td>
<td align="right">
<a href="data_queries.php?action=item_remove_gsv&snmp_query_graph_id=<?php print $_GET["id"];?>&id=<?php print $suggested_value["id"];?>&snmp_query_id=<?php print $_GET["snmp_query_id"];?>"><img src="images/delete_icon.gif" width="10" height="10" border="0" alt="Delete"></a>
</td>
</tr>
<?php
}
print "</table></td></tr>\n";
}
form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i);
?>
<td>
<table cellspacing="0" cellpadding="3" border="0" width="100%">
<tr>
<td width="1">
<input type="text" name="svg_text" size="30">
</td>
<td width="220" nowrap>
Field Name: <input type="text" name="svg_field" size="15">
</td>
<td>
<input type="image" src="images/button_add.gif" name="svg" alt="Add" align="absmiddle">
</td>
</tr>
</table>
</td>
</tr>
<?php
html_end_box();
}
form_save_button("data_queries.php?action=edit&id=" . $_GET["snmp_query_id"]);
}
/* ---------------------
Data Query Functions
--------------------- */
function data_query_remove() {
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
/* ==================================================== */
if ((read_config_option("remove_verification") == "on") && (!isset($_GET["confirm"]))) {
include("./include/top_header.php");
form_confirm("Are You Sure?", "Are you sure you want to delete the Data Query <strong>'" . db_fetch_cell("select name from snmp_query where id=" . $_GET["id"]) . "'</strong>?", "data_queries.php", "data_queries.php?action=remove&id=" . $_GET["id"]);
include("./include/bottom_footer.php");
exit;
}
if ((read_config_option("remove_verification") == "") || (isset($_GET["confirm"]))) {
$snmp_query_graph = db_fetch_assoc("select id from snmp_query_graph where snmp_query_id=" . $_GET["id"]);
if (sizeof($snmp_query_graph) > 0) {
foreach ($snmp_query_graph as $item) {
db_execute("delete from snmp_query_graph_rrd where snmp_query_graph_id=" . $item["id"]);
}
}
db_execute("delete from snmp_query where id=" . $_GET["id"]);
db_execute("delete from snmp_query_graph where snmp_query_id=" . $_GET["id"]);
db_execute("delete from host_template_snmp_query where snmp_query_id=" . $_GET["id"]);
db_execute("delete from host_snmp_query where snmp_query_id=" . $_GET["id"]);
db_execute("delete from host_snmp_cache where snmp_query_id=" . $_GET["id"]);
}
}
function data_query_edit() {
global $colors, $fields_data_query_edit, $config;
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
/* ==================================================== */
if (!empty($_GET["id"])) {
$snmp_query = db_fetch_row("select * from snmp_query where id=" . $_GET["id"]);
$header_label = "[edit: " . $snmp_query["name"] . "]";
}else{
$header_label = "[new]";
}
html_start_box("<strong>Data Queries</strong> $header_label", "98%", $colors["header"], "3", "center", "");
draw_edit_form(array(
"config" => array(),
"fields" => inject_form_variables($fields_data_query_edit, (isset($snmp_query) ? $snmp_query : array()))
));
html_end_box();
if (!empty($snmp_query["id"])) {
$xml_filename = str_replace("<path_cacti>", $config["base_path"], $snmp_query["xml_path"]);
if ((file_exists($xml_filename)) && (is_file($xml_filename))) {
$text = "<font color='#0d7c09'><strong>Successfully located XML file</strong></font>";
$xml_file_exists = true;
}else{
$text = "<font color='#ff0000'><strong>Could not locate XML file.</strong></font>";
$xml_file_exists = false;
}
html_start_box("", "98%", "aaaaaa", "3", "center", "");
print "<tr bgcolor='#f5f5f5'><td>$text</td></tr>";
html_end_box();
if ($xml_file_exists == true) {
html_start_box("<strong>Associated Graph Templates</strong>", "98%", $colors["header"], "3", "center", "data_queries.php?action=item_edit&snmp_query_id=" . $snmp_query["id"]);
print " <tr bgcolor='#" . $colors["header_panel"] . "'>
<td><span style='color: white; font-weight: bold;'>Name</span></td>
<td><span style='color: white; font-weight: bold;'>Graph Template Name</span></td>
<td></td>
</tr>";
$snmp_query_graphs = db_fetch_assoc("select
snmp_query_graph.id,
graph_templates.name as graph_template_name,
snmp_query_graph.name
from snmp_query_graph
left join graph_templates on (snmp_query_graph.graph_template_id=graph_templates.id)
where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . "
order by snmp_query_graph.name");
$i = 0;
if (sizeof($snmp_query_graphs) > 0) {
foreach ($snmp_query_graphs as $snmp_query_graph) {
form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++;
?>
<td>
<strong><a href="data_queries.php?action=item_edit&id=<?php print $snmp_query_graph["id"];?>&snmp_query_id=<?php print $snmp_query["id"];?>"><?php print $snmp_query_graph["name"];?></a></strong>
</td>
<td>
<?php print $snmp_query_graph["graph_template_name"];?>
</td>
<td align="right">
<a href="data_queries.php?action=item_remove&id=<?php print $snmp_query_graph["id"];?>&snmp_query_id=<?php print $snmp_query["id"];?>"><img src="images/delete_icon.gif" width="10" height="10" border="0" alt="Delete"></a>
</td>
</tr>
<?php
}
}else{
print "<tr><td><em>No Graph Templates Defined.</em></td></tr>";
}
html_end_box();
}
}
form_save_button("data_queries.php");
}
function data_query() {
global $colors;
/* clean up sort_column */
if (isset($_REQUEST["sort_column"])) {
$_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
}
/* clean up search string */
if (isset($_REQUEST["sort_direction"])) {
$_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
}
/* remember these search fields in session vars so we don't have to keep passing them around */
load_current_session_value("sort_column", "sess_data_queries_sort_column", "description");
load_current_session_value("sort_direction", "sess_data_queries_sort_direction", "ASC");
html_start_box("<strong>Data Queries</strong>", "98%", $colors["header"], "3", "center", "data_queries.php?action=edit");
$display_text = array(
"name" => array("Name", "ASC"),
"data_input_method" => array("Data Input Method", "ASC"));
html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"], 3);
$snmp_queries = db_fetch_assoc("SELECT
snmp_query.id,
snmp_query.name,
data_input.name AS data_input_method
FROM snmp_query INNER JOIN data_input ON (snmp_query.data_input_id = data_input.id)
ORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction']);
$i = 0;
if (sizeof($snmp_queries) > 0) {
foreach ($snmp_queries as $snmp_query) {
form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++;
?>
<td>
<a class="linkEditMain" href="data_queries.php?action=edit&id=<?php print $snmp_query["id"];?>"><?php print $snmp_query["name"];?></a>
</td>
<td>
<?php print $snmp_query["data_input_method"]; ?>
</td>
<td align="right">
<a href="data_queries.php?action=remove&id=<?php print $snmp_query["id"];?>"><img src="images/delete_icon.gif" width="10" height="10" border="0" alt="Delete"></a>
</td>
</tr>
<?php
}
}
html_end_box();
}
?>
|