Problem: if cacti polls (via our script), cacti determines what the polling time is, in cmd.php:
Code: Select all
$host_update_time = date("Y-m-d H:i:s"); // for poller update time
(...)
db_execute("insert into poller_output (local_data_id, rrd_name, time, output) values (" . $item["local_data_id"] . ", '" . $item["rrd_name"] . "', '$host_update_time', '" . addslashes($output) . "')");
Suggested solution: allow the script to overrule the poll time set by cacti.
Suggested implementation: it seems intrusive to change to a more direct input for rrdupdate (which does allow for a timestamp btw), ie I do not know what will be broken after I would patch function validate_result (in site/lib/functions.php). Giving special meaning to an output field, say, "poll_time" should have low impact and should not break any existing script, I hope. But it is feasible that someone already uses "poll_time" as a field, so only consider giving special meaning to "poll_time" if it is not used by user.
Suggested patch:
Code: Select all
root@anguish:/usr/share/cacti# diff -u site/lib/poller.php-dd20120912BD site/lib/poller.php
--- site/lib/poller.php-dd20120912BD 2012-04-23 04:00:14.000000000 +0200
+++ site/lib/poller.php 2012-09-17 14:42:40.806829762 +0200
@@ -394,6 +394,16 @@
}
$rrd_update_array{$item["rrd_path"]}["times"][$unix_time]{$rrd_field_names{$matches[0]}} = $matches[1];
+ }else{
+ /* This field name is not in use. Perhaps it is special. */
+
+ /* Consider the case where there is an intermediate data gatherer. If the intermediate gatherer does not give real time results (as is highly expected), the poll time 'now' does not make sense. Allow overrides then. */
+ if ($matches[0] === "poll_time") {
+ if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_DEBUG || $debug) {
+ cacti_log ("Found a non-user match, but cacti special match: $matches[0]=|$matches[1]| (name=" . $item["rrd_name"] . ", rrd_path=" . $item["rrd_path"] . ")");
+ }
+ $rrd_update_array{$item["rrd_path"]}["times"][$unix_time]['__actual_unix_time'] = $matches[1];
+ }
}
}
}
@@ -424,6 +434,15 @@
$k = 0;
$data_ids = array();
}
+
+ /* Overwrite poll time if output indicated so. This is a good place as $unix_time nor $item["unix_time"] is not used after this point. */
+ if (isset($rrd_update_array{$item["rrd_path"]}["times"][$unix_time]['__actual_unix_time'])) { var_dump ($rrd_update_array{$item["rrd_path"]});
+ $actual_unix_time = $rrd_update_array{$item["rrd_path"]}["times"][$unix_time]['__actual_unix_time'];
+ unset($rrd_update_array{$item["rrd_path"]}["times"][$unix_time]['__actual_unix_time']);
+
+ $rrd_update_array{$item["rrd_path"]}["times"][$actual_unix_time] = $rrd_update_array{$item["rrd_path"]}["times"][$unix_time];
+ unset ($rrd_update_array{$item["rrd_path"]}["times"][$unix_time]);
+ }
}else{
unset($rrd_update_array{$item["rrd_path"]}["times"][$unix_time]);
}