graph template line color

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
brandon.pal
Posts: 129
Joined: Wed Feb 19, 2014 10:18 pm

graph template line color

Post by brandon.pal »

Hey All,

I've created a custom disk check that analizes % free on all disks and outputs the data. Check works great. I've also created a custom graph that shows all disks in one graph. I'm using a loop to get all the drives added to one graph.

My questions is how can I get the color of the line to change in each loop iteration. I've tried adding an if and case statement into the loop but as soon as I do that my graph dies.

Any ideas?

My Current Graph Code is:

Code: Select all

<?php

$arrayCount=count($DS);

$opt[1] = "--vertical-label \"% Used\" -l0 --title \"Disk Space Usage for $hostname / $servicedesc\" ";

for($i=1; $i<=$arrayCount; $i++) {

  $def[1] .= "DEF:$NAME[$i]=$rrdfile:$DS[$i]:AVERAGE " ;
  $def[1] .= "LINE1:$NAME[$i]#0000FF:\"\"$NAME[$i] " ;
  $def[1] .= "GPRINT:$NAME[$i]:LAST:\"%3.2lf $unit[i] CUR \" ";
  $def[1] .= "GPRINT:$NAME[$i]:MAX:\"%3.2lf $unit[i] MAX \" ";
  $def[1] .= "GPRINT:$NAME[$i]" . ':AVERAGE:"%3.2lf $unit[i] AVG \j" ';
}
?>
You do not have the required permissions to view the files attached to this post.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: graph template line color

Post by Box293 »

You could create an array of colors before running the loop and then use the $i to reference the color in the array.

For example:

Code: Select all

$colors = array(
 1 => "#0000FF",
 2 => "#00FFFF",
 3 => "#FFFFFF"
 );
then inside the for statement:

Code: Select all

  $def[1] .= "LINE1:$NAME[$i]".$colors[$i].":\"\"$NAME[$i] " ;
Something along those lines

If the amount of disks is unknown, create an array of about 20 colors so that it'll always work.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
brandon.pal
Posts: 129
Joined: Wed Feb 19, 2014 10:18 pm

Re: graph template line color

Post by brandon.pal »

Works perfectly. THANK YOU :D
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: graph template line color

Post by tmcdonald »

Closing as solved.
Former Nagios employee
Locked