NCPA with Powershell - possible to dot-source functions?

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
md5hash
Posts: 1
Joined: Fri Feb 18, 2022 12:11 pm

NCPA with Powershell - possible to dot-source functions?

Post by md5hash »

We are in the process of migrating from the not-often-upgraded NSClient++ to NCPA 2.4.0. Some of our checks use powershell scripts that make use of functions within the file. For example, here we have a check from nsclient.ini to check flow rate going into our datacenter's air conditioner, using the file "nagios_flowmonitor.ps1" with the function "Get-FlowStatus"

Code: Select all

check_flow_status=cmd /c echo scripts\Nagios_FlowMonitor.ps1; exit($lastexitcode) | powershell.exe -command "& { . 'C:\Program Files\NSClient++\scripts\Nagios_FlowMonitor.ps1'; Get-FlowStatus}"
I'm struggling to figure out how to reproduce this check using NCPA, where the structure for imported scripts seems more rigid. With NSClient++ I was able to use powershell's -command parameter to dot-source the importing of the function with . .\file.ps1

However, I can't figure out if this is possible or supported with NCPA. Our usual command from the nagios server to a client, using ps1 files, would of course be:

Code: Select all

/usr/lib64/nagios/plugins/check_ncpa.py -H <ipaddress> -t 'tokenstring' -P 5693 -M 'plugins/Nagios_FlowMonitor.ps1' -a "Get-FlowStatus"
But in this case of course, we're just running the nagios_flowmonitor.ps1 file without taking the step to dot-source the functions, so of course the argument of "Get-FlowStatus" yields nothing.

We do understand we could rewrite the check to use modules instead, but I just thought I'd check if dot-sourcing is an option. Thanks!
Locked