#!/bin/bash
# Exabytes ID in-house script

# Get current date
current_date=$(date +"%d %b %Y")

# Get hostname
hostname=$(hostname)

# Get IP address
ip_address=$(hostname -I)

# Get OS information
os_info=$(awk -F= '$1=="PRETTY_NAME" {gsub(/"/, "", $2); split($2, a, " "); print a[1], a[2]}' /etc/os-release)

# Get total RAM in GB
ram_total=$(free -g | awk '/^Mem:/{print $2}')

# Get uptime
uptime=$(uptime | awk '{print $3" "$4}' | sed 's/,//')

# Get load average for the last 10 minutes
load_avg_10min=$(uptime | awk -F'average:' '{print $2}' | awk '{print $2, $3, $4}')

# Count total number of CPUs
cpu_total=$(lscpu | grep '^CPU(s):' | awk '{print $2}')

# Detect if using Plesk or cPanel
if [ -f /usr/local/psa/version ]; then
    control_panel="Plesk"
elif [ -f /usr/local/cpanel/version ]; then
    control_panel="cPanel"
else
    control_panel="Unknown"
fi

# Get total disk space in GB
disk_total=$(df -h --total | grep 'vda1' | awk 'END {print $2}' | cut -d'G' -f1)

# Get free disk
disk_free=$(df -h / | awk 'NR==2 {print $4}')

# Additional variable
manage="PRO"

# Write output to host.pro file
echo "$current_date, $hostname, $ip_address, $os_info, $ram_total GB, $uptime, $cpu_total CPUs, $disk_free, $disk_total GB, $control_panel, $manage" > "$hostname.pro"

# sync to ownstat
curl -X POST -F "file=@$hostname.pro" https://zero.idcloudhosting.my.id/guguk/
