MogiePete / zabbix-systemd-service-monitoring

Simple Zabbix Template to discover, monitor, and alert on systemd services.
GNU General Public License v2.0
91 stars 41 forks source link

I followed the installation instructions but things just don't want to work #7

Closed chetcuti closed 5 years ago

chetcuti commented 5 years ago

I've been trying to get your code up-and-running tonight, and for some reason it just doesn't want to work. It seems like everything is in-place and should be working, but it just doesn't for some reason.

I ran the tests in the README and the output is below. I'm hoping the results I'm seeing might help you point me in the right direction as to what's going wrong.

Any suggestions would be greatly appreciated!

# zabbix_agentd -t "systemd.service.discovery"
systemd.service.discovery                     [t|]

# zabbix_agentd -t "systemd.service.status[sshd]"
systemd.service.status[sshd]                  [t|0]

# zabbix_agentd -t "systemd.service.PID[sshd]"
systemd.service.PID[sshd]                     [m|ZBX_NOTSUPPORTED] [Unsupported item key.]
MogiePete commented 5 years ago

@chetcuti

Greg, if you are using the latest version the PID is no longer collected. It was previously collected and used to monitor the service to see if it had been restarted. That code was rewritten.

I will update the README.md to remove this erroneous command.

chetcuti commented 5 years ago

That's too bad, I was hoping the error might help troubleshoot why this isn't working for me.

Doing some manual tests, it seems like one of the .sh files might be having issue. Below is the output from running the zbx_service_discovery.sh and zbx_service_restart_check.sh scripts. Is there anything here that might indicate what's wrong?

