├── LICENSE ├── PSScriptAnalyzerSettings.psd1 ├── README.md ├── cache ├── README.md └── framework_cache.psm1 ├── custom ├── lib │ └── README.md └── plugins │ └── README.md ├── doc ├── 000-Introduction.md ├── 100-General │ ├── 01-Upgrading.md │ ├── 10-Changelog.md │ ├── 20-Eventlog.md │ └── 90-Roadmap.md ├── 110-Installation │ ├── 01-Getting-Started.md │ ├── 02-Icinga-Management-Console.md │ ├── 03-Installation-with-IMC.md │ ├── 04-Installation-Templates.md │ ├── 05-Background-Daemons.md │ ├── 06-Collect-Metrics-over-Time.md │ ├── 20-Install-Components.md │ ├── 30-API-Check-Forwarder.md │ ├── 40-Grafana-Integration.md │ └── 50-Windows-Terminal.md ├── 111-Updates-and-Uninstallation │ ├── 01-Update-Environment.md │ └── 02-Uninstall-Components.md ├── 120-Repository-Manager │ ├── 01-Add-Repositories.md │ ├── 02-Sync-Repositories.md │ ├── 03-Manage-Repositories.md │ ├── 04-Search-Repository.md │ ├── 05-Install-Components.md │ ├── 06-Pinning-Versions.md │ └── 07-Create-Own-Repositories.md ├── 130-JEA │ ├── 01-JEA-Profiles.md │ ├── 02-Installation.md │ └── 03-Uninstallation.md ├── 160-Features │ ├── 01-Enable-Proxy-Server.md │ ├── 02-Disable-Certificate-Validation.md │ ├── 03-Analyse-EventLog.md │ ├── 04-Manage-Icinga-Agent-Features.md │ ├── 05-Read-Icinga-Agent-Logs.md │ ├── 06-Test-Icinga-Installation.md │ ├── 07-Flush-Icinga-Agent-API-Directory.md │ └── 20-Change-Icinga-Service-User.md ├── 200-Icinga-Integration │ ├── 01-Director-Baskets.md │ ├── 02-Manual-Integration.md │ ├── 03-PowerShell-Arrays.md │ └── 04-Icinga-Config.md ├── 300-Knowledge-Base.md ├── 900-Developer-Guide │ ├── 00-General.md │ ├── 01-New-IcingaCheck.md │ ├── 02-New-IcingaCheckPackage.md │ ├── 03-New-IcingaCheckResult.md │ ├── 10-Custom-Daemons.md │ ├── 11-Custom-Plugins.md │ ├── 12-Custom-API-Endpoints.md │ ├── 20-Using-Console-Outputs.md │ ├── 21-Using-EventLog-Outputs.md │ ├── 50-Fetching-CIM-and-WMI-Data.md │ ├── 51-Working-with-Performance-Counters.md │ └── 52-Testing-of-Commands.md ├── 950-Deprecated │ ├── 01-Kickstart-Script.md │ ├── 02-Manual-Installation.md │ ├── 03-PowerShell-Gallery-Installation.md │ ├── 04-Icinga-Agent-Wizard.md │ ├── 05-Install-Wizard-Guide.md │ ├── 06-Enable-Framework-Code-Caching.md │ └── 07-Update-Framework-And-Components.md ├── frameworkusage │ ├── 34-Uninstall-Icinga-Agent.md │ └── 35-Install-Update-Icinga-Agent.md ├── images │ ├── 01_architecture │ │ └── architecture.png │ ├── 02_icons │ │ ├── framework.png │ │ ├── hyperv.png │ │ ├── iis.png │ │ ├── inventory.png │ │ ├── kickstart.png │ │ ├── mssql.png │ │ ├── plugins.png │ │ └── restapi.png │ ├── 03_windows_terminal │ │ ├── icinga_shell.png │ │ └── icingawhite.png │ ├── 04_knowledgebase │ │ ├── IWKB000002 │ │ │ ├── 01_Plugin_Output_Error.png │ │ │ ├── 02_Director_Config.png │ │ │ └── 03_Fixed_Output.png │ │ ├── IWKB000008 │ │ │ └── 01_EventLog_Error.png │ │ ├── IWKB000012 │ │ │ └── 01_Defender_Log.png │ │ ├── IWKB000013 │ │ │ └── 01_Cert_Not_Signed.png │ │ ├── IWKB000014 │ │ │ └── 01_framework_cache_exception.png │ │ ├── IWKB000015 │ │ │ ├── 01_stringescape.png │ │ │ └── 02_stringescaped_correctly.png │ │ └── IWKB000018 │ │ │ ├── 01_cert_store.png │ │ │ ├── 02_manage_private_keys.png │ │ │ ├── 03_add_networkservice_user.png │ │ │ └── 04_set_permission_and_apply.png │ └── 05_installation │ │ ├── 01_grafana │ │ ├── 01_import_dashboard.png │ │ ├── 02_settings_icon.png │ │ ├── 03_example_overview.png │ │ ├── 04_save_icon.png │ │ └── 05_save_dashboard.png │ │ └── 02_ifw-api │ │ └── 01_powershell_base.png └── knowledgebase │ ├── IWKB000001.md │ ├── IWKB000002.md │ ├── IWKB000003.md │ ├── IWKB000004.md │ ├── IWKB000005.md │ ├── IWKB000006.md │ ├── IWKB000007.md │ ├── IWKB000008.md │ ├── IWKB000009.md │ ├── IWKB000010.md │ ├── IWKB000011.md │ ├── IWKB000012.md │ ├── IWKB000013.md │ ├── IWKB000014.md │ ├── IWKB000015.md │ ├── IWKB000016.md │ ├── IWKB000017.md │ ├── IWKB000018.md │ └── IWKB000019.md ├── icinga-powershell-framework.psd1 ├── icinga-powershell-framework.psm1 ├── jobs ├── GetWindowsService.ps1 ├── RenewCertificate.ps1 ├── RestartWindowsService.ps1 ├── SetProcessPriority.ps1 ├── StartWindowsService.ps1 └── StopWindowsService.ps1 ├── lib ├── apis │ ├── Get-IcingaDirectorSelfServiceConfig.psm1 │ ├── Get-IcingaDirectorSelfServiceTicket.psm1 │ └── Register-IcingaDirectorSelfServiceHost.psm1 ├── config │ ├── Get-IcingaConfigTreeCount.psm1 │ ├── Get-IcingaPowerShellConfig.psm1 │ ├── New-IcingaPowerShellConfigItem.psm1 │ ├── Read-IcingaPowerShellConfig.psm1 │ ├── Remove-IcingaPowerShellConfig.psm1 │ ├── Set-IcingaPowerShellConfig.psm1 │ ├── Test-IcingaPowerShellConfigItem.psm1 │ └── Write-IcingaPowerShellConfig.psm1 ├── core │ ├── cache │ │ ├── Copy-IcingaCacheTempFile.psm1 │ │ ├── Get-IcingaCacheData.psm1 │ │ ├── Set-IcingaCacheData.psm1 │ │ └── Test-IcingaCacheDataTempFile.psm1 │ ├── dev │ │ ├── Get-IcingaForWindowsComponentPublicFunctions.psm1 │ │ ├── New-IcingaForWindowsComponent.psm1 │ │ ├── Open-IcingaForWindowsComponentInEditor.psm1 │ │ ├── Publish-IcingaForWindowsComponent.psm1 │ │ ├── Test-IcingaForWindowsComponent.psm1 │ │ ├── Test-IcingaForWindowsComponentPublicFunctions.psm1 │ │ ├── Update-IcingaForWindowsManifestArray.psm1 │ │ ├── Write-IcingaForWindowsComponentCompilationFile.psm1 │ │ └── Write-IcingaForWindowsComponentManifest.psm1 │ ├── docs │ │ ├── Add-IcingaDocumentContent.psm1 │ │ ├── New-IcingaDocumentObject.psm1 │ │ ├── Publish-IcingaEventlogDocumentation.psm1 │ │ └── Write-IcingaDocumentFile.psm1 │ ├── framework │ │ ├── Clear-IcingaCheckSchedulerCheckData.psm1 │ │ ├── Clear-IcingaCheckSchedulerEnvironment.psm1 │ │ ├── Copy-ItemSecure.psm1 │ │ ├── Disable-IcingaFrameworkApiChecks.psm1 │ │ ├── Disable-IcingaFrameworkConsoleOutput.psm1 │ │ ├── Disable-IcingaFrameworkDebugMode.psm1 │ │ ├── Enable-IcingaFrameworkApiChecks.psm1 │ │ ├── Enable-IcingaFrameworkConsoleOutput.psm1 │ │ ├── Enable-IcingaFrameworkDebugMode.psm1 │ │ ├── Expand-IcingaZipArchive.psm1 │ │ ├── Get-IcingaCheckSchedulerCheckData.psm1 │ │ ├── Get-IcingaCheckSchedulerPerfData.psm1 │ │ ├── Get-IcingaCheckSchedulerPluginOutput.psm1 │ │ ├── Get-IcingaFrameworkApiChecks.psm1 │ │ ├── Get-IcingaFrameworkDebugMode.psm1 │ │ ├── Get-IcingaFrameworkServiceBinary.psm1 │ │ ├── Get-IcingaPowerShellModuleArchive.psm1 │ │ ├── Get-IcingaPowerShellModuleVersion.psm1 │ │ ├── Get-IcingaPrivateEnvironmentVariable.psm1 │ │ ├── Get-IcingaTimer.psm1 │ │ ├── Install-IcingaForWindowsService.psm1 │ │ ├── Install-IcingaFrameworkComponent.psm1 │ │ ├── Install-IcingaFrameworkPlugins.psm1 │ │ ├── Install-IcingaFrameworkUpdate.psm1 │ │ ├── Invoke-IcingaForWindowsMigration.psm1 │ │ ├── Invoke-IcingaInternalServiceCall.psm1 │ │ ├── Invoke-IcingaNamespaceCmdlets.psm1 │ │ ├── New-IcingaEnvironmentVariable.psm1 │ │ ├── Publish-IcingaPluginConfiguration.psm1 │ │ ├── Publish-IcingaPluginDocumentation.psm1 │ │ ├── Read-IcingaForWindowsLog.psm1 │ │ ├── Read-IcingaWindowsEventLog.psm1 │ │ ├── Remove-ItemSecure.psm1 │ │ ├── Restart-IcingaService.psm1 │ │ ├── Set-IcingaForWindowsMigration.psm1 │ │ ├── Set-IcingaPrivateEnvironmentVariable.psm1 │ │ ├── Show-IcingaTimer.psm1 │ │ ├── Start-IcingaService.psm1 │ │ ├── Start-IcingaTimer.psm1 │ │ ├── Stop-IcingaService.psm1 │ │ ├── Stop-IcingaTimer.psm1 │ │ ├── Test-IcingaForWindowsMigration.psm1 │ │ ├── Test-IcingaForWindowsService.psm1 │ │ ├── Test-IcingaFrameworkConsoleOutput.psm1 │ │ ├── Test-IcingaTimer.psm1 │ │ ├── Test-IcingaZipBinaryChecksum.psm1 │ │ ├── Unblock-IcingaPowerShellFiles.psm1 │ │ ├── Uninstall-IcingaForWindows.psm1 │ │ ├── Uninstall-IcingaForWindowsService.psm1 │ │ └── Uninstall-IcingaFrameworkComponent.psm1 │ ├── health │ │ └── interceptcounter │ │ │ ├── Disable-IcingaInterceptCounter.psm1 │ │ │ ├── Enable-IcingaInterceptCounter.psm1 │ │ │ └── Test-IcingaInterceptCounter.psm1 │ ├── icingaagent │ │ ├── finders │ │ │ └── Find-IcingaAgentObjects.psm1 │ │ ├── firewall │ │ │ ├── Disable-IcingaFirewall.psm1 │ │ │ ├── Enable-IcingaFirewall.psm1 │ │ │ └── Get-IcingaFirewallConfig.psm1 │ │ ├── getters │ │ │ ├── Get-IcingaAgentArchitecture.psm1 │ │ │ ├── Get-IcingaAgentBinary.psm1 │ │ │ ├── Get-IcingaAgentConfigDirectory.psm1 │ │ │ ├── Get-IcingaAgentFeatures.psm1 │ │ │ ├── Get-IcingaAgentHostCertificate.psm1 │ │ │ ├── Get-IcingaAgentInstallation.psm1 │ │ │ ├── Get-IcingaAgentInstallerAnswerInput.psm1 │ │ │ ├── Get-IcingaAgentLogDirectory.psm1 │ │ │ ├── Get-IcingaAgentMSIPackage.psm1 │ │ │ ├── Get-IcingaAgentObjectList.psm1 │ │ │ ├── Get-IcingaAgentRootDirectory.psm1 │ │ │ ├── Get-IcingaAgentServicePermission.psm1 │ │ │ ├── Get-IcingaAgentVersion.psm1 │ │ │ ├── Get-IcingaHostname.psm1 │ │ │ ├── Get-IcingaNetbiosName.psm1 │ │ │ └── Get-IcingaServiceUser.psm1 │ │ ├── installer │ │ │ ├── Install-IcingaAgent.psm1 │ │ │ ├── Install-IcingaAgentBaseFeatures.psm1 │ │ │ ├── Install-IcingaAgentCertificates.psm1 │ │ │ └── Uninstall-IcingaAgent.psm1 │ │ ├── misc │ │ │ ├── Clear-IcingaAgentApiDirectory.psm1 │ │ │ ├── Compare-IcingaVersions.psm1 │ │ │ ├── Convert-IcingaDirectorSelfServiceArguments.psm1 │ │ │ ├── Disable-IcingaAgentFeature.psm1 │ │ │ ├── Enable-IcingaAgentFeature.psm1 │ │ │ ├── Move-IcingaAgentDefaultConfig.psm1 │ │ │ ├── Reset-IcingaAgentConfigFile.psm1 │ │ │ ├── Show-IcingaAgentObjects.psm1 │ │ │ ├── Split-IcingaVersion.psm1 │ │ │ ├── Start-IcingaAgentDirectorWizard.psm1 │ │ │ └── Start-IcingaAgentInstallWizard.psm1 │ │ ├── readers │ │ │ ├── Read-IcingaAgentDebugLogFile.psm1 │ │ │ ├── Read-IcingaAgentLogFile.psm1 │ │ │ └── Read-IcingaStateFile.psm1 │ │ ├── repair │ │ │ ├── Repair-IcingaService.psm1 │ │ │ └── Repair-IcingaStateFile.psm1 │ │ ├── setters │ │ │ ├── Set-IcingaAcl.psm1 │ │ │ ├── Set-IcingaAgentNodeName.psm1 │ │ │ ├── Set-IcingaAgentServicePermission.psm1 │ │ │ ├── Set-IcingaAgentServiceUser.psm1 │ │ │ ├── Set-IcingaServiceEnvironment.psm1 │ │ │ └── Set-IcingaUserPermissions.psm1 │ │ ├── tests │ │ │ ├── Test-IcingaAcl.psm1 │ │ │ ├── Test-IcingaAgent.psm1 │ │ │ ├── Test-IcingaAgentConfig.psm1 │ │ │ ├── Test-IcingaAgentFeatureEnabled.psm1 │ │ │ ├── Test-IcingaAgentNETFrameworkDependency.psm1 │ │ │ ├── Test-IcingaAgentServicePermission.psm1 │ │ │ ├── Test-IcingaForWindows.psm1 │ │ │ └── Test-IcingaStateFile.psm1 │ │ └── writers │ │ │ ├── Write-IcingaAgentApiConfig.psm1 │ │ │ ├── Write-IcingaAgentEventLogConfig.psm1 │ │ │ ├── Write-IcingaAgentObjectList.psm1 │ │ │ ├── Write-IcingaAgentZonesConfig.psm1 │ │ │ └── Write-IcingaTestOutput.psm1 │ ├── installer │ │ ├── Install-Icinga.psm1 │ │ ├── Start-IcingaForWindowsInstallation.psm1 │ │ ├── menu │ │ │ ├── installation │ │ │ │ ├── AdvancedEntries.psm1 │ │ │ │ ├── agent │ │ │ │ │ ├── AgentDirectory.psm1 │ │ │ │ │ ├── AgentServicePassword.psm1 │ │ │ │ │ ├── AgentUser.psm1 │ │ │ │ │ ├── AgentVersion.psm1 │ │ │ │ │ └── InstallAgent.psm1 │ │ │ │ ├── certificate │ │ │ │ │ ├── EnterIcingaCAFile.psm1 │ │ │ │ │ ├── EnterIcingaTicket.psm1 │ │ │ │ │ └── SelectCertificate.psm1 │ │ │ │ ├── director │ │ │ │ │ ├── DirectorTemplate.psm1 │ │ │ │ │ ├── DirectorUrl.psm1 │ │ │ │ │ ├── RegisterHost.psm1 │ │ │ │ │ ├── SelfServiceConfig.psm1 │ │ │ │ │ └── SelfServiceKey.psm1 │ │ │ │ ├── firewall │ │ │ │ │ └── SelectOpenWindowsFirewall.psm1 │ │ │ │ ├── framework │ │ │ │ │ ├── IcingaRepository.psm1 │ │ │ │ │ ├── InstallApiChecks.psm1 │ │ │ │ │ ├── InstallJEA.psm1 │ │ │ │ │ └── ServiceRecovery.psm1 │ │ │ │ ├── general │ │ │ │ │ ├── ConfigurationSummary.psm1 │ │ │ │ │ ├── ContinueConfiguration.psm1 │ │ │ │ │ ├── FinishInstaller.psm1 │ │ │ │ │ ├── InstallWindows.psm1 │ │ │ │ │ ├── InstallationAnswerFile.psm1 │ │ │ │ │ ├── InstallationConfigString.psm1 │ │ │ │ │ ├── InstallationFileExport.psm1 │ │ │ │ │ └── NewConfiguration.psm1 │ │ │ │ ├── icinga │ │ │ │ │ ├── EnterCustomHostname.psm1 │ │ │ │ │ ├── EnterIcingaParentAddresses.psm1 │ │ │ │ │ ├── EnterIcingaParentNodes.psm1 │ │ │ │ │ ├── EnterIcingaParentZone.psm1 │ │ │ │ │ ├── ForceCertificateGeneration.psm1 │ │ │ │ │ ├── IcingaCAServer.psm1 │ │ │ │ │ ├── IcingaPort.psm1 │ │ │ │ │ ├── SelectConnection.psm1 │ │ │ │ │ └── SelectHostname.psm1 │ │ │ │ ├── ifwservice │ │ │ │ │ ├── EnterWindowsServicePackageSource.psm1 │ │ │ │ │ ├── SelectInstallService.psm1 │ │ │ │ │ └── WindowsServiceDirectory.psm1 │ │ │ │ ├── plugins │ │ │ │ │ ├── EnterPluginsPackageSource.psm1 │ │ │ │ │ └── InstallIcingaPlugins.psm1 │ │ │ │ └── zones │ │ │ │ │ ├── CustomGlobalZones.psm1 │ │ │ │ │ └── SelectGlobalZones.psm1 │ │ │ ├── manage │ │ │ │ ├── agent │ │ │ │ │ ├── IcingaAgentFeatures.psm1 │ │ │ │ │ └── ReconfigureAgent.psm1 │ │ │ │ ├── framework │ │ │ │ │ ├── FrameworkExperimental.psm1 │ │ │ │ │ ├── IcingaForWindowsFeatures.psm1 │ │ │ │ │ ├── ToogleFrameworkApiChecks.psm1 │ │ │ │ │ ├── ToogleFrameworkDebug.psm1 │ │ │ │ │ ├── components │ │ │ │ │ │ └── ManageComponents.psm1 │ │ │ │ │ ├── daemons │ │ │ │ │ │ ├── ManageBackgroundDaemons.psm1 │ │ │ │ │ │ ├── RegisterBackgroundDaemons.psm1 │ │ │ │ │ │ └── UnregisterBackgroundDaemons.psm1 │ │ │ │ │ ├── jea │ │ │ │ │ │ └── ManageIcingaJEA.psm1 │ │ │ │ │ └── repository │ │ │ │ │ │ ├── DisableRepository.psm1 │ │ │ │ │ │ ├── EnableRepository.psm1 │ │ │ │ │ │ ├── ManageIcingaRepo.psm1 │ │ │ │ │ │ ├── PopRepository.psm1 │ │ │ │ │ │ ├── PushRepository.psm1 │ │ │ │ │ │ ├── RemoveRepository.psm1 │ │ │ │ │ │ ├── SetIcingaSnapshotRepo.psm1 │ │ │ │ │ │ ├── SetIcingaStableRepo.psm1 │ │ │ │ │ │ └── ShowRepositoryList.psm1 │ │ │ │ ├── general │ │ │ │ │ ├── InstallComponents.psm1 │ │ │ │ │ ├── InstallComponentsSnapshot.psm1 │ │ │ │ │ ├── ListOverview.psm1 │ │ │ │ │ ├── Manage.psm1 │ │ │ │ │ ├── RemoveComponents.psm1 │ │ │ │ │ ├── UpdateComponents.psm1 │ │ │ │ │ └── UpdateComponentsSnapshots.psm1 │ │ │ │ ├── settings │ │ │ │ │ ├── logs │ │ │ │ │ │ └── ViewLogs.psm1 │ │ │ │ │ ├── services │ │ │ │ │ │ └── ManageServices.psm1 │ │ │ │ │ └── troubleshooting │ │ │ │ │ │ └── Troubleshooting.psm1 │ │ │ │ └── shell │ │ │ │ │ └── StartIcingaShell.psm1 │ │ │ └── test │ │ │ │ └── ParentEndpoints.psm1 │ │ └── tools │ │ │ ├── AddConfigEntry.psm1 │ │ │ ├── AddDisabledEntry.psm1 │ │ │ ├── Alias.psm1 │ │ │ ├── Clear-CLIConsole.psm1 │ │ │ ├── ClearValuesFromStep.psm1 │ │ │ ├── ConfigEntry.psm1 │ │ │ ├── ConfigurationString.psm1 │ │ │ ├── ConsoleLastParent.psm1 │ │ │ ├── CustomConfig.psm1 │ │ │ ├── DirectorConfigModifyState.psm1 │ │ │ ├── Get-FileEncoding.psm1 │ │ │ ├── GetDisabledEntry.psm1 │ │ │ ├── GetLastParent.psm1 │ │ │ ├── GetPowerShellServicePassword.psm1 │ │ │ ├── JSONConfig.psm1 │ │ │ ├── Menu.psm1 │ │ │ ├── PaginationCache.psm1 │ │ │ ├── RemoveLastParent.psm1 │ │ │ ├── SetCloseIMC.psm1 │ │ │ ├── SetConsoleMenu.psm1 │ │ │ ├── SetPowerShellServicePassword.psm1 │ │ │ ├── SetUpdatingIMC.psm1 │ │ │ ├── SetValuesFromStep.psm1 │ │ │ ├── ShowInstallerMenu.psm1 │ │ │ ├── StepSelection.psm1 │ │ │ ├── TestUpdatingIMC.psm1 │ │ │ ├── ValuesFromStep.psm1 │ │ │ ├── Write-IcingaManagementConsoleCommand.psm1 │ │ │ ├── WriteConfigSwap.psm1 │ │ │ ├── actions │ │ │ ├── ConsoleContinue.psm1 │ │ │ ├── ConsoleDelete.psm1 │ │ │ ├── ConsoleExit.psm1 │ │ │ ├── ConsoleHelp.psm1 │ │ │ ├── ConsoleMenu.psm1 │ │ │ ├── ConsolePrevious.psm1 │ │ │ ├── LastInput.psm1 │ │ │ └── ShowYesNoDialog.psm1 │ │ │ └── environment │ │ │ ├── DisableHeaderPrint.psm1 │ │ │ ├── DisableJumpToSummary.psm1 │ │ │ ├── EnableHeaderPrint.psm1 │ │ │ ├── EnableJumpToSummary.psm1 │ │ │ ├── GetHeaderSelection.psm1 │ │ │ ├── HeaderPrint.psm1 │ │ │ ├── JumpToSummary.psm1 │ │ │ └── SetHeaderSelection.psm1 │ ├── jea │ │ ├── Deny-IcingaJEACommand.psm1 │ │ ├── Get-IcingaCommandDependency.psm1 │ │ ├── Get-IcingaFrameworkDependency.psm1 │ │ ├── Get-IcingaJEAConfiguration.psm1 │ │ ├── Get-IcingaJEAContext.psm1 │ │ ├── Get-IcingaJEAServicePid.psm1 │ │ ├── Get-IcingaJEASessionFile.psm1 │ │ ├── Install-IcingaJeaProfile.psm1 │ │ ├── Read-IcingaPowerShellModuleFile.psm1 │ │ ├── Register-IcingaJEAProfile.psm1 │ │ ├── Remove-IcingaFrameworkDependencyFile.psm1 │ │ ├── Set-IcingaForWindowsServiceJEAProfile.psm1 │ │ ├── Test-IcingaJEAServiceRunning.psm1 │ │ ├── Test-IcingaPowerShellCommandInCode.psm1 │ │ ├── Uninstall-IcingaJEAProfile.psm1 │ │ └── Write-IcingaJEAProfile.psm1 │ ├── logging │ │ ├── Get-IcingaExceptionString.psm1 │ │ ├── Icinga_EventLog_DebugEnums.psm1 │ │ ├── Icinga_EventLog_Enums.psm1 │ │ ├── Register-IcingaEventLog.psm1 │ │ ├── Register-IcingaForWindowsEventLogEnvironment.psm1 │ │ ├── Unregister-IcingaEventLog.psm1 │ │ ├── Write-IcingaConsoleDebug.psm1 │ │ ├── Write-IcingaConsoleError.psm1 │ │ ├── Write-IcingaConsoleNotice.psm1 │ │ ├── Write-IcingaConsoleOutput.psm1 │ │ ├── Write-IcingaConsolePlain.psm1 │ │ ├── Write-IcingaConsoleWarning.psm1 │ │ ├── Write-IcingaDebugMessage.psm1 │ │ ├── Write-IcingaDeprecated.psm1 │ │ ├── Write-IcingaErrorMessage.psm1 │ │ └── Write-IcingaEventMessage.psm1 │ ├── perfcounter │ │ ├── Add-IcingaPerformanceCounterCache.psm1 │ │ ├── Get-IcingaPerformanceCounterCacheItem.psm1 │ │ ├── Get-IcingaPerformanceCounterDetails.psm1 │ │ ├── New-IcingaPerformanceCounter.psm1 │ │ ├── New-IcingaPerformanceCounterArray.psm1 │ │ ├── New-IcingaPerformanceCounterNullObject.psm1 │ │ ├── New-IcingaPerformanceCounterObject.psm1 │ │ ├── New-IcingaPerformanceCounterResult.psm1 │ │ ├── New-IcingaPerformanceCounterStructure.psm1 │ │ ├── Show-IcingaPerformanceCounterCategories.psm1 │ │ ├── Show-IcingaPerformanceCounterHelp.psm1 │ │ ├── Show-IcingaPerformanceCounterInstances.psm1 │ │ ├── Show-IcingaPerformanceCounters.psm1 │ │ └── Test-IcingaPerformanceCounterCategory.psm1 │ ├── progress │ │ ├── Complete-IcingaProgressStatus.psm1 │ │ ├── New-IcingaProgressStatus.psm1 │ │ └── Write-IcingaProgressStatus.psm1 │ ├── repository │ │ ├── Add-IcingaRepository.psm1 │ │ ├── Add-IcingaRepositoryErrorState.psm1 │ │ ├── Clear-IcingaRepositoryErrorState.psm1 │ │ ├── Disable-IcingaRepository.psm1 │ │ ├── Enable-IcingaRepository.psm1 │ │ ├── Get-IcingaComponentList.psm1 │ │ ├── Get-IcingaComponentLock.psm1 │ │ ├── Get-IcingaForWindowsServiceData.psm1 │ │ ├── Get-IcingaInstallation.psm1 │ │ ├── Get-IcingaRepositories.psm1 │ │ ├── Get-IcingaRepositoryHash.psm1 │ │ ├── Get-IcingaRepositoryPackage.psm1 │ │ ├── Install-IcingaComponent.psm1 │ │ ├── Lock-IcingaComponent.psm1 │ │ ├── New-IcingaRepository.psm1 │ │ ├── New-IcingaRepositoryFile.psm1 │ │ ├── Pop-IcingaRepository.psm1 │ │ ├── Push-IcingaRepository.psm1 │ │ ├── Read-IcingaMSIMetadata.psm1 │ │ ├── Read-IcingaPackageManifest.psm1 │ │ ├── Read-IcingaRepositoryFile.psm1 │ │ ├── Read-IcingaServicePackage.psm1 │ │ ├── Remove-IcingaRepository.psm1 │ │ ├── Search-IcingaRepository.psm1 │ │ ├── Show-Icinga.psm1 │ │ ├── Show-IcingaRepository.psm1 │ │ ├── Sync-IcingaRepository.psm1 │ │ ├── Test-IcingaJSONObject.psm1 │ │ ├── Test-IcingaRepositoryErrorState.psm1 │ │ ├── Test-IcingaValidJSON.psm1 │ │ ├── Uninstall-IcingaComponent.psm1 │ │ ├── Unlock-IcingaComponent.psm1 │ │ ├── Update-Icinga.psm1 │ │ └── Update-IcingaRepository.psm1 │ ├── thread │ │ ├── Add-IcingaThreadPool.psm1 │ │ ├── Get-IcingaThreadPool.psm1 │ │ ├── New-IcingaThreadHash.psm1 │ │ ├── New-IcingaThreadInstance.psm1 │ │ ├── New-IcingaThreadPool.psm1 │ │ ├── Remove-IcingaThread.psm1 │ │ ├── Restart-IcingaThread.psm1 │ │ ├── Set-IcingaEnvironmentGlobal.psm1 │ │ ├── Set-IcingaEnvironmentJEA.psm1 │ │ ├── Set-IcingaEnvironmentThreadName.psm1 │ │ ├── Start-IcingaThread.psm1 │ │ ├── Stop-IcingaThread.psm1 │ │ └── Test-IcingaThread.psm1 │ ├── tools │ │ ├── Add-IcingaAddTypeLib.psm1 │ │ ├── Add-IcingaArrayListItem.psm1 │ │ ├── Add-IcingaHashtableItem.psm1 │ │ ├── Add-IcingaWhiteSpaceToString.psm1 │ │ ├── Add-PSCustomObjectMember.psm1 │ │ ├── Clear-IcingaAddTypeLib.psm1 │ │ ├── Compare-IcingaUnixTimeWithDateTime.psm1 │ │ ├── Convert-Bytes.psm1 │ │ ├── Convert-IcingaCheckArgumentToPSObject.psm1 │ │ ├── Convert-IcingaEndpointsToIP.psm1 │ │ ├── Convert-IcingaPluginThresholds.psm1 │ │ ├── Convert-IcingaPluginValueToString.psm1 │ │ ├── ConvertFrom-IcingaArrayToString.psm1 │ │ ├── ConvertFrom-IcingaSecureString.psm1 │ │ ├── ConvertFrom-JsonUTF8.psm1 │ │ ├── ConvertFrom-Percent.psm1 │ │ ├── ConvertFrom-TimeSpan.psm1 │ │ ├── ConvertTo-ByteUnitIEC.psm1 │ │ ├── ConvertTo-ByteUnitSI.psm1 │ │ ├── ConvertTo-BytesNextUnit.psm1 │ │ ├── ConvertTo-IcingaCommandArgumentString.psm1 │ │ ├── ConvertTo-IcingaIPBinaryString.psm1 │ │ ├── ConvertTo-IcingaIPv4BinaryString.psm1 │ │ ├── ConvertTo-IcingaIPv6BinaryString.psm1 │ │ ├── ConvertTo-IcingaNumericTimeIndex.psm1 │ │ ├── ConvertTo-IcingaPowerShellArguments.psm1 │ │ ├── ConvertTo-IcingaSecureSortedArray.psm1 │ │ ├── ConvertTo-IcingaSecureString.psm1 │ │ ├── ConvertTo-IcingaUTF8Value.psm1 │ │ ├── ConvertTo-IcingaUnixTime.psm1 │ │ ├── ConvertTo-Integer.psm1 │ │ ├── ConvertTo-JsonUTF8Bytes.psm1 │ │ ├── ConvertTo-Seconds.psm1 │ │ ├── Expand-IcingaIPv6String.psm1 │ │ ├── Format-IcingaDigitCount.psm1 │ │ ├── Format-IcingaPerfDataLabel.psm1 │ │ ├── Format-IcingaPerfDataValue.psm1 │ │ ├── Get-IPConfigFromString.psm1 │ │ ├── Get-IcingaCheckCommandConfig.psm1 │ │ ├── Get-IcingaFileHash.psm1 │ │ ├── Get-IcingaHashtableItem.psm1 │ │ ├── Get-IcingaMaxTextLength.psm1 │ │ ├── Get-IcingaNetworkInterface.psm1 │ │ ├── Get-IcingaNetworkInterfaceUnits.psm1 │ │ ├── Get-IcingaNetworkRoute.psm1 │ │ ├── Get-IcingaNextUnitIteration.psm1 │ │ ├── Get-IcingaPSObjectProperties.psm1 │ │ ├── Get-IcingaServices.psm1 │ │ ├── Get-IcingaUnixTime.psm1 │ │ ├── Get-IcingaUnixTimeOffsetNow.psm1 │ │ ├── Get-IcingaUserSID.psm1 │ │ ├── Get-IcingaUsernameFromSID.psm1 │ │ ├── Get-IcingaValue.psm1 │ │ ├── Get-StringSha1.psm1 │ │ ├── Get-UnitPrefixIEC.psm1 │ │ ├── Get-UnitPrefixSI.psm1 │ │ ├── Join-WebPath.psm1 │ │ ├── New-IcingaBasicAuthHeader.psm1 │ │ ├── New-IcingaCheckCommand.psm1 │ │ ├── New-IcingaNewLine.psm1 │ │ ├── New-IcingaTemporaryDirectory.psm1 │ │ ├── New-IcingaTemporaryFile.psm1 │ │ ├── New-IcingaVersionObject.psm1 │ │ ├── New-StringTree.psm1 │ │ ├── Optimize-IcingaForWindowsMemory.psm1 │ │ ├── Pop-IcingaArrayListItem.psm1 │ │ ├── Read-IcingaFileSecure.psm1 │ │ ├── Remove-IcingaDirectorSelfServiceKey.psm1 │ │ ├── Remove-IcingaHashtableItem.psm1 │ │ ├── Set-IcingaPSLocation.psm1 │ │ ├── Set-NumericNegative.psm1 │ │ ├── Show-IcingaDirectorSelfServiceKey.psm1 │ │ ├── Show-IcingaEventLogAnalysis.psm1 │ │ ├── Split-IcingaCheckCommandArgs.psm1 │ │ ├── Split-IcingaUserDomain.psm1 │ │ ├── Start-IcingaProcess.psm1 │ │ ├── Test-AdministrativeShell.psm1 │ │ ├── Test-IcingaAddTypeExist.psm1 │ │ ├── Test-IcingaArrayFilter.psm1 │ │ ├── Test-IcingaBinaryOperator.psm1 │ │ ├── Test-IcingaDecimal.psm1 │ │ ├── Test-IcingaForWindowsCmdletLoader.psm1 │ │ ├── Test-IcingaFunction.psm1 │ │ ├── Test-Numeric.psm1 │ │ ├── Test-PSCustomObjectMember.psm1 │ │ ├── Write-ColoredOutput.psm1 │ │ ├── Write-IcingaConsoleHeader.psm1 │ │ ├── Write-IcingaConsoleTextColorSplit.psm1 │ │ └── Write-IcingaFileSecure.psm1 │ ├── windows │ │ ├── Clear-IcingaWindowsUserPassword.psm1 │ │ ├── Disable-IcingaServiceRecovery.psm1 │ │ ├── Enable-IcingaServiceRecovery.psm1 │ │ ├── Get-IcingaRandomChars.psm1 │ │ ├── Get-IcingaWindowsUserConfig.psm1 │ │ ├── Get-IcingaWindowsUserMetadata.psm1 │ │ ├── Install-IcingaSecurity.psm1 │ │ ├── Install-IcingaServiceUser.psm1 │ │ ├── New-IcingaWindowsUser.psm1 │ │ ├── New-IcingaWindowsUserPassword.psm1 │ │ ├── Remove-IcingaWindowsUser.psm1 │ │ ├── Restart-Icinga.psm1 │ │ ├── Restart-IcingaWindowsService.psm1 │ │ ├── Set-IcingaForWindowsServicesDelayedStart.psm1 │ │ ├── Start-Icinga.psm1 │ │ ├── Start-IcingaForWindows.psm1 │ │ ├── Stop-Icinga.psm1 │ │ ├── Stop-IcingaJEAProcess.psm1 │ │ ├── Stop-IcingaWindowsService.psm1 │ │ ├── Test-IcingaManagedUser.psm1 │ │ ├── Uninstall-IcingaSecurity.psm1 │ │ ├── Uninstall-IcingaServiceUser.psm1 │ │ ├── Update-IcingaServiceUser.psm1 │ │ └── Update-IcingaWindowsUserPermission.psm1 │ └── wintasks │ │ ├── Invoke-IcingaWindowsScheduledTask.psm1 │ │ ├── Invoke-IcingaWindowsServiceHandlerTask.psm1 │ │ ├── Wait-IcingaWindowsScheduledTask.psm1 │ │ └── daemon │ │ ├── Register-TaskIcingaForWindowsProcessPriority.psm1 │ │ ├── Register-TaskRenewCertificate.psm1 │ │ ├── Start-TaskRenewCertificate.psm1 │ │ ├── Start-TaskSetProcessPriority.psm1 │ │ └── Unregister-TaskRenewCertificate.psm1 ├── daemon │ ├── Add-IcingaForWindowsDaemon.psm1 │ ├── Get-IcingaBackgroundDaemons.psm1 │ ├── Get-IcingaForWindowsServicePid.psm1 │ ├── Register-IcingaBackgroundDaemon.psm1 │ ├── Set-IcingaForWindowsThreadAlive.psm1 │ ├── Show-IcingaRegisteredBackgroundDaemons.psm1 │ ├── Start-IcingaPowerShellDaemon.psm1 │ ├── Suspend-IcingaForWindowsFrozenThreads.psm1 │ └── Unregister-IcingaBackgroundDaemon.psm1 ├── daemons │ ├── RestAPI │ │ ├── client │ │ │ ├── Add-IcingaRESTClientBlacklistCount.psm1 │ │ │ ├── Invoke-IcingaRESTAPIv1Calls.psm1 │ │ │ ├── Remove-IcingaRESTClientBlacklist.psm1 │ │ │ ├── Test-IcingaRESTClientBlacklisted.psm1 │ │ │ └── Test-IcingaRESTClientConnection.psm1 │ │ ├── daemon │ │ │ ├── New-IcingaForWindowsRESTApi.psm1 │ │ │ └── Start-IcingaWindowsRESTApi.psm1 │ │ ├── eventlog │ │ │ └── Register-IcingaEventLogMessagesRESTApi.psm1 │ │ ├── threads │ │ │ ├── Get-IcingaNextRESTApiThreadId.psm1 │ │ │ ├── New-IcingaForWindowsCertificateThreadTaskInstance.psm1 │ │ │ ├── New-IcingaForWindowsRESTThread.psm1 │ │ │ ├── Start-IcingaForWindowsCertificateThreadTask.psm1 │ │ │ └── Start-IcingaForWindowsRESTThread.psm1 │ │ └── tools │ │ │ ├── Add-IcingaRESTApiCommand.psm1 │ │ │ ├── New-IcingaForWindowsRESTEnvironment.psm1 │ │ │ ├── Remove-IcingaRESTApiCommand.psm1 │ │ │ ├── Show-IcingaApiCommands.psm1 │ │ │ └── Test-IcingaRESTApiCommand.psm1 │ ├── ServiceCheckDaemon │ │ ├── daemon │ │ │ ├── Add-IcingaServiceCheckDaemon.psm1 │ │ │ └── Start-IcingaServiceCheckDaemon.psm1 │ │ ├── task │ │ │ ├── Add-IcingaServiceCheckTask.psm1 │ │ │ └── Start-IcingaServiceCheckTask.psm1 │ │ └── tools │ │ │ ├── Clear-IcingaServiceCheckDaemonEnvironment.psm1 │ │ │ ├── Get-IcingaRegisteredServiceChecks.psm1 │ │ │ ├── New-IcingaServiceCheckDaemonEnvironment.psm1 │ │ │ ├── Read-IcingaCheckResultStore.psm1 │ │ │ ├── Register-IcingaServiceCheck.psm1 │ │ │ ├── Set-IcingaRegisteredServiceCheckConfig.psm1 │ │ │ ├── Show-IcingaRegisteredServiceChecks.psm1 │ │ │ └── Unregister-IcingaServiceCheck.psm1 │ └── modules │ │ └── ApiChecks │ │ ├── Invoke-IcingaApiChecksRESTCall.psm1 │ │ └── apichecks.psm1 ├── help │ └── help │ │ └── Get-IcingaHelpThresholds.psm1 ├── icinga │ ├── enums │ │ ├── Get-IcingaProviderEnumData.psm1 │ │ ├── Icinga_IcingaEnums.psm1 │ │ └── Test-IcingaWindowsInfoEnums.psm1 │ ├── exception │ │ ├── Exit-IcingaPluginNotInstalled.psm1 │ │ ├── Exit-IcingaThrowCritical.psm1 │ │ ├── Exit-IcingaThrowException.psm1 │ │ ├── Get-IcingaLastExceptionId.psm1 │ │ └── Icinga_IcingaExceptionEnums.psm1 │ └── plugin │ │ ├── Compare-IcingaPluginThresholds.psm1 │ │ ├── Compare-IcingaPluginValueToThreshold.psm1 │ │ ├── Convert-IcingaPluginThresholdsFromPercent.psm1 │ │ ├── ConvertTo-IcingaMetricsOverTime.psm1 │ │ ├── ConvertTo-IcingaPluginOutputTranslation.psm1 │ │ ├── Exit-IcingaExecutePlugin.psm1 │ │ ├── Get-IcingaInternalPluginExitCode.psm1 │ │ ├── Get-IcingaInternalPluginOutput.psm1 │ │ ├── Get-IcingaMetricsOverTimePerfData.psm1 │ │ ├── Get-IcingaThresholdCache.psm1 │ │ ├── New-IcingaCheck.psm1 │ │ ├── New-IcingaCheckBaseObject.psm1 │ │ ├── New-IcingaCheckPackage.psm1 │ │ ├── New-IcingaCheckResult.psm1 │ │ ├── New-IcingaPerformanceDataEntry.psm1 │ │ ├── Set-IcingaInternalPluginException.psm1 │ │ ├── Set-IcingaInternalPluginExitCode.psm1 │ │ ├── Write-IcingaExecutePluginException.psm1 │ │ ├── Write-IcingaPluginOutput.psm1 │ │ ├── Write-IcingaPluginPerfData.psm1 │ │ └── Write-IcingaPluginResult.psm1 ├── mssql │ ├── Close-IcingaMSSQLConnection.psm1 │ ├── Get-IcingaMSSQLInstanceName.psm1 │ ├── New-IcingaMSSQLCommand.psm1 │ ├── Open-IcingaMSSQLConnection.psm1 │ └── Send-IcingaMSSQLCommand.psm1 ├── provider │ ├── assets │ │ ├── cpu │ │ │ ├── Get-IcingaProviderDataValuesCpu.psm1 │ │ │ └── New-IcingaProviderFilterDataCpu.psm1 │ │ ├── hyperv │ │ │ └── Get-IcingaProviderDataValuesHyperV.psm1 │ │ └── process │ │ │ └── Get-IcingaProviderDataValuesProcess.psm1 │ ├── core │ │ ├── Get-IcingaProviderData.psm1 │ │ ├── Get-IcingaProviderElement.psm1 │ │ ├── Get-IcingaProviderFilterData.psm1 │ │ ├── New-IcingaProviderFilterObject.psm1 │ │ └── New-IcingaProviderObject.psm1 │ └── logging │ │ ├── Add-IcingaProviderEventlogFilterData.psm1 │ │ ├── Get-IcingaProviderDataValuesEventlog.psm1 │ │ └── New-IcingaProviderFilterDataEventlog.psm1 ├── web │ ├── Disable-IcingaProgressPreference.psm1 │ ├── Get-IcingaFrameworkProxyServer.psm1 │ ├── Invoke-IcingaWebRequest.psm1 │ ├── Set-IcingaFrameworkProxyServer.psm1 │ └── Set-IcingaTLSVersion.psm1 ├── webserver │ ├── Close-IcingaTCPConnection.psm1 │ ├── Close-IcingaTCPSocket.psm1 │ ├── Convert-Base64ToCredentials.psm1 │ ├── ConvertTo-IcingaX509Certificate.psm1 │ ├── Disable-IcingaUntrustedCertificateValidation.psm1 │ ├── Enable-IcingaUntrustedCertificateValidation.psm1 │ ├── Get-IcingaForWindowsCertificate.psm1 │ ├── Get-IcingaRESTHeaderValue.psm1 │ ├── Get-IcingaRESTPathElement.psm1 │ ├── Get-IcingaSSLCertForSocket.psm1 │ ├── Get-IcingaTCPClientRemoteEndpoint.psm1 │ ├── Icinga_HTTPResponse_Enums.psm1 │ ├── Import-IcingaCAToAuthRoot.psm1 │ ├── Install-IcingaForWindowsCertificate.psm1 │ ├── Invoke-IcingaForWindowsRESTApi.psm1 │ ├── New-IcingaSSLStream.psm1 │ ├── New-IcingaTCPClient.psm1 │ ├── New-IcingaTCPClientRESTMessage.psm1 │ ├── New-IcingaTCPSocket.psm1 │ ├── Open-IcingaTCPClientConnection.psm1 │ ├── Read-IcingaRESTMessage.psm1 │ ├── Read-IcingaTCPStream.psm1 │ ├── Send-IcingaTCPClientMessage.psm1 │ ├── Send-IcingaWebAuthMessage.psm1 │ ├── Test-IcingaCAInstalledToAuthRoot.psm1 │ ├── Test-IcingaForWindowsCertificate.psm1 │ └── Test-IcingaRESTCredentials.psm1 └── wmi │ ├── Add-IcingaWmiPermissions.psm1 │ ├── Get-IcingaWindowsInformation.psm1 │ ├── Get-IcingaWmiSecurityData.psm1 │ ├── Icinga_WBEM_Security.psm1 │ ├── New-IcingaWmiPermissionMask.psm1 │ ├── Remove-IcingaWmiPermissions.psm1 │ ├── Test-IcingaWindowsInformation.psm1 │ └── Test-IcingaWmiPermissions.psm1 └── templates ├── IcingaForWindows.psrc.template ├── IcingaForWindows.pssc.template ├── Manifest.psd1.template ├── PSScriptAnalyzerSettings.psd1.template ├── compilation.psm1.template └── framework_cache.psm1.template /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Icinga 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /cache/README.md: -------------------------------------------------------------------------------- 1 | # Cache folder 2 | 3 | Every content the module requires to run efficiently will be stored within this folder. The module will ensure housekeeping here to not spam the filesystem 4 | -------------------------------------------------------------------------------- /custom/lib/README.md: -------------------------------------------------------------------------------- 1 | # Custom Libraries 2 | 3 | Here you can place your own libraries for the module. You can either extend the module with this or override existing libraries without having to worry about breaking future updates 4 | -------------------------------------------------------------------------------- /custom/plugins/README.md: -------------------------------------------------------------------------------- 1 | # Custom Plugins 2 | 3 | Here you can place your own custom plugins or override existing ones. This will ensure future updates of the module will not rever your changes 4 | -------------------------------------------------------------------------------- /doc/160-Features/01-Enable-Proxy-Server.md: -------------------------------------------------------------------------------- 1 | # Enable Proxy Server 2 | 3 | With Icinga PowerShell Framework v1.3.0 we added support for using Proxy servers while using web requests to download and fetch information. For this we added a custom function `Invoke-IcingaWebRequest` as wrapper function for `Invoke-WebRequest`. 4 | 5 | ## Enable Proxy Server Support 6 | 7 | To enable the proxy server support, you simply have to use the Cmdlet `Set-IcingaFrameworkProxyServer` and set your proxy server: 8 | 9 | ```powershell 10 | Set-IcingaFrameworkProxyServer -Server 'http://example.com:8080'; 11 | ``` 12 | 13 | Once set, the Framework will automatically use this server configuration for all web requests. 14 | 15 | ## Disable Proxy Server Support 16 | 17 | To disable the proxy server, you can use the same Cmdlet again, but leaving the argument empty. 18 | 19 | ```powershell 20 | Set-IcingaFrameworkProxyServer; 21 | ``` 22 | 23 | Now all web requests are executed without the proxy server. 24 | -------------------------------------------------------------------------------- /doc/160-Features/02-Disable-Certificate-Validation.md: -------------------------------------------------------------------------------- 1 | # Disable Certificate Validation 2 | 3 | In some cases it might be required to disable checks for certificates while performing web requests. This is especially true while using self signed certificates which are not installed on the local Windows machine. 4 | 5 | ## Disable Validation 6 | 7 | To disable the certificate check for the entire certificate chain, you can simply use the following command within an Icinga Shell: 8 | 9 | ```powershell 10 | Enable-IcingaUntrustedCertificateValidation 11 | ``` 12 | 13 | Once enabled, certificates will no longer be checked while using this PowerShell instance. Web calls by using `Invoke-WebRequest` or `Invoke-IcingaWebRequest` will proceed, regardless of the certificate behind and possible SSL/TLS errors. 14 | 15 | ## Enable Validation 16 | 17 | To enable the validation again, you will have to close the PowerShell session and create a new one. There is no Cmdlet available to enable it again. 18 | -------------------------------------------------------------------------------- /doc/160-Features/07-Flush-Icinga-Agent-API-Directory.md: -------------------------------------------------------------------------------- 1 | # Flush Icinga Agent API Directory 2 | 3 | In some cases it might be helpful or required to flush the local Icinga Agent API directory from the disk. To assist with this process, there is a simple Cmdlet available. 4 | 5 | ## Delete the API Directory Content 6 | 7 | To flush the content, you will have to stop the Icinga Agent service and run the following Cmdlet within an Icinga Shell: 8 | 9 | ```powershell 10 | Clear-IcingaAgentApiDirectory 11 | ``` 12 | 13 | ## Delete API Directory with automated Icinga Agent handling 14 | 15 | In case you want to automate the process, you can add the `-Force` argument which will stop the Icinga Agent service for you, flush the API directory content and start the Icinga Agent afterwards again: 16 | 17 | ```powershell 18 | Clear-IcingaAgentApiDirectory -Force 19 | ``` 20 | -------------------------------------------------------------------------------- /doc/950-Deprecated/03-PowerShell-Gallery-Installation.md: -------------------------------------------------------------------------------- 1 | # Install the Framework with PowerShell Gallery 2 | 3 | PowerShell Gallery provides a collection of PowerShell modules and scripts which can easily be installed on target machines. For a further description, please have a look on the [PowerShell Gallery website](https://www.powershellgallery.com/). 4 | 5 | ## Getting Started 6 | 7 | Icinga is providing PowerShell Gallery packages within the [Icinga Profile](https://www.powershellgallery.com/profiles/Icinga) for the Framework itself and other related components. 8 | 9 | To install the Icinga PowerShell Framework you can simply use `Install-Module` in case it is available and configured on your system: 10 | 11 | ```powershell 12 | Install-Module -Name icinga-powershell-framework; 13 | ``` 14 | 15 | ## Execute the Icinga Agent installation wizard 16 | 17 | Once the entire Framework is installed and the module is runnable, you can start the Icinga Agent installation wizard. Please follow the [Icinga Agent Wizard](04-Icinga-Agent-Wizard.md) guide for examples and usage. 18 | -------------------------------------------------------------------------------- /doc/950-Deprecated/06-Enable-Framework-Code-Caching.md: -------------------------------------------------------------------------------- 1 | # Framework Code Caching 2 | 3 | By default, Icinga for Windows will compile all module files into a single cache file for quicker and easier loading. This ensures, that during startup all functions are available and can be used in combination with JEA profiles. 4 | 5 | The location of the cache file is at 6 | 7 | ``` 8 | .\cache\framework_cache.psm1 9 | ``` 10 | 11 | ## Pre-Cautions 12 | 13 | In case you are running custom modifications to the Framework or apply manual patches, you will **always** have to re-write the Icinga for Windows cache file! During upgrades by using the Icinga for Windows Cmdlets, the cache file is updated automatically. 14 | 15 | ## Updating Cache File 16 | 17 | To re-write the cache file and update it to the latest version manually, you can use the following command: 18 | 19 | ```powershell 20 | Write-IcingaFrameworkCodeCache 21 | ``` 22 | -------------------------------------------------------------------------------- /doc/images/01_architecture/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/01_architecture/architecture.png -------------------------------------------------------------------------------- /doc/images/02_icons/framework.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/02_icons/framework.png -------------------------------------------------------------------------------- /doc/images/02_icons/hyperv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/02_icons/hyperv.png -------------------------------------------------------------------------------- /doc/images/02_icons/iis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/02_icons/iis.png -------------------------------------------------------------------------------- /doc/images/02_icons/inventory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/02_icons/inventory.png -------------------------------------------------------------------------------- /doc/images/02_icons/kickstart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/02_icons/kickstart.png -------------------------------------------------------------------------------- /doc/images/02_icons/mssql.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/02_icons/mssql.png -------------------------------------------------------------------------------- /doc/images/02_icons/plugins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/02_icons/plugins.png -------------------------------------------------------------------------------- /doc/images/02_icons/restapi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/02_icons/restapi.png -------------------------------------------------------------------------------- /doc/images/03_windows_terminal/icinga_shell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/03_windows_terminal/icinga_shell.png -------------------------------------------------------------------------------- /doc/images/03_windows_terminal/icingawhite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/03_windows_terminal/icingawhite.png -------------------------------------------------------------------------------- /doc/images/04_knowledgebase/IWKB000002/01_Plugin_Output_Error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/04_knowledgebase/IWKB000002/01_Plugin_Output_Error.png -------------------------------------------------------------------------------- /doc/images/04_knowledgebase/IWKB000002/02_Director_Config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/04_knowledgebase/IWKB000002/02_Director_Config.png -------------------------------------------------------------------------------- /doc/images/04_knowledgebase/IWKB000002/03_Fixed_Output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/04_knowledgebase/IWKB000002/03_Fixed_Output.png -------------------------------------------------------------------------------- /doc/images/04_knowledgebase/IWKB000008/01_EventLog_Error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/04_knowledgebase/IWKB000008/01_EventLog_Error.png -------------------------------------------------------------------------------- /doc/images/04_knowledgebase/IWKB000012/01_Defender_Log.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/04_knowledgebase/IWKB000012/01_Defender_Log.png -------------------------------------------------------------------------------- /doc/images/04_knowledgebase/IWKB000013/01_Cert_Not_Signed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/04_knowledgebase/IWKB000013/01_Cert_Not_Signed.png -------------------------------------------------------------------------------- /doc/images/04_knowledgebase/IWKB000014/01_framework_cache_exception.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/04_knowledgebase/IWKB000014/01_framework_cache_exception.png -------------------------------------------------------------------------------- /doc/images/04_knowledgebase/IWKB000015/01_stringescape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/04_knowledgebase/IWKB000015/01_stringescape.png -------------------------------------------------------------------------------- /doc/images/04_knowledgebase/IWKB000015/02_stringescaped_correctly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/04_knowledgebase/IWKB000015/02_stringescaped_correctly.png -------------------------------------------------------------------------------- /doc/images/04_knowledgebase/IWKB000018/01_cert_store.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/04_knowledgebase/IWKB000018/01_cert_store.png -------------------------------------------------------------------------------- /doc/images/04_knowledgebase/IWKB000018/02_manage_private_keys.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/04_knowledgebase/IWKB000018/02_manage_private_keys.png -------------------------------------------------------------------------------- /doc/images/04_knowledgebase/IWKB000018/03_add_networkservice_user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/04_knowledgebase/IWKB000018/03_add_networkservice_user.png -------------------------------------------------------------------------------- /doc/images/04_knowledgebase/IWKB000018/04_set_permission_and_apply.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/04_knowledgebase/IWKB000018/04_set_permission_and_apply.png -------------------------------------------------------------------------------- /doc/images/05_installation/01_grafana/01_import_dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/05_installation/01_grafana/01_import_dashboard.png -------------------------------------------------------------------------------- /doc/images/05_installation/01_grafana/02_settings_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/05_installation/01_grafana/02_settings_icon.png -------------------------------------------------------------------------------- /doc/images/05_installation/01_grafana/03_example_overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/05_installation/01_grafana/03_example_overview.png -------------------------------------------------------------------------------- /doc/images/05_installation/01_grafana/04_save_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/05_installation/01_grafana/04_save_icon.png -------------------------------------------------------------------------------- /doc/images/05_installation/01_grafana/05_save_dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/05_installation/01_grafana/05_save_dashboard.png -------------------------------------------------------------------------------- /doc/images/05_installation/02_ifw-api/01_powershell_base.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icinga-powershell-framework/854ef78f919b4a09f6a75f61a7e7ad8d9fba6a6d/doc/images/05_installation/02_ifw-api/01_powershell_base.png -------------------------------------------------------------------------------- /doc/knowledgebase/IWKB000012.md: -------------------------------------------------------------------------------- 1 | # Icinga Knowledge Base - IWKB000012 2 | 3 | ## Short Message 4 | 5 | Icinga for Windows cannot be used with Microsoft Defender: `Windows Defender Antivirus has detected malware or other potentially unwanted software` 6 | 7 | ## Example Exception 8 | 9 | ![EventLog Defender](../images/04_knowledgebase/IWKB000012/01_Defender_Log.png) 10 | 11 | ## Reason 12 | 13 | Icinga for Windows is using many `Functions` and `Cmdlets` and different `Add-Type` features, to accomplish an overall monitoring of the Windows environment. In some cases it can happen, that false positives are generated, preventing the usage of Icinga for Windows. 14 | 15 | ## Solution 16 | 17 | In case you are running into the above problem, please [open a new issue](https://github.com/Icinga/icinga-powershell-framework/issues) and provide us with as much information as possible, allowing us to verify the problem and providing a solution. 18 | 19 | In addition, please ensure that your Microsoft Defender is up-to-date and the latest patches are installed for the detection engine. 20 | -------------------------------------------------------------------------------- /doc/knowledgebase/IWKB000013.md: -------------------------------------------------------------------------------- 1 | # Icinga Knowledge Base - IWKB000013 2 | 3 | ## Short Message 4 | 5 | The local Icinga Agent certificate seems not to be signed by our Icinga CA yet. Using this certificate for the REST-Api as example might not work yet. Please check the state of the certificate and complete the signing process if required 6 | 7 | ## Example Exception 8 | 9 | ![EventLog Defender](../images/04_knowledgebase/IWKB000013/01_Cert_Not_Signed.png) 10 | 11 | ## Reason 12 | 13 | This warning will occur, whenever Icinga for Windows is fetching the Icinga Agents local certificate, for compiling the `IcingaForWindows.pfx` certificate or by accessing the certificate for dynamically creating the REST-Api TLS certificate. 14 | 15 | ## Solution 16 | 17 | To resolve this issue, you will have to make sure the certificate is signed by the `Icinga CA` by either manually signing the certificate on the `CA master` with `icinga2 ca sign ` or by using a ticket during the setup process for signing the certificate right away. 18 | -------------------------------------------------------------------------------- /doc/knowledgebase/IWKB000017.md: -------------------------------------------------------------------------------- 1 | # Icinga Knowledge Base - IWKB000017 2 | 3 | ## Short Message 4 | 5 | Icinga throws exception during plugin execution after uninstalling SCOM or other vendor software using PowerShell modules 6 | 7 | ## Example Exception 8 | 9 | Icinga throws the exception 10 | 11 | `The Icinga PowerShell Framework is either not installed on the system or not configured properly. Please check https://icinga.com/docs/windows for further details` 12 | 13 | once a plugin is executed from the Icinga Agent after SCOM is uninstalled as example. 14 | 15 | ## Reason 16 | 17 | In some cases uninstalling certain software components which also ship PowerShell modules, like the Microsoft SCOM, Icinga for Windows will stop working. The Icinga Agent will assume that the PowerShell Framework is no longer installed as it cannot find the module afterwards. 18 | 19 | ## Solution 20 | 21 | The simple solution is to restart the Icinga Agent service which will resolve this issue and reload the environment variables. Afterwards the checks will work as before. 22 | 23 | ```powershell 24 | Restart-Icinga 25 | ```` 26 | -------------------------------------------------------------------------------- /jobs/RestartWindowsService.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | [string]$ServiceName = '', 3 | [string]$TmpFilePath = '' 4 | ); 5 | 6 | Use-Icinga -Minimal; 7 | 8 | [bool]$Success = $TRUE; 9 | [string]$ErrMsg = ""; 10 | [string]$Status = ''; 11 | 12 | try { 13 | Restart-Service "$ServiceName" -ErrorAction Stop; 14 | $Status = [string](Get-Service "$ServiceName").Status; 15 | } catch { 16 | $Success = $FALSE; 17 | $ErrMsg = [string]::Format('Failed to restart service "{0}": {1}', $ServiceName, $_.Exception.Message); 18 | } 19 | 20 | Write-IcingaFileSecure -File "$TmpFilePath" -Value ( 21 | @{ 22 | 'Success' = $Success; 23 | 'Message' = [string]::Format('Service "{0}" successfully restarted', $ServiceName); 24 | 'ErrMsg' = $ErrMsg; 25 | 'Status' = $Status; 26 | } | ConvertTo-Json -Depth 100 27 | ); 28 | -------------------------------------------------------------------------------- /jobs/SetProcessPriority.ps1: -------------------------------------------------------------------------------- 1 | # Load the basic framework data 2 | Use-Icinga -Minimal; 3 | 4 | # Wait 10 seconds before procedding 5 | Start-Sleep -Seconds 10; 6 | 7 | # Fetch the process information for JEA and the Icinga for Windows PID 8 | $JeaProcess = Get-Process -Id (Get-IcingaJEAServicePid) -ErrorAction SilentlyContinue; 9 | $IfWProcess = Get-Process -Id (Get-IcingaForWindowsServicePid) -ErrorAction SilentlyContinue; 10 | 11 | # Set the JEA pid to below normal 12 | if ($null -ne $JeaProcess -And $JeaProcess.ProcessName -eq 'wsmprovhost') { 13 | $JeaProcess.PriorityClass = 'BelowNormal'; 14 | } 15 | 16 | # Set the Icinga for Windows pid to below normal 17 | if ($null -ne $IfWProcess -And $IfWProcess.ProcessName -eq 'powershell') { 18 | $IfWProcess.PriorityClass = 'BelowNormal'; 19 | } 20 | 21 | # Exit with okay 22 | exit 0; 23 | -------------------------------------------------------------------------------- /jobs/StartWindowsService.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | [string]$ServiceName = '', 3 | [string]$TmpFilePath = '' 4 | ); 5 | 6 | Use-Icinga -Minimal; 7 | 8 | [bool]$Success = $TRUE; 9 | [string]$ErrMsg = ""; 10 | [string]$Status = ''; 11 | 12 | try { 13 | Start-Service "$ServiceName" -ErrorAction Stop; 14 | $Status = [string](Get-Service "$ServiceName").Status; 15 | } catch { 16 | $Success = $FALSE; 17 | $ErrMsg = [string]::Format('Failed to start service "{0}": {1}', $ServiceName, $_.Exception.Message); 18 | } 19 | 20 | Write-IcingaFileSecure -File "$TmpFilePath" -Value ( 21 | @{ 22 | 'Success' = $Success; 23 | 'Message' = [string]::Format('Service "{0}" successfully started', $ServiceName); 24 | 'ErrMsg' = $ErrMsg; 25 | 'Status' = $Status; 26 | } | ConvertTo-Json -Depth 100 27 | ); 28 | -------------------------------------------------------------------------------- /jobs/StopWindowsService.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | [string]$ServiceName = '', 3 | [string]$TmpFilePath = '' 4 | ); 5 | 6 | Use-Icinga -Minimal; 7 | 8 | [bool]$Success = $TRUE; 9 | [string]$ErrMsg = ""; 10 | [string]$Status = ''; 11 | 12 | try { 13 | Stop-Service "$ServiceName" -ErrorAction Stop; 14 | $Status = [string](Get-Service "$ServiceName").Status; 15 | } catch { 16 | $Success = $FALSE; 17 | $ErrMsg = [string]::Format('Failed to stop service "{0}": {1}', $ServiceName, $_.Exception.Message); 18 | } 19 | 20 | Write-IcingaFileSecure -File "$TmpFilePath" -Value ( 21 | @{ 22 | 'Success' = $Success; 23 | 'Message' = [string]::Format('Service "{0}" successfully stopped', $ServiceName); 24 | 'ErrMsg' = $ErrMsg; 25 | 'Status' = $Status; 26 | } | ConvertTo-Json -Depth 100 27 | ); 28 | -------------------------------------------------------------------------------- /lib/config/Get-IcingaConfigTreeCount.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Returns the amount of items for a config item 4 | .DESCRIPTION 5 | Returns the amount of items for a config item 6 | .FUNCTIONALITY 7 | Returns the amount of items for a config item 8 | .EXAMPLE 9 | PS>Get-IcingaConfigTreeCount -Path 'framework.daemons'; 10 | .PARAMETER Path 11 | The path to the config item to check for 12 | .INPUTS 13 | System.String 14 | .OUTPUTS 15 | System.Integer 16 | .LINK 17 | https://github.com/Icinga/icinga-powershell-framework 18 | #> 19 | 20 | function Get-IcingaConfigTreeCount() 21 | { 22 | param( 23 | $Path = '' 24 | ); 25 | 26 | $Config = Read-IcingaPowerShellConfig; 27 | $PathArray = $Path.Split('.'); 28 | $ConfigObject = $Config; 29 | [int]$Count = 0; 30 | 31 | foreach ($entry in $PathArray) { 32 | if (-Not (Test-IcingaPowerShellConfigItem -ConfigObject $ConfigObject -ConfigKey $entry)) { 33 | continue; 34 | } 35 | 36 | $ConfigObject = $ConfigObject.$entry; 37 | } 38 | 39 | foreach ($config in $ConfigObject.PSObject.Properties) { 40 | $Count += 1; 41 | } 42 | 43 | return $Count; 44 | } 45 | -------------------------------------------------------------------------------- /lib/config/New-IcingaPowerShellConfigItem.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Creates a new config entry with given arguments 4 | .DESCRIPTION 5 | Creates a new config entry with given arguments 6 | .FUNCTIONALITY 7 | Creates a new config entry with given arguments 8 | .EXAMPLE 9 | PS>New-IcingaPowerShellConfigItem -ConfigObject $PSObject -ConfigKey 'keyname' -ConfigValue 'keyvalue'; 10 | .PARAMETER ConfigObject 11 | The custom config object to modify 12 | .PARAMETER ConfigKey 13 | The key which is added to the config object 14 | .PARAMETER ConfigValue 15 | The value written for the ConfigKey 16 | .INPUTS 17 | System.Object 18 | .LINK 19 | https://github.com/Icinga/icinga-powershell-framework 20 | #> 21 | 22 | function New-IcingaPowerShellConfigItem() 23 | { 24 | param( 25 | $ConfigObject, 26 | [string]$ConfigKey, 27 | $ConfigValue = $null 28 | ); 29 | 30 | if ($null -eq $ConfigValue) { 31 | $ConfigValue = (New-Object -TypeName PSObject); 32 | } 33 | 34 | $ConfigObject | Add-Member -MemberType NoteProperty -Name $ConfigKey -Value $ConfigValue; 35 | } 36 | -------------------------------------------------------------------------------- /lib/config/Test-IcingaPowerShellConfigItem.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Test if a config entry on an object is already present 4 | .DESCRIPTION 5 | Test if a config entry on an object is already present 6 | .FUNCTIONALITY 7 | Test if a config entry on an object is already present 8 | .EXAMPLE 9 | PS>Test-IcingaPowerShellConfigItem -ConfigObject $PSObject -ConfigKey 'keyname'; 10 | .PARAMETER ConfigObject 11 | The custom config object to check for 12 | .PARAMETER ConfigKey 13 | The key which is checked 14 | .INPUTS 15 | System.String 16 | .OUTPUTS 17 | System.Boolean 18 | .LINK 19 | https://github.com/Icinga/icinga-powershell-framework 20 | #> 21 | 22 | function Test-IcingaPowerShellConfigItem() 23 | { 24 | param ( 25 | $ConfigObject, 26 | $ConfigKey 27 | ); 28 | 29 | if ($null -eq $ConfigObject -Or [string]::IsNullOrEmpty($ConfigKey)) { 30 | return $FALSE; 31 | } 32 | 33 | foreach ($entry in $ConfigObject.PSObject.Properties) { 34 | if ($entry.Name.ToLower() -eq $ConfigKey.ToLower()) { 35 | return $TRUE; 36 | } 37 | } 38 | 39 | return $FALSE; 40 | } 41 | -------------------------------------------------------------------------------- /lib/config/Write-IcingaPowerShellConfig.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Writes a given config object to disk 4 | .DESCRIPTION 5 | Writes a given config object to disk 6 | .FUNCTIONALITY 7 | Writes a given config object to disk 8 | .EXAMPLE 9 | PS>Write-IcingaPowerShellConfig -Config $PSObject; 10 | .PARAMETER Config 11 | A PSObject containing the entire configuration to write 12 | .INPUTS 13 | System.Object 14 | .LINK 15 | https://github.com/Icinga/icinga-powershell-framework 16 | #> 17 | 18 | function Write-IcingaPowerShellConfig() 19 | { 20 | param ( 21 | $Config 22 | ); 23 | 24 | $ConfigDir = Get-IcingaPowerShellConfigDir; 25 | $ConfigFile = Join-Path -Path $ConfigDir -ChildPath 'config.json'; 26 | 27 | if (-Not (Test-Path $ConfigDir)) { 28 | New-Item -Path $ConfigDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null; 29 | } 30 | 31 | $Content = ConvertTo-Json -InputObject $Config -Depth 100; 32 | 33 | Write-IcingaFileSecure -File $ConfigFile -Value $Content; 34 | } 35 | -------------------------------------------------------------------------------- /lib/core/cache/Copy-IcingaCacheTempFile.psm1: -------------------------------------------------------------------------------- 1 | function Copy-IcingaCacheTempFile() 2 | { 3 | param ( 4 | [string]$CacheFile = '', 5 | [string]$CacheTmpFile = '' 6 | ); 7 | 8 | # Copy the new file over the old one 9 | Copy-ItemSecure -Path $CacheTmpFile -Destination $CacheFile -Force | Out-Null; 10 | # Remove the old file 11 | Remove-ItemSecure -Path $CacheTmpFile -Retries 5 -Force | Out-Null; 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/cache/Test-IcingaCacheDataTempFile.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaCacheDataTempFile() 2 | { 3 | param ( 4 | [string]$Space, 5 | [string]$CacheStore, 6 | [string]$KeyName 7 | ); 8 | 9 | # Once the file is written successully, validate it is fine 10 | $tmpContent = Get-IcingaCacheData -Space $Space -CacheStore $CacheStore -KeyName $KeyName -TempFile; 11 | 12 | if ($null -eq $tmpContent) { 13 | # File is corrupt or empty 14 | return $FALSE; 15 | } 16 | 17 | return $TRUE; 18 | } 19 | -------------------------------------------------------------------------------- /lib/core/dev/Get-IcingaForWindowsComponentPublicFunctions.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaForWindowsComponentPublicFunctions() 2 | { 3 | param ( 4 | $FileObject = $null, 5 | [string]$ModuleName = '' 6 | ); 7 | 8 | [array]$ExportFunctions = @(); 9 | 10 | # First first if we are inside a public space 11 | if ((Test-IcingaForWindowsComponentPublicFunctions -FileObject $FileObject -ModuleName $ModuleName) -eq $FALSE) { 12 | $FileData = (Read-IcingaPowerShellModuleFile -File $FileObject.FullName); 13 | 14 | foreach ($entry in $FileData.FunctionList) { 15 | if ($entry.Contains('Global:')) { 16 | $ExportFunctions += $entry.Replace('Global:', ''); 17 | } 18 | } 19 | 20 | $ExportFunctions += $FileData.ExportFunction; 21 | 22 | return $ExportFunctions; 23 | } 24 | 25 | $FileData = (Read-IcingaPowerShellModuleFile -File $FileObject.FullName); 26 | $ExportFunctions += $FileData.FunctionList; 27 | $ExportFunctions += $FileData.ExportFunction; 28 | 29 | # If we are, add all functions we found 30 | return $ExportFunctions; 31 | } 32 | -------------------------------------------------------------------------------- /lib/core/dev/Test-IcingaForWindowsComponentPublicFunctions.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaForWindowsComponentPublicFunctions() 2 | { 3 | param ( 4 | $FileObject = $null, 5 | [string]$ModuleName = '' 6 | ); 7 | 8 | if ($null -eq $FileObject -Or [string]::IsNullOrEmpty($ModuleName)) { 9 | return $FALSE; 10 | } 11 | 12 | # If we load the main .psm1 file of this module, add all functions inside to the public space 13 | if ($FileObject.Name -eq ([string]::Format('{0}.psm1', $ModuleName))) { 14 | return $TRUE; 15 | } 16 | 17 | [int]$RelativPathStartIndex = $FileObject.FullName.IndexOf($ModuleName) + $ModuleName.Length; 18 | $ModuleFileRelativePath = $FileObject.FullName.SubString($RelativPathStartIndex, $FileObject.FullName.Length - $RelativPathStartIndex); 19 | 20 | if ($ModuleFileRelativePath.Contains('\public\') -Or $ModuleFileRelativePath.Contains('\plugins\') -Or $ModuleFileRelativePath.Contains('\endpoint\') -Or $ModuleFileRelativePath.Contains('\daemon\')) { 21 | return $TRUE; 22 | } 23 | 24 | return $FALSE; 25 | } 26 | -------------------------------------------------------------------------------- /lib/core/docs/Add-IcingaDocumentContent.psm1: -------------------------------------------------------------------------------- 1 | function Add-IcingaDocumentContent() 2 | { 3 | param ( 4 | [string]$Name = $null, 5 | [string]$Content = '', 6 | [switch]$NoNewLine = $FALSE 7 | ); 8 | 9 | if ([string]::IsNullOrEmpty($Name)) { 10 | Write-IcingaConsoleError 'You have to specify an internal name for the documentation object'; 11 | return; 12 | } 13 | 14 | if ($Global:Icinga.Private.Documentation.ContainsKey($Name) -eq $false) { 15 | Write-IcingaConsoleError 'A documentation object with the name "{0}" does not exist' -Objects $Name; 16 | return; 17 | } 18 | 19 | if ($NoNewLine) { 20 | $Global:Icinga.Private.Documentation[$Name]['Content'].Append($Content) | Out-Null; 21 | } else { 22 | $Global:Icinga.Private.Documentation[$Name]['Content'].AppendLine($Content) | Out-Null; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lib/core/docs/Write-IcingaDocumentFile.psm1: -------------------------------------------------------------------------------- 1 | function Write-IcingaDocumentFile() 2 | { 3 | param ( 4 | [string]$Name = $null, 5 | [switch]$ClearCache = $FALSE 6 | ); 7 | 8 | if ([string]::IsNullOrEmpty($Name)) { 9 | Write-IcingaConsoleError 'You have to specify an internal name for the documentation object'; 10 | return; 11 | } 12 | 13 | Write-IcingaFileSecure -File $Global:Icinga.Private.Documentation[$Name]['Path'] -Value $Global:Icinga.Private.Documentation[$Name]['Content'].ToString(); 14 | 15 | if ($ClearCache) { 16 | $Global:Icinga.Private.Documentation.Remove($Name); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/core/framework/Clear-IcingaCheckSchedulerCheckData.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Clear all cached values for all check commands executed by this thread. 4 | This is mandatory as we might run into a memory leak otherwise! 5 | .DESCRIPTION 6 | Clear all cached values for all check commands executed by this thread. 7 | This is mandatory as we might run into a memory leak otherwise! 8 | .FUNCTIONALITY 9 | Clear all cached values for all check commands executed by this thread. 10 | This is mandatory as we might run into a memory leak otherwise! 11 | .OUTPUTS 12 | System.Object 13 | .LINK 14 | https://github.com/Icinga/icinga-powershell-framework 15 | #> 16 | 17 | function Clear-IcingaCheckSchedulerCheckData() 18 | { 19 | $global:Icinga.Private.Scheduler.CheckData.Clear(); 20 | } 21 | -------------------------------------------------------------------------------- /lib/core/framework/Clear-IcingaCheckSchedulerEnvironment.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Clears the entire check scheduler cache environment and frees memory as 4 | well as cleaning the stack 5 | .DESCRIPTION 6 | Clears the entire check scheduler cache environment and frees memory as 7 | well as cleaning the stack 8 | .FUNCTIONALITY 9 | Clears the entire check scheduler cache environment and frees memory as 10 | well as cleaning the stack 11 | .OUTPUTS 12 | System.Object 13 | .LINK 14 | https://github.com/Icinga/icinga-powershell-framework 15 | #> 16 | 17 | function Clear-IcingaCheckSchedulerEnvironment() 18 | { 19 | param ( 20 | [switch]$ClearCheckData = $FALSE 21 | ); 22 | 23 | Get-IcingaCheckSchedulerPluginOutput | Out-Null; 24 | Get-IcingaCheckSchedulerPerfData | Out-Null; 25 | 26 | if ($ClearCheckData) { 27 | Clear-IcingaCheckSchedulerCheckData; 28 | } 29 | 30 | $Global:Icinga.Private.Scheduler.PluginException = $null; 31 | $Global:Icinga.Private.Scheduler.CheckResults = $null; 32 | $Global:Icinga.Private.Scheduler.ExitCode = $null; 33 | } 34 | -------------------------------------------------------------------------------- /lib/core/framework/Disable-IcingaFrameworkApiChecks.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Disables the feature to forward all executed checks to an internal 4 | installed API to run them within a daemon 5 | .DESCRIPTION 6 | Disables the feature to forward all executed checks to an internal 7 | installed API to run them within a daemon 8 | .FUNCTIONALITY 9 | Disables the Icinga for Windows Api checks forwarded 10 | .EXAMPLE 11 | PS>Disable-IcingaFrameworkApiChecks; 12 | .LINK 13 | https://github.com/Icinga/icinga-powershell-framework 14 | #> 15 | 16 | function Disable-IcingaFrameworkApiChecks() 17 | { 18 | Set-IcingaPowerShellConfig -Path 'Framework.ApiChecks' -Value $FALSE; 19 | } 20 | -------------------------------------------------------------------------------- /lib/core/framework/Disable-IcingaFrameworkConsoleOutput.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Allows to disable any console output for this PowerShell session 4 | .DESCRIPTION 5 | Allows to disable any console output for this PowerShell session 6 | .FUNCTIONALITY 7 | Allows to disable any console output for this PowerShell session 8 | .EXAMPLE 9 | PS>Disable-IcingaFrameworkConsoleOutput; 10 | .LINK 11 | https://github.com/Icinga/icinga-powershell-framework 12 | #> 13 | 14 | function Disable-IcingaFrameworkConsoleOutput() 15 | { 16 | if ($null -eq $global:Icinga) { 17 | $global:Icinga = @{ }; 18 | } 19 | 20 | if ($global:Icinga.ContainsKey('DisableConsoleOutput') -eq $FALSE) { 21 | $global:Icinga.Add('DisableConsoleOutput', $TRUE); 22 | } else { 23 | $global:Icinga.DisableConsoleOutput = $TRUE; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/core/framework/Disable-IcingaFrameworkDebugMode.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Disables the debug mode of the Framework 4 | .DESCRIPTION 5 | Disables the debug mode of the Framework 6 | .FUNCTIONALITY 7 | Disables the Icinga for Windows Debug-Log 8 | .EXAMPLE 9 | PS>Disable-IcingaFrameworkDebugMode; 10 | .LINK 11 | https://github.com/Icinga/icinga-powershell-framework 12 | #> 13 | 14 | function Disable-IcingaFrameworkDebugMode() 15 | { 16 | $Global:Icinga.Protected.DebugMode = $FALSE; 17 | Set-IcingaPowerShellConfig -Path 'Framework.DebugMode' -Value $FALSE; 18 | } 19 | -------------------------------------------------------------------------------- /lib/core/framework/Enable-IcingaFrameworkApiChecks.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Enables the feature to forward all executed checks to an internal 4 | installed API to run them within a daemon 5 | .DESCRIPTION 6 | Enables the feature to forward all executed checks to an internal 7 | installed API to run them within a daemon 8 | .FUNCTIONALITY 9 | Enables the Icinga for Windows Api checks forwarder 10 | .EXAMPLE 11 | PS>Enable-IcingaFrameworkApiChecks; 12 | .LINK 13 | https://icinga.com/docs/icinga-for-windows/latest/doc/110-Installation/30-API-Check-Forwarder/ 14 | #> 15 | 16 | function Enable-IcingaFrameworkApiChecks() 17 | { 18 | Set-IcingaPowerShellConfig -Path 'Framework.ApiChecks' -Value $TRUE; 19 | } 20 | -------------------------------------------------------------------------------- /lib/core/framework/Enable-IcingaFrameworkConsoleOutput.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Allows to enable any console output for this PowerShell session 4 | .DESCRIPTION 5 | Allows to enable any console output for this PowerShell session 6 | .FUNCTIONALITY 7 | Allows to enable any console output for this PowerShell session 8 | .EXAMPLE 9 | PS>Enable-IcingaFrameworkConsoleOutput; 10 | .LINK 11 | https://github.com/Icinga/icinga-powershell-framework 12 | #> 13 | 14 | function Enable-IcingaFrameworkConsoleOutput() 15 | { 16 | if ($null -eq $global:Icinga) { 17 | $global:Icinga = @{ }; 18 | } 19 | 20 | if ($global:Icinga.ContainsKey('DisableConsoleOutput') -eq $FALSE) { 21 | $global:Icinga.Add('DisableConsoleOutput', $FALSE); 22 | } else { 23 | $global:Icinga.DisableConsoleOutput = $FALSE; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/core/framework/Enable-IcingaFrameworkDebugMode.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Enables the debug mode of the Framework to print additional details into 4 | the Windows Event Log with Id 1000 5 | .DESCRIPTION 6 | Enables the debug mode of the Framework to print additional details into 7 | the Windows Event Log with Id 1000 8 | .FUNCTIONALITY 9 | Enables the Icinga for Windows Debug-Log 10 | .EXAMPLE 11 | PS>Enable-IcingaFrameworkDebugMode; 12 | .LINK 13 | https://github.com/Icinga/icinga-powershell-framework 14 | #> 15 | 16 | function Enable-IcingaFrameworkDebugMode() 17 | { 18 | $Global:Icinga.Protected.DebugMode = $TRUE; 19 | Set-IcingaPowerShellConfig -Path 'Framework.DebugMode' -Value $TRUE; 20 | } 21 | -------------------------------------------------------------------------------- /lib/core/framework/Get-IcingaCheckSchedulerCheckData.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Fetch the raw output values for a check command for each single object 4 | processed by New-IcingaCheck 5 | .DESCRIPTION 6 | Fetch the raw output values for a check command for each single object 7 | processed by New-IcingaCheck 8 | .FUNCTIONALITY 9 | Fetch the raw output values for a check command for each single object 10 | processed by New-IcingaCheck 11 | .OUTPUTS 12 | System.Object 13 | .LINK 14 | https://github.com/Icinga/icinga-powershell-framework 15 | #> 16 | 17 | function Get-IcingaCheckSchedulerCheckData() 18 | { 19 | return $global:Icinga.Private.Scheduler.CheckData; 20 | } 21 | -------------------------------------------------------------------------------- /lib/core/framework/Get-IcingaCheckSchedulerPluginOutput.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Function to fetch the last executed plugin output from an internal memory 4 | cache in case the Framework is running as daemon. 5 | .DESCRIPTION 6 | While running the Framework as daemon, checkresults for plugins are not 7 | printed into the console but written into an internal memory cache. Once 8 | a plugin was executed, use this function to fetch the plugin output 9 | .FUNCTIONALITY 10 | Returns the last checkresult output for executed plugins while the 11 | Framework is running as daemon 12 | .OUTPUTS 13 | System.Object 14 | .LINK 15 | https://github.com/Icinga/icinga-powershell-framework 16 | #> 17 | 18 | function Get-IcingaCheckSchedulerPluginOutput() 19 | { 20 | if ($Global:Icinga.Private.Scheduler.CheckResults.Count -eq 0) { 21 | return @(); 22 | } 23 | 24 | $CheckResult = [string]::Join("`r`n", $Global:Icinga.Private.Scheduler.CheckResults); 25 | [array]$Global:Icinga.Private.Scheduler.CheckResults = @(); 26 | 27 | return $CheckResult; 28 | } 29 | -------------------------------------------------------------------------------- /lib/core/framework/Get-IcingaFrameworkApiChecks.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Fetches the current enable/disable state of the feature 4 | for executing checks of the internal REST-Api 5 | .DESCRIPTION 6 | Fetches the current enable/disable state of the feature 7 | for executing checks of the internal REST-Api 8 | .FUNCTIONALITY 9 | Get the current API check execution configuration of the 10 | Icinga PowerShell Framework 11 | .EXAMPLE 12 | PS>Get-IcingaFrameworkApiChecks; 13 | .LINK 14 | https://github.com/Icinga/icinga-powershell-framework 15 | .OUTPUTS 16 | System.Boolean 17 | #> 18 | 19 | function Get-IcingaFrameworkApiChecks() 20 | { 21 | $ApiChecks = Get-IcingaPowerShellConfig -Path 'Framework.ApiChecks'; 22 | 23 | if ($null -eq $ApiChecks) { 24 | return $FALSE; 25 | } 26 | 27 | return $ApiChecks; 28 | } 29 | -------------------------------------------------------------------------------- /lib/core/framework/Get-IcingaFrameworkDebugMode.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Get the current debug mode configuration of the Framework 4 | .DESCRIPTION 5 | Get the current debug mode configuration of the Framework 6 | .FUNCTIONALITY 7 | Get the current debug mode configuration of the Framework 8 | .EXAMPLE 9 | PS>Get-IcingaFrameworkDebugMode; 10 | .LINK 11 | https://github.com/Icinga/icinga-powershell-framework 12 | .OUTPUTS 13 | System.Boolean 14 | #> 15 | 16 | function Get-IcingaFrameworkDebugMode() 17 | { 18 | $DebugMode = Get-IcingaPowerShellConfig -Path 'Framework.DebugMode'; 19 | 20 | if ($null -eq $DebugMode) { 21 | return $FALSE; 22 | } 23 | 24 | return $DebugMode; 25 | } 26 | -------------------------------------------------------------------------------- /lib/core/framework/Get-IcingaPowerShellModuleVersion.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Get the version of an installed PowerShell Module 4 | .DESCRIPTION 5 | Get the version of an installed PowerShell Module 6 | .FUNCTIONALITY 7 | Get the version of an installed PowerShell Module 8 | .EXAMPLE 9 | PS>Get-IcingaPowerShellModuleVersion -ModuleName 'icinga-powershell-framework'; 10 | .EXAMPLE 11 | PS>Get-IcingaPowerShellModuleVersion -ModuleName 'icinga-powershell-plugins'; 12 | .PARAMETER ModuleName 13 | The PowerShell module to fetch the installed version from 14 | .INPUTS 15 | System.String 16 | .OUTPUTS 17 | System.String 18 | .LINK 19 | https://github.com/Icinga/icinga-powershell-framework 20 | #> 21 | 22 | function Get-IcingaPowerShellModuleVersion() 23 | { 24 | param( 25 | $ModuleName 26 | ); 27 | 28 | $ModuleDetails = Get-Module -ListAvailable $ModuleName; 29 | 30 | if ($null -eq $ModuleDetails) { 31 | return $null; 32 | } 33 | 34 | return $ModuleDetails.PrivateData.Version; 35 | } 36 | -------------------------------------------------------------------------------- /lib/core/framework/Get-IcingaPrivateEnvironmentVariable.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Reads a private environment variable from Icinga for Windows 4 | of the current PowerShell session 5 | .DESCRIPTION 6 | Reads a private environment variable from Icinga for Windows 7 | of the current PowerShell session 8 | .PARAMETER Name 9 | The name of the variable to load the content from 10 | .EXAMPLE 11 | Get-IcingaPrivateEnvironmentVariable -Name 'AddTypeFunctions'; 12 | .NOTES 13 | General notes 14 | #> 15 | function Get-IcingaPrivateEnvironmentVariable() 16 | { 17 | param ( 18 | [string]$Name 19 | ); 20 | 21 | if ([string]::IsNullOrEmpty($Name)) { 22 | return $null; 23 | } 24 | 25 | if ($global:Icinga.Private.ContainsKey($Name) -eq $FALSE) { 26 | return $null; 27 | } 28 | 29 | return $global:Icinga.Private[$Name]; 30 | } 31 | -------------------------------------------------------------------------------- /lib/core/framework/Get-IcingaTimer.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Fetches a Stopwatch system object by a given name if initialised with Start-IcingaTimer 4 | .DESCRIPTION 5 | Fetches a Stopwatch system object by a given name if initialised with Start-IcingaTimer 6 | .FUNCTIONALITY 7 | Fetches a Stopwatch system object by a given name if initialised with Start-IcingaTimer 8 | .EXAMPLE 9 | PS>Get-IcingaTimer; 10 | .EXAMPLE 11 | PS>Get-IcingaTimer -Name 'My Test Timer'; 12 | .PARAMETER Name 13 | The name of a custom identifier to run mutliple timers at once 14 | .INPUTS 15 | System.String 16 | .OUTPUTS 17 | System.Diagnostics.Stopwatch 18 | .LINK 19 | https://github.com/Icinga/icinga-powershell-framework 20 | #> 21 | 22 | function Get-IcingaTimer() 23 | { 24 | param ( 25 | [string]$Name = 'DefaultTimer' 26 | ); 27 | 28 | $TimerData = Get-IcingaHashtableItem -Key $Name -Hashtable $Global:Icinga.Private.Timers; 29 | 30 | if ($null -eq $TimerData) { 31 | return $null; 32 | } 33 | 34 | return $TimerData.Timer; 35 | } 36 | -------------------------------------------------------------------------------- /lib/core/framework/Invoke-IcingaNamespaceCmdlets.psm1: -------------------------------------------------------------------------------- 1 | function Invoke-IcingaNamespaceCmdlets() 2 | { 3 | param ( 4 | [string]$Command 5 | ); 6 | 7 | [Hashtable]$CommandConfig = @{ }; 8 | 9 | if ($Command.Contains('*') -eq $FALSE) { 10 | $Command = [string]::Format('{0}*', $Command); 11 | } 12 | 13 | $CommandList = Get-Command $Command; 14 | 15 | foreach ($Cmdlet in $CommandList) { 16 | try { 17 | $CommandName = $Cmdlet.Name; 18 | $Content = (& $CommandName); 19 | 20 | Add-IcingaHashtableItem ` 21 | -Hashtable $CommandConfig ` 22 | -Key $Cmdlet.Name ` 23 | -Value $Content | Out-Null; 24 | } catch { 25 | Write-IcingaEventMessage -EventId 1103 -Namespace 'Framework' -ExceptionObject $_ -Objects $CommandName; 26 | } 27 | } 28 | 29 | return $CommandConfig; 30 | } 31 | -------------------------------------------------------------------------------- /lib/core/framework/Read-IcingaForWindowsLog.psm1: -------------------------------------------------------------------------------- 1 | function Read-IcingaForWindowsLog() 2 | { 3 | param ( 4 | [array]$Source = @(), 5 | [array]$Include = @(), 6 | [array]$Exclude = @() 7 | ); 8 | 9 | Read-IcingaWindowsEventLog -LogName 'Icinga for Windows' -Source $Source -MaxEntries 500 -Include $Include -Exclude $Exclude; 10 | } 11 | -------------------------------------------------------------------------------- /lib/core/framework/Set-IcingaForWindowsMigration.psm1: -------------------------------------------------------------------------------- 1 | function Set-IcingaForWindowsMigration() 2 | { 3 | param ( 4 | [Version]$MigrationVersion = $null 5 | ); 6 | 7 | if ($null -eq $MigrationVersion) { 8 | return; 9 | } 10 | 11 | [string]$MigrationConfigPath = [string]::Format('Framework.Migrations.{0}', $MigrationVersion.ToString().Replace('.', '')); 12 | 13 | Set-IcingaPowerShellConfig -Path $MigrationConfigPath -Value $TRUE | Out-Null 14 | } 15 | -------------------------------------------------------------------------------- /lib/core/framework/Set-IcingaPrivateEnvironmentVariable.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Sets a private variable for the Icinga for Windows environment 4 | to use within the current PowerShell Session 5 | .DESCRIPTION 6 | Sets a private variable for the Icinga for Windows environment 7 | to use within the current PowerShell Session 8 | .PARAMETER Name 9 | The name of the variable 10 | .PARAMETER Value 11 | The value the variable will be assigned with 12 | .EXAMPLE 13 | Set-IcingaPrivateEnvironmentVariable -Name 'AddTypeFunctions' -Value @{ 'IcingaDiskAttributes', $TRUE }; 14 | #> 15 | 16 | function Set-IcingaPrivateEnvironmentVariable() 17 | { 18 | param ( 19 | [string]$Name, 20 | $Value 21 | ); 22 | 23 | if ([string]::IsNullOrEmpty($Name)) { 24 | return; 25 | } 26 | 27 | if ($global:Icinga.Private.ContainsKey($Name) -eq $FALSE) { 28 | $global:Icinga.Private.Add($Name, $Value); 29 | return; 30 | } 31 | 32 | $global:Icinga.Private[$Name] = $Value; 33 | } 34 | -------------------------------------------------------------------------------- /lib/core/framework/Test-IcingaFrameworkConsoleOutput.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Allows to test if console output can be written or not for this PowerShell session 4 | .DESCRIPTION 5 | Allows to test if console output can be written or not for this PowerShell session 6 | .FUNCTIONALITY 7 | Allows to test if console output can be written or not for this PowerShell session 8 | .EXAMPLE 9 | PS>Enable-IcingaFrameworkConsoleOutput; 10 | .LINK 11 | https://github.com/Icinga/icinga-powershell-framework 12 | #> 13 | 14 | function Test-IcingaFrameworkConsoleOutput() 15 | { 16 | if ($null -eq $global:Icinga) { 17 | return $TRUE; 18 | } 19 | 20 | if ($global:Icinga.ContainsKey('DisableConsoleOutput') -eq $FALSE) { 21 | return $TRUE; 22 | } 23 | 24 | return (-Not ($global:Icinga.DisableConsoleOutput)); 25 | } 26 | -------------------------------------------------------------------------------- /lib/core/framework/Test-IcingaTimer.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Tests if a specific timer object is already present and started with Start-IcingaTimer 4 | .DESCRIPTION 5 | Tests if a specific timer object is already present and started with Start-IcingaTimer 6 | .FUNCTIONALITY 7 | Tests if a specific timer object is already present and started with Start-IcingaTimer 8 | .EXAMPLE 9 | PS>Test-IcingaTimer; 10 | .EXAMPLE 11 | PS>Test-IcingaTimer -Name 'My Test Timer'; 12 | .PARAMETER Name 13 | The name of a custom identifier to run mutliple timers at once 14 | .INPUTS 15 | System.String 16 | .OUTPUTS 17 | Boolean 18 | .LINK 19 | https://github.com/Icinga/icinga-powershell-framework 20 | #> 21 | 22 | function Test-IcingaTimer() 23 | { 24 | param ( 25 | [string]$Name = 'DefaultTimer' 26 | ); 27 | 28 | $TimerData = Get-IcingaHashtableItem -Key $Name -Hashtable $Global:Icinga.Private.Timers; 29 | 30 | if ($null -eq $TimerData) { 31 | return $FALSE; 32 | } 33 | 34 | return $TimerData.Active; 35 | } 36 | -------------------------------------------------------------------------------- /lib/core/framework/Unblock-IcingaPowerShellFiles.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Unblocks a folder with PowerShell module/script files to make them usable 4 | on certain environments 5 | .DESCRIPTION 6 | Wrapper command to unblock recursively a certain folder for PowerShell script 7 | and module files 8 | .FUNCTIONALITY 9 | Unblocks a folder with PowerShell module/script files to make them usable 10 | on certain environments 11 | .EXAMPLE 12 | PS>Unblock-IcingaPowerShellFiles -Path 'C:\Program Files\WindowsPowerShell\Modules\my-module'; 13 | .PARAMETER Path 14 | The path to a PowerShell module folder or script file to unblock it 15 | .INPUTS 16 | System.String 17 | .OUTPUTS 18 | Null 19 | .LINK 20 | https://github.com/Icinga/icinga-powershell-framework 21 | #> 22 | 23 | function Unblock-IcingaPowerShellFiles() 24 | { 25 | param( 26 | $Path 27 | ); 28 | 29 | if ([string]::IsNullOrEmpty($Path)) { 30 | Write-IcingaConsoleError 'The specified directory was not found'; 31 | return; 32 | } 33 | 34 | Write-IcingaConsoleNotice 'Unblocking Icinga PowerShell Files'; 35 | Get-ChildItem -Path $Path -Recurse | Unblock-File; 36 | } 37 | -------------------------------------------------------------------------------- /lib/core/icingaagent/finders/Find-IcingaAgentObjects.psm1: -------------------------------------------------------------------------------- 1 | function Find-IcingaAgentObjects() 2 | { 3 | param( 4 | $Find = @(), 5 | $OutFile = $null 6 | ); 7 | 8 | if ($Find.Length -eq 0) { 9 | throw 'Please specify content you want to look for'; 10 | } 11 | 12 | [array]$ObjectList = (Get-IcingaAgentObjectList).Split("`r`n"); 13 | [int]$lineIndex = 0; 14 | [array]$Result = @(); 15 | 16 | foreach ($line in $ObjectList) { 17 | if ([string]::IsNullOrEmpty($line)) { 18 | continue; 19 | } 20 | 21 | foreach ($entry in $Find) { 22 | if ($line -like $entry) { 23 | [string]$ResultLine = [string]::Format( 24 | 'Line #{0} => "{1}"', 25 | $lineIndex, 26 | $line 27 | ); 28 | $Result += $ResultLine; 29 | } 30 | } 31 | 32 | $lineIndex += 1; 33 | } 34 | 35 | if ([string]::IsNullOrEmpty($OutFile)) { 36 | Write-Output $Result; 37 | } else { 38 | Write-IcingaFileSecure -File $OutFile -Value $Result; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lib/core/icingaagent/getters/Get-IcingaAgentArchitecture.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaAgentArchitecture() 2 | { 3 | $IcingaAgent = Get-IcingaAgentInstallation; 4 | 5 | return $IcingaAgent.Architecture; 6 | } 7 | -------------------------------------------------------------------------------- /lib/core/icingaagent/getters/Get-IcingaAgentBinary.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaAgentBinary() 2 | { 3 | $IcingaRootDir = Get-IcingaAgentRootDirectory; 4 | if ([string]::IsNullOrEmpty($IcingaRootDir)) { 5 | throw 'The Icinga Agent seems not to be installed'; 6 | } 7 | 8 | $IcingaBinary = (Join-Path -Path $IcingaRootDir -ChildPath '\sbin\icinga2.exe'); 9 | 10 | if ((Test-Path $IcingaBinary) -eq $FALSE) { 11 | throw 'Icinga Agent binary could not be found'; 12 | } 13 | 14 | return $IcingaBinary; 15 | } 16 | -------------------------------------------------------------------------------- /lib/core/icingaagent/getters/Get-IcingaAgentConfigDirectory.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaAgentConfigDirectory() 2 | { 3 | return (Join-Path -Path $Env:ProgramData -ChildPath 'icinga2\etc\icinga2\') 4 | } 5 | -------------------------------------------------------------------------------- /lib/core/icingaagent/getters/Get-IcingaAgentFeatures.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaAgentFeatures() 2 | { 3 | $Binary = Get-IcingaAgentBinary; 4 | $ConfigResult = Start-IcingaProcess -Executable $Binary -Arguments 'feature list'; 5 | 6 | if ($ConfigResult.ExitCode -ne 0) { 7 | return @{ 8 | 'Enabled' = @(); 9 | 'Disabled' = @(); 10 | } 11 | } 12 | 13 | $DisabledFeatures = ( 14 | $ConfigResult.Message.SubString( 15 | 0, 16 | $ConfigResult.Message.IndexOf('Enabled features') 17 | ) 18 | ).Replace('Disabled features: ', '').Replace("`r`n", '').Replace("`r", '').Replace("`n", ''); 19 | 20 | $EnabledFeatures = ( 21 | $ConfigResult.Message.SubString( 22 | $ConfigResult.Message.IndexOf('Enabled features'), 23 | $ConfigResult.Message.Length - $ConfigResult.Message.IndexOf('Enabled features') 24 | ) 25 | ).Replace('Enabled features: ', '').Replace("`r`n", '').Replace("`r", '').Replace("`n", ''); 26 | 27 | return @{ 28 | 'Enabled' = ($EnabledFeatures.Split(' ')); 29 | 'Disabled' = ($DisabledFeatures.Split(' ')); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/core/icingaagent/getters/Get-IcingaAgentLogDirectory.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaAgentLogDirectory() 2 | { 3 | return (Join-Path -Path $Env:ProgramData -ChildPath 'icinga2\var\log\icinga2\') 4 | } 5 | -------------------------------------------------------------------------------- /lib/core/icingaagent/getters/Get-IcingaAgentObjectList.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaAgentObjectList() 2 | { 3 | $Binary = Get-IcingaAgentBinary; 4 | $ObjectList = Start-IcingaProcess -Executable $Binary -Arguments 'object list'; 5 | 6 | return $ObjectList.Message; 7 | } 8 | -------------------------------------------------------------------------------- /lib/core/icingaagent/getters/Get-IcingaAgentRootDirectory.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaAgentRootDirectory() 2 | { 3 | $IcingaAgent = Get-IcingaAgentInstallation; 4 | if ($IcingaAgent.Installed -eq $FALSE) { 5 | return ''; 6 | } 7 | 8 | return $IcingaAgent.RootDir; 9 | } 10 | -------------------------------------------------------------------------------- /lib/core/icingaagent/getters/Get-IcingaAgentServicePermission.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaAgentServicePermission() 2 | { 3 | $SystemPermissions = New-IcingaTemporaryFile; 4 | $SystemOutput = Start-IcingaProcess -Executable 'secedit.exe' -Arguments ([string]::Format('/export /cfg "{0}.inf"', $SystemPermissions)); 5 | 6 | if ($SystemOutput.ExitCode -ne 0) { 7 | throw ([string]::Format('Unable to fetch system permission information: {0}', $SystemOutput.Message)); 8 | return $null; 9 | } 10 | 11 | $SystemContent = Get-Content "$SystemPermissions.inf"; 12 | 13 | Remove-Item $SystemPermissions*; 14 | 15 | return $SystemContent; 16 | } 17 | -------------------------------------------------------------------------------- /lib/core/icingaagent/getters/Get-IcingaAgentVersion.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaAgentVersion() 2 | { 3 | $IcingaAgent = Get-IcingaAgentInstallation; 4 | 5 | return $IcingaAgent.Version; 6 | } 7 | -------------------------------------------------------------------------------- /lib/core/icingaagent/getters/Get-IcingaNetbiosName.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaNetbiosName() 2 | { 3 | $ComputerData = Get-IcingaWindowsInformation Win32_ComputerSystem; 4 | 5 | return $ComputerData.Name; 6 | } 7 | -------------------------------------------------------------------------------- /lib/core/icingaagent/getters/Get-IcingaServiceUser.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaServiceUser() 2 | { 3 | $IcingaService = $Global:Icinga.Protected.Environment.'Icinga Service'; 4 | $IfWService = $Global:Icinga.Protected.Environment.'PowerShell Service'; 5 | # Default User 6 | $ServiceUser = 'NT Authority\NetworkService'; 7 | 8 | if ($null -eq $IcingaService -Or $null -eq $IfWService) { 9 | Set-IcingaServiceEnvironment; 10 | } 11 | 12 | if ($IcingaService.Present) { 13 | $ServiceUser = $IcingaService.User.Replace('.\', ''); 14 | if ($ServiceUser -eq 'LocalSystem') { 15 | return 'NT Authority\SYSTEM'; 16 | } 17 | } elseif ($IfWService.Present) { 18 | $ServiceUser = $IfWService.User.Replace('.\', ''); 19 | if ($ServiceUser -eq 'LocalSystem') { 20 | return 'NT Authority\SYSTEM'; 21 | } 22 | } 23 | 24 | return $ServiceUser; 25 | } 26 | -------------------------------------------------------------------------------- /lib/core/icingaagent/installer/Install-IcingaAgentBaseFeatures.psm1: -------------------------------------------------------------------------------- 1 | function Install-IcingaAgentBaseFeatures() 2 | { 3 | Disable-IcingaAgentFeature -Feature 'checker'; 4 | Disable-IcingaAgentFeature -Feature 'notification'; 5 | Enable-IcingaAgentFeature -Feature 'api'; 6 | } 7 | -------------------------------------------------------------------------------- /lib/core/icingaagent/misc/Compare-IcingaVersions.psm1: -------------------------------------------------------------------------------- 1 | function Compare-IcingaVersions() 2 | { 3 | param( 4 | $CurrentVersion, 5 | $RequiredVersion 6 | ); 7 | 8 | if ([string]::IsNullOrEmpty($RequiredVersion)) { 9 | return $FALSE; 10 | } 11 | 12 | $RequiredVersion = Split-IcingaVersion -Version $RequiredVersion; 13 | 14 | if ([string]::IsNullOrEmpty($CurrentVersion) -eq $FALSE) { 15 | $CurrentVersion = Split-IcingaVersion -Version $CurrentVersion; 16 | } else { 17 | $CurrentVersion = Get-IcingaAgentVersion; 18 | } 19 | 20 | if ($requiredVersion.Major -gt $currentVersion.Major) { 21 | return $FALSE; 22 | } 23 | 24 | if ($requiredVersion.Minor -gt $currentVersion.Minor) { 25 | return $FALSE; 26 | } 27 | 28 | if ($requiredVersion.Minor -ge $currentVersion.Minor -And $requiredVersion.Fixes -gt $currentVersion.Fixes) { 29 | return $FALSE; 30 | } 31 | 32 | return $TRUE; 33 | } 34 | -------------------------------------------------------------------------------- /lib/core/icingaagent/misc/Disable-IcingaAgentFeature.psm1: -------------------------------------------------------------------------------- 1 | function Disable-IcingaAgentFeature() 2 | { 3 | param( 4 | [string]$Feature 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Feature)) { 8 | throw 'Please specify a valid feature'; 9 | } 10 | 11 | if ((Test-IcingaAgentFeatureEnabled -Feature $Feature) -eq $FALSE) { 12 | Write-IcingaConsoleNotice ([string]::Format('This feature is already disabled [{0}]', $Feature)); 13 | return; 14 | } 15 | 16 | $Binary = Get-IcingaAgentBinary; 17 | $Process = Start-IcingaProcess -Executable $Binary -Arguments ([string]::Format('feature disable {0}', $Feature)); 18 | 19 | if ($Process.ExitCode -ne 0) { 20 | throw ([string]::Format('Failed to disable Icinga Feature: {0}', $Process.Message)); 21 | } 22 | 23 | Write-IcingaConsoleNotice ([string]::Format('Feature "{0}" was successfully disabled', $Feature)); 24 | } 25 | -------------------------------------------------------------------------------- /lib/core/icingaagent/misc/Enable-IcingaAgentFeature.psm1: -------------------------------------------------------------------------------- 1 | function Enable-IcingaAgentFeature() 2 | { 3 | param( 4 | [string]$Feature 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Feature)) { 8 | throw 'Please specify a valid feature'; 9 | } 10 | 11 | if ((Test-IcingaAgentFeatureEnabled -Feature $Feature)) { 12 | Write-IcingaConsoleNotice ([string]::Format('This feature is already enabled [{0}]', $Feature)); 13 | return; 14 | } 15 | 16 | $Binary = Get-IcingaAgentBinary; 17 | $Process = Start-IcingaProcess -Executable $Binary -Arguments ([string]::Format('feature enable {0}', $Feature)); 18 | 19 | if ($Process.ExitCode -ne 0) { 20 | throw ([string]::Format('Failed to enable Icinga Feature: {0}', $Process.Message)); 21 | } 22 | 23 | Write-IcingaConsoleNotice ([string]::Format('Feature "{0}" was successfully enabled', $Feature)); 24 | } 25 | -------------------------------------------------------------------------------- /lib/core/icingaagent/misc/Show-IcingaAgentObjects.psm1: -------------------------------------------------------------------------------- 1 | function Show-IcingaAgentObjects() 2 | { 3 | $Binary = Get-IcingaAgentBinary; 4 | $Output = Start-IcingaProcess -Executable $Binary -Arguments 'object list'; 5 | 6 | if ($Output.ExitCode -ne 0) { 7 | Write-IcingaConsoleError ([string]::Format('Failed to fetch Icinga Agent objects list: {0}{1}', $Output.Message, $Output.Error)); 8 | return $null; 9 | } 10 | 11 | return $Output.Message; 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/icingaagent/misc/Split-IcingaVersion.psm1: -------------------------------------------------------------------------------- 1 | function Split-IcingaVersion() 2 | { 3 | param( 4 | [string]$Version 5 | ); 6 | 7 | # TODO: Allow developers to adjust their code from mayor to major naming 8 | # for the next releases and remove the mayor naming in the future 9 | if ([string]::IsNullOrEmpty($Version)) { 10 | return @{ 11 | 'Full' = ''; 12 | 'Mayor' = $null; 13 | 'Major' = $null; 14 | 'Minor' = $null; 15 | 'Fixes' = $null; 16 | 'Snapshot' = $null; 17 | } 18 | } 19 | 20 | [array]$IcingaVersion = $Version.Split('.'); 21 | $Snapshot = $null; 22 | 23 | if ([string]::IsNullOrEmpty($IcingaVersion[3]) -eq $FALSE) { 24 | $Snapshot = [int]$IcingaVersion[3]; 25 | } 26 | 27 | return @{ 28 | 'Full' = $Version; 29 | 'Mayor' = [int]$IcingaVersion[0]; 30 | 'Major' = [int]$IcingaVersion[0]; 31 | 'Minor' = [int]$IcingaVersion[1]; 32 | 'Fixes' = [int]$IcingaVersion[2]; 33 | 'Snapshot' = $Snapshot; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/core/icingaagent/readers/Read-IcingaAgentDebugLogFile.psm1: -------------------------------------------------------------------------------- 1 | function Read-IcingaAgentDebugLogFile() 2 | { 3 | $Logfile = Join-Path -Path (Get-IcingaAgentLogDirectory) -ChildPath 'debug.log'; 4 | if ((Test-Path $Logfile) -eq $FALSE) { 5 | Write-IcingaConsoleError 'Icinga 2 debug logfile not present. Unable to load it'; 6 | return; 7 | } 8 | 9 | Get-Content -Path $Logfile -Tail 20 -Wait -Encoding 'UTF8'; 10 | } 11 | -------------------------------------------------------------------------------- /lib/core/icingaagent/readers/Read-IcingaAgentLogFile.psm1: -------------------------------------------------------------------------------- 1 | function Read-IcingaAgentLogFile() 2 | { 3 | param ( 4 | [array]$Include = @(), 5 | [array]$Exclude = @() 6 | ); 7 | 8 | if ((Test-IcingaAgentFeatureEnabled -Feature 'windowseventlog') -And ([version](Get-IcingaAgentVersion).Full) -ge (New-IcingaVersionObject -Version '2.13.0')) { 9 | 10 | # Icinga 2.13.0 and beyond will log directly into the EventLog 11 | Read-IcingaWindowsEventLog -LogName 'Application' -Source 'Icinga 2' -MaxEntries 500 -Include $Include -Exclude $Exclude; 12 | } else { 13 | $Logfile = Join-Path -Path (Get-IcingaAgentLogDirectory) -ChildPath 'icinga2.log'; 14 | if ((Test-Path $Logfile) -eq $FALSE) { 15 | Write-IcingaConsoleError 'Icinga 2 logfile not present. Unable to load it'; 16 | return; 17 | } 18 | 19 | Get-Content -Path $Logfile -Tail 20 -Wait -Encoding 'UTF8'; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lib/core/icingaagent/repair/Repair-IcingaStateFile.psm1: -------------------------------------------------------------------------------- 1 | function Repair-IcingaStateFile() 2 | { 3 | param ( 4 | [switch]$Force 5 | ); 6 | 7 | [string]$StateFilePath = Join-Path -Path $ENV:ProgramData -ChildPath 'icinga2\var\lib\icinga2\icinga2.state*'; 8 | 9 | if ((Test-IcingaStateFile) -And $Force -eq $FALSE) { 10 | Write-IcingaConsoleNotice -Message 'The Icinga Agent state file seems to be okay'; 11 | return; 12 | } 13 | 14 | $Success = Remove-ItemSecure -Path $StateFilePath -Force -Retries 5; 15 | 16 | if ($Success) { 17 | Write-IcingaConsoleNotice -Message 'The corrupted Icinga Agent State files have been removed'; 18 | } else { 19 | Write-IcingaConsoleError -Message 'Failed to remove the corrupted Icinga Agent state files'; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lib/core/icingaagent/setters/Set-IcingaUserPermissions.psm1: -------------------------------------------------------------------------------- 1 | function Set-IcingaUserPermissions() 2 | { 3 | param ( 4 | [string]$IcingaUser = (Get-IcingaServiceUser), 5 | [switch]$Remove = $FALSE 6 | ); 7 | 8 | Set-IcingaAcl -Directory "$Env:ProgramData\icinga2\etc" -IcingaUser $IcingaUser -Remove:$Remove; 9 | Set-IcingaAcl -Directory "$Env:ProgramData\icinga2\var" -IcingaUser $IcingaUser -Remove:$Remove; 10 | Set-IcingaAcl -Directory (Get-IcingaCacheDir) -IcingaUser $IcingaUser -Remove:$Remove; 11 | Set-IcingaAcl -Directory (Get-IcingaPowerShellConfigDir) -IcingaUser $IcingaUser -Remove:$Remove; 12 | Set-IcingaAcl -Directory (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'certificate') -IcingaUser $IcingaUser -Remove:$Remove; 13 | } 14 | -------------------------------------------------------------------------------- /lib/core/icingaagent/tests/Test-IcingaAgentConfig.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaAgentConfig() 2 | { 3 | param ( 4 | [switch]$WriteStackTrace 5 | ); 6 | 7 | $Binary = Get-IcingaAgentBinary; 8 | $ConfigResult = Start-IcingaProcess -Executable $Binary -Arguments 'daemon -C'; 9 | 10 | if ($ConfigResult.ExitCode -eq 0) { 11 | Write-IcingaTestOutput -Severity 'Passed' -Message 'Icinga Agent configuration is valid'; 12 | return $TRUE; 13 | } else { 14 | Write-IcingaTestOutput -Severity 'Failed' -Message 'Icinga Agent configuration contains errors. Run this command for getting a detailed error report: "Test-IcingaAgentConfig -WriteStackTrace | Out-Null"'; 15 | if ($WriteStackTrace) { 16 | Write-IcingaConsolePlain $ConfigResult.Message; 17 | } 18 | return $FALSE; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/core/icingaagent/tests/Test-IcingaAgentFeatureEnabled.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaAgentFeatureEnabled() 2 | { 3 | param( 4 | [string]$Feature 5 | ); 6 | 7 | $Features = Get-IcingaAgentFeatures; 8 | 9 | if ($Features.Enabled -Contains $Feature) { 10 | return $TRUE; 11 | } 12 | 13 | return $FALSE; 14 | } 15 | -------------------------------------------------------------------------------- /lib/core/icingaagent/tests/Test-IcingaStateFile.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaStateFile() 2 | { 3 | param ( 4 | [switch]$WriteOutput = $FALSE 5 | ); 6 | 7 | $IcingaAgentData = Get-IcingaAgentInstallation; 8 | [string]$StateFilePath = Join-Path -Path $ENV:ProgramData -ChildPath 'icinga2\var\lib\icinga2\icinga2.state'; 9 | 10 | if ((Test-Path $StateFilePath) -eq $FALSE) { 11 | Write-IcingaTestOutput -Severity 'Passed' -Message 'The Icinga Agent state file does not exist' -DropMessage:(-Not $WriteOutput); 12 | return $TRUE; 13 | } 14 | 15 | $Success = Read-IcingaStateFile; 16 | 17 | if ($Success) { 18 | Write-IcingaTestOutput -Severity 'Passed' -Message 'The Icinga Agent state file is healthy' -DropMessage:(-Not $WriteOutput); 19 | return $TRUE; 20 | } else { 21 | Write-IcingaTestOutput -Severity 'Failed' -Message 'The Icinga Agent state file is corrupt. Use the "Repair-IcingaStateFile" command to repair the file or "Read-IcingaStateFile -WriteOutput" for further details' -DropMessage:(-Not $WriteOutput); 22 | } 23 | 24 | return $FALSE; 25 | } 26 | -------------------------------------------------------------------------------- /lib/core/icingaagent/writers/Write-IcingaAgentObjectList.psm1: -------------------------------------------------------------------------------- 1 | function Write-IcingaAgentObjectList() 2 | { 3 | param( 4 | [string]$Path 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Path)) { 8 | throw 'Please specify a path to write the Icinga objects to'; 9 | } 10 | 11 | $ObjectList = Get-IcingaAgentObjectList; 12 | 13 | Write-IcingaFileSecure -File $Path -Value $ObjectList; 14 | } 15 | -------------------------------------------------------------------------------- /lib/core/icingaagent/writers/Write-IcingaTestOutput.psm1: -------------------------------------------------------------------------------- 1 | function Write-IcingaTestOutput() 2 | { 3 | param( 4 | [ValidateSet('Passed', 'Warning', 'Failed')] 5 | $Severity, 6 | $Message, 7 | [switch]$DropMessage = $FALSE 8 | ); 9 | 10 | if ($DropMessage) { 11 | return; 12 | } 13 | 14 | $Color = 'Green'; 15 | 16 | Switch ($Severity) { 17 | 'Passed' { 18 | $Color = 'Green'; 19 | break; 20 | }; 21 | 'Warning' { 22 | $Color = 'Yellow'; 23 | break; 24 | }; 25 | 'Failed' { 26 | $Color = 'Red'; 27 | break; 28 | }; 29 | } 30 | 31 | Write-Host '[' -NoNewline; 32 | Write-Host $Severity -ForegroundColor $Color -NoNewline; 33 | Write-Host ']:' $Message; 34 | } 35 | -------------------------------------------------------------------------------- /lib/core/installer/menu/installation/general/ContinueConfiguration.psm1: -------------------------------------------------------------------------------- 1 | function Show-IcingaForWindowsInstallerMenuContinueConfiguration() 2 | { 3 | $SwapConfig = Get-IcingaPowerShellConfig -Path 'Framework.Config.Swap'; 4 | $global:Icinga.InstallWizard.Config = Convert-IcingaForwindowsManagementConsoleJSONConfig -Config $SwapConfig; 5 | [string]$Menu = Get-IcingaForWindowsInstallerLastParent; 6 | 7 | # We don't need the last entry, as this will be added anyways because we are 8 | # starting right from there and it will be added anyway 9 | Remove-IcingaForWindowsInstallerLastParent; 10 | 11 | if ($Menu.Contains(':')) { 12 | $Menu = Get-IcingaForWindowsInstallerLastParent; 13 | } 14 | 15 | $global:Icinga.InstallWizard.NextCommand = $Menu; 16 | } 17 | -------------------------------------------------------------------------------- /lib/core/installer/menu/installation/general/InstallationAnswerFile.psm1: -------------------------------------------------------------------------------- 1 | function Export-IcingaForWindowsManagementConsoleInstallationAnswerFile() 2 | { 3 | $FilePath = ''; 4 | $Value = $global:Icinga.InstallWizard.LastValues; 5 | 6 | if ($null -ne $Value -And $Value.Count -ne 0) { 7 | $FilePath = $Value[0] 8 | } 9 | 10 | if (Test-Path ($FilePath)) { 11 | Write-IcingaFileSecure -File (Join-Path -Path $FilePath -ChildPath 'IfW_answer.json') -Value (Get-IcingaForWindowsManagementConsoleConfigurationString); 12 | $global:Icinga.InstallWizard.NextCommand = 'Install-Icinga'; 13 | $global:Icinga.InstallWizard.LastNotice = ([string]::Format('Answer file "IfW_answer.json" successfully exported into "{0}"', $FilePath)); 14 | Clear-IcingaForWindowsManagementConsolePaginationCache; 15 | } else { 16 | $global:Icinga.InstallWizard.LastError += ([string]::Format('The provided path to store the answer file is invalid: "{0}"', $FilePath)); 17 | $global:Icinga.InstallWizard.NextCommand = 'Show-IcingaForWindowsManagementConsoleInstallationFileExport'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/core/installer/menu/installation/general/InstallationFileExport.psm1: -------------------------------------------------------------------------------- 1 | function Show-IcingaForWindowsManagementConsoleInstallationFileExport() 2 | { 3 | $FilePath = $ENV:USERPROFILE; 4 | 5 | if ($null -ne $global:Icinga.InstallWizard.LastValues -And $global:Icinga.InstallWizard.LastValues.Count -ne 0) { 6 | $FilePath = $global:Icinga.InstallWizard.LastValues[0]; 7 | } 8 | 9 | Show-IcingaForWindowsInstallerMenu ` 10 | -Header 'Where do you want to export the answer file to? The filename "IfW_answer.json" is added automatically.' ` 11 | -Entries @( 12 | @{ 13 | 'Caption' = ''; 14 | 'Command' = 'Export-IcingaForWindowsManagementConsoleInstallationAnswerFile'; 15 | 'Help' = 'This will all you to export the answer file with the given configuration. You can install Icinga for Windows with this file by using the command "Install-Icinga -InstallFile ".'; 16 | } 17 | ) ` 18 | -AddConfig ` 19 | -DefaultValues @( $FilePath ) ` 20 | -ConfigLimit 1 ` 21 | -DefaultIndex 'c' ` 22 | -MandatoryValue ` 23 | -Hidden; 24 | } 25 | -------------------------------------------------------------------------------- /lib/core/installer/menu/installation/general/NewConfiguration.psm1: -------------------------------------------------------------------------------- 1 | function Show-IcingaForWindowsInstallerMenuNewConfiguration() 2 | { 3 | $global:Icinga.InstallWizard.Config = @{ }; 4 | Show-IcingaForWindowsInstallerMenuSelectConnection; 5 | } 6 | -------------------------------------------------------------------------------- /lib/core/installer/menu/manage/agent/ReconfigureAgent.psm1: -------------------------------------------------------------------------------- 1 | function Invoke-IcingaForWindowsManagementConsoleReconfigureAgent() 2 | { 3 | $LiveConfig = Get-IcingaPowerShellConfig -Path 'Framework.Config.Live'; 4 | 5 | if ($null -eq $LiveConfig) { 6 | $global:Icinga.InstallWizard.NextCommand = 'Show-IcingaForWindowsInstallerMenuInstallWindows'; 7 | $global:Icinga.InstallWizard.LastError += 'Unable to load any previous live configuration. Reconfiguring not possible.'; 8 | return; 9 | } 10 | 11 | $global:Icinga.InstallWizard.Config = Convert-IcingaForwindowsManagementConsoleJSONConfig -Config $LiveConfig; 12 | $global:Icinga.InstallWizard.NextCommand = 'Show-IcingaForWindowsInstallerConfigurationSummary'; 13 | } 14 | -------------------------------------------------------------------------------- /lib/core/installer/menu/manage/framework/FrameworkExperimental.psm1: -------------------------------------------------------------------------------- 1 | function Show-IcingaForWindowsManagementConsoleFrameworkExperimental() 2 | { 3 | [array]$Entries = @(); 4 | 5 | if ($Entries.Count -ne 0) { 6 | Show-IcingaForWindowsInstallerMenu ` 7 | -Header 'Manage Icinga for Windows experimental features. Not recommended for production!' ` 8 | -Entries $Entries; 9 | } else { 10 | Show-IcingaForWindowsInstallerMenu ` 11 | -Header 'No experimental features for Icinga for Windows available'; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /lib/core/installer/menu/manage/framework/ToogleFrameworkApiChecks.psm1: -------------------------------------------------------------------------------- 1 | function Invoke-IcingaForWindowsManagementConsoleToggleFrameworkApiChecks() 2 | { 3 | if (Get-IcingaFrameworkApiChecks) { 4 | Disable-IcingaFrameworkApiChecks; 5 | } else { 6 | if ((Get-IcingaBackgroundDaemons).ContainsKey('Start-IcingaWindowsRESTApi') -eq $FALSE) { 7 | Register-IcingaBackgroundDaemon -Command 'Start-IcingaWindowsRESTApi'; 8 | Add-IcingaRESTApiCommand -Command 'Invoke-IcingaCheck*' -Endpoint 'apichecks'; 9 | } 10 | 11 | # We need to run the task renewal with our scheduled task to fix errors while using WinRM / SSH 12 | Start-IcingaWindowsScheduledTaskRenewCertificate; 13 | Enable-IcingaFrameworkApiChecks; 14 | } 15 | 16 | Restart-IcingaForWindows; 17 | } 18 | -------------------------------------------------------------------------------- /lib/core/installer/menu/manage/framework/ToogleFrameworkDebug.psm1: -------------------------------------------------------------------------------- 1 | function Invoke-IcingaForWindowsManagementConsoleToggleFrameworkDebug() 2 | { 3 | if (Get-IcingaFrameworkDebugMode) { 4 | Disable-IcingaFrameworkDebugMode; 5 | } else { 6 | Enable-IcingaFrameworkDebugMode; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /lib/core/installer/menu/manage/framework/daemons/ManageBackgroundDaemons.psm1: -------------------------------------------------------------------------------- 1 | function Show-IcingaForWindowsManagementConsoleManageBackgroundDaemons() 2 | { 3 | Show-IcingaForWindowsInstallerMenu ` 4 | -Header 'Manage the Icinga for Windows background daemons:' ` 5 | -Entries @( 6 | @{ 7 | 'Caption' = 'Register background daemon'; 8 | 'Command' = 'Show-IcingaForWindowsManagementConsoleRegisterBackgroundDaemons'; 9 | 'Help' = 'Allows you to register a new background daemon for Icinga for Windows'; 10 | 'Disabled' = $FALSE; 11 | }, 12 | @{ 13 | 'Caption' = 'Unregister background daemon'; 14 | 'Command' = 'Show-IcingaForWindowsManagementConsoleUnregisterBackgroundDaemons'; 15 | 'Help' = 'Remove registered Icinga for Windows background daemons'; 16 | 'Disabled' = $FALSE; 17 | } 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /lib/core/installer/menu/manage/framework/repository/ShowRepositoryList.psm1: -------------------------------------------------------------------------------- 1 | function Show-IcingaForWindowsManagementConsoleIcingaRepositoriesList() 2 | { 3 | [array]$Repositories = @(); 4 | [array]$RepoList = Get-IcingaRepositories; 5 | [int]$MaxLength = Get-IcingaMaxTextLength -TextArray $RepoList.Name; 6 | 7 | foreach ($repo in $RepoList) { 8 | 9 | $PrintName = Add-IcingaWhiteSpaceToString -Text $repo.Name -Length $MaxLength; 10 | $PrintName = [string]::Format('{0}=> {1}', $PrintName, $repo.Value.RemotePath); 11 | 12 | $Repositories += @{ 13 | 'Caption' = $PrintName; 14 | 'Command' = 'Show-IcingaForWindowsManagementConsoleIcingaRepositoriesList'; 15 | 'Help' = ''; 16 | 'Disabled' = (-Not $repo.Value.Enabled); 17 | } 18 | } 19 | 20 | if ($Repositories.Count -ne 0) { 21 | Show-IcingaForWindowsInstallerMenu ` 22 | -Header 'List of local configured Icinga Repositories' ` 23 | -Entries $Repositories; 24 | } else { 25 | Show-IcingaForWindowsInstallerMenu ` 26 | -Header 'There are no local configured Icinga Repositories' 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/core/installer/menu/manage/general/ListOverview.psm1: -------------------------------------------------------------------------------- 1 | function Show-IcingaForWindowsMenuListEnvironment() 2 | { 3 | Show-IcingaForWindowsInstallerMenu ` 4 | -Header 'Icinga for Windows environment overview:' ` 5 | -Entries @( 6 | @{ 7 | 'Caption' = ''; 8 | 'Command' = 'Install-Icinga'; 9 | 'Help' = 'A summary of your current Icinga for Windows installation'; 10 | } 11 | ) ` 12 | -AddConfig ` 13 | -DefaultValues @(([string]::Join("`n", (Show-Icinga -SkipHeader)))) ` 14 | -ConfigLimit 1 ` 15 | -DefaultIndex 'c' ` 16 | -ReadOnly ` 17 | -PlainTextOutput ` 18 | -Hidden; 19 | } 20 | -------------------------------------------------------------------------------- /lib/core/installer/menu/manage/shell/StartIcingaShell.psm1: -------------------------------------------------------------------------------- 1 | function Invoke-IcingaForWindowsMenuStartIcingaShell() 2 | { 3 | Clear-CLIConsole; 4 | $global:Icinga.InstallWizard.Closing = $TRUE; 5 | Invoke-IcingaCommand -Shell; 6 | } 7 | -------------------------------------------------------------------------------- /lib/core/installer/tools/AddDisabledEntry.psm1: -------------------------------------------------------------------------------- 1 | function Add-IcingaForWindowsInstallerDisabledEntry() 2 | { 3 | param ( 4 | [string]$Name = '', 5 | [string]$Reason = '' 6 | ); 7 | 8 | if ([string]::IsNullOrEmpty($Reason)) { 9 | $Reason = 'Generic disable message'; 10 | } 11 | 12 | if ($Global:Icinga.InstallWizard.DisabledEntries.ContainsKey($Name)) { 13 | $Global:Icinga.InstallWizard.DisabledEntries[$Name] = $Reason; 14 | return; 15 | } 16 | 17 | $Global:Icinga.InstallWizard.DisabledEntries.Add($Name, $Reason); 18 | } 19 | -------------------------------------------------------------------------------- /lib/core/installer/tools/Alias.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaForWindowsManagementConsoleAlias() 2 | { 3 | param ( 4 | [string]$Command 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Command)) { 8 | return ''; 9 | } 10 | 11 | $ParentEntry = $null; 12 | 13 | if ($Command.Contains(':')) { 14 | $KeyValue = $Command.Split(':'); 15 | $Command = $KeyValue[0]; 16 | $ParentEntry = $KeyValue[1]; 17 | } 18 | 19 | $CommandAlias = Get-Alias -Definition $Command -ErrorAction SilentlyContinue; 20 | 21 | if ($null -ne $CommandAlias) { 22 | $Command = $CommandAlias.Name; 23 | } 24 | 25 | if ([string]::IsNullOrEmpty($ParentEntry) -eq $FALSE) { 26 | $Command = [string]::Format('{0}:{1}', $Command, $ParentEntry); 27 | } 28 | 29 | return $Command; 30 | } 31 | -------------------------------------------------------------------------------- /lib/core/installer/tools/Clear-CLIConsole.psm1: -------------------------------------------------------------------------------- 1 | function Clear-CLIConsole() 2 | { 3 | try { 4 | Clear-Host -ErrorAction Stop; 5 | } catch { 6 | # Nothing to do 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /lib/core/installer/tools/ClearValuesFromStep.psm1: -------------------------------------------------------------------------------- 1 | function Clear-IcingaForWindowsInstallerValuesFromStep() 2 | { 3 | $Step = Get-IcingaForWindowsManagementConsoleMenu; 4 | 5 | if ($global:Icinga.InstallWizard.Config.ContainsKey($Step) -eq $FALSE) { 6 | return; 7 | } 8 | 9 | if ($null -eq $global:Icinga.InstallWizard.Config[$Step].Values) { 10 | return; 11 | } 12 | 13 | $global:Icinga.InstallWizard.Config[$Step].Values = @(); 14 | } 15 | -------------------------------------------------------------------------------- /lib/core/installer/tools/ConfigEntry.psm1: -------------------------------------------------------------------------------- 1 | function Remove-IcingaForWindowsInstallerConfigEntry() 2 | { 3 | param ( 4 | [string]$Menu, 5 | [string]$Parent 6 | ); 7 | 8 | $Menu = Get-IcingaForWindowsManagementConsoleAlias -Command $Menu; 9 | 10 | if ([string]::IsNullOrEmpty($Parent) -eq $FALSE) { 11 | $Menu = [string]::Format('{0}:{1}', $Menu, $Parent); 12 | } 13 | 14 | if ($global:Icinga.InstallWizard.Config.ContainsKey($Menu)) { 15 | $global:Icinga.InstallWizard.Config.Remove($Menu); 16 | } 17 | 18 | Write-IcingaforWindowsManagementConsoleConfigSwap -Config $global:Icinga.InstallWizard.Config; 19 | } 20 | -------------------------------------------------------------------------------- /lib/core/installer/tools/ConsoleLastParent.psm1: -------------------------------------------------------------------------------- 1 | function Add-IcingaForWindowsManagementConsoleLastParent() 2 | { 3 | $Menu = Get-IcingaForWindowsManagementConsoleAlias -Command (Get-IcingaForWindowsManagementConsoleMenu); 4 | 5 | if ($Menu -eq (Get-IcingaForWindowsInstallerLastParent)) { 6 | return; 7 | } 8 | 9 | # Do not add Yes/No Dialog to the list 10 | if ($Menu -eq 'Show-IcingaWindowsManagementConsoleYesNoDialog') { 11 | return; 12 | } 13 | 14 | $global:Icinga.InstallWizard.LastParent.Add($Menu) | Out-Null; 15 | } 16 | -------------------------------------------------------------------------------- /lib/core/installer/tools/DirectorConfigModifyState.psm1: -------------------------------------------------------------------------------- 1 | function Reset-IcingaForWindowsManagementConsoleInstallationDirectorConfigModifyState() 2 | { 3 | foreach ($entry in $Global:Icinga.InstallWizard.Config.Keys) { 4 | 5 | if ($entry -eq 'IfW-DirectorUrl' -Or $entry -eq 'IfW-DirectorSelfServiceKey') { 6 | continue; 7 | } 8 | 9 | $Global:Icinga.InstallWizard.Config[$entry].Modified = $FALSE; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/core/installer/tools/GetDisabledEntry.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaForWindowsInstallerDisabledEntry() 2 | { 3 | param ( 4 | [string]$Name = '' 5 | ); 6 | 7 | if ($Global:Icinga.InstallWizard.DisabledEntries.ContainsKey($Name)) { 8 | return ($Global:Icinga.InstallWizard.DisabledEntries[$Name]); 9 | } 10 | 11 | return ''; 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/installer/tools/GetLastParent.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaForWindowsInstallerLastParent() 2 | { 3 | if ($global:Icinga.InstallWizard.LastParent.Count -ne 0) { 4 | $Parent = $global:Icinga.InstallWizard.LastParent[-1]; 5 | return $Parent; 6 | } 7 | 8 | return $null; 9 | } 10 | -------------------------------------------------------------------------------- /lib/core/installer/tools/GetPowerShellServicePassword.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaInternalPowerShellServicePassword() 2 | { 3 | if ($null -eq $global:Icinga -Or $Global:Icinga.ContainsKey('InstallerServicePassword') -eq $FALSE) { 4 | return $null; 5 | } 6 | 7 | return $Global:Icinga.InstallerServicePassword; 8 | } 9 | -------------------------------------------------------------------------------- /lib/core/installer/tools/Menu.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaForWindowsManagementConsoleMenu() 2 | { 3 | if ($null -eq $global:Icinga -Or $null -eq $global:Icinga.InstallWizard) { 4 | return ''; 5 | } 6 | 7 | if ([string]::IsNullOrEmpty($global:Icinga.InstallWizard.Menu) -Or $global:Icinga.InstallWizard.Menu -eq 'break') { 8 | return ''; 9 | } 10 | 11 | return (Get-IcingaForWindowsManagementConsoleAlias -Command $global:Icinga.InstallWizard.Menu); 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/installer/tools/PaginationCache.psm1: -------------------------------------------------------------------------------- 1 | function Clear-IcingaForWindowsManagementConsolePaginationCache() 2 | { 3 | $global:Icinga.InstallWizard.LastParent.Clear(); 4 | } 5 | -------------------------------------------------------------------------------- /lib/core/installer/tools/RemoveLastParent.psm1: -------------------------------------------------------------------------------- 1 | function Remove-IcingaForWindowsInstallerLastParent() 2 | { 3 | if ($global:Icinga.InstallWizard.LastParent.Count -ne 0) { 4 | $global:Icinga.InstallWizard.LastParent.RemoveAt($global:Icinga.InstallWizard.LastParent.Count - 1); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /lib/core/installer/tools/SetCloseIMC.psm1: -------------------------------------------------------------------------------- 1 | function Set-IcingaForWindowsManagementConsoleClosing() 2 | { 3 | param ( 4 | [switch]$Completed = $FALSE 5 | ); 6 | 7 | if ($null -eq $Global:Icinga) { 8 | return; 9 | } 10 | 11 | if ($Global:Icinga.ContainsKey('InstallWizard') -eq $FALSE) { 12 | return; 13 | } 14 | 15 | if ($Global:Icinga.InstallWizard.ContainsKey('Closing') -eq $FALSE) { 16 | return; 17 | } 18 | 19 | $global:Icinga.InstallWizard.Closing = (-Not ([bool]$Completed)); 20 | } 21 | -------------------------------------------------------------------------------- /lib/core/installer/tools/SetConsoleMenu.psm1: -------------------------------------------------------------------------------- 1 | function Set-IcingaForWindowsManagementConsoleMenu() 2 | { 3 | param ( 4 | [string]$Menu 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Menu) -Or $Menu -eq 'break') { 8 | return; 9 | } 10 | 11 | $global:Icinga.InstallWizard.Menu = (Get-IcingaForWindowsManagementConsoleAlias -Command $Menu); 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/installer/tools/SetPowerShellServicePassword.psm1: -------------------------------------------------------------------------------- 1 | function Set-IcingaInternalPowerShellServicePassword() 2 | { 3 | param ( 4 | [SecureString]$Password = $null 5 | ); 6 | 7 | if ($null -eq $global:Icinga) { 8 | $Global:Icinga = @{ 9 | 'InstallerServicePassword' = $Password; 10 | } 11 | 12 | return; 13 | } 14 | 15 | if ($Global:Icinga.ContainsKey('InstallerServicePassword') -eq $FALSE) { 16 | $Global:Icinga.Add( 17 | 'InstallerServicePassword', 18 | $Password 19 | ) 20 | 21 | return; 22 | } 23 | 24 | $Global:Icinga.InstallerServicePassword = $Password; 25 | } 26 | -------------------------------------------------------------------------------- /lib/core/installer/tools/SetUpdatingIMC.psm1: -------------------------------------------------------------------------------- 1 | function Set-IcingaForWindowsManagementConsoleUpdating() 2 | { 3 | param ( 4 | [switch]$Completed = $FALSE 5 | ); 6 | 7 | Set-IcingaForWindowsManagementConsoleClosing; 8 | 9 | $UpdateFile = Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'framework.update'; 10 | if ($Completed) { 11 | if (Test-IcingaForWindowsManagementConsoleUpdating) { 12 | Remove-ItemSecure -Path $UpdateFile -Force -Retries 5 | Out-Null; 13 | } 14 | } else { 15 | New-Item -Path $UpdateFile -ItemType File -Force | Out-Null; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lib/core/installer/tools/SetValuesFromStep.psm1: -------------------------------------------------------------------------------- 1 | function Set-IcingaForWindowsInstallerValuesFromStep() 2 | { 3 | param ( 4 | [string]$InstallerStep, 5 | [string]$Parent, 6 | [array]$Values = @() 7 | ); 8 | 9 | $Step = Get-IcingaForWindowsManagementConsoleMenu; 10 | 11 | if ([string]::IsNullOrEmpty($InstallerStep) -eq $FALSE) { 12 | $Step = Get-IcingaForWindowsManagementConsoleAlias -Command $InstallerStep; 13 | 14 | if ([string]::IsNullOrEmpty($Parent) -eq $FALSE) { 15 | $Step = [string]::Format('{0}:{1}', $Step, $Parent); 16 | } 17 | } 18 | 19 | $global:Icinga.InstallWizard.Config[$Step].Values = $Values; 20 | } 21 | -------------------------------------------------------------------------------- /lib/core/installer/tools/StepSelection.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaForWindowsInstallerStepSelection() 2 | { 3 | param ( 4 | [string]$InstallerStep 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($InstallerStep)) { 8 | $InstallerStep = Get-IcingaForWindowsManagementConsoleMenu; 9 | } else { 10 | $InstallerStep = Get-IcingaForWindowsManagementConsoleAlias -Command $InstallerStep; 11 | } 12 | 13 | if ($global:Icinga.InstallWizard.Config.ContainsKey($InstallerStep)) { 14 | return $global:Icinga.InstallWizard.Config[$InstallerStep].Selection; 15 | } 16 | 17 | return $null; 18 | } 19 | -------------------------------------------------------------------------------- /lib/core/installer/tools/TestUpdatingIMC.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaForWindowsManagementConsoleUpdating() 2 | { 3 | $UpdateFile = Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'framework.update'; 4 | 5 | return (Test-Path -Path $UpdateFile); 6 | } 7 | -------------------------------------------------------------------------------- /lib/core/installer/tools/ValuesFromStep.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaForWindowsInstallerValuesFromStep() 2 | { 3 | param ( 4 | [string]$InstallerStep, 5 | [string]$Parent 6 | ); 7 | 8 | [array]$Values = @(); 9 | 10 | $Step = Get-IcingaForWindowsManagementConsoleMenu; 11 | 12 | if ([string]::IsNullOrEmpty($InstallerStep) -eq $FALSE) { 13 | $Step = Get-IcingaForWindowsManagementConsoleAlias -Command $InstallerStep; 14 | 15 | if ([string]::IsNullOrEmpty($Parent) -eq $FALSE) { 16 | $Step = [string]::Format('{0}:{1}', $Step, $Parent); 17 | } 18 | } 19 | 20 | if ($global:Icinga.InstallWizard.Config.ContainsKey($Step) -eq $FALSE) { 21 | return @(); 22 | } 23 | 24 | if ($null -eq $global:Icinga.InstallWizard.Config[$Step].Values) { 25 | return @(); 26 | } 27 | 28 | return [array]($global:Icinga.InstallWizard.Config[$Step].Values); 29 | } 30 | -------------------------------------------------------------------------------- /lib/core/installer/tools/WriteConfigSwap.psm1: -------------------------------------------------------------------------------- 1 | function Write-IcingaforWindowsManagementConsoleConfigSwap() 2 | { 3 | param ( 4 | $Config = @{ } 5 | ); 6 | 7 | [hashtable]$NewConfig = @{ }; 8 | 9 | # Remove passwords - do not store them inside our local config file 10 | foreach ($entry in $Config.Keys) { 11 | $Value = $Config[$entry]; 12 | 13 | $NewConfig.Add($entry, @{ }); 14 | 15 | foreach ($configElement in $Value.Keys) { 16 | $confValue = $Value[$configElement]; 17 | 18 | if ($Value.Password -eq $TRUE -And $configElement -eq 'Values') { 19 | $NewConfig[$entry].Add( 20 | $configElement, 21 | @( '***' ) 22 | ); 23 | } else { 24 | $NewConfig[$entry].Add( 25 | $configElement, 26 | $confValue 27 | ); 28 | } 29 | } 30 | } 31 | 32 | Set-IcingaPowerShellConfig -Path 'Framework.Config.Swap' -Value $NewConfig; 33 | } 34 | -------------------------------------------------------------------------------- /lib/core/installer/tools/actions/ConsoleContinue.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaForWindowsManagementConsoleContinue() 2 | { 3 | if ([string]::IsNullOrEmpty($global:Icinga.InstallWizard.LastInput)) { 4 | return $FALSE; 5 | } 6 | 7 | if ($global:Icinga.InstallWizard.LastInput -eq 'c') { 8 | return $TRUE; 9 | } 10 | 11 | return $FALSE; 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/installer/tools/actions/ConsoleDelete.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaForWindowsManagementConsoleDelete() 2 | { 3 | if ([string]::IsNullOrEmpty($global:Icinga.InstallWizard.LastInput)) { 4 | return $FALSE; 5 | } 6 | 7 | if ($global:Icinga.InstallWizard.LastInput -eq 'd') { 8 | return $TRUE; 9 | } 10 | 11 | return $FALSE; 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/installer/tools/actions/ConsoleExit.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaForWindowsManagementConsoleExit() 2 | { 3 | if ([string]::IsNullOrEmpty($global:Icinga.InstallWizard.LastInput)) { 4 | return $FALSE; 5 | } 6 | 7 | if ($global:Icinga.InstallWizard.LastInput -eq 'x') { 8 | return $TRUE; 9 | } 10 | 11 | return $FALSE; 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/installer/tools/actions/ConsoleHelp.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaForWindowsManagementConsoleHelp() 2 | { 3 | if ([string]::IsNullOrEmpty($global:Icinga.InstallWizard.LastInput)) { 4 | return $FALSE; 5 | } 6 | 7 | if ($global:Icinga.InstallWizard.LastInput -eq 'h') { 8 | return $TRUE; 9 | } 10 | 11 | return $FALSE; 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/installer/tools/actions/ConsoleMenu.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaForWindowsManagementConsoleMenu() 2 | { 3 | if ([string]::IsNullOrEmpty($global:Icinga.InstallWizard.LastInput)) { 4 | return $FALSE; 5 | } 6 | 7 | if ($global:Icinga.InstallWizard.LastInput -eq 'm') { 8 | return $TRUE; 9 | } 10 | 11 | return $FALSE; 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/installer/tools/actions/ConsolePrevious.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaForWindowsManagementConsolePrevious() 2 | { 3 | if ([string]::IsNullOrEmpty($global:Icinga.InstallWizard.LastInput)) { 4 | return $FALSE; 5 | } 6 | 7 | if ($global:Icinga.InstallWizard.LastInput -eq 'p') { 8 | return $TRUE; 9 | } 10 | 11 | return $FALSE; 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/installer/tools/actions/LastInput.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaForWindowsManagementConsoleLastInput() 2 | { 3 | return $global:Icinga.InstallWizard.LastInput; 4 | } 5 | -------------------------------------------------------------------------------- /lib/core/installer/tools/environment/DisableHeaderPrint.psm1: -------------------------------------------------------------------------------- 1 | function Disable-IcingaForWindowsInstallationHeaderPrint() 2 | { 3 | $global:Icinga.InstallWizard.HeaderPrint = $FALSE; 4 | } 5 | -------------------------------------------------------------------------------- /lib/core/installer/tools/environment/DisableJumpToSummary.psm1: -------------------------------------------------------------------------------- 1 | function Disable-IcingaForWindowsInstallationJumpToSummary() 2 | { 3 | $global:Icinga.InstallWizard.JumpToSummary = $FALSE; 4 | } 5 | -------------------------------------------------------------------------------- /lib/core/installer/tools/environment/EnableHeaderPrint.psm1: -------------------------------------------------------------------------------- 1 | function Enable-IcingaForWindowsInstallationHeaderPrint() 2 | { 3 | $global:Icinga.InstallWizard.HeaderPrint = $TRUE; 4 | } 5 | -------------------------------------------------------------------------------- /lib/core/installer/tools/environment/EnableJumpToSummary.psm1: -------------------------------------------------------------------------------- 1 | function Enable-IcingaForWindowsInstallationJumpToSummary() 2 | { 3 | $global:Icinga.InstallWizard.JumpToSummary = $TRUE; 4 | } 5 | -------------------------------------------------------------------------------- /lib/core/installer/tools/environment/GetHeaderSelection.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaForWindowsInstallationHeaderSelection() 2 | { 3 | return $global:Icinga.InstallWizard.HeaderSelection; 4 | } 5 | -------------------------------------------------------------------------------- /lib/core/installer/tools/environment/HeaderPrint.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaForWindowsInstallationHeaderPrint() 2 | { 3 | return $global:Icinga.InstallWizard.HeaderPrint; 4 | } 5 | -------------------------------------------------------------------------------- /lib/core/installer/tools/environment/JumpToSummary.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaForWindowsInstallationJumpToSummary() 2 | { 3 | return $global:Icinga.InstallWizard.JumpToSummary; 4 | } 5 | -------------------------------------------------------------------------------- /lib/core/installer/tools/environment/SetHeaderSelection.psm1: -------------------------------------------------------------------------------- 1 | function Set-IcingaForWindowsInstallationHeaderSelection() 2 | { 3 | param ( 4 | [string]$Selection = $null 5 | ); 6 | 7 | $global:Icinga.InstallWizard.HeaderSelection = $Selection; 8 | } 9 | -------------------------------------------------------------------------------- /lib/core/jea/Get-IcingaJEAContext.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaJEAContext() 2 | { 3 | return (Get-IcingaPowerShellConfig -Path 'Framework.JEAProfile'); 4 | } 5 | -------------------------------------------------------------------------------- /lib/core/jea/Get-IcingaJEAServicePid.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaJEAServicePid() 2 | { 3 | [string]$JeaPidFile = (Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'jea.pid'); 4 | [string]$JeaPid = Read-IcingaFileSecure -File $JeaPidFile; 5 | 6 | if ([string]::IsNullOrEmpty($JeaPid) -eq $FALSE) { 7 | $JeaPid = $JeaPid.Replace("`r`n", '').Replace("`n", '').Replace(' ', ''); 8 | } 9 | 10 | if ([string]::IsNullOrEmpty($JeaPid) -Or $JeaPid -eq '0' -Or $JeaPid -eq 0) { 11 | return $null; 12 | } 13 | 14 | return $JeaPid; 15 | } 16 | -------------------------------------------------------------------------------- /lib/core/jea/Get-IcingaJEASessionFile.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaJEASessionFile() 2 | { 3 | [string]$Path = Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'RoleCapabilities\IcingaForWindows.psrc'; 4 | 5 | if (Test-Path -Path $Path) { 6 | return $Path; 7 | } 8 | 9 | return ''; 10 | } 11 | -------------------------------------------------------------------------------- /lib/core/jea/Remove-IcingaFrameworkDependencyFile.psm1: -------------------------------------------------------------------------------- 1 | function Remove-IcingaFrameworkDependencyFile() 2 | { 3 | $DependencyFile = Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'framework_dependencies.json'; 4 | 5 | if (-Not (Test-Path $DependencyFile)) { 6 | return; 7 | } 8 | 9 | Remove-ItemSecure -Path $DependencyFile -Force | Out-Null; 10 | } 11 | -------------------------------------------------------------------------------- /lib/core/jea/Set-IcingaForWindowsServiceJEAProfile.psm1: -------------------------------------------------------------------------------- 1 | function Set-IcingaForWindowsServiceJEAProfile() 2 | { 3 | [string]$JeaProfile = Get-IcingaJEAContext; 4 | $IcingaForWindowsService = Get-IcingaForWindowsServiceData; 5 | 6 | if ([string]::IsNullOrEmpty($IcingaForWindowsService.FullPath) -Or (Test-Path $IcingaForWindowsService.FullPath) -eq $FALSE) { 7 | return; 8 | } 9 | 10 | [string]$PreparedServicePath = [string]::Format( 11 | '\"{0}\" \"{1}\" \"{2}\"', 12 | $IcingaForWindowsService.FullPath, 13 | (Get-IcingaPowerShellModuleFile), 14 | $JeaProfile 15 | ); 16 | 17 | $Result = Start-IcingaProcess -Executable 'sc.exe' -Arguments ([string]::Format('config icingapowershell binPath= "{0}"', $PreparedServicePath)); 18 | 19 | if ($Result.ExitCode -ne 0) { 20 | Write-IcingaConsoleError 'Failed to update Icinga for Windows service for JEA profile "{0}": {1}{2}' -Objects $JeaProfile, $ResolveStatus.Message, $ResolveStatus.Error; 21 | } else { 22 | Write-IcingaConsoleNotice 'Icinga for Windows service JEA handling has been configured successfully to profile "{0}"' -Objects $JeaProfile; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lib/core/jea/Test-IcingaJEAServiceRunning.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaJEAServiceRunning() 2 | { 3 | param ( 4 | [string]$JeaPid = $null 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($JeaPid)) { 8 | [string]$JeaPid = Get-IcingaJEAServicePid; 9 | } 10 | 11 | if ([string]::IsNullOrEmpty($JeaPid)) { 12 | return $FALSE; 13 | } 14 | 15 | if ($JeaPid -eq '0' -Or $JeaPid -eq 0) { 16 | return $FALSE; 17 | } 18 | 19 | $JeaPowerShellProcess = Get-Process -Id $JeaPid -ErrorAction SilentlyContinue; 20 | if ($null -eq $JeaPowerShellProcess) { 21 | return $FALSE; 22 | } 23 | 24 | if ($JeaPowerShellProcess.ProcessName -ne 'wsmprovhost') { 25 | return $FALSE; 26 | } 27 | 28 | return $TRUE; 29 | } 30 | -------------------------------------------------------------------------------- /lib/core/jea/Uninstall-IcingaJEAProfile.psm1: -------------------------------------------------------------------------------- 1 | function Uninstall-IcingaJEAProfile() 2 | { 3 | $JeaProfile = Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'IcingaForWindows.pssc'; 4 | $JeaProfileRessource = Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'RoleCapabilities\IcingaForWindows.psrc'; 5 | 6 | if (Test-Path $JeaProfile) { 7 | Write-IcingaConsoleNotice 'Removing JEA profile'; 8 | Remove-Item $JeaProfile -Force; 9 | } 10 | 11 | if (Test-Path $JeaProfileRessource) { 12 | Write-IcingaConsoleNotice 'Removing JEA profile ressource'; 13 | Remove-Item $JeaProfileRessource -Force; 14 | } 15 | 16 | Write-IcingaConsoleNotice 'Removing JEA profile registration'; 17 | Unregister-PSSessionConfiguration -Name 'IcingaForWindows' -Force -ErrorAction SilentlyContinue; 18 | 19 | Set-IcingaPowerShellConfig -Path 'Framework.JEAProfile' -Value ''; 20 | } 21 | -------------------------------------------------------------------------------- /lib/core/logging/Icinga_EventLog_DebugEnums.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | # This script will provide 'Enums' we can use for proper 3 | # error handling and to provide more detailed descriptions 4 | # 5 | # Example usage: 6 | # $IcingaEventLogEnums[2000] 7 | #> 8 | if ($null -eq $IcingaEventLogEnums -Or $IcingaEventLogEnums.ContainsKey('Debug') -eq $FALSE) { 9 | [hashtable]$IcingaEventLogEnums += @{ 10 | 'Debug' = @{ 11 | 1000 = @{ 12 | 'EntryType' = 'Information'; 13 | 'Message' = 'Generic debug message issued by the Framework or its components'; 14 | 'Details' = 'The Framework or is components can issue generic debug message in case the debug log is enabled. Please ensure to disable it, if not used. You can do so with the command "Disable-IcingaFrameworkDebugMode"'; 15 | 'EventId' = 1000; 16 | }; 17 | } 18 | }; 19 | } 20 | 21 | Export-ModuleMember -Variable @( 'IcingaEventLogEnums' ); 22 | -------------------------------------------------------------------------------- /lib/core/logging/Register-IcingaEventLog.psm1: -------------------------------------------------------------------------------- 1 | function Register-IcingaEventLog() 2 | { 3 | param ( 4 | [string]$LogName = $null 5 | ); 6 | 7 | if ((Test-AdministrativeShell) -eq $FALSE) { 8 | return; 9 | } 10 | 11 | if ([string]::IsNullOrEmpty($LogName)) { 12 | New-EventLog -LogName 'Icinga for Windows' -Source 'IfW::Framework' -ErrorAction SilentlyContinue; 13 | New-EventLog -LogName 'Icinga for Windows' -Source 'IfW::Service' -ErrorAction SilentlyContinue; 14 | New-EventLog -LogName 'Icinga for Windows' -Source 'IfW::Debug' -ErrorAction SilentlyContinue; 15 | } else { 16 | $LogName = [string]::Format('IfW::{0}', $LogName); 17 | 18 | New-EventLog -LogName 'Icinga for Windows' -Source $LogName -ErrorAction SilentlyContinue; 19 | } 20 | 21 | $IfWEventLog = Get-WinEvent -ListLog 'Icinga for Windows'; 22 | 23 | # In case the value is already set, nothing to do 24 | if ($IfWEventLog.MaximumSizeInBytes -ge 20971520) { 25 | return; 26 | } 27 | 28 | # Set the size to 20MiB 29 | $IfWEventLog.MaximumSizeInBytes = 20971520; 30 | $IfWEventLog.SaveChanges(); 31 | } 32 | -------------------------------------------------------------------------------- /lib/core/logging/Unregister-IcingaEventLog.psm1: -------------------------------------------------------------------------------- 1 | function Unregister-IcingaEventLog() 2 | { 3 | # Icinga for Windows v1.8.0 or later 4 | Remove-EventLog -LogName 'Icinga for Windows' -ErrorAction SilentlyContinue; 5 | 6 | # Older versions 7 | Remove-EventLog -Source 'Icinga for Windows' -ErrorAction SilentlyContinue; 8 | # Icinga for Windows v1.8.0 or later - required a second time to ensure 9 | # everything is removed for legacy versions 10 | Remove-EventLog -LogName 'Icinga for Windows' -ErrorAction SilentlyContinue; 11 | } 12 | -------------------------------------------------------------------------------- /lib/core/logging/Write-IcingaDebugMessage.psm1: -------------------------------------------------------------------------------- 1 | function Write-IcingaDebugMessage() 2 | { 3 | param ( 4 | [string]$Message, 5 | [array]$Objects = @(), 6 | $ExceptionObject = $null 7 | ); 8 | 9 | if ([string]::IsNullOrEmpty($Message)) { 10 | return; 11 | } 12 | 13 | if ($Global:Icinga.Protected.DebugMode -eq $FALSE) { 14 | return; 15 | } 16 | 17 | [array]$DebugContent = @($Message); 18 | $DebugContent += $Objects; 19 | 20 | Write-IcingaEventMessage -EventId 1000 -Namespace 'Debug' -ExceptionObject $ExceptionObject -Objects $DebugContent; 21 | 22 | $DebugContent = $null; 23 | } 24 | -------------------------------------------------------------------------------- /lib/core/logging/Write-IcingaDeprecated.psm1: -------------------------------------------------------------------------------- 1 | function Write-IcingaDeprecated() 2 | { 3 | param ( 4 | [string]$Function, 5 | [string]$Argument 6 | ); 7 | 8 | if ([string]::IsNullOrEmpty($Function)) { 9 | return; 10 | } 11 | 12 | $Message = 'The called function or method "{0}" is deprecated. Please update your component or contact the developer to update the component accordingly.'; 13 | 14 | if ([string]::IsNullOrEmpty($Argument) -eq $FALSE) { 15 | $Message = 'The function or method "{0}" is called with deprecated argument "{1}". Please update your component or contact the developer to update the component accordingly.'; 16 | } 17 | 18 | Write-IcingaConsoleOutput ` 19 | -Message $Message ` 20 | -Objects $Function, $Argument ` 21 | -ForeColor 'Cyan' ` 22 | -Severity 'Deprecated'; 23 | 24 | Write-IcingaEventMessage -EventId 1001 -Namespace 'Framework' -Objects ` 25 | ([string]::Format('Command or Method: {0}', $Function)), 26 | ([string]::Format('Argument: {0}', $Argument)), 27 | (Get-PSCallStack); 28 | } 29 | -------------------------------------------------------------------------------- /lib/core/logging/Write-IcingaErrorMessage.psm1: -------------------------------------------------------------------------------- 1 | function Write-IcingaErrorMessage() 2 | { 3 | param( 4 | [int]$EventId = 0, 5 | [string]$Message = $null 6 | ); 7 | 8 | if ($EventId -eq 0 -Or [string]::IsNullOrEmpty($Message)) { 9 | return; 10 | } 11 | 12 | Write-EventLog -LogName 'Icinga for Windows' -Source 'Icinga for Windows' -EntryType Error -EventId $EventId -Message $Message; 13 | } 14 | -------------------------------------------------------------------------------- /lib/core/perfcounter/Get-IcingaPerformanceCounterCacheItem.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Fetches stored data for a given performance counter path. Returns 4 | $null if no values are assigned 5 | .DESCRIPTION 6 | Fetches stored data for a given performance counter path. Returns 7 | $null if no values are assigned 8 | .FUNCTIONALITY 9 | Fetches stored data for a given performance counter path. Returns 10 | $null if no values are assigned 11 | .EXAMPLE 12 | PS>Get-IcingaPerformanceCounterCacheItem -Counter '\Processor(*)\% processor time'; 13 | .PARAMETER Counter 14 | The path to the counter to fetch data for 15 | .INPUTS 16 | System.String 17 | .LINK 18 | https://github.com/Icinga/icinga-powershell-framework 19 | #> 20 | 21 | function Get-IcingaPerformanceCounterCacheItem() 22 | { 23 | param ( 24 | $Counter 25 | ); 26 | 27 | if ([string]::IsNullOrEmpty($Counter)) { 28 | return $null; 29 | } 30 | 31 | if ($Global:Icinga.Private.PerformanceCounter.Cache.ContainsKey($Counter)) { 32 | return $Global:Icinga.Private.PerformanceCounter.Cache[$Counter]; 33 | } 34 | 35 | return $null; 36 | } 37 | -------------------------------------------------------------------------------- /lib/core/progress/Complete-IcingaProgressStatus.psm1: -------------------------------------------------------------------------------- 1 | function Complete-IcingaProgressStatus() 2 | { 3 | param ( 4 | [string]$Name = '' 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Name)) { 8 | Write-IcingaConsoleError -Message 'Failed to complete progress status. You have to specify a name.'; 9 | return; 10 | } 11 | 12 | if ($Global:Icinga.Private.ProgressStatus.ContainsKey($Name) -eq $FALSE) { 13 | return; 14 | } 15 | 16 | if ($Global:Icinga.Private.ProgressStatus[$Name].Details) { 17 | $Message = [string]::Format('{0}: {1}/{2}', $Global:Icinga.Private.ProgressStatus[$Name].Message, $Global:Icinga.Private.ProgressStatus[$Name].MaxValue, $Global:Icinga.Private.ProgressStatus[$Name].MaxValue); 18 | } else { 19 | $Message = $Global:Icinga.Private.ProgressStatus[$Name].Message; 20 | } 21 | 22 | $ProgressPreference = 'Continue'; 23 | Write-Progress -Activity $Message -Status ([string]::Format($Global:Icinga.Private.ProgressStatus[$Name].Status, 100)) -PercentComplete 100 -Completed; 24 | 25 | $Global:Icinga.Private.ProgressStatus.Remove($Name); 26 | 27 | $ProgressPreference = 'SilentlyContinue'; 28 | } 29 | -------------------------------------------------------------------------------- /lib/core/repository/Add-IcingaRepositoryErrorState.psm1: -------------------------------------------------------------------------------- 1 | function Add-IcingaRepositoryErrorState() 2 | { 3 | param ( 4 | [string]$Repository = $null 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Repository)) { 8 | return; 9 | } 10 | 11 | if ($Global:Icinga -eq $null) { 12 | return; 13 | } 14 | 15 | if ($Global:Icinga.Contains('Private') -eq $FALSE) { 16 | return; 17 | } 18 | 19 | if ($Global:Icinga.Private.Contains('RepositoryStatus') -eq $FALSE) { 20 | return; 21 | } 22 | 23 | if ($Global:Icinga.Private.RepositoryStatus.Contains('FailedRepositories') -eq $FALSE) { 24 | return; 25 | } 26 | 27 | if ($Global:Icinga.Private.RepositoryStatus.FailedRepositories.ContainsKey($Repository)) { 28 | return; 29 | } 30 | 31 | $Global:Icinga.Private.RepositoryStatus.FailedRepositories.Add($Repository, $TRUE); 32 | } 33 | -------------------------------------------------------------------------------- /lib/core/repository/Clear-IcingaRepositoryErrorState.psm1: -------------------------------------------------------------------------------- 1 | function Clear-IcingaRepositoryErrorState() 2 | { 3 | if ($Global:Icinga -eq $null) { 4 | return; 5 | } 6 | 7 | if ($Global:Icinga.Contains('Private') -eq $FALSE) { 8 | return; 9 | } 10 | 11 | if ($Global:Icinga.Private.Contains('RepositoryStatus') -eq $FALSE) { 12 | return; 13 | } 14 | 15 | $Global:Icinga.Private.RepositoryStatus.FailedRepositories = @{ }; 16 | } 17 | -------------------------------------------------------------------------------- /lib/core/repository/Disable-IcingaRepository.psm1: -------------------------------------------------------------------------------- 1 | function Disable-IcingaRepository() 2 | { 3 | param ( 4 | [string]$Name = $null 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Name)) { 8 | Write-IcingaConsoleError 'You have to provide a name for the repository'; 9 | return; 10 | } 11 | 12 | $Name = $Name.Replace('.', '-'); 13 | 14 | $CurrentRepositories = Get-IcingaPowerShellConfig -Path ([string]::Format('Framework.Repository.Repositories.{0}', $Name)); 15 | 16 | if ($null -eq $CurrentRepositories) { 17 | Write-IcingaConsoleError 'A repository with the name "{0}" is not configured' -Objects $Name; 18 | return; 19 | } 20 | 21 | if ($CurrentRepositories.Enabled -eq $FALSE) { 22 | Write-IcingaConsoleNotice 'The repository "{0}" is already disabled' -Objects $Name; 23 | return; 24 | } 25 | 26 | Set-IcingaPowerShellConfig -Path ([string]::Format('Framework.Repository.Repositories.{0}.Enabled', $Name)) -Value $FALSE; 27 | 28 | Write-IcingaConsoleNotice 'The repository "{0}" was successfully disabled' -Objects $Name; 29 | } 30 | -------------------------------------------------------------------------------- /lib/core/repository/Enable-IcingaRepository.psm1: -------------------------------------------------------------------------------- 1 | function Enable-IcingaRepository() 2 | { 3 | param ( 4 | [string]$Name = $null 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Name)) { 8 | Write-IcingaConsoleError 'You have to provide a name for the repository'; 9 | return; 10 | } 11 | 12 | $Name = $Name.Replace('.', '-'); 13 | 14 | $CurrentRepositories = Get-IcingaPowerShellConfig -Path ([string]::Format('Framework.Repository.Repositories.{0}', $Name)); 15 | 16 | if ($null -eq $CurrentRepositories) { 17 | Write-IcingaConsoleError 'A repository with the name "{0}" is not configured' -Objects $Name; 18 | return; 19 | } 20 | 21 | if ($CurrentRepositories.Enabled -eq $TRUE) { 22 | Write-IcingaConsoleNotice 'The repository "{0}" is already enabled' -Objects $Name; 23 | return; 24 | } 25 | 26 | Set-IcingaPowerShellConfig -Path ([string]::Format('Framework.Repository.Repositories.{0}.Enabled', $Name)) -Value $TRUE; 27 | 28 | Write-IcingaConsoleNotice 'The repository "{0}" was successfully enabled' -Objects $Name; 29 | } 30 | -------------------------------------------------------------------------------- /lib/core/repository/Get-IcingaComponentLock.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaComponentLock() 2 | { 3 | param ( 4 | [string]$Name = $null 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Name)) { 8 | Write-IcingaConsoleError 'You have to specify the component to get the lock version'; 9 | return; 10 | } 11 | 12 | $LockedComponents = Get-IcingaPowerShellConfig -Path 'Framework.Repository.ComponentLock'; 13 | 14 | if ($null -eq $LockedComponents) { 15 | return $null; 16 | } 17 | 18 | if (Test-IcingaPowerShellConfigItem -ConfigObject $LockedComponents -ConfigKey $Name) { 19 | return $LockedComponents.$Name; 20 | } 21 | 22 | return $null; 23 | } 24 | -------------------------------------------------------------------------------- /lib/core/repository/Get-IcingaRepositories.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaRepositories() 2 | { 3 | param ( 4 | [switch]$ExcludeDisabled = $FALSE 5 | ); 6 | 7 | $CurrentRepositories = Get-IcingaPowerShellConfig -Path 'Framework.Repository.Repositories'; 8 | [array]$RepoList = $CurrentRepositories.PSObject.Properties | Sort-Object { $_.Value.Order } -Descending; 9 | 10 | if ($ExcludeDisabled -eq $FALSE) { 11 | return $RepoList; 12 | } 13 | 14 | [array]$ActiveRepos = @(); 15 | 16 | foreach ($repo in $RepoList) { 17 | if ($repo.Value.Enabled -eq $FALSE) { 18 | continue; 19 | } 20 | 21 | $ActiveRepos += $repo; 22 | } 23 | 24 | return $ActiveRepos; 25 | } 26 | -------------------------------------------------------------------------------- /lib/core/repository/Remove-IcingaRepository.psm1: -------------------------------------------------------------------------------- 1 | function Remove-IcingaRepository() 2 | { 3 | param ( 4 | [string]$Name = $null 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Name)) { 8 | Write-IcingaConsoleError 'You have to provide a name for the repository to remove'; 9 | return; 10 | } 11 | 12 | $Name = $Name.Replace('.', '-'); 13 | 14 | $CurrentRepositories = Get-IcingaPowerShellConfig -Path 'Framework.Repository.Repositories'; 15 | 16 | if ((Test-IcingaPowerShellConfigItem -ConfigObject $CurrentRepositories -ConfigKey $Name) -eq $FALSE) { 17 | Write-IcingaConsoleError 'A repository with the name "{0}" is not configured' -Objects $Name; 18 | return; 19 | } 20 | 21 | Push-IcingaRepository -Name $Name -Silent; 22 | 23 | Remove-IcingaPowerShellConfig -Path ( 24 | [string]::Format( 25 | 'Framework.Repository.Repositories.{0}', 26 | $Name 27 | ) 28 | ); 29 | 30 | Write-IcingaConsoleNotice 'The repository with the name "{0}" was successfully removed' -Objects $Name; 31 | } 32 | -------------------------------------------------------------------------------- /lib/core/repository/Show-IcingaRepository.psm1: -------------------------------------------------------------------------------- 1 | function Show-IcingaRepository() 2 | { 3 | [hashtable]$Repositories = @{ }; 4 | [array]$RepoSummary = @( 5 | 'List of configured repositories on this system. The list order matches the apply order:', 6 | '' 7 | ); 8 | [array]$RepoList = Get-IcingaRepositories; 9 | 10 | foreach ($repo in $RepoList) { 11 | 12 | $RepoSummary += $repo.Name; 13 | $RepoSummary += '-----------'; 14 | 15 | [int]$MaxLength = Get-IcingaMaxTextLength -TextArray $repo.Value.PSObject.Properties.Name; 16 | [array]$RepoData = @(); 17 | 18 | foreach ($repoConfig in $repo.Value.PSObject.Properties) { 19 | $PrintName = Add-IcingaWhiteSpaceToString -Text $repoConfig.Name -Length $MaxLength; 20 | $RepoData += [string]::Format('{0} => {1}', $PrintName, $repoConfig.Value); 21 | } 22 | 23 | $RepoSummary += $RepoData | Sort-Object; 24 | $RepoSummary += ''; 25 | } 26 | 27 | if ($RepoList.Count -eq 0) { 28 | $RepoSummary += 'No repositories configured'; 29 | } 30 | 31 | Write-Output $RepoSummary; 32 | } 33 | -------------------------------------------------------------------------------- /lib/core/repository/Test-IcingaRepositoryErrorState.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaRepositoryErrorState() 2 | { 3 | param ( 4 | [string]$Repository 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Repository)) { 8 | return $FALSE; 9 | } 10 | 11 | if ($Global:Icinga -eq $null) { 12 | return $FALSE; 13 | } 14 | 15 | if ($Global:Icinga.Contains('Private') -eq $FALSE) { 16 | return $FALSE; 17 | } 18 | 19 | if ($Global:Icinga.Private.Contains('RepositoryStatus') -eq $FALSE) { 20 | return $FALSE; 21 | } 22 | 23 | if ($Global:Icinga.Private.RepositoryStatus.Contains('FailedRepositories') -eq $FALSE) { 24 | return $FALSE; 25 | } 26 | 27 | if ($Global:Icinga.Private.RepositoryStatus.FailedRepositories.ContainsKey($Repository) -eq $FALSE) { 28 | return $FALSE; 29 | } 30 | 31 | return $TRUE; 32 | } 33 | -------------------------------------------------------------------------------- /lib/core/repository/Test-IcingaValidJSON.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaValidJSON() 2 | { 3 | param ( 4 | [string]$String = '', 5 | [string]$File = '' 6 | ); 7 | 8 | if ([string]::IsNullOrEmpty($File) -eq $FALSE) { 9 | if ((Test-Path $File) -eq $FALSE) { 10 | return $FALSE; 11 | } 12 | 13 | $String = Get-Content -Path $File -Raw; 14 | } 15 | try { 16 | # Test the conversion to JSON and return false on failure and true on success 17 | ConvertFrom-Json -InputObject $String -ErrorAction Stop | Out-Null; 18 | } catch { 19 | return $FALSE; 20 | } 21 | 22 | return $TRUE; 23 | } 24 | -------------------------------------------------------------------------------- /lib/core/repository/Unlock-IcingaComponent.psm1: -------------------------------------------------------------------------------- 1 | function Unlock-IcingaComponent() 2 | { 3 | param ( 4 | [string]$Name = $null 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Name)) { 8 | Write-IcingaConsoleError 'You have to specify the component to unlock'; 9 | return; 10 | } 11 | 12 | $LockedComponents = Get-IcingaPowerShellConfig -Path 'Framework.Repository.ComponentLock'; 13 | 14 | if ($null -eq $LockedComponents) { 15 | Write-IcingaConsoleNotice 'You have currently no components which are locked configured'; 16 | return; 17 | } 18 | 19 | if (Test-IcingaPowerShellConfigItem -ConfigObject $LockedComponents -ConfigKey $Name) { 20 | Remove-IcingaPowerShellConfig -Path ([string]::Format('Framework.Repository.ComponentLock.{0}', $Name)); 21 | Write-IcingaConsoleNotice 'Unlocking of component "{0}" was successful.' -Objects $Name; 22 | } else { 23 | Write-IcingaConsoleNotice 'The component "{0}" is not locked on this system' -Objects $Name; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/core/thread/Add-IcingaThreadPool.psm1: -------------------------------------------------------------------------------- 1 | function Add-IcingaThreadPool() 2 | { 3 | param ( 4 | [string]$Name = '', 5 | [int]$MinInstances = 1, 6 | [int]$MaxInstances = 5 7 | ); 8 | 9 | if ($Global:Icinga.Public.ThreadPools.ContainsKey($Name)) { 10 | return; 11 | } 12 | 13 | $Global:Icinga.Public.ThreadPools.Add( 14 | $Name, 15 | (New-IcingaThreadPool -MinInstances $MinInstances -MaxInstances $MaxInstances) 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /lib/core/thread/Get-IcingaThreadPool.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaThreadPool() 2 | { 3 | param ( 4 | [string]$Name 5 | ); 6 | 7 | if ($Global:Icinga.Public.ThreadPools.ContainsKey($Name)) { 8 | return $Global:Icinga.Public.ThreadPools[$Name]; 9 | } 10 | 11 | Write-IcingaEventMessage -Namespace 'Framework' -EventId 1401 -Objects $Name; 12 | 13 | return (New-IcingaThreadPool); 14 | } 15 | -------------------------------------------------------------------------------- /lib/core/thread/New-IcingaThreadHash.psm1: -------------------------------------------------------------------------------- 1 | function New-IcingaThreadHash() 2 | { 3 | param( 4 | [string]$ShellScript, 5 | [array]$Arguments 6 | ); 7 | 8 | [string]$ScriptString = ''; 9 | [string]$ArgString = ($Arguments | Out-String); 10 | if ($null -ne $ShellScript) { 11 | $ScriptString = $ShellScript.ToString(); 12 | } 13 | return (Get-StringSha1 -Content ($ScriptString + $ArgString + (Get-Date -Format "MM-dd-yyyy-HH-mm-ffff"))); 14 | } 15 | -------------------------------------------------------------------------------- /lib/core/thread/New-IcingaThreadPool.psm1: -------------------------------------------------------------------------------- 1 | function New-IcingaThreadPool() 2 | { 3 | param( 4 | [int]$MinInstances = 1, 5 | [int]$MaxInstances = 5 6 | ); 7 | 8 | $SessionConfiguration = $null; 9 | $SessionFile = Get-IcingaJEASessionFile; 10 | 11 | if ([string]::IsNullOrEmpty((Get-IcingaJEAContext))) { 12 | $SessionConfiguration = [System.Management.Automation.RunSpaces.InitialSessionState]::CreateDefault(); 13 | } else { 14 | if ([string]::IsNullOrEmpty($SessionFile)) { 15 | Write-IcingaEventMessage -EventId 1502 -Namespace 'Framework'; 16 | return $null; 17 | } 18 | $SessionConfiguration = [System.Management.Automation.Runspaces.InitialSessionState]::CreateFromSessionConfigurationFile($SessionFile); 19 | } 20 | 21 | $RunSpaces = [RunSpaceFactory]::CreateRunSpacePool( 22 | $MinInstances, 23 | $MaxInstances, 24 | $SessionConfiguration, 25 | $host 26 | ) 27 | 28 | $RunSpaces.Open(); 29 | 30 | return $RunSpaces; 31 | } 32 | -------------------------------------------------------------------------------- /lib/core/thread/Remove-IcingaThread.psm1: -------------------------------------------------------------------------------- 1 | function Remove-IcingaThread() 2 | { 3 | param( 4 | [string]$Thread = '' 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Thread)) { 8 | return; 9 | } 10 | 11 | Stop-IcingaThread -Thread $Thread; 12 | 13 | if ($Global:Icinga.Public.Threads.ContainsKey($Thread)) { 14 | $Global:Icinga.Public.Threads[$Thread].Shell.Dispose(); 15 | $Global:Icinga.Public.Threads.Remove($Thread); 16 | 17 | Write-IcingaDebugMessage 'Removing Thread: {0}' -Objects $Thread; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/core/thread/Restart-IcingaThread.psm1: -------------------------------------------------------------------------------- 1 | function Restart-IcingaThread() 2 | { 3 | param( 4 | [string]$Thread 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Thread)) { 8 | return; 9 | } 10 | 11 | Stop-IcingaThread $Thread; 12 | Start-IcingaThread $Thread; 13 | } 14 | -------------------------------------------------------------------------------- /lib/core/thread/Set-IcingaEnvironmentGlobal.psm1: -------------------------------------------------------------------------------- 1 | function Set-IcingaEnvironmentGlobal() 2 | { 3 | param ( 4 | $GlobalEnvironment = $null 5 | ); 6 | 7 | if ($null -eq $GlobalEnvironment -Or $null -eq $Global:Icinga) { 8 | return; 9 | } 10 | 11 | if ($Global:Icinga.ContainsKey('Public') -eq $FALSE) { 12 | return; 13 | } 14 | 15 | $Global:Icinga.Public = $GlobalEnvironment; 16 | } 17 | -------------------------------------------------------------------------------- /lib/core/thread/Set-IcingaEnvironmentJEA.psm1: -------------------------------------------------------------------------------- 1 | function Set-IcingaEnvironmentJEA() 2 | { 3 | param ( 4 | [bool]$JeaEnabled = $FALSE 5 | ); 6 | 7 | if ($null -ne $Global:Icinga -And $Global:Icinga.ContainsKey('Protected') -And $Global:Icinga.Protected.ContainsKey('JEAContext')) { 8 | $Global:Icinga.Protected.JEAContext = $JeaEnabled; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /lib/core/thread/Set-IcingaEnvironmentThreadName.psm1: -------------------------------------------------------------------------------- 1 | function Set-IcingaEnvironmentThreadName() 2 | { 3 | param ( 4 | [string]$ThreadName = '' 5 | ); 6 | 7 | $Global:Icinga.Protected.ThreadName = $ThreadName; 8 | } 9 | -------------------------------------------------------------------------------- /lib/core/thread/Start-IcingaThread.psm1: -------------------------------------------------------------------------------- 1 | function Start-IcingaThread() 2 | { 3 | param( 4 | [string]$Thread 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Thread)) { 8 | return; 9 | } 10 | 11 | if ($Global:Icinga.Public.Threads.ContainsKey($Thread)) { 12 | if ($Global:Icinga.Public.Threads[$Thread].Started -eq $FALSE) { 13 | $Global:Icinga.Public.Threads[$Thread].Handle = $Global:Icinga.Public.Threads[$Thread].Shell.BeginInvoke(); 14 | $Global:Icinga.Public.Threads[$Thread].Started = $TRUE; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lib/core/thread/Stop-IcingaThread.psm1: -------------------------------------------------------------------------------- 1 | function Stop-IcingaThread() 2 | { 3 | param ( 4 | [string]$Thread = '' 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Thread)) { 8 | return; 9 | } 10 | 11 | if ($Global:Icinga.Public.Threads.ContainsKey($Thread)) { 12 | if ($Global:Icinga.Public.Threads[$Thread].Started -eq $TRUE) { 13 | $Global:Icinga.Public.Threads[$Thread].Shell.Stop(); 14 | $Global:Icinga.Public.Threads[$Thread].Handle = $null; 15 | $Global:Icinga.Public.Threads[$Thread].Started = $FALSE; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/core/thread/Test-IcingaThread.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaThread() 2 | { 3 | param( 4 | [string]$Thread 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Thread)) { 8 | return $FALSE; 9 | } 10 | 11 | return $Global:Icinga.Public.Threads.ContainsKey($Thread); 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/tools/Add-IcingaArrayListItem.psm1: -------------------------------------------------------------------------------- 1 | function Add-IcingaArrayListItem() 2 | { 3 | param ( 4 | [System.Collections.ArrayList]$Array, 5 | $Element 6 | ); 7 | 8 | if ($null -eq $Array -Or $null -eq $Element) { 9 | return; 10 | } 11 | 12 | $Array.Add($Element) | Out-Null; 13 | } 14 | -------------------------------------------------------------------------------- /lib/core/tools/Add-IcingaHashtableItem.psm1: -------------------------------------------------------------------------------- 1 | function Add-IcingaHashtableItem() 2 | { 3 | param( 4 | $Hashtable, 5 | $Key, 6 | $Value, 7 | [switch]$Override 8 | ); 9 | 10 | if ($null -eq $Hashtable) { 11 | return $FALSE; 12 | } 13 | 14 | if ($Hashtable.ContainsKey($Key) -eq $FALSE) { 15 | $Hashtable.Add($Key, $Value); 16 | return $TRUE; 17 | } else { 18 | if ($Override) { 19 | $Hashtable.Remove($Key); 20 | $Hashtable.Add($Key, $Value); 21 | return $TRUE; 22 | } 23 | } 24 | return $FALSE; 25 | } 26 | -------------------------------------------------------------------------------- /lib/core/tools/Add-IcingaWhiteSpaceToString.psm1: -------------------------------------------------------------------------------- 1 | function Add-IcingaWhiteSpaceToString() 2 | { 3 | param ( 4 | [string]$Text = '', 5 | [int]$Length = 0 6 | ); 7 | 8 | [int]$LengthOffset = $Length - $Text.Length; 9 | 10 | while ($LengthOffset -ge 0) { 11 | $Text += ' '; 12 | $LengthOffset -= 1; 13 | } 14 | 15 | return $Text; 16 | } 17 | -------------------------------------------------------------------------------- /lib/core/tools/Add-PSCustomObjectMember.psm1: -------------------------------------------------------------------------------- 1 | function Add-PSCustomObjectMember() 2 | { 3 | param ( 4 | $Object, 5 | $Key, 6 | $Value 7 | ); 8 | 9 | if ($null -eq $Object) { 10 | return $Object; 11 | } 12 | 13 | $Object | Add-Member -MemberType NoteProperty -Name $Key -Value $Value; 14 | 15 | return $Object; 16 | } 17 | -------------------------------------------------------------------------------- /lib/core/tools/Clear-IcingaAddTypeLib.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Removes the dll folder from the cache and deletes 4 | all pre-compiled libraries by Icinga for Windows 5 | .DESCRIPTION 6 | Removes the dll folder from the cache and deletes 7 | all pre-compiled libraries by Icinga for Windows 8 | .EXAMPLE 9 | PS> Clear-IcingaAddTypeLib 10 | #> 11 | function Clear-IcingaAddTypeLib() 12 | { 13 | [string]$DLLFolder = (Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'dll'); 14 | 15 | if ((Test-Path $DLLFolder) -eq $FALSE) { 16 | Write-IcingaConsoleNotice 'The dll folder does not exist'; 17 | return; 18 | } 19 | 20 | if (Remove-ItemSecure -Path $DLLFolder -Recurse -Force) { 21 | Write-IcingaConsoleNotice 'The dll cache folder was successfully removed'; 22 | } else { 23 | Write-IcingaConsoleError 'Failed to remove dll cache folder. Make sure it is not used at the moment and try again' 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/core/tools/ConvertFrom-IcingaSecureString.psm1: -------------------------------------------------------------------------------- 1 | function ConvertFrom-IcingaSecureString() 2 | { 3 | param([SecureString]$SecureString); 4 | 5 | if ($SecureString -eq $null) { 6 | return ''; 7 | } 8 | 9 | [IntPtr]$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString) 10 | [string]$String = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) 11 | 12 | return $String; 13 | } 14 | -------------------------------------------------------------------------------- /lib/core/tools/ConvertFrom-JsonUTF8.psm1: -------------------------------------------------------------------------------- 1 | function ConvertFrom-JsonUTF8() 2 | { 3 | [CmdletBinding()] 4 | param ( 5 | [parameter(Mandatory = $TRUE, ValueFromPipeline = $TRUE)] 6 | $InputObject = $null 7 | ); 8 | 9 | # We need to properly encode our String to UTF8 10 | $ContentBytes = [System.Text.Encoding]::Default.GetBytes($InputObject); 11 | $UTF8String = [System.Text.Encoding]::UTF8.GetString($ContentBytes); 12 | 13 | # Return the correct encoded JSON 14 | return (ConvertFrom-Json -InputObject $UTF8String); 15 | } 16 | -------------------------------------------------------------------------------- /lib/core/tools/ConvertFrom-Percent.psm1: -------------------------------------------------------------------------------- 1 | function ConvertFrom-Percent() 2 | { 3 | param ( 4 | $Value = $null, 5 | $Percent = $null, 6 | [int]$Digits = 0 7 | ); 8 | 9 | if ($null -eq $Value -Or $null -eq $Percent) { 10 | return 0; 11 | } 12 | 13 | return ([math]::Round(($Value / 100 * $Percent), $Digits)); 14 | } 15 | -------------------------------------------------------------------------------- /lib/core/tools/ConvertTo-BytesNextUnit.psm1: -------------------------------------------------------------------------------- 1 | function ConvertTo-BytesNextUnit() 2 | { 3 | param ( 4 | [string]$Value = $null, 5 | [string]$Unit = $null, 6 | [array]$Units = @('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB') 7 | ); 8 | 9 | [string]$UnitValue = [string]::Format('{0}{1}', $Value, $Unit); 10 | 11 | while ($TRUE) { 12 | $Unit = Get-IcingaNextUnitIteration -Unit $Unit -Units $Units; 13 | [decimal]$NewValue = (Convert-Bytes -Value $UnitValue -Unit $Unit).Value; 14 | if ($NewValue -ge 1.0) { 15 | if ($Unit -eq $RetUnit) { 16 | break; 17 | } 18 | $RetValue = [math]::Round([decimal]$NewValue, 2); 19 | $RetUnit = $Unit; 20 | } else { 21 | if ([string]::IsNullOrEmpty($RetUnit)) { 22 | $RetValue = $Value; 23 | $RetUnit = 'B'; 24 | } 25 | break; 26 | } 27 | } 28 | 29 | return ([string]::Format('{0}{1}', $RetValue, $RetUnit)); 30 | } 31 | -------------------------------------------------------------------------------- /lib/core/tools/ConvertTo-IcingaIPBinaryString.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Used to convert both IPv4 addresses and IPv6 addresses to binary. 4 | .DESCRIPTION 5 | ConvertTo-IcingaIPBinaryString returns a binary string based on the given IPv4 address or IPv6 address. 6 | 7 | More Information on https://github.com/Icinga/icinga-powershell-framework 8 | .FUNCTIONALITY 9 | This module is intended to be used to convert an IPv4 address or IPv6 address to binary string. 10 | .PARAMETER IP 11 | Used to specify an IPv4 address or IPv6 address. 12 | .INPUTS 13 | System.String 14 | .OUTPUTS 15 | System.String 16 | 17 | .LINK 18 | https://github.com/Icinga/icinga-powershell-framework 19 | .NOTES 20 | #> 21 | 22 | function ConvertTo-IcingaIPBinaryString() 23 | { 24 | param ( 25 | $IP 26 | ); 27 | 28 | if ($IP -like '*.*') { 29 | $IP = ConvertTo-IcingaIPv4BinaryString -IP $IP; 30 | } elseif ($IP -like '*:*') { 31 | $IP = ConvertTo-IcingaIPv6BinaryString -IP $IP; 32 | } else { 33 | return 'Invalid IP was provided!'; 34 | } 35 | 36 | return $IP; 37 | } 38 | -------------------------------------------------------------------------------- /lib/core/tools/ConvertTo-IcingaNumericTimeIndex.psm1: -------------------------------------------------------------------------------- 1 | function ConvertTo-IcingaNumericTimeIndex() 2 | { 3 | param ( 4 | [int]$TimeValue = 0 5 | ); 6 | 7 | if ($TimeValue -lt 60) { 8 | return ([string]::Format('{0}s', $TimeValue)); 9 | } 10 | 11 | [decimal]$Minutes = $TimeValue / 60; 12 | [decimal]$Seconds = $Minutes - [math]::Truncate($Minutes); 13 | [decimal]$Minutes = [math]::Truncate($Minutes); 14 | [decimal]$Seconds = [math]::Round(60 * $Seconds, 0); 15 | 16 | $TimeIndex = New-Object -TypeName 'System.Text.StringBuilder'; 17 | $TimeIndex.Append([string]::Format('{0}m', $Minutes)) | Out-Null; 18 | 19 | if ($Seconds -ne 0) { 20 | $TimeIndex.Append([string]::Format('{0}s', $Seconds)) | Out-Null; 21 | } 22 | 23 | return $TimeIndex.ToString(); 24 | } 25 | -------------------------------------------------------------------------------- /lib/core/tools/ConvertTo-IcingaSecureString.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | # Helper class allowing to easily convert strings into SecureStrings 3 | # and vice-versa 4 | #> 5 | function ConvertTo-IcingaSecureString() 6 | { 7 | param ( 8 | [string]$String 9 | ); 10 | 11 | if ([string]::IsNullOrEmpty($String)) { 12 | return $null; 13 | } 14 | 15 | return (ConvertTo-SecureString -AsPlainText $string -Force); 16 | } 17 | -------------------------------------------------------------------------------- /lib/core/tools/ConvertTo-IcingaUnixTime.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a time string to a Unix timestamp. 4 | 5 | .DESCRIPTION 6 | Converts a given time string like "2025-04-10 20:00:00" to a Unix timestamp. 7 | The function returns 0 if the input is null or empty. 8 | If the input cannot be parsed, it returns -1. 9 | The function uses the UTC time zone for the conversion. 10 | 11 | .PARAMETER TimeString 12 | The time string to convert. It should be in a format that can be parsed by [datetime]::Parse, like "2025-04-10 20:00:00" 13 | 14 | .EXAMPLE 15 | $UnixTime = ConvertTo-IcingaUnixTime -TimeString "2025-04-10 20:00:00" 16 | $UnixTime 17 | #> 18 | 19 | function ConvertTo-IcingaUnixTime() 20 | { 21 | param ( 22 | [string]$TimeString = $null 23 | ); 24 | 25 | if ([string]::IsNullOrEmpty($TimeString)) { 26 | return 0; 27 | } 28 | 29 | try { 30 | return [decimal][double]::Parse( 31 | (Get-Date -UFormat %s -Date (Get-Date -Date $TimeString).ToUniversalTime()) 32 | ); 33 | } catch { 34 | return -1; 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /lib/core/tools/ConvertTo-JsonUTF8Bytes.psm1: -------------------------------------------------------------------------------- 1 | function ConvertTo-JsonUTF8Bytes() 2 | { 3 | [CmdletBinding()] 4 | param ( 5 | [parameter(Mandatory = $TRUE, ValueFromPipeline = $TRUE)] 6 | $InputObject = $null, 7 | [int]$Depth = 10, 8 | [switch]$Compress = $FALSE 9 | ); 10 | 11 | $JsonBody = ConvertTo-Json -InputObject $InputObject -Depth 100 -Compress; 12 | $UTF8Bytes = ([System.Text.Encoding]::UTF8.GetBytes($JsonBody)); 13 | 14 | # Do not remove the "," as we require to force our PowerShell to handle our return value 15 | # as proper collection 16 | return , $UTF8Bytes; 17 | } 18 | -------------------------------------------------------------------------------- /lib/core/tools/Format-IcingaDigitCount.psm1: -------------------------------------------------------------------------------- 1 | function Format-IcingaDigitCount() 2 | { 3 | param( 4 | [string]$Value, 5 | [int]$Digits, 6 | [string]$Symbol = 0 7 | ); 8 | 9 | if ([string]::IsNullOrEmpty($Value)) { 10 | return $Value; 11 | } 12 | 13 | $CurrentLength = $Value.Length; 14 | if ($CurrentLength -ge $Digits) { 15 | return $Value; 16 | } 17 | 18 | while ($Value.Length -lt $Digits) { 19 | $Value = [string]::Format('{0}{1}', $Symbol, $Value); 20 | } 21 | 22 | return $Value; 23 | } 24 | -------------------------------------------------------------------------------- /lib/core/tools/Format-IcingaPerfDataLabel.psm1: -------------------------------------------------------------------------------- 1 | function Format-IcingaPerfDataLabel() 2 | { 3 | param( 4 | $PerfData, 5 | [switch]$MultiOutput = $FALSE 6 | ); 7 | 8 | if ($MultiOutput) { 9 | return (($PerfData) -Replace '[\W]', ''); 10 | } 11 | 12 | $Output = ((($PerfData) -Replace ' ', '_') -Replace '[\W]', ''); 13 | 14 | while ($Output.Contains('__')) { 15 | $Output = $Output.Replace('__', '_'); 16 | } 17 | 18 | # Remove all special characters and spaces on label names 19 | return $Output; 20 | } 21 | -------------------------------------------------------------------------------- /lib/core/tools/Format-IcingaPerfDataValue.psm1: -------------------------------------------------------------------------------- 1 | function Format-IcingaPerfDataValue() 2 | { 3 | param( 4 | $PerfValue 5 | ); 6 | 7 | if ((Test-Numeric $PerfValue) -eq $FALSE) { 8 | return $PerfValue; 9 | } 10 | 11 | # Convert our value to a string and replace ',' with a '.' to allow Icinga to parse the output 12 | # In addition, round every output to 6 digits 13 | return (([string]([math]::round([decimal]$PerfValue, 6))).Replace(',', '.')); 14 | } 15 | -------------------------------------------------------------------------------- /lib/core/tools/Get-IcingaHashtableItem.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaHashtableItem() 2 | { 3 | param( 4 | $Hashtable, 5 | $Key, 6 | $NullValue = $null 7 | ); 8 | 9 | if ($null -eq $Hashtable) { 10 | return $NullValue; 11 | } 12 | 13 | if ($Hashtable.ContainsKey($Key) -eq $FALSE) { 14 | return $NullValue; 15 | } 16 | 17 | return $Hashtable[$Key]; 18 | } 19 | -------------------------------------------------------------------------------- /lib/core/tools/Get-IcingaMaxTextLength.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaMaxTextLength() 2 | { 3 | param ( 4 | [array]$TextArray = '' 5 | ); 6 | 7 | [int]$MaxLength = 0; 8 | 9 | foreach ($text in $TextArray) { 10 | if ($MaxLength -lt $text.Length) { 11 | $MaxLength = $text.Length; 12 | } 13 | } 14 | 15 | return $MaxLength; 16 | } 17 | -------------------------------------------------------------------------------- /lib/core/tools/Get-IcingaNetworkInterfaceUnits.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaNetworkInterfaceUnits() 2 | { 3 | param ( 4 | [decimal]$Value = 0, 5 | [string]$Unit = '' 6 | ); 7 | 8 | [hashtable]$InterfaceData = @{ 9 | 'RawValue' = $Value; 10 | 'LinkSpeed' = 0; 11 | 'Unit' = 'Mbit' 12 | }; 13 | 14 | if ([string]::IsNullOrEmpty($Unit) -eq $FALSE) { 15 | $InterfaceData.LinkSpeed = $Value; 16 | $InterfaceData.Unit = $Unit; 17 | 18 | return $InterfaceData; 19 | } 20 | 21 | [decimal]$result = ($Value / [Math]::Pow(10, 6)); 22 | 23 | if ($result -ge 1000) { 24 | $InterfaceData.LinkSpeed = [decimal]($result / 1000); 25 | $InterfaceData.Unit = 'Gbit'; 26 | } else { 27 | $InterfaceData.LinkSpeed = $result; 28 | $InterfaceData.Unit = 'Mbit'; 29 | } 30 | 31 | return $InterfaceData; 32 | } 33 | -------------------------------------------------------------------------------- /lib/core/tools/Get-IcingaNetworkRoute.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Fetch the used interface for our Windows System 4 | .DESCRIPTION 5 | Newer Windows systems provide a Cmdlet 'Get-NetRoute' for fetching the 6 | network route configurations. Older systems however do not provide this 7 | and to ensure some sort of backwards compatibility, we will have a look 8 | on our route configuration and return the first valid interface found 9 | .FUNCTIONALITY 10 | This Cmdlet will return first valid IP for our interface 11 | .EXAMPLE 12 | PS>Get-IcingaNetworkRoute 13 | .OUTPUTS 14 | System.Array 15 | .LINK 16 | https://github.com/Icinga/icinga-powershell-framework 17 | .NOTES 18 | #> 19 | 20 | function Get-IcingaNetworkRoute() 21 | { 22 | $RouteConfig = (&route print | Where-Object { 23 | $_.TrimStart() -Like "0.0.0.0*"; 24 | }).Split() | Where-Object { 25 | return $_; 26 | }; 27 | 28 | $Interface = @{ 29 | 'Destination' = $RouteConfig[0]; 30 | 'Netmask' = $RouteConfig[1]; 31 | 'Gateway' = $RouteConfig[2]; 32 | 'Interface' = $RouteConfig[3]; 33 | 'Metric' = $RouteConfig[4]; 34 | } 35 | 36 | return $Interface; 37 | } 38 | -------------------------------------------------------------------------------- /lib/core/tools/Get-IcingaNextUnitIteration.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaNextUnitIteration() 2 | { 3 | param ( 4 | [string]$Unit = '', 5 | [array]$Units = @() 6 | ); 7 | 8 | [bool]$Found = $FALSE; 9 | 10 | foreach ($entry in $Units) { 11 | if ($Found) { 12 | return $entry; 13 | } 14 | if ($entry -eq $Unit) { 15 | $Found = $TRUE; 16 | } 17 | } 18 | 19 | return ''; 20 | } 21 | -------------------------------------------------------------------------------- /lib/core/tools/Get-IcingaUnixTime.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaUnixTime() 2 | { 3 | param( 4 | [switch]$Milliseconds = $FALSE 5 | ); 6 | 7 | if ($Milliseconds) { 8 | return ([int64](([DateTime]::UtcNow) - (Get-Date '1/1/1970')).TotalMilliseconds / 1000); 9 | } 10 | 11 | return [int][double]::Parse( 12 | (Get-Date -UFormat %s -Date (Get-Date).ToUniversalTime()) 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /lib/core/tools/Get-IcingaUsernameFromSID.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaUsernameFromSID() 2 | { 3 | param ( 4 | [string]$SID 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($SID)) { 8 | Write-IcingaConsoleError 'You have to specify a SID'; 9 | return $null; 10 | } 11 | 12 | $UserData = New-Object System.Security.Principal.SecurityIdentifier $SID; 13 | $UserObject = $UserData.Translate([System.Security.Principal.NTAccount]); 14 | 15 | return $UserObject.Value; 16 | } 17 | -------------------------------------------------------------------------------- /lib/core/tools/Get-StringSha1.psm1: -------------------------------------------------------------------------------- 1 | function Get-StringSha1() 2 | { 3 | param ( 4 | [string]$Content 5 | ); 6 | 7 | $CryptoAlgorithm = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider; 8 | $ContentHash = [System.Text.Encoding]::UTF8.GetBytes($Content); 9 | $ContentBytes = $CryptoAlgorithm.ComputeHash($ContentHash); 10 | $OutputHash = ''; 11 | 12 | foreach ($byte in $ContentBytes) { 13 | $OutputHash += $byte.ToString() 14 | } 15 | 16 | return $OutputHash; 17 | } 18 | -------------------------------------------------------------------------------- /lib/core/tools/Get-UnitPrefixIEC.psm1: -------------------------------------------------------------------------------- 1 | function Get-UnitPrefixIEC() 2 | { 3 | param( 4 | [single]$Value 5 | ); 6 | 7 | If ( $Value / [math]::Pow(2, 50) -ge 1 ) { 8 | return 'PiB' 9 | } elseif ( $Value / [math]::Pow(2, 40) -ge 1 ) { 10 | return 'TiB' 11 | } elseif ( $Value / [math]::Pow(2, 30) -ge 1 ) { 12 | return 'GiB' 13 | } elseif ( $Value / [math]::Pow(2, 20) -ge 1 ) { 14 | return 'MiB' 15 | } elseif ( $Value / [math]::Pow(2, 10) -ge 1 ) { 16 | return 'KiB' 17 | } else { 18 | return 'B' 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /lib/core/tools/Get-UnitPrefixSI.psm1: -------------------------------------------------------------------------------- 1 | function Get-UnitPrefixSI() 2 | { 3 | param( 4 | [single]$Value 5 | ); 6 | 7 | If ( $Value / [math]::Pow(10, 15) -ge 1 ) { 8 | return 'PB' 9 | } elseif ( $Value / [math]::Pow(10, 12) -ge 1 ) { 10 | return 'TB' 11 | } elseif ( $Value / [math]::Pow(10, 9) -ge 1 ) { 12 | return 'GB' 13 | } elseif ( $Value / [math]::Pow(10, 6) -ge 1 ) { 14 | return 'MB' 15 | } elseif ( $Value / [math]::Pow(10, 3) -ge 1 ) { 16 | return 'KB' 17 | } else { 18 | return 'B' 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/core/tools/Join-WebPath.psm1: -------------------------------------------------------------------------------- 1 | function Join-WebPath() 2 | { 3 | param( 4 | [string]$Path, 5 | [string]$ChildPath 6 | ); 7 | 8 | if ([string]::IsNullOrEmpty($Path) -Or [string]::IsNullOrEmpty($ChildPath)) { 9 | return $Path; 10 | } 11 | 12 | [int]$Length = $Path.Length; 13 | [int]$Slash = $Path.LastIndexOf('/') + 1; 14 | 15 | if ($Length -eq $Slash) { 16 | $Path = $Path.Substring(0, $Path.Length - 1); 17 | } 18 | 19 | if ($ChildPath[0] -eq '/') { 20 | return ([string]::Format('{0}{1}', $Path, $ChildPath)); 21 | } 22 | 23 | return ([string]::Format('{0}/{1}', $Path, $ChildPath)); 24 | } 25 | -------------------------------------------------------------------------------- /lib/core/tools/New-IcingaNewLine.psm1: -------------------------------------------------------------------------------- 1 | function New-IcingaNewLine() 2 | { 3 | return "`r`n"; 4 | } 5 | -------------------------------------------------------------------------------- /lib/core/tools/New-IcingaTemporaryDirectory.psm1: -------------------------------------------------------------------------------- 1 | function New-IcingaTemporaryDirectory() 2 | { 3 | [string]$TmpDirectory = ''; 4 | [string]$DirectoryPath = ''; 5 | 6 | while ($TRUE) { 7 | $TmpDirectory = [string]::Format('tmp_icinga{0}.d', (Get-Random)); 8 | $DirectoryPath = Join-Path $Env:TMP -ChildPath $TmpDirectory; 9 | 10 | if ((Test-Path $DirectoryPath) -eq $FALSE) { 11 | break; 12 | } 13 | } 14 | 15 | return (New-Item -Path $DirectoryPath -ItemType Directory); 16 | } 17 | -------------------------------------------------------------------------------- /lib/core/tools/New-IcingaTemporaryFile.psm1: -------------------------------------------------------------------------------- 1 | function New-IcingaTemporaryFile() 2 | { 3 | [string]$TmpFile = ''; 4 | [string]$FilePath = ''; 5 | 6 | while ($TRUE) { 7 | $TmpFile = [string]::Format('tmp_icinga{0}.tmp', (Get-Random)); 8 | $FilePath = Join-Path $Env:TMP -ChildPath $TmpFile; 9 | 10 | if ((Test-Path $FilePath) -eq $FALSE) { 11 | break; 12 | } 13 | } 14 | 15 | return (New-Item -Path $FilePath -ItemType File); 16 | } 17 | -------------------------------------------------------------------------------- /lib/core/tools/New-IcingaVersionObject.psm1: -------------------------------------------------------------------------------- 1 | function New-IcingaVersionObject() 2 | { 3 | param ( 4 | [array]$Version 5 | ); 6 | 7 | if ($null -eq $Version -Or $Version.Count -gt 4) { 8 | return (New-Object System.Version); 9 | } 10 | 11 | return (New-Object System.Version $Version); 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/tools/New-StringTree.psm1: -------------------------------------------------------------------------------- 1 | function New-StringTree() 2 | { 3 | param( 4 | [int]$Spacing 5 | ) 6 | 7 | if ($Spacing -eq 0) { 8 | return ''; 9 | } 10 | 11 | [string]$spaces = '\_ '; 12 | 13 | while ($Spacing -gt 1) { 14 | $Spacing -= 1; 15 | $spaces = ' ' + $spaces; 16 | } 17 | 18 | return $spaces; 19 | } 20 | -------------------------------------------------------------------------------- /lib/core/tools/Pop-IcingaArrayListItem.psm1: -------------------------------------------------------------------------------- 1 | function Pop-IcingaArrayListItem() 2 | { 3 | param( 4 | [System.Collections.ArrayList]$Array 5 | ); 6 | 7 | if ($null -eq $Array) { 8 | return $null; 9 | } 10 | 11 | if ($Array.Count -eq 0) { 12 | return $null; 13 | } 14 | 15 | $Content = $Array[0]; 16 | $Array.RemoveAt(0); 17 | 18 | return $Content; 19 | } 20 | -------------------------------------------------------------------------------- /lib/core/tools/Remove-IcingaDirectorSelfServiceKey.psm1: -------------------------------------------------------------------------------- 1 | function Remove-IcingaDirectorSelfServiceKey() 2 | { 3 | $Path = 'IcingaDirector.SelfService.ApiKey'; 4 | $Value = Get-IcingaPowerShellConfig $Path; 5 | if ($null -ne $Value) { 6 | Remove-IcingaPowerShellConfig 'IcingaDirector.SelfService.ApiKey'; 7 | $Value = Get-IcingaPowerShellConfig $Path; 8 | if ($null -eq $Value) { 9 | Write-IcingaConsoleNotice 'Icinga Director Self-Service Api key was successfully removed. Please dont forget to drop it within the Icinga Director as well'; 10 | } 11 | } else { 12 | Write-IcingaConsoleWarning 'There is no Self-Service Api key configured on this system'; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /lib/core/tools/Remove-IcingaHashtableItem.psm1: -------------------------------------------------------------------------------- 1 | function Remove-IcingaHashtableItem() 2 | { 3 | param( 4 | $Hashtable, 5 | $Key 6 | ); 7 | 8 | if ($null -eq $Hashtable) { 9 | return; 10 | } 11 | 12 | if ($Hashtable.ContainsKey($Key)) { 13 | $Hashtable.Remove($Key); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/core/tools/Set-IcingaPSLocation.psm1: -------------------------------------------------------------------------------- 1 | function Set-IcingaPSLocation() 2 | { 3 | param ( 4 | [string]$Path = (Get-Location) 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Path)) { 8 | return; 9 | } 10 | 11 | if ((Test-Path $Path) -eq $FALSE) { 12 | return; 13 | } 14 | 15 | [string]$IfWRootPath = Get-IcingaForWindowsRootPath; 16 | [string]$CurrentPath = Get-Location; 17 | 18 | if ($CurrentPath -Like ([string]::Format('{0}*', $Path))) { 19 | Set-Location -Path $IfWRootPath; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lib/core/tools/Set-NumericNegative.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Sets nummeric values to be negative 4 | .DESCRIPTION 5 | This module sets a numeric value to be negative. 6 | e.g 12 to -12 7 | 8 | More Information on https://github.com/Icinga/icinga-powershell-framework 9 | .EXAMPLE 10 | PS> Set-NumericNegative 32 11 | -32 12 | .LINK 13 | https://github.com/Icinga/icinga-powershell-framework 14 | .NOTES 15 | #> 16 | 17 | 18 | function Set-NumericNegative() 19 | { 20 | param( 21 | $Value 22 | ); 23 | 24 | $Value = $Value * -1; 25 | 26 | return $Value; 27 | } -------------------------------------------------------------------------------- /lib/core/tools/Show-IcingaDirectorSelfServiceKey.psm1: -------------------------------------------------------------------------------- 1 | function Show-IcingaDirecorSelfServiceKey() 2 | { 3 | $Path = 'IcingaDirector.SelfService.ApiKey'; 4 | $Value = Get-IcingaPowerShellConfig $Path; 5 | 6 | if ($null -ne $Value) { 7 | Write-IcingaConsoleNotice ([string]::Format('Self-Service Key: "{0}"', $Value)); 8 | } else { 9 | Write-IcingaConsoleWarning 'There is no Self-Service Api key configured on this system'; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/core/tools/Split-IcingaCheckCommandArgs.psm1: -------------------------------------------------------------------------------- 1 | function Split-IcingaCheckCommandArgs() 2 | { 3 | [array]$arguments = @(); 4 | foreach ($arg in $args) { 5 | $arguments += $arg; 6 | } 7 | 8 | return $arguments; 9 | } 10 | -------------------------------------------------------------------------------- /lib/core/tools/Test-AdministrativeShell.psm1: -------------------------------------------------------------------------------- 1 | function Test-AdministrativeShell() 2 | { 3 | $WindowsPrincipcal = New-Object System.Security.Principal.WindowsPrincipal( 4 | [System.Security.Principal.WindowsIdentity]::GetCurrent() 5 | ); 6 | 7 | if ($WindowsPrincipcal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) { 8 | return $TRUE; 9 | } 10 | return $FALSE; 11 | } 12 | -------------------------------------------------------------------------------- /lib/core/tools/Test-IcingaDecimal.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaDecimal() 2 | { 3 | param ( 4 | $Value = $null 5 | ); 6 | 7 | [hashtable]$RetValue = @{ 8 | 'Value' = $Value; 9 | 'Decimal' = $FALSE; 10 | }; 11 | 12 | if ($null -eq $Value -Or [string]::IsNullOrEmpty($Value)) { 13 | return $RetValue; 14 | } 15 | 16 | $TmpValue = ([string]$Value).Replace(',', '.'); 17 | 18 | if ((Test-Numeric $TmpValue) -eq $FALSE) { 19 | return $RetValue; 20 | } 21 | 22 | $RetValue.Value = [decimal]$TmpValue; 23 | $RetValue.Decimal = $TRUE; 24 | 25 | return $RetValue; 26 | } 27 | -------------------------------------------------------------------------------- /lib/core/tools/Test-IcingaForWindowsCmdletLoader.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaForWindowsCmdletLoader() 2 | { 3 | param ( 4 | [string]$Path = '' 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Path)) { 8 | return $FALSE; 9 | } 10 | 11 | if ((Test-Path -Path $Path) -eq $FALSE) { 12 | return $FALSE; 13 | } 14 | 15 | $FrameworkRootDir = [string]::Format('{0}*', (Get-IcingaForWindowsRootPath)); 16 | 17 | if ($Path -NotLike $FrameworkRootDir) { 18 | return $FALSE; 19 | } 20 | 21 | return $TRUE; 22 | } 23 | -------------------------------------------------------------------------------- /lib/core/tools/Test-IcingaFunction.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaFunction() 2 | { 3 | param( 4 | [string]$Name 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($Name)) { 8 | return $FALSE; 9 | } 10 | 11 | if (Get-Command $Name -ErrorAction SilentlyContinue) { 12 | return $TRUE; 13 | } 14 | 15 | return $FALSE; 16 | } 17 | -------------------------------------------------------------------------------- /lib/core/tools/Test-Numeric.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Tests whether a value is numeric 4 | .DESCRIPTION 5 | This module tests whether a value is numeric 6 | 7 | More Information on https://github.com/Icinga/icinga-powershell-framework 8 | .EXAMPLE 9 | PS> Test-Numeric 32 10 | True 11 | .LINK 12 | https://github.com/Icinga/icinga-powershell-framework 13 | .NOTES 14 | #> 15 | function Test-Numeric ($number) { 16 | return $number -Match "^-?[0-9]\d*(\.\d+)?$"; 17 | } 18 | -------------------------------------------------------------------------------- /lib/core/tools/Test-PSCustomObjectMember.psm1: -------------------------------------------------------------------------------- 1 | function Test-PSCustomObjectMember() 2 | { 3 | param ( 4 | $PSObject, 5 | $Name 6 | ); 7 | 8 | if ($null -eq $PSObject) { 9 | return $FALSE; 10 | } 11 | 12 | # Lets make sure we also test for hashtables in case our object is a hashtable 13 | # instead of a PSCustomObject 14 | if ($PSObject -Is [hashtable]) { 15 | return ([bool]($PSObject.ContainsKey($Name))); 16 | } 17 | 18 | return ([bool]($PSObject.PSObject.Properties.Name -eq $Name)); 19 | } 20 | -------------------------------------------------------------------------------- /lib/core/tools/Write-IcingaConsoleTextColorSplit.psm1: -------------------------------------------------------------------------------- 1 | function Write-IcingaConsoleTextColorSplit() 2 | { 3 | param ( 4 | [string]$Pattern = '', 5 | [string]$Message = '', 6 | [ValidateSet('Default', 'Black', 'DarkBlue', 'DarkGreen', 'DarkCyan', 'DarkRed', 'DarkMagenta', 'DarkYellow', 'Gray', 'DarkGray', 'Blue', 'Green', 'Cyan', 'Red', 'Magenta', 'Yellow', 'White')] 7 | [string]$ForeColor = 'Default' 8 | ); 9 | 10 | if ($Message.Contains($Pattern)) { 11 | [int]$RemoveLength = $Pattern.Length; 12 | [string]$SeverityMsg = $Pattern; 13 | Write-IcingaConsolePlain -Message ($Message.Substring(0, $Message.IndexOf($Pattern))) -NoNewLine; 14 | 15 | Write-IcingaConsolePlain -Message $SeverityMsg -ForeColor $ForeColor -NoNewLine; 16 | 17 | Write-IcingaConsolePlain -Message ($Message.Substring($Message.IndexOf($Pattern) + $RemoveLength, $Message.Length - $Message.IndexOf($Pattern) - $RemoveLength)); 18 | 19 | return $TRUE; 20 | } 21 | 22 | return $FALSE; 23 | } 24 | -------------------------------------------------------------------------------- /lib/core/windows/Clear-IcingaWindowsUserPassword.psm1: -------------------------------------------------------------------------------- 1 | function Clear-IcingaWindowsUserPassword() 2 | { 3 | if ($null -eq $Global:Icinga) { 4 | return; 5 | } 6 | 7 | if ($Global:Icinga.ContainsKey('ServiceUserPassword') -eq $FALSE) { 8 | return; 9 | } 10 | 11 | $Global:Icinga.ServiceUserPassword = $null; 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/windows/Get-IcingaWindowsUserMetadata.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaWindowsUserMetadata() 2 | { 3 | return @{ 4 | 'Description' = 'Dedicated user for Icinga for Windows with limited privileges. The user is only allowed to be used as service user, while local login or RDP sessions are disabled. For monitoring, this user requires a valid JEA profile.'; 5 | 'FullName' = 'Icinga for Windows Monitoring User'; 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /lib/core/windows/New-IcingaWindowsUserPassword.psm1: -------------------------------------------------------------------------------- 1 | function New-IcingaWindowsUserPassword() 2 | { 3 | if ($null -eq $Global:Icinga) { 4 | $Global:Icinga = @{ 5 | 'ServiceUserPassword' = $null 6 | }; 7 | } 8 | 9 | if ($Global:Icinga.ContainsKey('ServiceUserPassword') -eq $FALSE) { 10 | $Global:Icinga.Add('ServiceUserPassword', $null); 11 | } 12 | 13 | [SecureString]$Password = ConvertTo-IcingaSecureString -String (Get-IcingaRandomChars -Count 60); 14 | $Global:Icinga.ServiceUserPassword = $Password; 15 | 16 | return $Password; 17 | } 18 | -------------------------------------------------------------------------------- /lib/core/windows/Restart-Icinga.psm1: -------------------------------------------------------------------------------- 1 | function Restart-Icinga() 2 | { 3 | Stop-Icinga; 4 | Start-Icinga; 5 | } 6 | -------------------------------------------------------------------------------- /lib/core/windows/Restart-IcingaWindowsService.psm1: -------------------------------------------------------------------------------- 1 | function Restart-IcingaForWindows() 2 | { 3 | Stop-IcingaForWindows; 4 | Start-IcingaForWindows; 5 | } 6 | 7 | Set-Alias -Name 'Restart-IcingaWindowsService' -Value 'Restart-IcingaForWindows'; 8 | -------------------------------------------------------------------------------- /lib/core/windows/Start-Icinga.psm1: -------------------------------------------------------------------------------- 1 | function Start-Icinga() 2 | { 3 | Start-IcingaService -Service 'icinga2'; 4 | Start-IcingaForWindows; 5 | } 6 | -------------------------------------------------------------------------------- /lib/core/windows/Start-IcingaForWindows.psm1: -------------------------------------------------------------------------------- 1 | function Start-IcingaForWindows() 2 | { 3 | Start-IcingaService -Service 'icingapowershell'; 4 | # Update the process priority after each restart 5 | Start-IcingaWindowsScheduledTaskProcessPriority; 6 | } 7 | -------------------------------------------------------------------------------- /lib/core/windows/Stop-Icinga.psm1: -------------------------------------------------------------------------------- 1 | function Stop-Icinga() 2 | { 3 | Stop-IcingaService -Service 'icinga2'; 4 | Stop-IcingaForWindows; 5 | } 6 | -------------------------------------------------------------------------------- /lib/core/windows/Stop-IcingaJEAProcess.psm1: -------------------------------------------------------------------------------- 1 | function Stop-IcingaJEAProcess() 2 | { 3 | param ( 4 | [string]$JeaPid = $null 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($JeaPid)) { 8 | [string]$JeaPid = Get-IcingaJEAServicePid; 9 | } 10 | 11 | if ([string]::IsNullOrEmpty($JeaPid)) { 12 | return; 13 | } 14 | 15 | if ($JeaPid -eq '0' -Or $JeaPid -eq 0) { 16 | return; 17 | } 18 | 19 | $JeaPowerShellProcess = Get-Process -Id $JeaPid -ErrorAction SilentlyContinue; 20 | if ($null -eq $JeaPowerShellProcess) { 21 | return; 22 | } 23 | 24 | if ($JeaPowerShellProcess.ProcessName -ne 'wsmprovhost') { 25 | return; 26 | } 27 | 28 | try { 29 | Stop-Process -Id $JeaPid -Force -ErrorAction Stop; 30 | } catch { 31 | Write-IcingaConsoleError 'Unable to stop the JEA process "wsmprovhost" caused by the following error: "{0}".' -Objects $_.Exception.Message; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/core/windows/Stop-IcingaWindowsService.psm1: -------------------------------------------------------------------------------- 1 | function Stop-IcingaForWindows() 2 | { 3 | [string]$JeaPid = Get-IcingaJEAServicePid; 4 | 5 | Stop-IcingaService -Service 'icingapowershell'; 6 | 7 | if ((Test-IcingaJEAServiceRunning -JeaPid $JeaPid)) { 8 | Stop-Process -Id $JeaPid -Force; 9 | } 10 | } 11 | 12 | Set-Alias -Name 'Stop-IcingaWindowsService' -Value 'Stop-IcingaForWindows'; 13 | -------------------------------------------------------------------------------- /lib/core/windows/Test-IcingaManagedUser.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaManagedUser() 2 | { 3 | param ( 4 | [string]$IcingaUser = '', 5 | [string]$SID = '' 6 | ); 7 | 8 | $UserConfig = Get-IcingaWindowsUserConfig -UserName $IcingaUser -SID $SID; 9 | 10 | return $UserConfig.IcingaManagedUser; 11 | } 12 | -------------------------------------------------------------------------------- /lib/core/windows/Uninstall-IcingaSecurity.psm1: -------------------------------------------------------------------------------- 1 | function Uninstall-IcingaSecurity() 2 | { 3 | param ( 4 | $IcingaUser = 'icinga' 5 | ); 6 | 7 | Uninstall-IcingaServiceUser -IcingaUser $IcingaUser; 8 | Uninstall-IcingaJEAProfile; 9 | } 10 | -------------------------------------------------------------------------------- /lib/core/windows/Update-IcingaServiceUser.psm1: -------------------------------------------------------------------------------- 1 | function Update-IcingaServiceUser() 2 | { 3 | $IcingaUser = Get-IcingaPowerShellConfig -Path 'Framework.Icinga.ServiceUser'; 4 | 5 | if ([string]::IsNullOrEmpty($IcingaUser)) { 6 | return; 7 | } 8 | 9 | if ((Test-IcingaManagedUser -IcingaUser $IcingaUser) -eq $FALSE) { 10 | return; 11 | } 12 | 13 | $UserConfig = Get-IcingaWindowsUserConfig -UserName $IcingaUser; 14 | $User = New-IcingaWindowsUser -IcingaUser $UserConfig.Name; 15 | 16 | Set-IcingaServiceUser -User $IcingaUser -Password $Global:Icinga.ServiceUserPassword -Service 'icinga2' | Out-Null; 17 | Set-IcingaServiceUser -User $IcingaUser -Password $Global:Icinga.ServiceUserPassword -Service 'icingapowershell' | Out-Null; 18 | 19 | Restart-IcingaService 'icinga2'; 20 | Restart-IcingaForWindows; 21 | } 22 | -------------------------------------------------------------------------------- /lib/core/wintasks/Wait-IcingaWindowsScheduledTask.psm1: -------------------------------------------------------------------------------- 1 | function Wait-IcingaWindowsScheduledTask() 2 | { 3 | param ( 4 | [string]$TaskName = 'Management Task', 5 | [string]$TaskPath = '\Icinga\Icinga for Windows\', 6 | [int]$Timeout = 180 7 | ); 8 | 9 | [int]$TimeoutTicks = $Timeout * 1000; 10 | 11 | while ($TimeoutTicks -gt 0) { 12 | $TaskStatus = Get-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -ErrorAction SilentlyContinue; 13 | 14 | if ($null -eq $TaskStatus) { 15 | return; 16 | } 17 | 18 | if ($TaskStatus.State -eq 'Ready') { 19 | break; 20 | } 21 | Start-Sleep -Milliseconds 500; 22 | 23 | $TimeoutTicks -= 500; 24 | } 25 | 26 | if ($TimeoutTicks -le 0) { 27 | Stop-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath | Out-Null; 28 | 29 | Write-IcingaConsoleError 'The scheduled task "{0}" at path "{1}" could not be executed within {2} seconds and run into a timeout' -Objects $TaskName, $TaskPath, $Timeout; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/core/wintasks/daemon/Start-TaskRenewCertificate.psm1: -------------------------------------------------------------------------------- 1 | function Start-IcingaWindowsScheduledTaskRenewCertificate() 2 | { 3 | [string]$TaskName = 'Renew Certificate'; 4 | [string]$TaskPath = '\Icinga\Icinga for Windows\'; 5 | 6 | $RenewCertificateTask = Get-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -ErrorAction SilentlyContinue; 7 | 8 | if ($null -eq $RenewCertificateTask) { 9 | Write-IcingaConsoleNotice -Message 'The "{0}" task is not present on this system.' -Objects $TaskName; 10 | return; 11 | } 12 | 13 | Start-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath; 14 | } 15 | -------------------------------------------------------------------------------- /lib/core/wintasks/daemon/Start-TaskSetProcessPriority.psm1: -------------------------------------------------------------------------------- 1 | function Start-IcingaWindowsScheduledTaskProcessPriority() 2 | { 3 | [string]$TaskName = 'Set Process Priority'; 4 | [string]$TaskPath = '\Icinga\Icinga for Windows\'; 5 | 6 | $SetProcessPriorityTask = Get-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -ErrorAction SilentlyContinue; 7 | 8 | if ($null -eq $SetProcessPriorityTask) { 9 | Write-IcingaConsoleNotice -Message 'The "{0}" task is not present on this system.' -Objects $TaskName; 10 | return; 11 | } 12 | 13 | Start-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath; 14 | } 15 | -------------------------------------------------------------------------------- /lib/core/wintasks/daemon/Unregister-TaskRenewCertificate.psm1: -------------------------------------------------------------------------------- 1 | function Unregister-IcingaWindowsScheduledTaskRenewCertificate() 2 | { 3 | [string]$TaskName = 'Renew Certificate'; 4 | [string]$TaskPath = '\Icinga\Icinga for Windows\'; 5 | 6 | $RenewCertificateTask = Get-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -ErrorAction SilentlyContinue; 7 | 8 | if ($null -eq $RenewCertificateTask) { 9 | Write-IcingaConsoleNotice -Message 'The "{0}" task is not present on this system.' -Objects $TaskName; 10 | return; 11 | } 12 | 13 | Stop-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath | Out-Null; 14 | Unregister-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -Confirm:$FALSE -ErrorAction SilentlyContinue | Out-Null; 15 | Write-IcingaConsoleNotice -Message 'The "{0}" task was removed from the system.' -Objects $TaskName; 16 | } 17 | -------------------------------------------------------------------------------- /lib/daemon/Add-IcingaForWindowsDaemon.psm1: -------------------------------------------------------------------------------- 1 | function Add-IcingaForWindowsDaemon() 2 | { 3 | try { 4 | $EnabledDaemons = Get-IcingaBackgroundDaemons; 5 | 6 | foreach ($daemon in $EnabledDaemons.Keys) { 7 | Write-IcingaDebugMessage -Message 'Trying to enable background daemon' -Objects $daemon; 8 | if (-Not (Test-IcingaFunction $daemon)) { 9 | Write-IcingaEventMessage -EventId 1400 -Namespace 'Framework' $daemon; 10 | continue; 11 | } 12 | 13 | $daemonArgs = $EnabledDaemons[$daemon]; 14 | Write-IcingaDebugMessage -Message 'Starting background daemon' -Objects $daemon, $daemonArgs; 15 | 16 | & $daemon @daemonArgs; 17 | } 18 | } catch { 19 | # Todo: Add exception handling 20 | } 21 | 22 | while ($TRUE) { 23 | Start-Sleep -Seconds 10; 24 | 25 | # Handle possible threads being frozen 26 | Suspend-IcingaForWindowsFrozenThreads; 27 | 28 | # Force Icinga for Windows Garbage Collection 29 | Optimize-IcingaForWindowsMemory -ClearErrorStack -SmartGC; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/daemon/Get-IcingaBackgroundDaemons.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaBackgroundDaemons() 2 | { 3 | $Daemons = Get-IcingaPowerShellConfig -Path 'BackgroundDaemon.EnabledDaemons'; 4 | [hashtable]$Output = @{ }; 5 | 6 | if ($null -eq $Daemons) { 7 | return $Output; 8 | } 9 | 10 | foreach ($daemon in $Daemons.PSObject.Properties) { 11 | $Arguments = @{ }; 12 | 13 | foreach ($argument in $daemon.Value.Arguments.PSObject.Properties) { 14 | $Arguments.Add($argument.Name, $argument.Value); 15 | } 16 | 17 | $Output.Add($daemon.Name, $Arguments); 18 | } 19 | 20 | return $Output; 21 | } 22 | -------------------------------------------------------------------------------- /lib/daemon/Get-IcingaForWindowsServicePid.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaForWindowsServicePid() 2 | { 3 | [string]$PidFile = (Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'service.pid'); 4 | [string]$IfWPid = Read-IcingaFileSecure -File $PidFile; 5 | 6 | if ([string]::IsNullOrEmpty($IfWPid) -eq $FALSE) { 7 | $IfWPid = $IfWPid.Replace("`r`n", '').Replace("`n", '').Replace(' ', ''); 8 | } 9 | 10 | return $IfWPid; 11 | } 12 | -------------------------------------------------------------------------------- /lib/daemon/Register-IcingaBackgroundDaemon.psm1: -------------------------------------------------------------------------------- 1 | function Register-IcingaBackgroundDaemon() 2 | { 3 | param( 4 | [string]$Command, 5 | [hashtable]$Arguments 6 | ); 7 | 8 | if ([string]::IsNullOrEmpty($Command)) { 9 | throw 'Please specify a Cmdlet to run as Background Daemon'; 10 | } 11 | 12 | if (-Not (Test-IcingaFunction $Command)) { 13 | throw ([string]::Format('The Cmdlet "{0}" is not available in your session. Please restart the session and try again or verify your input', $Command)); 14 | } 15 | 16 | $Path = [string]::Format('BackgroundDaemon.EnabledDaemons.{0}', $Command); 17 | 18 | Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.Command', $Path)) -Value $Command; 19 | Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.Arguments', $Path)) -Value $Arguments; 20 | 21 | Write-IcingaConsoleNotice ([string]::Format('Background daemon Cmdlet "{0}" has been configured', $Command)); 22 | } 23 | -------------------------------------------------------------------------------- /lib/daemon/Unregister-IcingaBackgroundDaemon.psm1: -------------------------------------------------------------------------------- 1 | function Unregister-IcingaBackgroundDaemon() 2 | { 3 | param( 4 | [string]$BackgroundDaemon, 5 | [hashtable]$Arguments 6 | ); 7 | 8 | if ([string]::IsNullOrEmpty($BackgroundDaemon)) { 9 | throw 'Please specify a Cmdlet to remove from running as Background Daemon'; 10 | } 11 | 12 | $Path = [string]::Format('BackgroundDaemon.EnabledDaemons.{0}', $BackgroundDaemon); 13 | 14 | Remove-IcingaPowerShellConfig -Path $Path; 15 | 16 | Write-IcingaConsoleNotice 'Background daemon has been removed'; 17 | } 18 | -------------------------------------------------------------------------------- /lib/daemons/RestAPI/client/Add-IcingaRESTClientBlacklistCount.psm1: -------------------------------------------------------------------------------- 1 | function Add-IcingaRESTClientBlacklistCount() 2 | { 3 | param ( 4 | [System.Net.Sockets.TcpClient]$Client = $null, 5 | $ClientList = $null 6 | ); 7 | 8 | if ($null -eq $Client) { 9 | return; 10 | } 11 | 12 | [string]$Endpoint = Get-IcingaTCPClientRemoteEndpoint -Client $Client; 13 | [string]$IpAddress = $Endpoint.Split(':')[0]; 14 | [int]$Value = Get-IcingaHashtableItem ` 15 | -Hashtable $ClientList ` 16 | -Key $IpAddress ` 17 | -NullValue 0; 18 | 19 | Add-IcingaHashtableItem ` 20 | -Hashtable $ClientList ` 21 | -Key $IpAddress ` 22 | -Value ($Value + 1) ` 23 | -Override | Out-Null; 24 | } 25 | -------------------------------------------------------------------------------- /lib/daemons/RestAPI/client/Remove-IcingaRESTClientBlacklist.psm1: -------------------------------------------------------------------------------- 1 | function Remove-IcingaRESTClientBlacklist() 2 | { 3 | param ( 4 | [System.Net.Sockets.TcpClient]$Client = $null, 5 | $ClientList = $null 6 | ); 7 | 8 | if ($null -eq $Client) { 9 | return; 10 | } 11 | 12 | [string]$Endpoint = Get-IcingaTCPClientRemoteEndpoint -Client $Client; 13 | [string]$IpAddress = $Endpoint.Split(':')[0]; 14 | 15 | Remove-IcingaHashtableItem ` 16 | -Hashtable $ClientList ` 17 | -Key $IpAddress; 18 | } 19 | -------------------------------------------------------------------------------- /lib/daemons/RestAPI/client/Test-IcingaRESTClientBlacklisted.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaRESTClientBlacklisted() 2 | { 3 | param ( 4 | [System.Net.Sockets.TcpClient]$Client = $null, 5 | $ClientList = $null 6 | ); 7 | 8 | if ($null -eq $Client) { 9 | return $FALSE; 10 | } 11 | 12 | [string]$Endpoint = Get-IcingaTCPClientRemoteEndpoint -Client $Client; 13 | [string]$IpAddress = $Endpoint.Split(':')[0]; 14 | [int]$Value = Get-IcingaHashtableItem ` 15 | -Hashtable $ClientList ` 16 | -Key $IpAddress ` 17 | -NullValue 0; 18 | 19 | # After 9 invalid attempts we will blacklist the client 20 | if ($Value -gt 9) { 21 | Write-IcingaDebugMessage -Message 'Client is blacklisted' -Objects $IpAddress, $Value, $Client.Client; 22 | return $TRUE; 23 | } 24 | 25 | return $FALSE; 26 | } 27 | -------------------------------------------------------------------------------- /lib/daemons/RestAPI/client/Test-IcingaRESTClientConnection.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaRESTClientConnection() 2 | { 3 | param( 4 | [Hashtable]$Connection = @{ } 5 | ); 6 | 7 | # If we couldn't establish a proper SSL stream, close the connection 8 | # immediately without opening a client connection thread 9 | if ($null -eq $Connection.Stream) { 10 | Add-IcingaRESTClientBlacklistCount ` 11 | -Client $Connection.Client ` 12 | -ClientList $Global:Icinga.Public.Daemons.RESTApi.ClientBlacklist; 13 | Write-IcingaEventMessage -EventId 1501 -Namespace 'Framework' -Objects $Connection.Client.Client; 14 | Close-IcingaTCPConnection -Connection $Connection; 15 | $Connection = $null; 16 | return $FALSE; 17 | } 18 | 19 | Write-IcingaDebugMessage 'Client connection has passed Test'; 20 | 21 | return $TRUE; 22 | } 23 | -------------------------------------------------------------------------------- /lib/daemons/RestAPI/threads/New-IcingaForWindowsCertificateThreadTaskInstance.psm1: -------------------------------------------------------------------------------- 1 | function New-IcingaForWindowsCertificateThreadTaskInstance() 2 | { 3 | $IcingaHostname = Get-IcingaHostname -ReadConstants; 4 | 5 | while ($TRUE) { 6 | # Check every 10 minutes if our certificate is present and update it in case it is 7 | # missing or updates have happened 8 | 9 | $NewIcingaForWindowsCertificate = Get-IcingaForWindowsCertificate; 10 | 11 | if ($null -ne $NewIcingaForWindowsCertificate) { 12 | if ($NewIcingaForWindowsCertificate.Issuer.ToLower() -eq ([string]::Format('cn={0}', $IcingaHostname).ToLower())) { 13 | Write-IcingaEventMessage -EventId 1506 -Namespace 'Framework'; 14 | } else { 15 | if ($Global:Icinga.Public.SSL.Certificate.GetCertHashString() -ne $NewIcingaForWindowsCertificate.GetCertHashString()) { 16 | $Global:Icinga.Public.SSL.Certificate = $NewIcingaForWindowsCertificate; 17 | Write-IcingaEventMessage -EventId 2004 -Namespace 'RESTApi'; 18 | } 19 | } 20 | } 21 | 22 | Start-Sleep -Seconds (60 * 10); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lib/daemons/RestAPI/threads/Start-IcingaForWindowsCertificateThreadTask.psm1: -------------------------------------------------------------------------------- 1 | function Start-IcingaForWindowsCertificateThreadTask() 2 | { 3 | New-IcingaThreadInstance ` 4 | -Name 'CertificateRenewThread' ` 5 | -ThreadPool (New-IcingaThreadPool -MaxInstances 1) ` 6 | -Command 'New-IcingaForWindowsCertificateThreadTaskInstance' ` 7 | -Start; 8 | } 9 | -------------------------------------------------------------------------------- /lib/daemons/RestAPI/threads/Start-IcingaForWindowsRESTThread.psm1: -------------------------------------------------------------------------------- 1 | function Start-IcingaForWindowsRESTThread() 2 | { 3 | param ( 4 | [int]$ThreadId = 0, 5 | [switch]$RequireAuth = $FALSE 6 | ); 7 | 8 | # Now create a new thread, assign a name and parse all required arguments to it. 9 | # Last but not least start it directly 10 | New-IcingaThreadInstance ` 11 | -Name 'CheckThread' ` 12 | -ThreadPool (New-IcingaThreadPool -MaxInstances 1) ` 13 | -Command 'New-IcingaForWindowsRESTThread' ` 14 | -CmdParameters @{ 15 | 'RequireAuth' = $RequireAuth; 16 | 'ThreadId' = $ThreadId; 17 | } ` 18 | -Start ` 19 | -CheckAliveState; 20 | } 21 | -------------------------------------------------------------------------------- /lib/daemons/ServiceCheckDaemon/task/Start-IcingaServiceCheckTask.psm1: -------------------------------------------------------------------------------- 1 | function Start-IcingaServiceCheckTask() 2 | { 3 | param ( 4 | $CheckId, 5 | $CheckCommand, 6 | $Arguments, 7 | $Interval, 8 | $TimeIndexes 9 | ); 10 | 11 | New-IcingaThreadInstance -Name $CheckId -ThreadPool (Get-IcingaThreadPool -Name 'ServiceCheckPool') -Command 'Add-IcingaServiceCheckTask' -CmdParameters @{ 12 | 'CheckCommand' = $CheckCommand; 13 | 'Arguments' = $Arguments; 14 | 'Interval' = $Interval; 15 | 'TimeIndexes' = $TimeIndexes 16 | 'CheckId' = $CheckId; 17 | } -Start; 18 | } 19 | -------------------------------------------------------------------------------- /lib/daemons/ServiceCheckDaemon/tools/Clear-IcingaServiceCheckDaemonEnvironment.psm1: -------------------------------------------------------------------------------- 1 | function Clear-IcingaServiceCheckDaemonEnvironment() 2 | { 3 | $Global:Icinga.Private.Daemons.ServiceCheck.PassedTime = 0; 4 | $Global:Icinga.Private.Daemons.ServiceCheck.SortedResult.Clear(); 5 | $Global:Icinga.Private.Daemons.ServiceCheck.PerformanceCache.Clear(); 6 | } 7 | -------------------------------------------------------------------------------- /lib/daemons/ServiceCheckDaemon/tools/Get-IcingaRegisteredServiceChecks.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaRegisteredServiceChecks() 2 | { 3 | $Services = Get-IcingaPowerShellConfig -Path 'BackgroundDaemon.RegisteredServices'; 4 | [hashtable]$Output = @{ }; 5 | 6 | foreach ($service in $Services.PSObject.Properties) { 7 | $Content = @{ 8 | 'Id' = $service.Name; 9 | 'CheckCommand' = $service.Value.CheckCommand; 10 | 'Arguments' = $service.Value.Arguments; 11 | 'Interval' = $service.Value.Interval; 12 | 'TimeIndexes' = $service.Value.TimeIndexes; 13 | }; 14 | 15 | $Output.Add($service.Name, $Content); 16 | } 17 | 18 | return $Output; 19 | } 20 | -------------------------------------------------------------------------------- /lib/daemons/ServiceCheckDaemon/tools/Read-IcingaCheckResultStore.psm1: -------------------------------------------------------------------------------- 1 | function Read-IcingaCheckResultStore() 2 | { 3 | param ( 4 | $CheckCommand 5 | ); 6 | 7 | $LoadedCacheData = Get-IcingaCacheData -Space 'sc_daemon' -CacheStore 'checkresult_store' -KeyName $CheckCommand; 8 | 9 | if ($null -ne $LoadedCacheData) { 10 | foreach ($entry in $LoadedCacheData.PSObject.Properties) { 11 | $Global:Icinga.Private.Scheduler.CheckData[$CheckCommand]['results'].Add( 12 | $entry.name, 13 | @{ } 14 | ); 15 | foreach ($item in $entry.Value.PSObject.Properties) { 16 | $Global:Icinga.Private.Scheduler.CheckData[$CheckCommand]['results'][$entry.name].Add( 17 | $item.Name, 18 | $item.Value 19 | ); 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/daemons/ServiceCheckDaemon/tools/Register-IcingaServiceCheck.psm1: -------------------------------------------------------------------------------- 1 | function Register-IcingaServiceCheck() 2 | { 3 | param( 4 | [string]$CheckCommand, 5 | [hashtable]$Arguments, 6 | [int]$Interval = 60, 7 | [array]$TimeIndexes = @() 8 | ); 9 | 10 | if ([string]::IsNullOrEmpty($CheckCommand)) { 11 | throw 'Please specify a CheckCommand'; 12 | } 13 | 14 | $Hash = Get-StringSha1 ([string]::Format('{0} {1}', $CheckCommand, ($Arguments | Out-String))); 15 | $Path = [string]::Format('BackgroundDaemon.RegisteredServices.{0}', $Hash); 16 | 17 | Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.CheckCommand', $Path)) -Value $CheckCommand; 18 | Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.Arguments', $Path)) -Value $Arguments; 19 | Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.Interval', $Path)) -Value $Interval; 20 | Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.TimeIndexes', $Path)) -Value $TimeIndexes; 21 | 22 | Write-IcingaConsoleNotice 'Icinga background service check has been added'; 23 | } 24 | -------------------------------------------------------------------------------- /lib/daemons/ServiceCheckDaemon/tools/Unregister-IcingaServiceCheck.psm1: -------------------------------------------------------------------------------- 1 | function Unregister-IcingaServiceCheck() 2 | { 3 | param( 4 | [string]$ServiceId 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($ServiceId)) { 8 | throw 'Please specify a Service Id'; 9 | } 10 | 11 | $Path = [string]::Format('BackgroundDaemon.RegisteredServices.{0}', $ServiceId); 12 | 13 | Remove-IcingaPowerShellConfig -Path $Path; 14 | 15 | Write-IcingaConsoleNotice 'Icinga background service check has been removed'; 16 | } 17 | -------------------------------------------------------------------------------- /lib/icinga/exception/Get-IcingaLastExceptionId.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | This function returns the HRESULT unique value thrown by the last exception 4 | .DESCRIPTION 5 | This function returns the HRESULT unique value thrown by the last exception 6 | .OUTPUTS 7 | System.String 8 | #> 9 | function Get-IcingaLastExceptionId() 10 | { 11 | if ([string]::IsNullOrEmpty($Error)) { 12 | return ''; 13 | } 14 | 15 | [string]$ExceptionId = ([string]($Error.FullyQualifiedErrorId)).Split(',')[0].Split(' ')[1]; 16 | $Error.Clear(); 17 | 18 | return $ExceptionId; 19 | } 20 | -------------------------------------------------------------------------------- /lib/icinga/plugin/ConvertTo-IcingaPluginOutputTranslation.psm1: -------------------------------------------------------------------------------- 1 | function ConvertTo-IcingaPluginOutputTranslation() 2 | { 3 | param ( 4 | $Value = $null, 5 | [hashtable]$Translation = @{ } 6 | ); 7 | 8 | if ($null -eq $Value) { 9 | return 'Nothing'; 10 | } 11 | 12 | if ($null -eq $Translation -Or $Translation.Count -eq 0) { 13 | return $Value; 14 | } 15 | 16 | [array]$TranslationKeys = $Translation.Keys; 17 | [array]$TranslationValues = $Translation.Values; 18 | [int]$Index = 0; 19 | [bool]$FoundTranslation = $FALSE; 20 | 21 | foreach ($entry in $TranslationKeys) { 22 | if (([string]($Value)).ToLower() -eq ([string]($entry)).ToLower()) { 23 | $FoundTranslation = $TRUE; 24 | break; 25 | } 26 | $Index += 1; 27 | } 28 | 29 | if ($FoundTranslation -eq $FALSE) { 30 | return $Value; 31 | } 32 | 33 | return $TranslationValues[$Index]; 34 | } 35 | -------------------------------------------------------------------------------- /lib/icinga/plugin/Get-IcingaInternalPluginExitCode.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaInternalPluginExitCode() 2 | { 3 | return $Global:Icinga.Private.Scheduler.ExitCode; 4 | } 5 | -------------------------------------------------------------------------------- /lib/icinga/plugin/Get-IcingaInternalPluginOutput.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaInternalPluginOutput() 2 | { 3 | if ([string]::IsNullOrEmpty($Global:Icinga.Private.Scheduler.PluginException) -eq $FALSE) { 4 | return $Global:Icinga.Private.Scheduler.PluginException; 5 | } 6 | 7 | return $Global:Icinga.Private.Scheduler.CheckResults; 8 | } 9 | -------------------------------------------------------------------------------- /lib/icinga/plugin/Get-IcingaThresholdCache.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaThresholdCache() 2 | { 3 | param ( 4 | [string]$CheckCommand = $null 5 | ); 6 | 7 | if ([string]::IsNullOrEmpty($CheckCommand)) { 8 | return $null; 9 | } 10 | 11 | if ($Global:Icinga.Private.Scheduler.ThresholdCache.ContainsKey($CheckCommand) -eq $FALSE) { 12 | return $null; 13 | } 14 | 15 | return $Global:Icinga.Private.Scheduler.ThresholdCache[$CheckCommand]; 16 | } 17 | -------------------------------------------------------------------------------- /lib/icinga/plugin/Set-IcingaInternalPluginException.psm1: -------------------------------------------------------------------------------- 1 | function Set-IcingaInternalPluginException() 2 | { 3 | param ( 4 | [string]$PluginException = '' 5 | ); 6 | 7 | # Only catch the first exception 8 | if ([string]::IsNullOrEmpty($Global:Icinga.Private.Scheduler.PluginException)) { 9 | $Global:Icinga.Private.Scheduler.PluginException = $PluginException; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/icinga/plugin/Set-IcingaInternalPluginExitCode.psm1: -------------------------------------------------------------------------------- 1 | function Set-IcingaInternalPluginExitCode() 2 | { 3 | param ( 4 | $ExitCode = 0 5 | ); 6 | 7 | # Only add the first exit code we should cover during one runtime 8 | if ($null -eq $Global:Icinga.Private.Scheduler.ExitCode) { 9 | $Global:Icinga.Private.Scheduler.ExitCode = $ExitCode; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/icinga/plugin/Write-IcingaPluginOutput.psm1: -------------------------------------------------------------------------------- 1 | function Write-IcingaPluginOutput() 2 | { 3 | param ( 4 | $Output 5 | ); 6 | 7 | if ($Global:Icinga.Protected.RunAsDaemon -eq $FALSE -And $Global:Icinga.Protected.JEAContext -eq $FALSE) { 8 | if ($Global:Icinga.Protected.Minimal) { 9 | Clear-CLIConsole; 10 | } 11 | Write-IcingaConsolePlain $Output; 12 | } else { 13 | # New behavior with local thread separated results 14 | [array]$Global:Icinga.Private.Scheduler.CheckResults += $Output; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /lib/icinga/plugin/Write-IcingaPluginResult.psm1: -------------------------------------------------------------------------------- 1 | function Write-IcingaPluginResult() 2 | { 3 | param ( 4 | [string]$PluginOutput = '', 5 | [string]$PluginPerfData = '' 6 | ); 7 | 8 | [string]$CheckResult = $PluginOutput; 9 | 10 | if ([string]::IsNullOrEmpty($PluginPerfData) -eq $FALSE) { 11 | $CheckResult = [string]::Format('{0}{1}| {2}', $CheckResult, "`r`n", $PluginPerfData); 12 | } 13 | 14 | Write-IcingaConsolePlain $CheckResult; 15 | } 16 | -------------------------------------------------------------------------------- /lib/mssql/Close-IcingaMSSQLConnection.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Closes a open connection to a MSSQL server 4 | .DESCRIPTION 5 | This Cmdlet will close an open connection to a MSSQL server. 6 | .FUNCTIONALITY 7 | Closes an open connection to a MSSQL server. 8 | .EXAMPLE 9 | PS>Close-IcingaMSSQLConnection $OpenMSSQLConnection; 10 | .INPUTS 11 | System.Data.SqlClient.SqlConnection 12 | .OUTPUTS 13 | .LINK 14 | https://github.com/Icinga/icinga-powershell-framework 15 | #> 16 | function Close-IcingaMSSQLConnection() 17 | { 18 | param ( 19 | [System.Data.SqlClient.SqlConnection]$SqlConnection = $null 20 | ); 21 | 22 | if ($null -eq $SqlConnection) { 23 | return; 24 | } 25 | 26 | Write-IcingaDebugMessage ` 27 | -Message 'Closing client connection for endpoint {0}' ` 28 | -Objects $SqlConnection; 29 | 30 | $SqlConnection.Close(); 31 | $SqlConnection.Dispose(); 32 | $SqlConnection = $null; 33 | } 34 | -------------------------------------------------------------------------------- /lib/mssql/Send-IcingaMSSQLCommand.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Executes a SQL query 4 | .DESCRIPTION 5 | This Cmdlet will send a SQL query to a given database and 6 | execute the query and returns the output. 7 | .FUNCTIONALITY 8 | Executes a SQL query 9 | .EXAMPLE 10 | PS> Send-IcingaMSSQLCommand -SqlCommand $SqlCommand; 11 | .PARAMETER SqlCommand 12 | The SQL query which will be executed, e.g. $SqlCommand = New-IcingaMSSQLCommand 13 | .INPUTS 14 | System.Data.SqlClient.SqlCommand 15 | .OUTPUTS 16 | System.Data.DataSet 17 | .LINK 18 | https://github.com/Icinga/icinga-powershell-framework 19 | #> 20 | function Send-IcingaMSSQLCommand() 21 | { 22 | param ( 23 | [System.Data.SqlClient.SqlCommand]$SqlCommand = $null 24 | ); 25 | 26 | $Adapter = New-Object System.Data.SqlClient.SqlDataAdapter $SqlCommand; 27 | 28 | $Data = New-Object System.Data.DataSet; 29 | $Adapter.Fill($Data) | Out-Null; 30 | 31 | return $Data.Tables; 32 | } 33 | -------------------------------------------------------------------------------- /lib/provider/assets/cpu/Get-IcingaProviderDataValuesCpu.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaProviderDataValuesCpu() 2 | { 3 | param ( 4 | [array]$IncludeFilter = @(), 5 | [array]$ExcludeFilter = @(), 6 | [hashtable]$ProviderFilter = @{ }, 7 | [switch]$IncludeDetails = $FALSE 8 | ); 9 | 10 | $CpuData = New-IcingaProviderObject -Name 'Cpu'; 11 | [hashtable]$FilterObject = Get-IcingaProviderFilterData -ProviderName 'Cpu' -ProviderFilter $ProviderFilter; 12 | 13 | $CpuData.Metrics = $FilterObject.Cpu.Query.Metrics; 14 | $CpuData.MetricsOverTime = $FilterObject.Cpu.Query.MetricsOverTime; 15 | $CpuData.Metadata = $FilterObject.Cpu.Query.Metadata; 16 | 17 | $FilterObject = $null; 18 | 19 | return $CpuData; 20 | } 21 | -------------------------------------------------------------------------------- /lib/provider/core/Get-IcingaProviderElement.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaProviderElement() 2 | { 3 | param ( 4 | $Object = $null 5 | ); 6 | 7 | if ($null -eq $Object) { 8 | return @(); 9 | } 10 | 11 | try { 12 | return $Object.PSObject.Properties 13 | } catch { 14 | return @(); 15 | } 16 | 17 | return @(); 18 | } 19 | -------------------------------------------------------------------------------- /lib/provider/core/Get-IcingaProviderFilterData.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaProviderFilterData() 2 | { 3 | param ( 4 | [string]$ProviderName = '', 5 | [hashtable]$ProviderFilter = @{ } 6 | ); 7 | 8 | [hashtable]$FilterResult = @{ }; 9 | 10 | foreach ($filterObject in $ProviderFilter.Keys) { 11 | if ($filterObject.ToLower() -ne $ProviderName.ToLower()) { 12 | continue; 13 | } 14 | 15 | if ($FilterResult.ContainsKey($filterObject) -eq $FALSE) { 16 | $FilterResult.Add( 17 | $filterObject, 18 | (New-IcingaProviderFilterObject -ProviderName $ProviderName -HashtableFilter $ProviderFilter[$filterObject]) 19 | ); 20 | } 21 | } 22 | 23 | return $FilterResult; 24 | } 25 | -------------------------------------------------------------------------------- /lib/provider/logging/Add-IcingaProviderEventlogFilterData.psm1: -------------------------------------------------------------------------------- 1 | function Add-IcingaProviderEventlogFilterData() 2 | { 3 | param( 4 | [string]$EventFilter = '', 5 | $StringBuilderObject = $null 6 | ); 7 | 8 | if ($null -eq $StringBuilderObject -Or $StringBuilderObject.Length -eq 0) { 9 | return $EventFilter; 10 | } 11 | 12 | [string]$NewStringEntry = $StringBuilderObject.ToString(); 13 | 14 | $StringBuilderObject.Clear(); 15 | $StringBuilderObject = $null; 16 | 17 | if ([string]::IsNullOrEmpty($NewStringEntry)) { 18 | return $EventFilter; 19 | } 20 | 21 | if ([string]::IsNullOrEmpty($EventFilter)) { 22 | return $NewStringEntry; 23 | } 24 | 25 | [string]$EventFilter = [string]::Format('{0} and {1}', $EventFilter, $NewStringEntry); 26 | 27 | return $EventFilter; 28 | } 29 | -------------------------------------------------------------------------------- /lib/provider/logging/Get-IcingaProviderDataValuesEventlog.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaProviderDataValuesEventlog() 2 | { 3 | param ( 4 | [array]$IncludeFilter = @(), 5 | [array]$ExcludeFilter = @(), 6 | [hashtable]$ProviderFilter = @{ }, 7 | [switch]$IncludeDetails = $FALSE 8 | ); 9 | 10 | $EventlogData = New-IcingaProviderObject -Name 'Eventlog'; 11 | [hashtable]$FilterObject = Get-IcingaProviderFilterData -ProviderName 'Eventlog' -ProviderFilter $ProviderFilter; 12 | 13 | $EventLogData.Metrics | Add-Member -MemberType NoteProperty -Name 'List' -Value $FilterObject.EventLog.Query.List; 14 | $EventLogData.Metrics | Add-Member -MemberType NoteProperty -Name 'Events' -Value $FilterObject.EventLog.Query.Events; 15 | $EventLogData.Metrics | Add-Member -MemberType NoteProperty -Name 'Problems' -Value $FilterObject.EventLog.Query.Problems; 16 | $EventLogData.Metrics | Add-Member -MemberType NoteProperty -Name 'HasEvents' -Value $FilterObject.EventLog.Query.HasEvents; 17 | 18 | $FilterObject = $null; 19 | 20 | return $EventlogData; 21 | } 22 | -------------------------------------------------------------------------------- /lib/web/Disable-IcingaProgressPreference.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Disables the progress bar during file downloads or while loading certain modules. 4 | This will increase the speed of certain tasks, for example file downloads 5 | .DESCRIPTION 6 | Disables the progress bar during file downloads or while loading certain modules. 7 | This will increase the speed of certain tasks, for example file downloads 8 | .FUNCTIONALITY 9 | Sets the $ProgressPreference to 'SilentlyContinue' 10 | .LINK 11 | https://github.com/Icinga/icinga-powershell-framework 12 | #> 13 | 14 | function Disable-IcingaProgressPreference() 15 | { 16 | $global:ProgressPreference = "SilentlyContinue"; 17 | } 18 | -------------------------------------------------------------------------------- /lib/web/Get-IcingaFrameworkProxyServer.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Fetches the configuration of the configured Proxy server for the Framework, in 4 | case it is set 5 | .DESCRIPTION 6 | etches the configuration of the configured Proxy server for the Framework, in 7 | case it is set 8 | .FUNCTIONALITY 9 | etches the configuration of the configured Proxy server for the Framework, in 10 | case it is set 11 | .LINK 12 | https://github.com/Icinga/icinga-powershell-framework 13 | #> 14 | 15 | function Get-IcingaFrameworkProxyServer() 16 | { 17 | return (Get-IcingaPowerShellConfig -Path 'Framework.Proxy.Server'); 18 | } 19 | -------------------------------------------------------------------------------- /lib/web/Set-IcingaFrameworkProxyServer.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Sets the configuration for a proxy server which is used by all Invoke-WebRequests 4 | to ensure internet connections are working correctly. 5 | .DESCRIPTION 6 | Sets the configuration for a proxy server which is used by all Invoke-WebRequests 7 | to ensure internet connections are working correctly. 8 | .FUNCTIONALITY 9 | Sets the configuration for a proxy server which is used by all Invoke-WebRequests 10 | to ensure internet connections are working correctly. 11 | .EXAMPLE 12 | PS>Set-IcingaFrameworkProxyServer -Server 'http://example.com:8080'; 13 | .PARAMETER Server 14 | The server with the port for the Proxy. Example: 'http://example.com:8080' 15 | .INPUTS 16 | System.String 17 | .LINK 18 | https://github.com/Icinga/icinga-powershell-framework 19 | #> 20 | 21 | function Set-IcingaFrameworkProxyServer() 22 | { 23 | param ( 24 | [string]$Server = '' 25 | ); 26 | 27 | Set-IcingaPowerShellConfig -Path 'Framework.Proxy.Server' -Value $Server; 28 | 29 | Write-IcingaConsoleNotice 'The Proxy server for the PowerShell Framework has been set to "{0}"' -Objects $Server; 30 | } 31 | -------------------------------------------------------------------------------- /lib/web/Set-IcingaTLSVersion.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Sets the allowed TLS version for communicating with endpoints to TLS 1.2 and 1.1 4 | .DESCRIPTION 5 | Sets the allowed TLS version for communicating with endpoints to TLS 1.2 and 1.1 6 | .FUNCTIONALITY 7 | Uses the [Net.ServicePointManager] to set the SecurityProtocol to TLS 1.2 and 1.1 8 | .LINK 9 | https://github.com/Icinga/icinga-powershell-framework 10 | #> 11 | 12 | function Set-IcingaTLSVersion() 13 | { 14 | [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11"; 15 | } 16 | -------------------------------------------------------------------------------- /lib/webserver/Close-IcingaTCPConnection.psm1: -------------------------------------------------------------------------------- 1 | function Close-IcingaTCPConnection() 2 | { 3 | param( 4 | [hashtable]$Connection = @{ } 5 | ); 6 | 7 | if ($null -eq $Connection -Or $Connection.Count -eq 0) { 8 | $Connection = $null; 9 | 10 | return; 11 | } 12 | 13 | Write-IcingaDebugMessage -Message ( 14 | [string]::Format( 15 | 'Closing client connection for endpoint {0}', 16 | (Get-IcingaTCPClientRemoteEndpoint -Client $Connection.Client) 17 | ) 18 | ); 19 | 20 | try { 21 | if ($null -ne $Connection.Stream) { 22 | $Connection.Stream.Close(); 23 | $Connection.Stream.Dispose(); 24 | $Connection.Stream = $null; 25 | } 26 | } catch { 27 | $Connection.Stream = $null; 28 | } 29 | try { 30 | if ($null -ne $Connection.Client) { 31 | $Connection.Client.Close(); 32 | $Connection.Client.Dispose(); 33 | $Connection.Client = $null; 34 | } 35 | } catch { 36 | $Connection.Client = $null; 37 | } 38 | 39 | $Connection = $null; 40 | } 41 | -------------------------------------------------------------------------------- /lib/webserver/Close-IcingaTCPSocket.psm1: -------------------------------------------------------------------------------- 1 | function Close-IcingaTCPSocket() 2 | { 3 | param( 4 | [System.Net.Sockets.TcpListener]$Socket = $null 5 | ); 6 | 7 | if ($null -eq $Socket) { 8 | return; 9 | } 10 | 11 | Write-IcingaDebugMessage -Message ( 12 | [string]::Format( 13 | 'Closing TCP socket {0}', 14 | $Socket.LocalEndpoint 15 | ) 16 | ); 17 | 18 | $Socket.Stop(); 19 | } 20 | -------------------------------------------------------------------------------- /lib/webserver/Disable-IcingaUntrustedCertificateValidation.psm1: -------------------------------------------------------------------------------- 1 | function Disable-IcingaUntrustedCertificateValidation() 2 | { 3 | param ( 4 | [switch]$SuppressMessages = $FALSE 5 | ); 6 | 7 | try { 8 | [System.Net.ServicePointManager]::CertificatePolicy = $null; 9 | 10 | if ($SuppressMessages -eq $FALSE) { 11 | Write-IcingaConsoleNotice 'Successfully disabled untrusted certificate validation for this shell instance'; 12 | } 13 | } catch { 14 | if ($SuppressMessages -eq $FALSE) { 15 | Write-IcingaConsoleError ( 16 | [string]::Format( 17 | 'Failed to disable untrusted certificate policy: {0}', $_.Exception.Message 18 | ) 19 | ); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/webserver/Get-IcingaRESTHeaderValue.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaRESTHeaderValue() 2 | { 3 | param( 4 | [hashtable]$Request = @{ }, 5 | [string]$Header = $null 6 | ); 7 | 8 | if ($null -eq $Request -or [string]::IsNullOrEmpty($Header) -Or $Request.Count -eq 0) { 9 | return $null; 10 | } 11 | 12 | if ($Request.Header.ContainsKey($Header) -eq $FALSE) { 13 | return $null 14 | } 15 | 16 | return $Request.Header[$Header]; 17 | } 18 | -------------------------------------------------------------------------------- /lib/webserver/Get-IcingaRESTPathElement.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaRESTPathElement() 2 | { 3 | param( 4 | [Hashtable]$Request = @{ }, 5 | [int]$Index = 0 6 | ); 7 | 8 | if ($null -eq $Request -Or $Request.Count -eq 0) { 9 | return ''; 10 | } 11 | 12 | if ($Request.ContainsKey('RequestPath') -eq $FALSE) { 13 | return ''; 14 | } 15 | 16 | if (($Index + 1) -gt $Request.RequestPath.PathArray.Count) { 17 | return ''; 18 | } 19 | 20 | return $Request.RequestPath.PathArray[$Index]; 21 | } 22 | -------------------------------------------------------------------------------- /lib/webserver/Get-IcingaTCPClientRemoteEndpoint.psm1: -------------------------------------------------------------------------------- 1 | function Get-IcingaTCPClientRemoteEndpoint() 2 | { 3 | param( 4 | [System.Net.Sockets.TcpClient]$Client = $null 5 | ); 6 | 7 | if ($null -eq $Client) { 8 | return 'unknown'; 9 | } 10 | 11 | return $Client.Client.RemoteEndPoint; 12 | } 13 | -------------------------------------------------------------------------------- /lib/webserver/Import-IcingaCAToAuthRoot.psm1: -------------------------------------------------------------------------------- 1 | function Import-IcingaCAToAuthRoot() 2 | { 3 | $IcingaCAFile = Join-Path -Path $Env:ProgramData -ChildPath 'icinga2\var\lib\icinga2\certs\ca.crt'; 4 | 5 | if ((Test-Path $IcingaCAFile) -eq $FALSE) { 6 | return $FALSE; 7 | } 8 | 9 | if (Test-IcingaCAInstalledToAuthRoot) { 10 | return $TRUE; 11 | } 12 | 13 | Import-Certificate -FilePath $IcingaCAFile -CertStoreLocation 'Cert:\LocalMachine\AuthRoot\' | Out-Null; 14 | 15 | return ( 16 | Test-IcingaCAInstalledToAuthRoot 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /lib/webserver/New-IcingaSSLStream.psm1: -------------------------------------------------------------------------------- 1 | function New-IcingaSSLStream() 2 | { 3 | param( 4 | [System.Net.Sockets.TcpClient]$Client = $null, 5 | [Security.Cryptography.X509Certificates.X509Certificate2]$Certificate = $null 6 | ); 7 | 8 | if ($null -eq $Client) { 9 | return $null; 10 | } 11 | 12 | [System.Net.Security.SslStream]$SSLStream = $null; 13 | 14 | try { 15 | $SSLStream = New-Object System.Net.Security.SslStream($Client.GetStream(), $false); 16 | $TLSProtocols = [System.Security.Authentication.SslProtocols]::Tls12 -bor [System.Security.Authentication.SslProtocols]::Tls13; 17 | $SSLStream.AuthenticateAsServer($Certificate, $false, $TLSProtocols, $true) | Out-Null; 18 | } catch { 19 | if ($null -ne $SSLStream) { 20 | $SSLStream.Close(); 21 | $SSLStream.Dispose(); 22 | $SSLStream = $null; 23 | } 24 | Write-IcingaEventMessage -EventId 1500 -Namespace 'Framework' -ExceptionObject $_ -Objects $Client.Client; 25 | return $null; 26 | } 27 | 28 | return $SSLStream; 29 | } 30 | -------------------------------------------------------------------------------- /lib/webserver/New-IcingaTCPClient.psm1: -------------------------------------------------------------------------------- 1 | function New-IcingaTCPClient() 2 | { 3 | param( 4 | [System.Net.Sockets.TcpListener]$Socket = $null 5 | ); 6 | 7 | if ($null -eq $Socket) { 8 | return $null; 9 | } 10 | 11 | [System.Net.Sockets.TcpClient]$Client = $Socket.AcceptTcpClient(); 12 | 13 | Write-IcingaDebugMessage -Message ( 14 | [string]::Format( 15 | 'New incoming client connection for endpoint {0}', 16 | (Get-IcingaTCPClientRemoteEndpoint -Client $Client) 17 | ) 18 | ); 19 | 20 | return $Client; 21 | } 22 | -------------------------------------------------------------------------------- /lib/webserver/Open-IcingaTCPClientConnection.psm1: -------------------------------------------------------------------------------- 1 | function Open-IcingaTCPClientConnection() 2 | { 3 | param( 4 | [System.Net.Sockets.TcpClient]$Client = $null, 5 | [Security.Cryptography.X509Certificates.X509Certificate2]$Certificate = $null 6 | ); 7 | 8 | if ($null -eq $Client -Or $null -eq $Certificate) { 9 | return $null; 10 | } 11 | 12 | $Stream = New-IcingaSSLStream -Client $Client -Certificate $Certificate; 13 | 14 | return @{ 15 | 'Client' = $Client; 16 | 'Stream' = $Stream; 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /lib/webserver/Send-IcingaTCPClientMessage.psm1: -------------------------------------------------------------------------------- 1 | function Send-IcingaTCPClientMessage() 2 | { 3 | param( 4 | [Hashtable]$Message = @{ }, 5 | [System.Net.Security.SslStream]$Stream = $null 6 | ); 7 | 8 | if ($null -eq $Message -Or $Message.Count -eq 0 -Or $Message.length -eq 0) { 9 | return; 10 | } 11 | 12 | $Stream.Write($Message.message, 0, $Message.length); 13 | $Stream.Flush(); 14 | } 15 | -------------------------------------------------------------------------------- /lib/webserver/Send-IcingaWebAuthMessage.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Sends a basic auth request back to the client 4 | .DESCRIPTION 5 | Sends a basic auth request back to the client 6 | .FUNCTIONALITY 7 | Sends a basic auth request back to the client 8 | .EXAMPLE 9 | PS>Send-IcingaWebAuthMessage -Connection $Connection; 10 | .PARAMETER Connection 11 | The connection data of the Framework containing the client and stream object 12 | .INPUTS 13 | System.Hashtable 14 | .OUTPUTS 15 | Null 16 | .LINK 17 | https://github.com/Icinga/icinga-powershell-framework 18 | #> 19 | 20 | function Send-IcingaWebAuthMessage() 21 | { 22 | param ( 23 | [Hashtable]$Connection = @{ } 24 | ); 25 | 26 | Send-IcingaTCPClientMessage -Message ( 27 | New-IcingaTCPClientRESTMessage ` 28 | -HTTPResponse ($IcingaHTTPEnums.HTTPResponseType.Unauthorized) ` 29 | -ContentBody 'Please provide your credentials for login.' ` 30 | -BasicAuth 31 | ) -Stream $Connection.Stream; 32 | } 33 | -------------------------------------------------------------------------------- /lib/webserver/Test-IcingaCAInstalledToAuthRoot.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaCAInstalledToAuthRoot() 2 | { 3 | $IcingaCAFile = Join-Path -Path $Env:ProgramData -ChildPath 'icinga2\var\lib\icinga2\certs\ca.crt'; 4 | 5 | if ((Test-Path $IcingaCAFile) -eq $FALSE) { 6 | return $FALSE; 7 | } 8 | 9 | $IcingaCACert = New-Object Security.Cryptography.X509Certificates.X509Certificate2 $IcingaCAFile; 10 | 11 | [bool]$IcingaCAInstalled = $FALSE; 12 | 13 | Get-ChildItem -Recurse -Path 'Cert:\LocalMachine\AuthRoot\' | Where-Object { 14 | if ($_.Thumbprint -eq $IcingaCACert.Thumbprint) { 15 | $IcingaCAInstalled = $TRUE; 16 | } 17 | }; 18 | 19 | $IcingaCACert = $null; 20 | 21 | return $IcingaCAInstalled; 22 | } 23 | -------------------------------------------------------------------------------- /lib/webserver/Test-IcingaForWindowsCertificate.psm1: -------------------------------------------------------------------------------- 1 | function Test-IcingaForWindowsCertificate() 2 | { 3 | $IfWCertificate = Get-IcingaForWindowsCertificate; 4 | $Hostname = Get-IcingaHostname -ReadConstants; 5 | 6 | if ([string]::IsNullOrEmpty($Hostname)) { 7 | Write-IcingaEventMessage -EventId 1700 -Namespace 'Framework'; 8 | return $FALSE; 9 | } 10 | 11 | if ($null -eq $IfWCertificate) { 12 | return $FALSE; 13 | } 14 | 15 | if ($IfWCertificate.Issuer.ToLower() -eq ([string]::Format('cn={0}', $Hostname).ToLower())) { 16 | return $FALSE; 17 | } 18 | 19 | return $TRUE; 20 | } 21 | --------------------------------------------------------------------------------