Some time need to create custom template in pnp4nagios for some command which behave differently when execute on remote host as the appearance of graphs depends on the check command used. eg check_nrpe
Example:
define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
This would lead to a call of the check_nrpe.php template even when the monitored host would use a completely different plugin which is called via NRPE, eg
In service definition
define service{
use local-service,srv-pnp
host_name SomeHost
service_description Current Load
check_command check_nrpe!check_load
}
This will lead to call to check_nrpe command and it will use the default.php PNP template which may or may not give the graph as required.
Solution: Custom Template
1. Define new command in nagios/commands.cfg
define command{
command_name check_nrpe_load
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
2. Modify the service command for the host to use the new command
define service{
use local-service,srv-pnp
host_name SomeHost
service_description Current Load
check_command check_nrpe_load!check_load
}
Reload Nagios so that it start using the new check command.
At this point everything will be working just as before,
Pnp4nagios configuration
1. Define a check command /usr/local/pnp4nagios/etc/check_commands/check_nrpe_load.cfg (with the same name as the check command in above example)
Tip: Just copy the sample command definition /usr/local/pnp4nagios/etc/check_commands/check_nwstat.cfg-sample eg
cd /usr/local/pnp4nagios/etc/check_commands
sudo cp check_nwstat.cfg-sample check_nrpe_load.cfg
For more detail on custom command refer to http://docs.pnp4nagios.org/pnp-0.6/tpl_custom
2. Define a customer template for check_nrpe_load
In the above example if check_nrpe_load.cfg have
CUSTOM_TEMPLATE = 0,1 the it will results in → "check_nrpe_load_check_load.php"
Create a custom template in /usr/local/pnp4nagios/share/templates (pnp4nagios first look for template in this direcotry then fallback to other directories http://docs.pnp4nagios.org/pnp-0.6/tpl)
Note: Or you can just create a symbolic link to existing template that come with pnp4nagios installation eg ...
ln -s ../templates.dist/check_load.php check_nrpe_load_check_load.php
Here is the sample template for check_load on remote hosts that will plot graph of 1M and 15 minute graph for a host,
cd /usr/local/pnp4nagios/share/templates
sudo vi check_nrpe_load_check_load.php (template name should match with the custom command definition in our example check_nrpe_load_check_load.php)
<?php
$opt[1] = "--vertical-label Load -l0 -u 1 --title \"CPU Load for $hostname / $servicedesc\" ";
$def[1] = "DEF:var1=$rrdfile:$DS[1]:AVERAGE " ;
$def[1] .= "DEF:var2=$rrdfile:$DS[2]:AVERAGE " ;
$def[1] .= "DEF:var3=$rrdfile:$DS[3]:AVERAGE " ;
if ($WARN[1] != "") {
$def[1] .= "HRULE:$WARN[1]#FFFF00 ";
}
if ($CRIT[1] != "") {
$def[1] .= "HRULE:$CRIT[1]#FF0000 ";
}
$def[1] .= "AREA:var1#EACC00:\"Load average 1 min \" " ;
$def[1] .= "GPRINT:var1:LAST:\"%6.2lf last\" " ;
$def[1] .= "GPRINT:var1:AVERAGE:\"%6.2lf avg\" " ;
$def[1] .= "GPRINT:var1:MAX:\"%6.2lf max\\n\" ";
$def[1] .= "LINE:var3#FF0000:\"Load average 15 min \" " ;
$def[1] .= "GPRINT:var3:LAST:\"%6.2lf last\" " ;
$def[1] .= "GPRINT:var3:AVERAGE:\"%6.2lf avg\" " ;
$def[1] .= "GPRINT:var3:MAX:\"%6.2lf max\\n\" " ;
?>
nice post
ReplyDeleteNice post.. easy to follow !
ReplyDeleteDon't forget to put :
<?php at the beginning of the check_nrpe_load_check_load.php file or it won't work.
Thanks for the correction the missing starting php tag has been added.
ReplyDeletehttp://docs.pnp4nagios.org/pnp-0.4/tpl_custom
ReplyDeleteThanks for post! Very nice. Nothing superfluous
ReplyDeletehi,
ReplyDeletei would like to ask:
1) how can i consolidate multiple checks in one graph?
you see, we have a couple of custom scripts and we need to have that to be in one graph. can you help me with that?
thanks!
Anonymous,
ReplyDeleteLove to help but these days I am busy at some other task and not much time to play with Pnp4nagios. However you can ask your questions in the mailing list pnp4nagios-users@lists.sourceforge.net I am sure someone will help you out with your problem.
hi thanks for post.
ReplyDeleteI also need some help about a scritp that I write which checks cpu and memory how can I make graps with pnp4nagios of those scrits. If u can help me or If there ıs any document about it I will appreciate
Hi mine,
ReplyDeletePlease subscribe to pnp4nagios mailing list and for assistance.
Thanks
Nice article . Very helpful
ReplyDeleteThank you glad you like it.
DeleteJust what I was looking for! Thanks!
ReplyDeleteHi Askar,
ReplyDeleteHow to apply the Custom Template to Passive-Check service ?
Please give me advice ....
Hi Noel,
DeleteI am afraid I wouldn't be of much help its been long didn't worked on Pnp4nagios nor i have testing setup anymore. You can ask your question in PnPnagios mailing list pnp4nagios-users@lists.sourceforge.net I am sure good guys will help you out with your problem.
Cheers,