Command ran by nagios user or by nagios services

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
CSimpiFoN
Posts: 6
Joined: Mon Jan 29, 2018 7:37 am

Command ran by nagios user or by nagios services

Post by CSimpiFoN »

Hello Guys,

I have an issue with monitoring Dell EMC storages woth UEMCLI and monitoring VMware with ESXCLI. If I run a command after changing to Nagios user by su - nagios command, I can run the monitoring commands without any problem against both systems, but if I ask Nagios to run the same commands, it gets back some kind of error, that show that some environmental variables are not set correctly. I'm not sure what the differences between running command manually with nagios user or by the nagios service. Do you have any idea?

For example:
If I run the command "/usr/bin/uemcli -d {IP of array} /sys/general show -detail" it works well, but if Nagios runs the same command it gets the following error message:
Operation failed. Error code: 0x1000002
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Command ran by nagios user or by nagios services

Post by mcapra »

Without knowing more about how you configured your environment or how the uemcli program works, it's hard to say. My guess is that this probably boils down to the discrete differences between set, export, and env:
https://askubuntu.com/questions/205688/ ... i-use-each

Basically, Nagios Core doesn't just spin up the Nagios user's Bash session and run commands. It uses popen which doesn't necessarily inherit "all the Bash things". This is why Nagios Core and Bash and can sometimes produce two totally different results for a given command.

If you require specific environment variables as part of your command execution's execution, you can try declaring them in the Nagios Core command definition using env. Here's an example using some Oracle libraries in the check_oracle_health plugin:

Code: Select all

define command {
    command_name    check_oracle_health
    command_line    /usr/bin/env LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client/lib ORACLE_HOME=/usr/lib/oracle/12.1/client $USER1$/check_oracle_health $ARG1$
}
Former Nagios employee
https://www.mcapra.com/
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Command ran by nagios user or by nagios services

Post by dwhitfield »

@mcapra probably hit the nail on the head, but can you post your nagios.cfg? It might provide some additional insight.
CSimpiFoN
Posts: 6
Joined: Mon Jan 29, 2018 7:37 am

Re: Command ran by nagios user or by nagios services

Post by CSimpiFoN »

Hello,
Thanks for the answers, but the problem is, that I don't really know what ENV variables the uemcli or esxcli might miss, as the error message doesn't share too much information. Which part of nagios.cfg would you like to see? Or the whole?

Honestly not even sure it's a missing ENV variable, as the nagios user apparently doesn't have ENV variables set that is connected to uemcli or esxicli.
kyang

Re: Command ran by nagios user or by nagios services

Post by kyang »

I wouldn't know for sure as I'm not familar with UEMCLI or ESXCLI other than the docs available from a Google search.

Sure, you can PM or post me the whole nagios.cfg.

Have you tried just using plugins for monitoring?

https://exchange.nagios.org/index.php?o ... dell%20emc
https://exchange.nagios.org/
CSimpiFoN
Posts: 6
Joined: Mon Jan 29, 2018 7:37 am

Re: Command ran by nagios user or by nagios services

Post by CSimpiFoN »

Hello,

Thanks for the reply! I sent my nagios.cfg in a PM. Also I will try this Dell EMC Unity check you sent. As I see it's a quite new plugin, however it's using the REST API of the storage, and not the CLI, so event handling probably can't be done through it.
kyang

Re: Command ran by nagios user or by nagios services

Post by kyang »

Thanks I received your nagios.cfg.

Nothing noticeable.

This looks to be using the UEMCLI?
https://exchange.nagios.org/directory/P ... xe/details
CSimpiFoN
Posts: 6
Joined: Mon Jan 29, 2018 7:37 am

Re: Command ran by nagios user or by nagios services

Post by CSimpiFoN »

It really seems to be working if I set up Nagios to run it with sudo. However the behavior is still weird, that it works with Nagios user if I run it manually, but it does not if it's ran by Nagios.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Command ran by nagios user or by nagios services

Post by scottwilkerson »

CSimpiFoN wrote:It really seems to be working if I set up Nagios to run it with sudo. However the behavior is still weird, that it works with Nagios user if I run it manually, but it does not if it's ran by Nagios.
It could also be an environment variablethat is set if you are running form the CLI that nagios doesn't have access too
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked