2020-04-28 09:24:57 -04:00
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Reads the entire configuration and returns it as custom object
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
Reads the entire configuration and returns it as custom object
|
|
|
|
|
.FUNCTIONALITY
|
|
|
|
|
Reads the entire configuration and returns it as custom object
|
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS>Read-IcingaPowerShellConfig;
|
|
|
|
|
.OUTPUTS
|
|
|
|
|
System.Object
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/Icinga/icinga-powershell-framework
|
|
|
|
|
#>
|
|
|
|
|
|
2019-10-05 15:56:23 -04:00
|
|
|
function Read-IcingaPowerShellConfig()
|
|
|
|
|
{
|
|
|
|
|
$ConfigDir = Get-IcingaPowerShellConfigDir;
|
|
|
|
|
$ConfigFile = Join-Path -Path $ConfigDir -ChildPath 'config.json';
|
|
|
|
|
|
|
|
|
|
if ($global:IcingaDaemonData.FrameworkRunningAsDaemon) {
|
|
|
|
|
if ($global:IcingaDaemonData.ContainsKey('Config')) {
|
|
|
|
|
return $global:IcingaDaemonData.Config;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (-Not (Test-Path $ConfigFile)) {
|
2020-11-04 03:20:19 -05:00
|
|
|
return (New-Object -TypeName PSObject);
|
2019-10-05 15:56:23 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-22 11:28:07 -05:00
|
|
|
[string]$Content = Read-IcingaFileContent -File $ConfigFile;
|
2019-10-05 15:56:23 -04:00
|
|
|
|
|
|
|
|
if ([string]::IsNullOrEmpty($Content)) {
|
2020-11-04 03:20:19 -05:00
|
|
|
return (New-Object -TypeName PSObject);
|
2019-10-05 15:56:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (ConvertFrom-Json -InputObject $Content);
|
|
|
|
|
}
|