mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 15:19:58 -05:00
Added support to register checks to run in background
This commit is contained in:
parent
7d6b9016e4
commit
a59ae37b76
3 changed files with 53 additions and 0 deletions
19
lib/daemon/Get-IcingaRegisteredServiceChecks.psm1
Normal file
19
lib/daemon/Get-IcingaRegisteredServiceChecks.psm1
Normal 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;
|
||||
}
|
||||
23
lib/daemon/Register-IcingaServiceCheck.psm1
Normal file
23
lib/daemon/Register-IcingaServiceCheck.psm1
Normal 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';
|
||||
}
|
||||
11
lib/daemon/Show-IcingaRegisteredServiceChecks.psm1
Normal file
11
lib/daemon/Show-IcingaRegisteredServiceChecks.psm1
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue