Skip to content

Commit

Permalink
Support EC2 for windows - first release
Browse files Browse the repository at this point in the history
- Create relevant powershell scripts
- Update agent manifest
- Create a dir for windows EC2
  • Loading branch information
ralongit committed Oct 3, 2023
1 parent 1b9f6b4 commit cdf5687
Show file tree
Hide file tree
Showing 18 changed files with 2,062 additions and 0 deletions.
59 changes: 59 additions & 0 deletions agent-test-windows.rdp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
smart sizing:i:1
armpath:s:
enablerdsaadauth:i:0
targetisaadjoined:i:0
hubdiscoverygeourl:s:
redirected video capture encoding quality:i:0
camerastoredirect:s:
gatewaybrokeringtype:i:0
use redirection server name:i:0
alternate shell:s:
disable themes:i:0
geo:s:
disable cursor setting:i:1
remoteapplicationname:s:
resourceprovider:s:
disable menu anims:i:1
remoteapplicationcmdline:s:
promptcredentialonce:i:0
gatewaycertificatelogonauthority:s:
audiocapturemode:i:0
prompt for credentials on client:i:0
allowed security protocols:s:*
gatewayhostname:s:
remoteapplicationprogram:s:
gatewayusagemethod:i:2
screen mode id:i:2
use multimon:i:0
authentication level:i:2
desktopwidth:i:0
desktopheight:i:0
redirectsmartcards:i:1
redirectclipboard:i:1
forcehidpioptimizations:i:0
full address:s:ec2-15-229-47-49.sa-east-1.compute.amazonaws.com
drivestoredirect:s:
loadbalanceinfo:s:
networkautodetect:i:1
enablecredsspsupport:i:1
redirectprinters:i:1
autoreconnection enabled:i:1
session bpp:i:32
administrative session:i:1
audiomode:i:0
bandwidthautodetect:i:1
authoring tool:s:
connection type:i:7
remoteapplicationmode:i:0
disable full window drag:i:0
gatewayusername:s:
dynamic resolution:i:1
shell working directory:s:
wvd endpoint pool:s:
remoteapplicationappid:s:
username:s:Administrator
allow font smoothing:i:1
connect to console:i:1
disable wallpaper:i:0
gatewayaccesstoken:s:
auto connect:i:1
74 changes: 74 additions & 0 deletions configs/3-4-aws-ec2-windows-system.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"name": "AWS",
"logo": "https://dytvr9ot2sszz.cloudfront.net/logz-docs/shipper-logos/aws.svg",
"label": "AWS",
"description": "",
"hint": "Select the environment where you want to deploy Logz.io Telemetry Collector.",
"subtypes": [
{
"name": "EC2",
"logo": "https://dytvr9ot2sszz.cloudfront.net/logz-docs/shipper-logos/aws.svg",
"label": "EC2 Monitoring",
"description": "Windows Logs & Metrics",
"hint": "EC2 with Windows.",
"supportedOs": [
"Windows"
],
"datasources": [
{
"name": "System",
"logo": "https://dytvr9ot2sszz.cloudfront.net/logz-docs/shipper-logos/local_host.png",
"label": "System",
"description": "Logz.io Uses OpenTelemetry to monitor your EC2.",
"telemetries": [
{
"type": "LOG_ANALYTICS",
"hint": "Switch the toggle on if you want Logz.io Telemetry Collector to collect logs from your EC2.",
"otel": {
"receivers": [
"filelog"
],
"processors": [
"resourcedetection_system",
"resourcedetection_ec2"
]
},
"params": [
{
"type": "path-list",
"name": "logSources",
"label": "Location of your logs",
"required": true,
"description": "The paths of log files to collect.",
"hint": "By adding paths, OpenTelemetry will read logs from these log paths and will export them to Logz.io.",
"value": [
"C:\\Users\\my_example\\Documents\\*.log"
]
}
]
},
{
"type": "METRICS",
"hint": "Switch the toggle on if you want Logz.io Telemetry Collector to collect metrics from your EC2.",
"otel": {
"receivers": [
"hostmetrics"
],
"processors": [
"resourcedetection_system",
"resourcedetection_ec2",
"resource_agent",
"filter"
]
},
"params": [],
"dashboards": [
"2oLvCy5p914pM9m5pLoD6u"
]
}
]
}
]
}
]
}
26 changes: 26 additions & 0 deletions datasources/windows/aws/ec2/installer/agent_info.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#################################################################################################################################
################################################## WINDOWS Agent Info Script ####################################################
#################################################################################################################################

