Compare commits
7 commits
Author | SHA1 | Date | |
---|---|---|---|
|
eb48df0f85 | ||
|
0395efbb0f | ||
|
0402a15828 | ||
|
87a9707409 | ||
|
0f7ce34dbe | ||
|
055233e590 | ||
|
2336edcf2e |
2 changed files with 35 additions and 12 deletions
20
agent.sh
20
agent.sh
|
@ -115,23 +115,23 @@ then
|
||||||
cpu_freq=$(prep $(num "$(lscpu | grep 'CPU MHz' | awk -F\: '{ print $2 }' | sed -e 's/^ *//g' -e 's/ *$//g')"))
|
cpu_freq=$(prep $(num "$(lscpu | grep 'CPU MHz' | awk -F\: '{ print $2 }' | sed -e 's/^ *//g' -e 's/ *$//g')"))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# RAM usage
|
# RAM usage (in bytes)
|
||||||
ram_total=$(prep $(num "$(cat /proc/meminfo | grep ^MemTotal: | awk '{ print $2 }')"))
|
ram_total=$(prep $(num "$(cat /proc/meminfo | grep ^MemTotal: | awk '{ print $2 }')"))
|
||||||
ram_free=$(prep $(num "$(cat /proc/meminfo | grep ^MemFree: | awk '{ print $2 }')"))
|
ram_free=$(prep $(num "$(cat /proc/meminfo | grep ^MemFree: | awk '{ print $2 }')"))
|
||||||
ram_cached=$(prep $(num "$(cat /proc/meminfo | grep ^Cached: | awk '{ print $2 }')"))
|
ram_cached=$(prep $(num "$(cat /proc/meminfo | grep ^Cached: | awk '{ print $2 }')"))
|
||||||
ram_buffers=$(prep $(num "$(cat /proc/meminfo | grep ^Buffers: | awk '{ print $2 }')"))
|
ram_buffers=$(prep $(num "$(cat /proc/meminfo | grep ^Buffers: | awk '{ print $2 }')"))
|
||||||
ram_usage=$((($ram_total-($ram_free+$ram_cached+$ram_buffers))*1024))
|
ram_usage=$((($ram_total-($ram_free+$ram_cached+$ram_buffers)) * 1024))
|
||||||
ram_total=$(($ram_total*1024))
|
ram_total=$(($ram_total * 1024))
|
||||||
|
|
||||||
# Swap usage
|
# Swap usage (in bytes)
|
||||||
swap_total=$(prep $(num "$(cat /proc/meminfo | grep ^SwapTotal: | awk '{ print $2 }')"))
|
swap_total=$(prep $(num "$(cat /proc/meminfo | grep ^SwapTotal: | awk '{ print $2 }')"))
|
||||||
swap_free=$(prep $(num "$(cat /proc/meminfo | grep ^SwapFree: | awk '{ print $2 }')"))
|
swap_free=$(prep $(num "$(cat /proc/meminfo | grep ^SwapFree: | awk '{ print $2 }')"))
|
||||||
swap_usage=$((($swap_total-$swap_free)*1024))
|
swap_usage=$((($swap_total-$swap_free) * 1024))
|
||||||
swap_total=$(($swap_total*1024))
|
swap_total=$(($swap_total * 1024))
|
||||||
|
|
||||||
# Disk usage
|
# Disk usage (in bytes)
|
||||||
disk_total=$(prep $(num "$(($(df -P -B 1 | grep '^/' | awk '{ print $2 }' | sed -e :a -e '$!N;s/\n/+/;ta')))"))
|
disk_total=$(prep $(num "$(($(df --output=size,source -B 1 | grep ' /' | awk '{ print $1 }' | sed -e :a -e '$!N;s/\n/+/;ta')))"))
|
||||||
disk_usage=$(prep $(num "$(($(df -P -B 1 | grep '^/' | awk '{ print $3 }' | sed -e :a -e '$!N;s/\n/+/;ta')))"))
|
disk_usage=$(prep $(num "$(($(df --output=used,source -B 1 | grep ' /' | awk '{ print $1 }' | sed -e :a -e '$!N;s/\n/+/;ta')))"))
|
||||||
|
|
||||||
# Disk array
|
# Disk array
|
||||||
disk_array=$(prep "$(df -P -B 1 | grep '^/' | awk '{ print $1" "$2" "$3";" }' | sed -e :a -e '$!N;s/\n/ /;ta' | awk '{ print $0 } END { if (!NR) print "N/A" }')")
|
disk_array=$(prep "$(df -P -B 1 | grep '^/' | awk '{ print $1" "$2" "$3";" }' | sed -e :a -e '$!N;s/\n/ /;ta' | awk '{ print $0 } END { if (!NR) print "N/A" }')")
|
||||||
|
@ -145,7 +145,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Network interface
|
# Network interface
|
||||||
nic=$(prep "$(ip route get 8.8.8.8 | grep dev | awk -F'dev' '{ print $2 }' | awk '{ print $1 }')")
|
nic=$(prep "$(ip route get 1.1.1.1 | grep dev | awk -F'dev' '{ print $2 }' | awk '{ print $1 }')")
|
||||||
|
|
||||||
if [ -z $nic ]
|
if [ -z $nic ]
|
||||||
then
|
then
|
||||||
|
|
27
install.sh
27
install.sh
|
@ -14,13 +14,31 @@ then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Parameters required
|
# Required parameter
|
||||||
if [ $# -lt 1 ]
|
if [ $# -lt 1 ]
|
||||||
then
|
then
|
||||||
echo -e "| Usage: bash $0 'token'\n|"
|
echo -e "| Usage: bash $0 'token'\n|"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Exchange JIT token for agent token
|
||||||
|
if [[ $1 == jit-* ]]; then
|
||||||
|
# POST request to retrieve token
|
||||||
|
response=$(curl -s -X POST -d "token=$1" https://api.netweak.com/agent/get-token)
|
||||||
|
|
||||||
|
# Check if there's an error
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
echo -e "|\n| Error: Failed to retrieve token from API. Make sure your installation command is correct.\n|"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extracting token from response
|
||||||
|
token=$(echo "$response" | tr -d '\n')
|
||||||
|
else
|
||||||
|
# Token doesn't start with "jit-", using it as is
|
||||||
|
token=$1
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if crontab is installed
|
# Check if crontab is installed
|
||||||
if [ ! -n "$(command -v crontab)" ]
|
if [ ! -n "$(command -v crontab)" ]
|
||||||
then
|
then
|
||||||
|
@ -120,12 +138,14 @@ mkdir -p /etc/netweak/log
|
||||||
|
|
||||||
# Download agent
|
# Download agent
|
||||||
echo -e "| Downloading agent.sh to /etc/netweak\n|\n| + $(curl -JLso /etc/netweak/agent.sh https://github.com/netweak/agent/raw/main/agent.sh)"
|
echo -e "| Downloading agent.sh to /etc/netweak\n|\n| + $(curl -JLso /etc/netweak/agent.sh https://github.com/netweak/agent/raw/main/agent.sh)"
|
||||||
|
|
||||||
|
# Download heartbeat
|
||||||
echo -e "| Downloading heartbeat.sh to /etc/netweak\n|\n| + $(curl -JLso /etc/netweak/heartbeat.sh https://github.com/netweak/agent/raw/main/heartbeat.sh)"
|
echo -e "| Downloading heartbeat.sh to /etc/netweak\n|\n| + $(curl -JLso /etc/netweak/heartbeat.sh https://github.com/netweak/agent/raw/main/heartbeat.sh)"
|
||||||
|
|
||||||
if [ -f /etc/netweak/agent.sh ]
|
if [ -f /etc/netweak/agent.sh ]
|
||||||
then
|
then
|
||||||
# Create auth file
|
# Create auth file
|
||||||
echo "$1" > /etc/netweak/token.conf
|
echo "$token" > /etc/netweak/token.conf
|
||||||
|
|
||||||
# Create user
|
# Create user
|
||||||
useradd netweak -r -d /etc/netweak -s /bin/false
|
useradd netweak -r -d /etc/netweak -s /bin/false
|
||||||
|
@ -140,6 +160,9 @@ then
|
||||||
crontab -u netweak -l 2>/dev/null | { cat; echo "* * * * * bash /etc/netweak/heartbeat.sh > /etc/netweak/log/cron.log 2>&1"; } | crontab -u netweak -
|
crontab -u netweak -l 2>/dev/null | { cat; echo "* * * * * bash /etc/netweak/heartbeat.sh > /etc/netweak/log/cron.log 2>&1"; } | crontab -u netweak -
|
||||||
crontab -u netweak -l 2>/dev/null | { cat; echo "* * * * * bash /etc/netweak/agent.sh > /etc/netweak/log/cron.log 2>&1"; } | crontab -u netweak -
|
crontab -u netweak -l 2>/dev/null | { cat; echo "* * * * * bash /etc/netweak/agent.sh > /etc/netweak/log/cron.log 2>&1"; } | crontab -u netweak -
|
||||||
|
|
||||||
|
# Initial run of agent
|
||||||
|
bash /etc/netweak/agent.sh
|
||||||
|
|
||||||
# Show success
|
# Show success
|
||||||
echo -e "|\n| Success: The Netweak agent has been installed\n|"
|
echo -e "|\n| Success: The Netweak agent has been installed\n|"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue