icinga-powershell-framework icon indicating copy to clipboard operation
icinga-powershell-framework copied to clipboard

Feature: use dynamic parameters for plugins e.g. "$env:computername"

Open tectumopticum opened this issue 3 years ago • 2 comments

Expected Behavior

When using the "Invoke-IcingaCheckHTTPStatus"-plugin I'd like to fill the "-Url"-parameter dynamically, e.g. with the name of the host on which the plugin is executed. So something like Invoke-IcingaCheckHTTPStatus -Url http://$($env:computername):0815/config/v1/status should be expanded to Invoke-IcingaCheckHTTPStatus -Url http://local_examplehost:0815/config/v1/status

Another idea is using timestamps, e.g. Invoke-IcingaCheckHTTPStatus -Url http://local_examplehost:0815/config/v1/event_log?start=(Get-Date).AddMinutes(-5).ToString("yyy-mm-ddTHH:mm:ss")&end=(Get-Date).ToString("yyy-mm-ddTHH:mm:ss") which should resolve the current date/time as end-parameter and looks back for 5 minutes as the start-parameter in the Url. Invoke-IcingaCheckHTTPStatus -Url http://local_examplehost:0815/config/v1/event_log?start=2022-07-04T13:25:00&end=2022-07-04T13:30:00

Current Behavior

after configuring this in Director with http://$$($$env:computername):57412/config/v1/status , it doesn't work, because the config-data from Director is rendered with single-quotes around all parameters:

HTTP Status Code: Cannot bind parameter 'Uri'. Cannot convert value "[http://$($env:computername):57412/config/v1/status] to type "System.Uri". Error: "Invalid URI: The hostname could not be parsed."

Possible Solution

I have in mind that it might be a security-risk if any command will be executed by expansion. I don't have a simple solution for that.

Context

  • such a feature could be helpful when each plugin-call needs a changed parameter. Best example is a webservice or api where you query data by timestamp

tectumopticum avatar Sep 09 '22 14:09 tectumopticum

ref/NC/762630

carraroj avatar Sep 12 '22 06:09 carraroj

I will look into this for Icinga for Windows v1.11.0

One way to implement this, would be to provide a fixed scheme of strings which are replaced before execution of the plugin.

Something like

-Uri '&[System]::ComputerName&:57412/config/v1/status' -Timestamp '&[Time]::yyy-mm-ddTHH:mm:ss&'

What do you think?

The double & would be our command reader and the name between the [] would be the template source to read data from. Beyond the :: is then either the fixed name of the value to read from or in the [Time] case the formated timestamp we would print.

LordHepipud avatar Nov 21 '22 11:11 LordHepipud