112 lines
5.8 KiB
Bash
Executable File
112 lines
5.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# WEVIA Blade Health — runs via SSH from S204
|
|
# Usage: wevia-blade-health.sh [status|clean|security|full]
|
|
ACTION=${1:-status}
|
|
BLADE="10.1.0.4"
|
|
BLADE_USER="yanis"
|
|
SSH="ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no $BLADE_USER@$BLADE"
|
|
|
|
# Check if Blade reachable
|
|
if ! timeout 3 ping -c 1 $BLADE >/dev/null 2>&1; then
|
|
echo '{"status":"offline","blade":"unreachable"}'
|
|
exit 1
|
|
fi
|
|
|
|
case $ACTION in
|
|
status)
|
|
$SSH 'powershell -Command "
|
|
$cpu = (Get-WmiObject Win32_Processor | Measure-Object -Property LoadPercentage -Average).Average
|
|
$mem = Get-WmiObject Win32_OperatingSystem
|
|
$memUsed = [math]::Round(($mem.TotalVisibleMemorySize - $mem.FreePhysicalMemory) / 1MB, 1)
|
|
$memTotal = [math]::Round($mem.TotalVisibleMemorySize / 1MB, 1)
|
|
$memPct = [math]::Round(($mem.TotalVisibleMemorySize - $mem.FreePhysicalMemory) / $mem.TotalVisibleMemorySize * 100, 1)
|
|
$disk = Get-WmiObject Win32_LogicalDisk -Filter \"DriveType=3\" | Select-Object DeviceID, @{N=\"UsedPct\";E={[math]::Round(($_.Size - $_.FreeSpace) / $_.Size * 100, 1)}}, @{N=\"FreeGB\";E={[math]::Round($_.FreeSpace / 1GB, 1)}}
|
|
$uptime = (Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime
|
|
$procs = (Get-Process | Measure-Object).Count
|
|
$topCPU = Get-Process | Sort-Object CPU -Descending | Select-Object -First 5 Name, @{N=\"CPU_s\";E={[math]::Round($_.CPU,1)}}, @{N=\"RAM_MB\";E={[math]::Round($_.WorkingSet64/1MB,1)}}
|
|
Write-Output \"CPU: ${cpu}%\"
|
|
Write-Output \"RAM: ${memUsed}GB/${memTotal}GB (${memPct}%)\"
|
|
foreach ($d in $disk) { Write-Output \"Disk $($d.DeviceID): $($d.UsedPct)% used ($($d.FreeGB)GB free)\" }
|
|
Write-Output \"Uptime: $($uptime.Days)d $($uptime.Hours)h\"
|
|
Write-Output \"Processes: $procs\"
|
|
Write-Output \"--- TOP CPU ---\"
|
|
foreach ($p in $topCPU) { Write-Output \" $($p.Name): CPU=$($p.CPU_s)s RAM=$($p.RAM_MB)MB\" }
|
|
"' 2>/dev/null
|
|
;;
|
|
|
|
clean)
|
|
$SSH 'powershell -Command "
|
|
Write-Output \"=== BLADE CLEANUP ===\"
|
|
# Temp files
|
|
$before = (Get-ChildItem $env:TEMP -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum / 1MB
|
|
Remove-Item \"$env:TEMP\*\" -Recurse -Force -ErrorAction SilentlyContinue
|
|
Remove-Item \"C:\Windows\Temp\*\" -Recurse -Force -ErrorAction SilentlyContinue
|
|
$after = (Get-ChildItem $env:TEMP -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum / 1MB
|
|
Write-Output \"Temp: cleaned $([math]::Round($before - $after, 0))MB\"
|
|
# Browser cache
|
|
Remove-Item \"$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cache\*\" -Recurse -Force -ErrorAction SilentlyContinue
|
|
Write-Output \"Chrome cache: cleaned\"
|
|
# Windows Update cache
|
|
Stop-Service wuauserv -ErrorAction SilentlyContinue
|
|
Remove-Item \"C:\Windows\SoftwareDistribution\Download\*\" -Recurse -Force -ErrorAction SilentlyContinue
|
|
Start-Service wuauserv -ErrorAction SilentlyContinue
|
|
Write-Output \"WU cache: cleaned\"
|
|
# Recycle bin
|
|
Clear-RecycleBin -Force -ErrorAction SilentlyContinue
|
|
Write-Output \"Recycle bin: emptied\"
|
|
# Disk after
|
|
$disk = Get-WmiObject Win32_LogicalDisk -Filter \"DriveType=3 AND DeviceID='"'"'C:'"'"'\"
|
|
$free = [math]::Round($disk.FreeSpace / 1GB, 1)
|
|
Write-Output \"C: free: ${free}GB\"
|
|
"' 2>/dev/null
|
|
;;
|
|
|
|
security)
|
|
$SSH 'powershell -Command "
|
|
Write-Output \"=== BLADE SECURITY ===\"
|
|
# Windows Defender status
|
|
$defender = Get-MpComputerStatus -ErrorAction SilentlyContinue
|
|
Write-Output \"Defender: $($defender.AntivirusEnabled) | Sigs: $($defender.AntivirusSignatureLastUpdated)\"
|
|
Write-Output \"RealTime: $($defender.RealTimeProtectionEnabled)\"
|
|
# Firewall
|
|
$fw = Get-NetFirewallProfile | Select-Object Name, Enabled
|
|
foreach ($f in $fw) { Write-Output \"Firewall $($f.Name): $($f.Enabled)\" }
|
|
# Open ports
|
|
Write-Output \"--- LISTENING PORTS ---\"
|
|
Get-NetTCPConnection -State Listen | Select-Object LocalPort, OwningProcess | Sort-Object LocalPort -Unique | ForEach-Object {
|
|
$proc = (Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue).Name
|
|
Write-Output \" :$($_.LocalPort) → $proc\"
|
|
} | Select-Object -First 15
|
|
# Recent failed logins
|
|
Write-Output \"--- FAILED LOGINS (24h) ---\"
|
|
$failed = Get-WinEvent -FilterHashtable @{LogName=\"Security\";Id=4625;StartTime=(Get-Date).AddHours(-24)} -MaxEvents 5 -ErrorAction SilentlyContinue
|
|
Write-Output \" Count: $($failed.Count)\"
|
|
# Suspicious processes
|
|
Write-Output \"--- HIGH CPU PROCESSES ---\"
|
|
Get-Process | Where-Object {$_.CPU -gt 60} | Sort-Object CPU -Descending | Select-Object -First 5 Name, Id, CPU | ForEach-Object {
|
|
Write-Output \" $($_.Name) PID:$($_.Id) CPU:$([math]::Round($_.CPU,0))s\"
|
|
}
|
|
"' 2>/dev/null
|
|
;;
|
|
|
|
kill)
|
|
PROC=${2:-""}
|
|
if [ -n "$PROC" ]; then
|
|
$SSH "powershell -Command \"Stop-Process -Name '$PROC' -Force -ErrorAction SilentlyContinue; Write-Output 'Killed: $PROC'\"" 2>/dev/null
|
|
else
|
|
echo "Usage: wevia-blade-health.sh kill <process_name>"
|
|
fi
|
|
;;
|
|
|
|
full)
|
|
echo "=== BLADE FULL HEALTH ==="
|
|
$0 status
|
|
echo ""
|
|
$0 security
|
|
;;
|
|
|
|
*)
|
|
echo "Usage: $0 {status|clean|security|kill <proc>|full}"
|
|
;;
|
|
esac
|