Skip to content

Commit d0dcc0c

Browse files
committed
Adds Icinga Agent object list wrapper implementation
Fixes #44
1 parent 714827b commit d0dcc0c

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
Set-Content -Path $OutFile -Value $Result;
39+
}
40+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function Get-IcingaAgentObjectList()
2+
{
3+
$Binary = Get-IcingaAgentBinary;
4+
$ObjectList = Start-IcingaProcess -Executable $Binary -Arguments 'object list';
5+
6+
return $ObjectList.Message;
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
Set-Content -Path $Path -Value $ObjectList;
14+
}

0 commit comments

Comments
 (0)