#!/usr/bin/env php 0) { // create an array keyed off of each .rrd file foreach ($results as $item) { $rt_graph_path = read_config_option('realtime_cache_path') . '/user_' . $poller_id . '_' . $item['local_data_id'] . '.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); // replace path $command = str_replace($data_source_path, $rt_graph_path, $command); /** * minimum refresh interval - this will always have a value of 1 * so that at the one second realtime interval, good numbers are * returned to the user. We ignore the user setting. * * $step = read_config_option('realtime_interval'); * */ // replace step $command = preg_replace('/--step\s(\d+)/', '--step 1', $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 without going through a shell $rrdtool = read_config_option('path_rrdtool') . ' '; if (strpos($command, $rrdtool) === 0) { $command = substr($command, strlen($rrdtool)); } rrdtool_execute($command, false, RRDTOOL_OUTPUT_STDOUT, $rrdtool_pipe, 'POLLER'); // change permissions so that the poller can clear @chmod($rt_graph_path, 0644); } else { // change permissions so that the poller can clear @chmod($rt_graph_path, 0644); } // now, let's update the path to keep the RRDs 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; } else { // multiple value output $values = preg_split('/\s+/', $value); $rrd_field_names = array_rekey( db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name FROM graph_templates_item AS gti INNER JOIN data_template_rrd AS dtr ON gti.task_item_id = dtr.id INNER JOIN data_input_fields AS dif ON dtr.data_input_field_id = dif.id AND dtr.local_data_id = ?', [$item['local_data_id']]), 'data_name', 'data_source_name' ); if (cacti_sizeof($values)) { foreach (($values ?: []) as $value) { $matches = explode(':', $value); if (isset($rrd_field_names[$matches[0]])) { $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'; } elseif ((!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 foreach ($results as $item) { db_execute_prepared('DELETE FROM poller_output_realtime WHERE local_data_id = ? AND rrd_name = ? AND time = ? AND poller_id = ?', [$item['local_data_id'], $item['rrd_name'], $item['time'], $poller_id]); } $rrds_processed = rrdtool_function_update($rrd_update_array, $rrdtool_pipe); } return $rrds_processed; }