From befb25a14a697bc4ae580f7f9ce1a4b41c5b24e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 22 Aug 2018 22:34:07 +0300 Subject: [PATCH] MXS-1929: Add parameters to `maxctrl create monitor` The parameters for the monitor can now be defined when the monitor is created. This makes the filter, monitor and service creation consistent. --- .../MaxScale-2.3.0-Release-Notes.md | 6 ++++++ maxctrl/lib/create.js | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Documentation/Release-Notes/MaxScale-2.3.0-Release-Notes.md b/Documentation/Release-Notes/MaxScale-2.3.0-Release-Notes.md index 756efeff7..ba493d0b7 100644 --- a/Documentation/Release-Notes/MaxScale-2.3.0-Release-Notes.md +++ b/Documentation/Release-Notes/MaxScale-2.3.0-Release-Notes.md @@ -10,6 +10,12 @@ report at [Jira](https://jira.mariadb.org). ## Changed Features +### MaxCtrl `create monitor` + +The `create monitor` command now accepts a list of key-value parameters that are +passed to the monitor as the last argument. This allows creation and +configuration of monitors in one command. + ### `query_retries` The default value of `query_retries` was changed from 0 to 1. This turns diff --git a/maxctrl/lib/create.js b/maxctrl/lib/create.js index 1a6290168..45d869579 100644 --- a/maxctrl/lib/create.js +++ b/maxctrl/lib/create.js @@ -142,10 +142,12 @@ exports.builder = function(yargs) { describe: 'Password for the monitor user', type: 'string' }) - .command('monitor ', 'Create a new monitor', function(yargs) { + .command('monitor [params...]', 'Create a new monitor', function(yargs) { return yargs.epilog('The list of servers given with the --servers option should not ' + - 'contain any servers that are already monitored by another monitor.') - .usage('Usage: create monitor ') + 'contain any servers that are already monitored by another monitor. ' + + 'The last argument to this command is a list of key=value parameters ' + + 'given as the monitor parameters.') + .usage('Usage: create monitor [params...]') }, function(argv) { var monitor = { @@ -157,6 +159,15 @@ exports.builder = function(yargs) { } } + if (argv.params) { + var err = validateParams(argv, argv.params) + if (err) { + return Promise.reject(err) + } + + monitor.data.attributes.parameters = argv.params.reduce(to_obj, {}) + } + if (argv.servers) { for (i = 0; i < argv.servers.length; i++) { _.set(monitor, 'data.relationships.servers.data[' + i + ']', {id: argv.servers[i], type: 'servers'})