Esempio n. 1
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;
}
Esempio n. 2
0
function process_poller_output_rt($rrdtool_pipe, $poller_id, $interval) {
	global $config;

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

	/* let's count the number of rrd files we processed */
	$rrds_processed = 0;

	/* create/update the rrd files */
	$results = db_fetch_assoc("SELECT
		poller_output_rt.output,
		poller_output_rt.time,
		poller_output_rt.local_data_id,
		poller_item.rrd_path,
		poller_item.rrd_name,
		poller_item.rrd_num
		FROM (poller_output_rt,poller_item)
		WHERE (poller_output_rt.local_data_id=poller_item.local_data_id
		AND poller_output_rt.rrd_name=poller_item.rrd_name)
		AND poller_output_rt.poller_id = $poller_id");

	if (sizeof($results) > 0) {
		/* create an array keyed off of each .rrd file */
		foreach ($results as $item) {
			$rt_graph_path    = read_config_option("realtime_cache_path") . "/realtime_" . $item["local_data_id"] . "_5.rrd";
			$data_source_path = get_data_source_path($item['local_data_id'], true);

			/* create rt rrd */
			if (!file_exists($rt_graph_path)) {
				/* get the syntax */
				$command = @rrdtool_function_create($item['local_data_id'], true);

				/* change permissions so that the poller can clear */
				@chmod($rt_graph_path, 0666);

				/* replace path */
				$command = str_replace($data_source_path, $rt_graph_path, $command);

				/* replace step */
				$command = preg_replace('/--step\s(\d+)/', '--step ' . $interval, $command);

				/* WIN32: before sending this command off to rrdtool, get rid
				of all of the '\' characters. Unix does not care; win32 does.
				Also make sure to replace all of the fancy \'s at the end of the line,
				but make sure not to get rid of the "\n"'s that are supposed to be
				in there (text format) */
				$command = str_replace("\\\n", " ", $command);

				/* create the rrdfile */
				shell_exec($command);
			}else{
				/* change permissions so that the poller can clear */
				@chmod($rt_graph_path, 0666);
			}

			/* now, let's update the path to keep the RRD's updated */
			$item["rrd_path"] = $rt_graph_path;

			/* cleanup the value */
			$value            = trim($item["output"]);
			$unix_time        = strtotime($item["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;
			/* multiple value output */
			}else{
				$values = explode(" ", $value);

				$rrd_field_names = array_rekey(db_fetch_assoc("SELECT
					data_template_rrd.data_source_name,
					data_input_fields.data_name
					FROM (data_template_rrd,data_input_fields)
					WHERE data_template_rrd.data_input_field_id=data_input_fields.id
					AND data_template_rrd.local_data_id=" . $item["local_data_id"]), "data_name", "data_source_name");

				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]})) {
							$rrd_update_array{$item["rrd_path"]}["times"][$unix_time]{$rrd_field_names{$matches[1]}} = $matches[2];
						}
					}
				}
			}

			/* 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);
		foreach ($results as $item) {
			db_execute("DELETE FROM poller_output_rt
				WHERE local_data_id='" . $item["local_data_id"] . "'
				AND rrd_name='" . $item["rrd_name"] . "'
				AND time='" . $item["time"] . "'
				AND poller_id='" . $poller_id . "'");
		}

		$rrds_processed = rrdtool_function_update($rrd_update_array, $rrdtool_pipe);
	}

	return $rrds_processed;
}
Esempio n. 3
0
function process_poller_output($rrdtool_pipe, $remainder = FALSE) {
	global $config;

	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
		poller_output.output,
		poller_output.time,
		poller_output.local_data_id,
		poller_item.rrd_path,
		poller_item.rrd_name,
		poller_item.rrd_num
		from (poller_output,poller_item)
		where (poller_output.local_data_id=poller_item.local_data_id and poller_output.rrd_name=poller_item.rrd_name)
		$limit");

	if (sizeof($results) > 0) {
		/* create an array keyed off of each .rrd file */
		foreach ($results as $item) {
			$value = trim($item["output"]);
			$unix_time = strtotime($item["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;
			/* multiple value output */
			}else{
				$values = explode(" ", $value);

				$rrd_field_names = array_rekey(db_fetch_assoc("select
					data_template_rrd.data_source_name,
					data_input_fields.data_name
					from (data_template_rrd,data_input_fields)
					where data_template_rrd.data_input_field_id=data_input_fields.id
					and data_template_rrd.local_data_id=" . $item["local_data_id"]), "data_name", "data_source_name");

				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]})) {
							if (read_config_option("log_verbosity") == POLLER_VERBOSITY_DEBUG) {
								cacti_log("Parsed MULTI output field '" . $matches[0] . "' [map " . $matches[1] . "->" . $rrd_field_names{$matches[1]} . "]" , true, "POLLER");
							}

							$rrd_update_array{$item["rrd_path"]}["times"][$unix_time]{$rrd_field_names{$matches[1]}} = $matches[2];
						}
					}
				}
			}

			/* 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);
		foreach ($results as $item) {
			$unix_time = strtotime($item["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])) {
					db_execute("delete from poller_output where local_data_id='" . $item["local_data_id"] . "' and rrd_name='" . $item["rrd_name"] . "' and time='" . $item["time"] . "'");
				}else{
					unset($rrd_update_array{$item["rrd_path"]}["times"][$unix_time]);
				}
			}
		}

		$rrds_processed = rrdtool_function_update($rrd_update_array, $rrdtool_pipe);
	}

	return $rrds_processed;
}
Esempio n. 4
0
function process_poller_output($rrdtool_pipe, $print_to_stdout = false) {
	require_once(CACTI_BASE_PATH . "/lib/sys/rrd.php");

	/* let's count the number of rrd files we processed */
	$rrds_processed = 0;

	/* create/update the rrd files */
	$results = db_fetch_assoc("select
		poller_output.output,
		poller_output.time,
		poller_output.local_data_id,
		poller_item.rrd_path,
		poller_item.rrd_name,
		poller_item.rrd_num
		from poller_output,poller_item
		where (poller_output.local_data_id=poller_item.local_data_id and poller_output.rrd_name=poller_item.rrd_name)");

	if (sizeof($results) > 0) {
		/* create an array keyed off of each .rrd file */
		foreach ($results as $item) {
			$value = rtrim(strtr(strtr($item["output"],'\r',''),'\n',''));
			$unix_time = strtotime($item["time"]);

			$rrd_update_array{$item["rrd_path"]}["data_source_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;
			/* multiple value output (only supported for scripts) */
			}else{
				$values = explode(" ", $value);

				$rrd_field_names = array_rekey(db_fetch_assoc("select data_source_name,field_input_value from data_source_item where data_source_id = " . $item["local_data_id"]), "field_input_value", "data_source_name");

				for ($i=0; $i<count($values); $i++) {
					if (preg_match("/^([a-zA-Z0-9_.-]+):([+-0-9Ee.]+)$/", $values[$i], $matches)) {
						if (isset($rrd_field_names{$matches[1]})) {
							log_save("Parsed MULTI output field '" . $matches[0] . "' [map " . $matches[1] . "->" . $rrd_field_names{$matches[1]} . "]", SEV_DEBUG, FACIL_POLLER, "", $poller_id, $host_id, $print_to_stdout);

							$rrd_update_array{$item["rrd_path"]}["times"][$unix_time]{$rrd_field_names{$matches[1]}} = $matches[2];
						}
					}
				}
			}

			/* 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);
		foreach ($results as $item) {
			$unix_time = strtotime($item["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])) {
					db_execute("delete from poller_output where local_data_id = " . $item["local_data_id"] . " and rrd_name = '" . $item["rrd_name"] . "' and time = '" . $item["time"] . "'");
				}else{
					unset($rrd_update_array{$item["rrd_path"]}["times"][$unix_time]);
				}
			}
		}

		$rrds_processed = rrdtool_function_update($rrd_update_array, $rrdtool_pipe);
	}

	return $rrds_processed;
}
Esempio n. 5
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_prepared('SELECT
					data_template_rrd.data_source_name,
					data_input_fields.data_name
					FROM (data_template_rrd, data_input_fields)
					WHERE data_template_rrd.data_input_field_id = data_input_fields.id
					and data_template_rrd.local_data_id = ?', array($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) . ')');
        }
        /* process dsstats information */
        dsstats_poller_output($rrd_update_array);
        api_plugin_hook_function('poller_output', $rrd_update_array);
        if (boost_poller_on_demand($results)) {
            $rrds_processed = rrdtool_function_update($rrd_update_array, $rrdtool_pipe);
        }
    }
    return $rrds_processed;
}
Esempio n. 6
0
function process_poller_output($rrdtool_pipe, $remainder = FALSE) {
	global $config;

	include_once(CACTI_BASE_PATH . "/lib/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
		poller_output.output,
		poller_output.time,
		poller_output.local_data_id,
		poller_item.rrd_path,
		poller_item.rrd_name,
		poller_item.rrd_num
		from (poller_output,poller_item)
		where (poller_output.local_data_id=poller_item.local_data_id and poller_output.rrd_name=poller_item.rrd_name)
		$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\x0B\0\"'");
			$unix_time = strtotime($item["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;
					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
					data_template_rrd.data_source_name,
					data_input_fields.data_name
					from (data_template_rrd,data_input_fields)
					where data_template_rrd.data_input_field_id=data_input_fields.id
					and 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) {
								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);
		$sql_wheres = array();
		foreach ($results as $item) {
			$unix_time = strtotime($item["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])) {
					$sql_wheres[] = " ( local_data_id='{$item['local_data_id']}' AND rrd_name='{$item['rrd_name']}' AND time='{$item['time']}' ) ";
					if (count($sql_wheres) > 100) {
						db_execute("DELETE FROM poller_output WHERE " . implode(" OR ", $sql_wheres));
						$sql_wheres = array();
					}
				}else{
					unset($rrd_update_array{$item["rrd_path"]}["times"][$unix_time]);
				}
			}
		}
		if (count($sql_wheres) > 100) {
			db_execute("DELETE FROM poller_output WHERE " . implode(" OR ", $sql_wheres));
		}
		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;
}