Compare commits

...

5 Commits
v0.1.2 ... main

Author SHA1 Message Date
buchtioof
d0bfa85ffb v0.2 check storage/partitions 2026-02-23 15:20:20 +01:00
buchtioof
90f3a11b6b v0.2 check storage/partitions 2026-02-23 15:17:12 +01:00
buchtioof
39e06c5161 v0.1.4 security update 2026-02-19 17:14:48 +01:00
buchtioof
47d8ac2544 Merge branch 'main' of https://github.com/buchtioof/alfred 2026-02-18 23:28:59 +01:00
buchtioof
a31408bf31 v0.1.3 i use arch btw 2026-02-18 23:28:23 +01:00

View File

@ -6,6 +6,7 @@ export LANG=C
########## MAIN VARIABLES ########## ########## MAIN VARIABLES ##########
DATE=$(date +'%Y-%m-%d_%H:%M:%S') DATE=$(date +'%Y-%m-%d_%H:%M:%S')
TARGET=${1:-localhost:8000} TARGET=${1:-localhost:8000}
API_KEY=${2:-}
########## TEMPORARY WORKING REPERTORY ########## ########## TEMPORARY WORKING REPERTORY ##########
export PATH="$(pwd)/bin:$PATH" export PATH="$(pwd)/bin:$PATH"
@ -52,16 +53,41 @@ MB_SERIAL=$(inxi -M -c 0 | grep "Mobo:" | sed -E 's/.*Mobo: (.*) model: (.*) ser
GPU_MODEL=$(inxi -G -c 0 | grep "Device-1:" | cut -d: -f2 | xargs) GPU_MODEL=$(inxi -G -c 0 | grep "Device-1:" | cut -d: -f2 | xargs)
# --- STORAGE --- # --- STORAGE ---
SIZES=$(lsblk -dnb | grep -v loop | grep -v boot | tr -s " " | cut -d \ -f4) # Check le stockage total
TOTAL_STORAGE=0 TOTAL_STORAGE=$(inxi -D -c 0 | grep -o 'Total: [0-9.]* [A-Za-z]*' | sed 's/Total: //')
for SIZE in $SIZES; do TOTAL_STORAGE=$((TOTAL_STORAGE + SIZE)); done
TOTAL_STORAGE=$(numfmt --to iec $TOTAL_STORAGE) # Stockage des partitions
# Initialisation d'un tableau vide
mapfile -t ALL_DISKS < <(lsblk -d -n -o NAME,TYPE | awk '$2=="disk" {print $1}')
# Initialisation d'un tableau JSON vide pour stocker les disques
DISKS_JSON="[]"
for disk in "${ALL_DISKS[@]}"; do
# On récupère les partitions du disque courant.
DISK_PARTS=$(lsblk -J -l -o TYPE,NAME,FSTYPE,SIZE,FSUSED "/dev/$disk" 2>/dev/null | \
jq '[.blockdevices[]? | select(.type == "part") | {name: .name, fstype: (.fstype // "N/A"), size: (.size // "N/A"), used: (.fsused // "N/A")}]')
# Si le disque n'a pas de partitions, on mets un tableau vide
if [ -z "$DISK_PARTS" ] || [ "$DISK_PARTS" == "null" ]; then
DISK_PARTS="[]"
fi
# On crée l'objet parent "disque" qui contient son nom et son tableau de partitions
DISK_OBJECTS=$(jq -n \
--arg name "$disk" \
--argjson parts "$DISK_PARTS" \
'{name: $name, partitions: $parts}')
# On ajoute cet objet disque au tableau principal DISKS_JSON
DISKS_JSON=$(echo "$DISKS_JSON" | jq --argjson new_disk "$DISK_OBJECTS" '. + [$new_disk]')
done
# --- SOFTWARE --- # --- SOFTWARE ---
OS=$(lsb_release -d 2>/dev/null | cut -f2 || grep PRETTY_NAME /etc/os-release | cut -d= -f2 | tr -d '"') OS=$(lsb_release -d 2>/dev/null | cut -f2 || grep PRETTY_NAME /etc/os-release | cut -d= -f2 | tr -d '"')
ARCH=$(uname -m) ARCH=$(uname -m)
KERNEL=$(uname -r) KERNEL=$(uname -r)
HOSTNAME=$(hostname) HOSTNAME=$(uname -n)
DEFAULT_IFACE=$(ls /sys/class/net | grep -vE '^(lo|docker|veth|br)' | head -n 1) DEFAULT_IFACE=$(ls /sys/class/net | grep -vE '^(lo|docker|veth|br)' | head -n 1)
MAC_ADDRESS=$(cat "/sys/class/net/$DEFAULT_IFACE/address" 2>/dev/null || echo "Unknown-MAC") MAC_ADDRESS=$(cat "/sys/class/net/$DEFAULT_IFACE/address" 2>/dev/null || echo "Unknown-MAC")
@ -76,6 +102,8 @@ json_pkg() {
--arg cpu_frequency_min "$CPU_FREQUENCY_MIN" \ --arg cpu_frequency_min "$CPU_FREQUENCY_MIN" \
--arg cpu_frequency_cur "$CPU_FREQUENCY_CUR" \ --arg cpu_frequency_cur "$CPU_FREQUENCY_CUR" \
--arg cpu_frequency_max "$CPU_FREQUENCY_MAX" \ --arg cpu_frequency_max "$CPU_FREQUENCY_MAX" \
--arg total_storage "$TOTAL_STORAGE" \
--argjson disks "$DISKS_JSON" \
--arg gpu_model "$GPU_MODEL" \ --arg gpu_model "$GPU_MODEL" \
--arg ram_slots "$RAM_SLOTS" \ --arg ram_slots "$RAM_SLOTS" \
--arg ram_total "$RAM_TOTAL" \ --arg ram_total "$RAM_TOTAL" \
@ -100,7 +128,8 @@ json_pkg() {
gpu_model: $gpu_model, gpu_model: $gpu_model,
ram_slots: $ram_slots, ram_slots: $ram_slots,
ram_total: $ram_total, ram_total: $ram_total,
total_storage: $total_storage total_storage: $total_storage,
disks: $disks
}, },
SOFTWARE: { SOFTWARE: {
hostname: $hostname, hostname: $hostname,
@ -115,9 +144,10 @@ json_pkg() {
) )
curl -X POST "http://$TARGET/endpoint" \ curl -X POST "http://$TARGET/endpoint" \
-H "X-API-Key: $API_KEY" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$json_data" \ -d "$json_data" \
--connect-timeout 5 || echo "Erreur: Serveur $TARGET injoignable." --connect-timeout 5 || echo "[ERROR]: $TARGET server not found."
echo "" echo ""
} }