Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trigger in Zabbix 4.0 LTS, add support to systemd 219 (CentOS 7) #37

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ OS:

* RHEL/CentOS/Oracle EL
* Ubuntu 16.04/18.04
* (systemd version 230+)

Zabbix:

Expand All @@ -24,8 +25,8 @@ Installation
------------

* Server
* Import template `Template_App_systemd_Services_v4.xml` file if you have Zabbix 4
* Import template `Template_App_systemd_Services_v5.xml` file if you have Zabbix 5
* Import template `Template_systemd_Services_v4.xml` file if you have Zabbix 4
* Import template `Template_systemd_Services_v5.xml` file if you have Zabbix 5
* Link template to host
* Agent
* Place the following files inside `/etc/zabbix/`:
Expand Down Expand Up @@ -82,6 +83,13 @@ zabbix_agentd -t "systemd.service.status[sshd]"
zabbix_agentd -t "systemd.service.restart[sshd]"
```

The `status[SERVICENAME]` will return:

* `[t|1]` if that service is running
* `[t|0]` if that service is NOT running

The `restart[SERVICENAME]` will return the most recent restart date.

License
-------

Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions userparameter_systemd_services_old.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
UserParameter=systemd.service.discovery,/usr/local/bin/zbx_service_discovery.sh

UserParameter=systemd.service.status[*],$(systemctl is-active -q $1) && echo 1 || echo 0

UserParameter=systemd.service.restart[*],/usr/local/bin/zbx_service_restart_check.sh $1
Empty file modified usr/local/bin/zbx_service_discovery.sh
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions usr/local/bin/zbx_service_restart_check.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ uptime=$(date +%s -d "$(systemctl show --value -p ActiveEnterTimestamp sysinit.t
if [[ $(( now - uptime)) -lt 180 ]]; then
echo 0
else
# note that the next line requires systemd version 230 because of "--value"
service_start=$(systemctl show --value -p ActiveEnterTimestamp "$service")
service_start_as_epoch=$(date -d "$service_start" +%s)

Expand Down
18 changes: 18 additions & 0 deletions usr/local/bin/zbx_service_restart_check_old.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

service="$1"
now=$(date +%s)

uptime_value=$(systemctl show --value -p ActiveEnterTimestamp sysinit.target)

# Don't alert if the server has just been restarted
uptime=$(date +%s -d "$uptime_value")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just extracted the variable

if [[ $(( now - uptime)) -lt 180 ]]; then
echo 0
else
# note that the next line requires systemd version 230 because of "--value"
service_start=$(systemctl show --value -p ActiveEnterTimestamp "$service")
service_start_as_epoch=$(date -d "$service_start" +%s)

[[ $(( now - service_start_as_epoch )) -lt 180 ]] && echo 1 || echo 0
fi