selected period need to show in performance graph

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
zaji_nms
Posts: 616
Joined: Tue Oct 16, 2012 12:28 am

Re: selected period need to show in performance graph

Post by zaji_nms »

thanks for your efforts

so only solution is feature request, to add PERIOD via TEMPLATE

same time, please do not forget to add DISPLAY_NAME via TEMPLATE

both will we additional feature to add at below X-Axis of the graph

regards
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: selected period need to show in performance graph

Post by tgriep »

FYI, we did find a solution to print out the last time the rrd file was updated. Put the following line at the bottom of the template and it will print the date / time to the graph..

Code: Select all

$def[1] .= "COMMENT:'".str_replace(':', '\:', date("Y-m-d H:i:s", "$NAGIOS_TIMET"))."'" ;
I will put in a feature request for the rest of what you want to display in the graphs.
Be sure to check out our Knowledgebase for helpful articles and solutions!
zaji_nms
Posts: 616
Joined: Tue Oct 16, 2012 12:28 am

Re: selected period need to show in performance graph

Post by zaji_nms »

great its done

$def[1] .= "COMMENT:Printed\ on\ '".str_replace(':', '\:', date("D d-M-Y H:i", "$NAGIOS_TIMET"))." (GMT+n)"."'" ;

upon your this solution, thinking may be there is a way to call external PHP code from this template (check_xi_service_mrtgtraf.php)
will pass the $hostname & $servicedesc from this Template to external PHP function and will return Display_Name
we will write that small external PHP code / function, sure with your some guideline/hint


Regards
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: selected period need to show in performance graph

Post by tgriep »

There is not a direct way to get the display_name from an external application so something would have to be written to get the name.

If you do an API call to get the servicestatus for a host, it will return a list of the services for that host and the display_name will be included as json.
You could use that to get the data into the php script so you can display it in the graph.
curl -XGET "https://xxx.xxx.xxx.xxx/nagiosxi/api/v1 ... t&pretty=1" -k
Be sure to check out our Knowledgebase for helpful articles and solutions!
zaji_nms
Posts: 616
Joined: Tue Oct 16, 2012 12:28 am

Re: selected period need to show in performance graph

Post by zaji_nms »

dear tgriep
in /usr/local/nagios/share/pnp/templates
I have copied below files

hostservices.txt (left side host+service , one space , and right side is displayname)
router1giga1 connected_to_london
router1pos2 connected_to_paris
jnpr3xe-0/0/1 uplink-to-frakfurt

$ php ./fetchdispname.php jnpr3xe-0/0/1 <<<<<<<<<<<<<<<< has been written to fetch the DisplayName
uplink-to-frakfurt <<<<<<<<<<<<< tested working fine

now how to add this PHP code/function (fetchdispname.php) in MRTG template or any other place to show/print DisplayName in rrd / performance graph fetched by PHP Code (fetchdispname.php)

regards
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: selected period need to show in performance graph

Post by tgriep »

If the fetchdispname.php script in in the /usr/local/nagios/share/pnp/templates folder

You would add this to the mrtg template to get the display name. If you have any arguments needed for your script, you will have to pass them to it.

Code: Select all

$displayname = "php -q /usr/local/nagios/share/pnp/templates/fetchdispname.php";
As long as the permissions are good and the name of the macro it the same, it should work.
Be sure to check out our Knowledgebase for helpful articles and solutions!
zaji_nms
Posts: 616
Joined: Tue Oct 16, 2012 12:28 am

Re: selected period need to show in performance graph

Post by zaji_nms »

dear tgriep

$opt[1] = "--vertical-label score -l0 --title \"Score for $hostname / $servicedesc\" ";
$displayname = "php -q /usr/local/nagios/share/pnp/templates/fetchdispname.php";
#
$def[1] .= "COMMENT:\" DispName $displayname \" ";
$def[1] .= "COMMENT:mAGIc'" .$displayname. "'" ; <<<<<<<<<<< tried this way but no success

it just diplaying as below

DispName php -q /usr/local/nagios/share/pnp/templates/fetchdispname.php

(means it just assigning right side string "php -q /usr....." to $displayname) not executing the code

to make the simple, I just change the code to three lines only,

more fetchdispname.php
<?php
return "MyMagicDISPname";
?>


tried to change the different group but no success

chown nagios:nagios fetchdispname.php
chown root:nagios fetchdispname.php
chown apache:nagios fetchdispname.php

chmod 755 fetchdispname.php

Looks your some more last efforts will fix this issue

regards
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: selected period need to show in performance graph

Post by tgriep »

I forgot to remove the double quotes, from the command.

Try this

Code: Select all

$displayname = php -q /usr/local/nagios/share/pnp/templates/fetchdispname.php;
or this

Code: Select all

$displayname = /usr/local/nagios/share/pnp/templates/fetchdispname.php;
This line should look like this

Code: Select all

$opt[1] = "--vertical-label score -l0 --title \"Score for $hostname / $servicedesc / $displayname\" ";
Also, make sure you set the $displayname variable before trying to display it.
Be sure to check out our Knowledgebase for helpful articles and solutions!
zaji_nms
Posts: 616
Joined: Tue Oct 16, 2012 12:28 am

Re: selected period need to show in performance graph

Post by zaji_nms »

dear tgriep

no, not giving the desired result

$opt[1] = "--vertical-label score -l0 --title \"Score for $hostname / $servicedesc\" ";
$displayname = php -q /usr/local/nagios/share/pnp/templates/fetchdispname.php;
$def[1] .= "COMMENT:\" DispName $displayname \" ";

displaying >>>>> 0php <<<<<< this is the result of $displayname

two possibilities
1) may be the code not running as should
or
2) the PHP code (fetchdispname.php) is not correct

if No.1 is wrong, can you please test in your Leb
if No.2 is wrong, can you please write few line code with static output as I mentioned earlier to make sure code is correct (as below similar).

more fetchdispname.php
<?php
return "MyMagicDISPname";
?>

regards
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: selected period need to show in performance graph

Post by tgriep »

I added / edited these 2 lines to the top of the Graph Template

Code: Select all

$displayname = shell_exec( 'php /usr/local/nagios/share/pnp/templates/fetchdispname.php' );
$opt[1] = " --vertical-label \"Traffic $UNIT[1]\" -E --title \"Interface Traffic for $hostname / $servicedesc / $displayname\" ";
I had to change the fetchdispname.php script to the following

Code: Select all

<?php
print( "MyMagicDISPname");
?>

That printed MyMagicDISPname to the top line of graph.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked