Esempio n. 1
0
function export_tree_html($path, $filename, $tree_id, $parent_tree_item_id)
{
    /* auth check for hosts on the trees */
    if (read_config_option("auth_method") != 0) {
        $current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . read_config_option("export_user_id"));
        $sql_join = "LEFT JOIN user_auth_perms ON (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . read_config_option("export_user_id") . ")";
        if ($current_user["policy_hosts"] == "1") {
            $sql_where = "AND !(user_auth_perms.user_id IS NOT NULL AND graph_tree_items.host_id>0)";
        } elseif ($current_user["policy_hosts"] == "2") {
            $sql_where = "AND !(user_auth_perms.user_id IS NULL AND graph_tree_items.host_id>0)";
        }
    } else {
        $sql_join = "";
        $sql_where = "";
    }
    if ($tree_id == 0) {
        $sql_where = "WHERE graph_tree_items.local_graph_id=0\n\t\t\t{$sql_where}";
    } else {
        $sql_where = "WHERE graph_tree_items.graph_tree_id=" . $tree_id . "\n\t\t\t{$sql_where}\n\t\t\tAND graph_tree_items.local_graph_id=0";
    }
    $hier_sql = "SELECT DISTINCT\n\t\tgraph_tree.name,\n\t\tgraph_tree.id AS tree_id,\n\t\tgraph_tree_items.id,\n\t\tgraph_tree_items.title,\n\t\tgraph_tree_items.order_key,\n\t\tgraph_tree_items.host_id,\n\t\tgraph_tree_items.host_grouping_type,\n\t\thost.description AS hostname\n\t\tFROM graph_tree\n\t\tLEFT JOIN (graph_tree_items\n\t\tLEFT JOIN host ON (graph_tree_items.host_id=host.id)\n\t\t{$sql_join})\n\t\tON graph_tree.id = graph_tree_items.graph_tree_id\n\t\t{$sql_where}\n\t\tORDER BY graph_tree.name, graph_tree_items.order_key";
    $hierarchy = db_fetch_assoc($hier_sql);
    /* build all the html files */
    if (sizeof($hierarchy) > 0) {
        foreach ($hierarchy as $leaf) {
            if ($leaf["host_id"] > 0) {
                build_html_file($leaf, "host");
                if (read_config_option("export_tree_expand_hosts") == "on") {
                    if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
                        $graph_templates = db_fetch_assoc("SELECT\n\t\t\t\t\t\t\tgraph_templates.id,\n\t\t\t\t\t\t\tgraph_templates.name,\n\t\t\t\t\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\t\t\t\t\tgraph_templates_graph.title_cache\n\t\t\t\t\t\t\tFROM (graph_local,graph_templates,graph_templates_graph)\n\t\t\t\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t\t\t\t\t\tAND graph_templates_graph.graph_template_id=graph_templates.id\n\t\t\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\t\t\tAND graph_templates_graph.export='on'\n\t\t\t\t\t\t\tGROUP BY graph_templates.id\n\t\t\t\t\t\t\tORDER BY graph_templates.name");
                        if (sizeof($graph_templates)) {
                            foreach ($graph_templates as $graph_template) {
                                build_html_file($leaf, "gt", $graph_template);
                            }
                        }
                    } else {
                        if ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
                            $data_queries = db_fetch_assoc("SELECT\n\t\t\t\t\t\t\tsnmp_query.id,\n\t\t\t\t\t\t\tsnmp_query.name\n\t\t\t\t\t\t\tFROM (graph_local,snmp_query)\n\t\t\t\t\t\t\tWHERE graph_local.snmp_query_id=snmp_query.id\n\t\t\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\t\t\tGROUP BY snmp_query.id\n\t\t\t\t\t\t\tORDER BY snmp_query.name");
                            array_push($data_queries, array("id" => "0", "name" => "Graph Template Based"));
                            foreach ($data_queries as $data_query) {
                                build_html_file($leaf, "dq", $data_query);
                                /* fetch a list of field names that are sorted by the preferred sort field */
                                $sort_field_data = get_formatted_data_query_indexes($leaf["host_id"], $data_query["id"]);
                                if ($data_query["id"] > 0) {
                                    while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
                                        build_html_file($leaf, "dqi", $data_query, $snmp_index);
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                build_html_file($leaf, "leaf");
            }
        }
    }
}
Esempio n. 2
0
function export_tree_html($path, $filename, $tree_id, $parent_tree_item_id) {
	require(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_arrays.php");

	/* auth check for devices on the trees */
	if (read_config_option("auth_method") != 0) {
		$current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . read_config_option("export_user_id"));

		$sql_join = "LEFT JOIN user_auth_perms ON (device.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . read_config_option("export_user_id") . ")";

		if ($current_user["policy_devices"] == "1") {
			$sql_where = "AND !(user_auth_perms.user_id IS NOT NULL AND graph_tree_items.device_id>0)";
		}elseif ($current_user["policy_devices"] == "2") {
			$sql_where = "AND !(user_auth_perms.user_id IS NULL AND graph_tree_items.device_id>0)";
		}
	}else{
		$sql_join  = "";
		$sql_where = "";
	}

	if ($tree_id == 0) {
		$sql_where = "WHERE graph_tree_items.local_graph_id=0
			$sql_where";
	}else{
		$sql_where = "WHERE graph_tree_items.graph_tree_id=" . $tree_id . "
			$sql_where
			AND graph_tree_items.local_graph_id=0";
	}

	$hier_sql = "SELECT DISTINCT
		graph_tree.name,
		graph_tree.id AS tree_id,
		graph_tree_items.id,
		graph_tree_items.title,
		graph_tree_items.order_key,
		graph_tree_items.device_id,
		graph_tree_items.device_grouping_type,
		device.description AS hostname
		FROM graph_tree
		LEFT JOIN (graph_tree_items
		LEFT JOIN device ON (graph_tree_items.device_id=device.id)
		$sql_join)
		ON graph_tree.id = graph_tree_items.graph_tree_id
		$sql_where
		ORDER BY graph_tree.name, graph_tree_items.order_key";

	$hierarchy = db_fetch_assoc($hier_sql);

	/* build all the html files */
	if (sizeof($hierarchy) > 0) {
		foreach ($hierarchy as $leaf) {
			if ($leaf["device_id"] > 0) {
				build_html_file($leaf, "device");

				if (read_config_option("export_tree_expand_devices") == CHECKED) {
					if ($leaf["device_grouping_type"] == TREE_DEVICE_GROUPING_GRAPH_TEMPLATE) {
						$graph_templates = db_fetch_assoc("SELECT
							graph_templates.id,
							graph_templates.name,
							graph_templates_graph.local_graph_id,
							graph_templates_graph.title_cache
							FROM (graph_local,graph_templates,graph_templates_graph)
							WHERE graph_local.id=graph_templates_graph.local_graph_id
							AND graph_templates_graph.graph_template_id=graph_templates.id
							AND graph_local.device_id=" . $leaf["device_id"] . "
							AND graph_templates_graph.export='on'
							GROUP BY graph_templates.id
							ORDER BY graph_templates.name");

						if (sizeof($graph_templates)) {
							foreach($graph_templates as $graph_template) {
								build_html_file($leaf, "gt", $graph_template);
							}
						}
					}else if ($leaf["device_grouping_type"] == TREE_DEVICE_GROUPING_DATA_QUERY_INDEX) {
						$data_queries = db_fetch_assoc("SELECT
							snmp_query.id,
							snmp_query.name
							FROM (graph_local,snmp_query)
							WHERE graph_local.snmp_query_id=snmp_query.id
							AND graph_local.device_id=" . $leaf["device_id"] . "
							GROUP BY snmp_query.id
							ORDER BY snmp_query.name");

						array_push($data_queries, array(
							"id" => "0",
							"name" => "Graph Template Based"
							));

						foreach ($data_queries as $data_query) {
							build_html_file($leaf, "dq", $data_query);

							/* fetch a list of field names that are sorted by the preferred sort field */
							$sort_field_data = get_formatted_data_query_indexes($leaf["device_id"], $data_query["id"]);

							if ($data_query["id"] > 0) {
								while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
									build_html_file($leaf, "dqi", $data_query, $snmp_index);
								}
							}
						}
					}
				}
			}else{
				build_html_file($leaf, "leaf");
			}
		}
	}
}