"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/rrd.php" between
cacti-1.2.21.tar.gz and cacti-1.2.22.tar.gz

About: Cacti is a complete network graphing solution designed to harness the power of RRDTool’s data storage and graphing functionality.

rrd.php  (cacti-1.2.21):rrd.php  (cacti-1.2.22)
skipping to change at line 702 skipping to change at line 702
exists and if not create it. exists and if not create it.
*/ */
if (read_config_option('extended_paths') == 'on') { if (read_config_option('extended_paths') == 'on') {
if (read_config_option('storage_location')) { if (read_config_option('storage_location')) {
if (false === rrdtool_execute('is_dir ' . dirname($data_s ource_path), true, RRDTOOL_OUTPUT_BOOLEAN, $rrdtool_pipe, 'POLLER') ) { if (false === rrdtool_execute('is_dir ' . dirname($data_s ource_path), true, RRDTOOL_OUTPUT_BOOLEAN, $rrdtool_pipe, 'POLLER') ) {
if (false === rrdtool_execute('mkdir ' . dirname( $data_source_path), true, RRDTOOL_OUTPUT_BOOLEAN, $rrdtool_pipe, 'POLLER') ) { if (false === rrdtool_execute('mkdir ' . dirname( $data_source_path), true, RRDTOOL_OUTPUT_BOOLEAN, $rrdtool_pipe, 'POLLER') ) {
cacti_log("ERROR: Unable to create direct ory '" . dirname($data_source_path) . "'", false); cacti_log("ERROR: Unable to create direct ory '" . dirname($data_source_path) . "'", false);
} }
} }
} elseif (!is_dir(dirname($data_source_path))) { } elseif (!is_dir(dirname($data_source_path))) {
if ($config['is_web'] == false) { if ($config['is_web'] == false || is_writable($config['rr a_path'])) {
if (mkdir(dirname($data_source_path), 0775)) { if (mkdir(dirname($data_source_path), 0775)) {
if ($config['cacti_server_os'] != 'win32' ) { if ($config['cacti_server_os'] != 'win32' ) {
$owner_id = fileowner($config['rr a_path']); $owner_id = fileowner($config['rr a_path']);
$group_id = filegroup($config['rr a_path']); $group_id = filegroup($config['rr a_path']);
if ((chown(dirname($data_source_p ath), $owner_id)) && if ((chown(dirname($data_source_p ath), $owner_id)) &&
(chgrp(dirname($d ata_source_path), $group_id))) { (chgrp(dirname($d ata_source_path), $group_id))) {
/* permissions set ok */ /* permissions set ok */
} else { } else {
cacti_log("ERROR: Unable to set directory permissions for '" . dirname($data_source_path) . "'", false); cacti_log("ERROR: Unable to set directory permissions for '" . dirname($data_source_path) . "'", false);
skipping to change at line 740 skipping to change at line 740
function rrdtool_function_update($update_cache_array, $rrdtool_pipe = false) { function rrdtool_function_update($update_cache_array, $rrdtool_pipe = false) {
/* lets count the number of rrd files processed */ /* lets count the number of rrd files processed */
$rrds_processed = 0; $rrds_processed = 0;
foreach ($update_cache_array as $rrd_path => $rrd_fields) { foreach ($update_cache_array as $rrd_path => $rrd_fields) {
$create_rrd_file = false; $create_rrd_file = false;
if (is_array($rrd_fields['times']) && cacti_sizeof($rrd_fields['t imes'])) { if (is_array($rrd_fields['times']) && cacti_sizeof($rrd_fields['t imes'])) {
/* create the rrd if one does not already exist */ /* create the rrd if one does not already exist */
if (read_config_option('storage_location')) { if (read_config_option('storage_location') > 0) {
$file_exists = rrdtool_execute("file_exists $rrd_ path" , true, RRDTOOL_OUTPUT_BOOLEAN, $rrdtool_pipe, 'POLLER'); $file_exists = rrdtool_execute("file_exists $rrd_ path" , true, RRDTOOL_OUTPUT_BOOLEAN, $rrdtool_pipe, 'POLLER');
} else { } else {
$file_exists = file_exists($rrd_path); $file_exists = file_exists($rrd_path);
} }
ksort($rrd_fields['times']); ksort($rrd_fields['times']);
if ($file_exists === false) { if ($file_exists === false) {
$times = array_keys($rrd_fields['times']); $times = array_keys($rrd_fields['times']);
rrdtool_function_create($rrd_fields['local_data_i d'], false, $rrdtool_pipe); rrdtool_function_create($rrd_fields['local_data_i d'], false, $rrdtool_pipe);
skipping to change at line 863 skipping to change at line 863
$fetch_array['data_source_names'][0] = 'ds1' $fetch_array['data_source_names'][0] = 'ds1'
$fetch_array['data_source_names'][1] = 'ds2' $fetch_array['data_source_names'][1] = 'ds2'
$fetch_array['data_source_names'][2] = 'nth_percentile_maximum' $fetch_array['data_source_names'][2] = 'nth_percentile_maximum'
$fetch_array['start_time'] = $timestamp; $fetch_array['start_time'] = $timestamp;
$fetch_array['end_time'] = $timestamp; $fetch_array['end_time'] = $timestamp;
$fetch_array['values'][$dsindex1][...] = $value; $fetch_array['values'][$dsindex1][...] = $value;
$fetch_array['values'][$dsindex2][...] = $value; $fetch_array['values'][$dsindex2][...] = $value;
$fetch_array['values'][$nth_index][...] = $value; $fetch_array['values'][$nth_index][...] = $value;
Again, the 'nth_percentile_maximum' will have the maximum value amoungst al l the Again, the 'nth_percentile_maximum' will have the maximum value amongst all the
data sources for each set of data. So, if you have traffic_in and traffic_ out, data sources for each set of data. So, if you have traffic_in and traffic_ out,
each member element in the array will have the maximum of traffic_in and tr affic_out each member element in the array will have the maximum of traffic_in and tr affic_out
in it. in it.
*/ */
function rrdtool_function_fetch($local_data_id, $start_time, $end_time, $resolut ion = 0, $show_unknown = false, $rrdtool_file = null, $cf = 'AVERAGE', $rrdtool_ pipe = false) { function rrdtool_function_fetch($local_data_id, $start_time, $end_time, $resolut ion = 0, $show_unknown = false, $rrdtool_file = null, $cf = 'AVERAGE', $rrdtool_ pipe = false) {
global $config; global $config;
include_once($config['library_path'] . '/boost.php'); include_once($config['library_path'] . '/boost.php');
/* validate local data id */ /* validate local data id */
if (empty($local_data_id) && is_null($rrdtool_file)) { if (empty($local_data_id) && is_null($rrdtool_file)) {
return array(); return array();
} }
$time = time(); $time = time();
/* initialize fetch array */ /* initialize fetch array */
$fetch_array = array(); $fetch_array = array();
/* check if we have been passed a file instead of lodal data source to lo ok up */ /* check if we have been passed a file instead of local data source to lo ok up */
if (is_null($rrdtool_file)) { if (is_null($rrdtool_file)) {
$data_source_path = get_data_source_path($local_data_id, true); $data_source_path = get_data_source_path($local_data_id, true);
} else { } else {
$data_source_path = $rrdtool_file; $data_source_path = $rrdtool_file;
} }
// Find the correct resolution // Find the correct resolution
if ($resolution == 0) { if ($resolution == 0) {
$resolution = rrdtool_function_get_resstep($local_data_id, $start _time, $end_time, 'res'); $resolution = rrdtool_function_get_resstep($local_data_id, $start _time, $end_time, 'res');
} }
skipping to change at line 1217 skipping to change at line 1217
$graph_opts .= rrdtool_function_theme_font_options($graph_data_array); $graph_opts .= rrdtool_function_theme_font_options($graph_data_array);
/* Replace "|query_*|" in the graph command to replace e.g. vertical_labe l. */ /* Replace "|query_*|" in the graph command to replace e.g. vertical_labe l. */
$graph_opts = rrd_substitute_host_query_data($graph_opts, $graph, array() ); $graph_opts = rrd_substitute_host_query_data($graph_opts, $graph, array() );
/* provide smooth lines */ /* provide smooth lines */
if ($graph['slope_mode'] == 'on') { if ($graph['slope_mode'] == 'on') {
$graph_opts .= '--slope-mode' . RRD_NL; $graph_opts .= '--slope-mode' . RRD_NL;
} }
/* if the user desires a wartermark set it */ /* if the user desires a watermark set it */
if (read_config_option('graph_watermark') != '') { if (read_config_option('graph_watermark') != '') {
$graph_opts .= '--watermark ' . cacti_escapeshellarg(read_config_ option('graph_watermark')) . RRD_NL; $graph_opts .= '--watermark ' . cacti_escapeshellarg(read_config_ option('graph_watermark')) . RRD_NL;
} }
return $graph_opts; return $graph_opts;
} }
function rrdtool_function_graph($local_graph_id, $rra_id, $graph_data_array, $rr dtool_pipe = false, &$xport_meta = array(), $user = 0) { function rrdtool_function_graph($local_graph_id, $rra_id, $graph_data_array, $rr dtool_pipe = false, &$xport_meta = array(), $user = 0) {
global $config, $consolidation_functions, $graph_item_types, $encryption; global $config, $consolidation_functions, $graph_item_types, $encryption;
skipping to change at line 1657 skipping to change at line 1657
/* note the current item_id for easy access */ /* note the current item_id for easy access */
$graph_item_id = $graph_item['graph_templates_item_id']; $graph_item_id = $graph_item['graph_templates_item_id'];
/* if we are not displaying a legend there is no point in us even processing the /* if we are not displaying a legend there is no point in us even processing the
* auto padding, text format stuff. * auto padding, text format stuff.
*/ */
if (!isset($graph_data_array['graph_nolegend'])) { if (!isset($graph_data_array['graph_nolegend'])) {
/* PADDING: remember this is not perfect! its mai n use is for the basic graph setup of: /* PADDING: remember this is not perfect! its mai n use is for the basic graph setup of:
* AREA - GPRINT-CURRENT - GPRINT-AVERAGE - GPRIN T-MAXIMUM \n * AREA - GPRINT-CURRENT - GPRINT-AVERAGE - GPRIN T-MAXIMUM \n
* of course it can be used in other situations, however may not work as intended. * of course it can be used in other situations, however may not work as intended.
* If you have any additions to this small peice of code, feel free to send them to me. * If you have any additions to this small piece of code, feel free to send them to me.
*/ */
if ($graph['auto_padding'] == 'on') { if ($graph['auto_padding'] == 'on') {
/* only applies to AREA, STACK and LINEs */ /* only applies to AREA, STACK and LINEs */
if (preg_match('/(AREA|STACK|LINE[123])/' , $graph_item_types[$graph_item['graph_type_id']])) { if (preg_match('/(AREA|STACK|LINE[123])/' , $graph_item_types[$graph_item['graph_type_id']])) {
$text_format_length = mb_strlen(t rim($graph_variables['text_format'][$graph_item_id]), 'UTF-8'); $text_format_length = mb_strlen(t rim($graph_variables['text_format'][$graph_item_id]), 'UTF-8');
if ($text_format_length > $pad_nu mber) { if ($text_format_length > $pad_nu mber) {
$pad_number = $text_forma t_length; $pad_number = $text_forma t_length;
} }
} }
skipping to change at line 1866 skipping to change at line 1866
if ($count_similar_ds_dups > 1 && isset($ magic_item['COUNT_SIMILAR_DS_DUPS'])) { if ($count_similar_ds_dups > 1 && isset($ magic_item['COUNT_SIMILAR_DS_DUPS'])) {
$magic_item['COUNT_SIMILAR_DS_DUP S'] .= str_repeat(',+', ($count_similar_ds_dups - 2)) . ',+'; $magic_item['COUNT_SIMILAR_DS_DUP S'] .= str_repeat(',+', ($count_similar_ds_dups - 2)) . ',+';
} }
if ($count_similar_ds_nodups > 1 && isset ($magic_item['COUNT_SIMILAR_DS_NODUPS'])) { if ($count_similar_ds_nodups > 1 && isset ($magic_item['COUNT_SIMILAR_DS_NODUPS'])) {
$magic_item['COUNT_SIMILAR_DS_NOD UPS'] .= str_repeat(',+', ($count_similar_ds_nodups - 2)) . ',+'; $magic_item['COUNT_SIMILAR_DS_NOD UPS'] .= str_repeat(',+', ($count_similar_ds_nodups - 2)) . ',+';
} }
} }
/* allow automatic rate calculations on raw guage data */ /* allow automatic rate calculations on raw gauge data */
if (isset($graph_item['local_data_id'])) { if (isset($graph_item['local_data_id'])) {
$cdef_string = str_replace('CURRENT_DATA_ SOURCE_PI', db_fetch_cell_prepared('SELECT rrd_step FROM data_template_data WHER E local_data_id = ?', array($graph_item['local_data_id'])), $cdef_string); $cdef_string = str_replace('CURRENT_DATA_ SOURCE_PI', db_fetch_cell_prepared('SELECT rrd_step FROM data_template_data WHER E local_data_id = ?', array($graph_item['local_data_id'])), $cdef_string);
} else { } else {
$cdef_string = str_replace('CURRENT_DATA_ SOURCE_PI', read_config_option('poller_interval'), $cdef_string); $cdef_string = str_replace('CURRENT_DATA_ SOURCE_PI', read_config_option('poller_interval'), $cdef_string);
} }
$cdef_string = str_replace('CURRENT_DATA_SOURCE', generate_graph_def_name(strval((isset($cf_ds_cache[$graph_item['data_template_r rd_id']][$cf_id]) ? $cf_ds_cache[$graph_item['data_template_rrd_id']][$cf_id] : '0'))), $cdef_string); $cdef_string = str_replace('CURRENT_DATA_SOURCE', generate_graph_def_name(strval((isset($cf_ds_cache[$graph_item['data_template_r rd_id']][$cf_id]) ? $cf_ds_cache[$graph_item['data_template_rrd_id']][$cf_id] : '0'))), $cdef_string);
/* allow automatic rate calculations on raw guage data */ /* allow automatic rate calculations on raw gauge data */
if (isset($graph_item['local_data_id'])) { if (isset($graph_item['local_data_id'])) {
$cdef_string = str_replace('ALL_DATA_SOUR CES_DUPS_PI', db_fetch_cell_prepared('SELECT rrd_step FROM data_template_data WH ERE local_data_id = ?', array($graph_item['local_data_id'])), $cdef_string); $cdef_string = str_replace('ALL_DATA_SOUR CES_DUPS_PI', db_fetch_cell_prepared('SELECT rrd_step FROM data_template_data WH ERE local_data_id = ?', array($graph_item['local_data_id'])), $cdef_string);
} else { } else {
$cdef_string = str_replace('ALL_DATA_SOUR CES_DUPS_PI', read_config_option('poller_interval'), $cdef_string); $cdef_string = str_replace('ALL_DATA_SOUR CES_DUPS_PI', read_config_option('poller_interval'), $cdef_string);
} }
/* ALL|SIMILAR_DATA_SOURCES(NO)?DUPS are to be re placed here */ /* ALL|SIMILAR_DATA_SOURCES(NO)?DUPS are to be re placed here */
if (isset($magic_item['ALL_DATA_SOURCES_DUPS'])) { if (isset($magic_item['ALL_DATA_SOURCES_DUPS'])) {
$cdef_string = str_replace('ALL_DATA_SOUR CES_DUPS', $magic_item['ALL_DATA_SOURCES_DUPS'], $cdef_string); $cdef_string = str_replace('ALL_DATA_SOUR CES_DUPS', $magic_item['ALL_DATA_SOURCES_DUPS'], $cdef_string);
} }
/* allow automatic rate calculations on raw guage data */ /* allow automatic rate calculations on raw gauge data */
if (isset($graph_item['local_data_id'])) { if (isset($graph_item['local_data_id'])) {
$cdef_string = str_replace('ALL_DATA_SOUR CES_NODUPS_PI', db_fetch_cell_prepared('SELECT rrd_step FROM data_template_data WHERE local_data_id = ?', array($graph_item['local_data_id'])), $cdef_string); $cdef_string = str_replace('ALL_DATA_SOUR CES_NODUPS_PI', db_fetch_cell_prepared('SELECT rrd_step FROM data_template_data WHERE local_data_id = ?', array($graph_item['local_data_id'])), $cdef_string);
} else { } else {
$cdef_string = str_replace('ALL_DATA_SOUR CES_NODUPS_PI', read_config_option('poller_interval'), $cdef_string); $cdef_string = str_replace('ALL_DATA_SOUR CES_NODUPS_PI', read_config_option('poller_interval'), $cdef_string);
} }
if (isset($magic_item['ALL_DATA_SOURCES_NODUPS']) ) { if (isset($magic_item['ALL_DATA_SOURCES_NODUPS']) ) {
$cdef_string = str_replace('ALL_DATA_SOUR CES_NODUPS', $magic_item['ALL_DATA_SOURCES_NODUPS'], $cdef_string); $cdef_string = str_replace('ALL_DATA_SOUR CES_NODUPS', $magic_item['ALL_DATA_SOURCES_NODUPS'], $cdef_string);
} }
/* allow automatic rate calculations on raw guage data */ /* allow automatic rate calculations on raw gauge data */
if (isset($graph_item['local_data_id'])) { if (isset($graph_item['local_data_id'])) {
$cdef_string = str_replace('SIMILAR_DATA_ SOURCES_DUPS_PI', db_fetch_cell_prepared('SELECT rrd_step FROM data_template_dat a WHERE local_data_id = ?', array($graph_item['local_data_id'])), $cdef_string); $cdef_string = str_replace('SIMILAR_DATA_ SOURCES_DUPS_PI', db_fetch_cell_prepared('SELECT rrd_step FROM data_template_dat a WHERE local_data_id = ?', array($graph_item['local_data_id'])), $cdef_string);
} else { } else {
$cdef_string = str_replace('SIMILAR_DATA_ SOURCES_DUPS_PI', read_config_option('poller_interval'), $cdef_string); $cdef_string = str_replace('SIMILAR_DATA_ SOURCES_DUPS_PI', read_config_option('poller_interval'), $cdef_string);
} }
if (isset($magic_item['SIMILAR_DATA_SOURCES_DUPS' ])) { if (isset($magic_item['SIMILAR_DATA_SOURCES_DUPS' ])) {
$cdef_string = str_replace('SIMILAR_DATA_ SOURCES_DUPS', $magic_item['SIMILAR_DATA_SOURCES_DUPS'], $cdef_string); $cdef_string = str_replace('SIMILAR_DATA_ SOURCES_DUPS', $magic_item['SIMILAR_DATA_SOURCES_DUPS'], $cdef_string);
} }
skipping to change at line 2176 skipping to change at line 2176
$txt_graph_items .= 'GPRI NT:' . $data_source_name . ':MIN:' . cacti_escapeshellarg($text_format . $graph_ item['gprint_text'] . $hardreturn[$graph_item_id]) . ' '; $txt_graph_items .= 'GPRI NT:' . $data_source_name . ':MIN:' . cacti_escapeshellarg($text_format . $graph_ item['gprint_text'] . $hardreturn[$graph_item_id]) . ' ';
} else { } else {
$txt_graph_items .= 'GPRI NT:' . $data_source_name . ':' . cacti_escapeshellarg($text_format . $graph_item ['gprint_text'] . $hardreturn[$graph_item_id]) . ' '; $txt_graph_items .= 'GPRI NT:' . $data_source_name . ':' . cacti_escapeshellarg($text_format . $graph_item ['gprint_text'] . $hardreturn[$graph_item_id]) . ' ';
} }
} }
break; break;
case GRAPH_ITEM_TYPE_AREA: case GRAPH_ITEM_TYPE_AREA:
$text_format = rrdtool_escape_string(html _escape($graph_variables['text_format'][$graph_item_id] != '' ? str_pad($graph_v ariables['text_format'][$graph_item_id], $pad_number):'')); $text_format = rrdtool_escape_string(html _escape($graph_variables['text_format'][$graph_item_id] != '' ? str_pad($graph_v ariables['text_format'][$graph_item_id], $pad_number):''));
$txt_graph_items .= $graph_item_types[$gr if (read_config_option('enable_rrdtool_gr
aph_item['graph_type_id']] . ':' . $data_source_name . $graph_item_color_code . adient_support') == 'on') {
':' . cacti_escapeshellarg($text_format . $hardreturn[$graph_item_id]) . ' '; /* End color is a 40% (0.4) darke
ned (negative number) version of the original color */
$end_color = colourBrightn
ess( "#" . $graph_item[ "hex" ], -0.4 );
$txt_graph_items .= gradient($dat
a_source_name, $graph_item_color_code, $end_color . $graph_item['alpha'], cacti_
escapeshellarg($graph_variables['text_format'][$graph_item_id] . $hardreturn[$gr
aph_item_id]), 20, false, $graph_item[ "alpha" ]);
} else {
$txt_graph_items .= $graph_item_t
ypes[$graph_item['graph_type_id']] . ':' . $data_source_name . $graph_item_color
_code . ':' . cacti_escapeshellarg($text_format . $hardreturn[$graph_item_id]) .
' ';
}
if ($graph_item['shift'] == CHECKED && ab if ($graph_item['shift'] == CHECKED && ab
s($graph_item['value']) > 0) { # create a SHIFT statement s($graph_item['value']) > 0) {
/* create a SHIFT statement */
$txt_graph_items .= RRD_NL . 'SHI FT:' . $data_source_name . ':' . $graph_item['value']; $txt_graph_items .= RRD_NL . 'SHI FT:' . $data_source_name . ':' . $graph_item['value'];
} }
break; break;
case GRAPH_ITEM_TYPE_STACK: case GRAPH_ITEM_TYPE_STACK:
$text_format = rrdtool_escape_string(html _escape($graph_variables['text_format'][$graph_item_id] != '' ? str_pad($graph_v ariables['text_format'][$graph_item_id],$pad_number):'')); $text_format = rrdtool_escape_string(html _escape($graph_variables['text_format'][$graph_item_id] != '' ? str_pad($graph_v ariables['text_format'][$graph_item_id],$pad_number):''));
$txt_graph_items .= 'AREA:' . $data_sourc e_name . $graph_item_color_code . ':' . cacti_escapeshellarg($text_format . $har dreturn[$graph_item_id]) . ':STACK'; $txt_graph_items .= 'AREA:' . $data_sourc e_name . $graph_item_color_code . ':' . cacti_escapeshellarg($text_format . $har dreturn[$graph_item_id]) . ':STACK';
if ($graph_item['shift'] == CHECKED && $g raph_item['value'] > 0) { # create a SHIFT statement if ($graph_item['shift'] == CHECKED && $g raph_item['value'] > 0) { # create a SHIFT statement
skipping to change at line 2297 skipping to change at line 2304
$graph_defs = $graph_array['graph_defs']; $graph_defs = $graph_array['graph_defs'];
$txt_graph_items = $graph_array['txt_graph_items']; $txt_graph_items = $graph_array['txt_graph_items'];
$graph_opts = $graph_array['graph_opts']; $graph_opts = $graph_array['graph_opts'];
} }
/* either print out the source or pass the source onto rrdtool to get us a nice PNG */ /* either print out the source or pass the source onto rrdtool to get us a nice PNG */
if (isset($graph_data_array['print_source'])) { if (isset($graph_data_array['print_source'])) {
$source_command_line = read_config_option('path_rrdtool') . ' graph ' . $graph_opts . $graph_defs . $txt_graph_items; $source_command_line = read_config_option('path_rrdtool') . ' graph ' . $graph_opts . $graph_defs . $txt_graph_items;
$source_command_line_lengths = strlen(str_replace("\\\n", ' ', $source_command_line)); $source_command_line_lengths = strlen(str_replace("\\\n", ' ', $source_command_line));
print '<PRE>' . html_escape($source_command_line) . '</PR E>'; print '<PRE>' . html_escape($source_command_line) . '</PR E>';
print '<span class="textInfo">' . 'RRDtool Command length s = ' . $source_command_line_lengths . ' charaters.</span><br>'; print '<span class="textInfo">' . 'RRDtool Command length s = ' . $source_command_line_lengths . ' characters.</span><br>';
if ( $config['cacti_server_os'] == 'win32' && $source_com mand_line_lengths > 8191 ) { if ( $config['cacti_server_os'] == 'win32' && $source_com mand_line_lengths > 8191 ) {
print '<PRE>' . 'Warning: The Cacti OS is Windows system, RRDtool Command lengths should not exceed 8191 charaters.' . '</PRE>'; print '<PRE>' . 'Warning: The Cacti OS is Windows system, RRDtool Command lengths should not exceed 8191 characters.' . '</PRE>';
} }
} else { } else {
if (isset($graph_data_array['graphv'])) { if (isset($graph_data_array['graphv'])) {
$graph = 'graphv'; $graph = 'graphv';
} else { } else {
$graph = 'graph'; $graph = 'graph';
} }
if (isset($graph_data_array['get_error'])) { if (isset($graph_data_array['get_error'])) {
return rrdtool_execute("graph $graph_opts$graph_d efs$txt_graph_items", false, RRDTOOL_OUTPUT_STDERR); return rrdtool_execute("graph $graph_opts$graph_d efs$txt_graph_items", false, RRDTOOL_OUTPUT_STDERR);
skipping to change at line 2599 skipping to change at line 2606
} }
} }
} }
} }
} }
} }
return 0; return 0;
} }
/** given a data source id, return rrdtool info array /**
* @param $local_data_id - data source id * rrdtool_function_info - given a data source id, return rrdtool info array
* @return - (array) an array containing all data from rrdtool info command *
* @param (int) $local_data_id - data source id
*
* @return (array) an array containing all data from rrdtool info command
*/ */
function rrdtool_function_info($local_data_id) { function rrdtool_function_info($local_data_id) {
/* Get the path to rrdtool file */ /* Get the path to rrdtool file */
$data_source_path = get_data_source_path($local_data_id, true); $data_source_path = get_data_source_path($local_data_id, true);
/* Execute rrdtool info command */ /* Execute rrdtool info command */
$cmd_line = ' info ' . $data_source_path; $cmd_line = ' info ' . $data_source_path;
$output = rrdtool_execute($cmd_line, RRDTOOL_OUTPUT_NULL, RRDTOOL_OUTPUT_ STDOUT); $output = rrdtool_execute($cmd_line, RRDTOOL_OUTPUT_NULL, RRDTOOL_OUTPUT_ STDOUT);
if ($output == '') { if ($output == '') {
return false; return false;
skipping to change at line 2646 skipping to change at line 2656
} }
} }
$output = ''; $output = '';
$matches = array(); $matches = array();
/* Return parsed values */ /* Return parsed values */
return $rrd_info; return $rrd_info;
} }
/** rrdtool_function_contains_cf verifies if the RRDfile contains the 'MAX' con /**
solidation function * rrdtool_function_contains_cf verifies if the RRDfile contains the 'MAX' cons
* @param $local_data_id the id of the data source olidation function
* @param $cf the consolidation function to search for *
* @return boolean true or false depending o * @param (int) $local_data_id - the id of the data source
n the result * @param (int) $cf - the consolidation function to search for
*
* @return (bool) true or false depending on the result
*/ */
function rrdtool_function_contains_cf($local_data_id, $cf) { function rrdtool_function_contains_cf($local_data_id, $cf) {
$info = rrdtool_function_info($local_data_id); $info = rrdtool_function_info($local_data_id);
if (cacti_sizeof($info)) { if (cacti_sizeof($info)) {
if (isset($info['rra'])) { if (isset($info['rra'])) {
foreach($info['rra'] as $ds) { foreach($info['rra'] as $ds) {
if ($ds['cf'] == $cf) { if ($ds['cf'] == $cf) {
return true; return true;
} }
skipping to change at line 2896 skipping to change at line 2909
if (!isset($info['rra'][$file_rra_id]['seen'])) { if (!isset($info['rra'][$file_rra_id]['seen'])) {
$diff['rra'][$file_rra_id]['error'] = __("RRA '%s ' missing in Cacti definition", $file_rra_id); $diff['rra'][$file_rra_id]['error'] = __("RRA '%s ' missing in Cacti definition", $file_rra_id);
} }
} }
} }
return $diff; return $diff;
} }
/** take output from rrdtool info array and build html table /**
* @param array $info_array - array of rrdtool info data * rrdtool_info2html - take output from rrdtool info array and build html table
* @param array $diff - array of differences between definition and current rrd *
file settings * @param (array) $info_array - array of rrdtool info data
* @return string - html code * @param (array) $diff - array of differences between definition and current r
rd file settings
*
* @return (string) - html code
*/ */
function rrdtool_info2html($info_array, $diff=array()) { function rrdtool_info2html($info_array, $diff=array()) {
global $config; global $config;
include_once($config['library_path'] . '/time.php'); include_once($config['library_path'] . '/time.php');
html_start_box(__('RRD File Information'), '100%', '', '3', 'center', '') ; html_start_box(__('RRD File Information'), '100%', '', '3', 'center', '') ;
# header data # header data
$header_items = array( $header_items = array(
skipping to change at line 3030 skipping to change at line 3046
form_selectable_cell((isset($value['cdp_prep'][0]['value' ]) ? (strtolower($value['cdp_prep'][0]['value']) == 'nan') ? $value['cdp_prep'][ 0]['value'] : floatval($value['cdp_prep'][0]['value']) : ''), 'value', '', 'text -align:right'); form_selectable_cell((isset($value['cdp_prep'][0]['value' ]) ? (strtolower($value['cdp_prep'][0]['value']) == 'nan') ? $value['cdp_prep'][ 0]['value'] : floatval($value['cdp_prep'][0]['value']) : ''), 'value', '', 'text -align:right');
form_selectable_cell((isset($value['cdp_prep'][0]['unknow n_datapoints'])? $value['cdp_prep'][0]['unknown_datapoints'] : ''), 'unknown_ datapoints', '', 'text-align:right'); form_selectable_cell((isset($value['cdp_prep'][0]['unknow n_datapoints'])? $value['cdp_prep'][0]['unknown_datapoints'] : ''), 'unknown_ datapoints', '', 'text-align:right');
form_end_row(); form_end_row();
} }
} }
html_end_box(); html_end_box();
} }
/** rrdtool_tune - create rrdtool tune/resize commands /**
* html+cli enabled * rrdtool_tune - create rrdtool tune/resize commands html+cli enabled
* @param $rrd_file - rrd file name *
* @param $diff - array of discrepancies between cacti se * @param (string) $rrd_file - rrd file name
tttings and rrd file info * @param (array) $diff - array of discrepancies between cacti settings and rrd
* @param $show_source - only show text+commands or execute all commands, execut file info
e is for cli mode only! * @param (bool) $show_source - only show text+commands or execute all command
s, execute is for cli mode only!
*/ */
function rrdtool_tune($rrd_file, $diff, $show_source = true) { function rrdtool_tune($rrd_file, $diff, $show_source = true) {
function print_leaves($array, $nl) { function print_leaves($array, $nl) {
foreach ($array as $key => $line) { foreach ($array as $key => $line) {
if (!is_array($line)) { if (!is_array($line)) {
print $line . $nl; print $line . $nl;
} else { } else {
if ($key === 'tune') continue; if ($key === 'tune') continue;
if ($key === 'resize') continue; if ($key === 'resize') continue;
print_leaves($line, $nl); print_leaves($line, $nl);
skipping to change at line 3088 skipping to change at line 3105
print read_config_option('path_rrdtool') . ' resi ze ' . $line . $nl; print read_config_option('path_rrdtool') . ' resi ze ' . $line . $nl;
print __('rename %s to %s', dirname($rrd_file) . '/resize.rrd', $rrd_file) . $nl; print __('rename %s to %s', dirname($rrd_file) . '/resize.rrd', $rrd_file) . $nl;
} else { } else {
rrdtool_execute("resize $line", true, RRDTOOL_OUT PUT_STDOUT); rrdtool_execute("resize $line", true, RRDTOOL_OUT PUT_STDOUT);
rename(dirname($rrd_file) . '/resize.rrd', $rrd_f ile); rename(dirname($rrd_file) . '/resize.rrd', $rrd_f ile);
} }
} }
} }
} }
/** Given a data source id, check the rrdtool file to the data source definition /**
* @param $data_source_id - data source id * rrd_check - Given a data source id, check the rrdtool file to the data source
* @return - (array) an array containing issues with the rrdtool file definition definition
vs data source *
* @param (int) $data_source_id - data source id
*
* @return (array) an array containing issues with the rrdtool file definition v
s data source
*/ */
function rrd_check($data_source_id) { function rrd_check($data_source_id) {
global $rrd_tune_array, $data_source_types; global $rrd_tune_array, $data_source_types;
$data_source_name = get_data_source_item_name($rrd_tune_array['data_sourc e_id']); $data_source_name = get_data_source_item_name($rrd_tune_array['data_sourc e_id']);
$data_source_type = $data_source_types[$rrd_tune_array['data-source-type' ]]; $data_source_type = $data_source_types[$rrd_tune_array['data-source-type' ]];
$data_source_path = get_data_source_path($rrd_tune_array['data_source_id' ], true); $data_source_path = get_data_source_path($rrd_tune_array['data_source_id' ], true);
} }
/** Given a data source id, update the rrdtool file to match the data source def /**
inition * rrd_repair - Given a data source id, update the rrdtool file to match the dat
* @param $data_source_id - data source id a source definition
* @return - 1 success, 2 false *
* @param (int) $data_source_id - data source id
*
* @return (int) 1 success, 2 false
*/ */
function rrd_repair($data_source_id) { function rrd_repair($data_source_id) {
global $rrd_tune_array, $data_source_types; global $rrd_tune_array, $data_source_types;
$data_source_name = get_data_source_item_name($rrd_tune_array['data_sourc e_id']); $data_source_name = get_data_source_item_name($rrd_tune_array['data_sourc e_id']);
$data_source_type = $data_source_types[$rrd_tune_array['data-source-type' ]]; $data_source_type = $data_source_types[$rrd_tune_array['data-source-type' ]];
$data_source_path = get_data_source_path($rrd_tune_array['data_source_id' ], true); $data_source_path = get_data_source_path($rrd_tune_array['data_source_id' ], true);
} }
/** add a (list of) datasource(s) to an (array of) rrd file(s) /**
* @param array $file_array - array of rrd files * rrd_datasource_add - add a (list of) datasource(s) to an (array of) rrd file(
* @param array $ds_array - array of datasouce parameters s)
* @param bool $debug - debug mode *
* @return mixed - success (bool) or error message (array) * @param (array) $file_array - array of rrd files
* @param (array) $ds_array - array of datasource parameters
* @param (bool) $debug - debug mode
*
* @return (mixed) - success (bool) or error message (array)
*/ */
function rrd_datasource_add($file_array, $ds_array, $debug) { function rrd_datasource_add($file_array, $ds_array, $debug) {
global $data_source_types, $consolidation_functions; global $data_source_types, $consolidation_functions;
$rrdtool_pipe = rrd_init(); $rrdtool_pipe = rrd_init();
/* iterate all given rrd files */ /* iterate all given rrd files */
foreach ($file_array as $file) { foreach ($file_array as $file) {
/* create a DOM object from an rrdtool dump */ /* create a DOM object from an rrdtool dump */
$dom = new domDocument; $dom = new domDocument;
skipping to change at line 3141 skipping to change at line 3167
} }
/* rrdtool dump depends on rrd file version: /* rrdtool dump depends on rrd file version:
* version 0001 => RRDtool 1.0.x * version 0001 => RRDtool 1.0.x
* version 0003 => RRDtool 1.2.x, 1.3.x, 1.4.x, 1.5.x, 1.6.x * version 0003 => RRDtool 1.2.x, 1.3.x, 1.4.x, 1.5.x, 1.6.x
*/ */
$version = trim($dom->getElementsByTagName('version')->item(0)->n odeValue); $version = trim($dom->getElementsByTagName('version')->item(0)->n odeValue);
/* now start XML processing */ /* now start XML processing */
foreach ($ds_array as $ds) { foreach ($ds_array as $ds) {
/* first, append the <DS> strcuture in the rrd header */ /* first, append the <DS> structure in the rrd header */
if ($ds['type'] === $data_source_types[DATA_SOURCE_TYPE_C OMPUTE]) { if ($ds['type'] === $data_source_types[DATA_SOURCE_TYPE_C OMPUTE]) {
rrd_append_compute_ds($dom, $version, $ds['name'] , $ds['type'], $ds['cdef']); rrd_append_compute_ds($dom, $version, $ds['name'] , $ds['type'], $ds['cdef']);
} else { } else {
rrd_append_ds($dom, $version, $ds['name'], $ds['t ype'], $ds['heartbeat'], $ds['min'], $ds['max']); rrd_append_ds($dom, $version, $ds['name'], $ds['t ype'], $ds['heartbeat'], $ds['min'], $ds['max']);
} }
/* now work on the <DS> structure as part of the <cdp_pre p> tree */ /* now work on the <DS> structure as part of the <cdp_pre p> tree */
rrd_append_cdp_prep_ds($dom, $version); rrd_append_cdp_prep_ds($dom, $version);
/* add <V>alues to the <database> tree */ /* add <V>alues to the <database> tree */
rrd_append_value($dom); rrd_append_value($dom);
} }
skipping to change at line 3184 skipping to change at line 3210
} }
} }
} }
} }
rrd_close($rrdtool_pipe); rrd_close($rrdtool_pipe);
return true; return true;
} }
/** delete a (list of) rra(s) from an (array of) rrd file(s) /**
* @param array $file_array - array of rrd files * rrd_rra_delete - delete a (list of) rra(s) from an (array of) rrd file(s)
* @param array $rra_array - array of rra parameters *
* @param bool $debug - debug mode * @param (array) $file_array - array of rrd files
* @return mixed - success (bool) or error message (array) * @param (array) $rra_array - array of rra parameters
* @param (bool) $debug - debug mode
*
* @return (mixed) true for success (bool) or error message (array)
*/ */
function rrd_rra_delete($file_array, $rra_array, $debug) { function rrd_rra_delete($file_array, $rra_array, $debug) {
$rrdtool_pipe = rrd_init(); $rrdtool_pipe = rrd_init();
/* iterate all given rrd files */ /* iterate all given rrd files */
foreach ($file_array as $file) { foreach ($file_array as $file) {
/* create a DOM document from an rrdtool dump */ /* create a DOM document from an rrdtool dump */
$dom = new domDocument; $dom = new domDocument;
$dom->loadXML(rrdtool_execute("dump $file", false, RRDTOOL_OUTPUT _STDOUT, $rrdtool_pipe, 'UTIL')); $dom->loadXML(rrdtool_execute("dump $file", false, RRDTOOL_OUTPUT _STDOUT, $rrdtool_pipe, 'UTIL'));
if (!$dom) { if (!$dom) {
skipping to change at line 3239 skipping to change at line 3268
} }
} }
} }
} }
rrd_close($rrdtool_pipe); rrd_close($rrdtool_pipe);
return true; return true;
} }
/** clone a (list of) rra(s) from an (array of) rrd file(s) /**
* @param array $file_array - array of rrd files * rrd_rra_clone - clone a (list of) rra(s) from an (array of) rrd file(s)
* @param string $cf - new consolidation function *
* @param array $rra_array - array of rra parameters * @param (array) $file_array - array of rrd files
* @param bool $debug - debug mode * @param (string) $cf - new consolidation function
* @return mixed - success (bool) or error message (array) * @param (array) $rra_array - array of rra parameters
* @param (bool) $debug - debug mode
*
* @return (mixed) success (bool) or error message (array)
*/ */
function rrd_rra_clone($file_array, $cf, $rra_array, $debug) { function rrd_rra_clone($file_array, $cf, $rra_array, $debug) {
$rrdtool_pipe = rrd_init(); $rrdtool_pipe = rrd_init();
/* iterate all given rrd files */ /* iterate all given rrd files */
foreach ($file_array as $file) { foreach ($file_array as $file) {
/* create a DOM document from an rrdtool dump */ /* create a DOM document from an rrdtool dump */
$dom = new domDocument; $dom = new domDocument;
$dom->loadXML(rrdtool_execute("dump $file", false, RRDTOOL_OUTPUT _STDOUT, $rrdtool_pipe, 'UTIL')); $dom->loadXML(rrdtool_execute("dump $file", false, RRDTOOL_OUTPUT _STDOUT, $rrdtool_pipe, 'UTIL'));
if (!$dom) { if (!$dom) {
skipping to change at line 3295 skipping to change at line 3327
} }
} }
} }
} }
rrd_close($rrdtool_pipe); rrd_close($rrdtool_pipe);
return true; return true;
} }
/** appends a <DS> subtree to an RRD XML structure /**
* @param object $dom - the DOM object, where the RRD XML is stored * rrd_append_ds - appends a <DS> subtree to an RRD XML structure
* @param string $version- rrd file version *
* @param string $name - name of the new ds * @param (object) $dom - the DOM object, where the RRD XML is stored
* @param string $type - type of the new ds * @param (string) $version - rrd file version
* @param int $min_hb - heartbeat of the new ds * @param (string) $name - name of the new ds
* @param string $min - min value of the new ds or [NaN|U] * @param (string) $type - type of the new ds
* @param string $max - max value of the new ds or [NaN|U] * @param (int) $min_hb - heartbeat of the new ds
* @return object - modified DOM * @param (string) $min - min value of the new ds or [NaN|U]
* @param (string) $max - max value of the new ds or [NaN|U]
*
* @return (object) - modified DOM
*/ */
function rrd_append_ds($dom, $version, $name, $type, $min_hb, $min, $max) { function rrd_append_ds($dom, $version, $name, $type, $min_hb, $min, $max) {
/* rrdtool version dependencies */ /* rrdtool version dependencies */
if ($version === RRD_FILE_VERSION1) { if ($version === RRD_FILE_VERSION1) {
$last_ds = 'U'; $last_ds = 'U';
} }
elseif ($version === RRD_FILE_VERSION3) { elseif ($version === RRD_FILE_VERSION3) {
$last_ds = 'UNKN'; $last_ds = 'UNKN';
} }
skipping to change at line 3350 skipping to change at line 3385
* which is the <rra> entry */ * which is the <rra> entry */
#$insert = $xpath->query('/rrd/rra')->item(0); #$insert = $xpath->query('/rrd/rra')->item(0);
$insert = $dom->getElementsByTagName('rra')->item(0); $insert = $dom->getElementsByTagName('rra')->item(0);
/* import the new node */ /* import the new node */
$new_node = $dom->importNode($new_node, true); $new_node = $dom->importNode($new_node, true);
/* and insert it at the correct place */ /* and insert it at the correct place */
$insert->parentNode->insertBefore($new_node, $insert); $insert->parentNode->insertBefore($new_node, $insert);
} }
/** COMPUTE DS: appends a <DS> subtree to an RRD XML structure /**
* @param object $dom - the DOM object, where the RRD XML is stored * rrd_append_compute_ds - COMPUTE DS: appends a <DS> subtree to an RRD XML stru
* @param string $version- rrd file version cture
* @param string $name - name of the new ds *
* @param string $type - type of the new ds * @param (object) $dom - the DOM object, where the RRD XML is stored
* @param int $cdef - the cdef rpn used for COMPUTE * @param (string) $version - rrd file version
* @return object - modified DOM * @param (string) $name - name of the new ds
* @param (string) $type - type of the new ds
* @param (int) $cdef - the cdef rpn used for COMPUTE
*
* @return (object) - modified DOM
*/ */
function rrd_append_compute_ds($dom, $version, $name, $type, $cdef) { function rrd_append_compute_ds($dom, $version, $name, $type, $cdef) {
/* rrdtool version dependencies */ /* rrdtool version dependencies */
if ($version === RRD_FILE_VERSION1) { if ($version === RRD_FILE_VERSION1) {
$last_ds = 'U'; $last_ds = 'U';
} }
elseif ($version === RRD_FILE_VERSION3) { elseif ($version === RRD_FILE_VERSION3) {
$last_ds = 'UNKN'; $last_ds = 'UNKN';
} }
skipping to change at line 3400 skipping to change at line 3438
* which is the <rra> entry */ * which is the <rra> entry */
#$insert = $xpath->query('/rrd/rra')->item(0); #$insert = $xpath->query('/rrd/rra')->item(0);
$insert = $dom->getElementsByTagName('rra')->item(0); $insert = $dom->getElementsByTagName('rra')->item(0);
/* import the new node */ /* import the new node */
$new_node = $dom->importNode($new_node, true); $new_node = $dom->importNode($new_node, true);
/* and insert it at the correct place */ /* and insert it at the correct place */
$insert->parentNode->insertBefore($new_node, $insert); $insert->parentNode->insertBefore($new_node, $insert);
} }
/** append a <DS> subtree to the <CDP_PREP> subtrees of a RRD XML structure /**
* @param object $dom - the DOM object, where the RRD XML is stored * rrd_append_cdp_prep_ds - append a <DS> subtree to the <CDP_PREP> subtrees of
* @param string $version - rrd file version a RRD XML structure
* @return object - the modified DOM object *
* @param (object) $dom - the DOM object, where the RRD XML is stored
* @param (string) $version - rrd file version
*
* @return (object) - the modified DOM object
*/ */
function rrd_append_cdp_prep_ds($dom, $version) { function rrd_append_cdp_prep_ds($dom, $version) {
/* get all <cdp_prep><ds> entries */ /* get all <cdp_prep><ds> entries */
#$cdp_prep_list = $xpath->query('/rrd/rra/cdp_prep'); #$cdp_prep_list = $xpath->query('/rrd/rra/cdp_prep');
$cdp_prep_list = $dom->getElementsByTagName('rra')->item(0)->getElementsB yTagName('cdp_prep'); $cdp_prep_list = $dom->getElementsByTagName('rra')->item(0)->getElementsB yTagName('cdp_prep');
/* get XPATH notation required for positioning */ /* get XPATH notation required for positioning */
#$xpath = new DOMXPath($dom); #$xpath = new DOMXPath($dom);
/* get XPATH for source <ds> entry */ /* get XPATH for source <ds> entry */
skipping to change at line 3439 skipping to change at line 3480
/* iterate all entries found, equals 'number of <rra>' times 'number of < ds>' */ /* iterate all entries found, equals 'number of <rra>' times 'number of < ds>' */
if ($cdp_prep_list->length) { if ($cdp_prep_list->length) {
foreach ($cdp_prep_list as $cdp_prep) { foreach ($cdp_prep_list as $cdp_prep) {
/* $cdp_prep now points to the next <cdp_prep> XML Elemen t /* $cdp_prep now points to the next <cdp_prep> XML Elemen t
* and append new ds entry at end of <cdp_prep> child lis t */ * and append new ds entry at end of <cdp_prep> child lis t */
$cdp_prep->appendChild($new_ds); $cdp_prep->appendChild($new_ds);
} }
} }
} }
/** append a <V>alue element to the <DATABASE> subtrees of a RRD XML structure /**
* @param object $dom - the DOM object, where the RRD XML is stored * rrd_append_value - append a <V>alue element to the <DATABASE> subtrees of a R
* @return object - the modified DOM object RD XML structure
*
* @param (object) $dom - the DOM object, where the RRD XML is stored
*
* @return (object) - the modified DOM object
*/ */
function rrd_append_value($dom) { function rrd_append_value($dom) {
/* get XPATH notation required for positioning */ /* get XPATH notation required for positioning */
#$xpath = new DOMXPath($dom); #$xpath = new DOMXPath($dom);
/* get all <cdp_prep><ds> entries */ /* get all <cdp_prep><ds> entries */
#$itemList = $xpath->query('/rrd/rra/database/row'); #$itemList = $xpath->query('/rrd/rra/database/row');
$itemList = $dom->getElementsByTagName('row'); $itemList = $dom->getElementsByTagName('row');
/* create <V> entry to preserve RRDtool notation */ /* create <V> entry to preserve RRDtool notation */
skipping to change at line 3464 skipping to change at line 3508
/* iterate all entries found, equals 'number of <rra>' times 'number of < ds>' */ /* iterate all entries found, equals 'number of <rra>' times 'number of < ds>' */
if ($itemList->length) { if ($itemList->length) {
foreach ($itemList as $item) { foreach ($itemList as $item) {
/* $item now points to the next <cdp_prep> XML Element /* $item now points to the next <cdp_prep> XML Element
* and append new ds entry at end of <cdp_prep> child lis t */ * and append new ds entry at end of <cdp_prep> child lis t */
$item->appendChild($new_v); $item->appendChild($new_v);
} }
} }
} }
/** delete an <RRA> subtree from the <RRD> XML structure /**
* @param object $dom - the DOM document, where the RRD XML is stored * rrd_delete_rra - delete an <RRA> subtree from the <RRD> XML structure
* @param array $rra_parm - a single rra parameter set, given by the user *
* @return object - the modified DOM object * @param (object) $dom - the DOM document, where the RRD XML is stored
* @param (array) $rra_parm - a single rra parameter set, given by the user
*
* @return (object) - the modified DOM object
*/ */
function rrd_delete_rra($dom, $rra_parm) { function rrd_delete_rra($dom, $rra_parm) {
/* find all RRA DOMNodes */ /* find all RRA DOMNodes */
$rras = $dom->getElementsByTagName('rra'); $rras = $dom->getElementsByTagName('rra');
/* iterate all entries found */ /* iterate all entries found */
$nb = $rras->length; $nb = $rras->length;
for ($pos = 0; $pos < $nb; $pos++) { for ($pos = 0; $pos < $nb; $pos++) {
/* retrieve all RRA DOMNodes one by one */ /* retrieve all RRA DOMNodes one by one */
$rra = $rras->item($pos); $rra = $rras->item($pos);
skipping to change at line 3497 skipping to change at line 3544
print(__("RRA (CF=%s, ROWS=%d, PDP_PER_ROW=%d, XFF=%1.2f) removed from RRD file", $cf, $rows, $pdp_per_row, $xff)) . PHP_EOL; print(__("RRA (CF=%s, ROWS=%d, PDP_PER_ROW=%d, XFF=%1.2f) removed from RRD file", $cf, $rows, $pdp_per_row, $xff)) . PHP_EOL;
/* we need the parentNode for removal operation */ /* we need the parentNode for removal operation */
$parent = $rra->parentNode; $parent = $rra->parentNode;
$parent->removeChild($rra); $parent->removeChild($rra);
break; /* do NOT accidentally remove more than one elemen t, else loop back to forth */ break; /* do NOT accidentally remove more than one elemen t, else loop back to forth */
} }
} }
return $dom; return $dom;
} }
/** clone an <RRA> subtree of the <RRD> XML structure, replacing cf /**
* @param object $dom - the DOM document, where the RRD XML is stored * rrd_copy_rra - clone an <RRA> subtree of the <RRD> XML structure, replacing c
* @param string $cf - new consolidation function f
* @param array $rra_parm - a single rra parameter set, given by the user *
* @return object - the modified DOM object * @param (object) $dom - the DOM document, where the RRD XML is stored
* @param (string) $cf - new consolidation function
* @param (array) $rra_parm - a single rra parameter set, given by the user
*
* @return (object) - the modified DOM object
*/ */
function rrd_copy_rra($dom, $cf, $rra_parm) { function rrd_copy_rra($dom, $cf, $rra_parm) {
/* find all RRA DOMNodes */ /* find all RRA DOMNodes */
$rras = $dom->getElementsByTagName('rra'); $rras = $dom->getElementsByTagName('rra');
/* iterate all entries found */ /* iterate all entries found */
$nb = $rras->length; $nb = $rras->length;
for ($pos = 0; $pos < $nb; $pos++) { for ($pos = 0; $pos < $nb; $pos++) {
/* retrieve all RRA DOMNodes one by one */ /* retrieve all RRA DOMNodes one by one */
$rra = $rras->item($pos); $rra = $rras->item($pos);
skipping to change at line 3579 skipping to change at line 3629
$rra_path = '(' . __('RRA Folder') . ': ' . ((emp ty($rra_path) || $rra_path == ".") ? __('Root') : $rra_path) . ')'; $rra_path = '(' . __('RRA Folder') . ': ' . ((emp ty($rra_path) || $rra_path == ".") ? __('Root') : $rra_path) . ')';
} }
$string = $message . ":\n\0x27\n" . $rra_name; $string = $message . ":\n\0x27\n" . $rra_name;
if (!empty($rra_path)) { if (!empty($rra_path)) {
$string .= "\n" . $rra_path; $string .= "\n" . $rra_path;
} }
} }
} }
return $string; return $string;
} }
function rrdtool_create_error_image($string, $width = '', $height = '') { function rrdtool_create_error_image($string, $width = '', $height = '') {
global $config, $dejavu_paths; global $config, $dejavu_paths;
$string = rrdtool_parse_error($string); $string = rrdtool_parse_error($string);
/* put image in buffer */ /* put image in buffer */
ob_start(); ob_start();
skipping to change at line 3668 skipping to change at line 3719
/* merge the two images */ /* merge the two images */
imagecopy($image, $logo, 0, 0, 0, 0, 450, 200); imagecopy($image, $logo, 0, 0, 0, 0, 450, 200);
/* set the background color */ /* set the background color */
list($red, $green, $blue) = sscanf($font_color, '%02x%02x%02x'); list($red, $green, $blue) = sscanf($font_color, '%02x%02x%02x');
$text_color = imagecolorallocate($image, $red, $green, $blue); $text_color = imagecolorallocate($image, $red, $green, $blue);
/* see the size of the string */ /* see the size of the string */
$string = trim($string); $string = trim($string);
$maxstring = (450 - (125 + 10)) / ($font_size / 0.9); $maxstring = ceil((450 - (125 + 10)) / ($font_size / 0.9));
$stringlen = strlen($string) * $font_size; $stringlen = strlen($string) * $font_size;
$padding = 5; $padding = 5;
if ($stringlen > $maxstring) { if ($stringlen > $maxstring) {
$cstring = wordwrap($string, $maxstring, "\n", true); $cstring = wordwrap($string, $maxstring, "\n", true);
$strings = explode("\n", $cstring); $strings = explode("\n", $cstring);
$strings = array_reverse($strings); $strings = array_reverse($strings);
$lines = cacti_sizeof($strings); $lines = cacti_sizeof($strings);
} elseif (strlen(trim($string)) == 0) { } elseif (strlen(trim($string)) == 0) {
$strings = array(__('Unknown RRDtool Error')); $strings = array(__('Unknown RRDtool Error'));
skipping to change at line 3737 skipping to change at line 3788
imagedestroy($logo); imagedestroy($logo);
if (isset($nimage)) { if (isset($nimage)) {
imagedestroy($nimage); imagedestroy($nimage);
} }
/* flush the buffer */ /* flush the buffer */
ob_end_clean(); ob_end_clean();
return $image_data; return $image_data;
} }
/**
* gradient - Add gradient support for AREA type charts. This function adds seve
ral CDEF with different shading
*
* @param (bool) $vname - the data source name
* @param (string) $start_color - the start color for the gradient
* @param (string) $end_color - the end color for the gradient
* @param (bool) $label - any label attached to it
* @param (string) $steps - defaults to 20
* @param (bool) $lower - defaults to faulse
* @param (string) $alpha - Alpha channel to be used
*
* @return (string) - the additional CDEF/AREA command lines for rrdtool
*
* License: GPLv2
* Original Code: https://github.com/lingej/pnp4nagios/blob/master/share/pnp/app
lication/helpers/rrd.php
*/
function gradient($vname=FALSE, $start_color='#0000a0', $end_color='#f0f0f0', $l
abel=FALSE, $steps=20, $lower=FALSE, $alpha='FF'){
$label = preg_replace("/'/", "", $label);
if (preg_match('/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i',$start_col
or,$matches)) {
$r1=hexdec($matches[1]);
$g1=hexdec($matches[2]);
$b1=hexdec($matches[3]);
}
if (preg_match('/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i',$end_color
,$matches)) {
$r2=hexdec($matches[1]);
$g2=hexdec($matches[2]);
$b2=hexdec($matches[3]);
}
$diff_r=$r2-$r1;
$diff_g=$g2-$g1;
$diff_b=$b2-$b1;
$spline = "";
$spline_vname = "var".substr(sha1(rand()),1,4);
$vnamet = $vname.substr(sha1(rand()),1,4);
if(preg_match('/^([0-9]{1,3})%$/', $lower, $matches)) {
$lower = $matches[1];
$spline .= sprintf("CDEF:%sminimum=%s,100,/,%d,* ".RRD_NL, $vname
t, $vname, $lower);
} elseif (preg_match('/^([0-9]+)$/', $lower, $matches)) {
$lower = $matches[1];
$spline .= sprintf("CDEF:%sminimum=%s,%d,- ".RRD_NL, $vnamet, $vn
ame, $lower);
} else {
$lower = 0;
$spline .= sprintf("CDEF:%sminimum=%s,%s,- ".RRD_NL, $vnamet, $vn
ame, $vname);
}
for ($i=$steps; $i>0; $i--){
$spline .= sprintf("CDEF:%s%d=%s,%sminimum,-,%d,/,%d,*,%sminimum
,+ ".RRD_NL,$spline_vname,$i,$vname,$vnamet,$steps,$i,$vnamet);
}
// We don't use alpha blending for the area right now
$alpha = 'ff';
for ($i=$steps; $i>0; $i--){
$factor=$i / $steps;
$r=round($r1 + $diff_r * $factor);
$g=round($g1 + $diff_g * $factor);
$b=round($b1 + $diff_b * $factor);
if (($i == $steps) && ($label != false) && (strlen($label) > 2))
{
$spline .= sprintf("AREA:%s%d#%02X%02X%02X%s:\"%s\" ".RR
D_NL, $spline_vname,$i,$r,$g,$b,$alpha,$label);
} else {
$spline .= sprintf("AREA:%s%d#%02X%02X%02X%s ".RRD_NL, $
spline_vname,$i,$r,$g,$b,$alpha);
}
}
$spline .= sprintf("AREA:%s%d#%02X%02X%02X%s ".RRD_NL, $spline_vname,$st
eps,$r2,$g2,$b2,'00',$label);
return $spline;
}
/**
* colourBrightness - Add colourBrightness support for the gradient charts. This
function calculates the darker version of a given color
*
* @param (bool) $hex - The hex representation of a color
* @param (string) $percent - the percentage to darken the given color. decimal
number ( 0.4 -> 40% )
*
* @return (string) - the darker version of the given color
*
* License: GPLv2
* Original Code http://www.barelyfitz.com/projects/csscolor/
*/
function colourBrightness($hex, $percent) {
// Work out if hash given
$hash = '';
if (stristr($hex,'#')) {
$hex = str_replace('#','',$hex);
$hash = '#';
}
/// HEX TO RGB
$rgb = array(hexdec(substr($hex,0,2)), hexdec(substr($hex,2,2)), hexdec(s
ubstr($hex,4,2)));
//// CALCULATE
for ($i=0; $i<3; $i++) { // See if brighter or darker
if ($percent > 0) {
// Lighter
$rgb[$i] = round($rgb[$i] * $percent) + round(255 * (1-$p
ercent));
} else {
// Darker
$positivePercent = $percent - ($percent*2);
$rgb[$i] = round($rgb[$i] * (1-$positivePercent)); // rou
nd($rgb[$i] * (1-$positivePercent));
}
// In case rounding up causes us to go to 256
if ($rgb[$i] > 255) {
$rgb[$i] = 255;
}
}
//// RBG to Hex
$hex = '';
for ($i=0; $i < 3; $i++) {
// Convert the decimal digit to hex
$hexDigit = dechex($rgb[$i]);
// Add a leading zero if necessary
if (strlen($hexDigit) == 1) {
$hexDigit = "0" . $hexDigit;
}
// Append to the hex string
$hex .= $hexDigit;
}
return $hash.$hex;
}
 End of changes. 33 change blocks. 
96 lines changed or deleted 159 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)