[ZBXNEXT-2871] Monitor linux service by systemd Created: 2015 Jul 06 Updated: 2024 Apr 10 Resolved: 2019 Oct 28 |
|
Status: | Closed |
Project: | ZABBIX FEATURE REQUESTS |
Component/s: | Agent (G) |
Affects Version/s: | 2.5.0 |
Fix Version/s: | 4.4.0alpha3, 4.4 (plan) |
Type: | Change Request | Priority: | Trivial |
Reporter: | Timofey | Assignee: | Vladislavs Sokurenko |
Resolution: | Fixed | Votes: | 32 |
Labels: | discovery, lld, newitemkey, systemd | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified | ||
Environment: |
Linux |
Attachments: |
![]() |
||||||||||||
Issue Links: |
|
||||||||||||
Team: | |||||||||||||
Sprint: | Sprint 56 (Sep 2019), Sprint 55 (Aug 2019), Sprint 53 (Jun 2019), Sprint 54 (Jul 2019) | ||||||||||||
Story Points: | 5 |
Description |
Systemd have a generic APi for working with services and tracking service state by self, we can easy export service state, as example from systemctl status <service name> //Also, as idea for LLD |
Comments |
Comment by Raymond Kuiper [ 2015 Jul 23 ] |
Definitely a nice idea! Supporting systemd items natively will allow us to monitor 'services' on Linux almost the same way as we do on windows. root@localhost:~# service cron status
Jul 23 14:17:01 localhost CRON[687]: pam_unix(cron:session): session opened for user root by (uid=0) If done in the right way, this might enable the use of the service.discovery, service.info[service,<param>] and services[<type>,<state>,<exclude>] items on Linux |
Comment by Michael [ 2016 Apr 11 ] |
Is there any movement on this request? 90% of my systems are running CentOS 7.2 (with systemd) and having the ability to monitor systemd service status would be very beneficial. |
Comment by Anton Smirnov [ 2016 Apr 27 ] |
Michael, you may use some custom config like mine: /etc/zabbix_agentd.conf.d # checks to determine if specified unit is active, failed or enabled 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 It will create these checks: systemd.unit.is-active[<unit name>] # 1 if unit is active, 0 if inactive systemd.unit.is-failed[<unit name>] # 1 if unit if in failed state, 0 if not systemd.unit.is-enabled[<unit name>] # 1 if unit is enabled, 0 if not |
Comment by Michael [ 2016 Apr 28 ] |
Hi Anton, I'm running a check much the same; UserParameter=custom.service.check[*],if systemctl status $1 | grep running >> /dev/null; then echo 0; else echo 1; fi; But I think I will add in your checks as they are a little more conclusive, plus I like the shorthand if statements. I've ran into lots of selinux issues with this, will the zabbix selinux policy eventually allow systemctl access? How did you combat the selinux denials? The nuisance is I've created a custom policy to allow specific services to be monitored, in the event I want to monitor something new I have to create additional policies, very annoying. ----------------------------- #!/bin/bash checks=(is-active is-failed is-enabled); services=(firewalld postfix ntpd crond sshd fail2ban); if [ -z "$1" ]; then echo "enter host address"; read host; else host=$1; fi echo -e "checking host $host\n"; for service in "${services[@]}"; do echo "$service:"; for check in "${checks[@]}"; do echo -en "\t$check:"; test=`zabbix_get -s $host -k "systemd.unit.$check[$service]"` if [ "$test" = 0 ]; then echo -e "\t$test - success"; else echo -e "\t$test - failed"; fi done echo ""; done |
Comment by Ryan Armstrong [ 2017 Apr 21 ] |
I've created a loadable module to query systemd directly, via the D-Bus API. Aims to be be comprehensive as well as offering zabbix-friendly wrappers such as systemd.service.info. https://github.com/cavaliercoder/zabbix-module-systemd I'll create installation packages soon, but please take a look and file issues on GitHub if it doesn't work for you |
Comment by Juan Carlos Castro [ 2017 Jul 05 ] |
This is great! Is it usable with Zabbix 3.0? |
Comment by Jan Garaj [ 2017 Jul 05 ] |
All Zabbix versions with loadable module option are supported - that's Zabbix 2.2+ |
Comment by Juan Carlos Castro [ 2017 Jul 07 ] |
Compiled and running in agent. For those who have to deal with the yum repository that doesn't have *-devel packages (there's an issue here for that too, I voted it up: ZBXNEXT-2182) here's the steps. I assume a x64 server. (Who the netherworld uses a 32 bit server these days anyway?) Otherwise you can lose the --libdir switch in the ./configure command line. @Ryan, maybe you'd want to include these in your README?
That's it. Now I'm going to import the template in Zabbix and see if this actually works. Be right back. |
Comment by Juan Carlos Castro [ 2017 Jul 07 ] |
In order to import the template in 3.0 I had to edit the version tag to 3.0 and remove an empty <httptests /> tag. Waiting for auto-discovery of items now. Should work like filesystems do, yes? |
Comment by Jan Garaj [ 2017 Jul 07 ] |
Juan: https://github.com/cavaliercoder/zabbix-module-systemd is 3rd party project, so this Jira is not a right place for issue reporting of that module. Please use Github issue tracker. Feel free to create pull request if you think that README should be improved. That template is only example template and yes it was made for 3.2. Ryan has released https://github.com/cavaliercoder/zabbix-template-converter. Try to use it and convert that template to your 3.0 version. |
Comment by Pablo Mai [ 2017 Sep 28 ] |
Hola Juan Carlos, Funciono en Zabbix 3.0 ? Gracias por tu respuesta. Saludos Pablo |