[MXS-2792] Documentation for MaxScale's monitor script is incomplete Created: 2019-12-09  Updated: 2020-01-08  Resolved: 2020-01-08

Status: Closed
Project: MariaDB MaxScale
Component/s: Documentation, Monitor
Affects Version/s: 2.3.15, 2.4.4
Fix Version/s: 2.3.16, 2.4.6

Type: Bug Priority: Major
Reporter: Geoff Montee (Inactive) Assignee: Esa Korhonen
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MXS-121 Ability to launch external scripts fr... Closed
relates to MXS-1445 Add script variables Closed
relates to MXS-2791 Special arguments are not passed to M... Closed
Sprint: MXS-SPRINT-96, MXS-SPRINT-97

 Description   

The documentation for MaxScale's monitor script seems to be incomplete:

https://mariadb.com/kb/en/mariadb-maxscale-24-common-monitor-parameters/#script

https://mariadb.com/kb/en/mariadb-maxscale-23-common-monitor-parameters/#script

It is missing the following items:

1.) It is missing the $CREDENTIALS argument:

https://github.com/mariadb-corporation/MaxScale/blob/maxscale-2.4.4/server/core/monitor.cc#L1086

2.) It is missing a working example script:

The MariaDB Monitor page for MaxScale 2.3 currently has an example script:

https://mariadb.com/kb/en/mariadb-maxscale-23-mariadb-monitor/#example-1-monitor-script

However, this script doesn't even work. It results in an error like this:

line 5: ${$2/.*=/}: bad substitution

We should probably add a working example to the "Common Monitor Parameters" page.

For example, if we had the following monitor configured:

[Galera-Monitor]
type=monitor
module=galeramon
servers=C1N1,
        C1N2,
        C1N3
user=maxscale
password=password
monitor_interval=10000
script=/path/to/maxscale_monitor_alert_script.sh --initiator=$INITIATOR --parent=$PARENT --children=$CHILDREN --event=$EVENT --node_list=$NODELIST --list=$LIST --master_list=$MASTERLIST --slave_list=$SLAVELIST --synced_list=$SYNCEDLIST

Then the following script makes a good example:

#!/usr/bin/env bash
 
initiator=""
parent=""
children=""
event=""
# credentials aren't needed for an alert script
#credentials=""
node_list=""
list=""
master_list=""
slave_list=""
synced_list=""
 
process_arguments()
{
   while [ "$1" != "" ]; do
      if [[ "$1" =~ ^--initiator=.* ]]; then
         initiator=${1#'--initiator='}
      elif [[ "$1" =~ ^--parent.* ]]; then
         parent=${1#'--parent='}
      elif [[ "$1" =~ ^--children.* ]]; then
         children=${1#'--children='}
      elif [[ "$1" =~ ^--event.* ]]; then
         event=${1#'--event='}
#      elif [[ "$1" =~ ^--credentials.* ]]; then
#         credentials=${1#'--credentials='}
      elif [[ "$1" =~ ^--node_list.* ]]; then
         node_list=${1#'--node_list='}
      elif [[ "$1" =~ ^--list.* ]]; then
         list=${1#'--list='}
      elif [[ "$1" =~ ^--master_list.* ]]; then
         master_list=${1#'--master_list='}
      elif [[ "$1" =~ ^--slave_list.* ]]; then
         slave_list=${1#'--slave_list='}
      elif [[ "$1" =~ ^--synced_list.* ]]; then
         synced_list=${1#'--synced_list='}
      fi
      shift
   done
}
 
process_arguments $@
 
read -r -d '' MESSAGE << EOM
A server has changed state. The following information was provided:
 
Initiator: $initiator
Parent: $parent
Children: $children
Event: $event
Node list: $node_list
List: $list
Master list: $master_list
Slave list: $slave_list
Synced list: $synced_list
EOM
 
echo "$MESSAGE" | mail -s "MaxScale received $event event for initiator $initiator." mariadb_admin@domain.com


Generated at Thu Feb 08 04:16:43 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.