NagiosEnterprises / ncpa

Nagios Cross-Platform Agent
Other
177 stars 95 forks source link

check_ncpa.py comma separated arguments #789

Closed fraas04 closed 3 years ago

fraas04 commented 3 years ago

Hi,

I have a powershell that takes arguments this way: .\check_services_ex.ps1 edgeupdate,gupdate

The goal here is to check if there are stopped services, and the arguments are the ones I exclude from checking

I'm trying to use check_ncpa.py to checks this through Nagios, but I can't figure out how to pass the excluded servicenames with commas.

./check_ncpa.py -v -H HOSTNAME -M plugins/check_services_ex.ps1 -a edgeupdate,gupdate

doesn't pass the arguments, and marks these services as stopped, instead of ignoring them

./check_ncpa.py -v -H HOST -M plugins/check_services_ex.ps1 -a edgeupdate

works fine

Thanks

ccztux commented 3 years ago

Which version of NCPA and the client script check_ncpa.py are you using?

Can you try this?:

./check_ncpa.py -v -H HOSTNAME -M plugins/check_services_ex.ps1 -q 'args=edgeupdate,gupdate'
fraas04 commented 3 years ago

check_ncpa.py, Version 1.2.4 NCPA 2.3.1

It returns the following ./check_ncpa.py -v -H HOSTNAME-t SECRET -M plugins/check_services_ex.ps1 -q 'args=edgeupdate,gupdate' An error occurred: not enough values to unpack (expected 2, got 1)

ccztux commented 3 years ago

I am not able to reproduce this issue with the same version of NCPA and check_ncpa.py. Can you please post your plugin extension config for .ps1 scripts from your ncpa.cfg? Can you please execute the following commands and provide the output?:

./check_ncpa.py -D -H HOSTNAME -t SECRET -M plugins/check_services_ex.ps1 -q 'args=edgeupdate,gupdate'
./check_ncpa.py -D -H HOSTNAME -t SECRET -M plugins/check_services_ex.ps1 -a edgeupdate,gupdate
fraas04 commented 3 years ago

I'm sorry, I was away for a while. This is a different server, but the configuration is the same

the .ps1 config:

.ps1 = c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args

the outputs:

root@nagios:/usr/local/nagios/libexec# ./check_ncpa.py -D -H HOSTNAME -t SECRET -M plugins/check_services_ex.ps1 -a gupdate,sppsvc,RemoteRegistry Critical: 4 service(s) not running: gupdate (Stopped),RemoteRegistry (Stopped),SAP Business One RSP Agent Service (Stopped),sppsvc (Stopped),

root@nagios:/usr/local/nagios/libexec# ./check_ncpa.py -D -H HOSTNAME -t SECRET -M plugins/check_services_ex.ps1 -q 'args=gupdate,sppsvc,RemoteRegistry' The stack trace: Traceback (most recent call last): File "./check_ncpa.py", line 325, in main info_json = get_json(options) File "./check_ncpa.py", line 235, in get_json url = get_url_from_options(options) File "./check_ncpa.py", line 154, in get_url_from_options arguments = get_arguments_from_options(options) File "./check_ncpa.py", line 221, in get_arguments_from_options key, value = argument.split('=', 1) ValueError: not enough values to unpack (expected 2, got 1)

Please ignore the RSP Service

ccztux commented 3 years ago

No problem. :) I dont know how your powershell script handles arguments, but i had similar issues which i could solve this way https://github.com/NagiosEnterprises/ncpa/issues/585#issuecomment-882379451 Can you please give it a try? The solution in my cases was to remove the double quotes " from the arguments in the powershell script.

fraas04 commented 3 years ago

Thanks, that helped. I changed my powershell script to look like this

param (
    $Params
)

$Excludes = $Params.Split(",")

Now it works!

root@nagios:~# /usr/local/nagios/libexec/check_ncpa.py -H HOSTNAME -t SECRET -M plugins/check_services_ex.ps1 -a gupdate,sppsvc,RemoteRegistry,edgeupdate
OK: All services running | ServicesRunning=118;
caussatjerome commented 1 month ago

Bonjour j'ai trouvé une solution complémentaire pour ce problème surtout pour les espace dans un paramètre, je partage donc :

dans le script powershell, il faut s'assurer qu'il gère le lancement avec paramètre comprenant des espaces et entre guillemets, selon les cas, éliminer les guillemets reçu en paramètres :

la partie qui prend les paramètres dans le script ps1 :

# Global variables
$name = $args[0].Trim('"')
$period = $args[1].Trim('"')

pour la partie nrpd.cfg, il faut ajouter -args après le nom et chemin du script, et mettre entre apostrophe ' les variables séparé par des espaces. Enfin pour le cas de variables avec espaces, comme un nom, il faut mettre des guillemets.

exemple pour la partie nrpd.cfg de NCPA : plugins/check_veeam_backup.ps1 -args '"Backup SRV01 Mensuel" 32'

Espérant que cela en dépanne certains ;-)