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


PHP array_rekey函数代码示例

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


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

示例1: get_full_script_path

function get_full_script_path($data_source_id) {
	require_once(CACTI_BASE_PATH . "/lib/sys/variable.php");
	require_once(CACTI_BASE_PATH . "/include/data_source/data_source_constants.php");

	$data_input_type = db_fetch_cell("select data_input_type from data_source where id = $data_source_id");

	/* snmp-actions don't have paths */
	if ($data_input_type != DATA_INPUT_TYPE_SCRIPT) {
		return false;
	}

	$data_source_fields = array_rekey(db_fetch_assoc("select name,value from data_source_field where data_source_id = $data_source_id"), "name", "value");

	if (isset($data_source_fields["script_id"])) {
		$script_path = db_fetch_cell("select input_string from data_input where id = " . $data_source_fields["script_id"]);

		/* exclude the manditory script_id field */
		unset($data_source_fields["script_id"]);

		/* substitute user variables */
		while (list($name, $value) = each($data_source_fields)) {
			$script_path = str_replace("<" . $name . ">", $value, $script_path);
		}

		/* substitute path variables */
		$script_path = substitute_path_variables($script_path);

		/* remove all remaining variables */
		$script_path = preg_replace("/(<[A-Za-z0-9_]+>)+/", "", $script_path);

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

示例2: form_save

function form_save()
{
    if (isset($_POST["save_component_input"]) && !is_error_message()) {
        $graph_input_values = array();
        $selected_graph_items = array();
        $save["id"] = $_POST["graph_template_input_id"];
        $save["hash"] = get_hash_graph_template($_POST["graph_template_input_id"], "graph_template_input");
        $save["graph_template_id"] = $_POST["graph_template_id"];
        $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
        $save["description"] = form_input_validate($_POST["description"], "description", "", true, 3);
        $save["column_name"] = form_input_validate($_POST["column_name"], "column_name", "", true, 3);
        if (!is_error_message()) {
            $graph_template_input_id = sql_save($save, "graph_template_input");
            if ($graph_template_input_id) {
                raise_message(1);
                /* list all graph items from the db so we can compare them with the current form */
                $db_selected_graph_item = array_rekey(db_fetch_assoc("select graph_template_item_id from graph_template_input_defs where graph_template_input_id={$graph_template_input_id}"), "graph_template_item_id", "graph_template_item_id");
                /* list all select graph items for use down below */
                while (list($var, $val) = each($_POST)) {
                    if (preg_match("/^i_(\\d+)\$/", $var, $matches)) {
                        /* ================= input validation ================= */
                        input_validate_input_number($matches[1]);
                        /* ==================================================== */
                        $selected_graph_items[$matches[1]] = $matches[1];
                        if (isset($db_selected_graph_item[$matches[1]])) {
                            /* is selected and exists in the db; old item */
                            $old_members[$matches[1]] = $matches[1];
                        } else {
                            /* is selected and does not exist the db; new item */
                            $new_members[$matches[1]] = $matches[1];
                        }
                    }
                }
                if (isset($new_members) && sizeof($new_members) > 0) {
                    while (list($item_id, $item_id) = each($new_members)) {
                        push_out_graph_input($graph_template_input_id, $item_id, isset($new_members) ? $new_members : array());
                    }
                }
                db_execute("delete from graph_template_input_defs where graph_template_input_id={$graph_template_input_id}");
                if (sizeof($selected_graph_items) > 0) {
                    foreach ($selected_graph_items as $graph_template_item_id) {
                        db_execute("insert into graph_template_input_defs (graph_template_input_id,graph_template_item_id)\n\t\t\t\t\t\tvalues ({$graph_template_input_id},{$graph_template_item_id})");
                    }
                }
            } else {
                raise_message(2);
            }
        }
        if (is_error_message()) {
            header("Location: graph_templates_inputs.php?action=input_edit&graph_template_input_id=" . (empty($graph_template_input_id) ? $_POST["graph_template_input_id"] : $graph_template_input_id) . "&graph_template_id=" . $_POST["graph_template_id"]);
            exit;
        } else {
            header("Location: graph_templates.php?action=template_edit&id=" . $_POST["graph_template_id"]);
            exit;
        }
    }
}
开发者ID:BackupTheBerlios,项目名称:odp-svn,代码行数:57,代码来源:graph_templates_inputs.php

示例3: upgrade_to_0_8_8

function upgrade_to_0_8_8()
{
    /* speed up the joins */
    $_columns = array_rekey(db_fetch_assoc("SHOW COLUMNS FROM `poller_item`"), "Field", "Field");
    if (in_array("host_id", $_columns)) {
        db_install_execute("0.8.8", "ALTER TABLE `poller_item` MODIFY COLUMN `host_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0'");
        cacti_log(__FUNCTION__ . " upgrade table poller_item", false, "UPGRADE");
    }
    $_keys = array_rekey(db_fetch_assoc("SHOW KEYS FROM `poller_output`"), "Key_name", "Key_name");
    if (in_array("PRIMARY", $_keys)) {
        db_install_execute("0.8.8", "ALTER TABLE `poller_output` DROP PRIMARY KEY");
        cacti_log(__FUNCTION__ . " table poller_output: dropping old PRIMARY KEY", false, "UPGRADE");
    }
    /* now the KEY we want to create is definitively NOT present 
     * MySQL < 5.00.60 requires a different syntax, this was fixed in MySQL 5.00.60, so take care */
    db_install_execute("0.8.8", "ALTER TABLE `poller_output` ADD PRIMARY KEY (`local_data_id`, `rrd_name`, `time`) /*!50060 USING BTREE */");
    cacti_log(__FUNCTION__ . " upgrade table poller_output", false, "UPGRADE");
    /* speed up user management */
    $_keys = array_rekey(db_fetch_assoc("SHOW KEYS FROM `user_log`"), "Key_name", "Key_name");
    if (!in_array("user_id", $_keys)) {
        db_install_execute("0.8.8", "ALTER TABLE `user_log` ADD KEY `user_id` (`user_id`)");
        cacti_log(__FUNCTION__ . " upgrade table user_log", false, "UPGRADE");
    }
    /* Plugin Architecture
     * be prepared to find those data already present
     * in case of upgrade of a cacti+PIA installation */
    $sql = "CREATE TABLE IF NOT EXISTS `plugin_config` (\n\t\t\t\t`id` \t\tint(8) unsigned NOT NULL auto_increment,\n\t\t\t\t`directory` varchar(32) \tNOT NULL default '',\n\t\t\t\t`name` \t\tvarchar(64) \tNOT NULL default '',\n\t\t\t\t`status`\ttinyint(2) \t\tNOT NULL default 0,\n\t\t\t\t`author`\tvarchar(64) \tNOT NULL default '',\n\t\t\t\t`webpage`\tvarchar(255)  \tNOT NULL default '',\n\t\t\t\t`version`\tvarchar(8) \t\tNOT NULL default '',\n\t\t\t\tPRIMARY KEY  (`id`),\n\t\t\t\tKEY `status` (`status`),\n\t\t\t\tKEY `directory` (`directory`)\n\t\t\t\t) ENGINE=MyISAM COMMENT='Plugin Configuration'";
    db_install_execute("0.8.8", $sql);
    cacti_log(__FUNCTION__ . " install table plugin_config", false, "UPGRADE");
    $sql = "CREATE TABLE IF NOT EXISTS `plugin_db_changes` (\n\t\t\t\t`id` \t\tint(10) unsigned NOT NULL auto_increment,\n\t\t\t\t`plugin` \tvarchar(16) \tNOT NULL default '',\n\t\t\t\t`table` \tvarchar(64) \tNOT NULL default '',\n\t\t\t\t`column`\tvarchar(64) \tNOT NULL default '',\n\t\t\t\t`method` \tvarchar(16) \tNOT NULL default '',\n\t\t\t\tPRIMARY KEY  (`id`),\n\t\t\t\tKEY `plugin` (`plugin`),\n\t\t\t\tKEY `method` (`method`)\n\t\t\t\t) ENGINE=MyISAM COMMENT='Plugin Database Changes'";
    db_install_execute("0.8.8", $sql);
    cacti_log(__FUNCTION__ . " install table plugin_db_changes", false, "UPGRADE");
    $sql = "CREATE TABLE IF NOT EXISTS `plugin_hooks` (\n\t\t\t\t`id` \t\tint(8) unsigned NOT NULL auto_increment,\n\t\t\t\t`name` \t\tvarchar(32) \tNOT NULL default '',\n\t\t\t\t`hook` \t\tvarchar(64) \tNOT NULL default '',\n\t\t\t\t`file`\t\tvarchar(255) \tNOT NULL default '',\n\t\t\t\t`function` \tvarchar(128) \tNOT NULL default '',\n\t\t\t\t`status`\tint(8) \t\t\tNOT NULL default 0,\n\t\t\t\tPRIMARY KEY  (`id`),\n\t\t\t\tKEY `hook` (`hook`),\n\t\t\t\tKEY `status` (`status`)\n\t\t\t\t) ENGINE=MyISAM COMMENT='Plugin Hooks'";
    db_install_execute("0.8.8", $sql);
    cacti_log(__FUNCTION__ . " install table plugin_hooks", false, "UPGRADE");
    $sql = "CREATE TABLE IF NOT EXISTS `plugin_realms` (\n\t\t\t\t`id` \t\tint(8) unsigned NOT NULL auto_increment,\n\t\t\t\t`plugin` \tvarchar(32) \tNOT NULL default '',\n\t\t\t\t`file`\t\ttext\t\t \tNOT NULL,\n\t\t\t\t`display` \tvarchar(64) \tNOT NULL default '',\n\t\t\t\tPRIMARY KEY  (`id`),\n\t\t\t\tKEY `plugin` (`plugin`)\n\t\t\t\t) ENGINE=MyISAM COMMENT='Plugin Realms'";
    db_install_execute("0.8.8", $sql);
    cacti_log(__FUNCTION__ . " install table plugin_realms", false, "UPGRADE");
    /* fill initial data into plugin tables
     * be prepared to find those data already present
     * in case of upgrade of a cacti+PIA installation */
    db_install_execute("0.8.8", "REPLACE INTO `plugin_realms` VALUES (1, 'internal', 'plugins.php', 'Plugin Management')");
    db_install_execute("0.8.8", "REPLACE INTO `plugin_hooks` VALUES (1, 'internal', 'config_arrays', '', 'plugin_config_arrays', 1)");
    db_install_execute("0.8.8", "REPLACE INTO `plugin_hooks` VALUES (2, 'internal', 'draw_navigation_text', '', 'plugin_draw_navigation_text', 1)");
    /* allow admin user to access Plugin Management */
    db_install_execute("0.8.8", "REPLACE INTO user_auth_realm VALUES (101,1)");
    /* create index on data_template_data on data_input_id */
    $_keys = array_rekey(db_fetch_assoc("SHOW KEYS FROM `data_template_data`"), "Key_name", "Key_name");
    if (!in_array("data_input_id", $_keys)) {
        db_install_execute("0.8.8", "ALTER TABLE `data_template_data` ADD KEY `data_input_id` (`data_input_id`)");
        cacti_log(__FUNCTION__ . " upgrade table data_template_data", false, "UPGRADE");
    }
}
开发者ID:andrei1489,项目名称:cacti,代码行数:53,代码来源:0_8_7i_to_0_8_8.php

示例4: upgrade_to_0_8_7h

function upgrade_to_0_8_7h()
{
    global $config;
    require_once $config["base_path"] . "/lib/poller.php";
    /* speed up the reindexing */
    $_columns = array_rekey(db_fetch_assoc("SHOW COLUMNS FROM host_snmp_cache"), "Field", "Field");
    if (!in_array("present", $_columns)) {
        db_install_execute("0.8.7h", "ALTER TABLE host_snmp_cache ADD COLUMN present tinyint NOT NULL DEFAULT '1' AFTER `oid`");
        db_install_execute("0.8.7h", "ALTER TABLE host_snmp_cache ADD INDEX present (present)");
        cacti_log(__FUNCTION__ . " upgrade table host_snmp_cache", false, "UPGRADE");
    }
    $_columns = array_rekey(db_fetch_assoc("SHOW COLUMNS FROM poller_item"), "Field", "Field");
    if (!in_array("present", $_columns)) {
        db_install_execute("0.8.7h", "ALTER TABLE poller_item ADD COLUMN present tinyint NOT NULL DEFAULT '1' AFTER `action`");
        db_install_execute("0.8.7h", "ALTER TABLE poller_item ADD INDEX present (present)");
        cacti_log(__FUNCTION__ . " upgrade table poller_item", false, "UPGRADE");
    }
    $_columns = array_rekey(db_fetch_assoc("SHOW COLUMNS FROM poller_reindex"), "Field", "Field");
    if (!in_array("present", $_columns)) {
        db_install_execute("0.8.7h", "ALTER TABLE poller_reindex ADD COLUMN present tinyint NOT NULL DEFAULT '1' AFTER `action`");
        db_install_execute("0.8.7h", "ALTER TABLE poller_reindex ADD INDEX present (present)");
        cacti_log(__FUNCTION__ . " upgrade table poller_reindex", false, "UPGRADE");
    }
    $_columns = array_rekey(db_fetch_assoc("SHOW COLUMNS FROM host"), "Field", "Field");
    if (!in_array("device_threads", $_columns)) {
        db_install_execute("0.8.7h", "ALTER TABLE host ADD COLUMN device_threads tinyint(2) unsigned NOT NULL DEFAULT '1' AFTER max_oids;");
        cacti_log(__FUNCTION__ . " upgrade table host", false, "UPGRADE");
    }
    $_keys = array_rekey(db_fetch_assoc("SHOW KEYS FROM data_template_rrd"), "Key_name", "Key_name");
    if (!in_array("duplicate_dsname_contraint", $_keys)) {
        db_install_execute("0.8.7h", "ALTER TABLE `data_template_rrd` ADD UNIQUE INDEX `duplicate_dsname_contraint` (`local_data_id`, `data_source_name`, `data_template_id`)");
        cacti_log(__FUNCTION__ . " upgrade table data_template_rrd", false, "UPGRADE");
    }
    /* update the reindex cache, as we now introduced more options for "index count changed" */
    $command_string = read_config_option("path_php_binary");
    $extra_args = "-q \"" . $config["base_path"] . "/cli/poller_reindex_hosts.php\" --id=all";
    exec_background($command_string, "{$extra_args}");
    cacti_log(__FUNCTION__ . " running {$command_string} {$extra_args}", false, "UPGRADE");
}
开发者ID:andrei1489,项目名称:cacti,代码行数:39,代码来源:0_8_7g_to_0_8_7h.php

示例5: api_plugin_user_realm_auth

function api_plugin_user_realm_auth($filename = '')
{
    global $user_realms, $user_auth_realms, $user_auth_realm_filenames;
    /* list all realms that this user has access to */
    if (!isset($user_realms)) {
        if (read_config_option('global_auth') == 'on' || read_config_option('auth_method') != 0) {
            $user_realms = db_fetch_assoc("select realm_id from user_auth_realm where user_id=" . $_SESSION["sess_user_id"], false);
            $user_realms = array_rekey($user_realms, "realm_id", "realm_id");
        } else {
            $user_realms = $user_auth_realms;
        }
    }
    if ($filename != '' && isset($user_auth_realm_filenames[basename($filename)])) {
        if (isset($user_realms[$user_auth_realm_filenames[basename($filename)]])) {
            return TRUE;
        }
    }
    return FALSE;
}
开发者ID:resmon,项目名称:resmon-cacti,代码行数:19,代码来源:plugins.php

示例6: graphs


//.........这里部分代码省略.........
                        }
                        $sql_query .= ' FROM host_snmp_cache
						WHERE host_id=' . $host['id'] . '
						AND snmp_query_id=' . $snmp_query['id'] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index\n\t\t\t\t\t\t{$sql_order}\n\t\t\t\t\t\tLIMIT " . $row_limit * ($page - 1) . ',' . $row_limit;
                        $rows_query = 'SELECT host_id, snmp_query_id, snmp_index
						FROM host_snmp_cache
						WHERE host_id=' . $host['id'] . '
						AND snmp_query_id=' . $snmp_query['id'] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index";
                        $snmp_query_indexes = db_fetch_assoc($sql_query);
                        $total_rows = sizeof(db_fetch_assoc($rows_query));
                        if (($page - 1) * $row_limit > $total_rows) {
                            $page = 1;
                            $_REQUEST['page' . $query['id']] = $page;
                            load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1');
                        }
                        $nav = html_nav_bar('graphs_new.php', MAX_DISPLAY_PAGES, $page, $row_limit, $total_rows, 15, 'Items', 'page' . $snmp_query['id']);
                        print $nav;
                        while (list($field_name, $field_array) = each($xml_array['fields'])) {
                            if ($field_array['direction'] == 'input' && sizeof($field_names)) {
                                foreach ($field_names as $row) {
                                    if ($row['field_name'] == $field_name) {
                                        $html_dq_header .= "<td class='tableSubHeaderColumn'>" . $field_array['name'] . "</td>\n";
                                        break;
                                    }
                                }
                            }
                        }
                        if (!sizeof($snmp_query_indexes)) {
                            print "<tr class='odd'><td>This Data Query returned 0 rows, perhaps there was a problem executing this\n\t\t\t\t\t\t\tData Query. You can <a href='" . htmlspecialchars('host.php?action=query_verbose&id=' . $snmp_query['id'] . '&host_id=' . $host['id']) . "'>run this Data Query in debug mode</a> to get more information.</td></tr>\n";
                        } else {
                            print "<tr class='tableHeader'>\n\t\t\t\t\t\t\t\t{$html_dq_header}\n\t\t\t\t\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $snmp_query['id'] . "' title='Select All' onClick='SelectAll(\"sg_" . $snmp_query['id'] . "\",this.checked)'></td>\n\n\t\t\t\t\t\t\t</tr>\n";
                        }
                        $row_counter = 0;
                        $column_counter = 0;
                        $fields = array_rekey($field_names, 'field_name', 'field_name');
                        if (sizeof($snmp_query_indexes) > 0) {
                            foreach ($snmp_query_indexes as $row) {
                                $query_row = $snmp_query['id'] . '_' . encode_data_query_index($row['snmp_index']);
                                print "<tr id='line{$query_row}' class='selectable " . ($row_counter % 2 == 0 ? 'odd' : 'even') . "'>";
                                $i++;
                                $column_counter = 0;
                                reset($xml_array['fields']);
                                while (list($field_name, $field_array) = each($xml_array['fields'])) {
                                    if ($field_array['direction'] == 'input') {
                                        if (in_array($field_name, $fields)) {
                                            if (isset($row[$field_name])) {
                                                print "<td><span id='text{$query_row}" . '_' . $column_counter . "'>" . (strlen($_REQUEST['filter']) ? preg_replace('/(' . preg_quote($_REQUEST['filter']) . ')/i', "<span class='filteredValue'>\\1</span>", $row[$field_name]) : $row[$field_name]) . '</span></td>';
                                            } else {
                                                print "<td><span id='text{$query_row}" . '_' . $column_counter . "'></span></td>";
                                            }
                                            $column_counter++;
                                        }
                                    }
                                }
                                print "<td class='checkbox' align='right'>";
                                print "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}'>";
                                print '</td>';
                                print "</tr>\n";
                                $row_counter++;
                            }
                        }
                        if ($total_rows > $row_limit) {
                            print $nav;
                        }
                    } else {
                        print "<tr class='odd'><td class='textError'>Search Returned no Rows.</td></tr>\n";
                    }
                } else {
                    print "<tr class='odd'><td class='textError'>Error in data query.</td></tr>\n";
                }
                print '</table>';
                /* draw the graph template drop down here */
                $data_query_graphs = db_fetch_assoc_prepared('SELECT snmp_query_graph.id, snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id = ? ORDER BY snmp_query_graph.name', array($snmp_query['id']));
                if (sizeof($data_query_graphs) == 1) {
                    echo "<input type='hidden' id='sgg_" . $snmp_query['id'] . "' name='sgg_" . $snmp_query['id'] . "' value='" . $data_query_graphs[0]['id'] . "'>\n";
                } elseif (sizeof($data_query_graphs) > 1) {
                    print "\t<table align='center' width='100%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td width='100%' valign='middle'>\n\t\t\t\t\t\t\t\t<img src='images/arrow.gif' align='absmiddle' alt=''>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td style='white-space:nowrap;font-style: italic;'' align='right'>\n\t\t\t\t\t\t\t\tSelect a Graph Type to Create\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t\t\t<select name='sgg_" . $snmp_query['id'] . "' id='sgg_" . $snmp_query['id'] . "' onChange='dqUpdateDeps(" . $snmp_query['id'] . ',' . (isset($column_counter) ? $column_counter : '') . ");'>\n\t\t\t\t\t\t\t\t\t";
                    html_create_list($data_query_graphs, 'name', 'id', '0');
                    print "\n\t\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n";
                }
                print '<br>';
                $script .= 'dqUpdateDeps(' . $snmp_query['id'] . ',' . $num_visible_fields . ");\n";
            }
        }
    }
    if (strlen($script)) {
        $script .= "</script>\n";
        print $script;
    }
    form_hidden_box('save_component_graph', '1', '');
    if (!empty($_REQUEST['host_id'])) {
        form_hidden_box('host_id', $host['id'], '0');
        form_hidden_box('host_template_id', $host['host_template_id'], '0');
    }
    if (isset($_SERVER['HTTP_REFERER']) && !substr_count($_SERVER['HTTP_REFERER'], 'graphs_new')) {
        $_REQUEST['returnto'] = basename($_SERVER['HTTP_REFERER']);
    }
    load_current_session_value('returnto', 'sess_graphs_new_returnto', '');
    form_save_button($_REQUEST['returnto']);
}
开发者ID:MrWnn,项目名称:cacti,代码行数:101,代码来源:graphs_new.php

