Principle: The monitoring end sends the instruction to be monitored by check_nrpe to the monitored end, the monitoring side performs the monitoring task on the local machine, and transmits the result of the execution back to the monitoring side.
How do I extend Nagios to enable custom monitoring?
Each valid Nagios check (Nagios checked) with a plug-in generates a number indicating the exit status. The possible statuses are:
- 0--all aspects are normal, check successfully completed.
- The resource is in a warning state. Some place is not very good.
- 2--resources are in a critical state. This could be due to a host outage or a service not running.
- 3--unknown state, this does not necessarily indicate that there is a problem, but that the check does not give a clear state.
The plugin can also output text messages. By default, the message is displayed in the Nagios Web interface and the Nagios Mail alert information. Although the message is not a hard requirement, you can usually find them in the available plugins because the message tells the user what went wrong without forcing the user to consult the documentation.
For example on the Internet, I can test the normal use of my own changes after the experiment:
Monitored side settings:
Vim/usr/lib64/nagios/plugins/check_file
#!/bin/Bashfilename=$1if[!-e $filename]; Then Echo "criticall status-file $filename doesn ' t exist"Exit2elif[!-R $filename]; Then Echo "WARNING status-file $filename is not readable"Exit1elif[!-f $filename]; Then Echo "UNKNOWN status-file $filename is not a file"Exit3Else if[ $1]; Then Echo "OK status-file $filename is ok"Exit0 fifi
View Code
Vim/etc/nagios/nrpe.cfg
Command[check_file]=/usr/lib64/nagios/plugins/check_file /tmp/jjtest
Monitoring side settings:
Vim/usr/local/nagios/etc/objects/command.cfg
define command{ command_name check_file command_line $USER 1$/check_nrpe-h $ hostaddress$-c check_file }
Vim/usr/local/nagios/etc/objects/service.cfg
Define Service{
Use Linux-service
HOST_NAME Myhost
Service_description Jjtest
check_interval 1 # detection interval, active detection of hosts every 5 minutes by default
retry_interval 1 # retry interval, default value 1 minutes
Check_commandCheck_file
}
templates.cfg template File Related parameters Description : (Of course, also includes the above Check_interval and Retry_interval)
Max_check_attempts #这一项用来定义在检测返回结果不是OK时, Nagios retries the number of test commands . Setting this value to 1 will cause Nagios to alarm once and without retrying
Check_period #这一项用一个time The name of the period key to define the time period during which active detection of this host is activated. Time period is a configuration item defined in another file, where we can refer to it by name.
Contact_groups #这是一个联系组列表. We use the name of the contact Group to refer to them. Multiple contact groups are separated by ",".
Notification_interval #这一项用来定义当一个服务仍然down或unreachable时, How often do we re-send a notification to the contact group, the notification interval, the default 2 hours .
Notification_period #这一项用一个time period definition to identify what time period to send notifications to the contact group. Here we refer to it using the name defined by time period.
Notification_options #这一项用来决定发送通知的时机. The options are: D = Send notification when there is a down state, u = Send notification when there is a unreachable state, r = Send notification when there is a service recoveries, F = Send notification when the host is started or down. If you give an n option, then never send a notification.
--------------------------------------------------------------------------------------------------------------- ----
Yum install nagios-plugins-* generate/usr/lib64/nagios/plugins/check_* script file
Yum Install Nrpe
Prevent the Tomcat process from being suspended
Under Tomcat's WebApps directory, create a new directory Jiankong (this directory is built casually), and then place an ASP file underneath it. Then modify the commands.cfg and add the
#tomcat1 Set
Define Command{
Command_name check_tomcat_8028
Command_line/usr/local/nagios/libexec/check_http-i $HOSTADDRESS $-P 8028-u/jiankong/test.jsp-e 200
}
If there are multiple ports, you can build multiple, only need to modify the port number, above this is 8028 port, and then add the service in Servers.cfg.
Nagios Custom Extensions