Skip to content

Commit

Permalink
Add support for RRD --left-axis-format Option (#5280)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschultzca committed Mar 26, 2023
1 parent f051bf3 commit f8ce3b6
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 33 deletions.
1 change: 1 addition & 0 deletions aggregate_graphs.php
Expand Up @@ -958,6 +958,7 @@ function graph_edit() {
'#right_axis_label',
'#right_axis_format',
'#right_axis_formatter',
'#left_axis_format',
'#left_axis_formatter',
'#no_gridfit',
'#unit_length',
Expand Down
4 changes: 4 additions & 0 deletions cacti.sql
Expand Up @@ -153,6 +153,8 @@ CREATE TABLE `aggregate_graph_templates_graph` (
right_axis_format mediumint(8) DEFAULT NULL,
t_right_axis_formatter char(2) DEFAULT '',
right_axis_formatter varchar(10) DEFAULT NULL,
t_left_axis_format char(2) DEFAULT '',
left_axis_format mediumint(8) DEFAULT NULL,
t_left_axis_formatter char(2) DEFAULT '',
left_axis_formatter varchar(10) DEFAULT NULL,
t_no_gridfit char(2) DEFAULT '',
Expand Down Expand Up @@ -1841,6 +1843,8 @@ CREATE TABLE graph_templates_graph (
right_axis_format mediumint(8) DEFAULT NULL,
t_right_axis_formatter char(2) DEFAULT '',
right_axis_formatter varchar(10) DEFAULT NULL,
t_left_axis_format char(2) DEFAULT '',
left_axis_format mediumint(8) DEFAULT NULL,
t_left_axis_formatter char(2) DEFAULT '',
left_axis_formatter varchar(10) DEFAULT NULL,
t_no_gridfit char(2) DEFAULT '',
Expand Down
68 changes: 36 additions & 32 deletions docs/audit_schema.sql
Expand Up @@ -121,22 +121,24 @@ INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',42,'t_righ
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',43,'right_axis_format','mediumint(8)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',44,'t_right_axis_formatter','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',45,'right_axis_formatter','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',46,'t_left_axis_formatter','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',47,'left_axis_formatter','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',48,'t_no_gridfit','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',49,'no_gridfit','char(2)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',50,'t_unit_length','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',51,'unit_length','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',52,'t_tab_width','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',53,'tab_width','varchar(20)','YES','','30','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',54,'t_dynamic_labels','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',55,'dynamic_labels','char(2)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',56,'t_force_rules_legend','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',57,'force_rules_legend','char(2)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',58,'t_legend_position','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',59,'legend_position','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',60,'t_legend_direction','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',61,'legend_direction','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',46,'t_left_axis_format','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',47,'left_axis_format','mediumint(8)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',48,'t_left_axis_formatter','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',49,'left_axis_formatter','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',50,'t_no_gridfit','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',51,'no_gridfit','char(2)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',52,'t_unit_length','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',53,'unit_length','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',54,'t_tab_width','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',55,'tab_width','varchar(20)','YES','','30','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',56,'t_dynamic_labels','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',57,'dynamic_labels','char(2)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',58,'t_force_rules_legend','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',59,'force_rules_legend','char(2)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',60,'t_legend_position','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',61,'legend_position','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',62,'t_legend_direction','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_graph',63,'legend_direction','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_item',1,'aggregate_template_id','int(10) unsigned','NO','PRI',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_item',2,'graph_templates_item_id','int(10) unsigned','NO','PRI',NULL,'');
INSERT INTO `table_columns` VALUES ('aggregate_graph_templates_item',3,'sequence','mediumint(8) unsigned','NO','','0','');
Expand Down Expand Up @@ -537,22 +539,24 @@ INSERT INTO `table_columns` VALUES ('graph_templates_graph',48,'t_right_axis_for
INSERT INTO `table_columns` VALUES ('graph_templates_graph',49,'right_axis_format','mediumint(8)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',50,'t_right_axis_formatter','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',51,'right_axis_formatter','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',52,'t_left_axis_formatter','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',53,'left_axis_formatter','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',54,'t_no_gridfit','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',55,'no_gridfit','char(2)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',56,'t_unit_length','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',57,'unit_length','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',58,'t_tab_width','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',59,'tab_width','varchar(20)','YES','','30','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',60,'t_dynamic_labels','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',61,'dynamic_labels','char(2)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',62,'t_force_rules_legend','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',63,'force_rules_legend','char(2)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',64,'t_legend_position','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',65,'legend_position','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',66,'t_legend_direction','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',67,'legend_direction','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',52,'t_left_axis_label','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',53,'left_axis_label','varchar(200)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',54,'t_left_axis_formatter','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',55,'left_axis_formatter','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',56,'t_no_gridfit','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',57,'no_gridfit','char(2)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',58,'t_unit_length','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',59,'unit_length','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',60,'t_tab_width','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',61,'tab_width','varchar(20)','YES','','30','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',62,'t_dynamic_labels','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',63,'dynamic_labels','char(2)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',64,'t_force_rules_legend','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',65,'force_rules_legend','char(2)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',66,'t_legend_position','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',67,'legend_position','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',68,'t_legend_direction','char(2)','YES','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_graph',69,'legend_direction','varchar(10)','YES','',NULL,'');
INSERT INTO `table_columns` VALUES ('graph_templates_item',1,'id','int(10) unsigned','NO','PRI',NULL,'auto_increment');
INSERT INTO `table_columns` VALUES ('graph_templates_item',2,'hash','varchar(32)','NO','','','');
INSERT INTO `table_columns` VALUES ('graph_templates_item',3,'local_graph_template_item_id','int(10) unsigned','NO','MUL','0','');
Expand Down
2 changes: 2 additions & 0 deletions graph_templates.php
Expand Up @@ -186,6 +186,8 @@ function form_save() {
$save2['legend_direction'] = form_input_validate((isset_request_var('legend_direction') ? get_nfilter_request_var('legend_direction') : ''), 'legend_direction', '', true, 3);
$save2['t_right_axis_formatter'] = form_input_validate((isset_request_var('t_right_axis_formatter') ? get_nfilter_request_var('t_right_axis_formatter') : ''), 't_right_axis_formatter', '', true, 3);
$save2['right_axis_formatter'] = form_input_validate((isset_request_var('right_axis_formatter') ? get_nfilter_request_var('right_axis_formatter') : ''), 'right_axis_formatter', '', true, 3);
$save2['t_left_axis_format'] = form_input_validate((isset_request_var('t_left_axis_format') ? get_nfilter_request_var('t_left_axis_format') : ''), 't_left_axis_format', '', true, 3);
$save2['left_axis_format'] = form_input_validate((isset_request_var('left_axis_format') ? get_nfilter_request_var('left_axis_format') : ''), 'left_axis_format', '^[0-9]+$', true, 3);
$save2['t_left_axis_formatter'] = form_input_validate((isset_request_var('t_left_axis_formatter') ? get_nfilter_request_var('t_left_axis_formatter') : ''), 't_left_axis_formatter', '', true, 3);
$save2['left_axis_formatter'] = form_input_validate((isset_request_var('left_axis_formatter') ? get_nfilter_request_var('left_axis_formatter') : ''), 'left_axis_formatter', '', true, 3);

Expand Down
1 change: 1 addition & 0 deletions graphs.php
Expand Up @@ -318,6 +318,7 @@ function form_save() {
$save2['legend_position'] = form_input_validate((isset_request_var('legend_position') ? get_nfilter_request_var('legend_position') : ''), 'legend_position', '', true, 3);
$save2['legend_direction'] = form_input_validate((isset_request_var('legend_direction') ? get_nfilter_request_var('legend_direction') : ''), 'legend_direction', '', true, 3);
$save2['right_axis_formatter'] = form_input_validate((isset_request_var('right_axis_formatter') ? get_nfilter_request_var('right_axis_formatter') : ''), 'right_axis_formatter', '', true, 3);
$save2['left_axis_format'] = form_input_validate((isset_request_var('left_axis_format') ? get_nfilter_request_var('left_axis_format') : ''), 'left_axis_format', '^[0-9]+$', true, 3);
$save2['left_axis_formatter'] = form_input_validate((isset_request_var('left_axis_formatter') ? get_nfilter_request_var('left_axis_formatter') : ''), 'left_axis_formatter', '', true, 3);

if (!is_error_message()) {
Expand Down
8 changes: 8 additions & 0 deletions include/global_form.php
Expand Up @@ -902,6 +902,14 @@
'none_value' => __('None'),
'description' => __('When you setup the right axis labeling, apply a rule to the data format. Supported formats include "numeric" where data is treated as numeric, "timestamp" where values are interpreted as UNIX timestamps (number of seconds since January 1970) and expressed using strftime format (default is "%Y-%m-%d %H:%M:%S"). See also --units-length and --right-axis-format. Finally "duration" where values are interpreted as duration in milliseconds. Formatting follows the rules of valstrfduration qualified PRINT/GPRINT.'),
),
'left_axis_format' => array(
'friendly_name' => __('Left Axis Format (--left-axis-format <format>)'),
'method' => 'drop_sql',
'sql' => 'SELECT id, name FROM graph_templates_gprint ORDER BY name',
'default' => '',
'none_value' => __('None'),
'description' => __('By default, the format of the axis labels gets determined automatically. If you want to do this yourself, use this option with the same %lf arguments you know from the PRINT and GPRINT commands.'),
),
'left_axis_formatter' => array(
'friendly_name' => __('Left Axis Formatter (--left-axis-formatter <formatname>)'),
'method' => 'drop_array',
Expand Down
4 changes: 4 additions & 0 deletions install/upgrades/1_3_0.php
Expand Up @@ -30,6 +30,10 @@ function upgrade_to_1_3_0() {
db_install_add_column('host', array('name' => 'created', 'type' => 'timestamp', 'default' => 'CURRENT_TIMESTAMP'));
db_install_add_column('sites', array('name' => 'disabled', 'type' => 'char(2)', 'null' => false, 'default' => '', 'after' => 'name'));
db_install_add_column('user_domains_ldap', array('name' => 'tls_certificate', 'type' => 'tinyint(3)', 'unsigned' => true, 'null' => false, 'default' => '3'));
db_install_add_column('graph_templates_graph', array('name' => 't_left_axis_format', 'type' => 'char(2)', 'default' => '', 'after' => 'right_axis_formatter'));
db_install_add_column('graph_templates_graph', array('name' => 'left_axis_format', 'type' => 'mediumint(8)', 'NULL' => true, 'after' => 't_left_axis_format'));
db_install_add_column('aggregate_graph_templates_graph', array('name' => 't_left_axis_format', 'type' => 'char(2)', 'default' => '0', 'after' => 'right_axis_formatter'));
db_install_add_column('aggregate_graph_templates_graph', array('name' => 'left_axis_format', 'type' => 'mediumint(8)', 'NULL' => true, 'after' => 't_left_axis_format'));

//Not sure why we were adding this...
//db_install_add_column('user_domains', array('name' => 'tls_verify', 'type' => 'int', 'null' => false, 'default' => '0'));
Expand Down
1 change: 1 addition & 0 deletions lib/api_aggregate.php
Expand Up @@ -571,6 +571,7 @@ function aggregate_validate_graph_params($posted, $has_override = false) {
'grouping' => array('type' => 'str', 'allow_empty' => true, 'default' => '', 'regex' => ''),
'height' => array('type' => 'int', 'allow_empty' => false, 'default' => 0, 'regex' => '^[0-9]+$'),
'image_format_id' => array('type' => 'int', 'allow_empty' => false, 'default' => 0, 'regex' => ''),
'left_axis_format' => array('type' => 'int', 'allow_empty' => true, 'default' => '', 'regex' => '^[0-9]+$'),
'left_axis_formatter' => array('type' => 'str', 'allow_empty' => true, 'default' => '', 'regex' => ''),
'legend_direction' => array('type' => 'str', 'allow_empty' => true, 'default' => '', 'regex' => ''),
'legend_position' => array('type' => 'str', 'allow_empty' => true, 'default' => '', 'regex' => ''),
Expand Down
9 changes: 8 additions & 1 deletion lib/rrd.php
Expand Up @@ -1290,6 +1290,13 @@ function rrd_function_process_graph_options($graph_start, $graph_end, &$graph, &
$graph_opts .= '--right-axis-format ' . cacti_escapeshellarg(trim(str_replace('%s', '', $format))) . RRD_NL;
}

break;
case "left_axis_format":
if (!empty($value)) {
$format = db_fetch_cell_prepared('SELECT gprint_text from graph_templates_gprint WHERE id = ?', array($value));
$graph_opts .= "--left-axis-format " . cacti_escapeshellarg(trim(str_replace('%s', '', $format))) . RRD_NL;
}

break;
case 'no_gridfit':
if ($value == CHECKED) {
Expand Down Expand Up @@ -1513,7 +1520,7 @@ function rrdtool_function_graph($local_graph_id, $rra_id, $graph_data_array, $rr
gtg.right_axis, gtg.right_axis_label, gtg.right_axis_format, gtg.no_gridfit,
gtg.unit_length, gtg.tab_width, gtg.dynamic_labels, gtg.force_rules_legend,
gtg.legend_position, gtg.legend_direction, gtg.right_axis_formatter,
gtg.left_axis_formatter
gtg.left_axis_format, gtg.left_axis_formatter
FROM graph_templates_graph AS gtg
INNER JOIN graph_local AS gl
ON gl.id=gtg.local_graph_id
Expand Down
4 changes: 4 additions & 0 deletions locales/po/cacti.pot
Expand Up @@ -8510,6 +8510,10 @@ msgstr ""
msgid "Right Axis Format (--right-axis-format <format>)"
msgstr ""

#: include/global_form.php:905
msgid "Left Axis Format (--left-axis-format <format>)"
msgstr ""

#: include/global_form.php:895
#, php-format
msgid "By default, the format of the axis labels gets determined automatically. If you want to do this yourself, use this option with the same %lf arguments you know from the PRINT and GPRINT commands."
Expand Down

0 comments on commit f8ce3b6

Please sign in to comment.