Skip to content

Commit

Permalink
Added DetermineConfigPath function
Browse files Browse the repository at this point in the history
  • Loading branch information
racicLuka committed Oct 11, 2023
1 parent 3d78807 commit cdae7be
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions checkmk_extensions/agent/robotmk_collector.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,7 @@ Set-StrictMode -Version 3.0
$ErrorActionPreference = "Stop"

function Main {
Param (
[parameter(Mandatory=$false, Position=0)]
[string]$ConfigPath
)

#If the path is provided as an argument, use it.
if ($args.Count -gt 0) {
$ConfigPath = $args[0]
}

# If the -ConfigPath parameter is not defined, check the env:MK_CONFDIR environment variable.
# If it is not defined, default to C:\ProgramData\checkmk\agent\config\robotmk.json.
if (!$ConfigPath) {
$ConfigPath = $env:MK_CONFDIR
if (!$ConfigPath) {
$ConfigPath = 'C:\ProgramData\checkmk\agent\config\robotmk.json'
} else {
$ConfigPath += '\robotmk.json'
}
}

$ConfigPath = DetermineConfigPath -ProvidedPath $args
Write-Output "<<<robotmk_v2:sep(10)>>>"

try {
Expand All @@ -43,7 +23,26 @@ function Main {
}
}

function DetermineConfigPath {
[OutputType([string])]
param (
[array]$ProvidedPath
)

#If the path is provided as an argument, use it.
if ($ProvidedPath -ne $null -and $ProvidedPath.Count -gt 0) {
return $ProvidedPath[0]
}

# If the -ConfigPath parameter is not defined, check the env:MK_CONFDIR environment variable.
# If it is not defined, default to C:\ProgramData\checkmk\agent\config\robotmk.json.
$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 @@ -73,4 +72,4 @@ function GetResultsDirectory {
return $configData.results_directory -as [string]
}

Main
Main $args

0 comments on commit cdae7be

Please sign in to comment.