Page 1 of 1

NCPA custom plugins scripts and configuration

Posted: Sun Mar 14, 2021 9:22 am
by elade
Hi,

I started working with NCPA because NRPE is not supported anymore and I have a few issues with it's deployment and configuration.

I have linux machines (Ubuntu 16.04/18.08) with python3, bash and perl custom scripts.
I copied them into /usr/local/ncpa/plugins dir to be custom scripts.
I don't know how to add the new commands to NCPA cfg file and grant to some of them root privileges.
A few examples from what I did in nrpe.cfg:

Code: Select all

command[myscript]=sudo -S /usr/local/nagios/libexec/myscript.py
command[myscript2]=sudo -S -u root /usr/local/nagios/libexec/myscript2.py
command[myscript3]=/usr/local/nagios/libexec/myscript3.py
command[myscript4]=/usr/local/nagios/libexec/myscript4.pl
command[myscript5]=sudo -S /usr/local/nagios/libexec/myscript5
Suders file:

Code: Select all

nagios ALL=NOPASSWD: /usr/local/nagios/libexec/myscript.py
nagios ALL=(root) NOPASSWD: /usr/local/nagios/libexec/myscript2.py
My questions are:
1. How can I add the commands and sudoers to new NCPA configuration (ncpa.cfg) with the privileges that I need?
2. Almost all my scripts are in python 3.5+. Dose it matter for NCPA when running the scripts?

I have on my machines NCPA 2.3.1
Nagios XI - 5.8.2 with check_ncpa.py, Version 1.2.4
All the checks are need to active and not passive.

Thank you!

Re: NCPA custom plugins scripts and configuration

Posted: Mon Mar 15, 2021 12:50 pm
by dchurch
Hello!

It's possible to configure NCPA with custom handlers to make this possible.

NCPA should be configured with the Python 3 interpreter, down near the end of the file /usr/local/ncpa/etc/ncpa.cfg:

Code: Select all

# Linux / Mac OS X
.sh = /bin/sh $plugin_name $plugin_args
.py = python $plugin_name $plugin_args
.py2 = python2 $plugin_name $plugin_args
.py2-sudo = sudo python2 $plugin_name $plugin_args
.py3 = python3 $plugin_name $plugin_args
.py3-sudo = sudo python3 $plugin_name $plugin_args

# Windows
[...] (keep this the same)
/etc/sudoers:

Code: Select all

nagios ALL = NOPASSWD:/usr/bin/python3 /usr/local/ncpa/plugins/*.py3-sudo
nagios ALL = NOPASSWD:/usr/bin/python2 /usr/local/ncpa/plugins/*.py2-sudo
Then all you have to do is copy your plugins into /usr/local/ncpa/plugins/, renaming them:
  • If it's Python 2 and doesn't need sudo, give it the .py2 extension.
  • If it's Python 2 and needs sudo, give it the .py2-sudo extension.
  • If it's Python 3 and doesn't need sudo, give it the .py3 extension.
  • If it's Python 3 and needs sudo, give it the .py3-sudo extension.
Extend as-necessary for bash scripts that need sudo, etc.

Make sure to run service ncpa_listener restart if you update ncpa.cfg.

That's all you should need. The NCPA wizard should automatically pick up on any scripts that NCPA has a handler for in the /plugins directory.

Re: NCPA custom plugins scripts and configuration

Posted: Tue Mar 16, 2021 5:56 am
by elade
Hi,

I did as you wrote but I get the following:
sudo: no tty present and no askpass program specified

This is my configuration:
/usr/local/ncpa/etc/ncpa.cfg

Code: Select all

.sh = /bin/sh $plugin_name $plugin_args
.py = python3 $plugin_name $plugin_args
.sh-sudo = sudo /bin/sh $plugin_name $plugin_args
.py3-sudo = sudo python3 $plugin_name $plugin_args
/usr/local/ncpa/etc/ncpa.cfg.d/nagios.cfg

Code: Select all

.sh-sudo = sudo /bin/sh /usr/local/ncpa/plugins/myscript1
.py3-sudo = sudo python3 /usr/local/ncpa/plugins/myscript2.py
/etc/sudoers.d/nagios

Code: Select all

nagios ALL = NOPASSWD:/bin/sh /usr/local/ncpa/plugins/*.sh-sudo
nagios ALL = NOPASSWD:/usr/bin/python3 /usr/local/ncpa/plugins/*.py3-sudo
Any idea?

Re: NCPA custom plugins scripts and configuration

Posted: Wed Mar 17, 2021 9:43 am
by lmiltchev
sudo: no tty present and no askpass program specified
This looks like sudoers problem. See this:

https://askubuntu.com/questions/1113503 ... -specified

You placed your nagios entries in "/etc/sudoers.d/nagios". Do you have anything else in that file? What about the "/etc/sudoers" file?

I tried a similar setup on my test machines. I added two very simple scripts on Ubuntu 18.04 - just printing a line of text, and called them via check_ncpa.py. Both commands worked as expected:

Code: Select all

[root@main-nagios-xi libexec]# ./check_ncpa.py -H 192.168.x.x -t 'mytoken' -M 'plugins/myscript1' -q ''
This is myscript1
[root@main-nagios-xi libexec]# ./check_ncpa.py -H 192.168.x.x -t 'mytoken' -M 'plugins/myscript2.py' -q ''
This is myscript3.py.

Re: NCPA custom plugins scripts and configuration

Posted: Wed Mar 31, 2021 10:30 am
by elade
Sorry for the late respond.
The link you added did the job.
I'm still doing some tests testing to see how stable the NCPA.

Another question I have is how NCPA is working with proxy?
Almost on all my machines configure with proxy (also the Nagios machine) on it.
Dose NCPA know how to access and work with proxy on remote and Nagios machines?

Re: NCPA custom plugins scripts and configuration

Posted: Wed Mar 31, 2021 4:39 pm
by vtrac
Hi,
NCPA doesn't currently support using a proxy.

Here's a similar forum ticket regarding NCPA proxy:
https://support.nagios.com/forum/viewto ... 16&t=60064


Regards,
Vinh