-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKibanaConfiguration.ps1
68 lines (51 loc) · 1.77 KB
/
KibanaConfiguration.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
param(
[string]$ConfigFilePath = 'C:\Elk\kibana\config\kibana.yml',
[string]$ServerHost = "0.0.0.0"
)
function Update-KibanaConfiguration
{
Param(
[string]$ConfigFilePath,
[string]$ServerHost
)
function Set-ConfigurationEntry {
Param (
[string[]][ref]$FileLines,
[string]$MatchRegEx,
[string]$Value
)
$ConfigUpdate = $false
for($i = 0; $i -lt $FileLines.Count; $i++) {
$Line = $FileLines[$i]
if ($Line -match $MatchRegEx) {
Write-Host "Updating entry $Value"
$FileLines[$i] = $Value
$ConfigUpdate = $true
break
}
}
if (-not $ConfigUpdate) {
Write-Host "Appending new entry $Value"
# The array is of fixed size, so just append text to the last line
$FileLines[$FileLines.Count -1] += "`n$Value"
}
}
Write-Host $MyInvocation.MyCommand
if (-Not $ConfigFilePath -Or -Not (Test-Path $ConfigFilePath -PathType Leaf)) {
Write-Host "Failed to locate elasticsearch configuration file: $ConfigFilePath."
throw "Failed to locate elasticsearch configuration file: $ConfigFilePath."
}
[string[]]$FileLines = (Get-Content $ConfigFilePath)
$ServerHost = "server.host: $ServerHost" -replace '\\','/'
Set-ConfigurationEntry -FileLines ([ref]$FileLines) -MatchRegEx "^\s*server\.host\s*:\s*" -Value $ServerHost
Set-Content $ConfigFilePath $FileLines
Write-Host "$($MyInvocation.MyCommand) done."
}
try {
Update-KibanaConfiguration -ConfigFilePath $ConfigFilePath -ServerHost $ServerHost
exit 0
}
Catch {
Write-Host $_.Exception.Message
exit 1
}