This is probably better suited to the pnp4nagios users list, but I thought I'd post here as well.<br><br>I recently set out to do the exact same. Jorge was kind enough to help me along. The pnp4nagios "special" template (note: requires pnp4nagios 0.6.5+) below creates a stacked graph showing "messages per hour" on a number of ironport MTAs and at the bottom of the graph, shows the total of all messages for all ironports.<br>
<br>
The magic variables $rpn_stack and $counter are where the good stuff happens.<br>
<br>
<?php<br>
#<br>
$this->MACRO['TITLE'] = "messages per hour";<br>
$this->MACRO['COMMENT'] = "messages per hour";<br>
#<br>
# Get a List of Services by regex<br>
# Option 1 = 'Host Regex'<br>
# Option 2 = 'Service Regex'<br>
#<br>
$services = $this->tplGetServices("ironport","messages_per_hour");<br>
#<br>
# The Datasource Name for Graph 0<br>
$ds_name[0] = "total messages";<br>
$opt[0] = "--title \"messages per hour\"";<br>
$opt[0] .= " --watermark=\"ironport_messages_per_hour\" ";<br>
$def[0] = "";<br>
<br>
# THESE ARE THE MAGIC VARIABLES HERE:<br>
$rpn_stack = ""; # empty RPN string<br>
$counter = -1; # loop counter starting by -1<br>
#<br>
# Iterate through the list of hosts<br>
foreach($services as $key=>$val){<br>
#<br>
# get the data for a given Host/Service<br>
$a = $this->tplGetData($val['host'],$val['service']);<br>
#<br>
# Throw an exception to debug the content of $a<br>
# Just to get Infos about the Array Structure<br>
#<br>
#throw new Kohana_exception(print_r($a,TRUE));<br>
$def[0] .= rrd::def("a$key" ,$a['DS'][0]['RRDFILE'],
$a['DS'][0]['DS'], "AVERAGE");<br>
$def[0] .= rrd::area("a$key", rrd::color($key),
$a['MACRO']['HOSTNAME'], "STACK");<br>
$def[0] .= rrd::gprint("a$key", array("MIN", "MAX", "LAST",
"AVERAGE"), "%3.0lf %s");<br>
# THIS IS WHERE THE MAGIC VARIABLES GET USED:<br>
$rpn_stack .= "a$key,"; # add the current key to the stack<br>
$counter++; # counter +1<br>
}<br>
# AFTER THE FOREACH LOOP, CREATE THE RPN STACK, then use it in a CDEF.<br>
$rpn_stack .= str_repeat("+,", $counter); # build the rpn stack for
rrdtool "a0,a1,+,"<br>
$rpn_stack = substr($rpn_stack, 0, -1); # strip the last comma to
avoid rpn underflow<br>
$def[0] .= rrd::cdef("totals", $rpn_stack); # build a cdef using out rpn
expression<br>
$def[0] .=
rrd::comment("-------------------------------------------------------\\n");<br>
$def[0] .= rrd::comment("Totals\:\t ");<br>
$def[0] .= rrd::gprint("totals", array("MIN", "MAX", "LAST", "AVERAGE")
,"%3.2lf %s");<br>
$def[0] .= rrd::comment(" \\n");<br>
<br>cheers,<br><br>J<br>
<br><br><br><div class="gmail_quote">On Mon, Sep 20, 2010 at 9:24 AM, <span dir="ltr"><<a href="mailto:Matt.Garrett@shell.com">Matt.Garrett@shell.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-US">
<div>
<p class="MsoNormal">Folks</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">A little off topic but maybe someone can help.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Using pnp4nagios php template to loop through all rrds of a
certain type, which works fine.</p>
<p class="MsoNormal">However I would like to get the Grand Total of all rrds</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I know CDEF is the answer and can do this using php hard coding
but just cannot find out how to get this to work inside a php foreach loop</p>
<p class="MsoNormal">e.g</p>
<p class="MsoNormal">CDEF:total=var1,var2,+,var3,+</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">The php code I have been using is:</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">foreach($services as $key=>$val){</p>
<p class="MsoNormal"> #</p>
<p class="MsoNormal"> # get the data for a given Host/Service</p>
<p class="MsoNormal"> $data =
$this->tplGetData($val['host'],$val['service']);</p>
<p class="MsoNormal"> #</p>
<p class="MsoNormal"> $hostname
= rrd::cut($data['MACRO']['HOSTNAME']);</p>
<p class="MsoNormal"> $def[0] .=
rrd::def("var$key" , $data['DS'][0]['RRDFILE'], $data['DS'][0]['DS']
);</p>
<p class="MsoNormal"> $def[0] .=
rrd::line1("var$key", rrd::color($key), $hostname);</p>
<p class="MsoNormal"> $def[0] .=
rrd::gprint("var$key", array("LAST", "MAX"));</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">?></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Matthew<span style="font-size: 12pt; font-family: "Times New Roman","serif";"></span></p>
<p class="MsoNormal"><span style="font-size: 12pt; font-family: "Times New Roman","serif";"> </span></p>
</div>
</div>
<br>_______________________________________________<br>
rrd-users mailing list<br>
<a href="mailto:rrd-users@lists.oetiker.ch">rrd-users@lists.oetiker.ch</a><br>
<a href="https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users" target="_blank">https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users</a><br>
<br></blockquote></div><br>