Write-Host
Write-Host '###################'
Write-Host '### ' -NoNewline
Write-Host 'Information' -ForegroundColor Magenta -NoNewline
Write-Host ' ###'
Write-Host '###################'
Write-Host 'Collector Binary' -ForegroundColor Magenta -NoNewLine
Write-Host ": $script:OtelCollectorExe"
Write-Host 'Collector Config' -ForegroundColor Magenta -NoNewLine
Write-Host ": $script:OtelConfig"
Write-Host 'Logz.io Agent Logs' -ForegroundColor Magenta -NoNewLine
Write-Host ": $script:AgentLogFile"
Write-Host 'Start Service' -ForegroundColor Magenta -NoNewLine
Write-Host ": Start-Service -Name $script:LogzioOtelCollectorServiceName"
Write-Host 'Stop Service' -ForegroundColor Magenta -NoNewLine
Write-Host ": Stop-Service -Name $script:LogzioOtelCollectorServiceName"
Write-Host 'Delete Service' -ForegroundColor Magenta -NoNewLine
Write-Host ": sc.exe DELETE $script:LogzioOtelCollectorServiceName (stop the service before deleting it)"
Write-Host 'Show Service' -ForegroundColor Magenta -NoNewLine
Write-Host ": Get-Service -Name $script:LogzioOtelCollectorServiceName"
Write-Host 'Show Service Logs' -ForegroundColor Magenta -NoNewLine
Write-Host ": eventvwr.msc ('Windows Logs'->'Application' all logs with source '$script:LogzioOtelCollectorServiceName')"
204 changes: 204 additions & 0 deletions datasources/windows/aws/ec2/installer/functions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
#################################################################################################################################
############################################# WINDOWS Subtype Installer Functions ###############################################
#################################################################################################################################

# Checks if Logz.io OTEL collector service exists
# Input:
# ---
# Output:
# IsServiceExist - Tells if Logz.io OTEL collector service exists (true/false)
function Get-IsLogzioOtelCollectorServiceExist {
$local:FuncName = $MyInvocation.MyCommand.Name

$local:Message = 'Checking if Logz.io OTEL collector service exists ...'
Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepPreInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-Log $LogLevelDebug $Message

$local:Service = Get-Service -Name $script:LogzioOtelCollectorServiceName -ErrorAction SilentlyContinue
if ([string]::IsNullOrEmpty($Service)) {
$Message = "'$script:LogzioOtelCollectorServiceName' service does not exist"
Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepPreInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-Log $script:LogLevelDebug $Message

Write-TaskPostRun "`$script:IsServiceExist = `$false"
return
}

$Message = "'$script:LogzioOtelCollectorServiceName' service is already exists"
Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepPreInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-Log $script:LogLevelDebug $Message

Write-TaskPostRun "`$script:IsServiceExist = `$true"
}

# Deletes Logz.io OTEL collector service
# Input:
# ---
# Output:
# ---
function Remove-LogzioOtelCollectorService {
$local:ExitCode = 1
$local:FuncName = $MyInvocation.MyCommand.Name

$local:Message = 'Removing Logz.io OTEL collector service ...'
Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepPreInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-Log $script:LogLevelDebug $Message

try {
Stop-Service -Name $script:LogzioOtelCollectorServiceName -ErrorAction Stop | Out-Null
}
catch {
$Message = "installer.ps1 ($ExitCode): error stopping '$script:LogzioOtelCollectorServiceName' service: $_"
Send-LogToLogzio $script:LogLevelError $Message $script:LogStepPreInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-TaskPostRun "Write-Error `"$Message`""
}

sc.exe DELETE $script:LogzioOtelCollectorServiceName 2>$script:TaskErrorFile | Out-Null
if ($LASTEXITCODE -ne 0) {
$Message = "installer.ps1 ($ExitCode): error deleting '$script:LogzioOtelCollectorServiceName' service: $(Get-TaskErrorMessage)"
Send-LogToLogzio $script:LogLevelError $Message $script:LogStepPreInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-TaskPostRun "Write-Error `"$Message`""

return $ExitCode
}
}

