This support forum board is for support questions relating to
Nagios XI , our flagship commercial network monitoring solution.
brandon.pal
Posts: 129 Joined: Wed Feb 19, 2014 10:18 pm
Post
by brandon.pal » Mon May 26, 2014 10:34 am
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.
Box293
Too Basu
Posts: 5126 Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:
Post
by Box293 » Mon May 26, 2014 7:16 pm
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 .
tmcdonald
Posts: 9117 Joined: Mon Sep 23, 2013 8:40 am
Post
by tmcdonald » Tue May 27, 2014 9:41 am
Closing as solved.
Former Nagios employee