示例7: switch

include_once $config["base_path"] . "/lib/functions.php";
/* Now take an action */
switch ($action) {
    case "get-graphs":
        displayHostGraphs(host_id($ip), TRUE);
        break;
    case "drop-device":
        $host_id = host_id($ip);
        if ($delete_graphs) {
            // code copied & pasted from version 0.8.8a
            // cacti/site/lib/host.php and cacti/site/graphs.php
            // unfortunately no api function for this yet
            $graphs = db_fetch_assoc("select\n\t\t\tgraph_local.id as local_graph_id\n\t\t\tfrom graph_local\n\t\t\twhere graph_local.host_id=" . $host_id);
            if (sizeof($graphs) > 0) {
                foreach ($graphs as $graph) {
                    $data_sources = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id\n\t\t\t\t\tFROM (data_template_rrd, data_template_data, graph_templates_item)\n\t\t\t\t\tWHERE graph_templates_item.task_item_id=data_template_rrd.id\n\t\t\t\t\tAND data_template_rrd.local_data_id=data_template_data.local_data_id\n\t\t\t\t\tAND graph_templates_item.local_graph_id=" . $graph["local_graph_id"] . "\n\t\t\t\t\tAND data_template_data.local_data_id > 0"), "local_data_id", "local_data_id");
                    if (sizeof($data_sources)) {
                        api_data_source_remove_multi($data_sources);
                    }
                    api_graph_remove($graph["local_graph_id"]);
                }
            }
        }
        api_device_remove($host_id);
        if (host_id($ip, 1)) {
            die("Failed to remove hostname {$ip}");
        }
        exit(0);
        /*
        case "get-device":
        	echo host_id($ip);
开发者ID:carriercomm,项目名称:Freeside,代码行数:31,代码来源:freeside_cacti.php

示例8: draw_edit_control

function draw_edit_control($field_name, &$field_array)
{
    switch ($field_array["method"]) {
        case 'textbox':
            form_text_box($field_name, $field_array["value"], isset($field_array["default"]) ? $field_array["default"] : "", $field_array["max_length"], isset($field_array["size"]) ? $field_array["size"] : "40", "text", isset($field_array["form_id"]) ? $field_array["form_id"] : "");
            break;
        case 'filepath':
            form_filepath_box($field_name, $field_array["value"], isset($field_array["default"]) ? $field_array["default"] : "", $field_array["max_length"], isset($field_array["size"]) ? $field_array["size"] : "40", "text", isset($field_array["form_id"]) ? $field_array["form_id"] : "");
            break;
        case 'dirpath':
            form_dirpath_box($field_name, $field_array["value"], isset($field_array["default"]) ? $field_array["default"] : "", $field_array["max_length"], isset($field_array["size"]) ? $field_array["size"] : "40", "text", isset($field_array["form_id"]) ? $field_array["form_id"] : "");
            break;
        case 'textbox_password':
            form_text_box($field_name, $field_array["value"], isset($field_array["default"]) ? $field_array["default"] : "", $field_array["max_length"], isset($field_array["size"]) ? $field_array["size"] : "40", "password");
            print "<br>";
            form_text_box($field_name . "_confirm", $field_array["value"], isset($field_array["default"]) ? $field_array["default"] : "", $field_array["max_length"], isset($field_array["size"]) ? $field_array["size"] : "40", "password");
            break;
        case 'textarea':
            form_text_area($field_name, $field_array["value"], $field_array["textarea_rows"], $field_array["textarea_cols"], isset($field_array["default"]) ? $field_array["default"] : "", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
            break;
        case 'drop_array':
            form_dropdown($field_name, $field_array["array"], "", "", $field_array["value"], isset($field_array["none_value"]) ? $field_array["none_value"] : "", isset($field_array["default"]) ? $field_array["default"] : "", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
            break;
        case 'drop_sql':
            form_dropdown($field_name, db_fetch_assoc($field_array["sql"]), "name", "id", $field_array["value"], isset($field_array["none_value"]) ? $field_array["none_value"] : "", isset($field_array["default"]) ? $field_array["default"] : "", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
            break;
        case 'drop_multi':
            form_multi_dropdown($field_name, $field_array["array"], db_fetch_assoc($field_array["sql"]), "id", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
            break;
        case 'drop_multi_rra':
            form_multi_dropdown($field_name, array_rekey(db_fetch_assoc("select id,name from rra order by timespan"), "id", "name"), empty($field_array["form_id"]) ? db_fetch_assoc($field_array["sql_all"]) : db_fetch_assoc($field_array["sql"]), "id", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
            break;
        case 'drop_tree':
            grow_dropdown_tree($field_array["tree_id"], $field_name, $field_array["value"]);
            break;
        case 'drop_color':
            form_color_dropdown($field_name, $field_array["value"], "None", isset($field_array["default"]) ? $field_array["default"] : "", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
            break;
        case 'checkbox':
            form_checkbox($field_name, $field_array["value"], $field_array["friendly_name"], isset($field_array["default"]) ? $field_array["default"] : "", isset($field_array["form_id"]) ? $field_array["form_id"] : "", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
            break;
        case 'checkbox_group':
            while (list($check_name, $check_array) = each($field_array["items"])) {
                form_checkbox($check_name, $check_array["value"], $check_array["friendly_name"], isset($check_array["default"]) ? $check_array["default"] : "", isset($check_array["form_id"]) ? $check_array["form_id"] : "", isset($field_array["class"]) ? $field_array["class"] : "", isset($check_array["on_change"]) ? $check_array["on_change"] : (isset($field_array["on_change"]) ? $field_array["on_change"] : ""));
                print "<br>";
            }
            break;
        case 'radio':
            while (list($radio_index, $radio_array) = each($field_array["items"])) {
                form_radio_button($field_name, $field_array["value"], $radio_array["radio_value"], $radio_array["radio_caption"], isset($field_array["default"]) ? $field_array["default"] : "", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
                print "<br>";
            }
            break;
        case 'custom':
            print $field_array["value"];
            break;
        case 'template_checkbox':
            print "<em>" . html_boolean_friendly($field_array["value"]) . "</em>";
            form_hidden_box($field_name, $field_array["value"], "");
            break;
        case 'template_drop_array':
            print "<em>" . $field_array["array"][$field_array["value"]] . "</em>";
            form_hidden_box($field_name, $field_array["value"], "");
            break;
        case 'template_drop_multi_rra':
            $items = db_fetch_assoc($field_array["sql_print"]);
            if (sizeof($items) > 0) {
                foreach ($items as $item) {
                    print htmlspecialchars($item["name"], ENT_QUOTES) . "<br>";
                }
            }
            break;
        case 'font':
            form_font_box($field_name, $field_array["value"], isset($field_array["default"]) ? $field_array["default"] : "", $field_array["max_length"], isset($field_array["size"]) ? $field_array["size"] : "40", "text", isset($field_array["form_id"]) ? $field_array["form_id"] : "");
            break;
        case 'file':
            form_file($field_name, isset($field_array["size"]) ? $field_array["size"] : "40");
            break;
        default:
            print "<em>" . htmlspecialchars($field_array["value"], ENT_QUOTES) . "</em>";
            form_hidden_box($field_name, $field_array["value"], "");
            break;
    }
}
开发者ID:teddywen,项目名称:cacti,代码行数:84,代码来源:html_form.php

示例9: host_new_graphs

function host_new_graphs($selected_graphs = "", $map_id_to_index = "")
{
    global $colors;
    if (!is_array($selected_graphs)) {
        $selected_graphs = array();
        $map_id_to_index = array();
        /* summarize the 'create graph from host template/snmp index' stuff into an array */
        while (list($name, $value) = each($_POST)) {
            if (substr($name, 0, 3) == "cg_" && $name != "cg_g") {
                $matches = explode("_", $name);
                /* uniquely identify this yet to be created graph */
                $uniq_id = md5("gt" . $matches[1]);
                $map_id_to_index["gt"][$matches[1]][] = $uniq_id;
                $selected_graphs[$uniq_id]["graph_template_id"] = $matches[1];
            } else {
                if (substr($name, 0, 3) == "sg_") {
                    $matches = explode("_", $name);
                    /* uniquely identify this yet to be created graph */
                    $uniq_id = md5("dq" . $matches[1] . $matches[2]);
                    $map_id_to_index["dq"][$matches[1]][] = $uniq_id;
                    $selected_graphs[$uniq_id]["graph_template_id"] = $_POST["sgg_" . $matches[1]];
                    $selected_graphs[$uniq_id]["custom_data"]["all_dq"]["data_query_id"] = $matches[1];
                    $selected_graphs[$uniq_id]["custom_data"]["all_dq"]["data_query_index"] = $matches[2];
                } else {
                    if ($name == "cg_g" && !empty($value)) {
                        /* uniquely identify this yet to be created graph */
                        $uniq_id = md5("gt" . $_POST["cg_g"]);
                        $map_id_to_index["gt"][$_POST["cg_g"]][] = $uniq_id;
                        $selected_graphs[$uniq_id]["graph_template_id"] = $_POST["cg_g"];
                    }
                }
            }
        }
    }
    /* we use object buffering on this page to allow redirection to another page if no
    	fields are actually drawn */
    ob_start();
    require_once CACTI_BASE_PATH . "/include/top_header.php";
    print "<form method='post' action='graphs_new.php'>\n";
    $num_output_fields = 0;
    $data_query_id = 0;
    $graph_template_id = 0;
    foreach ($map_id_to_index as $form_type => $form_type_array) {
        foreach ($form_type_array as $form_type_index => $form_type_index_array) {
            if ($form_type == "gt") {
                $graph_template_id = $form_type_index;
                $data_query_id = 0;
                html_start_box("<strong>Create Graph from '" . db_fetch_cell("select template_name from graph_template where id = {$graph_template_id}") . "'", "98%", $colors["header_background"], "3", "center", "");
            } else {
                if ($form_type == "dq") {
                    /* one graph_template_id per data query, at a time */
                    $arr_values = array_values($form_type_index_array);
                    $graph_template_id = $selected_graphs[$arr_values[0]]["graph_template_id"];
                    $data_query_id = $form_type_index;
                    $num_graphs = sizeof($form_type_index_array);
                    /* DRAW: Data Query */
                    html_start_box("<strong>" . _("Create") . " {$num_graphs} " . _("Graph") . ($num_graphs > 1 ? "s" : "") . " from '" . api_data_query_name_get($data_query_id) . "'", "98%", $colors["header_background"], "3", "center", "");
                }
            }
            /* get information about this graph template */
            $graph_template = db_fetch_row("select * from graph_template where id = {$graph_template_id}");
            $num_output_fields += draw_nontemplated_fields_graph($graph_template_id, $graph_template, "g_{$data_query_id}" . "_" . $graph_template_id . "_|field|", "<strong>Graph</strong> [Template: " . $graph_template["template_name"] . "]", false);
            $num_output_fields += draw_nontemplated_fields_graph_item($graph_template_id, array_rekey(db_fetch_assoc("select * from graph_template_item where graph_template_id = {$graph_template_id}"), "id", array("id", "data_template_item_id", "color", "graph_item_type", "cdef", "consolidation_function", "gprint_format", "legend_format", "legend_value", "hard_return")), "gi_" . $data_query_id . "_" . $graph_template_id . "_|id|_|field|", "<strong>" . _("Graph Items") . "</strong> [" . _("Template: ") . $graph_template["template_name"] . "]", false);
            /* get information about each data template referenced by this graph template */
            $data_templates = db_fetch_assoc("select distinct\n\t\t\t\tdata_template.*\n\t\t\t\tfrom data_template,data_template_item,graph_template_item\n\t\t\t\twhere graph_template_item.data_template_item_id=data_template_item.id\n\t\t\t\tand data_template_item.data_template_id=data_template.id\n\t\t\t\tand graph_template_item.graph_template_id = {$graph_template_id}");
            /* DRAW: Data Sources */
            if (sizeof($data_templates) > 0) {
                foreach ($data_templates as $data_template) {
                    $num_output_fields += draw_nontemplated_fields_data_source($data_template["id"], $data_template, "d_" . $data_query_id . "_" . $graph_template_id . "_" . $data_template["id"] . "_|field|", true);
                    $num_output_fields += draw_nontemplated_fields_data_source_item($data_template["id"], db_fetch_assoc("select * from data_template_item where data_template_id = " . $data_template["id"] . " order by data_source_name"), "di_" . $data_query_id . "_" . $graph_template_id . "_" . $data_template["id"] . "_|id|_|field|", true);
                    $num_output_fields += draw_nontemplated_fields_data_input($data_template["id"], array_rekey(db_fetch_assoc("select name,value from data_template_field where data_template_id = " . $data_template["id"]), "name", array("value")), "c_" . $data_query_id . "_" . $graph_template_id . "_" . $data_template["id"] . "_|field|", "<strong>" . _("Custom Data") . "</strong> [" . _("Template: ") . $data_template["template_name"] . "]", false);
                }
            }
            html_end_box();
        }
    }
    /* no fields were actually drawn on the form; just save without prompting the user */
    if ($num_output_fields == 0) {
        ob_end_clean();
        /* since the user didn't actually click "Create" to POST the data; we have to
        		pretend like they did here */
        $_POST["host_id"] = $_POST["host_id"];
        $_POST["save_component_new_graphs"] = "1";
        $_POST["selected_graphs_array"] = addslashes(serialize($selected_graphs));
        $_POST["map_id_to_index_array"] = addslashes(serialize($map_id_to_index));
        host_new_graphs_save();
        header("Location: graphs_new.php?host_id=" . $_POST["host_id"]);
        exit;
    }
    /* flush the current output buffer to the browser */
    ob_end_flush();
    form_hidden_box("host_id", $_POST["host_id"], "0");
    form_hidden_box("save_component_new_graphs", "1", "");
    form_hidden_box("selected_graphs_array", serialize($selected_graphs), "");
    form_hidden_box("map_id_to_index_array", serialize($map_id_to_index), "");
    form_save_button("graphs_new.php?host_id=" . $_POST["host_id"]);
    require_once CACTI_BASE_PATH . "/include/bottom_footer.php";
}
开发者ID:songchin,项目名称:Cacti,代码行数:98,代码来源:graphs_new.php

