-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql_monitoring.jps
159 lines (139 loc) · 4.23 KB
/
mysql_monitoring.jps
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
version: 7.3.2
build: 20221125
type: update
name: 'Mysql Replication Monitoring'
id: 'Replication_monitoring'
baseUrl: https://raw.githubusercontent.com/layershift/mysql_replication_monitor/main
logo: /images/mysql-sync.png?_r=${fn.random}
targetNodes:
nodeType:
- mariadb
- mariadb-dockerized
- mariadb10
- mysql
- mysql5
- mysql8
categories:
- apps/others
description:
short: MySQL/MariaDB replication monitoring and alert
text: |
This add-on is intended to be installed on the slave nodes in MySQL/MariaDB database replication setups.
It will monitor and alert in case of replication issues.
globals:
message: ""
newline: "\n"
settings:
fields:
- type: string
caption: Database User
name: user
required: true
default: root
- type: string
caption: Database User Password
name: passwd
required: true
- type: string
caption: Alert recipient
name: alertRecipient
required: true
default:
tooltip: Multiple email addresses can be specified separated by ,
- type: string
name: appPass
inputType: hidden
value:
required: true
onBeforeInit: |
return {
"result": 0,
"settings": {
"fields": [{
"type": "string",
"name": "user",
"caption": "Database User",
"hideLabel": false,
"required": true,
"default": "root"
}, {
"type": "string",
"name": "passwd",
"caption": "Database User Password",
"hideLabel": false,
"required": true,
"default": ""
}, {
"type": "string",
"name": "alertRecipient",
"caption": "Alert recipient",
"hideLabel": false,
"required": true,
"default": "${user.email}",
"tooltip": "Multiple email addresses can be specified separated by ,"
}, {
"type": "string",
"name": "appPass",
"caption": "Database Script Password",
"value": com.hivext.api.utils.Random.getPswd(10),
"inputType": "hidden"
}]
}
};
menu:
- caption: Update
action: install_script
confirmText: Are you sure you wish to update the monitoring script?
loadingText: Updating...
buttons:
- caption: Check Replication status
action: checkReplicationStatus
confirmText: Are you sure you wish to check the replication status?
loadingText: Checking...
onInstall:
- install_script
- configure_script
- create_cron
onUninstall:
- remove_script
- remove_cron
actions:
install_script :
#This creates a copy of the monitoring script, and adds the "check_monit" mysql user
cmd[${targetNodes.nodeGroup}]:
- /bin/mkdir -p /opt/ls_tools
- /bin/curl -fsSL '${baseUrl}/scripts/replication_monitor.sh' -o /opt/ls_tools/replication_monitor.sh;
- chmod +x /opt/ls_tools/replication_monitor.sh;
user: root
configure_script:
cmd[${targetNodes.nodeGroup}]:
- /opt/ls_tools/replication_monitor.sh --create '${settings.user}' '${settings.passwd}' '${settings.alertRecipient}' '${settings.appPass}'
user: root
create_cron :
cmd[${targetNodes.nodeGroup}]:
- /bin/touch /etc/cron.d/replication_check
- /bin/echo "*/5 * * * * root /opt/ls_tools/replication_monitor.sh --check" > /etc/cron.d/replication_check
user: root
remove_script :
cmd[${targetNodes.nodeGroup}]:
- /opt/ls_tools/replication_monitor.sh --uninstall '${settings.user}' '${settings.passwd}'
- /usr/bin/rm -f /opt/ls_tools/replication_monitor.sh
user: root
remove_cron :
cmd[${targetNodes.nodeGroup}]:
- /usr/bin/rm -f /etc/cron.d/replication_check
user: root
checkReplicationStatus:
- setGlobals:
- message: ""
- forEach(node:targetNodes):
- cmd [${@node.id}]:
- /opt/ls_tools/replication_monitor.sh --status --short
user: root
- setGlobals:
message: ${globals.message}${globals.newline}${response.out}
- log:
- ${globals.message}
- message: ${globals.message}
script: |
return {result: 'info', message: message.replace(/\n/g, ' \n')}