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

Receiving error : Value should be a JSON object. #1

Closed prasul closed 6 years ago

prasul commented 6 years ago

Hi,

I did follow the installation instructions and added the discovery option to 3.4 installation of zabbix, but now the discovery instance throws up the error "Value should be a JSON object" I can find the JSON values when I run zabbix_agent -t command via root. Can you let me know what could be wrong ?

MogiePete commented 6 years ago

What OS are you running? Did you copy the sudoers file and uncomment the section for your OS?

What happens when you run this command as root?

sudo -H -u zabbix zabbix_agentd -t systemd.service.discovery

prasul commented 6 years ago

Hi,

I am running CentOS 7 and did copy in the sudoers file - updated the permissions to 0440 as visudo recommended. and here is the log of the commands - system discovery does work OK as root, but asks for sudo password when running as zabbix user.. here are the settings:

CloudLinux release 7.5 (Viktor Gorbatko) 
[sudo] password for zabbix: 

real    0m3.033s
user    0m0.015s
sys     0m0.020s
Running as root : systemd.service.discovery                     [t|{"data":[{"{#SERVICE}": "abrt-ccpp"},{"{#SERVICE}": "abrt-oops"},{"{#SERVICE}": "abrt-vmcore"},{"{#SERVICE}": "abrt-xorg"},{"{#SERVICE}": "abrtd"},{"{#SERVICE}": "atd"},{"{#SERVICE}": "atop"},{"{#SERVICE}": "auditd"},{"{#SERVICE}": "cagefs"},{"{#SERVICE}": "chronyd"},{"{#SERVICE}": "clamd"},{"{#SERVICE}": "cpanel-dovecot-solr"},{"{#SERVICE}": "cpanel"},{"{#SERVICE}": "cpanel_dovecot_solr"},{"{#SERVICE}": "cpdavd"},{"{#SERVICE}": "cpipv6"},{"{#SERVICE}": "crond"},{"{#SERVICE}": "csf"},{"{#SERVICE}": "dmraid-activation"},{"{#SERVICE}": "dnsadmin"},{"{#SERVICE}": "dovecot"},{"{#SERVICE}": "exim"},{"{#SERVICE}": "fastmail"},{"{#SERVICE}": "httpd"},{"{#SERVICE}": "ipaliases"},{"{#SERVICE}": "irqbalance"},{"{#SERVICE}": "kdump"},{"{#SERVICE}": "kernel-triggers"},{"{#SERVICE}": "lfd"},{"{#SERVICE}": "libstoragemgmt"},{"{#SERVICE}": "lshttpd"},{"{#SERVICE}": "lsws"},{"{#SERVICE}": "lve"},{"{#SERVICE}": "lve_namespaces"},{"{#SERVICE}": "lvectl"},{"{#SERVICE}": "lvestats"},{"{#SERVICE}": "lvm2-monitor"},{"{#SERVICE}": "mailman"},{"{#SERVICE}": "maldet"},{"{#SERVICE}": "mdmonitor"},{"{#SERVICE}": "microcode"},{"{#SERVICE}": "mysqld"},{"{#SERVICE}": "named"},{"{#SERVICE}": "NetworkManager-wait-online"},{"{#SERVICE}": "nscd"},{"{#SERVICE}": "proxyexecd"},{"{#SERVICE}": "pure-authd"},{"{#SERVICE}": "pure-ftpd"},{"{#SERVICE}": "pure-uploadscript"},{"{#SERVICE}": "rhel-autorelabel-mark"},{"{#SERVICE}": "rhel-autorelabel"},{"{#SERVICE}": "rhel-configure"},{"{#SERVICE}": "rhel-dmesg"},{"{#SERVICE}": "rhel-domainname"},{"{#SERVICE}": "rhel-import-state"},{"{#SERVICE}": "rhel-loadmodules"},{"{#SERVICE}": "rhel-readonly"},{"{#SERVICE}": "rngd"},{"{#SERVICE}": "rsyslog"},{"{#SERVICE}": "securetmp"},{"{#SERVICE}": "smartd"},{"{#SERVICE}": "sshd"},{"{#SERVICE}": "sysstat"},{"{#SERVICE}": "systemd-readahead-collect"},{"{#SERVICE}": "systemd-readahead-drop"},{"{#SERVICE}": "systemd-readahead-replay"},{"{#SERVICE}": "tailwatchd"},{"{#SERVICE}": "tuned"}]}] 

 Running as zabbix user: systemd.service.discovery                     [m|ZBX_NOTSUPPORTED] [Timeout while executing a shell script.]
[root@nitro ~]# cat /etc/sudoers.d/zbx_systemd 
#Required for Zabbix to query services running under systemd
Defaults:zabbix !requiretty

#Uncomment for Enterprise Linux based hosts
Cmnd_Alias ZBX_SYSTEMD = /usr/bin/systemctl status *, /usr/bin/systemctl list-unit-files *

#Uncomment for Ubuntu based hosts 
#Cmnd_Alias ZBX_SYSTEMD = /bin/systemctl status *, /bin/systemctl list-unit-files *

zabbix ALL=(ALL:ALL) NOPASSWD:ZBX_SYSTEMD

i did try running vfs.fs.discovery as zabbix user which works OK, did try systemctl as zabbix user and it works as well.

prasul commented 6 years ago

Removing the sudo command does make the results show up on ssh, but zabbix still complains of missing json object. Updated the discovery interval to 1minute to test this.

MogiePete commented 6 years ago

It seems that you have an issue with your sudoers configuration which explains why you are being prompted for the zabbix user's password.

If I run sudo -l as the zabbix user it returns the following:

Matching Defaults entries for zabbix on zabbix:
requiretty, !visiblepw, always_set_home, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS",
env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT
LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS
_XKB_CHARSET XAUTHORITY", secure_path=/sbin:/bin:/usr/sbin:/usr/bin, !requiretty, !requiretty
User zabbix may run the following commands on zabbix:
(ALL : ALL) NOPASSWD: /bin/systemctl status *, /bin/systemctl list-unit-files *

However you are correct and sudo is not required to list the unit files or check the status of a service.

I am going to modify the README and remove the sudoers requirement.

MogiePete commented 6 years ago

@prasul

Are you experiencing the same issue or is the data now being received by Zabbix correctly?

prasul commented 6 years ago

@MogiePete yes, got it to work now. Thank you for your tips. I was also looking at adding a filter to list the required services instead of getting the full list of systemctl enabled services. Like create a file and cat the entries to grep from the enabled list.

MogiePete commented 6 years ago

Glad you were able to get it working.