-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindows-install-sumologic.ps1
53 lines (42 loc) · 1.93 KB
/
windows-install-sumologic.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
# Install and register sumologic collector via token with specified default sources.json
# https://help.sumologic.com/03Send-Data/Installed-Collectors/05Reference-Information-for-Collector-Installation/04Add_a_Collector_to_a_Windows_Machine_Image
# Usage: ./windows-install-sumologic.ps1 -t <my secret token>
# Uninstall: C:\Program Files\Sumo Logic Collector\uninstall.exe -q -console
# Param(
# [Parameter(Mandatory=$true)]
# [string]$token,
# [string]$hostname = ($env:computerName).tolower()
# )
$ErrorActionPreference = "Stop"
$install_dir="C:\Sum"
$hostname=((hostname).tolower())
#$token="S0RlZlpnMmU0NVVWdmRyeWJHY0ppM1NHSTR0M0xPUU1odHRwczovL2NvbGxlY3RvcnMudXMyLnN1bW9sb2dpYy5jb20="
$token="eFptemZiWVRVUk1CN000TnhDUTdQcUJNSE5pRXc4NzFodHRwczovL2NvbGxlY3RvcnMudXMyLnN1bW9sb2dpYy5jb20="
function install() {
if(!(test-path $install_dir)){
New-Item -ItemType Directory -Force -Path $install_dir
}
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Tls12'
Invoke-WebRequest 'https://collectors.us2.sumologic.com/rest/download/win64' -outfile 'C:\Windows\Temp\SumoCollector.exe'
Invoke-WebRequest 'https://raw.githubusercontent.com/jeremybusk/sumologic/master/windows_default_sources.json' -outfile "$install_dir\sources.json"
C:\Windows\Temp\SumoCollector.exe -console -q -Vclobber=True "-Vsumo.token_and_url=$token" "-Vcollector.name=$hostname_events" "-Vsources=$install_dir\"
}
# Tests
function test_sumo_collector_service_not_running() {
if ((get-service -name sumo-collector).status -ne "Running") {
write-host "ERROR: Serivce is not running. Install appears to have failed."
exit 1
}
}
function test_not_running(){
# if ((get-service -name sumo-collector).status -eq "Running") {
if (get-service | findstr -i sumo-collector) {
write-host "ERROR: Serivce is already installed and running. Exiting install."
exit 1
}
}
function main() {
test_not_running
install
}
main