Zabbix agent windows ping remote host

Описание

Есть простая, но достаточно популярна задача, а именно пинг с удаленного хоста, другой удаленный хост. В интернетах в основном предлагают использовать доп устанавливаемую fping, мы же пойдем другим путем, напишем свой скрипт, который будет не только проверять отвечает/не отвечает удаленный хост, но логировать время. Скрипт написан для локальной сети, где отсутствует потеря пакетов, в случае потерь или отправки количества больше одного запроса на пинг, его придется модифицировать

На вход в качестве параметра будем принимать имя сервера или ip адрес который нам нужно пинговать, после чего отправляем  один запрос (1) и ждем две секунды оставляем только значения ответа в ms, в случае отсутствия ответа — выставляем 9999.  Форматирование — съехало, адаптируйте под себя

 
#!/bin/bash
pinghost=$1

ping_results=$(ping $pinghost -c 1 -W 2| awk -F= ‘{print $4}’ | tr -d ‘ ms’ | sed ‘/^$/d’ 2>&1);

if [ -z «$ping_results» ];then
ping_results=»9999″
echo $ping_results
else
echo $ping_results
fi

Сам скрипт мы будем использовать на следующем шаге

Настройки на стороне удаленного сервера с zabbix-agent

Создадим папку со скриптами, выдадим на нее права и сделаем скрипт исполняемым

mkdir /etc/zabbix/scripts/
chown root:zabbix -R /etc/zabbix/scripts/
chmod 750 /etc/zabbix/scripts/
nano /etc/zabbix/scripts/ping-v1.sh
chmod +x /etc/zabbix/scripts/ping-v1.sh

Если у вас включен selinux

semanage permissive -a zabbix_agent_t

теперь создадим файл с настройками для агента, где $1 — означает, что мы будем передавать нашему скрипту параметры

nano /etc/zabbix/zabbix_agentd.d/ping-remote-host.conf

#вставляем внутрь

UserParameter=ping.remotehost[*],/etc/zabbix/scripts/ping-v1.sh $1

Ну и рестартуем zabbix -agent

systemctl restart zabbix-agent

Настройка на zabbix-server

Создаем например новый шаблон, example-template, в нем хорошим тоном будет сразу сделать MACRO, например

screen-01

Далее идем в Items и создаем свой items для мониторинга, ключевыми параметрами тут являються, имя ключа, которое мы сделали в агенте, а так же MACRO, которое мы сделали в template (имя сервера который надо пинговать).

Так же выбираем тип информации Numeric (float)

screen-02

Собствено все, можно идти смотреть в lates data, ну либо с сервера заббикса выполнить

zabbix_get -s our-server -k ping.remotehost[our-remote-host]

Вот так мы достаточно простым скриптом, пингуем с удаленного сервера другой удаленный сервер, без установки доп утили

Опубликовано

Вопрос такой
Нужно киать пинг с машины на Windows через zabbix-agent до удаленного хоста, результат отправлять на сервер Zabbix (Centos6).
На сервере лежит система, за которой сидят пользователи, отвал пользователей нужно мониторить.
Пытаюсь реализовать через пользовательские параметры:

UserParameter=ping[*],echo $1

Элемент данных в интерфейсе:
5c407898f0776834780644.jpeg
Тригер в интерфейсе:
5c4078afa6388414109624.jpeg


  • Вопрос задан

  • 9194 просмотра

Пригласить эксперта

Выставляйте тип: Simple check

Отредактировал:

Key: icmpping или icmppingsec (я предпочитаю второй — иногда пинги вроде есть, но их значение зашкаливает — это тоже плохо)

Было настроено без изменений в UserParameter. Помогли «простые проверки» в виде icmpping[].
Элемент данных:
5c4182d654f21728560802.jpegТриггер:
5c4182ea29289081696942.jpeg
Функция count(120,0) считает количество нулевых значений итема за 120 секунд.
Соответственно, если за 120 секунд все 4 проверки возвратили 1, то триггер срабатывает.

Вроде работает. Возможно где то ошибся.

Простая проверка icmpping это всё же простая проверка, т.е. проверка с zabbix сервера. Если можете обойтись не пингом, а постучать по порту, до сам zabbix рекомендует

net.tcp.service.perf[сервис,,<порт>]
Проверка производительности TCP сервиса.
Ответ
0 — сервис недоступен
секунды — количество секунд потраченное на подключение к сервису
поддерживается Zabbix с версии 2.0

источник https://www.zabbix.com/documentation/current/ru/ma…


  • Показать ещё
    Загружается…

09 окт. 2023, в 12:05

2000 руб./за проект

09 окт. 2023, в 12:02

1000 руб./за проект

09 окт. 2023, в 12:01

1000 руб./в час

Минуточку внимания

Is it possible to ping from Zabbix agent and pass that data into Zabbix server? I would like to be able to get response time from the agent.

I read that it is possible by using fping, would be great if someone could guide me to the correct path.

Thank you,
Rijath Mohammed

asked May 11, 2016 at 18:16

rijAth mohAmmed nr's user avatar

While that is not currently available out of the box, you can implement such a functionality using a feature called «user parameters». This forum thread has a simple example:

UserParameter=myping[*],/etc/zabbix/fping -q $1;echo $? 

Although for you the path to fping is likely to be /usr/sbin/fping or /usr/bin/fping.

You can read more about user parameters in the official manual: https://www.zabbix.com/documentation/3.0/manual/config/items/userparameters .

While I haven’t ever configured that, it would be similar on Windows — see this forum thread for some inspiration.

And if you would like to see this feature implemented out of the box, make sure to vote on this feature request.

answered May 11, 2016 at 18:57

Richlv's user avatar

5

Got it working using the below powershell script, :)

$Test = test-connection google.com -count 1
$Test.responsetime

This will just return the response time for Google.com and that value is passed to Zabbix using the below user parameter:

UnsafeUserParameters=1
UserParameter=ping.google,C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\zabbix\pinggoogle.ps1

I am calling this parameter from Zabbix using the key «ping.google«

Gerald Schneider's user avatar

answered May 18, 2016 at 13:02

rijAth mohAmmed nr's user avatar

2

Index

  • Not supported by default
    • I would like to send a ping from the monitored host
    • simple check – icmpping and agent.ping
  • Use UserParameter
    • Check ping behavior
    • Set to UserParameter
    • Check with zabbix_get
  • Add item to host
    • Confirm with tcpdump
    • Set for value of mapping
    • Confirm Data
  • Set trigger
    • test for trigger
  • Summary

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.

Good day!

Help me please.

Windows machine should ping the remote host, transfer the host availability information to the zabbiks server.

  • Zabbix server for windows download
  • Zabbix agent windows msi установка
  • Zabbix agent для windows скачать
  • Zabbix agent for windows install
  • Zabbix agent for windows 2008