forked from hetrixtools/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hetrixtools_update.sh
166 lines (147 loc) · 5.44 KB
/
hetrixtools_update.sh
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
#
#
# HetrixTools Server Monitoring Agent - Update Script
# version 1.5.9
# Copyright 2015 - 2020 @ HetrixTools
# For support, please open a ticket on our website https://hetrixtools.com
#
#
# DISCLAIMER OF WARRANTY
#
# The Software is provided "AS IS" and "WITH ALL FAULTS," without warranty of any kind,
# including without limitation the warranties of merchantability, fitness for a particular purpose and non-infringement.
# HetrixTools makes no warranty that the Software is free of defects or is suitable for any particular purpose.
# In no event shall HetrixTools be responsible for loss or damages arising from the installation or use of the Software,
# including but not limited to any indirect, punitive, special, incidental or consequential damages of any character including,
# without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses.
# The entire risk as to the quality and performance of the Software is borne by you, the user.
#
#
# Set PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Old Agent Path
AGENT="/etc/hetrixtools/hetrixtools_agent.sh"
# Check if user specified version to update to
if [ -z "$1" ]
then
VERS="master"
else
VERS=$1
fi
# Check if install script is run by root
echo "Checking root privileges..."
if [ "$EUID" -ne 0 ]
then echo "ERROR: Please run the install script as root."
exit
fi
echo "... done."
# Check if system has crontab and wget
echo "Checking for crontab and wget..."
command -v crontab >/dev/null 2>&1 || { echo "ERROR: Crontab is required to run this agent." >&2; exit 1; }
command -v wget >/dev/null 2>&1 || { echo "ERROR: wget is required to run this agent." >&2; exit 1; }
echo "... done."
# Look for the old agent
echo "Looking for the old agent..."
if [ -f "$AGENT" ]
then
echo "... done."
else
echo "ERROR: No old agent found. Nothing to update." >&2; exit 1;
fi
# Extract data from the old agent
echo "Extracting configs from the old agent..."
# SID (Server ID)
SID=$(grep 'SID="' $AGENT | awk -F'"' '{ print $2 }')
# Network Interfaces
NetworkInterfaces=$(grep 'NetworkInterfaces="' $AGENT | awk -F'"' '{ print $2 }')
# Check Services
CheckServices=$(grep 'CheckServices="' $AGENT | awk -F'"' '{ print $2 }')
# Check Software RAID Health
CheckSoftRAID=$(grep 'CheckSoftRAID=' $AGENT | awk -F'=' '{ print $2 }')
# Check Drive Health
CheckDriveHealth=$(grep 'CheckDriveHealth=' $AGENT | awk -F'=' '{ print $2 }')
# RunningProcesses
RunningProcesses=$(grep 'RunningProcesses=' $AGENT | awk -F'=' '{ print $2 }')
if [ -z "$RunningProcesses" ]
then
RunningProcesses=0
fi
echo "... done."
# Port Connections
ConnectionPorts=$(grep 'ConnectionPorts="' $AGENT | awk -F'"' '{ print $2 }')
# Fetching new agent
echo "Fetching the new agent..."
wget -t 1 -T 30 -qO $AGENT --no-check-certificate https://raw.github.com/CodeCatsOfficial/agent/$VERS/hetrixtools_agent.sh
echo "... done."
# Inserting Server ID (SID) into the agent config
echo "Inserting Server ID (SID) into agent config..."
sed -i "s/SIDPLACEHOLDER/$SID/" $AGENT
echo "... done."
# Check if any network interfaces are specified
echo "Checking if any network interfaces are specified..."
if [ ! -z "$NetworkInterfaces" ]
then
echo "Network interfaces found, inserting them into the agent config..."
sed -i "s/NetworkInterfaces=\"\"/NetworkInterfaces=\"$NetworkInterfaces\"/" $AGENT
fi
# Check if any services are to be monitored
echo "Checking if any services should be monitored..."
if [ ! -z "$CheckServices" ]
then
echo "Services found, inserting them into the agent config..."
sed -i "s/CheckServices=\"\"/CheckServices=\"$CheckServices\"/" $AGENT
fi
echo "... done."
# Check if Software RAID should be monitored
echo "Checking if software RAID should be monitored..."
if [ "$CheckSoftRAID" -eq "1" ]
then
echo "Enabling software RAID monitoring in the agent config..."
sed -i "s/CheckSoftRAID=0/CheckSoftRAID=1/" $AGENT
fi
echo "... done."
# Check if Drive Health should be monitored
echo "Checking if Drive Health should be monitored..."
if [ "$CheckDriveHealth" -eq "1" ]
then
echo "Enabling Drive Health monitoring in the agent config..."
sed -i "s/CheckDriveHealth=0/CheckDriveHealth=1/" $AGENT
fi
echo "... done."
# Check if 'View running processes' should be enabled
echo "Checking if 'View running processes' should be enabled..."
if [ "$RunningProcesses" -eq "1" ]
then
echo "Enabling 'View running processes' in the agent config..."
sed -i "s/RunningProcesses=0/RunningProcesses=1/" $AGENT
fi
echo "... done."
# Check if any ports to monitor number of connections on
echo "Checking if any ports to monitor number of connections on..."
if [ ! -z "$ConnectionPorts" ]
then
echo "Ports found, inserting them into the agent config..."
sed -i "s/ConnectionPorts=\"\"/ConnectionPorts=\"$ConnectionPorts\"/" $AGENT
fi
echo "... done."
# Killing any running hetrixtools agents
echo "Making sure no hetrixtools agent scripts are currently running..."
ps aux | grep -ie hetrixtools_agent.sh | awk '{print $2}' | xargs kill -9
echo "... done."
# Assign permissions
echo "Assigning permissions for the hetrixtools user..."
if id -u hetrixtools >/dev/null 2>&1
then
chown -R hetrixtools:hetrixtools /etc/hetrixtools
chmod -R 700 /etc/hetrixtools
fi
# Cleaning up install file
echo "Cleaning up the update file..."
if [ -f $0 ]
then
rm -f $0
fi
echo "... done."
# All done
echo "HetrixTools agent update completed. It can take up to two (2) minutes for new data to be collected."