NCPA with Powershell - possible to dot-source functions?
Posted: Fri Feb 18, 2022 12:26 pm
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"
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:
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!
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}"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"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!