Using Nagios to monitor specified port numbers

Source: Internet
Author: User

Method One:

Experimental ideas:

the first step in commands.cfg the detection command that you want to use is defined in the file:

Vi/usr/local/nagios/etc/objects/commands.cfg

Define Command{

Command_name tcp60910 # command name

Command_line $USER 1$/check_tcp-h $HOSTADDRESS $-P 60910-t # command content, which is called to check_tcp This script -P is followed by the end Mouth. If you want to monitor a lot of ports, make a few more, and do a demonstration to get 2 . -T is the time-out, in seconds.        }

Define Command{

Command_name tcp60911

Command_line $USER 1$/check_nt-h $HOSTADDRESS $-P 60911-t # here if you don't use -t can also, the default is ten seconds, if your monitor is telecommunications, you are Monitoring end is Netcom, then you monitor the past will occasionally appear more than ten seconds, so this time can zoom point, but the maximum is a second.              }

Define the host group again.

The second step is to define the host for port monitoring and modify nagios.cfg file makes Nagios can identify:

#vi/usr/local/nagios/etc/objects/hosts.cfg # Note that this file itself is not self-bringing and can be straight

Connect VI Editor, don't forget to go to the nagios.cfg and declare it there .

The following is to declare its existence,vi/usr/local/nagios/etc/nagios.cfg

# You can specify individual object config files as shown below:

Cfg_file=/usr/local/nagios/etc/objects/hosts.cfg

Cfg_file=/usr/local/nagios/etc/objects/commands.cfg

Cfg_file=/usr/local/nagios/etc/objects/contacts.cfg

Cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg

Cfg_file=/usr/local/nagios/etc/objects/templates.cfg

The following is the file contents of Hosts.cfg.

Define Host{

Use Linux-server # here is the call template file is templates.cfg this inside the linux-server template, in fact, we monitor is Windo WS, but I tested the next template with Windows on the inexplicable error, you can use windows-server to try

HOST_NAME Ts1 # This is the definition of the ts1 name, which is used to call the following members .

Alias Ts1 # This is the text that will be displayed on the Site Monitor button.

Address XXX.XXX.XXX.XXX # This is the IP address of the corresponding ts1, which is the machine you want to monitor.


}


Define Host{

# This is the second one

Use Linux-server

HOST_NAME TS2

Alias Ts2

Address XXX.XXX.XXX.XXX

}

Define Hostgroup{

Hostgroup_name Ts-servers # host group name ts-servers the same wait to be monitored by the service call.

Alias Ts-servers # This same meaning as above, used to display the name on the Web page.

Members TS1,TS2 # Here is the call above the host_name content, with "," comma separate, I here on 2 , all added in.

}

OK, to the last step, call the host group name and command to monitor the service.

The third step defines the ports to be monitored by the host that requires port monitoring:

in # vi/usr/local/nagios/etc/objects/windows.cfg configuration

Define Service{

The Use Generic-service # call template is not exhausted. Can not call, but you have to put all the information directly in, what contact, notify the various assorted fields to fill. Get a template directly anyway, most of them are default, such as 24x7 monitoring.

Hostgroup_name Ts-servers # This is called the define HostGroup in Hosts.cfg . hostgroup_name"

Normal_check_interval 1 # This is the normal detection interval time, that is, the detection of 1 ports after the normal time of the next detection. The default is 1 minutes, and in nagios.cfg there's a

Interval_length=60 This refers to Nagios 's time unit, which defaults to a second, so here's 1 is 1 minutes.

Retry_check_interval 1 # This is abnormal detection interval time, that is, detect abnormal detection of the next time.

Service_description port60910 # This is a description, also appears on the Web page

check_command tcp60910 # This is the command that is called, the command that was defined at the beginning. Note that the tcp60910 behind this Check_command is to be followed by the command.cfg file as defined in the The name of the Command_name is the same.

}

The following is the monitoring of the second port, meaning is not exhausted.

Define Service{

Use Generic-service hostgroup_name ts-servers normal_chec K_interval 1 Retry_check_interval 1

Service_description port60911 Check_command tcp60911}

finally reboot Nagios, if reboot fails, please #/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg directly to view An error message for the Nagios configuration file.

I above that can not use windows-server template is so detected, pit Dad, that file clearly have Windows template, is not used, had to use linux-server. hope Yimeimei solve it.


Method Two:

The second method is to change a few places when you define the command.

Define Command{

Command_name tcp60910 # command name command_line $USER 1$/check_tcp-h

$HOSTADDRESS $-P $ARG 1$-T $ARG 2$ # "$ARG 1$" This is the meaning of the variable, that is, you want to lose what you lose, but must lose the corresponding meaning, and so on the following will be explained.

}

The intermediate host group and host are still the same, and the last service invocation command is changed

Define Service{

Use Generic-service hostgroup_name ts-servers normal_chec K_interval 1 Retry_check_interval 1

Service_description port60911

The first field is a fill IP , but because $HOSTADDRESS $ is defined in the macro. Is the ultimate host_name. Method 2 I have not tried, online said can directly ignore write the second field. People do not

Try it. The port and delay time are filled in directly here.


check_command tcp60911!60910!60 # Originally here is no parameter, the direct invocation of the command name, mainly because the original definition of the parameters, and now to write their own. ! number is a delimiter }

In fact, I think the method of two flexible points. Since I am using Centreon now, I havenot configured the Nagios file directly. In fact, the final effect is the same.

and monitoring multiple lines . HTTP Page method, the opportunity will be updated well.

if you want to define a machine, then you just have to define the Define host and add it as Ts1 ts2 in the define HostGroup .

If you both monitor windows and monitor Linux, the types of monitoring are different, so the principle is the same. Just add a good field and parameters to the file.














This article from "Anna--linux's Home" blog, declined reprint!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.