当前位置: 首页>>代码示例>>PHP>>正文


PHP push_out_host函数代码示例

本文整理汇总了PHP中push_out_host函数的典型用法代码示例。如果您正苦于以下问题:PHP push_out_host函数的具体用法?PHP push_out_host怎么用?PHP push_out_host使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了push_out_host函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: api_device_save

function api_device_save($id, $host_template_id, $description, $hostname, $snmp_community, $snmp_version, $snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disabled)
{
    /* fetch some cache variables */
    if (empty($id)) {
        $_host_template_id = 0;
    } else {
        $_host_template_id = db_fetch_cell("select host_template_id from host where id={$id}");
    }
    $save["id"] = $id;
    $save["host_template_id"] = form_input_validate($host_template_id, "host_template_id", "^[0-9]+\$", false, 3);
    $save["description"] = form_input_validate($description, "description", "", false, 3);
    $save["hostname"] = form_input_validate($hostname, "hostname", "", false, 3);
    $save["snmp_community"] = form_input_validate($snmp_community, "snmp_community", "", true, 3);
    $save["snmp_version"] = form_input_validate($snmp_version, "snmp_version", "", true, 3);
    $save["snmp_username"] = form_input_validate($snmp_username, "snmp_username", "", true, 3);
    $save["snmp_password"] = form_input_validate($snmp_password, "snmp_password", "", true, 3);
    $save["snmp_port"] = form_input_validate($snmp_port, "snmp_port", "^[0-9]+\$", false, 3);
    $save["snmp_timeout"] = form_input_validate($snmp_timeout, "snmp_timeout", "^[0-9]+\$", false, 3);
    $save["disabled"] = form_input_validate($disabled, "disabled", "", true, 3);
    $host_id = 0;
    if (!is_error_message()) {
        $host_id = sql_save($save, "host");
        if ($host_id) {
            raise_message(1);
            /* push out relavant fields to data sources using this host */
            push_out_host($host_id, 0);
            /* the host substitution cache is now stale; purge it */
            kill_session_var("sess_host_cache_array");
            /* update title cache for graph and data source */
            update_data_source_title_cache_from_host($host_id);
            update_graph_title_cache_from_host($host_id);
        } else {
            raise_message(2);
        }
        /* if the user changes the host template, add each snmp query associated with it */
        if ($host_template_id != $_host_template_id && !empty($host_template_id)) {
            $snmp_queries = db_fetch_assoc("select snmp_query_id from host_template_snmp_query where host_template_id={$host_template_id}");
            if (sizeof($snmp_queries) > 0) {
                foreach ($snmp_queries as $snmp_query) {
                    db_execute("replace into host_snmp_query (host_id,snmp_query_id,reindex_method) values ({$host_id}," . $snmp_query["snmp_query_id"] . "," . DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME . ")");
                    /* recache snmp data */
                    run_data_query($host_id, $snmp_query["snmp_query_id"]);
                }
            }
            $graph_templates = db_fetch_assoc("select graph_template_id from host_template_graph where host_template_id={$host_template_id}");
            if (sizeof($graph_templates) > 0) {
                foreach ($graph_templates as $graph_template) {
                    db_execute("replace into host_graph (host_id,graph_template_id) values ({$host_id}," . $graph_template["graph_template_id"] . ")");
                }
            }
        }
    }
    return $host_id;
}
开发者ID:songchin,项目名称:Cacti,代码行数:54,代码来源:api_device.php

示例2: api_device_save

function api_device_save($id, $host_template_id, $description, $hostname, $snmp_community, $snmp_version,
	$snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disabled,
	$availability_method, $ping_method, $ping_port, $ping_timeout, $ping_retries,
	$notes, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context) {

	/* fetch some cache variables */
	if (empty($id)) {
		$_host_template_id = 0;
	}else{
		$_host_template_id = db_fetch_cell("select host_template_id from host where id=$id");
	}

	$save["id"] = $id;
	$save["host_template_id"]     = form_input_validate($host_template_id, "host_template_id", "^[0-9]+$", false, 3);
	$save["description"]          = form_input_validate($description, "description", "", false, 3);
	$save["hostname"]             = form_input_validate($hostname, "hostname", "", false, 3);
	$save["notes"]                = form_input_validate($notes, "notes", "", true, 3);

	$save["snmp_version"]         = form_input_validate($snmp_version, "snmp_version", "", true, 3);
	$save["snmp_community"]       = form_input_validate($snmp_community, "snmp_community", "", true, 3);

	$save["snmp_username"]        = form_input_validate($snmp_username, "snmp_username", "", true, 3);
	$save["snmp_password"]        = form_input_validate($snmp_password, "snmp_password", "", true, 3);
	$save["snmp_auth_protocol"]   = form_input_validate($snmp_auth_protocol, "snmp_auth_protocol", "", true, 3);
	$save["snmp_priv_passphrase"] = form_input_validate($snmp_priv_passphrase, "snmp_priv_passphrase", "", true, 3);
	$save["snmp_priv_protocol"]   = form_input_validate($snmp_priv_protocol, "snmp_priv_protocol", "", true, 3);
	$save["snmp_context"]         = form_input_validate($snmp_context, "snmp_context", "", true, 3);

	$save["snmp_port"]            = form_input_validate($snmp_port, "snmp_port", "^[0-9]+$", false, 3);
	$save["snmp_timeout"]         = form_input_validate($snmp_timeout, "snmp_timeout", "^[0-9]+$", false, 3);

	$save["disabled"]             = form_input_validate($disabled, "disabled", "", true, 3);

	$save["availability_method"]  = form_input_validate($availability_method, "availability_method", "^[0-9]+$", false, 3);
	$save["ping_method"]          = form_input_validate($ping_method, "ping_method", "^[0-9]+$", false, 3);
	$save["ping_port"]            = form_input_validate($ping_port, "ping_port", "^[0-9]+$", true, 3);
	$save["ping_timeout"]         = form_input_validate($ping_timeout, "ping_timeout", "^[0-9]+$", true, 3);
	$save["ping_retries"]         = form_input_validate($ping_retries, "ping_retries", "^[0-9]+$", true, 3);

	$host_id = 0;

	if (!is_error_message()) {
		$host_id = sql_save($save, "host");

		if ($host_id) {
			raise_message(1);

			/* push out relavant fields to data sources using this host */
			push_out_host($host_id, 0);

			/* the host substitution cache is now stale; purge it */
			kill_session_var("sess_host_cache_array");

			/* update title cache for graph and data source */
			update_data_source_title_cache_from_host($host_id);
			update_graph_title_cache_from_host($host_id);
		}else{
			raise_message(2);
		}

		/* if the user changes the host template, add each snmp query associated with it */
		if (($host_template_id != $_host_template_id) && (!empty($host_template_id))) {
			$snmp_queries = db_fetch_assoc("select snmp_query_id from host_template_snmp_query where host_template_id=$host_template_id");

			if (sizeof($snmp_queries) > 0) {
			foreach ($snmp_queries as $snmp_query) {
				db_replace("host_snmp_query",array("host_id"=>$host_id,"snmp_query_id"=>$snmp_query["snmp_query_id"],"reindex_method"=>DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME),array("host_id","snmp_query_id"),true);

				/* recache snmp data */
				run_data_query($host_id, $snmp_query["snmp_query_id"]);
			}
			}

			$graph_templates = db_fetch_assoc("select graph_template_id from host_template_graph where host_template_id=$host_template_id");

			if (sizeof($graph_templates) > 0) {
			foreach ($graph_templates as $graph_template) {
				db_replace("host_graph",array("host_id"=>$host_id,"graph_template_id"=>$graph_template["graph_template_id"]),array("host_id","graph_template_id"),true);
			}
			}
		}
	}

	return $host_id;
}
开发者ID:songchin,项目名称:Cacti,代码行数:85,代码来源:api_device.php

