Added support to register checks to run in background

This commit is contained in:
Lord Hepipud 2019-10-05 22:02:17 +02:00
parent 6d15aa47a0
commit 084453e722
3 changed files with 53 additions and 0 deletions

View file

@ -0,0 +1,19 @@
function Get-IcingaRegisteredServiceChecks()
{
$Services = Get-IcingaPowerShellConfig -Path 'BackgroundDaemon.RegisteredServices';
[hashtable]$Output = @{};
foreach ($service in $Services.PSObject.Properties) {
$Content = @{
'Id' = $service.Name;
'CheckCommand' = $service.Value.CheckCommand;
'Arguments' = $service.Value.Arguments;
'Interval' = $service.Value.Interval;
'TimeIndexes' = $service.Value.TimeIndexes;
};
$Output.Add($service.Name, $Content);
}
return $Output;
}

View file

@ -0,0 +1,23 @@
function Register-IcingaServiceCheck()
{
param(
[string]$CheckCommand,
[hashtable]$Arguments,
[int]$Interval = 60,
[array]$TimeIndexes = @()
);
if ([string]::IsNullOrEmpty($CheckCommand)) {
throw 'Please specify a CheckCommand';
}
$Hash = Get-StringSha1 ([string]::Format('{0} {1}', $CheckCommand, ($Arguments | Out-String)));
$Path = [string]::Format('BackgroundDaemon.RegisteredServices.{0}', $Hash);
Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.CheckCommand', $Path)) -Value $CheckCommand;
Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.Arguments', $Path)) -Value $Arguments;
Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.Interval', $Path)) -Value $Interval;
Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.TimeIndexes', $Path)) -Value $TimeIndexes;
Write-Host 'Icinga Service Check has been configured';
}

View file

@ -0,0 +1,11 @@
function Show-IcingaRegisteredServiceChecks()
{
$Services = Get-IcingaRegisteredServiceChecks;
foreach ($service in $Services.Keys) {
Write-Host ([string]::Format('Service Id: {0}', $service));
Write-Host (
$Services[$service] | Out-String
);
}
}