#!/bin/bash

# ===== CONFIGURACIÓN =====
ENDPOINT_URL="https://tu-api.com/endpoint"
HOSTNAME=$(hostname)

# ===== SISTEMA OPERATIVO =====
OS=$(grep PRETTY_NAME /etc/os-release | cut -d= -f2 | tr -d '"')

# ===== CPU =====
CPU_CORES=$(nproc)
CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | awk '{print 100 - $8}')

# ===== MEMORIA (MB) =====
MEM_TOTAL=$(free -m | awk '/Mem:/ {print $2}')
MEM_USED=$(free -m | awk '/Mem:/ {print $3}')

# ===== DISCO (GB) =====
DISK_TOTAL=$(df -BG / | awk 'NR==2 {print $2}' | sed 's/G//')
DISK_USED=$(df -BG / | awk 'NR==2 {print $3}' | sed 's/G//')

# ===== TIMESTAMP =====
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

# ===== JSON =====
JSON=$(cat <<EOF
{
  "hostname": "$HOSTNAME",
  "operating_system": "$OS",
  "cpu": {
    "cores": $CPU_CORES,
    "usage_percent": $CPU_USAGE
  },
  "memory": {
    "total_mb": $MEM_TOTAL,
    "used_mb": $MEM_USED
  },
  "disk": {
    "total_gb": $DISK_TOTAL,
    "used_gb": $DISK_USED
  },
  "timestamp": "$TIMESTAMP"
}
EOF
)

# ===== REQUEST =====
curl -X POST "$ENDPOINT_URL" \
	  -H "Content-Type: application/json" \
	    -d "$JSON"

