Define graph colours from config.php instead of being hard coded in files

Could the definition of the variables $colours_in and $colours_out used by graphs be moved to the config.php instead of being hardcoded in the various graph files?

For example, in /opt/libre/includes/html/graphs/global/ defines
$colous_in = ‘greens’;
$colours_out = ‘blues’;

if these could be overridden in the config.php with a command something like

$config[‘colours_in’] = ‘greens’;
$config[‘colours_out’] = ‘blues’

and then in the various graph include files it reads the config.php colours_*

$colours_in = Config::colours_in;
$colours_out = Config::colours_out;

This way we can override the default colours by adding the following to the config.php:

$config[‘graph_colours’][‘bluegradient’] = array(“3FABEE”, “3998D7”, “3385C0”, “2D72A9”, “275F92”, “204B7A”, “1A3863”, “14254C”, “0E1235”);

and then set $config[‘colours_in’] = ‘bluegradient’;

sorry for the bad sudo code.


Have not played with colours, if you run the below - does that pick up all the instances where it would need changing?

/opt/librenms$ egrep -R '\$colours?_(.+)* =' *

I can see various examples of what you showed, some other hard codings, and some config linked ones.

Could you explain the expected changes for the various scenarios so it’s clear?

A couple of different examples from the above command output:

includes/html/graphs/global/$colours_in = 'greens';
includes/html/graphs/global/$colours_out = 'blues';
includes/html/graphs/global/$colour_line_in = '006600';
includes/html/graphs/global/$colour_line_out = '000099';
includes/html/graphs/global/$colour_area_in = 'CDEB8B';
includes/html/graphs/global/$colour_area_out = 'C3D9FF';
includes/html/graphs/    $colour_in = Config::get("graph_colours.$colours_in.$iter");
includes/html/graphs/    $colour_out = Config::get("graph_colours.$colours_out.$iter");
includes/html/graphs/        $colour_in = $rrd['colour_area_in'];
includes/html/graphs/        $colour_out = $rrd['colour_area_out'];
includes/html/graphs/application/$colour_area = 'F6F6F6';
includes/html/graphs/application/$colour_line = '555555';
includes/html/graphs/application/$colour_area_max = 'FFEE99';
includes/html/graphs/application/$colour_area = 'EEEEEE';
includes/html/graphs/application/$colour_line = '36393D';
includes/html/graphs/application/$colour_area_max = 'FFEE99';

As I’m still learning and many others probably don’t play with these settings - could you also show an example of which graph you’re changing, the code you change, and what it looks like before and after?

Then we can recreate what you’re doing to understand the moving parts.


Here are several examples, the file I am editing is in includes/graphs/multi/bits_separated.php to change colours.

This is the default using $colours_in = ‘greens’;

Altering the file and changing the $colours_in = ‘greens’; to $colours_in = ‘bluesgradient’; and where I have defined bluesgradient in the config.php by adding $config[‘graph_colours’][‘bluesgradient’] = array(“colour1”, “colour2”, etc);

Using the manual method of altering the graph php files is easy enough but it breaks the daily.php updates when changes are made. As requested initially, having the $colours_in and $colours_out defined in the config.php it would allow for graph customization and without breaking the update mechanism that is built into LibreNMS. This would also make it easier to move the colours out of config_definitions.json and into the config so LibreNMS users are aware of the different options for graph colours.