Execute complex commands with ncpa

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
sgomeztd
Posts: 51
Joined: Tue Apr 30, 2019 11:00 am

Execute complex commands with ncpa

Post by sgomeztd »

Hi,

I'm trying to figure out how to run complex commands with the ncpa on a linux client. What I'm trying to excute is the following

Code: Select all

scl enable rh-ruby24 '/usr/local/nagios/libexec/check_gitlab.rb -m health
scl enable rh-ruby24 '/usr/local/nagios/libexec/check_gitlab.rb -m health -s https://localhost/ 
I know how to execute a plugin with arguments but in this case, is a little bit more complex. I know I could create a .rb extension for plugin but is there a better way or alternative?

Also, in cases where I just a comman? For example on my current nrpe I have command the following that I have no idea how to run on ncpa

Code: Select all

[check_pacemaker]=sudo /usr/sbin/crm_mon -s
gsmith
Posts: 1253
Joined: Tue Mar 02, 2021 11:15 am

Re: Execute complex commands with ncpa

Post by gsmith »

Hi

Typically what is done is that you create your own plugin and then call it using check_ncpa.py

The plugin is essentially some sort of script.
Image001.jpg
The above is taken fromhttps://www.nagios.org/ncpa/help.php#ac ... tive-check

Here is some documentation on plugins:
https://assets.nagios.com/downloads/nag ... ugins.html
https://assets.nagios.com/downloads/nag ... inapi.html
https://nagios-plugins.org/doc/guidelines.html

On the client running ncpa their is a config file called ncpa.cfg This file has an area for plugin definition, so you could associate the ruby command with an .rb file extension, and also list commands that should be run using sudo. Here is a section of that cfg file:

Code: Select all

# This is for Unix only (Linux, Mac OS X, etc)
#
# run_with_sudo =

#
# Extensions for plugins
# ----------------------
# The extension for the plugin denotes how NCPA will try to run the plugin. Use this
# for setting how you want to run the plugin in the command line.
#
# NOTE: Plugins without an extension will be ran in the cmdline as follows:
#       $plugin_name $plugin_args
#
# Defaults:
# .sh = /bin/sh $plugin_name $plugin_args
# .py = python3 $plugin_name $plugin_args
# .pl = perl $plugin_name $plugin_args
# .php = php $plugin_name $plugin_args
# .ps1 = powershell -ExecutionPolicy Bypass -File $plugin_name $plugin_args
# .vbs = cscript $plugin_name $plugin_args //NoLogo
# .wsf = cscript $plugin_name $plugin_args //NoLogo
# .bat = cmd /c $plugin_name $plugin_args
#
# Since windows NCPA is 32-bit, if you need to use 64-bit powershell, try the following for
# the powershell plugin definition:
# .ps1 = c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args
#

# Linux / Mac OS X
.sh = /bin/sh $plugin_name $plugin_args
.py = python3 $plugin_name $plugin_args
.pl = perl $plugin_name $plugin_args
.php = php $plugin_name $plugin_args

# Windows
.ps1 = powershell -ExecutionPolicy Bypass -File $plugin_name $plugin_args
.vbs = cscript $plugin_name $plugin_args //NoLogo
.wsf = cscript $plugin_name $plugin_args //NoLogo
.bat = cmd /c $plugin_name $plugin_args
The above gives a pretty good background of creating plugins and using check_ncpa.py to run the plugins.

Another good resource is https://exchange.nagios.org/ where there are over 4000 plugins
created by users. Nagios Exchange is a central place for Nagios Community members and contributors to find and
share Nagios projects of all kinds - plugins, addons, documentation, extensions and more.


Thanks
You do not have the required permissions to view the files attached to this post.
sgomeztd
Posts: 51
Joined: Tue Apr 30, 2019 11:00 am

Re: Execute complex commands with ncpa

Post by sgomeztd »

Hi,

Ok, wrapping the command arround a bash script is what I have been doing, just wanted to know if there was a simpler alternative but it seems there is not.

Feel free to close this topic
Locked