Skip to content

Instantly share code, notes, and snippets.

@halr9000
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save halr9000/28000e6767199e436e97 to your computer and use it in GitHub Desktop.

Select an option

Save halr9000/28000e6767199e436e97 to your computer and use it in GitHub Desktop.
Splunk Stream helper module
<#
.Synopsis
Returns XML object for local stream forwarder configuration if it exists, or optionally, default configuration.
.DESCRIPTION
Long description
.EXAMPLE
Get-StreamForwarderConfigXml -DefaultConfig
xml CmConfig
--- --------
version="1.0" encoding="UTF-8" CmConfig
#>
function Get-StreamForwarderConfigXml {
[CmdletBinding()]
[OutputType([System.Xml.XmlDocument])]
param (
$SplunkHome = $env:SPLUNK_HOME,
[switch]$DefaultConfig
)
$streamTA = 'Splunk_TA_stream'
if ( !$SplunkHome ) {
$SplunkHome = Join-Path -Path $env:ProgramFiles -ChildPath "Splunk" -Resolve # Resolve flag throws exception if path doesn't exist
}
$StreamTAPath = Join-Path -Path $SplunkHome -ChildPath ( "etc\apps\" + $streamTA ) -Resolve
# Does a local streamfwd.xml file exist?
if ( Test-Path ( $StreamTAPath + "\local\streamfwd.xml" ) ) {
Write-Verbose "Found local streamfwd.xml"
[xml]$out = Get-Content ( $StreamTAPath + "\local\streamfwd.xml" )
} elseif ( $DefaultConfig ) {
Write-Verbose "No local streamfwd.xml found"
[xml]$out = Get-Content ( $StreamTAPath + "\default\streamfwd.xml" )
}
# Write the output to stdout so that user can do what they like with it
Write-Output $out
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment