greatcare / pm2-zabbix

A Node.js PM2 monitoring tool for Zabbix.
MIT License
88 stars 60 forks source link

A few issues #8

Closed kashak88 closed 7 years ago

kashak88 commented 7 years ago

Great module, however I've had issues getting it to work in our environment. Just fixed it and wanted to share: 1) The sysv script is missing the "--monitor" at the end of start-stop-daemon during startup operation. Not sure if this is intended? 2) The UserParameter had to be modified like this in order to work correctly for me: UserParameter=pm2.processes,sudo PM2_HOME=/home/testing/.pm2 -u testing /usr/bin/pm2-zabbix --discover

Reason being, 'zabbix' user invoking sudo would not use the correct .pm2 home directory for user 'testing', and would instead use /root/.pm2, trying to create a new instance of PM2(obviously failing) and causing "Value should be a JSON object" on Zabbix server. Invoking "sudo -u testing /usr/bin/pm2-zabbix --discover" manually as zabbix user with shell worked fine, and it would use correct PM2 instance + pull correct values. Starting "pm2-zabbix --monitor" as user 'testing' would partially fail with:

[ OK ] Periodic sending of PM2 status succeeded [ ERR ] Periodic sending of process list error: { [Error: Command failed: /usr/bin/zabbix_sender --config /etc/zabbix/zabbix_agentd.conf --input-file - ] killed: false, code: 2, signal: null, cmd: '/usr/bin/zabbix_sender --config /etc/zabbix/zabbix_agentd.conf --input-file -' }

Not sure what's going on there, but #2 fixed it for me. Used zabbix_agentd L4 logs to figure it out. Error produced in the log was:

fs.js:647 return binding.mkdir(pathModule._makeLong(path), ^ Error: EACCES, permission denied '/root/.pm2' at Object.fs.mkdirSync (fs.js:647:18) at Object.CLI.pm2Init (/usr/local/lib/node_modules/pm2/lib/CLI.js:37:8) at Object. (/usr/local/lib/node_modules/pm2/bin/pm2:20:5) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:902:3

rkaw92 commented 7 years ago
  1. Good catch! Sure, this is not intended. I'm going to fix it and release 0.2.1 soon. Hoping to cram in a few more fixes.
  2. This may be distro-specific. Are you using Ubuntu?
kashak88 commented 7 years ago

Yes, the VM I've tested this on was a Ubuntu Server 14.04.

rkaw92 commented 7 years ago

Looks like Ubuntu mangles $HOME, as described here: http://unix.stackexchange.com/questions/91384/how-is-sudo-set-to-not-change-home-in-ubuntu-and-how-to-disable-this-behavior

This will have to be considered in the installation instructions/files somehow. I would like to avoid telling users to always set a custom PM2_HOME, at least as the default solution.

Can you check if this works in your sudoers file, instead of the Defaults provided in this repository?

Defaults:zabbix !requiretty, always_set_home

The above directive should make sudo set $HOME to that of the target user when zabbix is sudoing to it, so it should not be necessary to manually override PM2_HOME.

kashak88 commented 7 years ago

I'll test this out in a few days and will report back

kashak88 commented 7 years ago

It works! Thanks