Esempio n. 1
0
function api_graph_template_list($filter_array = "", $current_page = 0, $rows_per_page = 0) {
	require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_form.php");

	$sql_where = "";
	/* validation and setup for the WHERE clause */
	if ((is_array($filter_array)) && (sizeof($filter_array) > 0)) {
		/* validate each field against the known master field list */
		$field_errors = api_graph_template_fields_validate(sql_filter_array_to_field_array($filter_array));

		/* if a field input error has occured, register the error in the session and return */
		if (sizeof($field_errors) > 0) {
			field_register_error($field_errors);
			return false;
		/* otherwise, form an SQL WHERE string using the filter fields */
		}else{
			$sql_where = sql_filter_array_to_where_string($filter_array, api_graph_template_form_list(), true);
		}
	}

	$sql_limit = "";
	/* validation and setup for the LIMIT clause */
	if ((is_numeric($current_page)) && (is_numeric($rows_per_page)) && (!empty($current_page)) && (!empty($rows_per_page))) {
		$sql_limit = "limit " . ($rows_per_page * ($current_page - 1)) . ",$rows_per_page";
	}

	return db_fetch_assoc("select
		graph_template.id,
		graph_template.template_name
		from graph_template
		$sql_where
		" . ($sql_where == "" ? "where" : "and") . " graph_template.package_id = 0
		order by template_name
		$sql_limit");
}
Esempio n. 2
0
/**
 * List auth records
 *
 * Given filter array, return list of user records
 *
 * @param array $filter_array filter array, field => value elements
 * @return array user records
 */
function api_auth_control_list ($control_type, $filter_array, $limit = -1, $offset = -1) {

	if (empty($control_type)) {
		return array();
	}

	$sql_where = " WHERE object_type = " . $control_type . " ";

	/* validation and setup for the WHERE clauses */
	if ((is_array($filter_array)) && (sizeof($filter_array) > 0)) {
		/* validate each field against the known master field list */
		$field_errors = validate_auth_control_fields(sql_filter_array_to_field_array($filter_array), "|field|");

		/* if a field input error has occured, register the error in the session and return */
		if (sizeof($field_errors) > 0) {
			field_register_error($field_errors);
			return false;

		/* otherwise, form an SQL WHERE string using the filter fields */
		}else{
			$sql_where .= sql_filter_array_to_where_string($filter_array, api_auth_user_form_list(), false);
		}

	}

        return db_fetch_assoc("SELECT * FROM (auth_control) $sql_where ORDER BY auth_control.name ASC",$limit,$offset);

}
Esempio n. 3
0
/**
 * List Event records
 *
 * Given filter array, return list of event records
 *
 * @param array $filter_array filter array, field => value elements
 * @return array event records
 */
function event_list ($filter_array) {
	$sql_where = '';
	/* validation and setup for the WHERE clause */
	if ((is_array($filter_array)) && (sizeof($filter_array) > 0)) {
		/* validate each field against the known master field list */
		$field_errors = event_validate(sql_filter_array_to_field_array($filter_array));

		/* if a field input error has occured, register the error in the session and return */
		if (sizeof($field_errors) > 0) {
			field_register_error($field_errors);
			return false;
		/* otherwise, form an SQL WHERE string using the filter fields */
		}else{
			$sql_where = sql_filter_array_to_where_string($filter_array, event_list_form(), true);
		}
	}
	return db_fetch_assoc("SELECT * FROM event_queue_control $sql_where ORDER BY id");
}
Esempio n. 4
0
function api_device_total_get($filter_array = "") {
	require_once(CACTI_BASE_PATH . "/lib/device/device_form.php");

	$sql_where = "";
	/* validation and setup for the WHERE clause */
	if ((is_array($filter_array)) && (sizeof($filter_array) > 0)) {
		/* validate each field against the known master field list */
		$field_errors = api_device_field_validate(sql_filter_array_to_field_array($filter_array), "|field|");

		/* if a field input error has occured, register the error in the session and return */
		if (sizeof($field_errors) > 0) {
			field_register_error($field_errors);
			return false;
		/* otherwise, form an SQL WHERE string using the filter fields */
		}else{
			$sql_where = sql_filter_array_to_where_string($filter_array, api_device_form_list(), true);
		}
	}

	return db_fetch_cell("select count(*) from host $sql_where");
}
Esempio n. 5
0
function api_graph_tree_item_list($graph_tree_id, $filter_array = "", $limit_sub_tree_id = "", $show_sub_tree_parent = false, $show_sub_tree_children = true, $current_page = 0, $rows_per_page = 0) {
	/* sanity checks */
	validate_id_die($graph_tree_id, "graph_tree_id");

	require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_form.php");

	$sql_where = "";
	/* validation and setup for the WHERE clause */
	if ((is_array($filter_array)) && (sizeof($filter_array) > 0)) {
		/* validate each field against the known master field list */
		$field_errors = api_graph_tree_item_fields_validate(sql_filter_array_to_field_array($filter_array));

		/* if a field input error has occured, register the error in the session and return */
		if (sizeof($field_errors) > 0) {
			field_register_error($field_errors);
			return false;
		/* otherwise, form an SQL WHERE string using the filter fields */
		}else{
			$sql_where = sql_filter_array_to_where_string($filter_array, api_graph_tree_item_form_list(), false);
		}
	}

	$sql_limit = "";
	/* validation and setup for the LIMIT clause */
	if ((is_numeric($current_page)) && (is_numeric($rows_per_page)) && (!empty($current_page)) && (!empty($rows_per_page))) {
		$sql_limit = "limit " . ($rows_per_page * ($current_page - 1)) . ",$rows_per_page";
	}

	/* only show tree items under this item if specified */
	if (db_integer_validate($limit_sub_tree_id, false, false)) {
		$graph_tree_item = api_graph_tree_item_get($limit_sub_tree_id);
		$search_key = substr($graph_tree_item["order_key"], 0, (api_graph_tree_item_depth_get($graph_tree_item["order_key"]) * CHARS_PER_TIER));

		if ($show_sub_tree_children == true) {
			$sql_where .= "and graph_tree_items.order_key like '$search_key%%'";
		}else{
			$sql_where .= " and graph_tree_items.order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'";
		}

		if ($show_sub_tree_parent == false) {
			$sql_where .= "and graph_tree_items.id != $limit_sub_tree_id";
		}
	}

	return db_fetch_assoc("select
		graph_tree_items.id,
		graph_tree_items.order_key,
		graph_tree_items.sort_children_type,
		graph_tree_items.device_grouping_type,
		graph_tree_items.item_type,
		graph_tree_items.item_value,
		graph.title_cache as graph_title,
		host.description as host_description,
		host.hostname as host_hostname
		from graph_tree_items
		left join graph on (graph_tree_items.item_value = graph.id and graph_tree_items.item_type = " . TREE_ITEM_TYPE_GRAPH . ")
		left join host on (graph_tree_items.item_value = host.id and graph_tree_items.item_type = " . TREE_ITEM_TYPE_HOST . ")
		where graph_tree_items.graph_tree_id = " . sql_sanitize($graph_tree_id) . "
		$sql_where
		order by graph_tree_items.order_key
		$sql_limit");
}
Esempio n. 6
0
/**
 * List log records
 *
 * Given filter array, return list of log records
 *
 * @param array $filter_array filter array, field => value elements
 * @return array log records
 */
function log_list ($filter_array,$limit = -1,$offset = -1) {

	$sql_where = "";
	/* validation and setup for the WHERE clause */
	if ((is_array($filter_array)) && (sizeof($filter_array) > 0)) {
		/* validate each field against the known master field list */
		$field_errors = log_validate(sql_filter_array_to_field_array($filter_array), "|field|");

		/* if a field input error has occured, register the error in the session and return */
		if (sizeof($field_errors) > 0) {
			field_register_error($field_errors);
			return false;

		/* otherwise, form an SQL WHERE string using the filter fields */
		}else{
			$sql_where = "";
			$sql_start = true;
			/* check for start_date and end_date fields */
			if (isset($filter_array["start_date"])) {
				$sql_where .= "logdate >= '" . $filter_array["start_date"] . "'";
				unset($filter_array["start_date"]);
				$sql_start = false;
			}
			if (isset($filter_array["end_date"])) {
				if ($sql_where != "") {
					$sql_where .= " AND ";
				}
				$sql_where .= "logdate <= '" . $filter_array["end_date"] . "'";
				unset($filter_array["end_date"]);
				$sql_start = false;
			}
			if ($sql_start == false) {
				$sql_where = " WHERE " . $sql_where;
			}

			$sql_where .= sql_filter_array_to_where_string($filter_array, log_list_form(), $sql_start);

		}

	}

	$sql_limit = "";

        return db_fetch_assoc("SELECT
                log.id,
                log.logdate,
                log.facility,
                log.severity,
                poller.name as poller_name,
                poller.id as poller_id,
                device.description as device,
                log.username,
		log.plugin,
		log.source,
                log.message
                FROM (log LEFT JOIN device ON log.device_id = device.id)
                LEFT JOIN poller ON log.poller_id = poller.id
                $sql_where
                order by log.logdate desc",$limit,$offset);

}