# Downloads OTEL collector exe
# Input:
# ---
# Output:
# OTEL collector exe in Logz.io temp directory
function Get-OtelCollectorExe {
$local:ExitCode = 2
$local:FuncName = $MyInvocation.MyCommand.Name

$local:Message = 'Downloading OTEL collector exe ...'
Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepPreInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-Log $script:LogLevelDebug $Message

try {
Invoke-WebRequest -Uri $script:OtelCollectorUrlDownload -OutFile "$script:LogzioTempDir\otelcol-logzio.zip" | Out-Null
}
catch {
$Message = "installer.ps1 ($ExitCode): error downloading OTEL collector zip: $_"
Send-LogToLogzio $script:LogLevelError $Message $script:LogStepPreInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-TaskPostRun "Write-Error `"$Message`""

return $ExitCode
}

try {
Expand-Archive -LiteralPath "$script:LogzioTempDir\otelcol-logzio.zip" -DestinationPath $script:LogzioTempDir -Force | Out-Null
}
catch {
$Message = "installer.ps1 ($ExitCode): error extracting files from zip: $_"
Send-LogToLogzio $script:LogLevelError $Message $script:LogStepPreInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-TaskPostRun "Write-Error `"$Message`""

return $ExitCode
}
}

# Creates Logz.io AppData subdirectory
# Input:
# ---
# Output:
# ---
function New-LogzioAppDataSubDir {
$local:ExitCode = 3
$local:FuncName = $MyInvocation.MyCommand.Name

$local:Message = 'Creating Logz.io AppData subdirectory ...'
Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-Log $script:LogLevelDebug $Message

try {
New-Item -Path $script:LogzioOtelCollectorDir -ItemType Directory -Force -ErrorAction Stop | Out-Null
}
catch {
$Message = "installer.ps1 ($ExitCode): error creating Logz.io OTEL collector directory: $_"
Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-TaskPostRun "Write-Error `"$Message`""

return $ExitCode
}
}

# Copies OTEL files to AppData subdirectory
# Input:
# ---
# Output:
# ---
function Copy-LogzioOtelFilesToAppDataSubDir {
$local:ExitCode = 4
$local:FuncName = $MyInvocation.MyCommand.Name

$local:Message = 'Copying Logz.io OTEL files to AppData subdirectory ...'
Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-Log $script:LogLevelDebug $Message

try {
Copy-Item -Path "$script:LogzioTempDir\$script:OtelCollectorExeName" -Destination $script:LogzioOtelCollectorDir -Force -ErrorAction Stop
Copy-Item -Path "$script:OtelResourcesDir\$script:OtelConfigName" -Destination $script:LogzioOtelCollectorDir -Force -ErrorAction Stop
}
catch {
$Message = "installer.ps1 ($ExitCode): error copying OTEL files to AppData subdirectory: $_"
Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-TaskPostRun "Write-Error `"$Message`""

return $ExitCode
}
}

# Runs Logz.io OTEL collector service
# Input:
# ---
# Output:
# ---
function Invoke-LogzioOtelCollectorService {
$local:ExitCode = 5
$local:FuncName = $MyInvocation.MyCommand.Name

$local:Message = 'Running Logz.io OTEL collector service ...'
Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-Log $script:LogLevelDebug $Message
$Message = Get-Content -Path $script:OtelConfig
Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-Log $script:LogLevelDebug $Message

try {
New-Service -Name $script:LogzioOtelCollectorServiceName -BinaryPathName "$script:OtelCollectorExe --config $script:OtelConfig" -Description "Collects localhost logs/metrics and sends them to Logz.io." -ErrorAction Stop | Out-Null
}
catch {
$Message = "installer.ps1 ($ExitCode): error creating '$script:LogzioOtelCollectorServiceName' service: $_"
Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-TaskPostRun "Write-Error `"$Message`""

sc.exe DELETE LogzioOTELCollector 2>$script:TaskErrorFile | Out-Null
if ($LASTEXITCODE -ne 0) {
$Message = "installer.ps1 ($ExitCode): error deleting '$script:LogzioOtelCollectorServiceName' service: $(Get-TaskErrorMessage)"
Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-TaskPostRun "Write-Warning `"$Message`""
}

return $ExitCode
}

try {
Start-Service -Name $script:LogzioOtelCollectorServiceName -ErrorAction Stop | Out-Null
}
catch {
$Message = "installer.ps1 ($ExitCode): error starting '$script:LogzioOtelCollectorServiceName' service: $_"
Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-TaskPostRun "Write-Error `"$Message`""

sc.exe DELETE LogzioOTELCollector 2>$script:TaskErrorFile | Out-Null
if ($LASTEXITCODE -ne 0) {
$Message = "installer.ps1 ($ExitCode): error deleting '$script:LogzioOtelCollectorServiceName' service: $(Get-TaskErrorMessage)"
Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype
Write-TaskPostRun "Write-Warning `"$Message`""
}

return $ExitCode
}
}
Loading

0 comments on commit cdf5687

Please sign in to comment.