Page 1 of 1
Execute complex commands with ncpa
Posted: Tue Jan 11, 2022 12:16 pm
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
Re: Execute complex commands with ncpa
Posted: Wed Jan 12, 2022 3:30 pm
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 from
https://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
Re: Execute complex commands with ncpa
Posted: Tue Feb 01, 2022 5:17 am
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