Example #1
0
function template_edit()
{
    global $colors, $data_source_types;
    if (!empty($_GET["id"])) {
        $data_template = db_fetch_row("select * from data_template where id=" . $_GET["id"]);
        $data_template_items = db_fetch_assoc("select * from data_template_item where data_template_id=" . $_GET["id"]);
        $header_label = _("[edit: ") . $data_template["template_name"] . "]";
    } else {
        $header_label = _("[new]");
    }
    form_start("data_templates.php", "form_data_template");
    /* ==================== Box: Data Template ==================== */
    html_start_box("<strong>" . _("Data Template") . "</strong> {$header_label}");
    _data_template_field__template_name("template_name", isset($data_template) ? $data_template["template_name"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    html_end_box();
    /* ==================== Box: Data Input ==================== */
    /* determine current value for 'data_input_type' */
    if (isset($_GET["data_input_type"])) {
        $_data_input_type = $_GET["data_input_type"];
    } else {
        if (isset($data_template["data_input_type"])) {
            $_data_input_type = $data_template["data_input_type"];
        } else {
            $_data_input_type = DATA_INPUT_TYPE_SCRIPT;
        }
    }
    /* get a list of all data input type fields for this data template */
    if (isset($data_template)) {
        $data_input_type_fields = array_rekey(db_fetch_assoc("select name,t_value,value from data_template_field where data_template_id = " . $data_template["id"]), "name", array("t_value", "value"));
    } else {
        $data_input_type_fields = array();
    }
    html_start_box("<strong>" . _("Data Input") . "</strong>");
    _data_source_input_field__data_input_type("data_input_type", true, $_data_input_type, empty($_GET["id"]) ? 0 : $_GET["id"]);
    /* grab the appropriate data input type form array */
    if ($_data_input_type == DATA_INPUT_TYPE_SCRIPT) {
        $scripts = api_script_list();
        if (sizeof($scripts) > 0) {
            /* determine current value for 'script_id' */
            if (isset($_GET["script_id"]) && is_numeric($_GET["script_id"])) {
                $_script_id = $_GET["script_id"];
            } else {
                if (isset($data_input_type_fields["script_id"])) {
                    $_script_id = $data_input_type_fields["script_id"]["value"];
                } else {
                    /* default to the first item in the script list */
                    $_script_id = $scripts[0]["id"];
                }
            }
            field_row_header(_("External Script"));
            _data_source_input_field__script_id("dif_script_id", "data_templates.php?action=edit" . (!empty($_GET["id"]) ? "&id=" . $_GET["id"] : "") . "&data_input_type={$_data_input_type}&script_id=|dropdown_value|", $_script_id);
            /* get each INPUT field for this script */
            $script_input_fields = db_fetch_assoc("select * from data_input_fields where data_input_id = {$_script_id} and input_output='in' order by name");
            if (sizeof($script_input_fields) > 0) {
                field_row_header(_("Custom Input Fields"));
                foreach ($script_input_fields as $field) {
                    _data_source_input_field__script("dif_" . $field["data_name"], $field["name"], true, isset($data_input_type_fields[$field["data_name"]]) ? $data_input_type_fields[$field["data_name"]]["value"] : "", "t_dif_" . $field["data_name"], isset($data_input_type_fields[$field["data_name"]]) ? $data_input_type_fields[$field["data_name"]]["t_value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                }
            }
        }
    } else {
        if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) {
            /* since the "sql" key is not executed until draw_edit_form(), we have fetch the list of
             * data queries here as well */
            $data_queries = api_data_query_list();
            if (sizeof($data_queries) > 0) {
                /* determine current value for 'data_query_id' */
                if (isset($_GET["data_query_id"]) && is_numeric($_GET["data_query_id"])) {
                    $_data_query_id = $_GET["data_query_id"];
                } else {
                    if (isset($data_input_type_fields["data_query_id"])) {
                        $_data_query_id = $data_input_type_fields["data_query_id"]["value"];
                    } else {
                        /* default to the first item in the data query list */
                        $_data_query_id = $data_queries[0]["id"];
                    }
                }
                field_row_header(_("Data Query"));
                _data_source_input_field__data_query_id("dif_data_query_id", "data_templates.php?action=edit" . (!empty($_GET["id"]) ? "&id=" . $_GET["id"] : "") . "&data_input_type={$_data_input_type}&data_query_id=|dropdown_value|", $_data_query_id);
            }
        } else {
            if ($_data_input_type == DATA_INPUT_TYPE_SNMP) {
                _data_source_input_field__device_hdr_generic();
                _data_source_input_field__device_snmp_port("dif_snmp_port", true, isset($data_input_type_fields["snmp_port"]) ? $data_input_type_fields["snmp_port"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_port"]) ? $data_input_type_fields["snmp_port"]["t_value"] : "0", isset($data_input_type_fields["snmp_port"]) ? "on" : "");
                _data_source_input_field__device_snmp_timeout("dif_snmp_timeout", true, isset($data_input_type_fields["snmp_timeout"]) ? $data_input_type_fields["snmp_timeout"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_timeout"]) ? $data_input_type_fields["snmp_timeout"]["t_value"] : "0", isset($data_input_type_fields["snmp_timeout"]) ? "on" : "");
                _data_source_input_field__device_snmp_version("dif_snmp_version", true, isset($data_input_type_fields["snmp_version"]) ? $data_input_type_fields["snmp_version"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_version"]) ? $data_input_type_fields["snmp_version"]["t_value"] : "0", isset($data_input_type_fields["snmp_version"]) ? "on" : "");
                _data_source_input_field__device_hdr_snmpv12();
                _data_source_input_field__device_snmp_community("dif_snmp_community", true, isset($data_input_type_fields["snmp_community"]) ? $data_input_type_fields["snmp_community"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_community"]) ? $data_input_type_fields["snmp_community"]["t_value"] : "0", isset($data_input_type_fields["snmp_community"]) ? "on" : "");
                _data_source_input_field__device_hdr_snmpv3();
                _data_source_input_field__device_snmpv3_auth_username("dif_snmpv3_auth_username", true, isset($data_input_type_fields["snmpv3_auth_username"]) ? $data_input_type_fields["snmpv3_auth_username"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_auth_username"]) ? $data_input_type_fields["snmpv3_auth_username"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_auth_username"]) ? "on" : "");
                _data_source_input_field__device_snmpv3_auth_password("dif_snmpv3_auth_password", true, isset($data_input_type_fields["snmpv3_auth_password"]) ? $data_input_type_fields["snmpv3_auth_password"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_auth_password"]) ? $data_input_type_fields["snmpv3_auth_password"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_auth_password"]) ? "on" : "");
                _data_source_input_field__device_snmpv3_auth_protocol("dif_snmpv3_auth_protocol", true, isset($data_input_type_fields["snmpv3_auth_protocol"]) ? $data_input_type_fields["snmpv3_auth_protocol"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_auth_protocol"]) ? $data_input_type_fields["snmpv3_auth_protocol"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_auth_protocol"]) ? "on" : "");
                _data_source_input_field__device_snmpv3_priv_passphrase("dif_snmpv3_priv_passphrase", true, isset($data_input_type_fields["snmpv3_priv_passphrase"]) ? $data_input_type_fields["snmpv3_priv_passphrase"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_priv_passphrase"]) ? $data_input_type_fields["snmpv3_priv_passphrase"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_priv_passphrase"]) ? "on" : "");
                _data_source_input_field__device_snmpv3_priv_protocol("dif_snmpv3_priv_protocol", true, isset($data_input_type_fields["snmpv3_priv_protocol"]) ? $data_input_type_fields["snmpv3_priv_protocol"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_priv_protocol"]) ? $data_input_type_fields["snmpv3_priv_protocol"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_priv_protocol"]) ? "on" : "");
            }
        }
    }
    html_end_box();
    /* ==================== Box: Data Source ==================== */
    $rra_items = api_data_template_rra_item_list($data_template["id"]);
    /* the user clicked the "add item" link. we need to make sure they get redirected back to
     * this page if an error occurs */
    if ($_GET["action"] == "sv_add") {
        form_hidden_box("redirect_sv_add", "x", "");
    }
    html_start_box("<strong>" . _("Data Source") . "</strong>");
    _data_source_field__name("name", true, empty($_GET["id"]) ? 0 : $_GET["id"], "t_name", isset($data_template["t_name"]) ? $data_template["t_name"] : "");
    _data_source_field__rra("preset_rra_id", true, isset($data_template["preset_rra_id"]) ? $data_template["preset_rra_id"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    _data_source_field__polling_interval("polling_interval", true, isset($data_template["polling_interval"]) ? $data_template["polling_interval"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_polling_interval", isset($data_template["t_polling_interval"]) ? $data_template["t_polling_interval"] : "");
    _data_source_field__active("active", true, isset($data_template["active"]) ? $data_template["active"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_active", isset($data_template["t_active"]) ? $data_template["t_active"] : "");
    html_end_box();
    /* ==================== Box: Data Source Item ==================== */
    html_start_box("<strong>" . _("Data Source Item") . "</strong>", empty($_GET["id"]) ? "" : "javascript:document.forms[0].action.value='item_add';submit_redirect(0, '" . htmlspecialchars("data_templates.php?action=item_add&id=" . $_GET["id"]) . "', '')");
    /* the user clicked the "add item" link. we need to make sure they get redirected back to
     * this page if an error occurs */
    if ($_GET["action"] == "item_add") {
        form_hidden_box("redirect_item_add", "x", "");
    }
    /* this allows a "blank" data template item to be displayed when the user wants to create
     * a new one */
    if (!isset($data_template_items) || sizeof($data_template_items) == 0 || $_GET["action"] == "item_add") {
        if (isset($data_template_items)) {
            $next_index = sizeof($data_template_items);
        } else {
            $next_index = 0;
        }
        $data_template_items[$next_index] = array();
    }
    if (sizeof($data_template_items) > 0) {
        if ($_data_input_type == DATA_INPUT_TYPE_SCRIPT) {
            $script_output_fields = db_fetch_assoc("select * from data_input_fields where data_input_id = {$_script_id} and input_output='out' order by name");
            $field_input_description = _("Script Output Field");
        } else {
            if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) {
                $field_list = api_data_query_field_list($_data_query_id, DATA_QUERY_FIELD_TYPE_OUTPUT);
                $data_query_output_fields = array();
                if (sizeof($field_list) > 0) {
                    foreach ($field_list as $field) {
                        $data_query_output_fields[$field["name"]] = $field["name"] . " (" . $field["name_desc"] . ")";
                    }
                }
                $field_input_description = _("Data Query Output Field");
            } else {
                if ($_data_input_type == DATA_INPUT_TYPE_SNMP) {
                    $field_input_description = _("SNMP OID");
                }
            }
        }
        foreach ($data_template_items as $item) {
            if ($_data_input_type != DATA_INPUT_TYPE_NONE) {
                ?>
				<tr bgcolor="<?php 
                print $colors["header_panel_background"];
                ?>
">
					<td class='textSubHeaderDark' colspan="2">
						<?php 
                print isset($item["data_source_name"]) ? $item["data_source_name"] : "(" . _("New Data Template Item") . ")";
                ?>
					</td>
					<td class='textSubHeaderDark' align='right'>
						<?php 
                if (isset($item["id"]) && sizeof($data_template_items) > 1) {
                    print "[<a href='data_templates.php?action=item_remove&id=" . $item["id"] . "&data_template_id=" . $item["data_template_id"] . "' class='linkOverDark'>remove</a>]\n";
                }
                ?>
					</td>
				</tr>
				<tr bgcolor="#e1e1e1">
					<td width="50%" style="border-bottom: 1px solid #a1a1a1;">
						<font class='textEditTitle'>Field Input: <?php 
                print $field_input_description;
                ?>
</font><br>
					</td>
					<td style="border-bottom: 1px solid #a1a1a1;" colspan="2">
						<?php 
                if ($_data_input_type == DATA_INPUT_TYPE_SCRIPT) {
                    form_dropdown("dsi|field_input_value|" . (isset($item["id"]) ? $item["id"] : "0"), $script_output_fields, "name", "data_name", isset($item["field_input_value"]) ? $item["field_input_value"] : "", "", "");
                } else {
                    if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) {
                        form_dropdown("dsi|field_input_value|" . (isset($item["id"]) ? $item["id"] : "0"), $data_query_output_fields, "", "", isset($item["field_input_value"]) ? $item["field_input_value"] : "", "", "");
                    } else {
                        if ($_data_input_type == DATA_INPUT_TYPE_SNMP) {
                            form_text_box("dsi|field_input_value|" . (isset($item["id"]) ? $item["id"] : "0"), isset($item["field_input_value"]) ? $item["field_input_value"] : "", "", "100", 40, "text", 0);
                        }
                    }
                }
                ?>
					</td>
				</tr>
				<?php 
            }
            $_field_id = isset($item["id"]) ? $item["id"] : 0;
            field_reset_row_color();
            field_increment_row_color();
            _data_source_item_field__data_source_name("dsi|data_source_name|{$_field_id}", true, isset($item["data_source_name"]) ? $item["data_source_name"] : "", $_field_id);
            _data_source_item_field__rrd_minimum("dsi|rrd_minimum|{$_field_id}", true, isset($item["rrd_minimum"]) ? $item["rrd_minimum"] : "", $_field_id, "dsi|t_rrd_minimum|{$_field_id}", isset($item["t_rrd_minimum"]) ? $item["t_rrd_minimum"] : "");
            _data_source_item_field__rrd_maximum("dsi|rrd_maximum|{$_field_id}", true, isset($item["rrd_maximum"]) ? $item["rrd_maximum"] : "", $_field_id, "dsi|t_rrd_maximum|{$_field_id}", isset($item["t_rrd_maximum"]) ? $item["t_rrd_maximum"] : "");
            _data_source_item_field__data_source_type("dsi|data_source_type|{$_field_id}", true, isset($item["data_source_type"]) ? $item["data_source_type"] : "", $_field_id, "dsi|t_data_source_type|{$_field_id}", isset($item["t_data_source_type"]) ? $item["t_data_source_type"] : "");
            _data_source_item_field__rrd_heartbeat("dsi|rrd_heartbeat|{$_field_id}", true, isset($item["rrd_heartbeat"]) ? $item["rrd_heartbeat"] : "", $_field_id, "dsi|t_rrd_heartbeat|{$_field_id}", isset($item["t_rrd_heartbeat"]) ? $item["t_rrd_heartbeat"] : "");
        }
    }
    html_end_box();
    form_hidden_box("data_template_id", empty($_GET["id"]) ? 0 : $_GET["id"], "");
    form_hidden_box("action_post", "data_template_edit");
    form_save_button("data_templates.php");
}
Example #2
0
function graph_edit()
{
    global $colors;
    if (!empty($_GET["id"])) {
        $graph = db_fetch_row("select * from graph where id=" . $_GET["id"]);
        if (!empty($graph["graph_template_id"])) {
            $graph_template = db_fetch_row("select * from graph_template where id=" . $graph["graph_template_id"]);
        }
        $header_label = _("[edit: ") . $graph["title_cache"] . "]";
    } else {
        $header_label = _("[new]");
    }
    /* handle debug mode */
    if (isset($_GET["debug"])) {
        if ($_GET["debug"] == "0") {
            kill_session_var("graph_debug_mode");
        } elseif ($_GET["debug"] == "1") {
            $_SESSION["graph_debug_mode"] = true;
        }
    }
    if (!empty($_GET["id"])) {
        ?>
		<table width="98%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php 
        echo $graph["title_cache"];
        ?>
				</td>
				<td class="textInfo" align="right" valign="top">
					<span style="color: #c16921;">*<a href='graphs.php?action=edit&id=<?php 
        print isset($_GET["id"]) ? $_GET["id"] : 0;
        ?>
&debug=<?php 
        print isset($_SESSION["graph_debug_mode"]) ? "0" : "1";
        ?>
'>Turn <strong><?php 
        print isset($_SESSION["graph_debug_mode"]) ? "Off" : "On";
        ?>
</strong> Graph Debug Mode.</a>
				</td>
			</tr>
		</table>
		<br>
		<?php 
    }
    /* ==================== Box: Device/Template Selection ==================== */
    $form_array = array("graph_template_id" => array("method" => "drop_sql", "friendly_name" => _("Selected Graph Template"), "description" => _("Choose a graph template to apply to this graph. Please note that graph data may be lost if you change the graph template after one is already applied."), "value" => isset($graph) ? $graph["graph_template_id"] : "0", "none_value" => _("None"), "sql" => "select graph_template.id,graph_template.template_name as name from graph_template order by template_name"), "host_id" => array("method" => "drop_sql", "friendly_name" => _("Host"), "description" => _("Choose the host that this graph belongs to."), "value" => isset($_GET["host_id"]) ? $_GET["host_id"] : $graph["host_id"], "none_value" => _("None"), "sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "id" => array("method" => "hidden", "value" => isset($graph) ? $graph["id"] : "0"));
    html_start_box("<strong>" . _("Device/Template Selection") . "</strong> {$header_label}", "98%", $colors["header_background"], "3", "center", "");
    draw_edit_form(array("config" => array(), "fields" => $form_array));
    html_end_box();
    /* ==================== Box: Supplemental Template Data ==================== */
    /* only display the "inputs" area if we are using a graph template for this graph */
    if (!empty($graph["graph_template_id"])) {
        ob_start();
        html_start_box("<strong>" . _("Supplemental Template Data") . "</strong>", "98%", $colors["header_background"], "3", "center", "");
        $num_output_fields = draw_nontemplated_fields_graph($graph["graph_template_id"], $graph, "g||field|", "<strong>" . _("Graph Fields") . "</strong>", true);
        $num_output_fields += draw_nontemplated_fields_graph_item($graph["graph_template_id"], array_rekey(db_fetch_assoc("select * from graph_item where graph_id = " . $graph["id"]), "graph_template_item_id", array("id", "data_source_item_id", "color", "graph_item_type", "cdef", "consolidation_function", "gprint_format", "legend_format", "legend_value", "hard_return")), "gip||field|||id|", "<strong>" . _("Graph Item Fields") . "</strong>", true);
        html_end_box();
        if ($num_output_fields == 0) {
            ob_end_clean();
        } else {
            ob_end_flush();
        }
    }
    /* graph item list goes here */
    if (!empty($_GET["id"]) && empty($graph["graph_template_id"])) {
        $graph_items = db_fetch_assoc("select\n\t\t\tgraph_item.id\n\t\t\tfrom graph_item\n\t\t\twhere graph_item.graph_id = " . $_GET["id"] . "\n\t\t\torder by graph_item.sequence");
        /* ==================== Box: Graph Items ==================== */
        html_start_box("<strong>" . _("Graph Items") . "</strong>", "98%", $colors["header_background"], "3", "center", "graphs_items.php?action=edit&graph_id=" . $_GET["id"]);
        draw_graph_item_editor($_GET["id"], "graph", false);
        html_end_box();
    }
    /* display sample graph, or graph source in debug mode */
    if (!empty($_GET["id"])) {
        ?>
		<table width="98%" align="center">
			<tr>
				<td align="center" class="textInfo" colspan="2">
					<img src="graph_image.php?graph_id=<?php 
        print $_GET["id"];
        ?>
&rra_id=1" alt="">
				</td>
				<?php 
        if (isset($_SESSION["graph_debug_mode"]) && isset($_GET["id"])) {
            $graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR;
            ?>
					<td>
						<span class="textInfo"><?php 
            echo _("RRDTool Says:");
            ?>
</span><br>
						<pre><?php 
            print rrdtool_function_graph($_GET["id"], 1, $graph_data_array);
            ?>
</pre>
					</td>
					<?php 
        }
        ?>
			</tr>
		</table>
		<br>
		<?php 
    }
    if (empty($graph["graph_template_id"]) && (isset($_GET["id"]) && is_numeric($_GET["id"]) || isset($_GET["host_id"]) && isset($_GET["graph_template_id"]))) {
        /* ==================== Box: Graph ==================== */
        html_start_box("<strong>" . _("Graph") . "</strong>", "98%", $colors["header_background"], "3", "center", "");
        field_row_header("General Options");
        _graph_field__title("g|title", false, empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__vertical_label("g|vertical_label", false, isset($graph["vertical_label"]) ? $graph["vertical_label"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__image_format("g|image_format", false, isset($graph["image_format"]) ? $graph["image_format"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__export("g|export", false, isset($graph["export"]) ? $graph["export"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__force_rules_legend("g|force_rules_legend", false, isset($graph["force_rules_legend"]) ? $graph["force_rules_legend"] : "");
        field_row_header("Image Size Options");
        _graph_field__height("g|height", false, isset($graph["height"]) ? $graph["height"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__width("g|width", false, isset($graph["width"]) ? $graph["width"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        field_row_header("Grid Options");
        _graph_field__x_grid("g|x_grid", false, isset($graph["x_grid"]) ? $graph["x_grid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__y_grid("g|y_grid", false, isset($graph["y_grid"]) ? $graph["y_grid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__y_grid_alt("g|y_grid_alt", false, isset($graph["y_grid_alt"]) ? $graph["y_grid_alt"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__no_minor("g|no_minor", false, isset($graph["no_minor"]) ? $graph["no_minor"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        field_row_header("Auto Scaling Options");
        _graph_field__auto_scale("g|auto_scale", false, isset($graph["auto_scale"]) ? $graph["auto_scale"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__auto_scale_opts("g|auto_scale_opts", false, isset($graph["auto_scale_opts"]) ? $graph["auto_scale_opts"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__auto_scale_log("g|auto_scale_log", false, isset($graph["auto_scale_log"]) ? $graph["auto_scale_log"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__auto_scale_rigid("g|auto_scale_rigid", false, isset($graph["auto_scale_rigid"]) ? $graph["auto_scale_rigid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__auto_padding("g|auto_padding", false, isset($graph["auto_padding"]) ? $graph["auto_padding"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_auto_padding");
        field_row_header("Fixed Scaling Options");
        _graph_field__upper_limit("g|upper_limit", false, isset($graph["upper_limit"]) ? $graph["upper_limit"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_upper_limit");
        _graph_field__lower_limit("g|lower_limit", false, isset($graph["lower_limit"]) ? $graph["lower_limit"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_lower_limit");
        _graph_field__base_value("g|base_value", false, isset($graph["base_value"]) ? $graph["base_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_base_value");
        field_row_header("Units Display Options");
        _graph_field__unit_value("g|unit_value", false, isset($graph["unit_value"]) ? $graph["unit_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_unit_value");
        _graph_field__unit_length("g|unit_length", false, isset($graph["unit_length"]) ? $graph["unit_length"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_unit_length");
        _graph_field__unit_exponent_value("g|unit_exponent_value", false, isset($graph["unit_exponent_value"]) ? $graph["unit_exponent_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        html_end_box();
    }
    form_hidden_box("action_post", "graph_edit");
    form_save_button("graphs.php");
}
Example #3
0
function script_field_edit() {
	$_script_id = get_get_var_number("script_id");
	$_script_field_id = get_get_var_number("id");
	$_field_type = get_get_var_number("field_type");

	if (empty($_script_field_id)) {
		$header_label = "[new]";
	}else{
		$script_field = api_script_field_get($_script_field_id);

		$header_label = "[edit: " . $script_field["data_name"] . "]";
	}

	$script = api_script_get($_script_id);

	if (($_field_type == SCRIPT_FIELD_TYPE_INPUT) || ($_field_type == SCRIPT_FIELD_TYPE_OUTPUT)) {
		$current_field_type = $_field_type;
	}else{
		$current_field_type = ($script_field["input_output"] == "in" ? SCRIPT_FIELD_TYPE_INPUT : "out");
	}

	if ($current_field_type == SCRIPT_FIELD_TYPE_INPUT) {
		$current_field_type_friendly = _("Input");
	}elseif ($current_field_type == SCRIPT_FIELD_TYPE_OUTPUT) {
		$current_field_type_friendly = _("Output");
	}

	form_start("scripts_fields.php", "form_script_field");

	html_start_box("<strong>$current_field_type_friendly Field</strong> $header_label");

	if ($current_field_type == SCRIPT_FIELD_TYPE_INPUT) {
		field_row_header("Input Options");

		_script_field_field__field_input_type("field_input_type", (isset($script_field["field_input_type"]) ? $script_field["field_input_type"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
		_script_field_field__field_input_value_custom("field_input_value_custom", (isset($script_field["field_input_value"]) ? $script_field["field_input_value"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
		_script_field_field__field_input_value_device("field_input_value_device", (isset($script_field["field_input_value"]) ? $script_field["field_input_value"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
	}

	field_row_header("Field Options");

	if ($current_field_type == SCRIPT_FIELD_TYPE_INPUT) {
		_script_field_field__data_name_input("data_name", $_script_id, (isset($script_field["data_name"]) ? $script_field["data_name"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
	}else if ($current_field_type == SCRIPT_FIELD_TYPE_OUTPUT) {
		_script_field_field__data_name_output("data_name", (isset($script_field["data_name"]) ? $script_field["data_name"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
	}

	_script_field_field__name("name", (isset($script_field["name"]) ? $script_field["name"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));

	if ($current_field_type == SCRIPT_FIELD_TYPE_INPUT) {
		_script_field_field__regexp_match("regexp_match", (isset($script_field["regexp_match"]) ? $script_field["regexp_match"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
		_script_field_field__allow_empty("allow_empty", (isset($script_field["allow_empty"]) ? $script_field["allow_empty"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
	}else if ($current_field_type == SCRIPT_FIELD_TYPE_OUTPUT) {
		_script_field_field__update_rrd("update_rrd", (isset($script_field["update_rrd"]) ? $script_field["update_rrd"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
	}

	_script_field_field__field_input_type_js_update((isset($script_field["field_input_type"]) ? $script_field["field_input_type"] : SCRIPT_FIELD_INPUT_CUSTOM), (empty($_script_field_id) ? 0 : $_script_field_id));

	html_end_box();

	form_hidden_box("id", $_script_field_id, "0");
	form_hidden_box("script_id", $_script_id, "0");
	form_hidden_box("field_type", $current_field_type, "0");
	form_hidden_box("action_post", "script_field_edit");

	form_save_button("scripts.php?action=edit&id=" . $_script_id);
}
Example #4
0
function template_edit()
{
    global $colors;
    if (!empty($_GET["id"])) {
        $graph_template = db_fetch_row("select * from graph_template where id=" . $_GET["id"]);
        $header_label = _("[edit: ") . $graph_template["template_name"] . "]";
    } else {
        $header_label = _("[new]");
    }
    form_start("graph_templates.php", "form_graph_template");
    /* ==================== Box: Graph Template ==================== */
    html_start_box("<strong>" . _("Graph Template") . "</strong> {$header_label}", "98%", $colors["header_background"], "3", "center", "");
    _graph_template_field__template_name("template_name", isset($graph_template) ? $graph_template["template_name"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    html_end_box();
    /* graph item list goes here */
    if (!empty($_GET["id"])) {
        /* ==================== Box: Graph Items ==================== */
        html_start_box("<strong>" . _("Graph Items") . "</strong>", "98%", $colors["header_background"], "3", "center", "graph_templates_items.php?action=edit&graph_template_id=" . $_GET["id"]);
        draw_graph_item_editor($_GET["id"], "graph_template", false);
        html_end_box();
        /* ==================== Box: Graph Item Inputs ==================== */
        html_start_box("<strong>" . _("Graph Item Inputs") . "</strong>", "98%", $colors["header_background"], "3", "center", "graph_templates_inputs.php?action=edit&graph_template_id=" . $_GET["id"]);
        $display_text = array("name" => array(_("Name"), "ASC"));
        html_header_sort($display_text, $sort_column, $sort_direction, 2);
        $template_item_list = db_fetch_assoc("select id,name from graph_template_item_input where graph_template_id=" . $_GET["id"] . " order by name");
        $i = 0;
        if (sizeof($template_item_list) > 0) {
            foreach ($template_item_list as $item) {
                form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], $i);
                $i++;
                ?>
					<td>
						<a class="linkEditMain" href="graph_templates_inputs.php?action=edit&id=<?php 
                print $item["id"];
                ?>
&graph_template_id=<?php 
                print $_GET["id"];
                ?>
"><?php 
                print $item["name"];
                ?>
</a>
					</td>
					<td align="right">
						<a href="graph_templates_inputs.php?action=remove&id=<?php 
                print $item["id"];
                ?>
&graph_template_id=<?php 
                print $_GET["id"];
                ?>
"><img src="<?php 
                print html_get_theme_images_path('delete_icon.gif');
                ?>
" width="10" height="10" border="0" alt="Delete"></a>
					</td>
				</tr>
				<?php 
            }
        } else {
            print "<tr bgcolor='#" . $colors["form_alternate2"] . "'><td colspan='2'><em>" . _("No Inputs") . "</em></td></tr>";
        }
        html_end_box();
    }
    /* ==================== Box: Graph ==================== */
    /* the user clicked the "add item" link. we need to make sure they get redirected back to
     * this page if an error occurs */
    if ($_GET["action"] == "sv_add") {
        form_hidden_box("redirect_sv_add", "x", "");
    }
    html_start_box("<strong>" . _("Graph") . "</strong>", "98%", $colors["header_background"], "3", "center", "");
    field_row_header("General Options");
    _graph_field__title("title", true, empty($_GET["id"]) ? 0 : $_GET["id"], "t_title", isset($graph_template["t_title"]) ? $graph_template["t_title"] : "");
    _graph_field__vertical_label("vertical_label", true, isset($graph_template["vertical_label"]) ? $graph_template["vertical_label"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_vertical_label", isset($graph_template["t_vertical_label"]) ? $graph_template["t_vertical_label"] : "");
    _graph_field__image_format("image_format", isset($graph_template["image_format"]) ? $graph_template["image_format"] : "", true, empty($_GET["id"]) ? 0 : $_GET["id"], "t_image_format", isset($graph_template["t_image_format"]) ? $graph_template["t_image_format"] : "");
    _graph_field__export("export", true, isset($graph_template["export"]) ? $graph_template["export"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_export", isset($graph_template["t_export"]) ? $graph_template["t_export"] : "");
    _graph_field__force_rules_legend("force_rules_legend", true, isset($graph_template["force_rules_legend"]) ? $graph_template["force_rules_legend"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_force_rules_legend", isset($graph_template["t_force_rules_legend"]) ? $graph_template["t_force_rules_legend"] : "");
    field_row_header("Image Size Options");
    _graph_field__height("height", true, isset($graph_template["height"]) ? $graph_template["height"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_height", isset($graph_template["t_height"]) ? $graph_template["t_height"] : "");
    _graph_field__width("width", true, isset($graph_template["width"]) ? $graph_template["width"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_width", isset($graph_template["t_width"]) ? $graph_template["t_width"] : "");
    field_row_header("Grid Options");
    _graph_field__x_grid("x_grid", true, isset($graph_template["x_grid"]) ? $graph_template["x_grid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_x_grid", isset($graph_template["t_x_grid"]) ? $graph_template["t_x_grid"] : "");
    _graph_field__y_grid("y_grid", true, isset($graph_template["y_grid"]) ? $graph_template["y_grid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_y_grid", isset($graph_template["t_y_grid"]) ? $graph_template["t_y_grid"] : "");
    _graph_field__y_grid_alt("y_grid_alt", true, isset($graph_template["y_grid_alt"]) ? $graph_template["y_grid_alt"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_y_grid_alt", isset($graph_template["t_y_grid_alt"]) ? $graph_template["t_y_grid_alt"] : "");
    _graph_field__no_minor("no_minor", true, isset($graph_template["no_minor"]) ? $graph_template["no_minor"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_no_minor", isset($graph_template["t_no_minor"]) ? $graph_template["t_no_minor"] : "");
    field_row_header("Auto Scaling Options");
    _graph_field__auto_scale("auto_scale", true, isset($graph_template["auto_scale"]) ? $graph_template["auto_scale"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_auto_scale", isset($graph_template["t_auto_scale"]) ? $graph_template["t_auto_scale"] : "");
    _graph_field__auto_scale_opts("auto_scale_opts", true, isset($graph_template["auto_scale_opts"]) ? $graph_template["auto_scale_opts"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_auto_scale_opts", isset($graph_template["t_auto_scale_opts"]) ? $graph_template["t_auto_scale_opts"] : "");
    _graph_field__auto_scale_log("auto_scale_log", true, isset($graph_template["auto_scale_log"]) ? $graph_template["auto_scale_log"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_auto_scale_log", isset($graph_template["t_auto_scale_log"]) ? $graph_template["t_auto_scale_log"] : "");
    _graph_field__auto_scale_rigid("auto_scale_rigid", true, isset($graph_template["auto_scale_rigid"]) ? $graph_template["auto_scale_rigid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_auto_scale_rigid", isset($graph_template["t_auto_scale_rigid"]) ? $graph_template["t_auto_scale_rigid"] : "");
    _graph_field__auto_padding("auto_padding", true, isset($graph_template["auto_padding"]) ? $graph_template["auto_padding"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_auto_padding", isset($graph_template["t_auto_padding"]) ? $graph_template["t_auto_padding"] : "");
    field_row_header("Fixed Scaling Options");
    _graph_field__upper_limit("upper_limit", true, isset($graph_template["upper_limit"]) ? $graph_template["upper_limit"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_upper_limit", isset($graph_template["t_upper_limit"]) ? $graph_template["t_upper_limit"] : "");
    _graph_field__lower_limit("lower_limit", true, isset($graph_template["lower_limit"]) ? $graph_template["lower_limit"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_lower_limit", isset($graph_template["t_lower_limit"]) ? $graph_template["t_lower_limit"] : "");
    _graph_field__base_value("base_value", true, isset($graph_template["base_value"]) ? $graph_template["base_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_base_value", isset($graph_template["t_base_value"]) ? $graph_template["t_base_value"] : "");
    field_row_header("Units Display Options");
    _graph_field__unit_value("unit_value", true, isset($graph_template["unit_value"]) ? $graph_template["unit_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_unit_value", isset($graph_template["t_unit_value"]) ? $graph_template["t_unit_value"] : "");
    _graph_field__unit_length("unit_length", true, isset($graph_template["unit_length"]) ? $graph_template["unit_length"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_unit_length", isset($graph_template["t_unit_length"]) ? $graph_template["t_unit_length"] : "");
    _graph_field__unit_exponent_value("unit_exponent_value", true, isset($graph_template["unit_exponent_value"]) ? $graph_template["unit_exponent_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_unit_exponent_value", isset($graph_template["t_unit_exponent_value"]) ? $graph_template["t_unit_exponent_value"] : "");
    html_end_box();
    form_hidden_box("graph_template_id", empty($_GET["id"]) ? 0 : $_GET["id"], "");
    form_hidden_box("action_post", "graph_template_edit");
    form_save_button("graph_templates.php");
}
Example #5
0
function ds_edit()
{
    global $colors, $data_source_types;
    $host_id = 0;
    if (!empty($_GET["id"])) {
        $data_source = db_fetch_row("select * from data_source where id = " . $_GET["id"]);
        $data_source_items = db_fetch_assoc("select * from data_source_item where data_source_id = " . $_GET["id"]);
        if (!empty($data_source["data_template_id"])) {
            $data_template = db_fetch_row("select id,name from data_template where id='" . $data_source["data_template_id"] . "'");
        }
        $header_label = _("[edit: ") . api_data_source_title_get($_GET["id"]) . "]";
        /* get a list of all data input type fields for this data template */
        $data_input_type_fields = array_rekey(db_fetch_assoc("select name,value from data_source_field where data_source_id = " . $data_source["id"]), "name", array("value"));
    } else {
        $header_label = _("[new]");
        $data_input_type_fields = array();
    }
    /* handle debug mode */
    if (isset($_GET["debug"])) {
        if ($_GET["debug"] == "0") {
            kill_session_var("ds_debug_mode");
        } elseif ($_GET["debug"] == "1") {
            $_SESSION["ds_debug_mode"] = true;
        }
    }
    if (!empty($_GET["id"])) {
        ?>
		<table width="98%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php 
        print api_data_source_title_get($_GET["id"]);
        ?>
				</td>
				<td class="textInfo" align="right" valign="top">
					<span style="color: #c16921;">*<a href='data_sources.php?action=edit&id=<?php 
        print isset($_GET["id"]) ? $_GET["id"] : 0;
        ?>
&debug=<?php 
        print isset($_SESSION["ds_debug_mode"]) ? "0" : "1";
        ?>
'>Turn <strong><?php 
        print isset($_SESSION["ds_debug_mode"]) ? "Off" : "On";
        ?>
</strong> Data Source Debug Mode.</a>
				</td>
			</tr>
		</table>
		<br>
		<?php 
    }
    form_start("data_sources.php", "form_data_source");
    /* ==================== Box: Device/Template Selection ==================== */
    html_start_box("<strong>" . _("Device/Template Selection") . "</strong> {$header_label}");
    _data_source_field__data_template_id("data_template_id", isset($data_source) ? $data_source["data_template_id"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    _data_source_field__host_id("host_id", isset($data_source) ? $data_source["host_id"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    html_end_box();
    /* ==================== Box: Supplemental Template Data ==================== */
    /* only display the "inputs" area if we are using a data template for this data source */
    if (!empty($data_source["data_template_id"])) {
        ob_start();
        html_start_box("<strong>" . _("Supplemental Template Data") . "</strong>");
        $num_output_fields = draw_nontemplated_fields_data_input($data_source["data_template_id"], $data_input_type_fields, "dif_|field|", "<strong>" . _("Data Input") . "</strong>", true);
        if ($data_source["data_input_type"] == DATA_INPUT_TYPE_DATA_QUERY) {
            _data_source_input_field__data_query_hdr();
            _data_source_input_field__data_query_field_name("dif_data_query_field_name", $data_input_type_fields["data_query_id"]["value"], isset($data_input_type_fields["data_query_field_name"]["value"]) ? $data_input_type_fields["data_query_field_name"]["value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
            _data_source_input_field__data_query_field_value("dif_data_query_field_value", isset($data_input_type_fields["data_query_field_name"]["value"]) ? $data_input_type_fields["data_query_field_value"]["value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
            $num_output_fields += 2;
        }
        $num_output_fields += draw_nontemplated_fields_data_source($data_source["data_template_id"], $data_source, "ds||field|", "<strong>" . _("Data Source Fields") . "</strong>", true, true);
        $num_output_fields += draw_nontemplated_fields_data_source_item($data_source["data_template_id"], db_fetch_assoc("select * from data_source_item where data_source_id = " . $data_source["id"] . " order by data_source_name"), "dsi||field|||id|", "<strong>" . _("Data Source Item Fields") . "</strong>", true, true);
        html_end_box();
        if ($num_output_fields == 0) {
            ob_end_clean();
        } else {
            ob_end_flush();
        }
    }
    if (empty($data_source["data_template_id"]) && (isset($_GET["id"]) && is_numeric($_GET["id"]) || isset($_GET["host_id"]) && isset($_GET["data_template_id"]))) {
        /* determine current value for 'data_input_type' */
        if (isset($_GET["data_input_type"])) {
            $_data_input_type = $_GET["data_input_type"];
        } else {
            if (isset($data_source["data_input_type"])) {
                $_data_input_type = $data_source["data_input_type"];
            } else {
                $_data_input_type = DATA_INPUT_TYPE_SCRIPT;
            }
        }
        /* ==================== Box: Data Input ==================== */
        html_start_box("<strong>" . _("Data Input") . "</strong>");
        _data_source_input_field__data_input_type("data_input_type", false, $_data_input_type, empty($_GET["id"]) ? 0 : $_GET["id"]);
        /* grab the appropriate data input type form array */
        if ($_data_input_type == DATA_INPUT_TYPE_SCRIPT) {
            $scripts = api_script_list();
            if (sizeof($scripts) > 0) {
                /* determine current value for 'script_id' */
                if (isset($_GET["script_id"]) && is_numeric($_GET["script_id"])) {
                    $_script_id = $_GET["script_id"];
                } else {
                    if (isset($data_input_type_fields["script_id"])) {
                        $_script_id = $data_input_type_fields["script_id"]["value"];
                    } else {
                        /* default to the first item in the script list */
                        $_script_id = $scripts[0]["id"];
                    }
                }
                field_row_header(_("External Script"));
                _data_source_input_field__script_id("dif_script_id", "data_sources.php?action=edit" . (!empty($_GET["id"]) ? "&id=" . $_GET["id"] : "") . "&data_template_id=" . (isset($_GET["data_template_id"]) ? $_GET["data_template_id"] : (isset($data_source) ? $data_source["data_template_id"] : 0)) . "&host_id=" . (isset($_GET["host_id"]) ? $_GET["host_id"] : (isset($data_source) ? $data_source["host_id"] : 0)) . "&data_input_type={$_data_input_type}&script_id=|dropdown_value|", $_script_id);
                /* get each INPUT field for this script */
                $script_input_fields = db_fetch_assoc("select * from data_input_fields where data_input_id = {$_script_id} and input_output='in' order by name");
                if (sizeof($script_input_fields) > 0) {
                    field_row_header(_("Custom Input Fields"));
                    foreach ($script_input_fields as $field) {
                        _data_source_input_field__script("dif_" . $field["data_name"], $field["name"], false, isset($data_input_type_fields[$field["data_name"]]) ? $data_input_type_fields[$field["data_name"]]["value"] : "", "", "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    }
                }
            }
        } else {
            if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) {
                /* determine current value for 'data_query_id' */
                if (isset($_GET["data_query_id"]) && is_numeric($_GET["data_query_id"])) {
                    $_data_query_id = $_GET["data_query_id"];
                } else {
                    if (isset($data_input_type_fields["data_query_id"])) {
                        $_data_query_id = $data_input_type_fields["data_query_id"]["value"];
                    } else {
                        /* default to the first item in the data query list */
                        $_data_query_id = $data_queries[0]["id"];
                    }
                }
                field_row_header(_("Data Query"));
                _data_source_input_field__data_query_id("dif_data_query_id", "data_sources.php?action=edit" . (!empty($_GET["id"]) ? "&id=" . $_GET["id"] : "") . "&data_template_id=" . (isset($_GET["data_template_id"]) ? $_GET["data_template_id"] : (isset($data_source) ? $data_source["data_template_id"] : 0)) . "&host_id=" . (isset($_GET["host_id"]) ? $_GET["host_id"] : (isset($data_source) ? $data_source["host_id"] : 0)) . "&data_input_type={$_data_input_type}&data_query_id=|dropdown_value|", $_data_query_id);
            } else {
                if ($_data_input_type == DATA_INPUT_TYPE_SNMP) {
                    _data_source_input_field__device_hdr_generic();
                    _data_source_input_field__device_snmp_port("dif_snmp_port", false, isset($data_input_type_fields["snmp_port"]) ? $data_input_type_fields["snmp_port"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_snmp_timeout("dif_snmp_timeout", false, isset($data_input_type_fields["snmp_timeout"]) ? $data_input_type_fields["snmp_timeout"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_snmp_version("dif_snmp_version", false, isset($data_input_type_fields["snmp_version"]) ? $data_input_type_fields["snmp_version"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_hdr_snmpv12();
                    _data_source_input_field__device_snmp_community("dif_snmp_community", false, isset($data_input_type_fields["snmp_community"]) ? $data_input_type_fields["snmp_community"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_hdr_snmpv3();
                    _data_source_input_field__device_snmpv3_auth_username("dif_snmpv3_auth_username", false, isset($data_input_type_fields["snmpv3_auth_username"]) ? $data_input_type_fields["snmpv3_auth_username"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_snmpv3_auth_password("dif_snmpv3_auth_password", false, isset($data_input_type_fields["snmpv3_auth_password"]) ? $data_input_type_fields["snmpv3_auth_password"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_snmpv3_auth_protocol("dif_snmpv3_auth_protocol", false, isset($data_input_type_fields["snmpv3_auth_protocol"]) ? $data_input_type_fields["snmpv3_auth_protocol"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_snmpv3_priv_passphrase("dif_snmpv3_priv_passphrase", false, isset($data_input_type_fields["snmpv3_priv_passphrase"]) ? $data_input_type_fields["snmpv3_priv_passphrase"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_snmpv3_priv_protocol("dif_snmpv3_priv_protocol", false, isset($data_input_type_fields["snmpv3_priv_protocol"]) ? $data_input_type_fields["snmpv3_priv_protocol"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                }
            }
        }
        html_end_box();
        /* ==================== Box: Data Source ==================== */
        if (empty($_GET["id"])) {
            $rra_items = array();
        } else {
            $rra_items = api_data_source_rra_item_list($data_source["id"]);
        }
        html_start_box("<strong>" . _("Data Source") . "</strong>");
        _data_source_field__name("ds|name", false, empty($_GET["id"]) ? 0 : $_GET["id"]);
        _data_source_field__rra("preset_rra_id", false, isset($data_source["preset_rra_id"]) ? $data_source["preset_rra_id"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _data_source_field__polling_interval("ds|polling_interval", false, isset($data_source["polling_interval"]) ? $data_source["polling_interval"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _data_source_field__active("ds|active", false, isset($data_source["active"]) ? $data_source["active"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        html_end_box();
        /* ==================== Box: Data Source Item ==================== */
        html_start_box("<strong>" . _("Data Source Item") . "</strong>", empty($_GET["id"]) ? "" : "javascript:document.forms[0].action.value='item_add';submit_redirect(0, '" . htmlspecialchars("data_sources.php?action=item_add&id=" . $_GET["id"]) . "', '')");
        /* the user clicked the "add item" link. we need to make sure they get redirected back to
         * this page if an error occurs */
        if ($_GET["action"] == "item_add") {
            form_hidden_box("redirect_item_add", "x", "");
        }
        /* this allows a "blank" data template item to be displayed when the user wants to create
         * a new one */
        if (!isset($data_source_items) || sizeof($data_source_items) == 0 || $_GET["action"] == "item_add") {
            if (isset($data_source_items)) {
                $next_index = sizeof($data_source_items);
            } else {
                $next_index = 0;
            }
            $data_source_items[$next_index] = array();
        }
        if (sizeof($data_source_items) > 0) {
            if ($_data_input_type == DATA_INPUT_TYPE_SCRIPT) {
                $script_output_fields = db_fetch_assoc("select * from data_input_fields where data_input_id = {$_script_id} and input_output='out' order by name");
                $field_input_description = _("Script Output Field");
            } else {
                if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) {
                    $field_list = api_data_query_field_list($_data_query_id, DATA_QUERY_FIELD_TYPE_OUTPUT);
                    $data_query_output_fields = array();
                    if (sizeof($field_list) > 0) {
                        foreach ($field_list as $field) {
                            $data_query_output_fields[$field["name"]] = $field["name"] . " (" . $field["name_desc"] . ")";
                        }
                    }
                    $field_input_description = _("Data Query Output Field");
                } else {
                    if ($_data_input_type == DATA_INPUT_TYPE_SNMP) {
                        $field_input_description = _("SNMP OID");
                    }
                }
            }
            foreach ($data_source_items as $item) {
                if ($_data_input_type != DATA_INPUT_TYPE_NONE) {
                    ?>
					<tr bgcolor="<?php 
                    print $colors["header_panel_background"];
                    ?>
">
						<td class='textSubHeaderDark' colspan="2">
							<?php 
                    print isset($item["data_source_name"]) ? $item["data_source_name"] : "(" . _("New Data Source Item") . ")";
                    ?>
						</td>
						<td class='textSubHeaderDark' align='right'>
							<?php 
                    if (isset($item["id"]) && sizeof($data_source_items) > 1) {
                        print "[<a href='data_sources.php?action=item_remove&id=" . $item["id"] . "&data_source_id=" . $item["data_source_id"] . "' class='linkOverDark'>remove</a>]\n";
                    }
                    ?>
						</td>
					</tr>
					<tr bgcolor="#e1e1e1">
						<td width="50%" style="border-bottom: 1px solid #a1a1a1;">
							<font class='textEditTitle'>Field Input: <?php 
                    print $field_input_description;
                    ?>
</font><br>
						</td>
						<td style="border-bottom: 1px solid #a1a1a1;" colspan="2">
							<?php 
                    if ($_data_input_type == DATA_INPUT_TYPE_SCRIPT) {
                        form_dropdown("dsi|field_input_value|" . (isset($item["id"]) ? $item["id"] : "0"), $script_output_fields, "name", "data_name", isset($item["field_input_value"]) ? $item["field_input_value"] : "", "", "");
                    } else {
                        if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) {
                            form_dropdown("dsi|field_input_value|" . (isset($item["id"]) ? $item["id"] : "0"), $data_query_output_fields, "", "", isset($item["field_input_value"]) ? $item["field_input_value"] : "", "", "");
                        } else {
                            if ($_data_input_type == DATA_INPUT_TYPE_SNMP) {
                                form_text_box("dsi|field_input_value|" . (isset($item["id"]) ? $item["id"] : "0"), isset($item["field_input_value"]) ? $item["field_input_value"] : "", "", "100", 40, "text", 0);
                            }
                        }
                    }
                    ?>
						</td>
					</tr>
					<?php 
                }
                $_field_id = isset($item["id"]) ? $item["id"] : 0;
                field_reset_row_color();
                field_increment_row_color();
                _data_source_item_field__data_source_name("dsi|data_source_name|{$_field_id}", false, isset($item["data_source_name"]) ? $item["data_source_name"] : "", $_field_id);
                _data_source_item_field__rrd_minimum("dsi|rrd_minimum|{$_field_id}", false, isset($item["rrd_minimum"]) ? $item["rrd_minimum"] : "", $_field_id, "dsi|t_rrd_minimum|{$_field_id}");
                _data_source_item_field__rrd_maximum("dsi|rrd_maximum|{$_field_id}", false, isset($item["rrd_maximum"]) ? $item["rrd_maximum"] : "", $_field_id, "dsi|t_rrd_maximum|{$_field_id}");
                _data_source_item_field__data_source_type("dsi|data_source_type|{$_field_id}", false, isset($item["data_source_type"]) ? $item["data_source_type"] : "", $_field_id, "dsi|t_data_source_type|{$_field_id}");
                _data_source_item_field__rrd_heartbeat("dsi|rrd_heartbeat|{$_field_id}", false, isset($item["rrd_heartbeat"]) ? $item["rrd_heartbeat"] : "", $_field_id, "dsi|t_rrd_heartbeat|{$_field_id}");
            }
        }
        html_end_box();
    }
    /* display the debug mode box if the user wants it */
    if (isset($_SESSION["ds_debug_mode"]) && isset($_GET["id"])) {
        html_start_box("<strong>Data Source Debug</strong>", "98%", $colors["header_background"], "3", "center", "");
        print "<tr><td bgcolor=#'" . $colors["messagebar_background"] . "' <pre>" . rrdtool_function_create($_GET["id"], true, array()) . "</pre></td></tr>";
        html_end_box();
    }
    if (isset($_GET["id"]) || isset($_GET["host_id"]) && isset($_GET["data_template_id"])) {
        form_hidden_box("action_post", "data_source_edit");
    } else {
        form_hidden_box("action_post", "data_source_add");
    }
    form_hidden_box("data_source_id", get_get_var_number("id"));
    form_save_button("data_sources.php");
}
Example #6
0
function _data_source_input_field__device_hdr_snmpv3() {
	require_once(CACTI_BASE_PATH . "/lib/sys/html_form.php");

	field_row_header(_("SNMP (v3 Options)"));
}