8

I know that Zabbix can monitor any service on Linux machine via two options:

  • scan particular tcp or udp port, on which the service is bound
  • or count the service processes with proc.num[<processname>]

It is totally counter-intuitive, because I can spawn processes with the same executable name and they will deceive Zabbix. I'd prefer to use standard service <servicename> status or systemctl status name.service tool. But there are no standard way to use it from Zabbix except system.run[cmd]

Could you help me to write templates for monitoring a particular service state. We want to use different OSes like Centos 7 and Ubuntu 14.04 and 16.04 distributions. It is pity but service <servicename> status is completely different in listed operating systems.

3 Answers 3

15

You can also add the following UserParameters in zabbix_agentd.conf to monitor service status in systemd systems. For non-systemd the OS doesn't really monitor service status, the various bash script "status" arguments are often unreliable.

UserParameter=systemd.unit.is-active[*],systemctl is-active --quiet '$1' && echo 1 || echo 0
UserParameter=systemd.unit.is-failed[*],systemctl is-failed --quiet '$1' && echo 1 || echo 0
UserParameter=systemd.unit.is-enabled[*],systemctl is-enabled --quiet '$1' && echo 1 || echo 0

And then e.g. for sshd status create an item with a key like:

systemd.unit.is-active[sshd]
1
  • 8
    Not sure why this was down-voted, this is a perfectly valid simple solution, that unlike the accepted answer doesn't have any additional dependencies, and so can in some situations even be the only practical solution. +1
    – redreinard
    Jan 15, 2019 at 21:19
2

If Linux services are managed by systemd (Centos 7+, Ubuntu 16+, ...), then you can use https://github.com/cavaliercoder/zabbix-module-systemd. It uses standard systemd D-Bus communication - that's what systemctl does under the hood.

2
  • And what should I use if there are no systemd (like Ubuntu 14)?
    – GEORG GAAL
    Apr 26, 2017 at 15:33
  • 1
    non systemd systems = wild wild west = you have to parse output of init scripts
    – Jan Garaj
    Apr 26, 2017 at 23:16
1

For centos 6 it can be done:

UserParameter=check_service_status_asterisk,sudo service asterisk status 2> /dev/null | grep -q "is running";echo $?

For centos 7 or similar it can be created with:

UserParameter=check_service_status_grafana,systemctl status grafana-server 2> /dev/null |sed -n 3p |grep -q "running";echo $?

or

UserParameter=check_service_status[*],systemctl status $1 2> /dev/null |sed -n 3p |grep -q "running";echo $?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.