mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
parent
714827bc0a
commit
d0dcc0c128
3 changed files with 61 additions and 0 deletions
40
lib/core/icingaagent/finders/Find-IcingaAgentObjects.psm1
Normal file
40
lib/core/icingaagent/finders/Find-IcingaAgentObjects.psm1
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
function Find-IcingaAgentObjects()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
$Find = @(),
|
||||||
|
$OutFile = $null
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($Find.Length -eq 0) {
|
||||||
|
throw 'Please specify content you want to look for';
|
||||||
|
}
|
||||||
|
|
||||||
|
[array]$ObjectList = (Get-IcingaAgentObjectList).Split("`r`n");
|
||||||
|
[int]$lineIndex = 0;
|
||||||
|
[array]$Result = @();
|
||||||
|
|
||||||
|
foreach ($line in $ObjectList) {
|
||||||
|
if ([string]::IsNullOrEmpty($line)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($entry in $Find) {
|
||||||
|
if ($line -like $entry) {
|
||||||
|
[string]$ResultLine = [string]::Format(
|
||||||
|
'Line #{0} => "{1}"',
|
||||||
|
$lineIndex,
|
||||||
|
$line
|
||||||
|
);
|
||||||
|
$Result += $ResultLine;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$lineIndex += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($OutFile)) {
|
||||||
|
Write-Output $Result;
|
||||||
|
} else {
|
||||||
|
Set-Content -Path $OutFile -Value $Result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
function Get-IcingaAgentObjectList()
|
||||||
|
{
|
||||||
|
$Binary = Get-IcingaAgentBinary;
|
||||||
|
$ObjectList = Start-IcingaProcess -Executable $Binary -Arguments 'object list';
|
||||||
|
|
||||||
|
return $ObjectList.Message;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
function Write-IcingaAgentObjectList()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[string]$Path
|
||||||
|
);
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($Path)) {
|
||||||
|
throw 'Please specify a path to write the Icinga objects to';
|
||||||
|
}
|
||||||
|
|
||||||
|
$ObjectList = Get-IcingaAgentObjectList;
|
||||||
|
|
||||||
|
Set-Content -Path $Path -Value $ObjectList;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue