From defdb38761da100e464b3530532a139a6a7793c4 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Wed, 25 Sep 2019 20:18:27 +0200 Subject: [PATCH] Added more details for new Check Plugin Command as starting point --- lib/core/tools/New-IcingaCheckCommand.psm1 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/core/tools/New-IcingaCheckCommand.psm1 b/lib/core/tools/New-IcingaCheckCommand.psm1 index 8fea58e..56c8a92 100644 --- a/lib/core/tools/New-IcingaCheckCommand.psm1 +++ b/lib/core/tools/New-IcingaCheckCommand.psm1 @@ -6,7 +6,7 @@ function New-IcingaCheckCommand() 'Warning', 'Critical', '[switch]NoPerfData', - 'Verbose' + '[int]Verbose' ), [array]$ImportLib = @() ); @@ -72,6 +72,14 @@ function New-IcingaCheckCommand() } Add-Content -Path $ScriptFile -Value ""; + Add-Content -Path $ScriptFile -Value ' <# Icinga Basic Check-Plugin Template. Below you will find an example structure. #>'; + Add-Content -Path $ScriptFile -Value ([string]::Format(' $CheckPackage = New-IcingaCheckPackage -Name {0}New Package{0} -OperatorAnd -Verbose $Verbose;', "'")); + Add-Content -Path $ScriptFile -Value ([string]::Format(' $IcingaCheck = New-IcingaCheck -Name {0}New Check{0} -Value 10 -Unit {0}%{0}', "'")); + Add-Content -Path $ScriptFile -Value ([string]::Format(' $IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;', "'")); + Add-Content -Path $ScriptFile -Value ([string]::Format(' $CheckPackage.AddCheck($IcingaCheck);', "'")); + Add-Content -Path $ScriptFile -Value ""; + Add-Content -Path $ScriptFile -Value ([string]::Format(' return (New-IcingaCheckresult -Check $CheckPackage -NoPerfData $NoPerfData -Compile);', "'")); + Add-Content -Path $ScriptFile -Value "}"; Write-Host ([string]::Format('The Check-Command "{0}" was successfully added.', $CommandName)); @@ -80,6 +88,8 @@ function New-IcingaCheckCommand() $DefaultEditor = (Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.psm1\OpenWithList' -Name a).a; $DefaultEditor = $DefaultEditor.Replace('.exe', ''); + Import-Module $ScriptFile -Global; + if ([string]::IsNullOrEmpty($DefaultEditor) -eq $FALSE -And ((Get-Command $DefaultEditor -ErrorAction SilentlyContinue) -eq $null) -And ((Test-Path $DefaultEditor) -eq $FALSE)) { Write-Host 'No default editor for .psm1 files found. Specify a default editor to automaticly open the newly generated check plugin.'; return;