Initialer Import des AssetManagers

This commit is contained in:
2026-08-02 21:28:50 +00:00
commit ed72ce8821
256 changed files with 26361 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
echo "AssetManager test job"
echo "JobId={{JobId}}"
echo "AssetName={{AssetName}}"
echo "Hostname={{Hostname}}"
echo "IPAddress={{IPAddress}}"
echo "Department={{Department}}"
echo "Location={{Location}}"
echo "MeshNodeId={{MeshNodeId}}"
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -Eeuo pipefail
CALLBACK_URL='{{CallbackUrl}}'
JOB_ID='{{JobId}}'
callback() {
local status="$1" code="$2" message="$3" attempt
for attempt in 1 2 3; do
if curl -fsS --max-time 60 -X POST -H 'Content-Type: application/json' --data "{\"status\":\"${status}\",\"exit_code\":${code},\"completed\":true,\"message\":\"${message}\"}" "$CALLBACK_URL" >/dev/null; then
return 0
fi
echo "Callback attempt ${attempt} of 3 failed" >&2
if [ "$attempt" -lt 3 ]; then sleep $((attempt * 2)); fi
done
return 1
}
trap 'code=$?; callback failed "$code" "Job failed" || true; exit "$code"' ERR
echo "$(date --iso-8601=seconds) job=${JOB_ID} started"
# --- Eigene Befehle hier einfügen ---
# --- Ende eigene Befehle ---
callback success 0 'Job completed'
+8
View File
@@ -0,0 +1,8 @@
echo AssetManager test job
echo JobId={{JobId}}
echo AssetName={{AssetName}}
echo Hostname={{Hostname}}
echo IPAddress={{IPAddress}}
echo Department={{Department}}
echo Location={{Location}}
echo MeshNodeId={{MeshNodeId}}
+15
View File
@@ -0,0 +1,15 @@
@echo off
setlocal EnableExtensions EnableDelayedExpansion
set "JOB_ID={{JobId}}"
set "CALLBACK_URL={{CallbackUrl}}"
rem --- Eigene Befehle hier einfügen ---
rem --- Ende eigene Befehle ---
set "EXIT_CODE=%ERRORLEVEL%"
if not "%EXIT_CODE%"=="0" goto :failed
powershell -NoProfile -ExecutionPolicy Bypass -Command "$body=@{status='success';exit_code=0;completed=$true;message='Job completed'}|ConvertTo-Json -Compress; $last=$null; for($attempt=1;$attempt -le 3;$attempt++){try{Invoke-RestMethod -Method Post -Uri '%CALLBACK_URL%' -ContentType 'application/json' -Body $body -TimeoutSec 60|Out-Null; exit 0}catch{$last=$_.Exception; if($attempt -lt 3){Start-Sleep -Seconds (2*$attempt)}}}; Write-Error ('Callback failed after 3 attempts: '+$last.Message); exit 1"
if errorlevel 1 exit /b 1
exit /b 0
:failed
powershell -NoProfile -ExecutionPolicy Bypass -Command "$body=@{status='failed';exit_code=%EXIT_CODE%;completed=$true;message='Job failed'}|ConvertTo-Json -Compress; for($attempt=1;$attempt -le 3;$attempt++){try{Invoke-RestMethod -Method Post -Uri '%CALLBACK_URL%' -ContentType 'application/json' -Body $body -TimeoutSec 60|Out-Null; break}catch{if($attempt -lt 3){Start-Sleep -Seconds (2*$attempt)}}}"
exit /b %EXIT_CODE%
+8
View File
@@ -0,0 +1,8 @@
Write-JobLog "AssetManager test job"
Write-JobLog "JobId={{JobId}}"
Write-JobLog "AssetName={{AssetName}}"
Write-JobLog "Hostname={{Hostname}}"
Write-JobLog "IPAddress={{IPAddress}}"
Write-JobLog "Department={{Department}}"
Write-JobLog "Location={{Location}}"
Write-JobLog "MeshNodeId={{MeshNodeId}}"
+45
View File
@@ -0,0 +1,45 @@
$ErrorActionPreference = 'Stop'
$log = Join-Path $env:ProgramData 'AssetManager\commands.log'
$clientLog = [System.Collections.Generic.List[string]]::new()
$JobResult = @{}
New-Item -ItemType Directory -Force -Path (Split-Path $log) | Out-Null
function Send-JobCallback([hashtable]$Data) {
$json = $Data | ConvertTo-Json -Depth 8 -Compress
$bodyBytes = [Text.Encoding]::UTF8.GetBytes($json)
$lastError = $null
for ($attempt = 1; $attempt -le 3; $attempt++) {
try {
Invoke-RestMethod -Method Post -Uri '{{CallbackUrl}}' -ContentType 'application/json; charset=utf-8' -Body $bodyBytes -TimeoutSec 60 | Out-Null
if ($attempt -gt 1) { Write-JobLog ("Callback accepted on attempt $attempt of 3") }
return
} catch {
$lastError = $_.Exception
Write-JobLog ("Callback attempt $attempt of 3 failed: " + $_.Exception.Message)
if ($attempt -lt 3) { Start-Sleep -Seconds (2 * $attempt) }
}
}
throw ("Callback failed after 3 attempts: " + $lastError.Message)
}
function Write-JobLog([string]$Message) {
$line = "$(Get-Date -Format o) job={{JobId}} $Message"
$clientLog.Add($line)
Add-Content -Path $log -Value $line -Encoding UTF8
Write-Output $line
}
try {
Write-JobLog 'Job started'
try { Send-JobCallback @{status='running'; completed=$false; message='Job started on client'; log=($clientLog -join "`n")} } catch { Write-JobLog ("Initial callback failed: " + $_.Exception.Message) }
# --- Eigene Befehle hier einfügen ---
# --- Ende eigene Befehle ---
Write-JobLog 'Job completed'
$bodyData = @{status='success'; exit_code=0; completed=$true; message='Job completed'; log=($clientLog -join "`n")}
if ($JobResult -is [System.Collections.IDictionary]) { foreach ($key in $JobResult.Keys) { $bodyData[$key] = $JobResult[$key] } }
$body = $bodyData | ConvertTo-Json -Depth 8 -Compress
Send-JobCallback $bodyData
} catch {
Write-JobLog ("Job failed: " + $_.Exception.Message)
$body = @{status='failed'; exit_code=1; completed=$true; message=$_.Exception.Message; log=($clientLog -join "`n"); stderr=($_ | Out-String)} | ConvertTo-Json -Compress
try { Send-JobCallback @{status='failed'; exit_code=1; completed=$true; message=$_.Exception.Message; log=($clientLog -join "`n"); stderr=($_ | Out-String)} } catch {}
exit 1
}
+8
View File
@@ -0,0 +1,8 @@
print("AssetManager test job")
print("JobId={{JobId}}")
print("AssetName={{AssetName}}")
print("Hostname={{Hostname}}")
print("IPAddress={{IPAddress}}")
print("Department={{Department}}")
print("Location={{Location}}")
print("MeshNodeId={{MeshNodeId}}")
+45
View File
@@ -0,0 +1,45 @@
import datetime
import json
import time
import traceback
import urllib.request
def callback(payload):
data = json.dumps(payload).encode("utf-8")
last_error = None
for attempt in range(1, 4):
request = urllib.request.Request(
"{{CallbackUrl}}",
data=data,
headers={"Content-Type": "application/json"},
method="POST",
)
try:
urllib.request.urlopen(request, timeout=60).read()
return
except Exception as exc:
last_error = exc
print(f"Callback attempt {attempt} of 3 failed: {exc}")
if attempt < 3:
time.sleep(2 * attempt)
raise RuntimeError(f"Callback failed after 3 attempts: {last_error}")
job_result = {}
try:
print(datetime.datetime.now(datetime.timezone.utc).isoformat(), "job={{JobId}} started")
# --- Eigene Befehle hier einfügen ---
# --- Ende eigene Befehle ---
payload = {"status": "success", "exit_code": 0, "completed": True, "message": "Job completed"}
if isinstance(job_result, dict):
payload.update(job_result)
callback(payload)
except Exception as exc:
try:
callback({"status": "failed", "exit_code": 1, "completed": True, "message": str(exc), "stderr": traceback.format_exc()})
finally:
raise