Jun 22, 2026, 1:46 PM
This commit is contained in:
+59
-17
@@ -436,14 +436,21 @@ $tvServers.Add_SelectedItemChanged({
|
||||
# Handle Add Server button
|
||||
$btnAddServer.Add_Click({
|
||||
$server = ""
|
||||
$promptMsg = "Enter SQL Server Instance Name (e.g., localhost, srv\SQLEXPRESS):"
|
||||
$title = "Add Server"
|
||||
if ($script:CurrentView -eq "Splunk") {
|
||||
$promptMsg = "Enter Splunk Host Name (e.g., splunk-host-prod-01):"
|
||||
$title = "Add Splunk Host"
|
||||
}
|
||||
|
||||
try {
|
||||
Add-Type -AssemblyName Microsoft.VisualBasic
|
||||
$server = [Microsoft.VisualBasic.Interaction]::InputBox("Enter SQL Server Instance Name (e.g., localhost, srv\SQLEXPRESS):", "Add Server", "")
|
||||
$server = [Microsoft.VisualBasic.Interaction]::InputBox($promptMsg, $title, "")
|
||||
} catch {
|
||||
# Fallback using current textbox value
|
||||
$server = $txtServerName.Text
|
||||
if ([string]::IsNullOrWhiteSpace($server)) {
|
||||
[System.Windows.MessageBox]::Show("Visual Basic assembly not found. Please type the server name in 'Server Name' textbox first, and then click 'Add Server'.", "Add Server Fallback", "OK", "Information")
|
||||
[System.Windows.MessageBox]::Show("Visual Basic assembly not found. Please type the name in 'Server Name' textbox first, and then click 'Add Server'.", $title, "OK", "Information")
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -451,47 +458,82 @@ $btnAddServer.Add_Click({
|
||||
if ([string]::IsNullOrWhiteSpace($server)) { return }
|
||||
$server = $server.Trim()
|
||||
|
||||
if ($script:CurrentView -eq "SQL") {
|
||||
if ($settings.Servers -contains $server) {
|
||||
[System.Windows.MessageBox]::Show("Server '$server' is already in the list.", "Server Already Exists", "OK", "Information")
|
||||
return
|
||||
}
|
||||
$settings.Servers = $settings.Servers + $server
|
||||
Write-Log "Successfully added server to list: $server"
|
||||
} else {
|
||||
if ($settings.SplunkHosts -contains $server) {
|
||||
[System.Windows.MessageBox]::Show("Splunk Host '$server' is already in the list.", "Host Already Exists", "OK", "Information")
|
||||
return
|
||||
}
|
||||
$settings.SplunkHosts = $settings.SplunkHosts + $server
|
||||
$script:SplunkHosts = $settings.SplunkHosts
|
||||
Write-Log "Successfully added Splunk host: $server"
|
||||
}
|
||||
|
||||
# Save to settings
|
||||
$settings.Servers = $settings.Servers + $server
|
||||
$settings | ConvertTo-Json | Set-Content $configPath
|
||||
|
||||
Refresh-ServerTree
|
||||
Write-Log "Successfully added server to list: $server"
|
||||
})
|
||||
|
||||
# Handle Remove Server button
|
||||
$btnRemoveServer.Add_Click({
|
||||
$selectedItem = $tvServers.SelectedItem
|
||||
if ($null -eq $selectedItem -or $selectedItem.Tag -eq "__ROOT__") {
|
||||
[System.Windows.MessageBox]::Show("Please select a server node in the tree to remove.", "Select Server", "OK", "Warning")
|
||||
$msg = if ($script:CurrentView -eq "SQL") { "Please select a server node in the tree to remove." } else { "Please select a Splunk Host node in the tree to remove." }
|
||||
[System.Windows.MessageBox]::Show($msg, "Select Node", "OK", "Warning")
|
||||
return
|
||||
}
|
||||
|
||||
$serverName = $selectedItem.Tag
|
||||
# Verify that we selected a server node (it has a string Tag and is in settings.Servers)
|
||||
if ($serverName -is [string] -and ($settings.Servers -contains $serverName)) {
|
||||
if ($serverName -is [string]) {
|
||||
if ($script:CurrentView -eq "SQL" -and ($settings.Servers -contains $serverName)) {
|
||||
$confirm = [System.Windows.MessageBox]::Show("Are you sure you want to remove '$serverName' from the list?", "Confirm Server Removal", "YesNo", "Question")
|
||||
if ($confirm -eq "Yes") {
|
||||
$settings.Servers = $settings.Servers | Where-Object { $_ -ne $serverName }
|
||||
$settings | ConvertTo-Json | Set-Content $configPath
|
||||
|
||||
Refresh-ServerTree
|
||||
Write-Log "Removed server from list: $serverName"
|
||||
}
|
||||
} else { return }
|
||||
} elseif ($script:CurrentView -eq "Splunk" -and ($settings.SplunkHosts -contains $serverName)) {
|
||||
$confirm = [System.Windows.MessageBox]::Show("Are you sure you want to remove '$serverName' from the list?", "Confirm Host Removal", "YesNo", "Question")
|
||||
if ($confirm -eq "Yes") {
|
||||
$settings.SplunkHosts = $settings.SplunkHosts | Where-Object { $_ -ne $serverName }
|
||||
$script:SplunkHosts = $settings.SplunkHosts
|
||||
Write-Log "Removed Splunk host from list: $serverName"
|
||||
} else { return }
|
||||
} else {
|
||||
[System.Windows.MessageBox]::Show("Only server nodes can be removed.", "Invalid Selection", "OK", "Warning")
|
||||
[System.Windows.MessageBox]::Show("Only host/server nodes can be removed.", "Invalid Selection", "OK", "Warning")
|
||||
return
|
||||
}
|
||||
|
||||
# Save to settings
|
||||
$settings | ConvertTo-Json | Set-Content $configPath
|
||||
Refresh-ServerTree
|
||||
} else {
|
||||
[System.Windows.MessageBox]::Show("Only server/host nodes can be removed.", "Invalid Selection", "OK", "Warning")
|
||||
}
|
||||
})
|
||||
|
||||
# Handle Main -> Host Slunk menu click
|
||||
$menuHostSlunk.Add_Click({
|
||||
Write-Log "Main -> Host Slunk menu item clicked."
|
||||
[System.Windows.MessageBox]::Show("Host Slunk menu option selected.", "Host Slunk", "OK", "Information")
|
||||
# Handle Main -> SQL Servers menu click
|
||||
$menuSqlServers.Add_Click({
|
||||
$script:CurrentView = "SQL"
|
||||
$grpDirectory.Header = "SQL Server Directory"
|
||||
Write-Log "Switched view to SQL Server Directory."
|
||||
Refresh-ServerTree
|
||||
})
|
||||
|
||||
# Handle Main -> Host Splunk menu click
|
||||
$menuHostSplunk.Add_Click({
|
||||
$script:CurrentView = "Splunk"
|
||||
$grpDirectory.Header = "Splunk Hosts Directory"
|
||||
Write-Log "Switched view to Splunk Observability Cloud."
|
||||
|
||||
# Fetch Splunk Hosts dynamically from API (or fallback/demo)
|
||||
$script:SplunkHosts = Get-SplunkAPIHosts
|
||||
Refresh-ServerTree
|
||||
})
|
||||
|
||||
# 5. Connection logic
|
||||
|
||||
Reference in New Issue
Block a user