示例3: form_actions

function form_actions()
{
    global $colors, $device_actions, $fields_host_edit;
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = unserialize(stripslashes($_POST["selected_items"]));
        if ($_POST["drp_action"] == "2") {
            /* Enable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                $data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'");
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        update_poller_cache($data_source["id"], false);
                    }
                }
            }
        } elseif ($_POST["drp_action"] == "3") {
            /* Disable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'");
                db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "4") {
            /* change snmp options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "5") {
            /* Clear Statisitics for Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0',\tavg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = '" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "6") {
            /* change availability options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "1") {
            /* delete */
            if (!isset($_POST["delete_type"])) {
                $_POST["delete_type"] = 2;
            }
            $data_sources_to_act_on = array();
            $graphs_to_act_on = array();
            $devices_to_act_on = array();
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                $data_sources = db_fetch_assoc("select\n\t\t\t\t\tdata_local.id as local_data_id\n\t\t\t\t\tfrom data_local\n\t\t\t\t\twhere " . array_to_sql_or($selected_items, "data_local.host_id"));
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $data_sources_to_act_on[] = $data_source["local_data_id"];
                    }
                }
                if ($_POST["delete_type"] == 2) {
                    $graphs = db_fetch_assoc("select\n\t\t\t\t\t\tgraph_local.id as local_graph_id\n\t\t\t\t\t\tfrom graph_local\n\t\t\t\t\t\twhere " . array_to_sql_or($selected_items, "graph_local.host_id"));
                    if (sizeof($graphs) > 0) {
                        foreach ($graphs as $graph) {
                            $graphs_to_act_on[] = $graph["local_graph_id"];
                        }
                    }
                }
                $devices_to_act_on[] = $selected_items[$i];
            }
            switch ($_POST["delete_type"]) {
                case '1':
                    /* leave graphs and data_sources in place, but disable the data sources */
                    api_data_source_disable_multi($data_sources_to_act_on);
//.........这里部分代码省略.........
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:host.php

示例4: push_out_host

function push_out_host($host_id, $local_data_id = 0, $data_template_id = 0) {
	/* ok here's the deal: first we need to find every data source that uses this host.
	then we go through each of those data sources, finding each one using a data input method
	with "special fields". if we find one, fill it will the data here from this host */

	if (!empty($data_template_id)) {
		$hosts = db_fetch_assoc("select host_id from data_local where data_template_id=$data_template_id group by host_id");

		if (sizeof($hosts) > 0) {
		foreach ($hosts as $host) {
			push_out_host($host["host_id"]);
		}
		}
	}

	if (empty($host_id)) { return 0; }

	/* get all information about this host so we can write it to the data source */
	$host = db_fetch_row("select * from host where id=$host_id");

	$data_sources = db_fetch_assoc("select
		data_template_data.id,
		data_template_data.data_input_id,
		data_template_data.local_data_id,
		data_template_data.local_data_template_data_id
		from data_local,data_template_data
		where " . (empty($local_data_id) ? "data_local.host_id=$host_id" : "data_local.id=$local_data_id") . "
		and data_local.id=data_template_data.local_data_id
		and data_template_data.data_input_id>0");

	/* loop through each matching data source */
	if (sizeof($data_sources) > 0) {
	foreach ($data_sources as $data_source) {
		/* get field information from the data template */
		if (!isset($template_fields{$data_source["local_data_template_data_id"]})) {
			$template_fields{$data_source["local_data_template_data_id"]} = db_fetch_assoc("select
				data_input_data.value,
				data_input_data.t_value,
				data_input_fields.id,
				data_input_fields.type_code
				from data_input_fields left join data_input_data
				on (data_input_fields.id=data_input_data.data_input_field_id and data_input_data.data_template_data_id=" . $data_source["local_data_template_data_id"] . ")
				where data_input_fields.data_input_id=" . $data_source["data_input_id"] . "
				and (data_input_data.t_value='' or data_input_data.t_value is null)
				and data_input_fields.input_output='in'");
		}

		reset($template_fields{$data_source["local_data_template_data_id"]});

		/* loop through each field contained in the data template and push out a host value if:
		 - the field is a valid "host field"
		 - the value of the field is empty
		 - the field is set to 'templated' */
		if (sizeof($template_fields{$data_source["local_data_template_data_id"]})) {
			foreach ($template_fields{$data_source["local_data_template_data_id"]} as $template_field) {
				if ((eregi('^' . VALID_HOST_FIELDS . '$', $template_field["type_code"])) && ($template_field["value"] == "") && ($template_field["t_value"] == "")) {
					db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,value) values (" . $template_field["id"] . "," . $data_source["id"] . ",'" . $host{$template_field["type_code"]} . "')");
				}
			}
		}

		/* make sure to update the poller cache as well */
		update_poller_cache($data_source["local_data_id"], false);
	}
	}
}
开发者ID:songchin,项目名称:Cacti,代码行数:66,代码来源:utility.php

示例5: form_actions

function form_actions()
{
    global $ds_actions;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), "^([a-zA-Z0-9_]+)\$");
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = sanitize_unserialize_selected_items($_POST['selected_items']);
        if ($selected_items != false) {
            if ($_POST["drp_action"] == "1") {
                /* delete */
                if (!isset($_POST["delete_type"])) {
                    $_POST["delete_type"] = 1;
                }
                switch ($_POST["delete_type"]) {
                    case '2':
                        /* delete all graph items tied to this data source */
                        $data_template_rrds = array_rekey(db_fetch_assoc("select id from data_template_rrd where " . array_to_sql_or($selected_items, "local_data_id")), "id", "id");
                        /* loop through each data source item */
                        if (sizeof($data_template_rrds) > 0) {
                            db_execute("delete from graph_templates_item where task_item_id IN (" . implode(",", $data_template_rrds) . ") and local_graph_id > 0");
                        }
                        api_plugin_hook_function('graph_items_remove', $data_template_rrds);
                        break;
                    case '3':
                        /* delete all graphs tied to this data source */
                        $graphs = array_rekey(db_fetch_assoc("select\n\t\t\t\t\t\t\tgraph_templates_graph.local_graph_id\n\t\t\t\t\t\t\tfrom (data_template_rrd,graph_templates_item,graph_templates_graph)\n\t\t\t\t\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\n\t\t\t\t\t\t\tand graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id\n\t\t\t\t\t\t\tand " . array_to_sql_or($selected_items, "data_template_rrd.local_data_id") . "\n\t\t\t\t\t\t\tand graph_templates_graph.local_graph_id > 0\n\t\t\t\t\t\t\tgroup by graph_templates_graph.local_graph_id"), "local_graph_id", "local_graph_id");
                        if (sizeof($graphs) > 0) {
                            api_graph_remove_multi($graphs);
                        }
                        api_plugin_hook_function('graphs_remove', $graphs);
                        break;
                }
                api_data_source_remove_multi($selected_items);
                api_plugin_hook_function('data_source_remove', $selected_items);
            } elseif ($_POST["drp_action"] == "2") {
                /* change graph template */
                input_validate_input_number(get_request_var_post("data_template_id"));
                for ($i = 0; $i < count($selected_items); $i++) {
                    change_data_template($selected_items[$i], $_POST["data_template_id"]);
                }
            } elseif ($_POST["drp_action"] == "3") {
                /* change host */
                input_validate_input_number(get_request_var_post("host_id"));
                for ($i = 0; $i < count($selected_items); $i++) {
                    db_execute("update data_local set host_id=" . $_POST["host_id"] . " where id=" . $selected_items[$i]);
                    push_out_host($_POST["host_id"], $selected_items[$i]);
                    update_data_source_title_cache($selected_items[$i]);
                }
            } elseif ($_POST["drp_action"] == "4") {
                /* duplicate */
                for ($i = 0; $i < count($selected_items); $i++) {
                    duplicate_data_source($selected_items[$i], 0, $_POST["title_format"]);
                }
            } elseif ($_POST["drp_action"] == "5") {
                /* data source -> data template */
                for ($i = 0; $i < count($selected_items); $i++) {
                    data_source_to_data_template($selected_items[$i], $_POST["title_format"]);
                }
            } elseif ($_POST["drp_action"] == "6") {
                /* data source enable */
                for ($i = 0; $i < count($selected_items); $i++) {
                    api_data_source_enable($selected_items[$i]);
                }
            } elseif ($_POST["drp_action"] == "7") {
                /* data source disable */
                for ($i = 0; $i < count($selected_items); $i++) {
                    api_data_source_disable($selected_items[$i]);
                }
            } elseif ($_POST["drp_action"] == "8") {
                /* reapply suggested data source naming */
                for ($i = 0; $i < count($selected_items); $i++) {
                    api_reapply_suggested_data_source_title($selected_items[$i]);
                    update_data_source_title_cache($selected_items[$i]);
                }
            } else {
                api_plugin_hook_function('data_source_action_execute', $_POST['drp_action']);
            }
            api_plugin_hook_function('data_source_action_bottom', array($_POST['drp_action'], $selected_items));
        }
        header("Location: data_sources.php");
        exit;
    }
    /* setup some variables */
    $ds_list = "";
    $i = 0;
    /* loop through each of the graphs selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match("/^chk_([0-9]+)\$/", $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            $ds_list .= "<li>" . htmlspecialchars(get_data_source_title($matches[1])) . "</li>";
            $ds_array[$i] = $matches[1];
            $i++;
        }
    }
    include_once "./include/top_header.php";
    html_start_box("<strong>" . $ds_actions[$_POST["drp_action"]] . "</strong>", "60%", "", "3", "center", "");
//.........这里部分代码省略.........
开发者ID:teddywen,项目名称:cacti,代码行数:101,代码来源:data_sources.php

示例6: form_actions

function form_actions()
{
    global $ds_actions;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST['selected_items'])) {
        $selected_items = unserialize(stripslashes($_POST['selected_items']));
        if ($_POST['drp_action'] == '1') {
            /* delete */
            if (!isset($_POST['delete_type'])) {
                $_POST['delete_type'] = 1;
            }
            switch ($_POST['delete_type']) {
                case '2':
                    /* delete all graph items tied to this data source */
                    $data_template_rrds = array_rekey(db_fetch_assoc('SELECT id FROM data_template_rrd WHERE ' . array_to_sql_or($selected_items, 'local_data_id')), 'id', 'id');
                    /* loop through each data source item */
                    if (sizeof($data_template_rrds) > 0) {
                        db_execute('DELETE FROM graph_templates_item WHERE task_item_id IN (' . implode(',', $data_template_rrds) . ') and local_graph_id > 0');
                    }
                    api_plugin_hook_function('graph_items_remove', $data_template_rrds);
                    break;
                case '3':
                    /* delete all graphs tied to this data source */
                    $graphs = array_rekey(db_fetch_assoc('SELECT
						graph_templates_graph.local_graph_id
						FROM (data_template_rrd,graph_templates_item,graph_templates_graph)
						WHERE graph_templates_item.task_item_id=data_template_rrd.id
						AND graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id
						AND ' . array_to_sql_or($selected_items, 'data_template_rrd.local_data_id') . '
						AND graph_templates_graph.local_graph_id > 0
						GROUP BY graph_templates_graph.local_graph_id'), 'local_graph_id', 'local_graph_id');
                    if (sizeof($graphs) > 0) {
                        api_graph_remove_multi($graphs);
                    }
                    api_plugin_hook_function('graphs_remove', $graphs);
                    break;
            }
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
            }
            api_data_source_remove_multi($selected_items);
            api_plugin_hook_function('data_source_remove', $selected_items);
        } elseif ($_POST['drp_action'] == '2') {
            /* change graph template */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                input_validate_input_number(get_request_var_post('data_template_id'));
                /* ==================================================== */
                change_data_template($selected_items[$i], $_POST['data_template_id']);
            }
        } elseif ($_POST['drp_action'] == '3') {
            /* change host */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                input_validate_input_number(get_request_var_post('host_id'));
                /* ==================================================== */
                db_execute_prepared('UPDATE data_local SET host_id = ? WHERE id = ?', array($_POST['host_id'], $selected_items[$i]));
                push_out_host($_POST['host_id'], $selected_items[$i]);
                update_data_source_title_cache($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '4') {
            /* duplicate */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                duplicate_data_source($selected_items[$i], 0, $_POST['title_format']);
            }
        } elseif ($_POST['drp_action'] == '5') {
            /* data source -> data template */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                data_source_to_data_template($selected_items[$i], $_POST['title_format']);
            }
        } elseif ($_POST['drp_action'] == '6') {
            /* data source enable */
            for ($i = 0; $i < count($selected_items); $i++) {
                api_data_source_enable($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '7') {
            /* data source disable */
            for ($i = 0; $i < count($selected_items); $i++) {
                api_data_source_disable($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '8') {
            /* reapply suggested data source naming */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_reapply_suggested_data_source_title($selected_items[$i]);
//.........这里部分代码省略.........
开发者ID:MrWnn,项目名称:cacti,代码行数:101,代码来源:data_sources.php

示例7: host_new_graphs_save

function host_new_graphs_save()
{
    $selected_graphs_array = unserialize(stripslashes($_POST['selected_graphs_array']));
    /* form an array that contains all of the data on the previous form */
    while (list($var, $val) = each($_POST)) {
        if (preg_match('/^g_(\\d+)_(\\d+)_(\\w+)/', $var, $matches)) {
            /* 1: snmp_query_id, 2: graph_template_id, 3: field_name */
            if (empty($matches[1])) {
                /* this is a new graph from template field */
                $values['cg'][$matches[2]]['graph_template'][$matches[3]] = $val;
            } else {
                /* this is a data query field */
                $values['sg'][$matches[1]][$matches[2]]['graph_template'][$matches[3]] = $val;
            }
        } elseif (preg_match('/^gi_(\\d+)_(\\d+)_(\\d+)_(\\w+)/', $var, $matches)) {
            /* 1: snmp_query_id, 2: graph_template_id, 3: graph_template_input_id, 4:field_name */
            /* ================= input validation ================= */
            input_validate_input_number($matches[3]);
            /* ==================================================== */
            /* we need to find out which graph items will be affected by saving this particular item */
            $item_list = db_fetch_assoc_prepared('SELECT
				graph_template_item_id
				FROM graph_template_input_defs
				WHERE graph_template_input_id = ?', array($matches[3]));
            /* loop through each item affected and update column data */
            if (sizeof($item_list) > 0) {
                foreach ($item_list as $item) {
                    if (empty($matches[1])) {
                        /* this is a new graph from template field */
                        $values['cg'][$matches[2]]['graph_template_item'][$item['graph_template_item_id']][$matches[4]] = $val;
                    } else {
                        /* this is a data query field */
                        $values['sg'][$matches[1]][$matches[2]]['graph_template_item'][$item['graph_template_item_id']][$matches[4]] = $val;
                    }
                }
            }
        } elseif (preg_match('/^d_(\\d+)_(\\d+)_(\\d+)_(\\w+)/', $var, $matches)) {
            /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:field_name */
            if (empty($matches[1])) {
                /* this is a new graph from template field */
                $values['cg'][$matches[2]]['data_template'][$matches[3]][$matches[4]] = $val;
            } else {
                /* this is a data query field */
                $values['sg'][$matches[1]][$matches[2]]['data_template'][$matches[3]][$matches[4]] = $val;
            }
        } elseif (preg_match('/^c_(\\d+)_(\\d+)_(\\d+)_(\\d+)/', $var, $matches)) {
            /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:data_input_field_id */
            if (empty($matches[1])) {
                /* this is a new graph from template field */
                $values['cg'][$matches[2]]['custom_data'][$matches[3]][$matches[4]] = $val;
            } else {
                /* this is a data query field */
                $values['sg'][$matches[1]][$matches[2]]['custom_data'][$matches[3]][$matches[4]] = $val;
            }
        } elseif (preg_match('/^di_(\\d+)_(\\d+)_(\\d+)_(\\d+)_(\\w+)/', $var, $matches)) {
            /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:local_data_template_rrd_id, 5:field_name */
            if (empty($matches[1])) {
                /* this is a new graph from template field */
                $values['cg'][$matches[2]]['data_template_item'][$matches[4]][$matches[5]] = $val;
            } else {
                /* this is a data query field */
                $values['sg'][$matches[1]][$matches[2]]['data_template_item'][$matches[4]][$matches[5]] = $val;
            }
        }
    }
    debug_log_clear('new_graphs');
    while (list($form_type, $form_array) = each($selected_graphs_array)) {
        $current_form_type = $form_type;
        while (list($form_id1, $form_array2) = each($form_array)) {
            /* enumerate information from the arrays stored in post variables */
            if ($form_type == 'cg') {
                $graph_template_id = $form_id1;
            } elseif ($form_type == 'sg') {
                while (list($form_id2, $form_array3) = each($form_array2)) {
                    $snmp_index_array = $form_array3;
                    $snmp_query_array['snmp_query_id'] = $form_id1;
                    $snmp_query_array['snmp_index_on'] = get_best_data_query_index_type($_POST['host_id'], $form_id1);
                    $snmp_query_array['snmp_query_graph_id'] = $form_id2;
                }
                $graph_template_id = db_fetch_cell_prepared('SELECT graph_template_id FROM snmp_query_graph WHERE id = ?', array($snmp_query_array['snmp_query_graph_id']));
            }
            if ($current_form_type == 'cg') {
                $return_array = create_complete_graph_from_template($graph_template_id, $_POST['host_id'], '', $values['cg']);
                debug_log_insert('new_graphs', 'Created graph: ' . get_graph_title($return_array['local_graph_id']));
                /* lastly push host-specific information to our data sources */
                if (sizeof($return_array['local_data_id'])) {
                    # we expect at least one data source associated
                    foreach ($return_array['local_data_id'] as $item) {
                        push_out_host($_POST['host_id'], $item);
                    }
                } else {
                    debug_log_insert('new_graphs', 'ERROR: no Data Source associated. Check Template');
                }
            } elseif ($current_form_type == 'sg') {
                while (list($snmp_index, $true) = each($snmp_index_array)) {
                    $snmp_query_array['snmp_index'] = decode_data_query_index($snmp_index, $snmp_query_array['snmp_query_id'], $_POST['host_id']);
                    $return_array = create_complete_graph_from_template($graph_template_id, $_POST['host_id'], $snmp_query_array, $values['sg'][$snmp_query_array['snmp_query_id']]);
                    debug_log_insert('new_graphs', 'Created graph: ' . get_graph_title($return_array['local_graph_id']));
                    /* lastly push host-specific information to our data sources */
                    if (sizeof($return_array['local_data_id'])) {
//.........这里部分代码省略.........
开发者ID:MrWnn,项目名称:cacti,代码行数:101,代码来源:graphs_new.php

示例8: form_actions

function form_actions()
{
    global $device_actions, $fields_host_edit;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST['selected_items'])) {
        $selected_items = unserialize(stripslashes($_POST['selected_items']));
        if ($_POST['drp_action'] == '2') {
            /* Enable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET disabled = '' WHERE id = ?", array($selected_items[$i]));
                /* update poller cache */
                $data_sources = db_fetch_assoc_prepared('SELECT id FROM data_local WHERE host_id = ?', array($selected_items[$i]));
                $poller_items = $local_data_ids = array();
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $local_data_ids[] = $data_source['id'];
                        $poller_items = array_merge($poller_items, update_poller_cache($data_source['id']));
                    }
                }
                if (sizeof($local_data_ids)) {
                    poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
                }
            }
        } elseif ($_POST['drp_action'] == '3') {
            /* Disable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET disabled='on' WHERE id = ?", array($selected_items[$i]));
                /* update poller cache */
                db_execute_prepared('DELETE FROM poller_item WHERE host_id = ?', array($selected_items[$i]));
                db_execute_prepared('DELETE FROM poller_reindex WHERE host_id = ?', array($selected_items[$i]));
            }
        } elseif ($_POST['drp_action'] == '4') {
            /* change snmp options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute_prepared("UPDATE host SET {$field_name} = ? WHERE id = ?", array($_POST[$field_name], $selected_items[$i]));
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '5') {
            /* Clear Statisitics for Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET min_time = '9.99999', max_time = '0', cur_time = '0', avg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = ?", array($selected_items[$i]));
            }
        } elseif ($_POST['drp_action'] == '6') {
            /* change availability options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute_prepared("UPDATE host SET {$field_name} = ? WHERE id = ?", array($_POST[$field_name], $selected_items[$i]));
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '1') {
            /* delete */
            if (!isset($_POST['delete_type'])) {
                $_POST['delete_type'] = 2;
            }
            $data_sources_to_act_on = array();
            $graphs_to_act_on = array();
            $devices_to_act_on = array();
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                $data_sources = db_fetch_assoc('SELECT
					data_local.id AS local_data_id
					FROM data_local
					WHERE ' . array_to_sql_or($selected_items, 'data_local.host_id'));
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $data_sources_to_act_on[] = $data_source['local_data_id'];
                    }
                }
                if ($_POST['delete_type'] == 2) {
                    $graphs = db_fetch_assoc('SELECT
						graph_local.id AS local_graph_id
//.........这里部分代码省略.........
开发者ID:MrWnn,项目名称:cacti,代码行数:101,代码来源:host.php

示例9: form_save


//.........这里部分代码省略.........
        $save3['rrd_heartbeat'] = form_input_validate($_POST['rrd_heartbeat'], 'rrd_heartbeat', '^[0-9]+$', isset($_POST['t_rrd_heartbeat']) ? true : false, 3);
        $save3['t_data_source_type_id'] = form_input_validate(isset($_POST['t_data_source_type_id']) ? $_POST['t_data_source_type_id'] : '', 't_data_source_type_id', '', true, 3);
        $save3['data_source_type_id'] = form_input_validate($_POST['data_source_type_id'], 'data_source_type_id', '', true, 3);
        $save3['t_data_source_name'] = form_input_validate(isset($_POST['t_data_source_name']) ? $_POST['t_data_source_name'] : '', 't_data_source_name', '', true, 3);
        $save3['data_source_name'] = form_input_validate($_POST['data_source_name'], 'data_source_name', '^[a-zA-Z0-9_]{1,19}$', isset($_POST['t_data_source_name']) ? true : false, 3);
        $save3['t_data_input_field_id'] = form_input_validate(isset($_POST['t_data_input_field_id']) ? $_POST['t_data_input_field_id'] : '', 't_data_input_field_id', '', true, 3);
        $save3['data_input_field_id'] = form_input_validate(isset($_POST['data_input_field_id']) ? $_POST['data_input_field_id'] : '0', 'data_input_field_id', '', true, 3);
        /* ok, first pull out all 'input' values so we know how much to save */
        $input_fields = db_fetch_assoc_prepared("SELECT\n\t\t\tid,\n\t\t\tinput_output,\n\t\t\tregexp_match,\n\t\t\tallow_nulls,\n\t\t\ttype_code,\n\t\t\tdata_name\n\t\t\tFROM data_input_fields\n\t\t\tWHERE data_input_id = ?\n\t\t\tAND input_output = 'in'", array($_POST['data_input_id']));
        /* pass 1 for validation */
        if (sizeof($input_fields) > 0) {
            foreach ($input_fields as $input_field) {
                $form_value = 'value_' . $input_field['data_name'];
                if (isset($_POST[$form_value]) && $input_field['type_code'] == '') {
                    if (isset($_POST['t_' . $form_value]) && $_POST['t_' . $form_value] == 'on') {
                        $not_required = true;
                    } else {
                        if ($input_field['allow_nulls'] == 'on') {
                            $not_required = true;
                        } else {
                            $not_required = false;
                        }
                    }
                    form_input_validate($_POST[$form_value], 'value_' . $input_field['data_name'], $input_field['regexp_match'], $not_required, 3);
                }
            }
        }
        if (!is_error_message()) {
            $data_template_id = sql_save($save1, 'data_template');
            if ($data_template_id) {
                raise_message(1);
            } else {
                raise_message(2);
            }
        }
        if (!is_error_message()) {
            $save2['data_template_id'] = $data_template_id;
            $data_template_data_id = sql_save($save2, 'data_template_data');
            if ($data_template_data_id) {
                raise_message(1);
            } else {
                raise_message(2);
            }
        }
        /* update actual host template information for live hosts */
        if (!is_error_message() && $save2['id'] > 0) {
            db_execute_prepared('UPDATE data_template_data set data_input_id = ? WHERE data_template_id = ?', array($_POST['data_input_id'], $_POST['data_template_id']));
        }
        if (!is_error_message()) {
            $save3['data_template_id'] = $data_template_id;
            $data_template_rrd_id = sql_save($save3, 'data_template_rrd');
            if ($data_template_rrd_id) {
                raise_message(1);
            } else {
                raise_message(2);
            }
        }
        if (!is_error_message()) {
            /* save entries in 'selected rras' field */
            db_execute_prepared('DELETE FROM data_template_data_rra WHERE data_template_data_id = ?', array($data_template_data_id));
            if (isset($_POST['rra_id'])) {
                for ($i = 0; $i < count($_POST['rra_id']); $i++) {
                    /* ================= input validation ================= */
                    input_validate_input_number($_POST['rra_id'][$i]);
                    /* ==================================================== */
                    db_execute_prepared('INSERT INTO data_template_data_rra (rra_id, data_template_data_id)
						VALUES (?, ?)', array($_POST['rra_id'][$i], $data_template_data_id));
                }
            }
            if (!empty($_POST['data_template_id'])) {
                /* push out all data source settings to child data source using this template */
                push_out_data_source($data_template_data_id);
                push_out_data_source_item($data_template_rrd_id);
                db_execute_prepared('DELETE FROM data_input_data WHERE data_template_data_id = ?', array($data_template_data_id));
                reset($input_fields);
                if (sizeof($input_fields) > 0) {
                    foreach ($input_fields as $input_field) {
                        $form_value = 'value_' . $input_field['data_name'];
                        if (isset($_POST[$form_value])) {
                            /* save the data into the 'host_template_data' table */
                            if (isset($_POST['t_value_' . $input_field['data_name']])) {
                                $template_this_item = 'on';
                            } else {
                                $template_this_item = '';
                            }
                            if (!empty($form_value) || !empty($_POST['t_value_' . $input_field['data_name']])) {
                                db_execute_prepared('INSERT INTO data_input_data (data_input_field_id, data_template_data_id, t_value, value)
								values (?, ?, ?, ?)', array($input_field['id'], $data_template_data_id, $template_this_item, trim($_POST[$form_value])));
                            }
                        }
                    }
                }
                /* push out all "custom data" for this data source template */
                push_out_data_source_custom_data($data_template_id);
                push_out_host(0, 0, $data_template_id);
            }
        }
        header('Location: data_templates.php?action=template_edit&id=' . (empty($data_template_id) ? $_POST['data_template_id'] : $data_template_id) . (empty($_POST['current_rrd']) ? '' : '&view_rrd=' . ($_POST['current_rrd'] ? $_POST['current_rrd'] : $data_template_rrd_id)));
    }
}
开发者ID:MrWnn,项目名称:cacti,代码行数:101,代码来源:data_templates.php

示例10: form_save


//.........这里部分代码省略.........
		$save3["t_data_input_field_id"] = form_input_validate((isset($_POST["t_data_input_field_id"]) ? $_POST["t_data_input_field_id"] : ""), "t_data_input_field_id", "", true, 3);
		$save3["data_input_field_id"] = form_input_validate((isset($_POST["data_input_field_id"]) ? $_POST["data_input_field_id"] : "0"), "data_input_field_id", "", true, 3);

		if (!is_error_message()) {
			$data_template_id = sql_save($save1, "data_template");

			if ($data_template_id) {
				raise_message(1);
			}else{
				raise_message(2);
			}
		}

		if (!is_error_message()) {
			$save2["data_template_id"] = $data_template_id;
			$data_template_data_id = sql_save($save2, "data_template_data");

			if ($data_template_data_id) {
				raise_message(1);
			}else{
				raise_message(2);
			}
		}

		/* update actual host template information for live hosts */
		if (!is_error_message()) {
			db_execute("update data_template_data set	data_input_id = '" . $_POST["data_input_id"] . "' where data_template_id = " . $_POST["data_template_id"] . ";");
		}

		if (!is_error_message()) {
			$save3["data_template_id"] = $data_template_id;
			$data_template_rrd_id = sql_save($save3, "data_template_rrd");

			if ($data_template_rrd_id) {
				raise_message(1);
			}else{
				raise_message(2);
			}
		}

		if (!is_error_message()) {
			/* save entries in 'selected rras' field */
			db_execute("delete from data_template_data_rra where data_template_data_id=$data_template_data_id");

			if (isset($_POST["rra_id"])) {
				for ($i=0; ($i < count($_POST["rra_id"])); $i++) {
					db_execute("insert into data_template_data_rra (rra_id,data_template_data_id)
						values (" . $_POST["rra_id"][$i] . ",$data_template_data_id)");
				}
			}

			if (!empty($_POST["data_template_id"])) {
				/* push out all data source settings to child data source using this template */
				push_out_data_source($data_template_data_id);
				push_out_data_source_item($data_template_rrd_id);

				/* ok, first pull out all 'input' values so we know how much to save */
				$input_fields = db_fetch_assoc("select
					id,
					input_output,
					data_name
					from data_input_fields
					where data_input_id=" . $_POST["data_input_id"] . "
					and input_output='in'");

				db_execute("delete from data_input_data where data_template_data_id=$data_template_data_id");

				if (sizeof($input_fields) > 0) {
				foreach ($input_fields as $input_field) {
					$form_value = "value_" . $input_field["data_name"];

					if (isset($_POST[$form_value])) {
						/* save the data into the 'host_template_data' table */
						if (isset($_POST{"t_value_" . $input_field["data_name"]})) {
							$template_this_item = "on";
						}else{
							$template_this_item = "";
						}

						if ((!empty($form_value)) || (!empty($_POST{"t_value_" . $input_field["data_name"]}))) {
							db_execute("insert into data_input_data (data_input_field_id,data_template_data_id,t_value,value)
								values (" . $input_field["id"] . ",$data_template_data_id,'$template_this_item','" . $_POST[$form_value] . "')");
						}
					}
				}
				}

				/* push out all "custom data" for this data source template */
				push_out_data_source_custom_data($data_template_id);
				push_out_host(0, 0, $data_template_id);
			}
		}

		if ((is_error_message()) || (empty($_POST["data_template_id"]))) {
			header("Location: data_templates.php?action=template_edit&id=" . (empty($data_template_id) ? $_POST["data_template_id"] : $data_template_id) . (empty($_POST["current_rrd"]) ? "" : "&view_rrd=" . ($_POST["current_rrd"] ? $_POST["current_rrd"] : $data_template_rrd_id)));
		}else{
			header("Location: data_templates.php");
		}
	}
}
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:data_templates.php

示例11: api_device_save

function api_device_save($id, $host_template_id, $description, $hostname, $snmp_community, $snmp_version, $snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disabled, $availability_method, $ping_method, $ping_port, $ping_timeout, $ping_retries, $notes, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $max_oids, $device_threads)
{
    global $config;
    include_once $config["base_path"] . "/lib/utility.php";
    include_once $config["base_path"] . "/lib/variables.php";
    include_once $config["base_path"] . "/lib/data_query.php";
    /* fetch some cache variables */
    if (empty($id)) {
        $_host_template_id = 0;
    } else {
        $_host_template_id = db_fetch_cell("select host_template_id from host where id={$id}");
    }
    $save["id"] = $id;
    $save["host_template_id"] = form_input_validate($host_template_id, "host_template_id", "^[0-9]+\$", false, 3);
    $save["description"] = form_input_validate($description, "description", "", false, 3);
    $save["hostname"] = form_input_validate(trim($hostname), "hostname", "", false, 3);
    $save["notes"] = form_input_validate($notes, "notes", "", true, 3);
    $save["snmp_version"] = form_input_validate($snmp_version, "snmp_version", "", true, 3);
    $save["snmp_community"] = form_input_validate($snmp_community, "snmp_community", "", true, 3);
    if ($save["snmp_version"] == 3) {
        $save["snmp_username"] = form_input_validate($snmp_username, "snmp_username", "", true, 3);
        $save["snmp_password"] = form_input_validate($snmp_password, "snmp_password", "", true, 3);
        $save["snmp_auth_protocol"] = form_input_validate($snmp_auth_protocol, "snmp_auth_protocol", "", true, 3);
        $save["snmp_priv_passphrase"] = form_input_validate($snmp_priv_passphrase, "snmp_priv_passphrase", "", true, 3);
        $save["snmp_priv_protocol"] = form_input_validate($snmp_priv_protocol, "snmp_priv_protocol", "", true, 3);
        $save["snmp_context"] = form_input_validate($snmp_context, "snmp_context", "", true, 3);
    } else {
        $save["snmp_username"] = "";
        $save["snmp_password"] = "";
    }
    $save["snmp_port"] = form_input_validate($snmp_port, "snmp_port", "^[0-9]+\$", false, 3);
    $save["snmp_timeout"] = form_input_validate($snmp_timeout, "snmp_timeout", "^[0-9]+\$", false, 3);
    $save["disabled"] = form_input_validate($disabled, "disabled", "", true, 3);
    $save["availability_method"] = form_input_validate($availability_method, "availability_method", "^[0-9]+\$", false, 3);
    $save["ping_method"] = form_input_validate($ping_method, "ping_method", "^[0-9]+\$", false, 3);
    $save["ping_port"] = form_input_validate($ping_port, "ping_port", "^[0-9]+\$", true, 3);
    $save["ping_timeout"] = form_input_validate($ping_timeout, "ping_timeout", "^[0-9]+\$", true, 3);
    $save["ping_retries"] = form_input_validate($ping_retries, "ping_retries", "^[0-9]+\$", true, 3);
    $save["max_oids"] = form_input_validate($max_oids, "max_oids", "^[0-9]+\$", true, 3);
    $save["device_threads"] = form_input_validate($device_threads, "device_threads", "^[0-9]+\$", true, 3);
    $save = api_plugin_hook_function('api_device_save', $save);
    $host_id = 0;
    if (!is_error_message()) {
        $host_id = sql_save($save, "host");
        if ($host_id) {
            raise_message(1);
            /* push out relavant fields to data sources using this host */
            push_out_host($host_id, 0);
            /* the host substitution cache is now stale; purge it */
            kill_session_var("sess_host_cache_array");
            /* update title cache for graph and data source */
            update_data_source_title_cache_from_host($host_id);
            update_graph_title_cache_from_host($host_id);
        } else {
            raise_message(2);
        }
        /* if the user changes the host template, add each snmp query associated with it */
        if ($host_template_id != $_host_template_id && !empty($host_template_id)) {
            $snmp_queries = db_fetch_assoc("select snmp_query_id from host_template_snmp_query where host_template_id={$host_template_id}");
            if (sizeof($snmp_queries) > 0) {
                foreach ($snmp_queries as $snmp_query) {
                    db_execute("replace into host_snmp_query (host_id,snmp_query_id,reindex_method) values ({$host_id}," . $snmp_query["snmp_query_id"] . "," . read_config_option("reindex_method") . ")");
                    /* recache snmp data */
                    run_data_query($host_id, $snmp_query["snmp_query_id"]);
                }
            }
            $graph_templates = db_fetch_assoc("select graph_template_id from host_template_graph where host_template_id={$host_template_id}");
            if (sizeof($graph_templates) > 0) {
                foreach ($graph_templates as $graph_template) {
                    db_execute("replace into host_graph (host_id,graph_template_id) values ({$host_id}," . $graph_template["graph_template_id"] . ")");
                    api_plugin_hook_function('add_graph_template_to_host', array("host_id" => $host_id, "graph_template_id" => $graph_template["graph_template_id"]));
                }
            }
        }
    }
    # now that we have the id of the new host, we may plugin postprocessing code
    $save["id"] = $host_id;
    api_plugin_hook_function('api_device_new', $save);
    return $host_id;
}
开发者ID:resmon,项目名称:resmon-cacti,代码行数:80,代码来源:api_device.php

示例12: form_actions

function form_actions()
{
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $rows = db_fetch_assoc("\r\n            SELECT host.id FROM host\r\n                INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'");
        foreach ($rows as $row) {
            $hosts[] = $row["id"];
        }
    }
    /* modify for multi user end */
    global $colors, $device_actions, $fields_host_edit;
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = unserialize(stripslashes($_POST["selected_items"]));
        /* modify for multi user start */
        if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
            for ($i = 0; $i < count($selected_items); $i++) {
                if (!in_array($selected_items[$i], $hosts)) {
                    access_denied();
                }
            }
        }
        /* modify for multi user end */
        if ($_POST["drp_action"] == "2") {
            /* Enable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                /* modify for multi user start */
                if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                    if (db_fetch_cell("SELECT id FROM host WHERE id = '" . $selected_items[$i] . "' AND disabled = 'ps'")) {
                        continue;
                    }
                }
                /* modify for multi user end */
                db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                $data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'");
                $poller_items = array();
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $local_data_ids[] = $data_source["id"];
                        $poller_items = array_merge($poller_items, update_poller_cache($data_source["id"]));
                    }
                }
                poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
            }
        } elseif ($_POST["drp_action"] == "3") {
            /* Disable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                /* modify for multi user start */
                if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                    if (db_fetch_cell("SELECT id FROM host WHERE id = '" . $selected_items[$i] . "' AND disabled = 'ps'")) {
                        continue;
                    }
                }
                /* modify for multi user end */
                db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'");
                db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "4") {
            /* change snmp options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "5") {
            /* Clear Statisitics for Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0',\tavg_time = '0',\r\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\r\n\t\t\t\t\t\twhere id = '" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "6") {
            /* change availability options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
//.........这里部分代码省略.........
开发者ID:resmon,项目名称:resmon-cacti,代码行数:101,代码来源:host.php

示例13: form_actions

function form_actions()
{
    global $colors, $device_actions, $fields_host_edit;
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = unserialize(stripslashes($_POST["selected_items"]));
        if ($_POST["drp_action"] == "2") {
            /* Enable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                $data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'");
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        update_poller_cache($data_source["id"], false);
                    }
                }
            }
        } elseif ($_POST["drp_action"] == "3") {
            /* Disable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'");
                db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "4") {
            /* change snmp options */
            for ($i = 0; $i < count($selected_items); $i++) {
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "6") {
            /* change poller */
            for ($i = 0; $i < count($selected_items); $i++) {
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "7") {
            /* change availability options */
            for ($i = 0; $i < count($selected_items); $i++) {
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "5") {
            /* Clear Statisitics for Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0',\tavg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = '" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "1") {
            /* delete */
            for ($i = 0; $i < count($selected_items); $i++) {
                if (!isset($_POST["delete_type"])) {
                    $_POST["delete_type"] = 2;
                }
                switch ($_POST["delete_type"]) {
                    case '1':
                        /* leave graphs and data_sources in place, but disable the data sources */
                        $data_sources = db_fetch_assoc("select id from data_source where " . array_to_sql_or($selected_items, "host_id"));
                        if (sizeof($data_sources) > 0) {
                            foreach ($data_sources as $data_source) {
                                api_data_source_disable($data_source["id"]);
                            }
                        }
                        break;
                    case '2':
                        /* delete graphs/data sources tied to this device */
                        $data_sources = db_fetch_assoc("select id from data_source where " . array_to_sql_or($selected_items, "host_id"));
                        if (sizeof($data_sources) > 0) {
                            foreach ($data_sources as $data_source) {
                                api_data_source_remove($data_source["id"]);
                            }
                        }
                        $graphs = db_fetch_assoc("select id from graph where " . array_to_sql_or($selected_items, "host_id"));
                        if (sizeof($graphs) > 0) {
                            foreach ($graphs as $graph) {
                                api_graph_remove($graph["id"]);
                            }
                        }
                        break;
                }
                api_device_remove($selected_items[$i]);
            }
        }
        header("Location: devices.php");
//.........这里部分代码省略.........
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:devices.php

示例14: form_actions

function form_actions() {
	global $colors, $device_actions, $fields_host_edit;

	/* if we are to save this form, instead of display it */
	if (isset($_POST["selected_items"])) {
		$selected_items = unserialize(stripslashes($_POST["selected_items"]));

		if ($_POST["drp_action"] == "2") { /* Enable Selected Devices */
			for ($i=0;($i<count($selected_items));$i++) {
				db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'");

				/* update poller cache */
				$data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'");

				if (sizeof($data_sources) > 0) {
					foreach ($data_sources as $data_source) {
						update_poller_cache($data_source["id"], false);
					}
				}
			}
		}elseif ($_POST["drp_action"] == "3") { /* Disable Selected Devices */
			for ($i=0;($i<count($selected_items));$i++) {
				db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'");

				/* update poller cache */
				db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'");
				db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'");
			}
		}elseif ($_POST["drp_action"] == "4") { /* change snmp options */
			for ($i=0;($i<count($selected_items));$i++) {
				reset($fields_host_edit);
				while (list($field_name, $field_array) = each($fields_host_edit)) {
					if (isset($_POST["t_$field_name"])) {
						db_execute("update host set $field_name = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
					}
				}

				push_out_host($selected_items[$i]);
			}
		}elseif ($_POST["drp_action"] == "5") { /* Clear Statisitics for Selected Devices */
			for ($i=0;($i<count($selected_items));$i++) {
				db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0',	avg_time = '0',
						total_polls = '0', failed_polls = '0',	availability = '100.00'
						where id = '" . $selected_items[$i] . "'");
			}
		}elseif ($_POST["drp_action"] == "1") { /* delete */
			for ($i=0; $i<count($selected_items); $i++) {
				if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 2; }

				switch ($_POST["delete_type"]) {
					case '2': /* delete graphs/data sources tied to this device */
						$data_sources = db_fetch_assoc("select
							data_local.id as local_data_id
							from data_local
							where " . array_to_sql_or($selected_items, "data_local.host_id"));

						if (sizeof($data_sources) > 0) {
							foreach ($data_sources as $data_source) {
								api_data_source_remove($data_source["local_data_id"]);
							}
						}

						$graphs = db_fetch_assoc("select
							graph_local.id as local_graph_id
							from graph_local
							where " . array_to_sql_or($selected_items, "graph_local.host_id"));

						if (sizeof($graphs) > 0) {
							foreach ($graphs as $graph) {
								api_graph_remove($graph["local_graph_id"]);
							}
						}

						break;
				}

				api_device_remove($selected_items[$i]);
			}
		}

		header("Location: host.php");
		exit;
	}

	/* setup some variables */
	$host_list = ""; $i = 0;

	/* loop through each of the host templates selected on the previous page and get more info about them */
	while (list($var,$val) = each($_POST)) {
		if (ereg("^chk_([0-9]+)$", $var, $matches)) {
			$host_list .= "<li>" . db_fetch_cell("select description from host where id=" . $matches[1]) . "<br>";
			$host_array[$i] = $matches[1];
		}

		$i++;
	}

	include_once("./include/top_header.php");

	html_start_box("<strong>" . $device_actions{$_POST["drp_action"]} . "</strong>", "60%", $colors["header_panel"], "3", "center", "");
//.........这里部分代码省略.........
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:host.php

示例15: host_new_graphs_save

function host_new_graphs_save()
{
    $selected_graphs_array = unserialize(stripslashes($_POST["selected_graphs_array"]));
    /* form an array that contains all of the data on the previous form */
    while (list($var, $val) = each($_POST)) {
        if (preg_match("/^g_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) {
            /* 1: snmp_query_id, 2: graph_template_id, 3: field_name */
            if (empty($matches[1])) {
                /* this is a new graph from template field */
                $values["cg"][$matches[2]]["graph_template"][$matches[3]] = $val;
            } else {
                /* this is a data query field */
                $values["sg"][$matches[1]][$matches[2]]["graph_template"][$matches[3]] = $val;
            }
        } elseif (preg_match("/^gi_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) {
            /* 1: snmp_query_id, 2: graph_template_id, 3: graph_template_input_id, 4:field_name */
            /* ================= input validation ================= */
            input_validate_input_number($matches[3]);
            /* ==================================================== */
            /* we need to find out which graph items will be affected by saving this particular item */
            $item_list = db_fetch_assoc("select\n\t\t\t\tgraph_template_item_id\n\t\t\t\tfrom graph_template_input_defs\n\t\t\t\twhere graph_template_input_id=" . $matches[3]);
            /* loop through each item affected and update column data */
            if (sizeof($item_list) > 0) {
                foreach ($item_list as $item) {
                    if (empty($matches[1])) {
                        /* this is a new graph from template field */
                        $values["cg"][$matches[2]]["graph_template_item"][$item["graph_template_item_id"]][$matches[4]] = $val;
                    } else {
                        /* this is a data query field */
                        $values["sg"][$matches[1]][$matches[2]]["graph_template_item"][$item["graph_template_item_id"]][$matches[4]] = $val;
                    }
                }
            }
        } elseif (preg_match("/^d_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) {
            /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:field_name */
            if (empty($matches[1])) {
                /* this is a new graph from template field */
                $values["cg"][$matches[2]]["data_template"][$matches[3]][$matches[4]] = $val;
            } else {
                /* this is a data query field */
                $values["sg"][$matches[1]][$matches[2]]["data_template"][$matches[3]][$matches[4]] = $val;
            }
        } elseif (preg_match("/^c_(\\d+)_(\\d+)_(\\d+)_(\\d+)/", $var, $matches)) {
            /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:data_input_field_id */
            if (empty($matches[1])) {
                /* this is a new graph from template field */
                $values["cg"][$matches[2]]["custom_data"][$matches[3]][$matches[4]] = $val;
            } else {
                /* this is a data query field */
                $values["sg"][$matches[1]][$matches[2]]["custom_data"][$matches[3]][$matches[4]] = $val;
            }
        } elseif (preg_match("/^di_(\\d+)_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) {
            /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:local_data_template_rrd_id, 5:field_name */
            if (empty($matches[1])) {
                /* this is a new graph from template field */
                $values["cg"][$matches[2]]["data_template_item"][$matches[4]][$matches[5]] = $val;
            } else {
                /* this is a data query field */
                $values["sg"][$matches[1]][$matches[2]]["data_template_item"][$matches[4]][$matches[5]] = $val;
            }
        }
    }
    debug_log_clear("new_graphs");
    while (list($form_type, $form_array) = each($selected_graphs_array)) {
        $current_form_type = $form_type;
        while (list($form_id1, $form_array2) = each($form_array)) {
            /* enumerate information from the arrays stored in post variables */
            if ($form_type == "cg") {
                $graph_template_id = $form_id1;
            } elseif ($form_type == "sg") {
                while (list($form_id2, $form_array3) = each($form_array2)) {
                    $snmp_index_array = $form_array3;
                    $snmp_query_array["snmp_query_id"] = $form_id1;
                    $snmp_query_array["snmp_index_on"] = get_best_data_query_index_type($_POST["host_id"], $form_id1);
                    $snmp_query_array["snmp_query_graph_id"] = $form_id2;
                }
                $graph_template_id = db_fetch_cell("select graph_template_id from snmp_query_graph where id=" . $snmp_query_array["snmp_query_graph_id"]);
            }
            if ($current_form_type == "cg") {
                $return_array = create_complete_graph_from_template($graph_template_id, $_POST["host_id"], "", $values["cg"]);
                debug_log_insert("new_graphs", "Created graph: " . get_graph_title($return_array["local_graph_id"]));
                /* lastly push host-specific information to our data sources */
                if (sizeof($return_array["local_data_id"])) {
                    # we expect at least one data source associated
                    foreach ($return_array["local_data_id"] as $item) {
                        push_out_host($_POST["host_id"], $item);
                    }
                } else {
                    debug_log_insert("new_graphs", "ERROR: no Data Source associated. Check Template");
                }
            } elseif ($current_form_type == "sg") {
                while (list($snmp_index, $true) = each($snmp_index_array)) {
                    $snmp_query_array["snmp_index"] = decode_data_query_index($snmp_index, $snmp_query_array["snmp_query_id"], $_POST["host_id"]);
                    $return_array = create_complete_graph_from_template($graph_template_id, $_POST["host_id"], $snmp_query_array, $values["sg"][$snmp_query_array["snmp_query_id"]]);
                    debug_log_insert("new_graphs", "Created graph: " . get_graph_title($return_array["local_graph_id"]));
                    /* lastly push host-specific information to our data sources */
                    if (sizeof($return_array["local_data_id"])) {
                        # we expect at least one data source associated
                        foreach ($return_array["local_data_id"] as $item) {
                            push_out_host($_POST["host_id"], $item);
//.........这里部分代码省略.........
开发者ID:teddywen,项目名称:cacti,代码行数:101,代码来源:graphs_new.php


注:本文中的push_out_host函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。