示例10: ds

function ds()
{
    global $colors, $ds_actions;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("host_id"));
    input_validate_input_number(get_request_var_request("page"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    /* clean up sort_column string */
    if (isset($_REQUEST["sort_column"])) {
        $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
    }
    /* clean up sort_direction string */
    if (isset($_REQUEST["sort_direction"])) {
        $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_ds_current_page");
        kill_session_var("sess_ds_filter");
        kill_session_var("sess_ds_sort_column");
        kill_session_var("sess_ds_sort_direction");
        kill_session_var("sess_ds_host_id");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
        unset($_REQUEST["host_id"]);
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("page", "sess_ds_current_page", "1");
    load_current_session_value("filter", "sess_ds_filter", "");
    load_current_session_value("sort_column", "sess_ds_sort_column", "name_cache");
    load_current_session_value("sort_direction", "sess_ds_sort_direction", "ASC");
    load_current_session_value("host_id", "sess_ds_host_id", "-1");
    $host = db_fetch_row("select hostname from host where id=" . $_REQUEST["host_id"]);
    html_start_box("<strong>Data Sources</strong> [host: " . (empty($host["hostname"]) ? "No Host" : $host["hostname"]) . "]", "100%", $colors["header"], "3", "center", "data_sources.php?action=ds_edit&host_id=" . $_REQUEST["host_id"]);
    include "./include/html/inc_data_source_filter_table.php";
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen($_REQUEST["filter"])) {
        $sql_where = "AND (data_template_data.name_cache like '%%" . $_REQUEST["filter"] . "%%'" . " OR data_template.name like '%%" . $_REQUEST["filter"] . "%%'" . " OR data_input.name like '%%" . $_REQUEST["filter"] . "%%')";
    } else {
        $sql_where = "";
    }
    if ($_REQUEST["host_id"] == "-1") {
        /* Show all items */
    } elseif ($_REQUEST["host_id"] == "0") {
        $sql_where .= " AND data_local.host_id=0";
    } elseif (!empty($_REQUEST["host_id"])) {
        $sql_where .= " AND data_local.host_id=" . $_REQUEST["host_id"];
    }
    $total_rows = sizeof(db_fetch_assoc("SELECT\n\t\tdata_local.id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where}"));
    $poller_intervals = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id AS id,\n\t\tMin(data_template_data.rrd_step*rra.steps) AS poller_interval\n\t\tFROM data_template\n\t\tINNER JOIN (data_local\n\t\tINNER JOIN ((data_template_data_rra\n\t\tINNER JOIN data_template_data ON data_template_data_rra.data_template_data_id=data_template_data.id)\n\t\tINNER JOIN rra ON data_template_data_rra.rra_id = rra.id) ON data_local.id = data_template_data.local_data_id) ON data_template.id = data_template_data.data_template_id\n\t\t{$sql_where}\n\t\tGROUP BY data_template_data.local_data_id"), "id", "poller_interval");
    $data_sources = db_fetch_assoc("SELECT\n\t\tdata_template_data.local_data_id,\n\t\tdata_template_data.name_cache,\n\t\tdata_template_data.active,\n\t\tdata_input.name as data_input_name,\n\t\tdata_template.name as data_template_name,\n\t\tdata_local.host_id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where}\n\t\tORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction'] . " LIMIT " . read_config_option("num_rows_data_source") * ($_REQUEST["page"] - 1) . "," . read_config_option("num_rows_data_source"));
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    /* generate page list */
    $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_data_source"), $total_rows, "data_sources.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"]);
    $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t<td colspan='6'>\n\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong>&lt;&lt; ";
    if ($_REQUEST["page"] > 1) {
        $nav .= "<a class='linkOverDark' href='data_sources.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"] - 1) . "'>";
    }
    $nav .= "Previous";
    if ($_REQUEST["page"] > 1) {
        $nav .= "</a>";
    }
    $nav .= "</strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\tShowing Rows " . (read_config_option("num_rows_data_source") * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_data_source") || $total_rows < read_config_option("num_rows_data_source") * $_REQUEST["page"] ? $total_rows : read_config_option("num_rows_data_source") * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong>";
    if ($_REQUEST["page"] * read_config_option("num_rows_data_source") < $total_rows) {
        $nav .= "<a class='linkOverDark' href='data_sources.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"] + 1) . "'>";
    }
    $nav .= "Next";
    if ($_REQUEST["page"] * read_config_option("num_rows_data_source") < $total_rows) {
        $nav .= "</a>";
    }
    $nav .= " &gt;&gt;</strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n";
    print $nav;
    $display_text = array("name_cache" => array("Name", "ASC"), "data_input_name" => array("Data Input Method", "ASC"), "nosort" => array("Poller<br>Interval", "ASC"), "active" => array("Active", "ASC"), "data_template_name" => array("Template Name", "ASC"));
    html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
    $i = 0;
    if (sizeof($data_sources) > 0) {
        foreach ($data_sources as $data_source) {
            $data_template_name = empty($data_source["data_template_name"]) ? "<em>None</em>" : $data_source["data_template_name"];
            $data_input_name = empty($data_source["data_input_name"]) ? "<em>External</em>" : $data_source["data_input_name"];
            $poller_interval = isset($poller_intervals[$data_source["local_data_id"]]) ? $poller_intervals[$data_source["local_data_id"]] : 0;
            form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $data_source["local_data_id"]);
            $i++;
            form_selectable_cell("<a class='linkEditMain' href='data_sources.php?action=ds_edit&id=" . $data_source["local_data_id"] . "'>" . ($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim(htmlentities($data_source["name_cache"]), read_config_option("max_title_data_source"))) : title_trim(htmlentities($data_source["name_cache"]), read_config_option("max_title_data_source"))) . "</a>", $data_source["local_data_id"]);
            form_selectable_cell(($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $data_input_name) : $data_input_name) . "</a>", $data_source["local_data_id"]);
            form_selectable_cell(get_poller_interval($poller_interval), $data_source["local_data_id"]);
            form_selectable_cell($data_source['active'], $data_source["local_data_id"]);
            form_selectable_cell(($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $data_source['data_template_name']) : $data_source['data_template_name']) . "</a>", $data_source["local_data_id"]);
            form_checkbox_cell($data_source["name_cache"], $data_source["local_data_id"]);
            form_end_row();
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:odp-svn,代码行数:101,代码来源:data_sources.php