# ./zbx_service_discovery.sh
{"data":[{"{#SERVICE}": "accounts-daemon"},{"{#SERVICE}": "apparmor"},{"{#SERVICE}": "apport"},{"{#SERVICE}": "atd"},{"{#SERVICE}": "avahi-daemon"},{"{#SERVICE}": "binfmt-support"},{"{#SERVICE}": "blk-availability"},{"{#SERVICE}": "bluetooth"},{"{#SERVICE}": "cloud-config"},{"{#SERVICE}": "cloud-final"},{"{#SERVICE}": "cloud-init-local"},{"{#SERVICE}": "cloud-init"},{"{#SERVICE}": "console-setup"},{"{#SERVICE}": "cron"},{"{#SERVICE}": "dbus-fi.w1.wpa_supplicant1"},{"{#SERVICE}": "dbus-org.bluez"},{"{#SERVICE}": "dbus-org.freedesktop.Avahi"},{"{#SERVICE}": "dbus-org.freedesktop.ModemManager1"},{"{#SERVICE}": "dbus-org.freedesktop.nm-dispatcher"},{"{#SERVICE}": "dbus-org.freedesktop.resolve1"},{"{#SERVICE}": "dbus-org.freedesktop.thermald"},{"{#SERVICE}": "ebtables"},{"{#SERVICE}": "grub-common"},{"{#SERVICE}": "irqbalance"},{"{#SERVICE}": "iscsi"},{"{#SERVICE}": "keyboard-setup"},{"{#SERVICE}": "lvm2-monitor"},{"{#SERVICE}": "lxcfs"},{"{#SERVICE}": "lxd-containers"},{"{#SERVICE}": "ModemManager"},{"{#SERVICE}": "network-manager"},{"{#SERVICE}": "networkd-dispatcher"},{"{#SERVICE}": "NetworkManager-dispatcher"},{"{#SERVICE}": "NetworkManager-wait-online"},{"{#SERVICE}": "NetworkManager"},{"{#SERVICE}": "nzbget"},{"{#SERVICE}": "nzbhydra2"},{"{#SERVICE}": "ondemand"},{"{#SERVICE}": "open-iscsi"},{"{#SERVICE}": "open-vm-tools"},{"{#SERVICE}": "pppd-dns"},{"{#SERVICE}": "radarr"},{"{#SERVICE}": "rsync"},{"{#SERVICE}": "rsyslog"},{"{#SERVICE}": "setvtrgb"},{"{#SERVICE}": "snapd.autoimport"},{"{#SERVICE}": "snapd.core-fixup"},{"{#SERVICE}": "snapd.seeded"},{"{#SERVICE}": "snapd"},{"{#SERVICE}": "snapd.system-shutdown"},{"{#SERVICE}": "sonarr"},{"{#SERVICE}": "ssh"},{"{#SERVICE}": "sshd"},{"{#SERVICE}": "syslog"},{"{#SERVICE}": "systemd-networkd-wait-online"},{"{#SERVICE}": "systemd-networkd"},{"{#SERVICE}": "systemd-resolved"},{"{#SERVICE}": "systemd-timesyncd"},{"{#SERVICE}": "tautulli"},{"{#SERVICE}": "thermald"},{"{#SERVICE}": "udisks2"},{"{#SERVICE}": "ufw"},{"{#SERVICE}": "unattended-upgrades"},{"{#SERVICE}": "ureadahead"},{"{#SERVICE}": "vboxadd-service"},{"{#SERVICE}": "vboxadd"},{"{#SERVICE}": "vgauth"},{"{#SERVICE}": "wpa_supplicant"},{"{#SERVICE}": "zabbix-agent"}]}
# ./zbx_service_restart_check.sh
Failed to mangle name: Invalid argument
Failed to expand names: Invalid argument
./zbx_service_restart_check.sh: line 9: [: : integer expression expected
Failed to mangle name: Invalid argument
Failed to expand names: Invalid argument
./zbx_service_restart_check.sh: line 20: 150223 -  : syntax error: operand expected (error token is "-  ")
MogiePete commented 5 years ago

You need to pass a variable to the zbx_service_restart_check.sh for it to work properly.

[root@localhost /]# /usr/local/bin/zbx_service_restart_check.sh
Failed to get properties: Unit name .service is not valid.
/usr/local/bin/zbx_service_restart_check.sh: line 9: [: : integer expression expected
Failed to get properties: Unit name .service is not valid.
/usr/local/bin/zbx_service_restart_check.sh: line 20: 102745 -  : syntax error: operand expected (error token is "-  ")

[root@localhost /]# /usr/local/bin/zbx_service_restart_check.sh sshd
0
chetcuti commented 5 years ago

The .sh files seem to be working properly when executed on their own:

# ./zbx_service_restart_check.sh ssh
0

# sudo systemctl restart ssh

# ./zbx_service_restart_check.sh ssh
1
# ./zbx_service_discovery.sh
{"data":[{"{#SERVICE}": "accounts-daemon"},{"{#SERVICE}": "apparmor"},{"{#SERVICE}": "apport"},{"{#SERVICE}": "atd"},{"{#SERVICE}": "avahi-daemon"},{"{#SERVICE}": "binfmt-support"},{"{#SERVICE}": "blk-availability"},{"{#SERVICE}": "bluetooth"},{"{#SERVICE}": "cloud-config"},{"{#SERVICE}": "cloud-final"},{"{#SERVICE}": "cloud-init-local"},{"{#SERVICE}": "cloud-init"},{"{#SERVICE}": "console-setup"},{"{#SERVICE}": "cron"},{"{#SERVICE}": "dbus-fi.w1.wpa_supplicant1"},{"{#SERVICE}": "dbus-org.bluez"},{"{#SERVICE}": "dbus-org.freedesktop.Avahi"},{"{#SERVICE}": "dbus-org.freedesktop.ModemManager1"},{"{#SERVICE}": "dbus-org.freedesktop.nm-dispatcher"},{"{#SERVICE}": "dbus-org.freedesktop.resolve1"},{"{#SERVICE}": "dbus-org.freedesktop.thermald"},{"{#SERVICE}": "ebtables"},{"{#SERVICE}": "grub-common"},{"{#SERVICE}": "irqbalance"},{"{#SERVICE}": "iscsi"},{"{#SERVICE}": "keyboard-setup"},{"{#SERVICE}": "lvm2-monitor"},{"{#SERVICE}": "lxcfs"},{"{#SERVICE}": "lxd-containers"},{"{#SERVICE}": "ModemManager"},{"{#SERVICE}": "network-manager"},{"{#SERVICE}": "networkd-dispatcher"},{"{#SERVICE}": "NetworkManager-dispatcher"},{"{#SERVICE}": "NetworkManager-wait-online"},{"{#SERVICE}": "NetworkManager"},{"{#SERVICE}": "ondemand"},{"{#SERVICE}": "open-iscsi"},{"{#SERVICE}": "open-vm-tools"},{"{#SERVICE}": "pppd-dns"},{"{#SERVICE}": "rsync"},{"{#SERVICE}": "rsyslog"},{"{#SERVICE}": "setvtrgb"},{"{#SERVICE}": "snapd.autoimport"},{"{#SERVICE}": "snapd.core-fixup"},{"{#SERVICE}": "snapd.seeded"},{"{#SERVICE}": "snapd"},{"{#SERVICE}": "snapd.system-shutdown"},{"{#SERVICE}": "ssh"},{"{#SERVICE}": "sshd"},{"{#SERVICE}": "syslog"},{"{#SERVICE}": "systemd-networkd-wait-online"},{"{#SERVICE}": "systemd-networkd"},{"{#SERVICE}": "systemd-resolved"},{"{#SERVICE}": "systemd-timesyncd"},{"{#SERVICE}": "thermald"},{"{#SERVICE}": "udisks2"},{"{#SERVICE}": "ufw"},{"{#SERVICE}": "unattended-upgrades"},{"{#SERVICE}": "ureadahead"},{"{#SERVICE}": "vboxadd-service"},{"{#SERVICE}": "vboxadd"},{"{#SERVICE}": "vgauth"},{"{#SERVICE}": "wpa_supplicant"},{"{#SERVICE}": "zabbix-agent"}]}

Status and restart seem to be working correctly when called through zabbix_agent:

# zabbix_agentd -t "systemd.service.status[ssh]"
systemd.service.status[ssh]                   [t|1]

# sudo systemctl start ssh

# zabbix_agentd -t "systemd.service.status[ssh]"
systemd.service.status[ssh]                   [t|0]
# zabbix_agentd -t "systemd.service.restart[ssh]"
systemd.service.restart[ssh]                  [t|0]

# sudo systemctl restart ssh

# zabbix_agentd -t "systemd.service.restart[ssh]"
systemd.service.restart[ssh]                  [t|1]

I'm not sure what the output for discovery should be, but this is all I get. Is this correct?

# zabbix_agentd -t "systemd.service.discovery"
systemd.service.discovery                     [t|]
MogiePete commented 5 years ago

Greg,

There was an error in the updated userparameter file. Please download the newest one and try again.

chetcuti commented 5 years ago

Nice! That was it! Everything is working now, and I've officially finished my migration from PRTG to Zabbix.

Thanks a lot for your help, and thank you so much for making such a great add-on!

MogiePete commented 5 years ago

Glad we were able to work out the issues!