Exemple #1
0
function run_data_query($host_id, $snmp_query_id)
{
    global $config, $input_types;
    include_once $config["library_path"] . "/poller.php";
    include_once $config["library_path"] . "/utility.php";
    debug_log_insert("data_query", "Running data query [{$snmp_query_id}].");
    $type_id = db_fetch_cell("select data_input.type_id from (snmp_query,data_input) where snmp_query.data_input_id=data_input.id and snmp_query.id={$snmp_query_id}");
    if (isset($input_types[$type_id])) {
        debug_log_insert("data_query", "Found type = '" . $type_id . "' [" . $input_types[$type_id] . "].");
    }
    if ($type_id == DATA_INPUT_TYPE_SNMP_QUERY) {
        $result = query_snmp_host($host_id, $snmp_query_id);
    } elseif ($type_id == DATA_INPUT_TYPE_SCRIPT_QUERY) {
        $result = query_script_host($host_id, $snmp_query_id);
    } elseif ($type_id == DATA_INPUT_TYPE_QUERY_SCRIPT_SERVER) {
        $result = query_script_host($host_id, $snmp_query_id);
    } else {
        debug_log_insert("data_query", "Unknown type = '{$type_id}'");
    }
    /* update the sort cache */
    update_data_query_sort_cache($host_id, $snmp_query_id);
    /* update the auto reindex cache */
    update_reindex_cache($host_id, $snmp_query_id);
    /* update the the "local" data query cache */
    update_data_query_cache($host_id, $snmp_query_id);
    /* update the poller cache */
    update_poller_cache_from_query($host_id, $snmp_query_id);
    api_plugin_hook_function('run_data_query', array("host_id" => $host_id, "snmp_query_id" => $snmp_query_id));
    return isset($result) ? $result : true;
}
function api_data_query_execute($host_id, $data_query_id) {
	require_once(CACTI_BASE_PATH . "/include/data_query/data_query_constants.php");
	require_once(CACTI_BASE_PATH . "/lib/data_query/data_query_info.php");
	require_once(CACTI_BASE_PATH . "/lib/data_query/data_query_update.php");
	require_once(CACTI_BASE_PATH . "/lib/poller.php");

	/* get information about the data query */
	$data_query = api_data_query_get($data_query_id);

	debug_log_insert("data_query", "Running data query [$data_query_id].");

	if ($data_query["input_type"] == DATA_QUERY_INPUT_TYPE_SNMP_QUERY) {
		debug_log_insert("data_query", _("Found type = '1' [snmp query]."));
		$result = api_data_query_snmp_execute($host_id, $data_query_id);
	}elseif ($data_query["input_type"] == DATA_QUERY_INPUT_TYPE_SCRIPT_QUERY) {
		debug_log_insert("data_query", _("Found type = '2 '[script query]."));
		$result = api_data_query_script_execute($host_id, $data_query_id);
	}elseif ($data_query["input_type"] == DATA_QUERY_INPUT_TYPE_PHP_SCRIPT_SERVER_QUERY) {
		debug_log_insert("data_query", _("Found type = '3 '[php script server query]."));
		$result = api_data_query_script_execute($host_id, $data_query_id);
	}else{
		debug_log_insert("data_query", sprintf(_("Unknown type = '%i'"), $data_query["input_type"]));
	}

	/* update the sort cache */
	update_data_query_sort_cache($host_id, $data_query_id);

	/* update the auto reindex cache */
	update_reindex_cache($host_id, $data_query_id);

	/* update the poller cache */
	update_poller_cache_from_query($host_id, $data_query_id);

	return (isset($result) ? $result : true);
}
Exemple #3
0
function run_data_query($host_id, $snmp_query_id) {
	global $config;

	include_once($config["library_path"] . "/poller.php");

	debug_log_insert("data_query", "Running data query [$snmp_query_id].");
	$type_id = db_fetch_cell("select data_input.type_id from snmp_query,data_input where snmp_query.data_input_id=data_input.id and snmp_query.id=$snmp_query_id");

	if ($type_id == DATA_INPUT_TYPE_SNMP_QUERY) {
		debug_log_insert("data_query", "Found type = '3' [snmp query].");
		$result = query_snmp_host($host_id, $snmp_query_id);
	}elseif ($type_id == DATA_INPUT_TYPE_SCRIPT_QUERY) {
		debug_log_insert("data_query", "Found type = '4 '[script query].");
		$result = query_script_host($host_id, $snmp_query_id);
	}elseif ($type_id == DATA_INPUT_TYPE_QUERY_SCRIPT_SERVER) {
		debug_log_insert("data_query", "Found type = '6 '[script query].");
		$result = query_script_host($host_id, $snmp_query_id);
	}else{
		debug_log_insert("data_query", "Unknown type = '$type_id'");
	}

	/* update the sort cache */
	update_data_query_sort_cache($host_id, $snmp_query_id);

	/* update the auto reindex cache */
	update_reindex_cache($host_id, $snmp_query_id);

	/* update the the "local" data query cache */
	update_data_query_cache($host_id, $snmp_query_id);

	return (isset($result) ? $result : true);
}
Exemple #4
0
/**
 * run the data query
 * @param int $device_id
 * @param int $snmp_query_id
 */