示例11: thold_setup_database


//.........这里部分代码省略.........
    $data['unique_keys'][] = array('name' => 'user_id_type', 'columns' => 'user_id`, `type');
    $data['type'] = 'InnoDB';
    $data['comment'] = 'Table of threshold contacts';
    api_plugin_db_table_create('thold', 'plugin_thold_contacts', $data);
    $data = array();
    $data['columns'][] = array('name' => 'template_id', 'type' => 'int(12)', 'NULL' => false);
    $data['columns'][] = array('name' => 'contact_id', 'type' => 'int(12)', 'NULL' => false);
    $data['keys'][] = array('name' => 'template_id', 'columns' => 'template_id');
    $data['keys'][] = array('name' => 'contact_id', 'columns' => 'contact_id');
    $data['type'] = 'InnoDB';
    $data['comment'] = 'Table of Tholds Template Contacts';
    api_plugin_db_table_create('thold', 'plugin_thold_template_contact', $data);
    $data = array();
    $data['columns'][] = array('name' => 'thold_id', 'type' => 'int(12)', 'NULL' => false);
    $data['columns'][] = array('name' => 'contact_id', 'type' => 'int(12)', 'NULL' => false);
    $data['keys'][] = array('name' => 'thold_id', 'columns' => 'thold_id');
    $data['keys'][] = array('name' => 'contact_id', 'columns' => 'contact_id');
    $data['type'] = 'InnoDB';
    $data['comment'] = 'Table of Tholds Threshold Contacts';
    api_plugin_db_table_create('thold', 'plugin_thold_threshold_contact', $data);
    $data = array();
    $data['columns'][] = array('name' => 'id', 'type' => 'int(12)', 'NULL' => false, 'auto_increment' => true);
    $data['columns'][] = array('name' => 'time', 'type' => 'int(24)', 'NULL' => false);
    $data['columns'][] = array('name' => 'host_id', 'type' => 'int(10)', 'NULL' => false);
    $data['columns'][] = array('name' => 'local_graph_id', 'type' => 'int(10)', 'NULL' => false);
    $data['columns'][] = array('name' => 'threshold_id', 'type' => 'int(10)', 'NULL' => false);
    $data['columns'][] = array('name' => 'threshold_value', 'type' => 'varchar(64)', 'NULL' => false);
    $data['columns'][] = array('name' => 'current', 'type' => 'varchar(64)', 'NULL' => false);
    $data['columns'][] = array('name' => 'status', 'type' => 'int(5)', 'NULL' => false);
    $data['columns'][] = array('name' => 'type', 'type' => 'int(5)', 'NULL' => false);
    $data['columns'][] = array('name' => 'description', 'type' => 'varchar(255)', 'NULL' => false);
    $data['primary'] = 'id';
    $data['keys'][] = array('name' => 'time', 'columns' => 'time');
    $data['keys'][] = array('name' => 'host_id', 'columns' => 'host_id');
    $data['keys'][] = array('name' => 'local_graph_id', 'columns' => 'local_graph_id');
    $data['keys'][] = array('name' => 'threshold_id', 'columns' => 'threshold_id');
    $data['keys'][] = array('name' => 'status', 'columns' => 'status');
    $data['keys'][] = array('name' => 'type', 'columns' => 'type');
    $data['type'] = 'InnoDB';
    $data['comment'] = 'Table of All Threshold Breaches';
    api_plugin_db_table_create('thold', 'plugin_thold_log', $data);
    $data = array();
    $data['columns'][] = array('name' => 'id', 'type' => 'int(12)', 'NULL' => false, 'auto_increment' => true);
    $data['columns'][] = array('name' => 'name', 'type' => 'varchar(128)', 'NULL' => false);
    $data['columns'][] = array('name' => 'description', 'type' => 'varchar(512)', 'NULL' => false);
    $data['columns'][] = array('name' => 'emails', 'type' => 'varchar(512)', 'NULL' => false);
    $data['primary'] = 'id';
    $data['type'] = 'InnoDB';
    $data['comment'] = 'Table of Notification Lists';
    api_plugin_db_table_create('thold', 'plugin_notification_lists', $data);
    api_plugin_register_hook('thold', 'host_edit_bottom', 'thold_host_edit_bottom', 'setup.php');
    api_plugin_db_add_column('thold', 'host', array('name' => 'thold_send_email', 'type' => 'int(10)', 'NULL' => false, 'default' => '1', 'after' => 'disabled'));
    api_plugin_db_add_column('thold', 'host', array('name' => 'thold_host_email', 'type' => 'int(10)', 'NULL' => false, 'after' => 'thold_send_email'));
    $data = array();
    $data['columns'][] = array('name' => 'id', 'type' => 'int(12)', 'NULL' => false, 'unsigned' => true, 'auto_increment' => true);
    $data['columns'][] = array('name' => 'host_id', 'type' => 'int(12)', 'unsigned' => true, 'NULL' => false);
    $data['primary'] = 'id';
    $data['type'] = 'InnoDB';
    $data['comment'] = 'Table of Devices in a Down State';
    api_plugin_db_table_create('thold', 'plugin_thold_host_failed', $data);
    $data = array();
    $data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false);
    $data['columns'][] = array('name' => 'pid', 'type' => 'varchar(25)', 'NULL' => false);
    $data['columns'][] = array('name' => 'rrd_reindexed', 'type' => 'varchar(600)', 'NULL' => false);
    $data['columns'][] = array('name' => 'rrd_time_reindexed', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false);
    $data['keys'][] = array('name' => 'id', 'columns' => 'id`, `pid');
    $data['type'] = 'InnoDB';
    $data['comment'] = 'Table of Poller Outdata needed for queued daemon processes';
    api_plugin_db_table_create('thold', 'plugin_thold_daemon_data', $data);
    $data = array();
    $data['columns'][] = array('name' => 'pid', 'type' => 'varchar(25)', 'NULL' => false);
    $data['columns'][] = array('name' => 'start', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'end', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'processed_items', 'type' => 'mediumint(8)', 'NULL' => false, 'default' => '0');
    $data['primary'] = 'pid';
    $data['type'] = 'InnoDB';
    $data['comment'] = 'Table of Thold Daemon Processes being queued';
    api_plugin_db_table_create('thold', 'plugin_thold_daemon_processes', $data);
    $data = array();
    $data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'unsigned' => true, 'NULL' => false, 'auto_increment' => true);
    $data['columns'][] = array('name' => 'host_template_id', 'type' => 'int(11)', 'unsigned' => true, 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'thold_template_id', 'type' => 'int(11)', 'unsigned' => true, 'NULL' => false, 'default' => '0');
    $data['primary'] = 'id';
    $data['type'] = 'InnoDB';
    $data['comment'] = 'Table of Device Template Threshold Templates';
    api_plugin_db_table_create('thold', 'plugin_thold_host_template', $data);
    $indexes = array_rekey(db_fetch_assoc('SHOW INDEX FROM data_local'), 'Key_name', 'Key_name');
    if (!array_key_exists('data_template_id', $indexes)) {
        db_execute('ALTER TABLE data_local ADD INDEX data_template_id(data_template_id)');
    }
    if (!array_key_exists('snmp_query_id', $indexes)) {
        db_execute('ALTER TABLE data_local ADD INDEX snmp_query_id(snmp_query_id)');
    }
    $indexes = array_rekey(db_fetch_assoc('SHOW INDEX FROM host_snmp_cache'), 'Key_name', 'Key_name');
    if (!array_key_exists('snmp_query_id', $indexes)) {
        db_execute('ALTER TABLE host_snmp_cache ADD INDEX snmp_query_id(snmp_query_id)');
    }
    /* increase the size of the settings table */
    db_execute("ALTER TABLE settings MODIFY column `value` varchar(4096) not null default ''");
}
开发者ID:Cacti,项目名称:plugin_thold,代码行数:101,代码来源:database.php

