[comment]: # attributes: notoc

[comment]: # translation:outdated

[comment]: # ({be4ab03d-be4ab03d})

# 5 简单检查

[comment]: # ({/be4ab03d-be4ab03d})

[comment]: # ({05b34fc5-76023448})
### 概述

简单检查通常用于检查远程未安装Zabbix agent的服务。

请注意，简单检查不需要Zabbix agent，由Zabbix server和Zabbix proxy来负责处理（例如创建外部连接等）。

简单检查使用示例：

    net.tcp.service[ftp,,155]
    net.tcp.service[http]
    net.tcp.service.perf[http,,8080]
    net.udp.service.perf[ntp]

::: noteclassic
简单检查项配置中的*用户名*和*密码*字段(不超过255个字符)用于VMware监控项;否则忽略。
:::

[comment]: # ({/05b34fc5-76023448})

[comment]: # ({9aaf2d21-f59a5ccc})
### 支持的检查

列出的监控项键没有可选参数和附加信息。单击监控项键查看完整的详细信息。

参见[VMware监控项键](/manual/vm_monitoring/vmware_keys).

|监控项键|说明|
|--|--------|
|[icmpping](#icmpping)|通过ICMP ping 检测主机的可访问性。|
|[icmppingloss](#icmppingloss)|丢包的百分比。|
|[icmppingsec](#icmppingsec)|ICMP ping 响应时间。|
|[net.tcp.service](#nettcpservice)|检查服务是否在运行并且接受 TCP 连接。|
|[net.tcp.service.perf](#nettcpserviceperf)|检测 TCP 服务性能。|
|[net.udp.service](#netudpservice)|检测服务是否正在运行并响应UDP请求。|
|[net.udp.service.perf](#netudpserviceperf)|检测 UDP 服务的性能。|

[comment]: # ({/9aaf2d21-f59a5ccc})

[comment]: # ({b1bc108a-23d7246f})

### 监控键详细信息

没有尖括号的参数是必需的。标有尖括号**<** **>**的参数是可选的。

[comment]: # ({/b1bc108a-23d7246f})

[comment]: # ({52d234e4-7d8dff2e})

##### icmpping\[<target>,<packets>,<interval>,<size>,<timeout>,<options>\] {#icmpping}

<br>
ICMP ping 的主机可访问性。<br>
返回值：*0* - ICMP ping 失败；*1* - ICMP ping 成功。

参数:

-   **target** - 主机 IP 或 DNS 名称;
-   **packets** - 数据包数量;
-   **interval** - 连续数据包之间的时间（以毫秒为单位）;
-   **size** - 数据包大小（以字节为单位）;
-   **timeout** - 超时（以毫秒为单位）;
-   **options** - 用于允许重定向：如果为空（默认值），则重定向响应被视为目标主机关闭；如果设置为 *allow_redirect*，则重定向响应被视为目标主机启动。

另请参阅 [默认值](#default-values) 表。

示例：

    icmpping[,4] #If at least one packet of the four is returned, the item will return 1.

[comment]: # ({/52d234e4-7d8dff2e})

[comment]: # ({1976ee61-6cd0f1b1})

##### icmppingloss\[<target>,<packets>,<interval>,<size>,<timeout>,<options>\] {#icmppingloss}

<br>
丢失数据包的百分比。<br>
返回值：*浮点数*。

参数：

- **target** - 主机 IP 或 DNS 名称；
- **packets** - 数据包数量；
- **interval** - 连续数据包之间的时间（以毫秒为单位）；
- **size** - 数据包大小（以字节为单位）；
- **timeout** - 超时（以毫秒为单位）；
- **options** - 用于允许重定向：如果为空（默认值），则重定向响应被视为目标主机关闭；如果设置为 *allow_redirect*，则重定向响应被视为目标主机启动。

另请参阅 [默认值](#default-values) 表。

[comment]: # ({/1976ee61-6cd0f1b1})

[comment]: # ({new-a7b509ca})

##### icmppingretry\[<target>,<retries>,<backoff>,<size>,<timeout>,<options>\] {#icmppingretry}

<br>
The host accessibility by ICMP ping with retries.<br>
Return value: *0* - ICMP ping fails; *1* - ICMP ping successful.

Parameters:

-   **target** - the host IP or DNS name;
-   **retries** - the number of times an attempt at pinging a target will be made, not including the first try (0 or greater; default 1);
-   **backoff** - the number by which the wait time is multiplied on each successive request (1.0-5.0 range; default 1.0);
-   **size** - the packet size in bytes;
-   **timeout** - the timeout in milliseconds;
-   **options** - used for allowing redirect: if empty (default value), redirected responses are treated as target host down; if set to *allow_redirect*, redirected responses are treated as target host up.

See also the table of [default values](#default-values).

[comment]: # ({/new-a7b509ca})

[comment]: # ({5c6701a7-b5636838})

##### icmppingsec\[<target>,<packets>,<interval>,<size>,<timeout>,<mode>,<options>\] {#icmppingsec}

<br>
ICMP ping 响应时间（以秒为单位）。<br>
返回值：*Float*。

参数：

- **target** - 主机 IP 或 DNS 名称；
- **packets** - 数据包数量；
- **interval** - 连续数据包之间的时间（以毫秒为单位）；
- **size** - 数据包大小（以字节为单位）；
- **timeout** - 超时（以毫秒为单位）；
- **mode** - 可能的值：*min*、*max* 或 *avg*（默认）；
- **options** - 用于允许重定向：如果为空（默认值），则重定向响应将被视为目标主机已关闭；如果设置为 *allow_redirect*，则重定向响应将被视为目标主机已启动。

注释：

- 丢失或超时的数据包不用于计算；
- 如果主机不可用（已达到超时），则该监控项将返回 0；
- 如果返回值小于 0.0001 秒，则该值将设置为 0.0001 秒；
- 另请参阅 [默认值](#default-values) 表。

[comment]: # ({/5c6701a7-b5636838})

[comment]: # ({3a1d49d8-b0a71170})

##### net.tcp.service[service,<ip>,<port>] {#nettcpservice}

<br>
检查服务是否正在运行并接受 TCP 连接。<br> 
返回值：*0* - 服务已关闭；*1* - 服务正在运行。

参数：

- **service** - 可能的值：*ssh*、*ldap*、*smtp*、*ftp*、*http*、*pop*、*nntp*、*imap*、*tcp*、*https*、*telnet*（参见[详细信息](/manual/appendix/items/service_check_details)）；
- **ip** - IP 地址或 DNS 名称（默认情况下使用主机 IP/DNS）；
- **port** - 端口号（默认情况下使用标准服务端口号）。

注释：

- 请注意，对于 *tcp* 服务，指示端口是强制性的； 
- 这些检查可能会导致系统守护进程日志文件中出现其他消息（通常会记录 SMTP 和 SSH 会话）； 
- 目前不支持检查加密协议（如端口 993 上的 IMAP 或端口 995 上的 POP）。作为解决方法，请使用 `net.tcp.service[tcp,<ip>,port]` 进行此类检查。

示例：

    net.tcp.service[ftp,,45] #此监控项可用于测试 TCP 端口 45 上 FTP 服务器的可用性。

[comment]: # ({/3a1d49d8-b0a71170})

[comment]: # ({39da67f1-946385b4})

##### net.tcp.service.perf[service,<ip>,<port>] {#nettcpserviceperf}

<br>
检查 TCP 服务的性能。<br> 
返回值：*Float*：*0.000000* - 服务已关闭；*seconds* - 连接到服务所花费的秒数。

参数：

- **service** - 可能的值：*ssh*、*ldap*、*smtp*、*ftp*、*http*、*pop*、*nntp*、*imap*、*tcp*、*https*、*telnet*（参见[详细信息](/manual/appendix/items/service_check_details)）；
- **ip** - IP 地址或 DNS 名称（默认情况下使用主机 IP/DNS）； 
- **port** - 端口号（默认情况下使用标准服务端口号）。


注释：

 - 请注意，使用 *tcp* 服务时必须指定端口；
- 目前不支持检查加密协议（如端口 993 上的 IMAP 或端口 995 上的 POP）。作为解决方法，请使用 `net.tcp.service[tcp,<ip>,port]` 进行此类检查。

示例：

    net.tcp.service.perf[ssh] #此监控项可用于测试 SSH 服务器的初始响应速度。

[comment]: # ({/39da67f1-946385b4})

[comment]: # ({5cba2094-2859223a})

##### net.udp.service[service,<ip>,<port>] {#netudpservice}

<br>
检查服务是否正在运行并响应 UDP 请求。<br> 
返回值：*0* - 服务已关闭；*1* - 服务正在运行。

参数： 
- **service** - 可能的值：*ntp*（参见 [details](/manual/appendix/items/service_check_details)）；
- **ip** - IP 地址或 DNS 名称（默认情况下使用主机 IP/DNS）； 
- **port** - 端口号（默认情况下使用标准服务端口号）。

示例：

    net.udp.service[ntp,,45] #此监控项可用于测试 UDP 端口 45 上的 NTP 服务的可用性。

[comment]: # ({/5cba2094-2859223a})

[comment]: # ({bae0ccf0-9cf5922c})

##### net.udp.service.perf[service,<ip>,<port>] {#netudpserviceperf}

<br>
检查 UDP 服务的性能。<br>
返回值：*Float*：*0.000000* - 服务已关闭；*seconds* - 等待服务响应所花费的秒数。

Parameters:

- **service** - 可能的值：*ntp*（参见 [details](/manual/appendix/items/service_check_details)）；
- **ip** - IP 地址或 DNS 名称（默认情况下使用主机 IP/DNS）；
- **port** - 端口号（默认情况下使用标准服务端口号）。

示例：

    net.udp.service.perf[ntp] #此监控项可用于测试 NTP 服务的响应时间。

[comment]: # ({/bae0ccf0-9cf5922c})

[comment]: # ({621c13d4-85612a2b})
  
::: noteimportant
对于 LDAP 简单检查中的 SourceIP 支持（例如 `net.tcp.service[ldap]`），需要 OpenLDAP 版本 2.6.1 或更高版本。
:::

[comment]: # ({/621c13d4-85612a2b})

[comment]: # ({05fdbf12-92a6c4ae})
#####超时处理

Zabbix 不会处理时间超过 [item configuration](/manual/config/items/item#configuration) 表单中定义的 *Timeout* 秒的简单检查。
对于 [VMware items](/manual/vm_monitoring/vmware_keys) 和 [icmpping*](#icmp-pings) 监控项， Zabbix 不会处理时间超过 Zabbix [server](/manual/appendix/config/zabbix_server#timeout) 或 [proxy](/manual/appendix/config/zabbix_proxy#timeout) 配置文件中定义的 `Timeout` 秒的简单检查。

[comment]: # ({/05fdbf12-92a6c4ae})

[comment]: # ({30611a67-b08a4508})
#### ICMP pings

Zabbix 使用外部程序 **fping** 来处理 ICMP pings。

Fping不包含在Zabbix的发行版中，您需要另外安装。 如果程序未安装、程序权限错误或者程序路径与配置文件中('FpingLocation' 参数)定义的不匹配，则不会处理ICMP ping (**icmpping**, **icmppingloss**, **icmppingsec**)。

另请参考: [已知问题](/manual/installation/known_issues#simple_checks)

**fping** 必须可以被 Zabbix 守护进程以 root 身份执行，需要设置 setuid 权限。为设置正确的权限，请以 **root** 身份来执行这些命令:

    shell> chown root:zabbix /usr/sbin/fping
    shell> chmod 4710 /usr/sbin/fping

执行以上两句命令，然后检查**fping**的权限。在某些情况下，可以通过执行chmod命令来重置所有权。

还要检查一下，如果用户zabbix属于zabbix组，则运行:

    shell> groups zabbix

如果没有添加成功，通过如下命令解决:

    shell> usermod -a -G zabbix zabbix

ICMP检测参数的默认值、限制和以及数值的描述：

|参数|单位|描述|Fping 的参数|Fping 默认设置|<| Zabbix <br>允许的限制|<|
|---------|----|-----------|------------|---------------|-|---------------------------|-|
|||||**fping**|**Zabbix**|**min**|**max**|
|packets|计数|发送到目标的请求报文数|-C||3|1|10000|
|interval|毫秒|连续数据包之间的间隔时间|-p|1000||20|不限制|
|size|byte|用字节描述的包大小<br>x86 架构是 56 byte, x86_64架构是68 byte|-b|56 or 68||24|65507|
|timeout|毫秒|**fping v3.x** - 上次发送数据包后等待超时时间，影响 *-C* 参数<br> **fping v4.x** - 每个包的单独超时时间|-t|**fping v3.x** - 500<br>**fping v4.x** - 继承 *-p* 参数的值，但是不能超过 2000||50|不限制|

此外，Zabbix 使用 fping 参数 *-i interval ms* (不要和上边表格中的监控项参数 *interval* 混淆，它对应 fping 的 *-p* 参数)  和  *-S source IP address* (或者旧版本的 *-I* i)。这些参数通过使用不同的参数组合运行自动检测。 Zabbix尝试检测fping允许对*-i*参数一起使用的最小值(以毫秒为单位)，尝试 3个值: 0, 1 和 10。第一个成功的值将用于后续的ICMP检查. 这个过程是由每个 [ICMP pinger](/manual/concepts/server#server_process_types) 进程单独完成的。

从Zabbix 5.0.4版本开始，fping 自动检测的参数每小时都会失效，并且在下一次尝试执行ICMP检查时再次加载。设置 DebugLevel>=4 可以在服务器或代理日志文件中查看该进程的详细信息。

::: notewarning
警告: 根据平台和版本的不同，fping的默认值也会有所不同 - 如有疑问, 请参考fping文档。
:::

Zabbix将三个 *icmpping\** 键值中任何一个IP地址写入一个临时文件中，然后传递给 **fping**。如果监控项有不同的键值参数，则只有具有相同键值参数的监控项IP才会被写入相同的单个文件。\
所有写入到单个文件的IP地址将被fping并行检查，因此Zabbix icmp pinger进程将花费固定的时间来处理监控项，而不管文件中的IP地址数量。

[comment]: # ({/30611a67-b08a4508})

[comment]: # ({beb7601c-e3dd9826})

##### 安装

fping 不包含在 Zabbix 中，需要单独安装：

- 各种基于 Unix 的平台在其默认存储库中都有 fping 包，但未预安装。在这种情况下，您可以使用包管理器安装 fping。

- Zabbix 为 RHEL 提供 [fping 包](http://repo.zabbix.com/non-supported/rhel/)。请注意，这些包不提供官方支持。

- fping 也可以从源代码编译](https://github.com/schweikert/fping/blob/develop/README.md#installation)。

[comment]: # ({/beb7601c-e3dd9826})

[comment]: # ({b2c27900-9ced6345})
##### 配置

在 Zabbix 服务器/代理配置文件的 *[FpingLocation](/manual/appendix/config/zabbix_server#fpinglocation)* 参数中指定 fping 位置
（或使用 IPv6 地址的 *[Fping6Location](/manual/appendix/config/zabbix_server#fping6location)* 参数）。

fping 应由运行 Zabbix 服务器/代理的用户执行，并且该用户应具有足够的权限。

另请参阅：[已知问题](/manual/installation/known_issues#simple_checks)，以使用低于 3.10 的 fping 版本处理简单检查。

[comment]: # ({/b2c27900-9ced6345})

[comment]: # ({b0275ef4-3c21487d})

##### 默认值

ICMP 检查参数的默认值、限制和值说明：

|参数|单位|说明|Fping 的标志|默认值由|<|Zabbix 允许的限制<br>设置|<|
|--|--|--------|-|--|--|--|--|
|||||**fping**|**Zabbix**|**min**|**max**|
|packets|number|发送到目标的请求数据包数量|-C||3|1|10000|
|interval|milliseconds|等待发送到单个目标的连续数据包之间的时间|-p|1000||20|unlimited|
|size|bytes|数据包大小（以字节为单位）<br>x86 上为 56 字节，x86_64 上为 68 字节|-b|56 或 68||24|65507|
|timeout|毫秒|**fping v3.x** - 发送最后一个数据包后等待的超时时间，受 *-C* 标志影响<br> **fping v4.x** - 每个数据包的单独超时|-t|**fping v3.x** - 500<br>**fping v4.x** 及更新版本 - 从 *-p* 标志继承，但不超过 2000||50|无限制|

默认值可能因平台和版本而略有不同。

此外，Zabbix 使用 fping 选项 *-i interval ms*（不要与上表中提到的监控项参数 *interval* 混淆，
它对应于 fping 选项 *-p*）和 *-S source IP address*（或旧版 fping 中的 *-I*）。
这些选项可通过使用不同的选项组合运行检查来自动检测。
Zabbix 尝试通过尝试 3 个值（0、1 和 10）来检测 fping 允许使用 *-i* 的最小毫秒值。
第一个成功的值将用于后续的 ICMP 检查。
此过程由每个 [ICMP pinger](/manual/concepts/server#server_process_types_and_threads) 进程单独完成。

自动检测到的 fping 选项每小时失效一次，并在下次尝试执行 ICMP 检查时再次检测。
设置 [DebugLevel](/manual/appendix/config/zabbix_server#debuglevel)>=4 以便在服务器或代理日志文件中查看此过程的详细信息。

Zabbix 将要由三个 *icmpping\** 键中的任何一个检查的 IP 地址写入临时文件，然后将其传递给 fping。如果监控项具有不同的关键参数，则只有具有相同关键参数的监控项才会写入单个文件。写入单个文件的所有 IP 地址将由 fping 并行检查，因此， Zabbix ICMP pinger 进程将花费固定的时间，而不管文件中的 IP 地址数量。

[comment]: # ({/b0275ef4-3c21487d})
