Hello. I’m trying to implement a plugin I wrote in python.
In this python-script a subprocess is opened with ps = subprocess.Popen(('/usr/NX/bin/nxserver', '--list'), stdout=subprocess.PIPE).
I want this line to be executed on an agent, but I get an error message in icinga2-web, that the file can’t be found. By the python version displayed in the error message I realised, that this line is executed on the master node.
My services.conf in the global-templates zone looks like this:
apply Service "systemd status" {
import "generic-service"
check_command = "check_systemd"
command_endpoint = host.vars.agent_endpoint
assign where host.vars.os == "linux"
ignore where host.vars.noagent
}
apply Service "NoMachine status" {
import "generic-service"
check_command = "check_nomachine_sessions"
command_endpoint = host.vars.client_endpoint
assign where host.vars.os == "linux" && host.vars.Services == "NoMachine"
assign where host.name == "sc-030175l.intra.dlr.de"
ignore where host.vars.noagent
}
The systemd status is working correctly but for my own script I get the FileNotFoundException.
Any ideas what I could’ve configured wrong?
on your working systemd status service you defined the command_endpoint with host.vars.agent_endpoint and on the NoMachine status service with host.vars.client_endpoint - maybe a typo?
But now all I get is the execvpe(…) failed: No such file or directory error. The help I found in this forum didn’t work for me.
When I run the command sudo -u nagios /bin/sudo /usr/lib/nagios/plugins/check_nomachine_sessions.py locally on the machine, it works exactly the way I want. But on Icinga-web I get the error mentioned above.
Any ideas?
Thanks for guiding me through this.
It’s partially working now. The script is getting executed, but I need sudo-privileges to be able to get the output correctly.
I’ve tried
but if I do it like this, I get a No such file or directory error again.
I enabled the nagios User to execute the script and the target-file in the script as sudo without a password.
Why put sudo?
this: "/bin/sudo " will break it
you can check some of the other files in the /usr/lib/nagios/plugins/
directory
perhaps you need to adjust your file permissions so that this file can be ran without sudo.
you can copy the permissions of a different file in that directory like the check_disk file
If you need help you can calculate them here:
Both files: check_nomachine_sessions.py and the /usr/NX/bin/nxserver have the 755 permissions. So they are executable. But /usr/NX/bin/nxserver --list will return -1 if not run with sudo privileges.
So your problem is not with icinga at this point in time but with the: check_nomachine_sessions.py
script trying to get a valid output from the: /usr/NX/bin/nxserver
executable.
So, short answer is take a look at sudoers files and allow the nagios user to run this command. or create create a simple shell script instead. Or rewrite the python script to a shell script entirely. test.sh