function run_data_query($device_id, $snmp_query_id) {
	global $config;

	require_once(CACTI_BASE_PATH . "/include/data_input/data_input_constants.php");
	include_once(CACTI_BASE_PATH . "/lib/poller.php");
	include_once(CACTI_BASE_PATH . "/lib/utility.php");

	debug_log_insert("data_query", __("Running data query") . " [$snmp_query_id].");
	$type_id = db_fetch_cell("select data_input.type_id from (snmp_query,data_input) where snmp_query.data_input_id=data_input.id and snmp_query.id=$snmp_query_id");

	if ($type_id == DATA_INPUT_TYPE_SNMP_QUERY) {
		debug_log_insert("data_query", __("Found type") . " = '3' [snmp query].");
		$result = query_snmp_device($device_id, $snmp_query_id);
	}elseif ($type_id == DATA_INPUT_TYPE_SCRIPT_QUERY) {
		debug_log_insert("data_query", __("Found type") . " = '4 '[script query].");
		$result = query_script_device($device_id, $snmp_query_id);
	}elseif ($type_id == DATA_INPUT_TYPE_QUERY_SCRIPT_SERVER) {
		debug_log_insert("data_query", __("Found type") . " = '6 '[script query].");
		$result = query_script_device($device_id, $snmp_query_id);
	}else{
		debug_log_insert("data_query", __("Unknown type") . " = '$type_id'");
	}

	/* update the sort cache */
	update_data_query_sort_cache($device_id, $snmp_query_id);

	/* update the auto reindex cache */
	update_reindex_cache($device_id, $snmp_query_id);

	/* update the the "local" data query cache */
	update_data_query_cache($device_id, $snmp_query_id);

	/* update the poller cache */
	update_poller_cache_from_query($device_id, $snmp_query_id);

	api_plugin_hook_function('run_data_query', array("device_id" => $device_id, "snmp_query_id" => $snmp_query_id));

	return (isset($result) ? $result : true);
}
Exemple #5
0
function upgrade_to_0_8_6()
{
    include "../lib/data_query.php";
    include "../lib/tree.php";
    include "../lib/import.php";
    include "../lib/poller.php";
    db_install_execute("0.8.6", "DROP TABLE `snmp_query_field`;");
    db_install_execute("0.8.6", "DROP TABLE `data_input_data_cache`;");
    db_install_execute("0.8.6", "DROP TABLE `data_input_data_fcache`;");
    /* distributed poller support */
    db_install_execute("0.8.6", "CREATE TABLE `poller` (`id` smallint(5) unsigned NOT NULL auto_increment, `hostname` varchar(250) NOT NULL default '', `ip_address` int(11) unsigned NOT NULL default '0', `last_update` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY  (`id`)) TYPE=MyISAM;");
    db_install_execute("0.8.6", "CREATE TABLE `poller_command` (`poller_id` smallint(5) unsigned NOT NULL default '0', `time` datetime NOT NULL default '0000-00-00 00:00:00', `action` tinyint(3) unsigned NOT NULL default '0', `command` varchar(200) NOT NULL default '', PRIMARY KEY  (`poller_id`,`action`,`command`)) TYPE=MyISAM;");
    db_install_execute("0.8.6", "CREATE TABLE `poller_item` (`local_data_id` mediumint(8) unsigned NOT NULL default '0', `poller_id` smallint(5) unsigned NOT NULL default '0', `host_id` mediumint(8) NOT NULL default '0', `action` tinyint(2) unsigned NOT NULL default '1', `hostname` varchar(250) NOT NULL default '', `snmp_community` varchar(100) NOT NULL default '', `snmp_version` tinyint(1) unsigned NOT NULL default '0', `snmp_username` varchar(50) NOT NULL default '', `snmp_password` varchar(50) NOT NULL default '', `snmp_port` mediumint(5) unsigned NOT NULL default '161', `snmp_timeout` mediumint(8) unsigned NOT NULL default '0', `rrd_name` varchar(19) NOT NULL default '', `rrd_path` varchar(255) NOT NULL default '', `rrd_num` tinyint(2) unsigned NOT NULL default '0', `arg1` varchar(255) default NULL, `arg2` varchar(255) default NULL, `arg3` varchar(255) default NULL, PRIMARY KEY  (`local_data_id`,`rrd_name`), KEY `local_data_id` (`local_data_id`), KEY `host_id` (`host_id`)) TYPE=MyISAM;");
    db_install_execute("0.8.6", "CREATE TABLE `poller_output` (`local_data_id` mediumint(8) unsigned NOT NULL default '0', `rrd_name` varchar(19) NOT NULL default '', `time` datetime NOT NULL default '0000-00-00 00:00:00', `output` text NOT NULL, PRIMARY KEY  (`local_data_id`,`rrd_name`,`time`)) TYPE=MyISAM;");
    db_install_execute("0.8.6", "CREATE TABLE `poller_reindex` (`host_id` mediumint(8) unsigned NOT NULL default '0', `data_query_id` mediumint(8) unsigned NOT NULL default '0', `action` tinyint(3) unsigned NOT NULL default '0', `op` char(1) NOT NULL default '', `assert_value` varchar(100) NOT NULL default '', `arg1` varchar(100) NOT NULL default '', PRIMARY KEY  (`host_id`,`data_query_id`,`arg1`)) TYPE=MyISAM;");
    db_install_execute("0.8.6", "CREATE TABLE `poller_time` (`id` mediumint(8) unsigned NOT NULL auto_increment, `poller_id` smallint(5) unsigned NOT NULL default '0', `start_time` datetime NOT NULL default '0000-00-00 00:00:00', `end_time` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY  (`id`)) TYPE=MyISAM;");
    db_install_execute("0.8.6", "ALTER TABLE `graph_tree_items` ADD `host_grouping_type` TINYINT( 3 ) UNSIGNED DEFAULT '1' NOT NULL, ADD `sort_children_type` TINYINT( 3 ) UNSIGNED DEFAULT '1' NOT NULL;");
    db_install_execute("0.8.6", "ALTER TABLE `host_snmp_query` ADD `sort_field` VARCHAR( 50 ) NOT NULL, ADD `title_format` VARCHAR( 50 ) NOT NULL, ADD `reindex_method` TINYINT( 3 ) UNSIGNED DEFAULT '1' NOT NULL;");
    db_install_execute("0.8.6", "ALTER TABLE `graph_tree` CHANGE `user_id` `sort_type` TINYINT( 3 ) UNSIGNED DEFAULT '1' NOT NULL;");
    db_install_execute("0.8.6", "ALTER TABLE `graph_tree_items` CHANGE `order_key` `order_key` VARCHAR( 100 ) DEFAULT '0' NOT NULL;");
    db_install_execute("0.8.6", "ALTER TABLE `host` ADD `status_event_count` mediumint(8) unsigned NOT NULL default '0', ADD `status_fail_date` datetime NOT NULL default '0000-00-00 00:00:00', ADD `status_rec_date` datetime NOT NULL default '0000-00-00 00:00:00', ADD `status_last_error` varchar(50) default '', ADD `min_time` decimal(7,5) default '9.99999', ADD `max_time` decimal(7,5) default '0.00000', ADD `cur_time` decimal(7,5) default '0.00000', ADD `avg_time` decimal(7,5) default '0.00000', ADD `total_polls` int(12) unsigned default '0', ADD `failed_polls` int(12) unsigned default '0', ADD `availability` decimal(7,5) default '100.000' NOT NULL;");
    db_install_execute("0.8.6", "UPDATE snmp_query_graph_rrd_sv set text = REPLACE(text,' (In)','') where snmp_query_graph_id = 2;");
    db_install_execute("0.8.6", "UPDATE graph_tree set sort_type = '1';");
    /* update the sort cache */
    $host_snmp_query = db_fetch_assoc("select host_id,snmp_query_id from host_snmp_query");
    if (sizeof($host_snmp_query) > 0) {
        foreach ($host_snmp_query as $item) {
            update_data_query_sort_cache($item["host_id"], $item["snmp_query_id"]);
            update_reindex_cache($item["host_id"], $item["snmp_query_id"]);
        }
    }
    /* script query data input methods */
    $xml_data = "<cacti>\n\t\t\t<hash_030003332111d8b54ac8ce939af87a7eac0c06>\n\t\t\t\t<name>Get Script Server Data (Indexed)</name>\n\t\t\t\t<type_id>6</type_id>\n\t\t\t\t<input_string></input_string>\n\t\t\t\t<fields>\n\t\t\t\t\t<hash_070003172b4b0eacee4948c6479f587b62e512>\n\t\t\t\t\t\t<name>Index Type</name>\n\t\t\t\t\t\t<update_rra></update_rra>\n\t\t\t\t\t\t<regexp_match></regexp_match>\n\t\t\t\t\t\t<allow_nulls></allow_nulls>\n\t\t\t\t\t\t<type_code>index_type</type_code>\n\t\t\t\t\t\t<input_output>in</input_output>\n\t\t\t\t\t\t<data_name>index_type</data_name>\n\t\t\t\t\t</hash_070003172b4b0eacee4948c6479f587b62e512>\n\t\t\t\t\t<hash_07000330fb5d5bcf3d66bb5abe88596f357c26>\n\t\t\t\t\t\t<name>Index Value</name>\n\t\t\t\t\t\t<update_rra></update_rra>\n\t\t\t\t\t\t<regexp_match></regexp_match>\n\t\t\t\t\t\t<allow_nulls></allow_nulls>\n\t\t\t\t\t\t<type_code>index_value</type_code>\n\t\t\t\t\t\t<input_output>in</input_output>\n\t\t\t\t\t\t<data_name>index_value</data_name>\n\t\t\t\t\t</hash_07000330fb5d5bcf3d66bb5abe88596f357c26>\n\t\t\t\t\t<hash_07000331112c85ae4ff821d3b288336288818c>\n\t\t\t\t\t\t<name>Output Type ID</name>\n\t\t\t\t\t\t<update_rra></update_rra>\n\t\t\t\t\t\t<regexp_match></regexp_match>\n\t\t\t\t\t\t<allow_nulls></allow_nulls>\n\t\t\t\t\t\t<type_code>output_type</type_code>\n\t\t\t\t\t\t<input_output>in</input_output>\n\t\t\t\t\t\t<data_name>output_type</data_name>\n\t\t\t\t\t</hash_07000331112c85ae4ff821d3b288336288818c>\n\t\t\t\t\t<hash_0700035be8fa85472d89c621790b43510b5043>\n\t\t\t\t\t\t<name>Output Value</name>\n\t\t\t\t\t\t<update_rra>on</update_rra>\n\t\t\t\t\t\t<regexp_match></regexp_match>\n\t\t\t\t\t\t<allow_nulls></allow_nulls>\n\t\t\t\t\t\t<type_code></type_code>\n\t\t\t\t\t\t<input_output>out</input_output>\n\t\t\t\t\t\t<data_name>output</data_name>\n\t\t\t\t\t</hash_0700035be8fa85472d89c621790b43510b5043>\n\t\t\t\t</fields>\n\t\t\t</hash_030003332111d8b54ac8ce939af87a7eac0c06>\n\t\t</cacti>";
    import_xml_data($xml_data);
    /* update trees to three characters per tier */
    $trees = db_fetch_assoc("select id from graph_tree");
    if (sizeof($trees) > 0) {
        foreach ($trees as $tree) {
            $tree_items = db_fetch_assoc("select\n\t\t\t\tgraph_tree_items.id,\n\t\t\t\tgraph_tree_items.order_key\n\t\t\t\tfrom graph_tree_items\n\t\t\t\twhere graph_tree_items.graph_tree_id='" . $tree["id"] . "'\n\t\t\t\torder by graph_tree_items.order_key");
            if (sizeof($tree_items) > 0) {
                $_tier = 0;
                /* only do the upgrade once */
                if ($tree_items[0]["order_key"] == "001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") {
                    return;
                }
                foreach ($tree_items as $tree_item) {
                    $tier = tree_tier($tree_item["order_key"], 2);
                    /* back off */
                    if ($tier < $_tier) {
                        for ($i = $_tier; $i > $tier; $i--) {
                            $tier_counter[$i] = 0;
                        }
                    }
                    /* we key tier==0 off of '1' and tier>0 off of '0' */
                    if (!isset($tier_counter[$tier])) {
                        $tier_counter[$tier] = 1;
                    } else {
                        $tier_counter[$tier]++;
                    }
                    $search_key = preg_replace("/0+\$/", "", $tree_item["order_key"]);
                    if (strlen($search_key) % 2 != 0) {
                        $search_key .= "0";
                    }
                    $new_search_key = "";
                    for ($i = 1; $i < $tier; $i++) {
                        $new_search_key .= str_pad(strval($tier_counter[$i]), 3, '0', STR_PAD_LEFT);
                    }
                    /* build the new order key string */
                    $key = str_pad($new_search_key . str_pad(strval($tier_counter[$tier]), 3, '0', STR_PAD_LEFT), 90, '0', STR_PAD_RIGHT);
                    db_execute("update graph_tree_items set order_key='{$key}' where id=" . $tree_item["id"]);
                    $_tier = $tier;
                }
            }
        }
    }
}