Example #1
0
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);
}
Example #2
0
function update_data_query_sort_cache_by_host($host_id) {
	$data_queries = db_fetch_assoc("select snmp_query_id from host_snmp_query where host_id = '$host_id'");

	if (sizeof($data_queries) > 0) {
		foreach ($data_queries as $data_query) {
			update_data_query_sort_cache($host_id, $data_query["snmp_query_id"]);
		}
	}
}
Example #3
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;
                }
            }
        }
    }
}
Example #4
0
    display_help();
    exit;
}
/* get all object that have to be scanned */
$data_queries = db_fetch_assoc("SELECT " . "`data_local`.`host_id`, " . "`data_local`.`snmp_query_id`, " . "`data_local`.`snmp_index`, " . "`data_template_data`.`local_data_id`, " . "`data_template_data`.`data_input_id`, " . "`data_input_data`.`data_template_data_id`, " . "`data_input_data`.`data_input_field_id`, " . "`data_input_data`.`value` " . "FROM data_local " . "LEFT JOIN data_template_data ON data_local.id=data_template_data.local_data_id " . "LEFT JOIN data_input_fields ON data_template_data.data_input_id = data_input_fields.data_input_id " . "LEFT JOIN data_input_data ON ( " . "data_template_data.id = data_input_data.data_template_data_id " . "AND data_input_fields.id = data_input_data.data_input_field_id " . ") " . $sql_where . " ");
/* issue warnings and start message if applicable */
print "WARNING: Do not interrupt this script.  Reordering can take quite some time\n";
debug("There are '" . sizeof($data_queries) . "' data query index items to run");
$i = 1;
if (sizeof($data_queries)) {
    foreach ($data_queries as $data_query) {
        if (!$debug) {
            print ".";
        }
        /* fetch current index_order from data_query XML definition and put it into host_snmp_query */
        update_data_query_sort_cache($data_query["host_id"], $data_query["snmp_query_id"]);
        /* build array required for function call */
        $data_query["snmp_index_on"] = get_best_data_query_index_type($data_query["host_id"], $data_query["snmp_query_id"]);
        /* as we request the output_type, "value" gives the snmp_query_graph_id */
        $data_query["snmp_query_graph_id"] = $data_query["value"];
        debug("Data Query #'" . $i . "' host: '" . $data_query["host_id"] . "' SNMP Query Id: '" . $data_query["snmp_query_id"] . "' Index: " . $data_query["snmp_index"] . "' Index On: " . $data_query["snmp_index_on"]);
        update_snmp_index_order($data_query);
        $i++;
    }
}
/**
 * perform sql updates for all required tables for new index_sort_order
 * @arg array $snmp_query_array
 * 				$host_id
 * 				snmp_query_id
 * 				snmp_index_on
Example #5
0
function update_data_query_sort_cache_by_host($host_id)
{
    $data_queries = db_fetch_assoc("SELECT snmp_query_id FROM host_snmp_query WHERE host_id = '{$host_id}'");
    if (sizeof($data_queries) > 0) {
        foreach ($data_queries as $data_query) {
            update_data_query_sort_cache($host_id, $data_query["snmp_query_id"]);
        }
    }
}
Example #6
0
<?php

$no_http_headers = true;
include "../include/global.php";
include "../lib/data_query.php";
$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"]);
    }
}