Skip to content

Instantly share code, notes, and snippets.

@oazabir
Created April 19, 2016 16:37
Show Gist options
  • Save oazabir/cf43e76ad8ebfa15c8dbb92ed41c7877 to your computer and use it in GitHub Desktop.
Save oazabir/cf43e76ad8ebfa15c8dbb92ed41c7877 to your computer and use it in GitHub Desktop.
$elasticsearch="https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/zip/elasticsearch/2.3.1/elasticsearch-2.3.1.zip"
$logstash="https://download.elastic.co/logstash/logstash/logstash-2.3.1.zip"
$filebeat="https://download.elastic.co/beats/filebeat/filebeat-1.2.1-windows.zip"
$grafana="https://grafanarel.s3.amazonaws.com/winbuilds/dist/grafana-3.0.0-beta5.windows-x64.zip"
$logstashconf="https://gist.githubusercontent.com/oazabir/9b9cfc8795581ae5ec07e40245a86081/raw/6a6016a3902e4f2f964a266592a5799aebe3469c/logstash.yml"
$logstashtemplate="https://gist.githubusercontent.com/oazabir/000bde7bc3c8567ea665a0b59c0d86ca/raw/eab8f426b70ff131a40eb4a0ca85429688721901/logstash-template.json"
$filebeatconf="https://gist.githubusercontent.com/oazabir/8046a3c33b61a15d0661f85fae60e245/raw/9cf520fc61c8f1318ef27703c2c24f7c2ffe2442/filebeat.yml"
$grafanatemplate="https://gist.githubusercontent.com/oazabir/6a3021d8a08fd60a43a48a41cf721742/raw/2806b32d6eb35093f6897c3900ff5a3365bb93ee/GrafanaWebLogTemplate.json"
if (-not (Test-Path "Elastic")) { ni Elastic -ItemType "Directory" }
cd Elastic | Out-Null
$path=(pwd).ToString()
function Expand-ZIPFile($file, $destination)
{
Write-Host "Extracting $file -> $destination ...";
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
foreach($item in $zip.items())
{
$shell.Namespace($destination).copyhere($item)
}
}
function DownloadAndUnzip($url, $path, $file) {
Write-Host "Downloading $url -> $path ...";
$fullpath = Join-Path $path $file;
Invoke-WebRequest -Uri $url -OutFile $fullpath
Expand-ZIPFile $fullpath $path
}
DownloadAndUnzip $filebeat $path "filebeat.zip"
DownloadAndUnzip $grafana $path "grafana.zip"
DownloadAndUnzip $logstash $path "logstash.zip"
DownloadAndUnzip $elasticsearch $path "elasticsearch.zip"
Write-Host "All Downloaded."
Write-Host "Start ElasticSearch..."
cd elasticsearch*
start cmd "/c .\bin\elasticsearch.bat"
cd ..
sleep 5
Write-Host "Start Logstash..."
cd logstash-*
if (-not (Test-Path "conf")) { ni conf -ItemType "Directory" }
cd conf
Invoke-WebRequest -Uri $logstashconf -OutFile logstash.yml
Invoke-WebRequest -Uri $logstashtemplate -OutFile logstash-template.json
cd ..
start cmd "/c .\bin\logstash.bat -f .\conf\logstash.yml"
cd ..
sleep 5
Write-Host "Start Grafana..."
cd grafana*
start cmd "/c bin\grafana-server.exe"
cd ..
sleep 5
Write-Host "Start Filebeat..."
cd filebeat*
Invoke-WebRequest -Uri $filebeatconf -OutFile filebeat_original.yml
# Get IIS web log folders
$SystemDrive = [system.environment]::getenvironmentvariable("SystemDrive")
$logfolder = resolve-path "$SystemDrive\inetpub\logs\LogFiles\"
$iisLogFolders=@()
gci $logfolder | %{ $iisLogFolders += $_.FullName + "\*" }
if ($iisLogFolders.Length -eq 0) { Write-Host "*** There is no IIS Folder configured. You need an IIS website. ***" }
# put them all on filebeat.yml
$filebeatconfig = [IO.File]::ReadAllText((Join-Path (pwd) "filebeat_original.yml"));
$padding = " - "
$logpaths = [string]::Join([Environment]::NewLine + $padding, $iisLogFolders);
$pos = $filebeatconfig.IndexOf("paths:");
$filebeatconfig = $filebeatconfig.Substring(1, $pos+5) + [Environment]::NewLine + $padding + $logpaths + $filebeatconfig.Substring($pos+6);
[IO.File]::WriteAllText((Join-Path (pwd) "filebeat.yml"), $filebeatconfig);
start cmd "/c filebeat.exe"
cd ..
sleep 5
$templatePath = Join-Path (pwd) "GrafanaWebLogTemplate.json"
Invoke-WebRequest $grafanatemplate -OutFile $templatePath
Write-Host "########### README CAREFULLY ##########"
Write-Host "I am about to launch Grafana. This is what you need to do:"
Write-Host "1. Login to grafana using admin/admin"
Write-Host "2. Create a new Data source exactly named 'Elasticsearch Logstash'"
Write-Host " Name: Elasticsearch Logstash"
Write-Host " Type: ElasticSearch"
Write-Host " Url: http://127.0.0.1:9200"
Write-Host " Pattern: Daily"
Write-Host " Index name: (It will come automatically when you select pattern)"
Write-Host " Version: 2.x"
Write-Host " Click Add"
Write-Host "3. Click on Dashboards. Click Import. Import the file: $templatePath"
Sleep 5
pause
start "http://127.0.0.1:3000"
Write-Host "All done."
# Cleanup - remove this!
#cd ..
#rm -force $path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment