Пример #1
0
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;
	}
}
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;
        }
    }
}
Пример #3
0
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");
    }
}
Пример #4
0
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");
}
Пример #5
0
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;
}
Пример #6
0
function graphs()
{
    global $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('host_id'));
    input_validate_input_number(get_request_var_request('graph_type'));
    input_validate_input_number(get_request_var_request('rows'));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST['filter'])) {
        $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter'));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST['clear_x'])) {
        kill_session_var('sess_graphs_new_filter');
        kill_session_var('sess_default_rows');
        unset($_REQUEST['filter']);
        unset($_REQUEST['rows']);
        $changed = true;
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = false;
        $changed += check_changed('host_id', 'sess_graphs_new_host_id');
        $changed += check_changed('graph_type', 'sess_graphs_new_graph_type');
        $changed += check_changed('filter', 'sess_graphs_new_filter');
        $changed += check_changed('rows', 'sess_default_rows');
    }
    load_current_session_value('host_id', 'sess_graphs_new_host_id', db_fetch_cell('SELECT id FROM host ORDER BY description, hostname LIMIT 1'));
    load_current_session_value('graph_type', 'sess_graphs_new_graph_type', read_config_option('default_graphs_new_dropdown'));
    load_current_session_value('filter', 'sess_graphs_new_filter', '');
    load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    if (!empty($_REQUEST['host_id'])) {
        $host = db_fetch_row_prepared('SELECT id, description, hostname, host_template_id FROM host WHERE id = ?', array($_REQUEST['host_id']));
        $header = ' [ ' . htmlspecialchars($host['description']) . ' (' . htmlspecialchars($host['hostname']) . ') ' . (!empty($host['host_template_id']) ? htmlspecialchars(db_fetch_cell_prepared('SELECT name FROM host_template WHERE id = ?', array($host['host_template_id']))) : '') . ' ]';
    } else {
        $host = array();
        $header = 'None Host Type';
    }
    $row_limit = get_request_var_request('rows');
    html_start_box("<strong>New Graphs for</strong> {$header}", '100%', '', '3', 'center', '');
    form_alternate_row();
    print '<td class="even">';
    ?>
	<script type='text/javascript'>
	<!--

	function applyFilter() {
		strURL = '?graph_type=' + $('#graph_type').val();
		strURL = strURL + '&host_id=' + $('#host_id').val();
		strURL = strURL + '&filter=' + $('#filter').val();;
		strURL = strURL + '&rows=' + $('#rows').val();;
		document.location = strURL;
	}

	-->
	</script>
	<form name='form_graphs_new' action='graphs_new.php'>
	<table width='100%' cellpadding='2' cellspacing='0' border='0' align='left'>
		<tr>
			<?php 
    print html_host_filter($_REQUEST['host_id']);
    ?>
			<td style='white-space:nowrap;' width='1'>
				Graph Types
			</td>
			<td width='1'>
				<select id='graph_type' name='graph_type' onChange='applyFilter()'>
					<option value='-2'<?php 
    if ($_REQUEST['graph_type'] == '-2') {
        ?>
 selected<?php 
    }
    ?>
>All</option>
					<option value='-1'<?php 
    if ($_REQUEST['graph_type'] == '-1') {
        ?>
 selected<?php 
    }
    ?>
>Graph Template Based</option>
					<?php 
    $snmp_queries = db_fetch_assoc_prepared('SELECT
						snmp_query.id,
						snmp_query.name,
						snmp_query.xml_path
						FROM (snmp_query, host_snmp_query)
						WHERE host_snmp_query.snmp_query_id = snmp_query.id
						AND host_snmp_query.host_id = ?
						ORDER BY snmp_query.name', array($host['id']));
    if (sizeof($snmp_queries) > 0) {
        foreach ($snmp_queries as $query) {
            print "<option value='" . $query['id'] . "'";
            if ($_REQUEST['graph_type'] == $query['id']) {
                print ' selected';
            }
            print '>' . $query['name'] . "</option>\n";
        }
    }
    ?>
				</select>
			</td>
			<td width='50'>
				Rows
			</td>
			<td>
				<select id='rows' name='rows' onChange='applyFilter()'>
					<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request('rows') == $key) {
                print ' selected';
            }
            print '>' . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
				</select>
			</td>
			<td rowspan='3' class='textInfo' align='right' valign='top'>
				<span class='linkMarker'>*</span><a class='hyperLink' href='<?php 
    print htmlspecialchars('host.php?action=edit&id=' . $_REQUEST['host_id']);
    ?>
'>Edit this Device</a><br>
				<span class='linkMarker'>*</span><a class='hyperLink' href='<?php 
    print htmlspecialchars('host.php?action=edit');
    ?>
'>Create New Device</a><br>
				<?php 
    api_plugin_hook('graphs_new_top_links');
    ?>
			</td>
		</tr>
		<tr style='<?php 
    if ($_REQUEST['graph_type'] <= 0) {
        ?>
display:none;<?php 
    }
    ?>
'>
			<td width='50'>
				Search
			</td>
			<td style='white-space:nowrap;'>
				<input id='filter' type='text' name='filter' size='25' value='<?php 
    print htmlspecialchars(get_request_var_request('filter'));
    ?>
'>
			</td>
			<td colspan='3' style='white-space:nowrap;'>
				<input type='submit' value='Go' title='Set/Refresh Filters'>
				<input type='submit' name='clear_x' value='Clear' title='Clear Filters'>
			</td>
		</tr>
	</table>
	</form>
	</td>
	</tr>

	<?php 
    html_end_box();
    ?>

	<form name='chk' method='post' action='graphs_new.php'>
	<?php 
    $total_rows = sizeof(db_fetch_assoc_prepared('SELECT graph_template_id FROM host_graph WHERE host_id = ?', array($_REQUEST['host_id'])));
    $i = 0;
    if ($changed) {
        foreach ($snmp_queries as $query) {
            kill_session_var('sess_graphs_new_page' . $query['id']);
            unset($_REQUEST['page' . $query['id']]);
            load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1');
        }
    }
    if ($_REQUEST['graph_type'] > 0) {
        load_current_session_value('page' . $_REQUEST['graph_type'], 'sess_graphs_new_page' . $_REQUEST['graph_type'], '1');
    } else {
        if ($_REQUEST['graph_type'] == -2) {
            foreach ($snmp_queries as $query) {
                load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1');
            }
        }
    }
    $script = "<script type='text/javascript'>\nvar gt_created_graphs = new Array();\nvar created_graphs = new Array()\n";
    if ($_REQUEST['graph_type'] < 0) {
        html_start_box('<strong>Graph Templates</strong>', '100%', '', '3', 'center', '');
        print "<tr class='tableHeader'>\n\t\t\t\t<td class='tableSubHeaderColumn'>Graph Template Name</td>\n\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='Select All' onClick='SelectAll(\"sg\",this.checked);'></td>\n\n\t\t\t</tr>\n";
        $graph_templates = db_fetch_assoc_prepared('SELECT
			graph_templates.id AS graph_template_id,
			graph_templates.name AS graph_template_name
			FROM (host_graph, graph_templates)
			WHERE host_graph.graph_template_id = graph_templates.id
			AND host_graph.host_id = ?
			ORDER BY graph_templates.name', array($_REQUEST['host_id']));
        if (!empty($_REQUEST['host_id'])) {
            $template_graphs = db_fetch_assoc_prepared('SELECT
				graph_local.graph_template_id
				FROM (graph_local, host_graph)
				WHERE graph_local.graph_template_id = host_graph.graph_template_id
				AND graph_local.host_id = host_graph.host_id
				AND graph_local.host_id = ?
				GROUP BY graph_local.graph_template_id', array($host['id']));
            if (sizeof($template_graphs) > 0) {
                $script .= 'var gt_created_graphs = new Array(';
                $cg_ctr = 0;
                foreach ($template_graphs as $template_graph) {
                    $script .= ($cg_ctr > 0 ? ',' : '') . "'" . $template_graph['graph_template_id'] . "'";
                    $cg_ctr++;
                }
                $script .= ")\n";
            }
        }
        /* create a row for each graph template associated with the host template */
        if (sizeof($graph_templates) > 0) {
            foreach ($graph_templates as $graph_template) {
                $query_row = $graph_template['graph_template_id'];
                print "<tr id='gt_line{$query_row}' class='selectable " . ($i % 2 == 0 ? 'odd' : 'even') . "'>";
                $i++;
                print "<td>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'>" . htmlspecialchars($graph_template['graph_template_name']) . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right' class='checkbox'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
            }
        }
        html_end_box();
        html_start_box('', '100%', '', '3', 'center', '');
        $available_graph_templates = db_fetch_assoc('SELECT
			graph_templates.id, graph_templates.name
			FROM snmp_query_graph RIGHT JOIN graph_templates
			ON (snmp_query_graph.graph_template_id = graph_templates.id)
			WHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name');
        /* create a row at the bottom that lets the user create any graph they choose */
        print "\t<tr class='even'>\n\t\t\t\t<td width='1'><i>Create</i></td>\n\t\t\t\t<td align='left'>";
        form_dropdown('cg_g', $available_graph_templates, 'name', 'id', '', '(Select a graph type to create)', '', 'textArea');
        print '</td>
			</tr>';
        html_end_box();
    }
    if ($_REQUEST['graph_type'] != -1 && !empty($_REQUEST['host_id'])) {
        $snmp_queries = db_fetch_assoc('SELECT
			snmp_query.id,
			snmp_query.name,
			snmp_query.xml_path
			FROM (snmp_query,host_snmp_query)
			WHERE host_snmp_query.snmp_query_id=snmp_query.id
			AND host_snmp_query.host_id=' . $host['id'] . ($_REQUEST['graph_type'] != -2 ? ' AND snmp_query.id=' . $_REQUEST['graph_type'] : '') . '
			ORDER BY snmp_query.name');
        if (sizeof($snmp_queries) > 0) {
            foreach ($snmp_queries as $snmp_query) {
                unset($total_rows);
                if (!$changed) {
                    $page = $_REQUEST['page' . $snmp_query['id']];
                } else {
                    $page = 1;
                }
                $xml_array = get_data_query_array($snmp_query['id']);
                $num_input_fields = 0;
                $num_visible_fields = 0;
                if ($xml_array != false) {
                    /* loop through once so we can find out how many input fields there are */
                    reset($xml_array['fields']);
                    while (list($field_name, $field_array) = each($xml_array['fields'])) {
                        if ($field_array['direction'] == 'input') {
                            $num_input_fields++;
                            if (!isset($total_rows)) {
                                $total_rows = db_fetch_cell_prepared('SELECT count(*) FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ? AND field_name = ?', array($host['id'], $snmp_query['id'], $field_name));
                            }
                        }
                    }
                }
                if (!isset($total_rows)) {
                    $total_rows = 0;
                }
                $snmp_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($snmp_query_graphs) > 0) {
                    foreach ($snmp_query_graphs as $snmp_query_graph) {
                        $created_graphs = db_fetch_assoc_prepared("SELECT DISTINCT\n\t\t\t\t\t\tdata_local. snmp_index\n\t\t\t\t\t\tFROM (data_local, data_template_data)\n\t\t\t\t\t\tLEFT JOIN data_input_data ON (data_template_data.id = data_input_data.data_template_data_id)\n\t\t\t\t\t\tLEFT JOIN data_input_fields ON (data_input_data.data_input_field_id = data_input_fields.id)\n\t\t\t\t\t\tWHERE data_local.id = data_template_data.local_data_id\n\t\t\t\t\t\tAND data_input_fields.type_code = 'output_type'\n\t\t\t\t\t\tAND data_input_data.value = ?\n\t\t\t\t\t\tAND data_local.host_id = ?", array($snmp_query_graph['id'], $host['id']));
                        $script .= 'created_graphs[' . $snmp_query_graph['id'] . '] = new Array(';
                        $cg_ctr = 0;
                        if (sizeof($created_graphs) > 0) {
                            foreach ($created_graphs as $created_graph) {
                                $script .= ($cg_ctr > 0 ? ',' : '') . "'" . encode_data_query_index($created_graph['snmp_index']) . "'";
                                $cg_ctr++;
                            }
                        }
                        $script .= ")\n";
                    }
                }
                print "\t<table width='100%' class='cactiTable' align='center' cellpadding='3' cellspacing='0'>\n\n\t\t\t\t\t<tr class='cactiTableTitle'>\n\t\t\t\t\t\t<td colspan='" . ($num_input_fields + 1) . "'>\n\t\t\t\t\t\t\t<table  cellspacing='0' cellpadding='0' width='100%' >\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t<strong>Data Query</strong> [" . $snmp_query['name'] . "]\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t<td align='right' nowrap>\n\t\t\t\t\t\t\t\t\t\t<a href='" . htmlspecialchars('graphs_new.php?action=query_reload&id=' . $snmp_query['id'] . '&host_id=' . $host['id']) . "'><img src='images/reload_icon_small.gif' title='Reload Associated Query' alt='' border='0' align='absmiddle'></a>\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
                if ($xml_array != false) {
                    $html_dq_header = '';
                    $snmp_query_indexes = array();
                    reset($xml_array['fields']);
                    /* if there is a where clause, get the matching snmp_indexes */
                    $sql_where = '';
                    if (strlen($_REQUEST['filter'])) {
                        $sql_where = '';
                        $indexes = db_fetch_assoc("SELECT DISTINCT snmp_index\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE field_value LIKE '%%" . $_REQUEST['filter'] . "%%'\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query['id'] . "\n\t\t\t\t\t\tAND host_id=" . $host['id']);
                        if (sizeof($indexes)) {
                            foreach ($indexes as $index) {
                                if (strlen($sql_where)) {
                                    $sql_where .= ", '" . $index['snmp_index'] . "'";
                                } else {
                                    $sql_where .= " AND snmp_index IN('" . $index['snmp_index'] . "'";
                                }
                            }
                            $sql_where .= ')';
                        }
                    }
                    if (strlen($_REQUEST['filter']) == 0 || strlen($_REQUEST['filter']) && sizeof($indexes)) {
                        /* determine the sort order */
                        if (isset($xml_array['index_order_type'])) {
                            if ($xml_array['index_order_type'] == 'numeric') {
                                $sql_order = 'ORDER BY CAST(snmp_index AS unsigned)';
                            } else {
                                if ($xml_array['index_order_type'] == 'alphabetic') {
                                    $sql_order = 'ORDER BY snmp_index';
                                } else {
                                    if ($xml_array['index_order_type'] == 'natural') {
                                        $sql_order = 'ORDER BY INET_ATON(snmp_index)';
                                    } else {
                                        $sql_order = '';
                                    }
                                }
                            }
                        } else {
                            $sql_order = '';
                        }
                        /* get the unique field values from the database */
                        $field_names = db_fetch_assoc_prepared('SELECT DISTINCT field_name
						FROM host_snmp_cache
						WHERE host_id = ?
						AND snmp_query_id = ?', array($host['id'], $snmp_query['id']));
                        /* build magic query */
                        $sql_query = 'SELECT host_id, snmp_query_id, snmp_index';
                        $num_visible_fields = sizeof($field_names);
                        $i = 0;
                        if (sizeof($field_names) > 0) {
                            foreach ($field_names as $column) {
                                $field_name = $column['field_name'];
                                $sql_query .= ", MAX(CASE WHEN field_name='{$field_name}' THEN field_value ELSE NULL END) AS '{$field_name}'";
                                $i++;
                            }
                        }
                        $sql_query .= ' FROM host_snmp_cache
						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']);
}
Пример #7
0
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);
Пример #8
0
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;
    }
}
Пример #9
0
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";
}
Пример #10
0
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 {
        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";
}
Пример #11
0
function thold_setup_database()
{
    $data = array();
    $data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true);
    $data['columns'][] = array('name' => 'name', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'local_data_id', 'type' => 'int(11)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'data_template_rrd_id', 'type' => 'int(11)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'local_graph_id', 'type' => 'int(11)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'graph_template_id', 'type' => 'int(11)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'data_template_id', 'type' => 'int(11)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'thold_hi', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'thold_low', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'thold_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'thold_fail_count', 'type' => 'int(11)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'time_hi', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'time_low', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'time_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1);
    $data['columns'][] = array('name' => 'time_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1);
    $data['columns'][] = array('name' => 'thold_warning_hi', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'thold_warning_low', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'thold_warning_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'thold_warning_fail_count', 'type' => 'int(11)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'time_warning_hi', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'time_warning_low', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'time_warning_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1);
    $data['columns'][] = array('name' => 'time_warning_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1);
    $data['columns'][] = array('name' => 'thold_alert', 'type' => 'int(1)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'thold_enabled', 'type' => "enum('on','off')", 'NULL' => false, 'default' => 'on');
    $data['columns'][] = array('name' => 'thold_type', 'type' => 'int (3)', 'NULL' => false, 'default' => 0);
    $data['columns'][] = array('name' => 'bl_ref_time_range', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'bl_pct_down', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'bl_pct_up', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'bl_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'bl_fail_count', 'type' => 'int(11)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'bl_alert', 'type' => 'int(2)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'lastread', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'lasttime', 'type' => 'timestamp', 'NULL' => false, 'default' => '0000-00-00 00:00:00');
    $data['columns'][] = array('name' => 'oldvalue', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'repeat_alert', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'notify_default', 'type' => "enum('on','off')", 'NULL' => true);
    $data['columns'][] = array('name' => 'notify_extra', 'type' => 'varchar(512)', 'NULL' => true);
    $data['columns'][] = array('name' => 'notify_warning_extra', 'type' => 'varchar(512)', 'NULL' => true);
    $data['columns'][] = array('name' => 'notify_warning', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'notify_alert', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'host_id', 'type' => 'int(10)', 'NULL' => true);
    $data['columns'][] = array('name' => 'syslog_priority', 'type' => 'int(2)', 'NULL' => false, 'default' => '3');
    $data['columns'][] = array('name' => 'data_type', 'type' => 'int(12)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'cdef', 'type' => 'int(11)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'percent_ds', 'type' => 'varchar(64)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'expression', 'type' => 'varchar(70)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'thold_template_id', 'type' => 'int(11)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'template_enabled', 'type' => 'char(3)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'tcheck', 'type' => 'int(1)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'exempt', 'type' => 'char(3)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'restored_alert', 'type' => 'char(3)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'bl_thold_valid', 'type' => 'int(10)', 'NULL' => false, 'default' => '0', 'unsigned' => true);
    $data['columns'][] = array('name' => 'snmp_event_category', 'type' => 'varchar(255)', 'NULL' => true);
    $data['columns'][] = array('name' => 'snmp_event_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '3');
    $data['columns'][] = array('name' => 'snmp_event_warning_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '2');
    $data['columns'][] = array('name' => 'thold_daemon_pid', 'type' => 'varchar(25)', 'NULL' => false, 'default' => '');
    $data['primary'] = 'id';
    $data['keys'][] = array('name' => 'host_id', 'columns' => 'host_id');
    $data['keys'][] = array('name' => 'local_data_id', 'columns' => 'local_data_id');
    $data['keys'][] = array('name' => 'data_template_rrd_id', 'columns' => 'data_template_rrd_id');
    $data['keys'][] = array('name' => 'local_graph_id', 'columns' => 'local_graph_id');
    $data['keys'][] = array('name' => 'thold_template_id', 'columns' => 'thold_template_id');
    $data['keys'][] = array('name' => 'thold_enabled', 'columns' => 'thold_enabled');
    $data['keys'][] = array('name' => 'template_enabled', 'columns' => 'template_enabled');
    $data['keys'][] = array('name' => 'tcheck', 'columns' => 'tcheck');
    $data['type'] = 'InnoDB';
    $data['comment'] = 'Threshold data';
    api_plugin_db_table_create('thold', 'thold_data', $data);
    $data = array();
    $data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true);
    $data['columns'][] = array('name' => 'hash', 'type' => 'varchar(32)', 'NULL' => false);
    $data['columns'][] = array('name' => 'name', 'type' => 'varchar(100)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'data_template_id', 'type' => 'int(10)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'data_template_name', 'type' => 'varchar(100)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'data_source_id', 'type' => 'int(10)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'data_source_name', 'type' => 'varchar(100)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'data_source_friendly', 'type' => 'varchar(100)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'thold_hi', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'thold_low', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'thold_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'time_hi', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'time_low', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'time_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1);
    $data['columns'][] = array('name' => 'time_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1);
    $data['columns'][] = array('name' => 'thold_warning_hi', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'thold_warning_low', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'thold_warning_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'thold_warning_fail_count', 'type' => 'int(11)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'time_warning_hi', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'time_warning_low', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'time_warning_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1);
    $data['columns'][] = array('name' => 'time_warning_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1);
    $data['columns'][] = array('name' => 'thold_enabled', 'type' => "enum('on','off')", 'NULL' => false, 'default' => 'on');
    $data['columns'][] = array('name' => 'thold_type', 'type' => 'int (3)', 'NULL' => false, 'default' => 0);
    $data['columns'][] = array('name' => 'bl_ref_time_range', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'bl_pct_down', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'bl_pct_up', 'type' => 'varchar(100)', 'NULL' => true);
    $data['columns'][] = array('name' => 'bl_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'bl_fail_count', 'type' => 'int(11)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'bl_alert', 'type' => 'int(2)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'repeat_alert', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'notify_default', 'type' => "enum('on','off')", 'NULL' => true);
    $data['columns'][] = array('name' => 'notify_extra', 'type' => 'varchar(512)', 'NULL' => true);
    $data['columns'][] = array('name' => 'notify_warning_extra', 'type' => 'varchar(512)', 'NULL' => true);
    $data['columns'][] = array('name' => 'notify_warning', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'notify_alert', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true);
    $data['columns'][] = array('name' => 'data_type', 'type' => 'int(12)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'cdef', 'type' => 'int(11)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'percent_ds', 'type' => 'varchar(64)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'expression', 'type' => 'varchar(70)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'exempt', 'type' => 'char(3)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'restored_alert', 'type' => 'char(3)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'snmp_event_category', 'type' => 'varchar(255)', 'NULL' => true);
    $data['columns'][] = array('name' => 'snmp_event_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '3');
    $data['columns'][] = array('name' => 'snmp_event_warning_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '2');
    $data['primary'] = 'id';
    $data['keys'][] = array('name' => 'id', 'columns' => 'id');
    $data['keys'][] = array('name' => 'data_source_id', 'columns' => 'data_source_id');
    $data['keys'][] = array('name' => 'data_template_id', 'columns' => 'data_template_id');
    $data['type'] = 'InnoDB';
    $data['comment'] = 'Table of thresholds defaults for graphs';
    api_plugin_db_table_create('thold', 'thold_template', $data);
    $data = array();
    $data['columns'][] = array('name' => 'id', 'type' => 'int(12)', 'NULL' => false, 'auto_increment' => true);
    $data['columns'][] = array('name' => 'user_id', 'type' => 'int(12)', 'NULL' => false);
    $data['columns'][] = array('name' => 'type', 'type' => 'varchar(32)', 'NULL' => false);
    $data['columns'][] = array('name' => 'data', 'type' => 'text', 'NULL' => false);
    $data['primary'] = 'id';
    $data['keys'][] = array('name' => 'type', 'columns' => 'type');
    $data['keys'][] = array('name' => 'user_id', 'columns' => 'user_id');
    $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 ''");
}
Пример #12
0
function boost_process_poller_output($use_server = FALSE, $local_data_id = "")
{
    global $config, $boost_sock, $boost_timeout, $debug, $get_memory, $memory_used;
    global $rrdtool_pipe, $rrdtool_read_pipe;
    include_once $config["library_path"] . "/rrd.php";
    /* suppress warnings */
    if (defined("E_DEPRECATED")) {
        error_reporting(E_ALL ^ E_DEPRECATED);
    } else {
        error_reporting(E_ALL);
    }
    /* install the boost error handler */
    set_error_handler("boost_error_handler");
    /* load system variables needed */
    $log_verbosity = read_config_option("log_verbosity");
    $upd_string_len = read_config_option("boost_rrd_update_string_length");
    /* tiny SQL where addendum for boost */
    if (strlen($local_data_id)) {
        /* we can simplify the delete process if only one local_data_id */
        $single_local_data_id = TRUE;
        $orig_local_data_id = $local_data_id;
        /* aquire lock in order to prevent race conditions */
        while (!db_fetch_cell("SELECT GET_LOCK('boost.single_ds.{$local_data_id}', 1)")) {
            usleep(50000);
        }
    } else {
        $single_local_data_id = FALSE;
        $poller_interval = read_config_option("poller_interval");
        $rrd_update_interval = read_config_option("boost_rrd_update_interval");
        $data_ids_to_get = read_config_option("boost_rrd_update_max_records_per_select");
        $archive_table = boost_get_arch_table_name();
        if ($archive_table === FALSE) {
            cacti_log("Failed to determine archive table", FALSE, "BOOST");
            return 0;
        }
    }
    /* get the records */
    if ($single_local_data_id) {
        $query_string = "";
        $arch_tables = db_fetch_assoc("\tSELECT table_name AS name\r\n\t\t\t\t\t\tFROM information_schema.tables\r\n\t\t\t\t\t\t\tWHERE table_schema=SCHEMA()\r\n\t\t\t\t\t\t\tAND table_name LIKE 'poller_output_boost_arch_%'\r\n\t\t\t\t\t\t\tAND table_rows>0;\r\n\t\t\t\t\t\t");
        if (count($arch_tables)) {
            foreach ($arch_tables as $table) {
                if (strlen($query_string)) {
                    $query_string .= " UNION ";
                }
                $query_string .= " ( SELECT local_data_id, UNIX_TIMESTAMP(time) AS timestamp, rrd_name, output FROM " . $table["name"] . " WHERE local_data_id='{$local_data_id}' ) ";
            }
        }
        if (strlen($query_string)) {
            $query_string .= " UNION ";
        }
        $timestamp = time();
        $query_string .= " ( SELECT local_data_id, UNIX_TIMESTAMP(time) AS timestamp, rrd_name, output FROM poller_output_boost WHERE local_data_id='{$local_data_id}' AND time < FROM_UNIXTIME('{$timestamp}') ) ";
        $query_string .= "  ORDER BY local_data_id ASC, timestamp ASC, rrd_name ASC ";
    } else {
        $query_string = "SELECT local_data_id, UNIX_TIMESTAMP(time) AS timestamp, rrd_name, output FROM {$archive_table} FORCE INDEX (PRIMARY)\r\n\t\t\t\tORDER BY local_data_id ASC, time ASC, rrd_name ASC\r\n\t\t\t\tLIMIT {$data_ids_to_get} ";
    }
    boost_timer("get_records", BOOST_TIMER_START);
    $results = db_fetch_assoc($query_string);
    boost_timer("get_records", BOOST_TIMER_END);
    /* log memory */
    if ($get_memory) {
        $cur_memory = memory_get_usage();
        if ($cur_memory > $memory_used) {
            $memory_used = $cur_memory;
        }
    }
    if ($single_local_data_id && ($debug || $log_verbosity >= POLLER_VERBOSITY_MEDIUM)) {
        cacti_log("NOTE: Updating Local Data ID:'{$local_data_id}', Total of '" . sizeof($results) . "' Updates to Process", FALSE, "BOOST");
    }
    if (sizeof($results) > 0) {
        /* open the boost socket connection if applicable */
        if (read_config_option("boost_server_enable") == "on" && $local_data_id != "" && $use_server) {
            $boost_timeout = read_config_option("boost_server_timeout");
            $boost_sock = boost_server_connect();
            if ($boost_sock < 0) {
                /* restore original error handler */
                restore_error_handler();
                return 0;
            }
        }
        /* create an array keyed off of each .rrd file */
        $local_data_id = -1;
        $time = -1;
        $outbuf = "";
        $last_update = -1;
        $last_item = array("local_data_id" => -1, "timestamp" => -1, "rrd_name" => "");
        /* we are going to blow away all record if ok */
        $vals_in_buffer = 0;
        /* cut last DS (likely to be incomplete due to LIMIT)*/
        if (!$single_local_data_id) {
            reset($results);
            $first_ds = $results[key($results)];
            $first_ds = intval($first_ds["local_data_id"]);
            end($results);
            $last_ds = $results[key($results)];
            $last_ds = intval($last_ds["local_data_id"]);
            reset($results);
            if ($first_ds == $last_ds) {
                if (sizeof($results) == $data_ids_to_get) {
                    cacti_log("FALURE: Current LIMIT ({$data_ids_to_get}) is too low to run multiple DS RRD writes, consider raising it", FALSE, "BOOST");
                }
                restore_error_handler();
                return boost_process_poller_output($use_server, $first_ds);
            }
        }
        boost_timer("results_cycle", BOOST_TIMER_START);
        /* go through each poller_output_boost entries and process */
        foreach ($results as $item) {
            $item["timestamp"] = trim($item["timestamp"]);
            if ($single_local_data_id && $last_item["local_data_id"] == $item["local_data_id"] && $last_item["timestamp"] == $item["timestamp"] && strcmp($last_item["rrd_name"], $item["rrd_name"]) == 0) {
                continue;
            }
            if (!$single_local_data_id && $first_ds != $last_ds && $last_ds == $item["local_data_id"]) {
                /* we faced last and possibly incomplete DS, bail out */
                break;
            }
            /* if the local_data_id changes, we need to flush the buffer */
            if ($local_data_id != $item["local_data_id"]) {
                /* update the rrd for the previous local_data_id */
                if ($vals_in_buffer) {
                    if ($debug || $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");
                    }
                }
                /* reset the rrd file path and templates, assume non multi output */
                boost_timer("rrd_filename_and_template", BOOST_TIMER_START);
                $rrd_data = boost_get_rrd_filename_and_template($item["local_data_id"]);
                $rrd_tmpl = $rrd_data["rrd_template"];
                $rrd_path = $rrd_data["rrd_path"];
                boost_timer("rrd_filename_and_template", BOOST_TIMER_END);
                $pipe = is_resource($rrdtool_read_pipe) || is_array($rrdtool_read_pipe) ? $rrdtool_read_pipe : $rrdtool_pipe;
                boost_timer("rrd_lastupdate", BOOST_TIMER_START);
                $last_update = boost_rrdtool_get_last_update_time($rrd_path, $pipe);
                boost_timer("rrd_lastupdate", BOOST_TIMER_END);
                $local_data_id = $item["local_data_id"];
                $time = $item["timestamp"];
                $initial_time = $time;
                $outbuf = " " . $time;
                $multi_vals_set = FALSE;
            }
            /* don't generate error messages if the RRD has already been updated */
            if ($time <= $last_update) {
                cacti_log("WARNING: Stale Poller Data Found! Item Time:'" . $time . "', RRD Time:'" . $last_update . "' Ignoring Value!", FALSE, "BOOST");
                $value = 'DNP';
            } else {
                $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++;
                }
            } else {
                cacti_log("WARNING: Local Data Id [" . $item["local_data_id"] . "] Contains an empty value", FALSE, "BOOST");
            }
        }
        /* process the last rrdupdate if applicable */
        if ($vals_in_buffer) {
            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);
            /* 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");
            }
        }
        boost_timer("results_cycle", BOOST_TIMER_END);
        /* remove the entries from the table */
        boost_timer("delete", BOOST_TIMER_START);
        if ($single_local_data_id) {
            $tables = db_fetch_assoc("SELECT table_name AS name\r\n\t\t\t\t\t\tFROM information_schema.tables\r\n\t\t\t\t\t\tWHERE table_schema=SCHEMA()\r\n\t\t\t\t\t\tAND ( table_name LIKE 'poller_output_boost_arch_%' OR table_name LIKE 'poller_output_boost' )\r\n\t\t\t\t\t\tAND table_rows>0;\r\n\t\t\t\t\t\t");
            if (count($tables)) {
                foreach ($tables as $table) {
                    db_execute("DELETE FROM " . $table["name"] . " WHERE local_data_id='{$local_data_id}' AND time < FROM_UNIXTIME('{$timestamp}')");
                }
            }
        } else {
            db_execute("DELETE FROM {$archive_table} WHERE local_data_id BETWEEN '{$first_ds}' AND '" . ($last_ds - 1) . "'");
        }
        boost_timer("delete", BOOST_TIMER_END);
        /* close the boost server connection, if applicable */
        if (read_config_option("boost_server_enable") == "on" && $local_data_id != "" && $use_server) {
            boost_server_disconnect($boost_sock);
        }
    }
    if ($single_local_data_id) {
        db_execute("SELECT RELEASE_LOCK('boost.single_ds.{$orig_local_data_id}')");
    }
    /* restore original error handler */
    restore_error_handler();
    return sizeof($results);
}
Пример #13
0
function ds()
{
    global $ds_actions, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("ds_rows"));
    input_validate_input_number(get_request_var_request("host_id"));
    input_validate_input_number(get_request_var_request("template_id"));
    input_validate_input_number(get_request_var_request("method_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_rows");
        kill_session_var("sess_ds_host_id");
        kill_session_var("sess_ds_template_id");
        kill_session_var("sess_ds_method_id");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
        unset($_REQUEST["ds_rows"]);
        unset($_REQUEST["host_id"]);
        unset($_REQUEST["template_id"]);
        unset($_REQUEST["method_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("ds_rows", "sess_ds_rows", read_config_option("num_rows_data_source"));
    load_current_session_value("host_id", "sess_ds_host_id", "-1");
    load_current_session_value("template_id", "sess_ds_template_id", "-1");
    load_current_session_value("method_id", "sess_ds_method_id", "-1");
    $host = db_fetch_row("select hostname from host where id=" . get_request_var_request("host_id"));
    /* if the number of rows is -1, set it to the default */
    if (get_request_var_request("ds_rows") == -1) {
        $_REQUEST["ds_rows"] = read_config_option("num_rows_data_source");
    }
    ?>
	<script type="text/javascript">
	<!--

	function applyDSFilterChange(objForm) {
		strURL = '?host_id=' + objForm.host_id.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		strURL = strURL + '&ds_rows=' + objForm.ds_rows.value;
		strURL = strURL + '&template_id=' + objForm.template_id.value;
		strURL = strURL + '&method_id=' + objForm.method_id.value;
		document.location = strURL;
	}

	-->
	</script>
	<?php 
    html_start_box("<strong>Data Sources</strong> [host: " . (empty($host["hostname"]) ? "No Host" : htmlspecialchars($host["hostname"])) . "]", "100%", "", "3", "center", "data_sources.php?action=ds_edit&host_id=" . get_request_var_request("host_id"));
    ?>
	<tr class='even noprint'>
		<td>
		<form name="form_data_sources" action="data_sources.php">
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td width="50">
						Host:&nbsp;
					</td>
					<td>
						<select name="host_id" onChange="applyDSFilterChange(document.form_data_sources)">
							<option value="-1"<?php 
    if (get_request_var_request("host_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
							<option value="0"<?php 
    if (get_request_var_request("host_id") == "0") {
        ?>
 selected<?php 
    }
    ?>
>None</option>
							<?php 
    $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname");
    if (sizeof($hosts) > 0) {
        foreach ($hosts as $host) {
            print "<option value='" . $host["id"] . "'";
            if (get_request_var_request("host_id") == $host["id"]) {
                print " selected";
            }
            print ">" . title_trim(htmlspecialchars($host["name"]), 40) . "</option>\n";
        }
    }
    ?>

						</select>
					</td>
					<td width="50">
						&nbsp;Template:&nbsp;
					</td>
					<td width="1">
						<select name="template_id" onChange="applyDSFilterChange(document.form_data_sources)">
							<option value="-1"<?php 
    if (get_request_var_request("template_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
							<option value="0"<?php 
    if (get_request_var_request("template_id") == "0") {
        ?>
 selected<?php 
    }
    ?>
>None</option>
							<?php 
    $templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name\n\t\t\t\t\t\t\t\tFROM data_template\n\t\t\t\t\t\t\t\tINNER JOIN data_template_data\n\t\t\t\t\t\t\t\tON data_template.id=data_template_data.data_template_id\n\t\t\t\t\t\t\t\tWHERE data_template_data.local_data_id>0\n\t\t\t\t\t\t\t\tORDER BY data_template.name");
    if (sizeof($templates) > 0) {
        foreach ($templates as $template) {
            print "<option value='" . $template["id"] . "'";
            if (get_request_var_request("template_id") == $template["id"]) {
                print " selected";
            }
            print ">" . title_trim(htmlspecialchars($template["name"]), 40) . "</option>\n";
        }
    }
    ?>

						</select>
					</td>
					<td nowrap style='white-space: nowrap;'>
						&nbsp;<input type="submit" value="Go" title="Set/Refresh Filters">
						<input type="submit" name="clear_x" value="Clear" title="Clear Filters">
					</td>
				</tr>
				<tr>
					<td width="50">
						Method:&nbsp;
					</td>
					<td width="1">
						<select name="method_id" onChange="applyDSFilterChange(document.form_data_sources)">
							<option value="-1"<?php 
    if (get_request_var_request("method_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
							<option value="0"<?php 
    if (get_request_var_request("method_id") == "0") {
        ?>
 selected<?php 
    }
    ?>
>None</option>
							<?php 
    $methods = db_fetch_assoc("SELECT DISTINCT data_input.id, data_input.name\n\t\t\t\t\t\t\t\tFROM data_input\n\t\t\t\t\t\t\t\tINNER JOIN data_template_data\n\t\t\t\t\t\t\t\tON data_input.id=data_template_data.data_input_id\n\t\t\t\t\t\t\t\tWHERE data_template_data.local_data_id>0\n\t\t\t\t\t\t\t\tORDER BY data_input.name");
    if (sizeof($methods) > 0) {
        foreach ($methods as $method) {
            print "<option value='" . $method["id"] . "'";
            if (get_request_var_request("method_id") == $method["id"]) {
                print " selected";
            }
            print ">" . title_trim(htmlspecialchars($method["name"]), 40) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="50">
						&nbsp;Rows per Page:&nbsp;
					</td>
					<td width="1">
						<select name="ds_rows" onChange="applyDSFilterChange(document.form_data_sources)">
							<option value="-1"<?php 
    if (get_request_var_request("ds_rows") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Default</option>
							<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request("ds_rows") == $key) {
                print " selected";
            }
            print ">" . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
				</tr>
			</table>
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td width="50">
						Search:&nbsp;
					</td>
					<td width="1">
						<input type="text" name="filter" size="40" value="<?php 
    print htmlspecialchars(get_request_var_request("filter"));
    ?>
">
					</td>
				</tr>
			</table>
			<input type='hidden' name='page' value='1'>
		</form>
		</td>
	</tr>
	<?php 
    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";
}
Пример #14
0
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";

	print '</table></td></tr>';
}
Пример #15
0
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;
}
Пример #16
0
function upgrade_to_0_8_6a()
{
    /* fix import/export template bug */
    $item = db_fetch_assoc("select id from data_template");
    for ($i = 0; $i < count($item); $i++) {
        db_execute("update data_template set hash='" . get_hash_data_template($item[$i]["id"]) . "' where id=" . $item[$i]["id"] . ";");
        $item2 = db_fetch_assoc("select id from data_template_rrd where data_template_id=" . $item[$i]["id"] . " and local_data_id=0");
        for ($j = 0; $j < count($item2); $j++) {
            db_execute("update data_template_rrd set hash='" . get_hash_data_template($item2[$j]["id"], "data_template_item") . "' where id=" . $item2[$j]["id"] . ";");
        }
    }
    $item = db_fetch_assoc("select id from graph_templates");
    for ($i = 0; $i < count($item); $i++) {
        db_execute("update graph_templates set hash='" . get_hash_graph_template($item[$i]["id"]) . "' where id=" . $item[$i]["id"] . ";");
        $item2 = db_fetch_assoc("select id from graph_templates_item where graph_template_id=" . $item[$i]["id"] . " and local_graph_id=0");
        for ($j = 0; $j < count($item2); $j++) {
            db_execute("update graph_templates_item set hash='" . get_hash_graph_template($item2[$j]["id"], "graph_template_item") . "' where id=" . $item2[$j]["id"] . ";");
        }
        $item2 = db_fetch_assoc("select id from graph_template_input where graph_template_id=" . $item[$i]["id"]);
        for ($j = 0; $j < count($item2); $j++) {
            db_execute("update graph_template_input set hash='" . get_hash_graph_template($item2[$j]["id"], "graph_template_input") . "' where id=" . $item2[$j]["id"] . ";");
        }
    }
    /* clean up data template item orphans left behind by the graph->graph template bug */
    $graph_templates = db_fetch_assoc("select id from graph_templates");
    if (sizeof($graph_templates) > 0) {
        foreach ($graph_templates as $graph_template) {
            /* find non-templated graph template items */
            $non_templated_items = array_rekey(db_fetch_assoc("select\n\t\t\t\tgraph_template_input_defs.graph_template_item_id\n\t\t\t\tfrom (graph_template_input,graph_template_input_defs)\n\t\t\t\twhere graph_template_input_defs.graph_template_input_id=graph_template_input.id\n\t\t\t\tand graph_template_input.column_name = 'task_item_id'\n\t\t\t\tand graph_template_input.graph_template_id = '" . $graph_template["id"] . "'"), "graph_template_item_id", "graph_template_item_id");
            /* find all graph items */
            $graph_template_items = db_fetch_assoc("select\n\t\t\t\tgraph_templates_item.id,\n\t\t\t\tgraph_templates_item.task_item_id\n\t\t\t\tfrom graph_templates_item\n\t\t\t\twhere graph_templates_item.graph_template_id = '" . $graph_template["id"] . "'\n\t\t\t\tand graph_templates_item.local_graph_id = 0");
            if (sizeof($graph_template_items) > 0) {
                foreach ($graph_template_items as $graph_template_item) {
                    if (!isset($non_templated_items[$graph_template_item["id"]])) {
                        if ($graph_template_item["task_item_id"] > 0) {
                            $dest_dti = db_fetch_row("select local_data_id from data_template_rrd where id = '" . $graph_template_item["task_item_id"] . "'");
                            /* it's an orphan! */
                            if (!isset($dest_dti["local_data_id"]) || $dest_dti["local_data_id"] > 0) {
                                /* clean graph template */
                                db_execute("update graph_templates_item set task_item_id = 0 where id = '" . $graph_template_item["id"] . "' and local_graph_id = 0 and graph_template_id = '" . $graph_template["id"] . "'");
                                /* clean attached graphs */
                                db_execute("update graph_templates_item set task_item_id = 0 where local_graph_template_item_id = '" . $graph_template_item["id"] . "' and local_graph_id > 0 and graph_template_id = '" . $graph_template["id"] . "'");
                            }
                        }
                    }
                }
            }
        }
    }
    /* make sure the 'host_graph' table is populated (problem from 0.8.4) */
    $hosts = db_fetch_assoc("select id,host_template_id from host where host_template_id > 0");
    if (sizeof($hosts) > 0) {
        foreach ($hosts as $host) {
            $graph_templates = db_fetch_assoc("select graph_template_id from host_template_graph where host_template_id=" . $host["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"] . ")");
                }
            }
        }
    }
}
Пример #17
0
function api_get_graphs_from_datasource($local_data_id) {
	return array_rekey(db_fetch_assoc("SELECT DISTINCT graph_templates_graph.local_graph_id AS id,
		graph_templates_graph.title_cache AS name
		FROM (graph_templates_graph
		INNER JOIN graph_templates_item
		ON graph_templates_graph.local_graph_id=graph_templates_item.local_graph_id)
		INNER JOIN data_template_rrd
		ON graph_templates_item.task_item_id=data_template_rrd.id
		WHERE graph_templates_graph.local_graph_id>0
		AND data_template_rrd.local_data_id=$local_data_id"), "id", "name");
}
Пример #18
0
function graph()
{
    $current_page = get_get_var_number("page", "1");
    $menu_items = array("remove" => "Remove", "duplicate" => "Duplicate", "change_graph_template" => "Change Graph Template", "change_host" => "Change Host", "convert_graph_template" => "Convert to Graph Template", "place_tree" => "Place on Tree");
    $filter_array = array();
    /* search field: device template */
    if (isset_get_var("search_device")) {
        $filter_array["host_id"] = get_get_var("search_device");
    }
    /* search field: filter (searches data source name) */
    if (isset_get_var("search_filter")) {
        $filter_array["filter"] = array("title_cache|title" => get_get_var("search_filter"));
    }
    /* get a list of all graphs on this page */
    $graphs = api_graph_list($filter_array, $current_page, read_config_option("num_rows_data_source"));
    /* get the total number of graphs on all pages */
    $total_rows = api_graph_total_get($filter_array);
    /* generate page list */
    $url_string = build_get_url_string(array("search_device", "search_filter"));
    $url_page_select = get_page_list($current_page, MAX_DISPLAY_PAGES, read_config_option("num_rows_graph"), $total_rows, "graphs.php" . $url_string . ($url_string == "" ? "?" : "&") . "page=|PAGE_NUM|");
    form_start("graphs.php");
    $box_id = "1";
    html_start_box("<strong>" . _("Graphs") . "</strong>", "graphs.php?action=edit", $url_page_select);
    html_header_checkbox(array(_("Graph Title"), _("Template Name"), _("Size")), $box_id);
    $i = 0;
    if (sizeof($graphs) > 0) {
        foreach ($graphs as $graph) {
            ?>
			<tr class="item" id="box-<?php 
            echo $box_id;
            ?>
-row-<?php 
            echo $graph["id"];
            ?>
" onClick="display_row_select('<?php 
            echo $box_id;
            ?>
',document.forms[0],'box-<?php 
            echo $box_id;
            ?>
-row-<?php 
            echo $graph["id"];
            ?>
', 'box-<?php 
            echo $box_id;
            ?>
-chk-<?php 
            echo $graph["id"];
            ?>
')" onMouseOver="display_row_hover('box-<?php 
            echo $box_id;
            ?>
-row-<?php 
            echo $graph["id"];
            ?>
')" onMouseOut="display_row_clear('box-<?php 
            echo $box_id;
            ?>
-row-<?php 
            echo $graph["id"];
            ?>
')">
				<td class="title">
					<a onClick="display_row_block('box-<?php 
            echo $box_id;
            ?>
-row-<?php 
            echo $graph["id"];
            ?>
')" href="graphs.php?action=edit&id=<?php 
            echo $graph["id"];
            ?>
"><span id="box-<?php 
            echo $box_id;
            ?>
-text-<?php 
            echo $graph["id"];
            ?>
"><?php 
            echo html_highlight_words(get_get_var("search_filter"), $graph["title_cache"]);
            ?>
</span></a>
				</td>
				<td>
					<?php 
            echo empty($graph["template_name"]) ? "<em>" . _("None") . "</em>" : $graph["template_name"];
            ?>
				</td>
				<td>
					<?php 
            echo $graph["height"];
            ?>
x<?php 
            echo $graph["width"];
            ?>
				</td>
				<td class="checkbox" align="center">
					<input type='checkbox' name='box-<?php 
            echo $box_id;
            ?>
-chk-<?php 
            echo $graph["id"];
            ?>
' id='box-<?php 
            echo $box_id;
            ?>
-chk-<?php 
            echo $graph["id"];
            ?>
' title="<?php 
            echo $graph["title_cache"];
            ?>
">
				</td>
			</tr>
			<?php 
        }
    } else {
        ?>
		<tr class="empty">
			<td colspan="6">
				No graphs found.
			</td>
		</tr>
		<?php 
    }
    html_box_toolbar_draw($box_id, "0", "3", sizeof($filter_array) == 0 ? HTML_BOX_SEARCH_INACTIVE : HTML_BOX_SEARCH_ACTIVE, $url_page_select);
    html_end_box(false);
    html_box_actions_menu_draw($box_id, "0", $menu_items);
    html_box_actions_area_create($box_id);
    form_hidden_box("action_post", "graph_list");
    form_end();
    /* pre-cache the device list since we need it in more than one place below */
    $device_list = array_rekey(api_device_list(), "id", "description");
    /* fill in the list of available devices for the search dropdown */
    $search_devices = array();
    $search_devices["-1"] = "Any";
    $search_devices["0"] = "None";
    $search_devices += $device_list;
    /* fill in the list of available devices for the change host dropdown */
    $change_host_list = array();
    $change_host_list["0"] = "None";
    $change_host_list += $device_list;
    ?>

	<script language="JavaScript">
	<!--
	function action_area_handle_type(box_id, type, parent_div, parent_form) {
		if (type == 'remove') {
			parent_div.appendChild(document.createTextNode('Are you sure you want to remove these graphs?'));
			parent_div.appendChild(action_area_generate_selected_rows(box_id));

			action_area_update_header_caption(box_id, 'Remove Graph');
			action_area_update_submit_caption(box_id, 'Remove');
			action_area_update_selected_rows(box_id, parent_form);
		}else if (type == 'duplicate') {
			parent_div.appendChild(document.createTextNode('Are you sure you want to duplicate these graphs?'));
			parent_div.appendChild(action_area_generate_selected_rows(box_id));
			parent_div.appendChild(action_area_generate_input('text', 'box-' + box_id + '-action-area-txt1', ''));

			action_area_update_header_caption(box_id, 'Duplicate Graph');
			action_area_update_submit_caption(box_id, 'Duplicate');
			action_area_update_selected_rows(box_id, parent_form);
		}else if (type == 'search') {
			_elm_dt_input = action_area_generate_select('box-' + box_id + '-search_device');
			<?php 
    echo get_js_dropdown_code('_elm_dt_input', $search_devices, isset_get_var("search_device") ? get_get_var("search_device") : "-1");
    ?>

			_elm_ht_input = action_area_generate_input('text', 'box-' + box_id + '-search_filter', '<?php 
    echo get_get_var("search_filter");
    ?>
');
			_elm_ht_input.size = '30';

			parent_div.appendChild(action_area_generate_search_field(_elm_dt_input, 'Device', true, false));
			parent_div.appendChild(action_area_generate_search_field(_elm_ht_input, 'Filter', false, true));

			action_area_update_header_caption(box_id, 'Search');
			action_area_update_submit_caption(box_id, 'Search');
		}else if (type == 'change_host') {
			parent_div.appendChild(document.createTextNode('Are you sure you want to change the host for these graphs?'));
			parent_div.appendChild(action_area_generate_selected_rows(box_id));

			_elm_dt_input = action_area_generate_select('box-' + box_id + '-change_device');
			<?php 
    echo get_js_dropdown_code('_elm_dt_input', $change_host_list, "0");
    ?>

			parent_div.appendChild(action_area_generate_search_field(_elm_dt_input, 'New Device', true, true));

			action_area_update_header_caption(box_id, 'Change Host');
			action_area_update_submit_caption(box_id, 'Change');
			action_area_update_selected_rows(box_id, parent_form);
		}
	}
	-->
	</script>

	<?php 
}
Пример #19
0
function template_edit()
{
    global $colors, $data_source_types;
    if (!empty($_GET["id"])) {
        $data_template = db_fetch_row("select * from data_template where id=" . $_GET["id"]);
        $data_template_items = db_fetch_assoc("select * from data_template_item where data_template_id=" . $_GET["id"]);
        $header_label = _("[edit: ") . $data_template["template_name"] . "]";
    } else {
        $header_label = _("[new]");
    }
    form_start("data_templates.php", "form_data_template");
    /* ==================== Box: Data Template ==================== */
    html_start_box("<strong>" . _("Data Template") . "</strong> {$header_label}");
    _data_template_field__template_name("template_name", isset($data_template) ? $data_template["template_name"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    html_end_box();
    /* ==================== Box: Data Input ==================== */
    /* determine current value for 'data_input_type' */
    if (isset($_GET["data_input_type"])) {
        $_data_input_type = $_GET["data_input_type"];
    } else {
        if (isset($data_template["data_input_type"])) {
            $_data_input_type = $data_template["data_input_type"];
        } else {
            $_data_input_type = DATA_INPUT_TYPE_SCRIPT;
        }
    }
    /* get a list of all data input type fields for this data template */
    if (isset($data_template)) {
        $data_input_type_fields = array_rekey(db_fetch_assoc("select name,t_value,value from data_template_field where data_template_id = " . $data_template["id"]), "name", array("t_value", "value"));
    } else {
        $data_input_type_fields = array();
    }
    html_start_box("<strong>" . _("Data Input") . "</strong>");
    _data_source_input_field__data_input_type("data_input_type", true, $_data_input_type, empty($_GET["id"]) ? 0 : $_GET["id"]);
    /* grab the appropriate data input type form array */
    if ($_data_input_type == DATA_INPUT_TYPE_SCRIPT) {
        $scripts = api_script_list();
        if (sizeof($scripts) > 0) {
            /* determine current value for 'script_id' */
            if (isset($_GET["script_id"]) && is_numeric($_GET["script_id"])) {
                $_script_id = $_GET["script_id"];
            } else {
                if (isset($data_input_type_fields["script_id"])) {
                    $_script_id = $data_input_type_fields["script_id"]["value"];
                } else {
                    /* default to the first item in the script list */
                    $_script_id = $scripts[0]["id"];
                }
            }
            field_row_header(_("External Script"));
            _data_source_input_field__script_id("dif_script_id", "data_templates.php?action=edit" . (!empty($_GET["id"]) ? "&id=" . $_GET["id"] : "") . "&data_input_type={$_data_input_type}&script_id=|dropdown_value|", $_script_id);
            /* get each INPUT field for this script */
            $script_input_fields = db_fetch_assoc("select * from data_input_fields where data_input_id = {$_script_id} and input_output='in' order by name");
            if (sizeof($script_input_fields) > 0) {
                field_row_header(_("Custom Input Fields"));
                foreach ($script_input_fields as $field) {
                    _data_source_input_field__script("dif_" . $field["data_name"], $field["name"], true, isset($data_input_type_fields[$field["data_name"]]) ? $data_input_type_fields[$field["data_name"]]["value"] : "", "t_dif_" . $field["data_name"], isset($data_input_type_fields[$field["data_name"]]) ? $data_input_type_fields[$field["data_name"]]["t_value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                }
            }
        }
    } else {
        if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) {
            /* since the "sql" key is not executed until draw_edit_form(), we have fetch the list of
             * data queries here as well */
            $data_queries = api_data_query_list();
            if (sizeof($data_queries) > 0) {
                /* determine current value for 'data_query_id' */
                if (isset($_GET["data_query_id"]) && is_numeric($_GET["data_query_id"])) {
                    $_data_query_id = $_GET["data_query_id"];
                } else {
                    if (isset($data_input_type_fields["data_query_id"])) {
                        $_data_query_id = $data_input_type_fields["data_query_id"]["value"];
                    } else {
                        /* default to the first item in the data query list */
                        $_data_query_id = $data_queries[0]["id"];
                    }
                }
                field_row_header(_("Data Query"));
                _data_source_input_field__data_query_id("dif_data_query_id", "data_templates.php?action=edit" . (!empty($_GET["id"]) ? "&id=" . $_GET["id"] : "") . "&data_input_type={$_data_input_type}&data_query_id=|dropdown_value|", $_data_query_id);
            }
        } else {
            if ($_data_input_type == DATA_INPUT_TYPE_SNMP) {
                _data_source_input_field__device_hdr_generic();
                _data_source_input_field__device_snmp_port("dif_snmp_port", true, isset($data_input_type_fields["snmp_port"]) ? $data_input_type_fields["snmp_port"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_port"]) ? $data_input_type_fields["snmp_port"]["t_value"] : "0", isset($data_input_type_fields["snmp_port"]) ? "on" : "");
                _data_source_input_field__device_snmp_timeout("dif_snmp_timeout", true, isset($data_input_type_fields["snmp_timeout"]) ? $data_input_type_fields["snmp_timeout"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_timeout"]) ? $data_input_type_fields["snmp_timeout"]["t_value"] : "0", isset($data_input_type_fields["snmp_timeout"]) ? "on" : "");
                _data_source_input_field__device_snmp_version("dif_snmp_version", true, isset($data_input_type_fields["snmp_version"]) ? $data_input_type_fields["snmp_version"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_version"]) ? $data_input_type_fields["snmp_version"]["t_value"] : "0", isset($data_input_type_fields["snmp_version"]) ? "on" : "");
                _data_source_input_field__device_hdr_snmpv12();
                _data_source_input_field__device_snmp_community("dif_snmp_community", true, isset($data_input_type_fields["snmp_community"]) ? $data_input_type_fields["snmp_community"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_community"]) ? $data_input_type_fields["snmp_community"]["t_value"] : "0", isset($data_input_type_fields["snmp_community"]) ? "on" : "");
                _data_source_input_field__device_hdr_snmpv3();
                _data_source_input_field__device_snmpv3_auth_username("dif_snmpv3_auth_username", true, isset($data_input_type_fields["snmpv3_auth_username"]) ? $data_input_type_fields["snmpv3_auth_username"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_auth_username"]) ? $data_input_type_fields["snmpv3_auth_username"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_auth_username"]) ? "on" : "");
                _data_source_input_field__device_snmpv3_auth_password("dif_snmpv3_auth_password", true, isset($data_input_type_fields["snmpv3_auth_password"]) ? $data_input_type_fields["snmpv3_auth_password"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_auth_password"]) ? $data_input_type_fields["snmpv3_auth_password"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_auth_password"]) ? "on" : "");
                _data_source_input_field__device_snmpv3_auth_protocol("dif_snmpv3_auth_protocol", true, isset($data_input_type_fields["snmpv3_auth_protocol"]) ? $data_input_type_fields["snmpv3_auth_protocol"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_auth_protocol"]) ? $data_input_type_fields["snmpv3_auth_protocol"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_auth_protocol"]) ? "on" : "");
                _data_source_input_field__device_snmpv3_priv_passphrase("dif_snmpv3_priv_passphrase", true, isset($data_input_type_fields["snmpv3_priv_passphrase"]) ? $data_input_type_fields["snmpv3_priv_passphrase"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_priv_passphrase"]) ? $data_input_type_fields["snmpv3_priv_passphrase"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_priv_passphrase"]) ? "on" : "");
                _data_source_input_field__device_snmpv3_priv_protocol("dif_snmpv3_priv_protocol", true, isset($data_input_type_fields["snmpv3_priv_protocol"]) ? $data_input_type_fields["snmpv3_priv_protocol"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_priv_protocol"]) ? $data_input_type_fields["snmpv3_priv_protocol"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_priv_protocol"]) ? "on" : "");
            }
        }
    }
    html_end_box();
    /* ==================== Box: Data Source ==================== */
    $rra_items = api_data_template_rra_item_list($data_template["id"]);
    /* the user clicked the "add item" link. we need to make sure they get redirected back to
     * this page if an error occurs */
    if ($_GET["action"] == "sv_add") {
        form_hidden_box("redirect_sv_add", "x", "");
    }
    html_start_box("<strong>" . _("Data Source") . "</strong>");
    _data_source_field__name("name", true, empty($_GET["id"]) ? 0 : $_GET["id"], "t_name", isset($data_template["t_name"]) ? $data_template["t_name"] : "");
    _data_source_field__rra("preset_rra_id", true, isset($data_template["preset_rra_id"]) ? $data_template["preset_rra_id"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    _data_source_field__polling_interval("polling_interval", true, isset($data_template["polling_interval"]) ? $data_template["polling_interval"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_polling_interval", isset($data_template["t_polling_interval"]) ? $data_template["t_polling_interval"] : "");
    _data_source_field__active("active", true, isset($data_template["active"]) ? $data_template["active"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_active", isset($data_template["t_active"]) ? $data_template["t_active"] : "");
    html_end_box();
    /* ==================== Box: Data Source Item ==================== */
    html_start_box("<strong>" . _("Data Source Item") . "</strong>", empty($_GET["id"]) ? "" : "javascript:document.forms[0].action.value='item_add';submit_redirect(0, '" . htmlspecialchars("data_templates.php?action=item_add&id=" . $_GET["id"]) . "', '')");
    /* the user clicked the "add item" link. we need to make sure they get redirected back to
     * this page if an error occurs */
    if ($_GET["action"] == "item_add") {
        form_hidden_box("redirect_item_add", "x", "");
    }
    /* this allows a "blank" data template item to be displayed when the user wants to create
     * a new one */
    if (!isset($data_template_items) || sizeof($data_template_items) == 0 || $_GET["action"] == "item_add") {
        if (isset($data_template_items)) {
            $next_index = sizeof($data_template_items);
        } else {
            $next_index = 0;
        }
        $data_template_items[$next_index] = array();
    }
    if (sizeof($data_template_items) > 0) {
        if ($_data_input_type == DATA_INPUT_TYPE_SCRIPT) {
            $script_output_fields = db_fetch_assoc("select * from data_input_fields where data_input_id = {$_script_id} and input_output='out' order by name");
            $field_input_description = _("Script Output Field");
        } else {
            if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) {
                $field_list = api_data_query_field_list($_data_query_id, DATA_QUERY_FIELD_TYPE_OUTPUT);
                $data_query_output_fields = array();
                if (sizeof($field_list) > 0) {
                    foreach ($field_list as $field) {
                        $data_query_output_fields[$field["name"]] = $field["name"] . " (" . $field["name_desc"] . ")";
                    }
                }
                $field_input_description = _("Data Query Output Field");
            } else {
                if ($_data_input_type == DATA_INPUT_TYPE_SNMP) {
                    $field_input_description = _("SNMP OID");
                }
            }
        }
        foreach ($data_template_items as $item) {
            if ($_data_input_type != DATA_INPUT_TYPE_NONE) {
                ?>
				<tr bgcolor="<?php 
                print $colors["header_panel_background"];
                ?>
">
					<td class='textSubHeaderDark' colspan="2">
						<?php 
                print isset($item["data_source_name"]) ? $item["data_source_name"] : "(" . _("New Data Template Item") . ")";
                ?>
					</td>
					<td class='textSubHeaderDark' align='right'>
						<?php 
                if (isset($item["id"]) && sizeof($data_template_items) > 1) {
                    print "[<a href='data_templates.php?action=item_remove&id=" . $item["id"] . "&data_template_id=" . $item["data_template_id"] . "' class='linkOverDark'>remove</a>]\n";
                }
                ?>
					</td>
				</tr>
				<tr bgcolor="#e1e1e1">
					<td width="50%" style="border-bottom: 1px solid #a1a1a1;">
						<font class='textEditTitle'>Field Input: <?php 
                print $field_input_description;
                ?>
</font><br>
					</td>
					<td style="border-bottom: 1px solid #a1a1a1;" colspan="2">
						<?php 
                if ($_data_input_type == DATA_INPUT_TYPE_SCRIPT) {
                    form_dropdown("dsi|field_input_value|" . (isset($item["id"]) ? $item["id"] : "0"), $script_output_fields, "name", "data_name", isset($item["field_input_value"]) ? $item["field_input_value"] : "", "", "");
                } else {
                    if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) {
                        form_dropdown("dsi|field_input_value|" . (isset($item["id"]) ? $item["id"] : "0"), $data_query_output_fields, "", "", isset($item["field_input_value"]) ? $item["field_input_value"] : "", "", "");
                    } else {
                        if ($_data_input_type == DATA_INPUT_TYPE_SNMP) {
                            form_text_box("dsi|field_input_value|" . (isset($item["id"]) ? $item["id"] : "0"), isset($item["field_input_value"]) ? $item["field_input_value"] : "", "", "100", 40, "text", 0);
                        }
                    }
                }
                ?>
					</td>
				</tr>
				<?php 
            }
            $_field_id = isset($item["id"]) ? $item["id"] : 0;
            field_reset_row_color();
            field_increment_row_color();
            _data_source_item_field__data_source_name("dsi|data_source_name|{$_field_id}", true, isset($item["data_source_name"]) ? $item["data_source_name"] : "", $_field_id);
            _data_source_item_field__rrd_minimum("dsi|rrd_minimum|{$_field_id}", true, isset($item["rrd_minimum"]) ? $item["rrd_minimum"] : "", $_field_id, "dsi|t_rrd_minimum|{$_field_id}", isset($item["t_rrd_minimum"]) ? $item["t_rrd_minimum"] : "");
            _data_source_item_field__rrd_maximum("dsi|rrd_maximum|{$_field_id}", true, isset($item["rrd_maximum"]) ? $item["rrd_maximum"] : "", $_field_id, "dsi|t_rrd_maximum|{$_field_id}", isset($item["t_rrd_maximum"]) ? $item["t_rrd_maximum"] : "");
            _data_source_item_field__data_source_type("dsi|data_source_type|{$_field_id}", true, isset($item["data_source_type"]) ? $item["data_source_type"] : "", $_field_id, "dsi|t_data_source_type|{$_field_id}", isset($item["t_data_source_type"]) ? $item["t_data_source_type"] : "");
            _data_source_item_field__rrd_heartbeat("dsi|rrd_heartbeat|{$_field_id}", true, isset($item["rrd_heartbeat"]) ? $item["rrd_heartbeat"] : "", $_field_id, "dsi|t_rrd_heartbeat|{$_field_id}", isset($item["t_rrd_heartbeat"]) ? $item["t_rrd_heartbeat"] : "");
        }
    }
    html_end_box();
    form_hidden_box("data_template_id", empty($_GET["id"]) ? 0 : $_GET["id"], "");
    form_hidden_box("action_post", "data_template_edit");
    form_save_button("data_templates.php");
}
Пример #20
0
function substitute_data_input_data($string, $graph, $local_data_id, $max_chars = 0)
{
    if (empty($local_data_id)) {
        if (isset($graph['local_graph_id'])) {
            $local_data_ids = array_rekey(db_fetch_assoc_prepared('SELECT DISTINCT local_data_id
				FROM data_template_rrd
				INNER JOIN graph_templates_item
				ON data_template_rrd.id = graph_templates_item.task_item_id
				WHERE local_graph_id = ?', array($graph['local_graph_id'])), 'local_data_id', 'local_data_id');
            if (sizeof($local_data_ids)) {
                $data_template_data_id = db_fetch_cell('SELECT id FROM data_template_data WHERE local_data_id IN (' . implode(',', $local_data_ids) . ')');
            } else {
                $data_template_data_id = 0;
            }
        } else {
            $data_template_data_id = 0;
        }
    } else {
        $data_template_data_id = db_fetch_cell_prepared('SELECT id FROM data_template_data WHERE local_data_id = ?', array($local_data_id));
    }
    if (!empty($data_template_data_id)) {
        $data = db_fetch_assoc_prepared("SELECT\n\t\t\tdif.data_name, did.value\n\t\t\tFROM data_input_fields AS dif\n\t\t\tINNER JOIN data_input_data AS did\n\t\t\tON dif.id = did.data_input_field_id\n\t\t\tWHERE data_template_data_id = ?\n\t\t\tAND input_output = 'in'", array($data_template_data_id));
        if (sizeof($data)) {
            foreach ($data as $item) {
                if ($item['value'] != '') {
                    if ($max_chars > 0) {
                        $item['value'] = substr($item['field_value'], 0, $max_chars);
                    }
                    $string = stri_replace('|input_' . $item['data_name'] . '|', $item['value'], $string);
                }
            }
        }
    }
    return $string;
}
Пример #21
0
function form_save() {
	if (isset($_POST["save_component_item"])) {
		/* ================= input validation ================= */
		input_validate_input_number(get_request_var_post("graph_template_id"));
		input_validate_input_number(get_request_var_post("task_item_id"));
		/* ==================================================== */

		global $graph_item_types;

		$items[0] = array();

		if ($graph_item_types{$_POST["graph_type_id"]} == "LEGEND") {
			/* this can be a major time saver when creating lots of graphs with the typical
			GPRINT LAST/AVERAGE/MAX legends */
			$items = array(
				0 => array(
					"color_id" => "0",
					"graph_type_id" => "9",
					"consolidation_function_id" => "4",
					"text_format" => "Current:",
					"hard_return" => ""
					),
				1 => array(
					"color_id" => "0",
					"graph_type_id" => "9",
					"consolidation_function_id" => "1",
					"text_format" => "Average:",
					"hard_return" => ""
					),
				2 => array(
					"color_id" => "0",
					"graph_type_id" => "9",
					"consolidation_function_id" => "3",
					"text_format" => "Maximum:",
					"hard_return" => "on"
					));
		}

		foreach ($items as $item) {
			/* generate a new sequence if needed */
			if (empty($_POST["sequence"])) {
				$_POST["sequence"] = get_sequence($_POST["sequence"], "sequence", "graph_templates_item", "graph_template_id=" . $_POST["graph_template_id"] . " and local_graph_id=0");
			}

			$save["id"] = $_POST["graph_template_item_id"];
			$save["hash"] = get_hash_graph_template($_POST["graph_template_item_id"], "graph_template_item");
			$save["graph_template_id"] = $_POST["graph_template_id"];
			$save["local_graph_id"] = 0;
			$save["task_item_id"] = form_input_validate($_POST["task_item_id"], "task_item_id", "", true, 3);
			$save["color_id"] = form_input_validate((isset($item["color_id"]) ? $item["color_id"] : $_POST["color_id"]), "color_id", "", true, 3);
			/* if alpha is disabled, use invisible_alpha instead */
			if (!isset($_POST["alpha"])) {$_POST["alpha"] = $_POST["invisible_alpha"];}
			$save["alpha"] = form_input_validate((isset($item["alpha"]) ? $item["alpha"] : $_POST["alpha"]), "alpha", "", true, 3);
			$save["graph_type_id"] = form_input_validate((isset($item["graph_type_id"]) ? $item["graph_type_id"] : $_POST["graph_type_id"]), "graph_type_id", "", true, 3);
			$save["cdef_id"] = form_input_validate($_POST["cdef_id"], "cdef_id", "", true, 3);
			$save["consolidation_function_id"] = form_input_validate((isset($item["consolidation_function_id"]) ? $item["consolidation_function_id"] : $_POST["consolidation_function_id"]), "consolidation_function_id", "", true, 3);
			$save["text_format"] = form_input_validate((isset($item["text_format"]) ? $item["text_format"] : $_POST["text_format"]), "text_format", "", true, 3);
			$save["value"] = form_input_validate($_POST["value"], "value", "", true, 3);
			$save["hard_return"] = form_input_validate(((isset($item["hard_return"]) ? $item["hard_return"] : (isset($_POST["hard_return"]) ? $_POST["hard_return"] : ""))), "hard_return", "", true, 3);
			$save["gprint_id"] = form_input_validate($_POST["gprint_id"], "gprint_id", "", true, 3);
			$save["sequence"] = $_POST["sequence"];

			if (!is_error_message()) {
				/* Before we save the item, let's get a look at task_item_id <-> input associations */
				$orig_data_source_graph_inputs = db_fetch_assoc("select
					graph_template_input.id,
					graph_template_input.name,
					graph_templates_item.task_item_id
					from (graph_template_input,graph_template_input_defs,graph_templates_item)
					where graph_template_input.id=graph_template_input_defs.graph_template_input_id
					and graph_template_input_defs.graph_template_item_id=graph_templates_item.id
					and graph_template_input.graph_template_id=" . $save["graph_template_id"] . "
					and graph_template_input.column_name='task_item_id'
					group by graph_templates_item.task_item_id");

				$orig_data_source_to_input = array_rekey($orig_data_source_graph_inputs, "task_item_id", "id");

				$graph_template_item_id = sql_save($save, "graph_templates_item");

				if ($graph_template_item_id) {
					raise_message(1);

					if (!empty($save["task_item_id"])) {
						/* old item clean-up.  Don't delete anything if the item <-> task_item_id association remains the same. */
						if ($_POST["_task_item_id"] != $_POST["task_item_id"]) {
							/* It changed.  Delete any old associations */
							db_execute("delete from graph_template_input_defs where graph_template_item_id=$graph_template_item_id");

							/* Input for current data source exists and has changed.  Update the association */
							if (isset($orig_data_source_to_input{$save["task_item_id"]})) {
								db_execute("replace into graph_template_input_defs (graph_template_input_id,
								graph_template_item_id) values (" . $orig_data_source_to_input{$save["task_item_id"]}
								. ",$graph_template_item_id)");
							}
						}

						/* an input for the current data source does NOT currently exist, let's create one */
						if (!isset($orig_data_source_to_input{$save["task_item_id"]})) {
							$ds_name = db_fetch_cell("select data_source_name from data_template_rrd where id=" . $_POST["task_item_id"]);

							db_execute("replace into graph_template_input (hash,graph_template_id,name,column_name) values (
								'" . get_hash_graph_template(0, "graph_template_input") . "'," . $save["graph_template_id"] . ",
								'Data Source [$ds_name]','task_item_id')");

							$graph_template_input_id = db_fetch_insert_id();

							$graph_items = db_fetch_assoc("select id from graph_templates_item where graph_template_id=" . $save["graph_template_id"] . " and task_item_id=" . $_POST["task_item_id"]);

							if (sizeof($graph_items) > 0) {
							foreach ($graph_items as $graph_item) {
								db_execute("replace into graph_template_input_defs (graph_template_input_id,graph_template_item_id) values ($graph_template_input_id," . $graph_item["id"] . ")");
							}
							}
						}
					}

					push_out_graph_item($graph_template_item_id);

					if (isset($orig_data_source_to_input{$_POST["task_item_id"]})) {
						/* make sure all current graphs using this graph input are aware of this change */
						push_out_graph_input($orig_data_source_to_input{$_POST["task_item_id"]}, $graph_template_item_id, array($graph_template_item_id => $graph_template_item_id));
					}
				}else{
					raise_message(2);
				}
			}

			$_POST["sequence"] = 0;
		}

		if (is_error_message()) {
			header("Location: graph_templates_items.php?action=item_edit&graph_template_item_id=" . (empty($graph_template_item_id) ? $_POST["graph_template_item_id"] : $graph_template_item_id) . "&id=" . $_POST["graph_template_id"]);
			exit;
		}else{
			header("Location: graph_templates.php?action=template_edit&id=" . $_POST["graph_template_id"]);
			exit;
		}
	}
}
Пример #22
0
function form_actions()
{
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $rows = db_fetch_assoc("\r\n            SELECT graph_local.id FROM graph_local \r\n                INNER JOIN host ON graph_local.host_id = host.id\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) {
            $graphs[] = $row["id"];
        }
    }
    /* modify for multi user end */
    global $colors, $graph_actions;
    /* 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], $graphs)) {
                    access_denied();
                }
            }
        }
        /* modify for multi user end */
        if ($_POST["drp_action"] == "1") {
            /* delete */
            if (!isset($_POST["delete_type"])) {
                $_POST["delete_type"] = 1;
            }
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
            }
            switch ($_POST["delete_type"]) {
                case '2':
                    /* delete all data sources referenced by this graph */
                    $data_sources = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id\r\n\t\t\t\t\t\tFROM (data_template_rrd, data_template_data, graph_templates_item)\r\n\t\t\t\t\t\tWHERE graph_templates_item.task_item_id=data_template_rrd.id\r\n\t\t\t\t\t\tAND data_template_rrd.local_data_id=data_template_data.local_data_id\r\n\t\t\t\t\t\tAND " . array_to_sql_or($selected_items, "graph_templates_item.local_graph_id") . "\r\n\t\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_plugin_hook_function('data_source_remove', $data_sources);
                    }
                    break;
            }
            api_graph_remove_multi($selected_items);
            api_plugin_hook_function('graphs_remove', $selected_items);
        } elseif ($_POST["drp_action"] == "2") {
            /* change graph template */
            input_validate_input_number(get_request_var_post("graph_template_id"));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                change_graph_template($selected_items[$i], $_POST["graph_template_id"], true);
            }
        } elseif ($_POST["drp_action"] == "3") {
            /* duplicate */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                duplicate_graph($selected_items[$i], 0, $_POST["title_format"]);
            }
        } elseif ($_POST["drp_action"] == "4") {
            /* graph -> graph template */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                graph_to_graph_template($selected_items[$i], $_POST["title_format"]);
            }
        } elseif (preg_match("/^tr_([0-9]+)\$/", $_POST["drp_action"], $matches)) {
            /* place on tree */
            input_validate_input_number(get_request_var_post("tree_id"));
            input_validate_input_number(get_request_var_post("tree_item_id"));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_GRAPH, $_POST["tree_item_id"], "", $selected_items[$i], read_graph_config_option("default_rra_id"), 0, 0, 0, false);
            }
        } elseif ($_POST["drp_action"] == "5") {
            /* change host */
            input_validate_input_number(get_request_var_post("host_id"));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update graph_local set host_id=" . $_POST["host_id"] . " where id=" . $selected_items[$i]);
                update_graph_title_cache($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "6") {
            /* reapply suggested naming */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_reapply_suggested_graph_title($selected_items[$i]);
                update_graph_title_cache($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "7") {
            /* resize graphs */
            input_validate_input_number(get_request_var_post("graph_width"));
            input_validate_input_number(get_request_var_post("graph_height"));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_resize_graphs($selected_items[$i], $_POST["graph_width"], $_POST["graph_height"]);
            }
        } else {
            api_plugin_hook_function('graphs_action_execute', $_POST['drp_action']);
        }
        header("Location: graphs.php");
        exit;
    }
    /* setup some variables */
    $graph_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]);
            /* ==================================================== */
            /* modify for multi user start */
            if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                if (!in_array($matches[1], $graphs)) {
                    access_denied();
                }
            }
            /* modify for multi user end */
            $graph_list .= "<li>" . get_graph_title($matches[1]) . "</li>";
            $graph_array[$i] = $matches[1];
            $i++;
        }
    }
    include_once "./include/top_header.php";
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    html_start_box("<strong>" . $graph_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel"], "3", "center", "");
    print "<form action='graphs.php' method='post'>\n";
    if (isset($graph_array) && sizeof($graph_array)) {
        if ($_POST["drp_action"] == "1") {
            /* delete */
            $graphs = array();
            /* find out which (if any) data sources are being used by this graph, so we can tell the user */
            if (isset($graph_array) && sizeof($graph_array)) {
                $data_sources = db_fetch_assoc("select\r\n\t\t\t\t\tdata_template_data.local_data_id,\r\n\t\t\t\t\tdata_template_data.name_cache\r\n\t\t\t\t\tfrom (data_template_rrd,data_template_data,graph_templates_item)\r\n\t\t\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\r\n\t\t\t\t\tand data_template_rrd.local_data_id=data_template_data.local_data_id\r\n\t\t\t\t\tand " . array_to_sql_or($graph_array, "graph_templates_item.local_graph_id") . "\r\n\t\t\t\t\tand data_template_data.local_data_id > 0\r\n\t\t\t\t\tgroup by data_template_data.local_data_id\r\n\t\t\t\t\torder by data_template_data.name_cache");
            }
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be deleted.  Please note, Data Source(s) should be deleted only if they are only used by these Graph(s)\r\n\t\t\t\t\t\tand not others.</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>";
            if (isset($data_sources) && sizeof($data_sources)) {
                print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td class='textArea'><p class='textArea'>The following Data Source(s) are in use by these Graph(s):</p>\n";
                print "<ul>";
                foreach ($data_sources as $data_source) {
                    print "<li><strong>" . $data_source["name_cache"] . "</strong></li>\n";
                }
                print "</ul>";
                print "<br>";
                form_radio_button("delete_type", "1", "1", "Leave the Data Source(s) untouched.", "1");
                print "<br>";
                form_radio_button("delete_type", "1", "2", "Delete all <strong>Data Source(s)</strong> referenced by these Graph(s).", "1");
                print "<br>";
                print "</td></tr>";
            }
            print "\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Graph(s)'>";
        } elseif ($_POST["drp_action"] == "2") {
            /* change graph template */
            /* modify for multi user start */
            $sql_where = "";
            if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                $sql_where = "WHERE graph_templates.name NOT LIKE '%@system'";
            }
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>Choose a Graph Template and click \"Continue\" to change the Graph Template for\r\n\t\t\t\t\t\tthe following Graph(s). Be aware that all warnings will be suppressed during the\r\n\t\t\t\t\t\tconversion, so Graph data loss is possible.</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>New Graph Template:</strong><br>";
            form_dropdown("graph_template_id", db_fetch_assoc("select graph_templates.id,graph_templates.name from graph_templates {$sql_where} order by name"), "name", "id", "", "", "0");
            print "</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            /* modify for multi user end */
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Graph Template'>";
        } elseif ($_POST["drp_action"] == "3") {
            /* duplicate */
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be duplicated. You can\r\n\t\t\t\t\t\toptionally change the title format for the new Graph(s).</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box("title_format", "<graph_title> (1)", "", "255", "30", "text");
            print "</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Duplicate Graph(s)'>";
        } elseif ($_POST["drp_action"] == "4") {
            /* graph -> graph template */
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be converted into Graph Template(s).\r\n\t\t\t\t\t\tYou can optionally change the title format for the new Graph Template(s).</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box("title_format", "<graph_title> Template", "", "255", "30", "text");
            print "</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Convert to Graph Template'>";
        } elseif (preg_match("/^tr_([0-9]+)\$/", $_POST["drp_action"], $matches)) {
            /* place on tree */
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be placed under the Tree Branch selected below.</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>Destination Branch:</strong><br>";
            grow_dropdown_tree($matches[1], "tree_item_id", "0");
            print "</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Place Graph(s) on Tree'>";
        } elseif ($_POST["drp_action"] == "5") {
            /* change host */
            /* modify for multi user start */
            if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                $sql_join = "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'";
            }
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>Choose a new Device for these Graph(s) and click \"Continue\"</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>New Host:</strong><br>";
            form_dropdown("host_id", db_fetch_assoc("select host.id,CONCAT_WS('',host.description,' (',host.hostname,')') as name from host order by description,hostname"), "name", "id", "", "", "0");
            print "</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            /* modify for multi user end */
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Graph(s) Associated Device'>";
        } elseif ($_POST["drp_action"] == "6") {
            /* reapply suggested naming to host */
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will have thier suggested naming convensions\r\n\t\t\t\t\t\trecalculated and applied to the Graph(s).</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Reapply Suggested Naming to Graph(s)'>";
        } elseif ($_POST["drp_action"] == "7") {
            /* resize graphs */
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be resized per your specifications.</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>Graph Height:</strong><br>";
            form_text_box("graph_height", "", "", "255", "30", "text");
            print "</p>\r\n\t\t\t\t\t\t<p><strong>Graph Width:</strong><br>";
            form_text_box("graph_width", "", "", "255", "30", "text");
            print "</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Resize Selected Graph(s)'>";
        } else {
            $save['drp_action'] = $_POST['drp_action'];
            $save['graph_list'] = $graph_list;
            $save['graph_array'] = isset($graph_array) ? $graph_array : array();
            api_plugin_hook_function('graphs_action_prepare', $save);
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
        }
    } else {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one graph.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\r\n\t\t\t<td align='right' bgcolor='#eaeaea'>\r\n\t\t\t\t<input type='hidden' name='action' value='actions'>\r\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($graph_array) ? serialize($graph_array) : '') . "'>\r\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\r\n\t\t\t\t{$save_html}\r\n\t\t\t</td>\r\n\t\t</tr>\r\n\t\t";
    html_end_box();
    include_once "./include/bottom_footer.php";
}
Пример #23
0
	$print_data_to_stdout = true;
	/* Get number of polling items from the database */
	$hosts = db_fetch_assoc("select * from host where disabled = '' order by id");
	$hosts = array_rekey($hosts,"id",$host_struc);
	$host_count = sizeof($hosts);
	$script_server_calls = db_fetch_cell("SELECT count(*) from poller_item WHERE action=2");
}else{
	$print_data_to_stdout = false;
	if ($_SERVER["argc"] == "3") {
		if ($_SERVER["argv"][1] <= $_SERVER["argv"][2]) {
			$hosts = db_fetch_assoc("select * from host where (disabled = '' and " .
					"id >= " .
					$_SERVER["argv"][1] .
					" and id <= " .
					$_SERVER["argv"][2] . ") ORDER by id");
			$hosts = array_rekey($hosts,"id",$host_struc);
			$host_count = sizeof($hosts);

			$polling_items = db_fetch_assoc("SELECT * from poller_item " .
					"WHERE (host_id >= " .
					$_SERVER["argv"][1] .
					" and host_id <= " .
					$_SERVER["argv"][2] . ") ORDER by host_id");

			$script_server_calls = db_fetch_cell("SELECT count(*) from poller_item " .
					"WHERE (action=2 AND (host_id >= " .
					$_SERVER["argv"][1] .
					" and host_id <= " .
					$_SERVER["argv"][2] . "))");
		}else{
			print "ERROR: Invalid Arguments.  The first argument must be less than or equal to the first.\n";
Пример #24
0
function update_poller_cache($local_data_id, $commit = false) {
	global $config;
	require_once(CACTI_BASE_PATH . "/include/data_input/data_input_constants.php");
	include_once(CACTI_BASE_PATH . "/lib/data_query.php");
	include_once(CACTI_BASE_PATH . "/lib/api_poller.php");

	$poller_items = array();

	$data_input = db_fetch_row("select
		data_input.id,
		data_input.type_id,
		data_template_data.id as data_template_data_id,
		data_template_data.data_template_id,
		data_template_data.active,
		data_template_data.rrd_step
		from (data_template_data,data_input)
		where data_template_data.data_input_id=data_input.id
		and data_template_data.local_data_id=$local_data_id");

	$data_source = db_fetch_row("select device_id,snmp_query_id,snmp_index from data_local where id=$local_data_id");

	/* we have to perform some additional sql queries if this is a "query" */
	if (($data_input["type_id"] == DATA_INPUT_TYPE_SNMP_QUERY) ||
		($data_input["type_id"] == DATA_INPUT_TYPE_SCRIPT_QUERY) ||
		($data_input["type_id"] == DATA_INPUT_TYPE_QUERY_SCRIPT_SERVER)){
		$field = data_query_field_list($data_input["data_template_data_id"]);

		if (strlen($field["output_type"])) {
			$output_type_sql = "and snmp_query_graph_rrd.snmp_query_graph_id=" . $field["output_type"];
		}else{
			$output_type_sql = "";
		}

		$outputs = db_fetch_assoc("select
			snmp_query_graph_rrd.snmp_field_name,
			data_template_rrd.id as data_template_rrd_id
			from (snmp_query_graph_rrd,data_template_rrd)
			where snmp_query_graph_rrd.data_template_rrd_id=data_template_rrd.local_data_template_rrd_id
			$output_type_sql
			and snmp_query_graph_rrd.data_template_id=" . $data_input["data_template_id"] . "
			and data_template_rrd.local_data_id=$local_data_id");
	}

	if ($data_input["active"] == CHECKED) {
		if (($data_input["type_id"] == DATA_INPUT_TYPE_SCRIPT) || ($data_input["type_id"] == DATA_INPUT_TYPE_PHP_SCRIPT_SERVER)) { /* script */
			/* fall back to non-script server actions if the user is running a version of php older than 4.3 */
			if (($data_input["type_id"] == DATA_INPUT_TYPE_PHP_SCRIPT_SERVER) && (function_exists("proc_open"))) {
				$action = POLLER_ACTION_SCRIPT_PHP;
				$script_path = get_full_script_path($local_data_id);
			}else if (($data_input["type_id"] == DATA_INPUT_TYPE_PHP_SCRIPT_SERVER) && (!function_exists("proc_open"))) {
				$action = POLLER_ACTION_SCRIPT;
				$script_path = read_config_option("path_php_binary") . " -q " . get_full_script_path($local_data_id);
			}else{
				$action = POLLER_ACTION_SCRIPT;
				$script_path = get_full_script_path($local_data_id);
			}

			$num_output_fields = sizeof(db_fetch_assoc("select id from data_input_fields where data_input_id=" . $data_input["id"] . " and input_output='out' and update_rra='on'"));

			if ($num_output_fields == 1) {
				$data_template_rrd_id = db_fetch_cell("select id from data_template_rrd where local_data_id=$local_data_id");
				$data_source_item_name = get_data_source_item_name($data_template_rrd_id);
			}else{
				$data_source_item_name = "";
			}

			$poller_items[] = api_poller_cache_item_add($data_source["device_id"], array(), $local_data_id, $data_input["rrd_step"], $action, $data_source_item_name, 1, addslashes($script_path));
		}else if ($data_input["type_id"] == DATA_INPUT_TYPE_SNMP) { /* snmp */
			/* get the device override fields */
			$data_template_id = db_fetch_cell("SELECT data_template_id FROM data_template_data WHERE local_data_id=$local_data_id");

			/* get device fields first */
			$device_fields = array_rekey(db_fetch_assoc("SELECT
				data_input_fields.type_code,
				data_input_data.value
				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_input["data_template_data_id"] . ")
				WHERE ((type_code LIKE 'snmp_%') OR (type_code='hostname'))
				AND data_input_data.value != ''"), "type_code", "value");

			$data_template_fields = array_rekey(db_fetch_assoc("SELECT
				data_input_fields.type_code,
				data_input_data.value
				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_template_id)
				WHERE ((type_code LIKE 'snmp_%') OR (type_code='hostname'))
				AND data_template_data_id=$data_template_id
				AND data_input_data.value != ''"), "type_code", "value");

			if (sizeof($device_fields)) {
				if (sizeof($data_template_fields)) {
				foreach($data_template_fields as $key => $value) {
					if (!isset($device_fields[$key])) {
						$device_fields[$key] = $value;
					}
				}
				}
			} elseif (sizeof($data_template_fields)) {
				$device_fields = $data_template_fields;
			}

			$data_template_rrd_id = db_fetch_cell("select id from data_template_rrd where local_data_id=$local_data_id");

			$poller_items[] = api_poller_cache_item_add($data_source["device_id"], $device_fields, $local_data_id, $data_input["rrd_step"], 0, get_data_source_item_name($data_template_rrd_id), 1, (isset($device_fields["snmp_oid"]) ? $device_fields["snmp_oid"] : ""));
		}else if ($data_input["type_id"] == DATA_INPUT_TYPE_SNMP_QUERY) { /* snmp query */
			$snmp_queries = get_data_query_array($data_source["snmp_query_id"]);

			/* get the device override fields */
			$data_template_id = db_fetch_cell("SELECT data_template_id FROM data_template_data WHERE local_data_id=$local_data_id");

			/* get device fields first */
			$device_fields = array_rekey(db_fetch_assoc("SELECT
				data_input_fields.type_code,
				data_input_data.value
				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_input["data_template_data_id"] . ")
				WHERE ((type_code LIKE 'snmp_%') OR (type_code='hostname'))
				AND data_input_data.value != ''"), "type_code", "value");

			$data_template_fields = array_rekey(db_fetch_assoc("SELECT
				data_input_fields.type_code,
				data_input_data.value
				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_template_id)
				WHERE ((type_code LIKE 'snmp_%') OR (type_code='hostname'))
				AND data_template_data_id=$data_template_id
				AND data_input_data.value != ''"), "type_code", "value");

			if (sizeof($device_fields)) {
				if (sizeof($data_template_fields)) {
				foreach($data_template_fields as $key => $value) {
					if (!isset($device_fields[$key])) {
						$device_fields[$key] = $value;
					}
				}
				}
			} elseif (sizeof($data_template_fields)) {
				$device_fields = $data_template_fields;
			}

			if (sizeof($outputs) > 0) {
			foreach ($outputs as $output) {
				if (isset($snmp_queries["fields"]{$output["snmp_field_name"]}["oid"])) {
					$oid_suffix = $data_source["snmp_index"];
					if(isset($snmp_queries["fields"]{$output["snmp_field_name"]}["rewrite_index"])){
						$oid_suffix = data_query_rewrite_indexes($errmsg, $data_source["device_id"], $data_source["snmp_query_id"], $snmp_queries["fields"]{$output["snmp_field_name"]}["rewrite_index"], $oid_suffix);
						if($oid_suffix == NULL){ // rewriting index failed for some reason
							if(sizeof($errmsg)){
								foreach($errmsg as $message){
									cacti_log(__("Field '%s':", $output["snmp_field_name"]) . $message, false, "POLLER");
								}
							}
							continue;
						}
					}
					$oid = $snmp_queries["fields"]{$output["snmp_field_name"]}["oid"] . "." . $oid_suffix;

					if (isset($snmp_queries["fields"]{$output["snmp_field_name"]}["oid_suffix"])) {
						$oid .= "." . $snmp_queries["fields"]{$output["snmp_field_name"]}["oid_suffix"];
					}
				}

				if (!empty($oid)) {
					$poller_items[] = api_poller_cache_item_add($data_source["device_id"], $device_fields, $local_data_id, $data_input["rrd_step"], 0, get_data_source_item_name($output["data_template_rrd_id"]), sizeof($outputs), $oid);
				}
			}
			}
		}else if (($data_input["type_id"] == DATA_INPUT_TYPE_SCRIPT_QUERY) || ($data_input["type_id"] == DATA_INPUT_TYPE_QUERY_SCRIPT_SERVER)) { /* script query */
			$script_queries = get_data_query_array($data_source["snmp_query_id"]);

			/* get the device override fields */
			$data_template_id = db_fetch_cell("SELECT data_template_id FROM data_template_data WHERE local_data_id=$local_data_id");

			/* get device fields first */
			$device_fields = array_rekey(db_fetch_assoc("SELECT
				data_input_fields.type_code,
				data_input_data.value
				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_input["data_template_data_id"] . ")
				WHERE ((type_code LIKE 'snmp_%') OR (type_code='hostname'))
				AND data_input_data.value != ''"), "type_code", "value");

			$data_template_fields = array_rekey(db_fetch_assoc("SELECT
				data_input_fields.type_code,
				data_input_data.value
				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_template_id)
				WHERE ((type_code LIKE 'snmp_%') OR (type_code='hostname'))
				AND data_template_data_id=$data_template_id
				AND data_input_data.value != ''"), "type_code", "value");

			if (sizeof($device_fields)) {
				if (sizeof($data_template_fields)) {
				foreach($data_template_fields as $key => $value) {
					if (!isset($device_fields[$key])) {
						$device_fields[$key] = $value;
					}
				}
				}
			} elseif (sizeof($data_template_fields)) {
				$device_fields = $data_template_fields;
			}

			if (sizeof($outputs) > 0) {
				foreach ($outputs as $output) {
					if (isset($script_queries["fields"]{$output["snmp_field_name"]}["query_name"])) {
						$identifier = $script_queries["fields"]{$output["snmp_field_name"]}["query_name"];

						/* fall back to non-script server actions if the user is running a version of php older than 4.3 */
						if (($data_input["type_id"] == DATA_INPUT_TYPE_QUERY_SCRIPT_SERVER) && (function_exists("proc_open"))) {
							$action = POLLER_ACTION_SCRIPT_PHP;
							$script_path = get_script_query_path((isset($script_queries["arg_prepend"]) ? $script_queries["arg_prepend"] : "") . " " . $script_queries["arg_get"] . " " . $identifier . " " . $data_source["snmp_index"], $script_queries["script_path"] . " " . $script_queries["script_function"], $data_source["device_id"]);
						}else if (($data_input["type_id"] == DATA_INPUT_TYPE_QUERY_SCRIPT_SERVER) && (!function_exists("proc_open"))) {
							$action = POLLER_ACTION_SCRIPT;
							$script_path = read_config_option("path_php_binary") . " -q " . get_script_query_path((isset($script_queries["arg_prepend"]) ? $script_queries["arg_prepend"] : "") . " " . $script_queries["arg_get"] . " " . $identifier . " " . $data_source["snmp_index"], $script_queries["script_path"], $data_source["device_id"]);
						}else{
							$action = POLLER_ACTION_SCRIPT;
							$script_path = get_script_query_path((isset($script_queries["arg_prepend"]) ? $script_queries["arg_prepend"] : "") . " " . $script_queries["arg_get"] . " " . $identifier . " " . $data_source["snmp_index"], $script_queries["script_path"], $data_source["device_id"]);
						}
					}

					if (isset($script_path)) {
						$poller_items[] = api_poller_cache_item_add($data_source["device_id"], $device_fields, $local_data_id, $data_input["rrd_step"], $action, get_data_source_item_name($output["data_template_rrd_id"]), sizeof($outputs), addslashes($script_path));
					}
				}
			}
		}
	}

	if ($commit) {
		poller_update_poller_cache_from_buffer((array)$local_data_id, $poller_items);
	} else {
		return $poller_items;
	}
}
Пример #25
0
function get_ordered_index_type_list($host_id, $data_query_id, $data_query_index_array = array()) {
	$raw_xml = get_data_query_array($data_query_id);

	/* invalid xml check */
	if ((!is_array($raw_xml)) || (sizeof($raw_xml) == 0)) {
		return array();
	}

	$xml_outputs = array();

	/* create an SQL string that contains each index in this snmp_index_id */
	$sql_or = array_to_sql_or($data_query_index_array, "snmp_index");

	/* check for nonunique query parameter, set value */
	if (isset($raw_xml["index_type"])) {
		if ($raw_xml["index_type"] == "nonunique") {
			$nonunique = 1;
		}else{
			$nonunique = 0;
		}
	} else {
		$nonunique = 0;
	}

	/* list each of the input fields for this snmp query */
	while (list($field_name, $field_array) = each($raw_xml["fields"])) {
		if ($field_array["direction"] == "input") {
			/* create a list of all values for this index */
			if (sizeof($data_query_index_array) == 0) {
				$field_values = db_fetch_assoc("select field_value from host_snmp_cache where host_id=$host_id and snmp_query_id=$data_query_id and field_name='$field_name'");
			}else{
				$field_values = db_fetch_assoc("select field_value from host_snmp_cache where host_id=$host_id and snmp_query_id=$data_query_id and field_name='$field_name' and $sql_or");
			}

			/* aggregate the above list so there is no duplicates */
			$aggregate_field_values = array_rekey($field_values, "field_value", "field_value");

			/* fields that contain duplicate or empty values are not suitable to index off of */
			if (!((sizeof($aggregate_field_values) < sizeof($field_values)) || (in_array("", $aggregate_field_values) == true) || (sizeof($aggregate_field_values) == 0)) || ($nonunique)) {
				array_push($xml_outputs, $field_name);
			}
		}
	}

	$return_array = array();

	/* the xml file contains an ordered list of "indexable" fields */
	if (isset($raw_xml["index_order"])) {
		$index_order_array = explode(":", $raw_xml["index_order"]);

		for ($i=0; $i<count($index_order_array); $i++) {
			if (in_array($index_order_array[$i], $xml_outputs)) {
				$return_array[] = $index_order_array[$i];
			}
		}
	/* the xml file does not contain a field list, ignore the order */
	}else{
		for ($i=0; $i<count($xml_outputs); $i++) {
			$return_array[] = $xml_outputs[$i];
		}
	}

	return $return_array;
}
Пример #26
0
function host()
{
    global $colors, $device_actions, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("host_template_id"));
    input_validate_input_number(get_request_var_request("page"));
    input_validate_input_number(get_request_var_request("host_status"));
    input_validate_input_number(get_request_var_request("host_rows"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    /* clean up sort_column */
    if (isset($_REQUEST["sort_column"])) {
        $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
    }
    /* clean up search string */
    if (isset($_REQUEST["sort_direction"])) {
        $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_device_current_page");
        kill_session_var("sess_device_filter");
        kill_session_var("sess_device_host_template_id");
        kill_session_var("sess_host_status");
        kill_session_var("sess_host_rows");
        kill_session_var("sess_host_sort_column");
        kill_session_var("sess_host_sort_direction");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["host_template_id"]);
        unset($_REQUEST["host_status"]);
        unset($_REQUEST["host_rows"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
    }
    if (!empty($_SESSION["sess_host_status"]) && !empty($_REQUEST["host_status"])) {
        if ($_SESSION["sess_host_status"] != $_REQUEST["host_status"]) {
            $_REQUEST["page"] = 1;
        }
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("page", "sess_device_current_page", "1");
    load_current_session_value("filter", "sess_device_filter", "");
    load_current_session_value("host_template_id", "sess_device_host_template_id", "-1");
    load_current_session_value("host_status", "sess_host_status", "-1");
    load_current_session_value("host_rows", "sess_host_rows", read_config_option("num_rows_device"));
    load_current_session_value("sort_column", "sess_host_sort_column", "description");
    load_current_session_value("sort_direction", "sess_host_sort_direction", "ASC");
    /* if the number of rows is -1, set it to the default */
    if ($_REQUEST["host_rows"] == -1) {
        $_REQUEST["host_rows"] = read_config_option("num_rows_device");
    }
    ?>
	<script type="text/javascript">
	<!--

	function applyViewDeviceFilterChange(objForm) {
		strURL = '?host_status=' + objForm.host_status.value;
		strURL = strURL + '&host_template_id=' + objForm.host_template_id.value;
		strURL = strURL + '&host_rows=' + objForm.host_rows.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}

	-->
	</script>
	<?php 
    html_start_box("<strong>Devices</strong>", "100%", $colors["header"], "3", "center", "host.php?action=edit&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status"));
    ?>
	<tr bgcolor="<?php 
    print $colors["panel"];
    ?>
">
		<form name="form_devices">
		<td>
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td nowrap style='white-space: nowrap;' width="50">
						Type:&nbsp;
					</td>
					<td width="1">
						<select name="host_template_id" onChange="applyViewDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php 
    if (get_request_var_request("host_template_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
							<option value="0"<?php 
    if (get_request_var_request("host_template_id") == "0") {
        ?>
 selected<?php 
    }
    ?>
>None</option>
							<?php 
    $host_templates = db_fetch_assoc("select id,name from host_template order by name");
    if (sizeof($host_templates) > 0) {
        foreach ($host_templates as $host_template) {
            print "<option value='" . $host_template["id"] . "'";
            if (get_request_var_request("host_template_id") == $host_template["id"]) {
                print " selected";
            }
            print ">" . $host_template["name"] . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="50">
						&nbsp;Status:&nbsp;
					</td>
					<td width="1">
						<select name="host_status" onChange="applyViewDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php 
    if (get_request_var_request("host_status") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
							<option value="-3"<?php 
    if (get_request_var_request("host_status") == "-3") {
        ?>
 selected<?php 
    }
    ?>
>Enabled</option>
							<option value="-2"<?php 
    if (get_request_var_request("host_status") == "-2") {
        ?>
 selected<?php 
    }
    ?>
>Disabled</option>
							<option value="-4"<?php 
    if (get_request_var_request("host_status") == "-4") {
        ?>
 selected<?php 
    }
    ?>
>Not Up</option>
							<option value="3"<?php 
    if (get_request_var_request("host_status") == "3") {
        ?>
 selected<?php 
    }
    ?>
>Up</option>
							<option value="1"<?php 
    if (get_request_var_request("host_status") == "1") {
        ?>
 selected<?php 
    }
    ?>
>Down</option>
							<option value="2"<?php 
    if (get_request_var_request("host_status") == "2") {
        ?>
 selected<?php 
    }
    ?>
>Recovering</option>
							<option value="0"<?php 
    if (get_request_var_request("host_status") == "0") {
        ?>
 selected<?php 
    }
    ?>
>Unknown</option>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="20">
						&nbsp;Search:&nbsp;
					</td>
					<td width="1">
						<input type="text" name="filter" size="20" value="<?php 
    print get_request_var_request("filter");
    ?>
">
					</td>
					<td nowrap style='white-space: nowrap;' width="50">
						&nbsp;Rows per Page:&nbsp;
					</td>
					<td width="1">
						<select name="host_rows" onChange="applyViewDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php 
    if (get_request_var_request("host_rows") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Default</option>
							<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request("host_rows") == $key) {
                print " selected";
            }
            print ">" . $value . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td nowrap>
						&nbsp;<input type="image" src="images/button_go.gif" alt="Go" border="0" align="absmiddle">
						<input type="image" src="images/button_clear.gif" name="clear" alt="Clear" border="0" align="absmiddle">
					</td>
				</tr>
			</table>
		</td>
		<input type='hidden' name='page' value='1'>
		</form>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen(get_request_var_request("filter"))) {
        $sql_where = "where (host.hostname like '%%" . get_request_var_request("filter") . "%%' OR host.description like '%%" . get_request_var_request("filter") . "%%')";
    } else {
        $sql_where = "";
    }
    if (get_request_var_request("host_status") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("host_status") == "-2") {
        $sql_where .= strlen($sql_where) ? " and host.disabled='on'" : "where host.disabled='on'";
    } elseif (get_request_var_request("host_status") == "-3") {
        $sql_where .= strlen($sql_where) ? " and host.disabled=''" : "where host.disabled=''";
    } elseif (get_request_var_request("host_status") == "-4") {
        $sql_where .= strlen($sql_where) ? " and (host.status!='3' or host.disabled='on')" : "where (host.status!='3' or host.disabled='on')";
    } else {
        $sql_where .= strlen($sql_where) ? " and (host.status=" . get_request_var_request("host_status") . " AND host.disabled = '')" : "where (host.status=" . get_request_var_request("host_status") . " AND host.disabled = '')";
    }
    if (get_request_var_request("host_template_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("host_template_id") == "0") {
        $sql_where .= strlen($sql_where) ? " and host.host_template_id=0" : "where host.host_template_id=0";
    } elseif (!empty($_REQUEST["host_template_id"])) {
        $sql_where .= strlen($sql_where) ? " and host.host_template_id=" . get_request_var_request("host_template_id") : "where host.host_template_id=" . get_request_var_request("host_template_id");
    }
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    $total_rows = db_fetch_cell("select\n\t\tCOUNT(host.id)\n\t\tfrom host\n\t\t{$sql_where}");
    $sortby = get_request_var_request("sort_column");
    if ($sortby == "hostname") {
        $sortby = "INET_ATON(hostname)";
    }
    $host_graphs = array_rekey(db_fetch_assoc("SELECT host_id, count(*) as graphs FROM graph_local GROUP BY host_id"), "host_id", "graphs");
    $host_data_sources = array_rekey(db_fetch_assoc("SELECT host_id, count(*) as data_sources FROM data_local GROUP BY host_id"), "host_id", "data_sources");
    $sql_query = "SELECT *\n\t\tFROM host\n\t\t{$sql_where}\n\t\tORDER BY " . $sortby . " " . get_request_var_request("sort_direction") . "\n\t\tLIMIT " . get_request_var_request("host_rows") * (get_request_var_request("page") - 1) . "," . get_request_var_request("host_rows");
    $hosts = db_fetch_assoc($sql_query);
    /* generate page list */
    $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("host_rows"), $total_rows, "host.php?filter=" . get_request_var_request("filter") . "&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status"));
    $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t<td colspan='11'>\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 (get_request_var_request("page") > 1) {
        $nav .= "<a class='linkOverDark' href='host.php?filter=" . get_request_var_request("filter") . "&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status") . "&page=" . (get_request_var_request("page") - 1) . "'>";
    }
    $nav .= "Previous";
    if (get_request_var_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 " . (get_request_var_request("host_rows") * (get_request_var_request("page") - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_device") || $total_rows < get_request_var_request("host_rows") * get_request_var_request("page") ? $total_rows : get_request_var_request("host_rows") * get_request_var_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 (get_request_var_request("page") * get_request_var_request("host_rows") < $total_rows) {
        $nav .= "<a class='linkOverDark' href='host.php?filter=" . get_request_var_request("filter") . "&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status") . "&page=" . (get_request_var_request("page") + 1) . "'>";
    }
    $nav .= "Next";
    if (get_request_var_request("page") * get_request_var_request("host_rows") < $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("description" => array("Description", "ASC"), "id" => array("ID", "ASC"), "nosort1" => array("Graphs", "ASC"), "nosort2" => array("Data Sources", "ASC"), "status" => array("Status", "ASC"), "status_event_count" => array("Event Count", "ASC"), "hostname" => array("Hostname", "ASC"), "cur_time" => array("Current (ms)", "DESC"), "avg_time" => array("Average (ms)", "DESC"), "availability" => array("Availability", "ASC"));
    html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"));
    $i = 0;
    if (sizeof($hosts) > 0) {
        foreach ($hosts as $host) {
            form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $host["id"]);
            $i++;
            form_selectable_cell("<a class='linkEditMain' href='host.php?action=edit&id=" . $host["id"] . "'>" . (strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["description"]) : $host["description"]) . "</a>", $host["id"], 250);
            form_selectable_cell(round($host["id"], 2), $host["id"]);
            form_selectable_cell(isset($host_graphs[$host["id"]]) ? $host_graphs[$host["id"]] : 0, $host["id"]);
            form_selectable_cell(isset($host_data_sources[$host["id"]]) ? $host_data_sources[$host["id"]] : 0, $host["id"]);
            form_selectable_cell(get_colored_device_status($host["disabled"] == "on" ? true : false, $host["status"]), $host["id"]);
            form_selectable_cell(round($host["status_event_count"], 2), $host["id"]);
            form_selectable_cell(strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["hostname"]) : $host["hostname"], $host["id"]);
            form_selectable_cell(round($host["cur_time"], 2), $host["id"]);
            form_selectable_cell(round($host["avg_time"], 2), $host["id"]);
            form_selectable_cell(round($host["availability"], 2), $host["id"]);
            form_checkbox_cell($host["description"], $host["id"]);
            form_end_row();
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr><td><em>No Hosts</em></td></tr>";
    }
    html_end_box(false);
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($device_actions);
    print "</form>\n";
}
Пример #27
0
/** create_complete_graph_from_template - creates a graph and all necessary data sources based on a
	graph template
   @param int $graph_template_id 			- the id of the graph template that will be used to create the new	graph
   @param int $device_id 					- the id of the device to associate the new graph and data sources with
   @param array $snmp_query_array 			- if the new data sources are to be based on a data query, specify the
	necessary data query information here. it must contain the following information:
	  $snmp_query_array["snmp_query_id"]
	  $snmp_query_array["snmp_index_on"]
	  $snmp_query_array["snmp_query_graph_id"]
	  $snmp_query_array["snmp_index"]
   @param array $suggested_values_array 	- any additional information to be included in the new graphs or
	data sources must be included in the array. data is to be included in the following format:
	  $values["cg"][graph_template_id]["graph_template"][field_name] = $value  // graph template
	  $values["cg"][graph_template_id]["graph_template_item"][graph_template_item_id][field_name] = $value  // graph template item
	  $values["cg"][data_template_id]["data_template"][field_name] = $value  // data template
	  $values["cg"][data_template_id]["data_template_item"][data_template_item_id][field_name] = $value  // data template item
	  $values["sg"][data_query_id][graph_template_id]["graph_template"][field_name] = $value  // graph template (w/ data query)
	  $values["sg"][data_query_id][graph_template_id]["graph_template_item"][graph_template_item_id][field_name] = $value  // graph template item (w/ data query)
	  $values["sg"][data_query_id][data_template_id]["data_template"][field_name] = $value  // data template (w/ data query)
	  $values["sg"][data_query_id][data_template_id]["data_template_item"][data_template_item_id][field_name] = $value  // data template item (w/ data query) */
function create_complete_graph_from_template($graph_template_id, $device_id, $snmp_query_array, &$suggested_values_array) {
	global $config;

	include_once(CACTI_BASE_PATH . "/lib/data_query.php");

	/* create the graph */
	$save["id"] = 0;
	$save["graph_template_id"] = $graph_template_id;
	$save["device_id"] = $device_id;

	$cache_array["local_graph_id"] = sql_save($save, "graph_local");
	change_graph_template($cache_array["local_graph_id"], $graph_template_id, true);

	if (is_array($snmp_query_array)) {
		/* suggested values for snmp query code */
		$suggested_values = db_fetch_assoc("select text,field_name from snmp_query_graph_sv where snmp_query_graph_id=" . $snmp_query_array["snmp_query_graph_id"] . " order by sequence");

		if (sizeof($suggested_values) > 0) {
		foreach ($suggested_values as $suggested_value) {
			/* once we find a match; don't try to find more */
			if (!isset($suggested_values_graph[$graph_template_id]{$suggested_value["field_name"]})) {
				$subs_string = substitute_snmp_query_data($suggested_value["text"], $device_id, $snmp_query_array["snmp_query_id"], $snmp_query_array["snmp_index"], read_config_option("max_data_query_field_length"), false);
				/* if there are no '|' characters, all of the substitutions were successful */
				if (!strstr($subs_string, "|query")) {
					db_execute("update graph_templates_graph set " . $suggested_value["field_name"] . "='" . addslashes($subs_string) . "' where local_graph_id=" . $cache_array["local_graph_id"]);

					/* once we find a working value, stop */
					$suggested_values_graph[$graph_template_id]{$suggested_value["field_name"]} = true;
				}
			}
		}
		}
	}

	/* suggested values: graph */
	if (isset($suggested_values_array[$graph_template_id]["graph_template"])) {
		while (list($field_name, $field_value) = each($suggested_values_array[$graph_template_id]["graph_template"])) {
			db_execute("update graph_templates_graph set $field_name='$field_value' where local_graph_id=" . $cache_array["local_graph_id"]);
		}
	}

	/* suggested values: graph item */
	if (isset($suggested_values_array[$graph_template_id]["graph_template_item"])) {
		while (list($graph_template_item_id, $field_array) = each($suggested_values_array[$graph_template_id]["graph_template_item"])) {
			while (list($field_name, $field_value) = each($field_array)) {
				$graph_item_id = db_fetch_cell("select id from graph_templates_item where local_graph_template_item_id=$graph_template_item_id and local_graph_id=" . $cache_array["local_graph_id"]);
				db_execute("update graph_templates_item set $field_name='$field_value' where id=$graph_item_id");
			}
		}
	}

	update_graph_title_cache($cache_array["local_graph_id"]);

	/* create each data source */
	$data_templates = db_fetch_assoc("select
		data_template.id,
		data_template.name,
		data_template_rrd.data_source_name
		from (data_template, data_template_rrd, graph_templates_item)
		where graph_templates_item.task_item_id=data_template_rrd.id
		and data_template_rrd.data_template_id=data_template.id
		and data_template_rrd.local_data_id=0
		and graph_templates_item.local_graph_id=0
		and graph_templates_item.graph_template_id=" . $graph_template_id . "
		group by data_template.id
		order by data_template.name");

	if (sizeof($data_templates) > 0) {
	foreach ($data_templates as $data_template) {
		unset($save);

		$save["id"] = 0;
		$save["data_template_id"] = $data_template["id"];
		$save["device_id"] = $device_id;

		$cache_array["local_data_id"]{$data_template["id"]} = sql_save($save, "data_local");
		change_data_template($cache_array["local_data_id"]{$data_template["id"]}, $data_template["id"]);

		$data_template_data_id = db_fetch_cell("select id from data_template_data where local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]});

		if (is_array($snmp_query_array)) {
			/* suggested values for snmp query code */
			$suggested_values = db_fetch_assoc("select text,field_name from snmp_query_graph_rrd_sv where snmp_query_graph_id=" . $snmp_query_array["snmp_query_graph_id"] . " and data_template_id=" . $data_template["id"] . " order by sequence");

			if (sizeof($suggested_values) > 0) {
			foreach ($suggested_values as $suggested_value) {
				/* once we find a match; don't try to find more */
				if (!isset($suggested_values_ds{$data_template["id"]}{$suggested_value["field_name"]})) {
					$subs_string = substitute_snmp_query_data($suggested_value["text"], $device_id, $snmp_query_array["snmp_query_id"], $snmp_query_array["snmp_index"], read_config_option("max_data_query_field_length"), false);

					/* if there are no '|' characters, all of the substitutions were successful */
					if (!strstr($subs_string, "|query")) {
						if (sizeof(db_fetch_row("show columns from data_template_data like '" . $suggested_value["field_name"] . "'"))) {
							db_execute("update data_template_data set " . $suggested_value["field_name"] . "='" . addslashes($subs_string) . "' where local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]});
						}

						/* once we find a working value, stop */
						$suggested_values_ds{$data_template["id"]}{$suggested_value["field_name"]} = true;

						if ((sizeof(db_fetch_row("show columns from data_template_rrd like '" . $suggested_value["field_name"] . "'"))) &&
							(!substr_count($subs_string, "|"))) {
							db_execute("update data_template_rrd set " . $suggested_value["field_name"] . "='" . $subs_string . "' where local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]});
						}
					}
				}
			}
			}
		}

		if (is_array($snmp_query_array)) {
			$data_input_field = array_rekey(db_fetch_assoc("SELECT
				data_input_fields.id,
				data_input_fields.type_code
				FROM (snmp_query,data_input,data_input_fields)
				WHERE snmp_query.data_input_id=data_input.id
				AND data_input.id=data_input_fields.data_input_id
				AND (data_input_fields.type_code='index_type'
					OR data_input_fields.type_code='index_value'
					OR data_input_fields.type_code='output_type')
				AND snmp_query.id=" . $snmp_query_array["snmp_query_id"]), "type_code", "id");

			$snmp_cache_value = db_fetch_cell("SELECT field_value
				FROM device_snmp_cache
				WHERE device_id='$device_id'
				AND snmp_query_id='" . $snmp_query_array["snmp_query_id"] . "'
				AND field_name='" . $snmp_query_array["snmp_index_on"] . "'
				AND snmp_index='" . $snmp_query_array["snmp_index"] . "'");

			/* save the value to index on (ie. ifindex, ifip, etc) */
			db_execute("REPLACE INTO data_input_data
				(data_input_field_id, data_template_data_id, t_value, value)
				VALUES (" . $data_input_field["index_type"] . ", $data_template_data_id, '', '" . $snmp_query_array["snmp_index_on"] . "')");

			/* save the actual value (ie. 3, 192.168.1.101, etc) */
			db_execute("REPLACE INTO data_input_data
				(data_input_field_id,data_template_data_id,t_value,value)
				VALUES (" . $data_input_field["index_value"] . ",$data_template_data_id,'','" . addslashes($snmp_cache_value) . "')");

			/* set the expected output type (ie. bytes, errors, packets) */
			db_execute("REPLACE INTO data_input_data
				(data_input_field_id,data_template_data_id,t_value,value)
				VALUES (" . $data_input_field["output_type"] . ",$data_template_data_id,'','" . $snmp_query_array["snmp_query_graph_id"] . "')");

			/* now that we have put data into the 'data_input_data' table, update the snmp cache for ds's */
			update_data_source_data_query_cache($cache_array["local_data_id"]{$data_template["id"]});
		}

		/* suggested values: data source */
		if (isset($suggested_values_array[$graph_template_id]["data_template"]{$data_template["id"]})) {
			reset($suggested_values_array[$graph_template_id]["data_template"]{$data_template["id"]});
			while (list($field_name, $field_value) = each($suggested_values_array[$graph_template_id]["data_template"]{$data_template["id"]})) {
				db_execute("UPDATE data_template_data
					SET $field_name='$field_value'
					WHERE local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]});
			}
		}

		/* suggested values: data source item */
		if (isset($suggested_values_array[$graph_template_id]["data_template_item"])) {
			reset($suggested_values_array[$graph_template_id]["data_template_item"]);
			while (list($data_template_item_id, $field_array) = each($suggested_values_array[$graph_template_id]["data_template_item"])) {
				while (list($field_name, $field_value) = each($field_array)) {
					$data_source_item_id = db_fetch_cell("select id from data_template_rrd where local_data_template_rrd_id=$data_template_item_id and local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]});
					db_execute("UPDATE data_template_rrd
						SET $field_name='$field_value'
						WHERE id=$data_source_item_id");
				}
			}
		}

		/* suggested values: custom data */
		if (isset($suggested_values_array[$graph_template_id]["custom_data"]{$data_template["id"]})) {
			reset($suggested_values_array[$graph_template_id]["custom_data"]{$data_template["id"]});
			while (list($data_input_field_id, $field_value) = each($suggested_values_array[$graph_template_id]["custom_data"]{$data_template["id"]})) {
				db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values ($data_input_field_id,$data_template_data_id,'','$field_value')");
			}
		}

		update_data_source_title_cache($cache_array["local_data_id"]{$data_template["id"]});
	}
	}

	/* connect the dots: graph -> data source(s) */
	$template_item_list = db_fetch_assoc("select
		graph_templates_item.id,
		data_template_rrd.id as data_template_rrd_id,
		data_template_rrd.data_template_id
		from (graph_templates_item,data_template_rrd)
		where graph_templates_item.task_item_id=data_template_rrd.id
		and graph_templates_item.graph_template_id=$graph_template_id
		and local_graph_id=0
		and task_item_id>0");

	/* loop through each item affected and update column data */
	if (sizeof($template_item_list) > 0) {
	foreach ($template_item_list as $template_item) {
		$local_data_id = $cache_array["local_data_id"]{$template_item["data_template_id"]};

		$graph_template_item_id = db_fetch_cell("select id from graph_templates_item where local_graph_template_item_id=" . $template_item["id"] . " and local_graph_id=" . $cache_array["local_graph_id"]);
		$data_template_rrd_id = db_fetch_cell("select id from data_template_rrd where local_data_template_rrd_id=" . $template_item["data_template_rrd_id"] . " and local_data_id=$local_data_id");

		if (!empty($data_template_rrd_id)) {
			db_execute("update graph_templates_item set task_item_id='$data_template_rrd_id' where id=$graph_template_item_id");
		}
	}
	}

	/* this will not work until the ds->graph dots are connected */
	if (is_array($snmp_query_array)) {
		update_graph_data_query_cache($cache_array["local_graph_id"]);
	}

	# now that we have the id of the new host, we may plugin postprocessing code
	$save["id"] = $cache_array["local_graph_id"];
	$save["graph_template_id"] = $graph_template_id;	// attention: unset!
	if (is_array($snmp_query_array)) {
		$save["snmp_query_id"] = $snmp_query_array["snmp_query_id"];
		$save["snmp_index"] = $snmp_query_array["snmp_index"];
	} else {
		$save["snmp_query_id"] = 0;
		$save["snmp_index"] = 0;
	}
	api_plugin_hook_function('create_complete_graph_from_template', $save);

	return $cache_array;
}
Пример #28
0
function api_graph_template_item_input_item_list($graph_template_item_input_id) {
	/* sanity checks */
	validate_id_die($graph_template_item_input_id, "graph_template_item_input_id");

	return array_rekey(db_fetch_assoc("select * from graph_template_item_input_item where graph_template_item_input_id = " . sql_sanitize($graph_template_item_input_id)), "", "graph_template_item_id");
}
function mactrack_filter_table() {
	global $config, $rows_selector, $colors;

	$filterChange = "applyInterfaceFilterChange(document.view_mactrack)";
	?>
	<tr id='filter' bgcolor="<?php print $colors["panel"];?>">
		<td>
			<form name="view_mactrack" style="margin:0px;">
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td width="50">
						Site:&nbsp;
					</td>
					<td width="1">
						<select name="site" onChange="<?php print $filterChange;?>">
						<option value="-1"<?php if ($_REQUEST["site"] == "-1") {?> selected<?php }?>>All</option>
						<?php
						$sites = db_fetch_assoc("SELECT site_id, site_name FROM mac_track_sites ORDER BY site_name");
						if (sizeof($sites) > 0) {
						foreach ($sites as $site) {
							print '<option value="' . $site["site_id"] .'"'; if ($_REQUEST["site"] == $site["site_id"]) { print " selected"; } print ">" . $site["site_name"] . "</option>";
						}
						}
						?>
						</select>
					</td>
					<td width="50">
						&nbsp;Filters:&nbsp;
					</td>
					<td width="1">
						<select name="issues" onChange="<?php print $filterChange;?>">
						<option value="-2"<?php if ($_REQUEST["issues"] == "-2") {?> selected<?php }?>>All Interfaces</option>
						<option value="-3"<?php if ($_REQUEST["issues"] == "-3") {?> selected<?php }?>>All Non-Ignored Interfaces</option>
						<option value="-4"<?php if ($_REQUEST["issues"] == "-4") {?> selected<?php }?>>All Ignored Interfaces</option>
						<?php if ($_REQUEST["bwusage"] != "-1") {?><option value="9"<?php if ($_REQUEST["issues"] == "9" && $_REQUEST["bwusage"] != "-1") {?> selected<?php }?>>High In/Out Utilization > <?php print $_REQUEST["bwusage"] . "%";?></option><?php }?>
						<?php if ($_REQUEST["bwusage"] != "-1") {?><option value="10"<?php if ($_REQUEST["issues"] == "10" && $_REQUEST["bwusage"] != "-1") {?> selected<?php }?>>High In Utilization > <?php print $_REQUEST["bwusage"] . "%";?></option><?php }?>
						<?php if ($_REQUEST["bwusage"] != "-1") {?><option value="11"<?php if ($_REQUEST["issues"] == "11" && $_REQUEST["bwusage"] != "-1") {?> selected<?php }?>>High Out Utilization > <?php print $_REQUEST["bwusage"] . "%";?></option><?php }?>
						<option value="-1"<?php if ($_REQUEST["issues"] == "-1") {?> selected<?php }?>>With Issues</option>
						<option value="0"<?php if ($_REQUEST["issues"] == "0") {?> selected<?php }?>>Up Interfaces</option>
						<option value="1"<?php if ($_REQUEST["issues"] == "1") {?> selected<?php }?>>Up Interfaces No Alias</option>
						<option value="2"<?php if ($_REQUEST["issues"] == "2") {?> selected<?php }?>>Errors Accumulating</option>
						<option value="3"<?php if ($_REQUEST["issues"] == "3") {?> selected<?php }?>>Discards Accumulating</option>
						<option value="7"<?php if ($_REQUEST["issues"] == "7") {?> selected<?php }?>>Changed in Last Day</option>
						</select><BR>
					<td width="50">
						&nbsp;Bandwidth:&nbsp;
					</td>
					<td width="1">
						<select name="bwusage" onChange="<?php print $filterChange;?>">
						<option value="-1"<?php if ($_REQUEST["bwusage"] == "-1") {?> selected<?php }?>>N/A</option>
						<?php
						for ($bwpercent = 10; $bwpercent <100; $bwpercent+=10) {
							?><option value="<?php print $bwpercent; ?>" <?php if (isset($_REQUEST["bwusage"]) and ($_REQUEST["bwusage"] == $bwpercent)) {?> selected<?php }?>><?php print $bwpercent; ?>%</option><?php
						}
						?>
						</select>
					</td>
					<td>
						<input type="submit" name="Go" value="Go" alt="Go" border="0" align="absmiddle">
					</td>
					<td>
						<input type="submit" name="clear_x" value="Clear" alt="Clear" border="0" align="absmiddle">
					</td>
					<td>
						<input type="submit" name="export_x" value="Export" alt="Export" border="0" align="absmiddle">
					</td>
                    <td>
						<input type="button" name="report" value="PDF Report" alt="PDF report" border="0" align="absmiddle" onclick="printreport(<?php echo $_GET["device"]; ?>)">
					</td>
				</tr>
			</table>
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td width="50">
						Type:&nbsp;
					</td>
					<td width="1">
						<select name="type" onChange="<?php print $filterChange;?>">
						<option value="-1"<?php if ($_REQUEST["type"] == "-1") {?> selected<?php }?>>All</option>
						<?php
						if ($_REQUEST["site"] != -1) {
							$sql_where .= " WHERE (mac_track_devices.site_id='" . $_REQUEST["site"] . "')";
						}else{
							$sql_where  = "";
						}
						$types = db_fetch_assoc("SELECT DISTINCT mac_track_device_types.device_type_id, mac_track_device_types.description AS device_type
							FROM mac_track_device_types
							INNER JOIN mac_track_devices
							ON mac_track_device_types.device_type_id=mac_track_devices.device_type_id
							$sql_where
							ORDER BY device_type");
						if (sizeof($types) > 0) {
						foreach ($types as $type) {
							print '<option value="' . $type["device_type_id"] .'"'; if ($_REQUEST["type"] == $type["device_type_id"]) { print " selected"; } print ">" . $type["device_type"] . "</option>";
						}
						}
						?>
						</select>
					</td>
					<td width="50">
						&nbsp;Device:&nbsp;
					</td>
					<td width="1">
						<select name="device" onChange="<?php print $filterChange;?>">
						<option value="-1"<?php if ($_REQUEST["device"] == "-1") {?> selected<?php }?>>All</option>
						<?php
						$sql_where = "";
						if ($_REQUEST["site"] != -1) {
							$sql_where .= (strlen($sql_where) ? " AND " : "WHERE ") . "(site_id='" . $_REQUEST["site"] . "')";
						}
						if ($_REQUEST["type"] != "-1") {
							$sql_where .= (strlen($sql_where) ? " AND " : "WHERE ") . "(device_type_id='" . $_REQUEST["type"] . "')";
						}
						$devices = array_rekey(db_fetch_assoc("SELECT device_id, device_name FROM mac_track_devices $sql_where ORDER BY device_name"), "device_id", "device_name");
						if (sizeof($devices) > 0) {
						foreach ($devices as $device_id => $device_name) {
							print '<option value="' . $device_id .'"'; if ($_REQUEST["device"] == $device_id) { print " selected"; } print ">" . $device_name . "</option>";
						}
						}
						?>
						</select>
					</td>
					<td width="40">
						&nbsp;Rows:&nbsp;
					</td>
					<td width="1">
						<select name="rows" onChange="<?php print $filterChange;?>">
						<?php
						if (sizeof($rows_selector) > 0) {
						foreach ($rows_selector as $key => $value) {
							print '<option value="' . $key . '"'; if ($_REQUEST["rows"] == $key) { print "selected"; } print ">" . $value . "</option>\n";
						}
						}
						?>
						</select>
					</td>
				</tr>
			</table>
			<table cellpadding=1 cellspacing=0>
				<tr>
					<td width="50">
						Search:&nbsp;
					</td>
					<td width="1">
						<input type="text" name="filter" size="40" value="<?php print $_REQUEST["filter"];?>">
					</td>
					<td>
						<input type="checkbox" id="totals" name="totals" onChange="<?php print $filterChange;?>" <?php print ($_REQUEST["totals"] == "on" || $_REQUEST["totals"] == "true" ? "checked":"");?>>
					</td>
					<td>
						<label for="totals">Show Total Errors</label>
					</td>
				</tr>
			</table>
			<input type='hidden' name='page' value='1'>
			</form>
		</td>
	</tr><?php
}
Пример #30
0
/** function syslog_messages()
 *  This is the main page display function in Syslog.  Displays all the
 *  syslog messages that are relevant to Syslog.
*/
function syslog_messages($tab = "syslog")
{
    global $colors, $sql_where, $hostfilter, $severities;
    global $config, $syslog_incoming_config, $reset_multi, $syslog_levels;
    include "./include/global_arrays.php";
    /* force the initial timespan to be 30 minutes for performance reasons */
    if (!isset($_SESSION["sess_syslog_init"])) {
        $_SESSION["sess_current_timespan"] = 1;
        $_SESSION["sess_syslog_init"] = 1;
    }
    if (file_exists("./lib/timespan_settings.php")) {
        include "./lib/timespan_settings.php";
    } else {
        include "./include/html/inc_timespan_settings.php";
    }
    include dirname(__FILE__) . "/config.php";
    /* create the custom css and javascript for the page */
    generate_syslog_cssjs();
    $url_curr_page = get_browser_query_string();
    $sql_where = "";
    if ($_REQUEST["rows"] == -1) {
        $row_limit = read_config_option("num_rows_syslog");
    } elseif ($_REQUEST["rows"] == -2) {
        $row_limit = 999999;
    } else {
        $row_limit = $_REQUEST["rows"];
    }
    $syslog_messages = get_syslog_messages($sql_where, $row_limit, $tab);
    $total_rows = syslog_filter($sql_where, $tab);
    /* generate page list */
    $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, "syslog.php?tab={$tab}");
    if ($total_rows > 0) {
        $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t\t\t<td colspan='13'>\n\t\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t<strong>&lt;&lt; ";
        if ($_REQUEST["page"] > 1) {
            $nav .= "<a class='linkOverDark' href='syslog.php?tab={$tab}&page=" . ($_REQUEST["page"] - 1) . "'>";
        }
        $nav .= "Previous";
        if ($_REQUEST["page"] > 1) {
            $nav .= "</a>";
        }
        $nav .= "</strong>\n\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\tShowing Rows " . ($total_rows == 0 ? "None" : $row_limit * ($_REQUEST["page"] - 1) + 1 . " to " . ($total_rows < $row_limit || $total_rows < $row_limit * $_REQUEST["page"] ? $total_rows : $row_limit * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]") . "\n\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t<strong>";
        if ($_REQUEST["page"] * $row_limit < $total_rows) {
            $nav .= "<a class='linkOverDark' href='syslog.php?tab={$tab}&page=" . ($_REQUEST["page"] + 1) . "'>";
        }
        $nav .= "Next";
        if ($_REQUEST["page"] * $row_limit < $total_rows) {
            $nav .= "</a>";
        }
        $nav .= " &gt;&gt;</strong>\n\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
    } else {
        $nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'>\n\t\t\t\t\t<td colspan='22'>\n\t\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\tNo Rows Found\n\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
    }
    print $nav;
    if ($tab == "syslog") {
        if (api_plugin_user_realm_auth('syslog_alerts.php')) {
            $display_text = array("nosortt" => array("Actions", "ASC"), "host_id" => array("Host", "ASC"), "logtime" => array("Date", "ASC"), "message" => array("Message", "ASC"), "facility_id" => array("Facility", "ASC"), "priority_id" => array("Priority", "ASC"));
        } else {
            $display_text = array("host_id" => array("Host", "ASC"), "logtime" => array("Date", "ASC"), "message" => array("Message", "ASC"), "facility_id" => array("Facility", "ASC"), "priority_id" => array("Priority", "ASC"));
        }
        html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
        $hosts = array_rekey(syslog_db_fetch_assoc("SELECT host_id, host FROM `" . $syslogdb_default . "`.`syslog_hosts`"), "host_id", "host");
        $facilities = array_rekey(syslog_db_fetch_assoc("SELECT facility_id, facility FROM `" . $syslogdb_default . "`.`syslog_facilities`"), "facility_id", "facility");
        $priorities = array_rekey(syslog_db_fetch_assoc("SELECT priority_id, priority FROM `" . $syslogdb_default . "`.`syslog_priorities`"), "priority_id", "priority");
        $i = 0;
        if (sizeof($syslog_messages) > 0) {
            foreach ($syslog_messages as $syslog_message) {
                $title = "'" . str_replace("\"", "", str_replace("'", "", $syslog_message["message"])) . "'";
                $tip_options = "CLICKCLOSE, 'true', WIDTH, '40', DELAY, '500', FOLLOWMOUSE, 'true', FADEIN, 450, FADEOUT, 450, BGCOLOR, '#F9FDAF', STICKY, 'true', SHADOWCOLOR, '#797C6E', TITLE, 'Message'";
                syslog_row_color($colors["alternate"], $colors["light"], $i, $priorities[$syslog_message["priority_id"]], $title);
                $i++;
                if (api_plugin_user_realm_auth('syslog_alerts.php')) {
                    print "<td style='whitspace-nowrap;width:1%;'>";
                    if ($syslog_message['mtype'] == 'main') {
                        print "<a href='syslog_alerts.php?id=" . $syslog_message[$syslog_incoming_config["id"]] . "&date=" . $syslog_message["logtime"] . "&action=newedit&type=0'><img src='images/green.gif' align='absmiddle' border=0></a>\n\t\t\t\t\t\t<a href='syslog_removal.php?id=" . $syslog_message[$syslog_incoming_config["id"]] . "&date=" . $syslog_message["logtime"] . "&action=newedit&type=new&type=0'><img src='images/red.gif' align='absmiddle' border=0></a>\n";
                    }
                    print "</td>\n";
                }
                print "<td>" . $hosts[$syslog_message["host_id"]] . "</td>\n";
                print "<td>" . $syslog_message["logtime"] . "</td>\n";
                print "<td>" . (strlen($_REQUEST["filter"]) ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim($syslog_message[$syslog_incoming_config["textField"]], get_request_var_request("trimval"))) : title_trim($syslog_message[$syslog_incoming_config["textField"]], get_request_var_request("trimval"))) . "</td>\n";
                print "<td>" . ucfirst($facilities[$syslog_message["facility_id"]]) . "</td>\n";
                print "<td>" . ucfirst($priorities[$syslog_message["priority_id"]]) . "</td>\n";
            }
        } else {
            print "<tr><td><em>No Messages</em></td></tr>";
        }
        print $nav;
        html_end_box(false);
        syslog_syslog_legend();
    } else {
        $display_text = array("name" => array("Alert Name", "ASC"), "severity" => array("Severity", "ASC"), "count" => array("Count", "ASC"), "logtime" => array("Date", "ASC"), "logmsg" => array("Message", "ASC"), "slhost" => array("Host", "ASC"), "facility" => array("Facility", "ASC"), "priority" => array("Priority", "ASC"));
        html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
        $i = 0;
        if (sizeof($syslog_messages) > 0) {
            foreach ($syslog_messages as $log) {
                $title = "'" . str_replace("\"", "", str_replace("'", "", $log["logmsg"])) . "'";
                $tip_options = "CLICKCLOSE, 'true', WIDTH, '40', DELAY, '500', FOLLOWMOUSE, 'true', FADEIN, 450, FADEOUT, 450, BGCOLOR, '#F9FDAF', STICKY, 'true', SHADOWCOLOR, '#797C6E', TITLE, 'Message'";
                switch ($log['severity']) {
                    case "0":
                        $color = "notice";
                        break;
                    case "1":
                        $color = "warn";
                        break;
                    case "2":
                        $color = "crit";
                        break;
                    default:
                        $color = "info";
                        break;
                }
                syslog_row_color($colors["alternate"], $colors["light"], $i, $color, $title);
                $i++;
                print "<td><a class='linkEditMain' href='" . $config["url_path"] . "plugins/syslog/syslog.php?id=" . $log["seq"] . "&tab=current'>" . (strlen($log["name"]) ? $log["name"] : "Alert Removed") . "</a></td>\n";
                print "<td>" . (isset($severities[$log["severity"]]) ? $severities[$log["severity"]] : "Unknown") . "</td>\n";
                print "<td>" . $log["count"] . "</td>\n";
                print "<td>" . $log["logtime"] . "</td>\n";
                print "<td>" . (strlen($_REQUEST["filter"]) ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim($log["logmsg"], get_request_var_request("trimval"))) : title_trim($log["logmsg"], get_request_var_request("trimval"))) . "</td>\n";
                print "<td>" . $log["host"] . "</td>\n";
                print "<td>" . ucfirst($log["facility"]) . "</td>\n";
                print "<td>" . ucfirst($log["priority"]) . "</td>\n";
            }
        } else {
            print "<tr><td><em>No Messages</em></td></tr>";
        }
        print $nav;
        html_end_box(false);
        syslog_log_legend();
    }
    /* put the nav bar on the bottom as well */
    ?>

								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			</form>
			<script type='text/javascript'>
			function syslogFindPos(obj) {
				var curleft = curtop = 0;

				if (obj.offsetParent) {
					curleft = obj.offsetLeft;
					curtop  = obj.offsetTop;

					while (obj = obj.offsetParent) {
						curleft += obj.offsetLeft;
						curtop  += obj.offsetTop;
					}
				}

				return [curleft,curtop];
			}

			function setHostMultiSelect() {
				selectPos = syslogFindPos(document.getElementById("host_select"));
				textSize  = document.getElementById("host_all").scrollHeight;
				if (textSize == 0) textSize = 16;

				if (window.innerHeight) {
					height = window.innerHeight;
				}else{
					height = document.body.clientHeight;
				}
				//alert("Height:"+height+", YPos:"+selectPos[1]+", TextSize:"+textSize);

				/* the full window size of the multi-select */
				size = parseInt((height-selectPos[1]-5)/textSize);
				window.onresize = null;
				document.getElementById("host_select").size=size;
				window.onresize = this;
			}

			window.onresize = setHostMultiSelect;
			window.onload   = setHostMultiSelect;
			</script>
<?php 
}