forked from openemr/openemr-devops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor-installer
85 lines (76 loc) · 3.89 KB
/
monitor-installer
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
#!/bin/bash
# Function: Setup the monitor environment
installDir=$1
hostIp=$2
smtpServer=$3
senderEmail=$4
emailPassword=$5
receiverEmail=$6
# Check docker and dock-compose exist
DOCKER_CODE=10
DOCKER_START=11
DOCKER_COMPOSE_CODE=12
if ! which docker &>/dev/null
then
echo "Please check docker and docker-compose install or not."
exit $DOCKER_CODE
elif ! which docker-compose &>/dev/null
then
echo "Please check docker-compose install or not."
exit $DOCKER_COMPOSE_CODE
elif [ `ps aux|grep dockerd|grep -v grep|wc -l` -ne 1 ]
then
echo "Please check doceker start or not."
exit $DOCKER_START
fi
# Modify the ip and mail setting for the yml files
ARG_CODE=13
if [ $# -ne 6 ]
then
echo "Usage: bash `basename $0` <install dir> <host ip> <smtp server:port> <mail sender> <sender password> <receiver>"
echo 'e.g.'
echo "bash `basename $0` /home/openemr-monitor 192.168.2.111 smtp.gmail.com:587 [email protected] pass12 [email protected]"
exit $ARG_CODE
fi
# Install location
[ ! -d "$installDir" ] && mkdir $installDir/grafana/provisioning/{dashboards,datasources} -p
mkdir $installDir/prometheus -p
echo ' '
# Download the yml files
echo 'Downloading the configuration files...'
echo ' '
curl -L https://raw.githubusercontent.com/openemr/openemr-devops/master/utilities/openemr-monitor/prometheus/prometheus.yml > $installDir/prometheus/prometheus.yml
curl -L https://raw.githubusercontent.com/openemr/openemr-devops/master/utilities/openemr-monitor/prometheus/alert-rules.yml > $installDir/prometheus/alert-rules.yml
curl -L https://raw.githubusercontent.com/openemr/openemr-devops/master/utilities/openemr-monitor/alertmanager.yml > $installDir/alertmanager.yml
curl -L https://raw.githubusercontent.com/openemr/openemr-devops/master/utilities/openemr-monitor/docker-compose.yml > $installDir/docker-compose.yml
curl -L https://raw.githubusercontent.com/openemr/openemr-devops/master/utilities/openemr-monitor/grafana/provisioning/dashboards/dashboard-193.json > $installDir/grafana/provisioning/dashboards/dashboard-193.json
curl -L https://raw.githubusercontent.com/openemr/openemr-devops/master/utilities/openemr-monitor/grafana/provisioning/dashboards/dashboard.yml > $installDir/grafana/provisioning/dashboards/dashboard.yml
curl -L https://raw.githubusercontent.com/openemr/openemr-devops/master/utilities/openemr-monitor/grafana/provisioning/datasources/datasource.yml > $installDir/grafana/provisioning/datasources/datasource.yml
echo ' '
# Input Host ip
sed -i "s/hostIp/${hostIp}/g" ${installDir}/prometheus/prometheus.yml
sed -i "s/hostIp/${hostIp}/g" ${installDir}/grafana/provisioning/datasources/datasource.yml
# Input Smtp Server
sed -i "s/smtpServer/$smtpServer/g" ${installDir}/alertmanager.yml
# Input the sender email
sed -i "s/senderEmail/$senderEmail/g" ${installDir}/alertmanager.yml
sed -i "s/senderUsername/$senderEmail/g" ${installDir}/alertmanager.yml
# Input the sender email password
sed -i "s/senderLoginPassword/$emailPassword/g" ${installDir}/alertmanager.yml
# Input the receiver email
sed -i "s/receiverEmail/$receiverEmail/g" ${installDir}/alertmanager.yml
echo '******************************Check the Modification******************************'
echo "Setting in ${installDir}/prometheus/prometheus.yml file."
egrep "3001|3002|3003" ${installDir}/prometheus/prometheus.yml
echo ' '
echo "Setting in ${installDir}/grafana/provisioning/datasources/datasource.yml file."
grep url ${installDir}/grafana/provisioning/datasources/datasource.yml
echo ' '
echo "Setting in ${installDir}/alertmanager.yml file."
egrep 'smtp|to' ${installDir}/alertmanager.yml
echo '**********************************************************************************'
echo ''
echo '=======================Startup========================'
echo 'Please run below commands to startup the monitor env:'
echo "cd ${installDir} && docker-compose up"
echo '======================================================'