Custom drawing templates:
[Root @ RHEL5 ~] # Cd/usr/local/pnp4nagios/share/templates/
[Root @ RHEL5 templates] # vi check_cpu.php
<?php#-----The Color of The Three Primary Colors-----$colors = array( 'red' => '#FF0000', 'green' => '#00FF00', 'blue' => '#0000FF', 'yellow' => '#FFFF00', 'black' => '#000000', 'deepred' => '#330000', );#------------------Image Title------------------$opt[1] = "--title \"CPU_Load For $hostname / $servicedesc\" ";#-------------1 Minutes Average Load------------$def[1] = "DEF:var1=$RRDFILE[1]:$DS[1]:AVERAGE " ;$def[1] .= "HRULE:$WARN[1]#00FF00 ";$def[1] .= "HRULE:$CRIT[1]#FF0000 ";$def[1] .= "LINE1:var1#0000FF:\"1-Mins \" " ;$def[1] .= "GPRINT:var1:MIN:\"%3.4lg %s$UNIT[1] Min \\t\" ";$def[1] .= "GPRINT:var1:MAX:\"%3.4lg %s$UNIT[1] Max \\t\" ";$def[1] .= "GPRINT:var1:AVERAGE:\"%3.4lg %s$UNIT[1] Average \\n\" ";#-------------15 Minutes Average Load-----------$def[1] .= "DEF:var2=$RRDFILE[2]:$DS[2]:AVERAGE " ;$def[1] .= "LINE2:var2$colors[black]:\"15-Mins \" " ;$def[1] .= "GPRINT:var2:MIN:\"%3.4lg Min \\t\" ";$def[1] .= "GPRINT:var2:MAX:\"%3.4lg Max \\t\" ";$def[1] .= "GPRINT:var2:AVERAGE:\"%3.4lg Average \\n\" ";?>
[Root @ RHEL5 templates] # chown nagios: nagios *
Monitoring plugin:
[Root @ RHEL5 ~] # Tail-n 2/etc/nagios/resource. cfg
#Add by Kingcraft$USER5$=/usr/local/nagios/customexec
[Root @ RHEL5 ~] # Vi/usr/local/nagios/customexec/check_cpu.sh
#!/bin/sh#Author:zhai_kang,20131031WARN=$2CRIT=$4#1 minutes load,15 minutes loadLoad_One=`uptime | awk -F "[:]" '{print $NF}' | awk -F "[,]" '{print $1}'`Load_Fifteen=`uptime | awk -F "[:]" '{print $NF}' | awk -F "[,]" '{print $3}'`#to obtain Max valueMax=$Load_OneSIGN=`echo $Max $Load_Fifteen | awk '{if($1<$2)print 1;else print 0}'`if [[ $SIGN -ge 1 ]]then Max=$Load_Fifteenfi#get return dataSIGN_C=`echo $CRIT $Max | awk '{if($1<$2)print 1;else print 0}'`SIGN_W=`echo $WARN $Max | awk '{if($1<$2)print 1;else print 0}'`SIGN_O=`echo 0 $Max | awk '{if($1<$2)print 1;else print 0}'`if [[ $SIGN_C -eq 1 ]]then line=`echo "Critical : 1-Mins = $Load_One; 15-Mins = $Load_Fifteen"` RC=2elif [[ $SIGN_W -eq 1 ]]then line=`echo "Warning : 1-Mins = $Load_One; 15-Mins = $Load_Fifteen"` RC=1elif [[ $SIGN_O -eq 1 ]]then line=`echo "OK : 1-Mins = $Load_One; 15-Mins = $Load_Fifteen"` RC=0else line=`echo "Unknown"` RC=3fiecho $line \| CPU_Load="$Load_One;$WARN;$CRIT" CPU_Load="$Load_Fifteen"exit $RC
Define the monitoring command:
[Root @ RHEL5 ~] # Vi/etc/nagios/objects/commands. cfg
define command{ command_name check_cpu command_line $USER5$/check_cpu.sh -w $ARG1$ -c $ARG2$ }
Definition monitor file:
[Root @ RHEL5 ~] # Vi/etc/nagios/Linuxhosts/localhost. cfg
define host{ use linux-server,host-pnp host_name Monitor alias Monitor address 172.17.10.4 }define service{ use local-service,srv-pnp host_name Monitor service_description check_cpu check_command check_cpu!2!3 }
Define the time range:
[Root @ RHEL5 ~] # Vi/etc/pnp/config. php
# Define default views with title and start timerange in seconds# Modify by zhai_kang,20131031$views[] = array('title' => 'One Hour', 'start' => (60*60) );$views[] = array('title' => 'Five Hours', 'start' => (60*60*5) );$views[] = array('title' => 'One Week', 'start' => (60*60*25*7) );$views[] = array('title' => 'One Month', 'start' => (60*60*24*32) );
Restart:
[Root @ RHEL5 ~] # Service nagios restart
Verification:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131227/15495BX7-0.jpg "title =" Timerange "alt =" 17480020..jpg"/>
This article is from the "Kingcraft" blog, please be sure to keep this source http://kingcraft.blog.51cto.com/2776630/1317866