Problem with shell commands nagios


#1

hello;
I have a problem with the execution of shell commands in the definition of notifications;
voila definition commands
define command (
command_name notify_host_by_eject
command_line / usr / bin / eject cdrom
)
This definition is just an example to see the execution of shell commands.
notify_host_by_eject is triggered after the log file, but it is not executed.

I’m new to supervision and nagios and I do not know much about commands and how they are written.
I would like you help me with the syntax and the execution of shell commands in the definition of commands nagios.
Thank you


#2

As far as I know, it should work like that, IF

  1. that kind of command rally exists and it works
  2. user nagios has rights to execute that command

#3

I second what Judanssi says, so switch to nagios user and run the command, just like you defined. For your example, it would be

su nagios -c “/usr/bin/eject cdrom”

Only after you have successfully tested the command, define it in nagios, just to avoid small issues like typos, permissions or other assumptions.

In this specific case (taking it as certain) there can be details like “eject” is not in /usr/bin. I’ve found that in suse it’s in /bin; in RHEL, it’s in /usr/sbin, and in ubuntu, it’s in /usr/bin.