Skip to content

Commit

Permalink
Add possibility to provide path as argument and default value for fal…
Browse files Browse the repository at this point in the history
…lback (#374)
  • Loading branch information
racicLuka authored Oct 12, 2023
1 parent 30b1457 commit 610122e
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions checkmk_extensions/agent/robotmk_collector.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ Set-StrictMode -Version 3.0
$ErrorActionPreference = "Stop"

function Main {
Param (
[parameter(Mandatory=$true, Position=0)]
[string]$ConfigPath
)
$ConfigPath = DetermineConfigPath -CommandLineArgs $args
Write-Output "<<<robotmk_v2:sep(10)>>>"

try {
Expand All @@ -27,6 +24,24 @@ function Main {
}


function DetermineConfigPath {
[OutputType([string])]
Param (
[parameter(Mandatory=$false, Position=0)]
[String[]]$CommandLineArgs
)

if ($CommandLineArgs -ne "" -and $CommandLineArgs.Count -gt 0) {
return $CommandLineArgs[0]
}

$configDir = $env:MK_CONFDIR
if ($null -eq $configDir) {
$configDir = 'C:\ProgramData\checkmk\agent\config'
}

return Join-Path $configDir 'robotmk.json'
}
function SerializeConfigReadingError {
[OutputType([string])]
Param (
Expand Down Expand Up @@ -56,4 +71,4 @@ function GetResultsDirectory {
return $configData.results_directory -as [string]
}

Main("${env:MK_CONFDIR}\robotmk.json")
Main $args

0 comments on commit 610122e

Please sign in to comment.