How to send ping from zabbix-agent

Not supported by default

I would like to send a ping from the monitored host

Background:

I built a Linux-based VPN router strongSwan, but when I set up a VPN between routers with ipsec, I want to monitor ping from strongSwan to monitor communication to the address when NAT is applied on the remote router side.

simple check – icmpping and agent.ping

As you can see from the simple check, it is a monitoring that does not involve zabbix-agent.
The ping source will be the ZABBIX server and will send the ping.

If you set only icmpping as the key when setting the item, it will be monitored for the host that set the item.

If you set it like icmpping[1.1.1.1], it will monitor ping from ZABBIX server to 1.1.1.1, and the result will be displayed in the latest data of the host where the item is set.

Of course, the communication destination of the VPN cannot be seen from the ZABBIX server, so it cannot be pinged directly.

agent.ping is a way to monitor the presence or absence of a response from zabbix-agent without using ICMP.

Use UserParameter

Check ping behavior

ping -c 1 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=55 time=3.62 ms
--- 8.8.8.8 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 3.629/3.629/3.629/0.000 ms

If 1 is specified in the c option, ping will be sent only once.

ping -c 1 -w 1 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=116 time=3.17 ms
--- 8.8.8.8 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 3.170/3.170/3.170/0.000 ms

Set the timeout to 1 second with the w option.

ping -c 1 -w 1 8.8.8.8 > /dev/null 2>&1

Redirect standard output and errors to /dev/null and throw them away. (no output)

ping -c 1 -w 1 8.8.8.8 > /dev/null 2>&1 ; echo $?
.0

Connect to the next command with a semicolon and output the return value of ping with echo $?. Returns 0 for ping response, 2 for no response.

The dot before the 0 is actually not printed. The dot is inserted because it cannot be displayed if it is only 0 due to the problem of the plug-in.

Set to UserParameter

vi /etc/zabbix/zabbix_agentd.conf
UserParameter=remote.ping[*],/usr/bin/ping -c 1 -w 1 $1 > /dev/null 2>&1 ; echo $?

Set it in zabbix_agentd.conf of the host you want to ping from, and then restart the agent.

Check with zabbix_get

sudo zabbix_get -s 127.0.0.1 -k remote.ping[8.8.8.8]
.0

made new UserParameter named remote.ping and test it from monitored host.
sample as above, using userparameter “remote.ping” and test ping to 8.8.8.8 from monitored host.

result is 0. it mean ping reachable.

Add item to host

Name:ping test from remote
Type:Zabbix agent
Key:remote.ping[8.8.8.8]
Type of information:Numeric(unsigned)

test for ping to 8.8.8.8

Confirm with tcpdump

tcpdump -nvA -i enp0s7 dst host 8.8.8.8
dropped privs to tcpdump
tcpdump: listening on enp0s7, link-type EN10MB (Ethernet), capture size 262144 bytes
13:11:51.378848 IP (tos 0x0, ttl 64, id 9884, offset 0, flags [DF], proto ICMP (1), length 84)
192.168.64.6 > 8.8.8.8: ICMP echo request, id 11, seq 1, length 64
E..T&.@.@..O..@………….g8.d………………………. !”#$%&'()*+,-./01234567
13:11:51.797126 IP (tos 0x0, ttl 64, id 10299, offset 0, flags [DF], proto ICMP (1), length 84)
192.168.64.6 > 8.8.8.8: ICMP echo request, id 12, seq 1, length 64
E..T(;@.@…..@…….~[….g8.d….E(…………………. !”#$%&'()*+,-./01234567

Certainly, you can see ping from the monitoring host to 8.8.8.8.

Set for value of mapping

set for value 0 as up. and value 1 as down.

set value mapping to item.

Confirm Data

You can see result is as Up (0)

Set trigger

set for if value will become 1, it will be trigger.

test for trigger

change ping target to unreachable destination for test.
it will display as ping down on Dashboard.

Summary

I think there is a demand for ping monitoring from monitoring to another target.
It is strange why it is not implemented by default.
But you can easily implement it using UserParameter.

This time, we have actually monitored Strongswan with LLD (low level discovery) and automatically add the IPsec communication destination to ping monitoring.

Even if the connection destination of the router VPN increases, it will automatically add to the ping monitoring.

Let’s enhance the monitoring.

TwitterFacebookLinkedInHatenaPocketCopy Link