diff --git a/discovery/Dockerfile b/discovery/Dockerfile new file mode 100644 index 0000000..dcfcd24 --- /dev/null +++ b/discovery/Dockerfile @@ -0,0 +1,10 @@ +FROM ubuntu:latest + +RUN apt -y update && apt -y install curl iproute2 + +ENV COLONY_API_URL=https://colony-api-development.mgmt-20.kubefirst.com +ENV COLONY_HARDWARE_ID=2de76518-16e2-45ec-b3ae-ee8db5f4de6f + +COPY . . + +CMD [ "./entrypoint.sh" ] \ No newline at end of file diff --git a/discovery/entrypoint.sh b/discovery/entrypoint.sh new file mode 100755 index 0000000..74e400b --- /dev/null +++ b/discovery/entrypoint.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +# Function to get architecture info +get_architecture_info() { + architecture_info=$(lscpu | grep Architecture: | awk '{print $2}') + echo "$architecture_info" +} + +# Function to get number of cpu +get_cpu_info() { + cpu_info=$(nproc) + echo "$cpu_info" +} + +# Function to get memory info +get_mem_info() { + mem_info=$(free -m | grep Mem | awk '{print $2}') + echo "$mem_info" +} + +# Function to get physical disk info +get_disk_info() { + disk_info=$(lsblk -o NAME,TYPE,SIZE | grep disk | awk 'NR>1{if (NR!=1) printf ","; printf "\"%s\"", $1}') + echo "["${disk_info#,}"]" +} + + +# Function to get physical interface info +get_interface_info() { + interface_info=$(ip -o link show | awk -F': ' 'NR>1{print ",\""$2"\""}') + echo "["${interface_info:1}"]" +} + + +# Main function to generate JSON output +generate_json() { + architecture_info=$(get_architecture_info) + cpu_info=$(get_cpu_info) + mem_info=$(get_mem_info) + disk_info=$(get_disk_info) + interface_info=$(get_interface_info) + + json_output=$(cat <