示例12: boost_process_poller_output


//.........这里部分代码省略.........
                $value = trim($item["output"]);
            }
            if ($time != $item["timestamp"]) {
                if (strlen($outbuf) > $upd_string_len) {
                    if ($log_verbosity >= POLLER_VERBOSITY_MEDIUM) {
                        cacti_log("NOTE: Updating Local Data Id:'{$local_data_id}', Template:" . $rrd_tmpl . ", Output:" . $outbuf, FALSE, "BOOST");
                    }
                    boost_timer("rrdupdate", BOOST_TIMER_START);
                    $return_value = boost_rrdtool_function_update($local_data_id, $rrd_path, $rrd_tmpl, $initial_time, $outbuf, $rrdtool_pipe);
                    boost_timer("rrdupdate", BOOST_TIMER_END);
                    $outbuf = "";
                    $vals_in_buffer = 0;
                    /* check return status for delete operation */
                    if (trim($return_value) != "OK") {
                        cacti_log("WARNING: RRD Update Warning '" . $return_value . "' for Local Data ID '{$local_data_id}'", FALSE, "BOOST");
                    }
                }
                $outbuf .= " " . $item["timestamp"];
                $time = $item["timestamp"];
            }
            /* single one value output */
            if (strcmp($value, 'DNP') == 0) {
                /* continue, bad time */
            } elseif (is_numeric($value) || strcmp($value, "U") == 0) {
                $outbuf .= ":" . $value;
                $vals_in_buffer++;
            } elseif (function_exists("is_hexadecimal") && is_hexadecimal($value)) {
                $outbuf .= ":" . hexdec($value);
                $vals_in_buffer++;
            } elseif (strlen($value)) {
                /* break out multiple value output to an array */
                $values = explode(" ", $value);
                if (!$multi_vals_set) {
                    $rrd_field_names = array_rekey(db_fetch_assoc("SELECT\r\n\t\t\t\t\t\tdata_template_rrd.data_source_name,\r\n\t\t\t\t\t\tdata_input_fields.data_name\r\n\t\t\t\t\t\tFROM (data_template_rrd,data_input_fields)\r\n\t\t\t\t\t\tWHERE data_template_rrd.data_input_field_id=data_input_fields.id\r\n\t\t\t\t\t\tAND data_template_rrd.local_data_id=" . $item["local_data_id"]), "data_name", "data_source_name");
                    $rrd_tmpl = "";
                }
                $first_tmpl = 1;
                $multi_ok = FALSE;
                for ($i = 0; $i < count($values); $i++) {
                    if (preg_match("/^([a-zA-Z0-9_\\.-]+):([eE0-9\\+\\.-]+)\$/", $values[$i], $matches)) {
                        if (isset($rrd_field_names[$matches[1]])) {
                            $multi_ok = TRUE;
                            if ($log_verbosity == POLLER_VERBOSITY_DEBUG) {
                                cacti_log("Parsed MULTI output field '" . $matches[0] . "' [map " . $matches[1] . "->" . $rrd_field_names[$matches[1]] . "]", FALSE, "BOOST");
                            }
                            if (!$multi_vals_set) {
                                if (!$first_tmpl) {
                                    $rrd_tmpl .= ":";
                                }
                                $rrd_tmpl .= $rrd_field_names[$matches[1]];
                                $first_tmpl = 0;
                            }
                            if (is_numeric($matches[2]) || $matches[2] == "U") {
                                $outbuf .= ":" . $matches[2];
                            } elseif (function_exists("is_hexadecimal") && is_hexadecimal($matches[2])) {
                                $outbuf .= ":" . hexdec($matches[2]);
                            } else {
                                $outbuf .= ":U";
                            }
                        }
                    }
                }
                /* we only want to process the template and gather the fields once */
                $multi_vals_set = TRUE;
                if ($multi_ok) {
                    $vals_in_buffer++;
开发者ID:resmon,项目名称:resmon-cacti,代码行数:67,代码来源:setup.php

示例13: ds


//.........这里部分代码省略.........
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen(get_request_var_request("filter"))) {
        $sql_where1 = "AND (data_template_data.name_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template_data.local_data_id like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%'" . " OR data_input.name like '%%" . get_request_var_request("filter") . "%%')";
        $sql_where2 = "AND (data_template_data.name_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%')";
    } else {
        $sql_where1 = "";
        $sql_where2 = "";
    }
    if (get_request_var_request("host_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("host_id") == "0") {
        $sql_where1 .= " AND data_local.host_id=0";
        $sql_where2 .= " AND data_local.host_id=0";
    } elseif (!empty($_REQUEST["host_id"])) {
        $sql_where1 .= " AND data_local.host_id=" . get_request_var_request("host_id");
        $sql_where2 .= " AND data_local.host_id=" . get_request_var_request("host_id");
    }
    if (get_request_var_request("template_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("template_id") == "0") {
        $sql_where1 .= " AND data_template_data.data_template_id=0";
        $sql_where2 .= " AND data_template_data.data_template_id=0";
    } elseif (!empty($_REQUEST["host_id"])) {
        $sql_where1 .= " AND data_template_data.data_template_id=" . get_request_var_request("template_id");
        $sql_where2 .= " AND data_template_data.data_template_id=" . get_request_var_request("template_id");
    }
    if (get_request_var_request("method_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("method_id") == "0") {
        $sql_where1 .= " AND data_template_data.data_input_id=0";
        $sql_where2 .= " AND data_template_data.data_input_id=0";
    } elseif (!empty($_REQUEST["method_id"])) {
        $sql_where1 .= " AND data_template_data.data_input_id=" . get_request_var_request("method_id");
        $sql_where2 .= " AND data_template_data.data_input_id=" . get_request_var_request("method_id");
    }
    $total_rows = sizeof(db_fetch_assoc("SELECT\n\t\tdata_local.id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where1}"));
    $poller_intervals = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id AS id,\n\t\tMin(data_template_data.rrd_step*rra.steps) AS poller_interval\n\t\tFROM data_template\n\t\tINNER JOIN (data_local\n\t\tINNER JOIN ((data_template_data_rra\n\t\tINNER JOIN data_template_data ON data_template_data_rra.data_template_data_id=data_template_data.id)\n\t\tINNER JOIN rra ON data_template_data_rra.rra_id = rra.id) ON data_local.id = data_template_data.local_data_id) ON data_template.id = data_template_data.data_template_id\n\t\t{$sql_where2}\n\t\tGROUP BY data_template_data.local_data_id"), "id", "poller_interval");
    $data_sources = db_fetch_assoc("SELECT\n\t\tdata_template_data.local_data_id,\n\t\tdata_template_data.name_cache,\n\t\tdata_template_data.active,\n\t\tdata_input.name as data_input_name,\n\t\tdata_template.name as data_template_name,\n\t\tdata_local.host_id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where1}\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " LIMIT " . get_request_var_request("ds_rows") * (get_request_var_request("page") - 1) . "," . get_request_var_request("ds_rows"));
    print "<form name='chk' method='post' action='data_sources.php'>\n";
    html_start_box("", "100%", "", "3", "center", "");
    $nav = html_nav_bar("data_sources.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id"), MAX_DISPLAY_PAGES, get_request_var_request("page"), get_request_var_request("ds_rows"), $total_rows, 7);
    print $nav;
    $display_text = array("name_cache" => array("Name", "ASC"), "local_data_id" => array("ID", "ASC"), "data_input_name" => array("Data Input Method", "ASC"), "nosort" => array("Poller Interval", "ASC"), "active" => array("Active", "ASC"), "data_template_name" => array("Template Name", "ASC"));
    html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false);
    $i = 0;
    if (sizeof($data_sources) > 0) {
        foreach ($data_sources as $data_source) {
            $data_source["data_template_name"] = htmlspecialchars($data_source["data_template_name"]);
            $data_name_cache = title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source"));
            if (trim(get_request_var_request("filter") != "")) {
                $data_name_cache = preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $data_name_cache);
            }
            /* keep copy of data source for comparison */
            $data_source_orig = $data_source;
            $data_source = api_plugin_hook_function('data_sources_table', $data_source);
            /* we're escaping strings here, so no need to escape them on form_selectable_cell */
            if (empty($data_source["data_template_name"])) {
                $data_template_name = "<em>None</em>";
            } elseif ($data_source_orig["data_template_name"] != $data_source["data_template_name"]) {
                /* was changed by plugin, plugin has to take care for html-escaping */
                $data_template_name = empty($data_source["data_template_name"]) ? "<em>None</em>" : $data_source["data_template_name"];
            } elseif (trim(get_request_var_request("filter") != "")) {
                /* we take care of html-escaping */
                $data_template_name = preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($data_source['data_template_name']));
            } else {
                $data_template_name = htmlspecialchars($data_source["data_template_name"]);
            }
            if (empty($data_source["data_input_name"])) {
                $data_input_name = "<em>None</em>";
            } elseif ($data_source_orig["data_input_name"] != $data_source["data_input_name"]) {
                /* was changed by plugin, plugin has to take care for html-escaping */
                $data_input_name = empty($data_source["data_input_name"]) ? "<em>None</em>" : $data_source["data_input_name"];
            } elseif (trim(get_request_var_request("filter") != "")) {
                /* we take care of html-escaping */
                $data_input_name = preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($data_source['data_input_name']));
            } else {
                $data_input_name = htmlspecialchars($data_source["data_input_name"]);
            }
            $poller_interval = isset($poller_intervals[$data_source["local_data_id"]]) ? $poller_intervals[$data_source["local_data_id"]] : 0;
            form_alternate_row('line' . $data_source["local_data_id"], true);
            form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("data_sources.php?action=ds_edit&id=" . $data_source["local_data_id"]) . "' title='" . htmlspecialchars($data_source["name_cache"], ENT_QUOTES) . "'>" . (get_request_var_request("filter") != "" ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source"))) : title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source"))) . "</a>", $data_source["local_data_id"]);
            form_selectable_cell($data_source['local_data_id'], $data_source['local_data_id']);
            form_selectable_cell($data_input_name, $data_source["local_data_id"]);
            form_selectable_cell(get_poller_interval($poller_interval), $data_source["local_data_id"]);
            form_selectable_cell($data_source['active'] == "on" ? "Yes" : "No", $data_source["local_data_id"]);
            form_selectable_cell($data_template_name, $data_source["local_data_id"]);
            form_checkbox_cell($data_source["name_cache"], $data_source["local_data_id"]);
            form_end_row();
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr><td><em>No Data Sources</em></td></tr>";
    }
    html_end_box(false);
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($ds_actions);
    print "</form>\n";
}
开发者ID:teddywen,项目名称:cacti,代码行数:101,代码来源:data_sources.php

