-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_send.sh
More file actions
56 lines (48 loc) · 2.06 KB
/
data_send.sh
File metadata and controls
56 lines (48 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
#config
miner_name="" #set the desired miner name (if you have multiple miners can be useful)
miner_logs_path="" #Path the temporary logs will be saved
miner_helper_scripts_path="" # Path to helper scripts folder
splunk_HTTP_Connector_Token=""
splunk_machine_ip_port="ip:8088" #Default port is 8088
stats_data_path="/var/tmp" # Path to the data files on simplemining OS this is found on /var/tmp
data_list="stats_sys_ipLAN\|stats_hash\|stats_sys_pwr\|stats_gpu_temp_jq\|stats_sys_uptime\|stats_eth_price\|stats_wei_daily\|stats_wei_unpaid\|stats_usd_to_nis"
sleep_offset=0 # if the script is commited by Crontab this can help pick which script will execute first. (In seconds)
use_helper_scripts=$false
sleep $sleep_offset
#Constants
timestamp=$(date +%Y-%m-%dT%H:%M:%S) # This Timestamp the logs to splunk
#helper scripts that are desgined to get external values from Pools or Currency API, Disabled by Default
if [ $use_helper_scripts = $true ]
then
for filename in $(ls $miner_helper_scripts_path | grep *.sh)
do
bash $filename
done
fi
# Test if folder exist if not creates one.
if [ -d "$miner_logs_path" ]
then test
else
mkdir $miner_logs_path
fi
# Gets all the hardware stats from tmp folder and run in a for each loop.
echo "miner_name=$miner_name" >> $miner_logs_path/miner_$timestamp.log
for i in $(ls $stats_data_path | grep $data_list | grep -v ".sent")
do
echo -n "$i=\"" >> $miner_logs_path/miner_$timestamp.log
if [[ "$i" =~ "jq" ]] # check if data file is JSON Format
then
echo $(cat "$stats_data_path/$i" | jq -r '."0"')\" >> $miner_logs_path/miner_$timestamp.log
else
echo $(cat "$stats_data_path/$i")\" >> $miner_logs_path/miner_$timestamp.log
fi
done
status_code=$(curl -m 5 -k https://$splunk_machine_ip_port/services/collector/raw -H "Authorization: Splunk $splunk_HTTP_Connector_Token" -F "$miner_name=@$miner_logs_path/miner_$timestamp.log") 2> /dev/null
if [ $status_code = '{"text":"Success","code":0}' ] # if sending is successful deletes local log, if not keep it
then
rm "$miner_logs_path/miner_$timestamp.log"
echo "true"
else
echo "false"
fi