fffff
This commit is contained in:
@@ -96,30 +96,7 @@ if (`$local -ne `$remote) {
|
|||||||
"@
|
"@
|
||||||
Set-Content -Path $SyncScriptPath -Value $SyncScriptContent -Encoding UTF8
|
Set-Content -Path $SyncScriptPath -Value $SyncScriptContent -Encoding UTF8
|
||||||
|
|
||||||
# =========================
|
|
||||||
# 4. Script de Boot (Tu lógica de Loki)
|
|
||||||
# =========================
|
|
||||||
$BootScriptContent = @'
|
|
||||||
Start-Sleep -Seconds 180
|
|
||||||
$event = Get-WinEvent -LogName "Microsoft-Windows-Diagnostics-Performance/Operational" -MaxEvents 20 | Where-Object { $_.Id -eq 100 } | Select-Object -First 1
|
|
||||||
if ($null -eq $event) { exit 0 }
|
|
||||||
|
|
||||||
$timestamp = [string](([DateTimeOffset]$event.TimeCreated).ToUnixTimeMilliseconds() * 1000000)
|
|
||||||
[xml]$xml = $event.ToXml()
|
|
||||||
$data = @{}
|
|
||||||
foreach ($d in $xml.Event.EventData.Data) { $data[[string]$d.Name] = [string]$d.'#text' }
|
|
||||||
|
|
||||||
$logObject = [ordered]@{
|
|
||||||
machine_name = $env:COMPUTERNAME
|
|
||||||
boot_time_ms = $data["BootTime"]
|
|
||||||
message = $event.Message
|
|
||||||
}
|
|
||||||
$logLine = $logObject | ConvertTo-Json -Compress
|
|
||||||
$payload = "{ `"streams`": [ { `"stream`": { `"job`": `"windows_boot_custom`", `"computer`": `"$($env:COMPUTERNAME)`" }, `"values`": [ [ `"$timestamp`", `"$($logLine.Replace('"', '\"'))`" ] ] } ] }"
|
|
||||||
|
|
||||||
Invoke-WebRequest -Uri "https://loki.insidemicro.com/loki/api/v1/push" -Method Post -ContentType "application/json" -Body ([System.Text.Encoding]::UTF8.GetBytes($payload))
|
|
||||||
'@
|
|
||||||
Set-Content -Path $BootScriptPath -Value $BootScriptContent -Encoding UTF8
|
|
||||||
|
|
||||||
# =========================
|
# =========================
|
||||||
# 5. Registro de Tareas Programadas
|
# 5. Registro de Tareas Programadas
|
||||||
@@ -132,11 +109,6 @@ $actionSync = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoPr
|
|||||||
$triggerSync = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 10)
|
$triggerSync = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 10)
|
||||||
Register-ScheduledTask -TaskName $TaskNameSync -Action $actionSync -Trigger $triggerSync -Principal $principal -Settings $settings -Force
|
Register-ScheduledTask -TaskName $TaskNameSync -Action $actionSync -Trigger $triggerSync -Principal $principal -Settings $settings -Force
|
||||||
|
|
||||||
# Tarea Boot (Al iniciar)
|
|
||||||
$actionBoot = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$BootScriptPath`""
|
|
||||||
$triggerBoot = New-ScheduledTaskTrigger -AtStartup
|
|
||||||
Register-ScheduledTask -TaskName $TaskNameBoot -Action $actionBoot -Trigger $triggerBoot -Principal $principal -Settings $settings -Force
|
|
||||||
|
|
||||||
# =========================
|
# =========================
|
||||||
# 6. Arranque Inicial
|
# 6. Arranque Inicial
|
||||||
# =========================
|
# =========================
|
||||||
|
|||||||
Reference in New Issue
Block a user