示例14: draw_menu

function draw_menu() {
	global $colors, $config, $user_auth_realms, $user_auth_realm_filenames;

	include($config["include_path"] . "/config_arrays.php");

	/* list all realms that this user has access to */
	if (read_config_option("global_auth") == "on") {
		$user_realms = db_fetch_assoc("select realm_id from user_auth_realm where user_id=" . $_SESSION["sess_user_id"]);
		$user_realms = array_rekey($user_realms, "realm_id", "realm_id");
	}else{
		$user_realms = $user_auth_realms;
	}

	print "<tr><td width='100%'><table cellpadding='3' cellspacing='0' border='0' width='100%'>\n";

	/* loop through each header */
	while (list($header_name, $header_array) = each($menu)) {
		/* pass 1: see if we are allowed to view any children */
		$show_header_items = false;
		while (list($item_url, $item_title) = each($header_array)) {
			$current_realm_id = (isset($user_auth_realm_filenames{basename($item_url)}) ? $user_auth_realm_filenames{basename($item_url)} : 0);

			if ((isset($user_realms[$current_realm_id])) || (!isset($user_auth_realm_filenames{basename($item_url)}))) {
				$show_header_items = true;
			}
		}

		reset($header_array);

		if ($show_header_items == true) {
			print "<tr><td class='textMenuHeader'>$header_name</td></tr>\n";
		}

		/* pass 2: loop through each top level item and render it */
		while (list($item_url, $item_title) = each($header_array)) {
			$current_realm_id = (isset($user_auth_realm_filenames{basename($item_url)}) ? $user_auth_realm_filenames{basename($item_url)} : 0);

			/* if this item is an array, then it contains sub-items. if not, is just
			the title string and needs to be displayed */
			if (is_array($item_title)) {
				$i = 0;

				if ((isset($user_realms[$current_realm_id])) || (!isset($user_auth_realm_filenames{basename($item_url)}))) {
					/* if the current page exists in the sub-items array, draw each sub-item */
					if (array_key_exists(basename($_SERVER["PHP_SELF"]), $item_title) == true) {
						$draw_sub_items = true;
					}else{
						$draw_sub_items = false;
					}

					while (list($item_sub_url, $item_sub_title) = each($item_title)) {
						/* indent sub-items */
						if ($i > 0) {
							$prepend_string = "---&nbsp;";
						}else{
							$prepend_string = "";
						}

						/* do not put a line between each sub-item */
						if (($i == 0) || ($draw_sub_items == false)) {
							$background = "images/menu_line.gif";
						}else{
							$background = "";
						}

						/* draw all of the sub-items as selected for ui grouping reasons. we can use the 'bold'
						or 'not bold' to distinguish which sub-item is actually selected */
						if ((basename($_SERVER["PHP_SELF"]) == basename($item_sub_url)) || ($draw_sub_items)) {
							$td_class = "textMenuItemSelected";
						}else{
							$td_class = "textMenuItem";
						}

						/* always draw the first item (parent), only draw the children if we are viewing a page
						that is contained in the sub-items array */
						if (($i == 0) || ($draw_sub_items)) {
							if (basename($_SERVER["PHP_SELF"]) == basename($item_sub_url)) {
								print "<tr><td class='$td_class' background='$background'>$prepend_string<strong><a href='$item_sub_url'>$item_sub_title</a></strong></td></tr>\n";
							}else{
								print "<tr><td class='$td_class' background='$background'>$prepend_string<a href='$item_sub_url'>$item_sub_title</a></td></tr>\n";
							}
						}

						$i++;
					}
				}
			}else{
				if ((isset($user_realms[$current_realm_id])) || (!isset($user_auth_realm_filenames{basename($item_url)}))) {
					/* draw normal (non sub-item) menu item */
					if (basename($_SERVER["PHP_SELF"]) == basename($item_url)) {
						print "<tr><td class='textMenuItemSelected' background='images/menu_line.gif'><strong><a href='$item_url'>$item_title</a></strong></td></tr>\n";
					}else{
						print "<tr><td class='textMenuItem' background='images/menu_line.gif'><a href='$item_url'>$item_title</a></td></tr>\n";
					}
				}
			}
		}
	}

	print "<tr><td class='textMenuItem' background='images/menu_line.gif'></td></tr>\n";
//.........这里部分代码省略.........
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:html.php

示例15: process_poller_output

function process_poller_output(&$rrdtool_pipe, $remainder = FALSE)
{
    global $config, $debug;
    include_once $config["library_path"] . "/rrd.php";
    /* let's count the number of rrd files we processed */
    $rrds_processed = 0;
    if ($remainder) {
        $limit = "";
    } else {
        $limit = "LIMIT 10000";
    }
    /* create/update the rrd files */
    $results = db_fetch_assoc("select\n\t\tpoller_output.output,\n\t\tpoller_output.time,\n\t\tUNIX_TIMESTAMP(poller_output.time) as unix_time,\n\t\tpoller_output.local_data_id,\n\t\tpoller_item.rrd_path,\n\t\tpoller_item.rrd_name,\n\t\tpoller_item.rrd_num\n\t\tfrom (poller_output,poller_item)\n\t\twhere (poller_output.local_data_id=poller_item.local_data_id and poller_output.rrd_name=poller_item.rrd_name)\n\t\torder by poller_output.local_data_id\n\t\t{$limit}");
    if (sizeof($results) > 0) {
        /* create an array keyed off of each .rrd file */
        foreach ($results as $item) {
            /* trim the default characters, but add single and double quotes */
            $value = trim($item["output"], " \r\n\t\v\"'");
            $unix_time = $item["unix_time"];
            $rrd_update_array[$item["rrd_path"]]["local_data_id"] = $item["local_data_id"];
            /* single one value output */
            if (is_numeric($value) || $value == "U") {
                $rrd_update_array[$item["rrd_path"]]["times"][$unix_time][$item["rrd_name"]] = $value;
                /* special case of one value output: hexadecimal to decimal conversion */
            } elseif (is_hexadecimal($value)) {
                /* attempt to accomodate 32bit and 64bit systems */
                $value = str_replace(' ', '', $value);
                if (strlen($value) <= 8 || 2147483647 + 1 == intval(2147483647 + 1)) {
                    $rrd_update_array[$item["rrd_path"]]["times"][$unix_time][$item["rrd_name"]] = hexdec($value);
                } elseif (function_exists("bcpow")) {
                    $dec = 0;
                    $vallen = strlen($value);
                    for ($i = 1; $i <= $vallen; $i++) {
                        $dec = bcadd($dec, bcmul(strval(hexdec($value[$i - 1])), bcpow('16', strval($vallen - $i))));
                    }
                    $rrd_update_array[$item["rrd_path"]]["times"][$unix_time][$item["rrd_name"]] = $dec;
                } else {
                    $rrd_update_array[$item["rrd_path"]]["times"][$unix_time][$item["rrd_name"]] = "U";
                }
                /* multiple value output */
            } else {
                $values = explode(" ", $value);
                $rrd_field_names = array_rekey(db_fetch_assoc("select\n\t\t\t\t\tdata_template_rrd.data_source_name,\n\t\t\t\t\tdata_input_fields.data_name\n\t\t\t\t\tfrom (data_template_rrd,data_input_fields)\n\t\t\t\t\twhere data_template_rrd.data_input_field_id=data_input_fields.id\n\t\t\t\t\tand data_template_rrd.local_data_id=" . $item["local_data_id"]), "data_name", "data_source_name");
                if (sizeof($values)) {
                    foreach ($values as $value) {
                        $matches = explode(":", $value);
                        if (sizeof($matches) == 2) {
                            if (isset($rrd_field_names[$matches[0]])) {
                                if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_DEBUG || $debug) {
                                    cacti_log("Parsed MULTI output field '" . $matches[0] . ":" . $matches[1] . "' [map " . $matches[0] . "->" . $rrd_field_names[$matches[0]] . "]", true, "POLLER");
                                }
                                $rrd_update_array[$item["rrd_path"]]["times"][$unix_time][$rrd_field_names[$matches[0]]] = $matches[1];
                            }
                        }
                    }
                }
            }
            /* fallback values */
            if (!isset($rrd_update_array[$item["rrd_path"]]["times"][$unix_time]) && $item["rrd_name"] != "") {
                $rrd_update_array[$item["rrd_path"]]["times"][$unix_time][$item["rrd_name"]] = "U";
            } else {
                if (!isset($rrd_update_array[$item["rrd_path"]]["times"][$unix_time]) && $item["rrd_name"] == "") {
                    unset($rrd_update_array[$item["rrd_path"]]);
                }
            }
        }
        /* make sure each .rrd file has complete data */
        reset($results);
        $k = 0;
        $data_ids = array();
        foreach ($results as $item) {
            $unix_time = $item["unix_time"];
            if (isset($rrd_update_array[$item["rrd_path"]]["times"][$unix_time])) {
                if ($item["rrd_num"] <= sizeof($rrd_update_array[$item["rrd_path"]]["times"][$unix_time])) {
                    $data_ids[] = $item["local_data_id"];
                    $k++;
                    if ($k % 10000 == 0) {
                        db_execute("DELETE FROM poller_output WHERE local_data_id IN (" . implode(",", $data_ids) . ")");
                        $k = 0;
                        $data_ids = array();
                    }
                } else {
                    unset($rrd_update_array[$item["rrd_path"]]["times"][$unix_time]);
                }
            }
        }
        if ($k > 0) {
            db_execute("DELETE FROM poller_output WHERE local_data_id IN (" . implode(",", $data_ids) . ")");
        }
        api_plugin_hook_function('poller_output', $rrd_update_array);
        if (api_plugin_hook_function('poller_on_demand', $results)) {
            $rrds_processed = rrdtool_function_update($rrd_update_array, $rrdtool_pipe);
        }
    }
    return $rrds_processed;
}
开发者ID:teddywen,项目名称:cacti,代码行数:96,代码来源:poller.php


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