mirror of
https://github.com/netweak/agent.git
synced 2024-12-16 21:46:58 -05:00
Add heartbeat
This commit is contained in:
parent
394f29d48a
commit
8eeeaf7f44
2 changed files with 39 additions and 1 deletions
2
agent.sh
2
agent.sh
|
@ -4,7 +4,7 @@
|
|||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
# Agent version
|
||||
version="1.1.0"
|
||||
version="1.2.0"
|
||||
|
||||
# API Token
|
||||
if [ -f /etc/netweak/token.conf ]
|
||||
|
|
38
heartbeat.sh
Normal file
38
heartbeat.sh
Normal file
|
@ -0,0 +1,38 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Set env
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
# API Token
|
||||
if [ -f /etc/netweak/token.conf ]
|
||||
then
|
||||
auth=($(cat /etc/netweak/token.conf))
|
||||
else
|
||||
echo "Error: File /etc/netweak/token.conf is missing."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Build data for post
|
||||
data_post="token=${auth[0]}"
|
||||
|
||||
# API request with automatic termination
|
||||
if [ -n "$(command -v timeout)" ]
|
||||
then
|
||||
timeout -s SIGKILL 30 wget -q -o /dev/null -O /etc/netweak/log/agent.log -T 25 --post-data "$data_post" --no-check-certificate "https://api.netweak.com/agent/heartbeat"
|
||||
else
|
||||
wget -q -o /dev/null -O /etc/netweak/log/agent.log -T 25 --post-data "$data_post" --no-check-certificate "https://api.netweak.com/agent/heartbeat"
|
||||
wget_pid=$!
|
||||
wget_counter=0
|
||||
wget_timeout=30
|
||||
|
||||
while kill -0 "$wget_pid" && (( wget_counter < wget_timeout ))
|
||||
do
|
||||
sleep 1
|
||||
(( wget_counter++ ))
|
||||
done
|
||||
|
||||
kill -0 "$wget_pid" && kill -s SIGKILL "$wget_pid"
|
||||
fi
|
||||
|
||||
# Finished
|
||||
exit 1
|
Loading…
Reference in a new issue