diff --git a/include/maxscale/monitor.h b/include/maxscale/monitor.h index af8a7e9cf..727e844b4 100644 --- a/include/maxscale/monitor.h +++ b/include/maxscale/monitor.h @@ -218,9 +218,6 @@ typedef enum NEW_NDB_EVENT = (1 << 21), /**< new_ndb */ } mxs_monitor_event_t; -// Bitmask value that matches all events, used for the "all" enum value -static const uint64_t ALL_MONITOR_EVENTS = ~0; - /** * The linked list of servers that are being monitored by the monitor module. */ @@ -267,6 +264,8 @@ struct mxs_monitor bool active; /**< True if monitor is active */ time_t journal_max_age; /**< Maximum age of journal file */ uint32_t script_timeout; /**< Timeout in seconds for the monitor scripts */ + const char* script; /**< Launchable script. */ + uint64_t events; /**< Enabled monitor events. */ uint8_t journal_hash[SHA_DIGEST_LENGTH]; /**< SHA1 hash of the latest written journal */ MxsDiskSpaceThreshold* disk_space_threshold; /**< Disk space thresholds */ int64_t disk_space_check_interval; /**< How often should a disk space check be made at most. */ @@ -274,40 +273,6 @@ struct mxs_monitor struct mxs_monitor *next; /**< Next monitor in the linked list */ }; -static const MXS_ENUM_VALUE mxs_monitor_event_enum_values[] = -{ - {"master_down", MASTER_DOWN_EVENT}, - {"master_up", MASTER_UP_EVENT}, - {"slave_down", SLAVE_DOWN_EVENT}, - {"slave_up", SLAVE_UP_EVENT}, - {"server_down", SERVER_DOWN_EVENT}, - {"server_up", SERVER_UP_EVENT}, - {"synced_down", SYNCED_DOWN_EVENT}, - {"synced_up", SYNCED_UP_EVENT}, - {"donor_down", DONOR_DOWN_EVENT}, - {"donor_up", DONOR_UP_EVENT}, - {"ndb_down", NDB_DOWN_EVENT}, - {"ndb_up", NDB_UP_EVENT}, - {"lost_master", LOST_MASTER_EVENT}, - {"lost_slave", LOST_SLAVE_EVENT}, - {"lost_synced", LOST_SYNCED_EVENT}, - {"lost_donor", LOST_DONOR_EVENT}, - {"lost_ndb", LOST_NDB_EVENT}, - {"new_master", NEW_MASTER_EVENT}, - {"new_slave", NEW_SLAVE_EVENT}, - {"new_synced", NEW_SYNCED_EVENT}, - {"new_donor", NEW_DONOR_EVENT}, - {"new_ndb", NEW_NDB_EVENT}, - {"all", ALL_MONITOR_EVENTS}, - {NULL} -}; - -/** Default value for the `events` parameter */ -static const char MXS_MONITOR_EVENT_DEFAULT_VALUE[] = "master_down,master_up,slave_down," - "slave_up,server_down,server_up,synced_down,synced_up,donor_down,donor_up," - "ndb_down,ndb_up,lost_master,lost_slave,lost_synced,lost_donor,lost_ndb," - "new_master,new_slave,new_synced,new_donor,new_ndb"; - /** * Monitor configuration parameters names */ diff --git a/include/maxscale/monitor.hh b/include/maxscale/monitor.hh index 64d75c53e..ce3616459 100644 --- a/include/maxscale/monitor.hh +++ b/include/maxscale/monitor.hh @@ -114,9 +114,6 @@ public: protected: MonitorInstance(MXS_MONITOR* pMonitor); - const std::string& script() const { return m_script; } - uint64_t events() const { return m_events; } - /** * @brief Should the monitor shut down? * @@ -215,8 +212,6 @@ private: int32_t m_state; /**< The current state of the monitor. */ int32_t m_shutdown; /**< Non-zero if the monitor should shut down. */ bool m_checked; /**< Whether server access has been checked. */ - std::string m_script; /**< Launchable script. */ - uint64_t m_events; /**< Enabled monitor events. */ Semaphore m_semaphore; /**< Semaphore for synchronizing with monitor thread. */ int64_t m_loop_called; /**< When was the loop called the last time. */ diff --git a/server/core/config.cc b/server/core/config.cc index ab37388fb..53f952596 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -308,20 +308,30 @@ const MXS_MODULE_PARAM config_monitor_params[] = { {CN_TYPE, MXS_MODULE_PARAM_STRING, NULL, MXS_MODULE_OPT_REQUIRED}, {CN_MODULE, MXS_MODULE_PARAM_STRING, NULL, MXS_MODULE_OPT_REQUIRED}, + {CN_USER, MXS_MODULE_PARAM_STRING, NULL, MXS_MODULE_OPT_REQUIRED}, {CN_PASSWORD, MXS_MODULE_PARAM_STRING, NULL, MXS_MODULE_OPT_REQUIRED}, + {CN_SERVERS, MXS_MODULE_PARAM_STRING}, - {CN_SCRIPT, MXS_MODULE_PARAM_STRING}, - {CN_EVENTS, MXS_MODULE_PARAM_ENUM, "all", 0, mxs_monitor_event_enum_values}, {CN_MONITOR_INTERVAL, MXS_MODULE_PARAM_COUNT, "2000"}, - {CN_JOURNAL_MAX_AGE, MXS_MODULE_PARAM_COUNT, "28800"}, - {CN_SCRIPT_TIMEOUT, MXS_MODULE_PARAM_COUNT, "90"}, {CN_BACKEND_CONNECT_TIMEOUT, MXS_MODULE_PARAM_COUNT, "3"}, {CN_BACKEND_READ_TIMEOUT, MXS_MODULE_PARAM_COUNT, "1"}, {CN_BACKEND_WRITE_TIMEOUT, MXS_MODULE_PARAM_COUNT, "2"}, {CN_BACKEND_CONNECT_ATTEMPTS, MXS_MODULE_PARAM_COUNT, "1"}, + + {CN_JOURNAL_MAX_AGE, MXS_MODULE_PARAM_COUNT, "28800"}, {CN_DISK_SPACE_THRESHOLD, MXS_MODULE_PARAM_STRING}, {CN_DISK_SPACE_CHECK_INTERVAL, MXS_MODULE_PARAM_COUNT, "0"}, + + {CN_SCRIPT, MXS_MODULE_PARAM_STRING}, // Cannot be a path type as the script may have parameters + {CN_SCRIPT_TIMEOUT, MXS_MODULE_PARAM_COUNT, "90"}, + { + CN_EVENTS, + MXS_MODULE_PARAM_ENUM, + mxs_monitor_event_default_enum.name, + MXS_MODULE_OPT_NONE, + mxs_monitor_event_enum_values + }, {NULL} }; diff --git a/server/core/internal/monitor.h b/server/core/internal/monitor.h index adfdf4152..b3f8c9419 100644 --- a/server/core/internal/monitor.h +++ b/server/core/internal/monitor.h @@ -47,6 +47,37 @@ typedef enum MONITOR_CONNECT_ATTEMPTS = 3 } monitor_timeouts_t; +/* Is not really an event as the other values, but is a valid config setting and also the default. + * Bitmask value matches all events. */ +static const MXS_ENUM_VALUE mxs_monitor_event_default_enum = {"all", ~0ULL}; +static const MXS_ENUM_VALUE mxs_monitor_event_enum_values[] = +{ + mxs_monitor_event_default_enum, + {"master_down", MASTER_DOWN_EVENT}, + {"master_up", MASTER_UP_EVENT}, + {"slave_down", SLAVE_DOWN_EVENT}, + {"slave_up", SLAVE_UP_EVENT}, + {"server_down", SERVER_DOWN_EVENT}, + {"server_up", SERVER_UP_EVENT}, + {"synced_down", SYNCED_DOWN_EVENT}, + {"synced_up", SYNCED_UP_EVENT}, + {"donor_down", DONOR_DOWN_EVENT}, + {"donor_up", DONOR_UP_EVENT}, + {"ndb_down", NDB_DOWN_EVENT}, + {"ndb_up", NDB_UP_EVENT}, + {"lost_master", LOST_MASTER_EVENT}, + {"lost_slave", LOST_SLAVE_EVENT}, + {"lost_synced", LOST_SYNCED_EVENT}, + {"lost_donor", LOST_DONOR_EVENT}, + {"lost_ndb", LOST_NDB_EVENT}, + {"new_master", NEW_MASTER_EVENT}, + {"new_slave", NEW_SLAVE_EVENT}, + {"new_synced", NEW_SYNCED_EVENT}, + {"new_donor", NEW_DONOR_EVENT}, + {"new_ndb", NEW_NDB_EVENT}, + {NULL} +}; + MXS_MONITOR *monitor_create(const char *, const char *, MXS_CONFIG_PARAMETER* params); void monitor_destroy(MXS_MONITOR *); diff --git a/server/core/monitor.cc b/server/core/monitor.cc index 48e76e79f..e8057e222 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -134,6 +134,8 @@ MXS_MONITOR* monitor_create(const char *name, const char *module, MXS_CONFIG_PAR mon->interval = config_get_integer(params, CN_MONITOR_INTERVAL); mon->journal_max_age = config_get_integer(params, CN_JOURNAL_MAX_AGE); mon->script_timeout = config_get_integer(params, CN_SCRIPT_TIMEOUT); + mon->script = config_get_string(params, CN_SCRIPT); + mon->events = config_get_enum(params, CN_EVENTS, mxs_monitor_event_enum_values); mon->check_maintenance_flag = MAINTENANCE_FLAG_NOCHECK; mon->ticks = 0; mon->parameters = NULL; @@ -1077,13 +1079,13 @@ const char* mon_get_event_name(mxs_monitor_event_t event) { for (int i = 0; mxs_monitor_event_enum_values[i].name; i++) { - if (mxs_monitor_event_enum_values[i].enum_value & event) + if (mxs_monitor_event_enum_values[i].enum_value == event) { return mxs_monitor_event_enum_values[i].name; } } - ss_dassert(false); + ss_dassert(!true); return "undefined_event"; } @@ -1788,7 +1790,6 @@ static const char* monitor_state_to_string(int state) json_t* monitor_parameters_to_json(const MXS_MONITOR* monitor) { json_t* rval = json_object(); - json_object_set_new(rval, CN_USER, json_string(monitor->user)); json_object_set_new(rval, CN_PASSWORD, json_string(monitor->password)); json_object_set_new(rval, CN_MONITOR_INTERVAL, json_integer(monitor->interval)); @@ -1797,18 +1798,14 @@ json_t* monitor_parameters_to_json(const MXS_MONITOR* monitor) json_object_set_new(rval, CN_BACKEND_WRITE_TIMEOUT, json_integer(monitor->write_timeout)); json_object_set_new(rval, CN_BACKEND_CONNECT_ATTEMPTS, json_integer(monitor->connect_attempts)); json_object_set_new(rval, CN_JOURNAL_MAX_AGE, json_integer(monitor->journal_max_age)); + // TODO: print disk_space_threshold + json_object_set_new(rval, CN_DISK_SPACE_CHECK_INTERVAL, json_integer(monitor->disk_space_check_interval)); + json_object_set_new(rval, CN_SCRIPT, json_string(monitor->script)); json_object_set_new(rval, CN_SCRIPT_TIMEOUT, json_integer(monitor->script_timeout)); - + // TODO: print events /** Add custom module parameters */ const MXS_MODULE* mod = get_module(monitor->module_name, MODULE_MONITOR); config_add_module_params_json(mod, monitor->parameters, config_monitor_params, rval); - - /** Don't show the default value for events if no script is defined */ - if (json_object_get(rval, CN_SCRIPT) == NULL) - { - json_object_del(rval, CN_EVENTS); - } - return rval; } @@ -2486,7 +2483,6 @@ MonitorInstance::MonitorInstance(MXS_MONITOR* pMonitor) , m_state(MXS_MONITOR_STOPPED) , m_shutdown(0) , m_checked(false) - , m_events(0) , m_loop_called(0) { } @@ -2524,35 +2520,7 @@ void MonitorInstance::diagnostics(DCB* pDcb) const json_t* MonitorInstance::diagnostics_json() const { - json_t* pJson = json_object(); - - if (!m_script.empty()) - { - json_object_set_new(pJson, CN_SCRIPT, json_string(m_script.c_str())); - - string events; - - const MXS_ENUM_VALUE* pValue = mxs_monitor_event_enum_values; - - while (pValue->name) - { - if (pValue->enum_value & m_events) - { - if (!events.empty()) - { - events += ","; - } - - events += pValue->enum_value; - } - - ++pValue; - } - - json_object_set_new(pJson, CN_EVENTS, json_string(events.c_str())); - } - - return pJson; + return NULL; } bool MonitorInstance::start(const MXS_CONFIG_PARAMETER* pParams) @@ -2578,8 +2546,6 @@ bool MonitorInstance::start(const MXS_CONFIG_PARAMETER* pParams) if (m_checked) { - m_script = config_get_string(pParams, CN_SCRIPT); - m_events = config_get_enum(pParams, CN_EVENTS, mxs_monitor_event_enum_values); m_master = NULL; if (configure(pParams)) @@ -2889,7 +2855,7 @@ void MonitorInstance::post_loop() void MonitorInstance::process_state_changes() { - mon_process_state_changes(m_monitor, m_script.empty() ? NULL : m_script.c_str(), m_events); + mon_process_state_changes(m_monitor, m_monitor->script, m_monitor->events); } bool MonitorInstance::pre_run() diff --git a/server/modules/monitor/auroramon/auroramon.cc b/server/modules/monitor/auroramon/auroramon.cc index 9fadbdebf..b4bf1e6c8 100644 --- a/server/modules/monitor/auroramon/auroramon.cc +++ b/server/modules/monitor/auroramon/auroramon.cc @@ -110,19 +110,6 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE() NULL, /* Thread init. */ NULL, /* Thread finish. */ { - { - "script", - MXS_MODULE_PARAM_PATH, - NULL, - MXS_MODULE_OPT_PATH_X_OK - }, - { - "events", - MXS_MODULE_PARAM_ENUM, - MXS_MONITOR_EVENT_DEFAULT_VALUE, - MXS_MODULE_OPT_NONE, - mxs_monitor_event_enum_values - }, {MXS_END_MODULE_PARAMS} } }; diff --git a/server/modules/monitor/galeramon/galeramon.cc b/server/modules/monitor/galeramon/galeramon.cc index 45518f4e3..d0600f80b 100644 --- a/server/modules/monitor/galeramon/galeramon.cc +++ b/server/modules/monitor/galeramon/galeramon.cc @@ -764,19 +764,6 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE() {"disable_master_role_setting", MXS_MODULE_PARAM_BOOL, "false"}, {"root_node_as_master", MXS_MODULE_PARAM_BOOL, "false"}, {"use_priority", MXS_MODULE_PARAM_BOOL, "false"}, - { - "script", - MXS_MODULE_PARAM_PATH, - NULL, - MXS_MODULE_OPT_PATH_X_OK - }, - { - "events", - MXS_MODULE_PARAM_ENUM, - MXS_MONITOR_EVENT_DEFAULT_VALUE, - MXS_MODULE_OPT_NONE, - mxs_monitor_event_enum_values - }, {"set_donor_nodes", MXS_MODULE_PARAM_BOOL, "false"}, {MXS_END_MODULE_PARAMS} } diff --git a/server/modules/monitor/grmon/grmon.cc b/server/modules/monitor/grmon/grmon.cc index 442787d5a..b3600f4de 100644 --- a/server/modules/monitor/grmon/grmon.cc +++ b/server/modules/monitor/grmon/grmon.cc @@ -150,19 +150,6 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE() NULL, /* Thread init. */ NULL, /* Thread finish. */ { - { - "script", - MXS_MODULE_PARAM_PATH, - NULL, - MXS_MODULE_OPT_PATH_X_OK - }, - { - "events", - MXS_MODULE_PARAM_ENUM, - MXS_MONITOR_EVENT_DEFAULT_VALUE, - MXS_MODULE_OPT_NONE, - mxs_monitor_event_enum_values - }, {MXS_END_MODULE_PARAMS} } }; diff --git a/server/modules/monitor/mariadbmon/mariadbmon.cc b/server/modules/monitor/mariadbmon/mariadbmon.cc index b946dc30f..52984686c 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon.cc +++ b/server/modules/monitor/mariadbmon/mariadbmon.cc @@ -209,8 +209,6 @@ bool MariaDBMonitor::configure(const MXS_CONFIG_PARAMETER* params) m_ignore_external_masters = config_get_bool(params, "ignore_external_masters"); m_detect_standalone_master = config_get_bool(params, CN_DETECT_STANDALONE_MASTER); m_failcount = config_get_integer(params, CN_FAILCOUNT); - m_script = config_get_string(params, "script"); - m_events = config_get_enum(params, "events", mxs_monitor_event_enum_values); m_failover_timeout = config_get_integer(params, CN_FAILOVER_TIMEOUT); m_switchover_timeout = config_get_integer(params, CN_SWITCHOVER_TIMEOUT); m_auto_failover = config_get_bool(params, CN_AUTO_FAILOVER); @@ -324,26 +322,6 @@ json_t* MariaDBMonitor::diagnostics_to_json() const { json_t* rval = json_object(); json_object_set_new(rval, "monitor_id", json_integer(m_id)); - json_object_set_new(rval, "detect_stale_master", json_boolean(m_detect_stale_master)); - json_object_set_new(rval, "detect_stale_slave", json_boolean(m_detect_stale_slave)); - json_object_set_new(rval, "detect_replication_lag", json_boolean(m_detect_replication_lag)); - json_object_set_new(rval, CN_DETECT_STANDALONE_MASTER, json_boolean(m_detect_standalone_master)); - json_object_set_new(rval, CN_FAILCOUNT, json_integer(m_failcount)); - json_object_set_new(rval, CN_AUTO_FAILOVER, json_boolean(m_auto_failover)); - json_object_set_new(rval, CN_FAILOVER_TIMEOUT, json_integer(m_failover_timeout)); - json_object_set_new(rval, CN_SWITCHOVER_TIMEOUT, json_integer(m_switchover_timeout)); - json_object_set_new(rval, CN_AUTO_REJOIN, json_boolean(m_auto_rejoin)); - json_object_set_new(rval, CN_ENFORCE_READONLY, json_boolean(m_enforce_read_only_slaves)); - - if (!m_script.empty()) - { - json_object_set_new(rval, "script", json_string(m_script.c_str())); - } - if (m_excluded_servers.size() > 0) - { - string list = monitored_servers_to_string(m_excluded_servers); - json_object_set_new(rval, CN_NO_PROMOTE_SERVERS, json_string(list.c_str())); - } if (!m_servers.empty()) { @@ -1283,19 +1261,6 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE() {CN_FAILCOUNT, MXS_MODULE_PARAM_COUNT, "5"}, {"allow_cluster_recovery", MXS_MODULE_PARAM_BOOL, "true", MXS_MODULE_OPT_DEPRECATED}, {"ignore_external_masters", MXS_MODULE_PARAM_BOOL, "false"}, - { - "script", - MXS_MODULE_PARAM_PATH, - NULL, - MXS_MODULE_OPT_PATH_X_OK - }, - { - "events", - MXS_MODULE_PARAM_ENUM, - MXS_MONITOR_EVENT_DEFAULT_VALUE, - MXS_MODULE_OPT_NONE, - mxs_monitor_event_enum_values - }, {CN_AUTO_FAILOVER, MXS_MODULE_PARAM_BOOL, "false"}, {CN_FAILOVER_TIMEOUT, MXS_MODULE_PARAM_COUNT, "90"}, {CN_SWITCHOVER_TIMEOUT, MXS_MODULE_PARAM_COUNT, "90"}, diff --git a/server/modules/monitor/mariadbmon/mariadbmon.hh b/server/modules/monitor/mariadbmon/mariadbmon.hh index 7c53d9aac..2fd9a0505 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon.hh +++ b/server/modules/monitor/mariadbmon/mariadbmon.hh @@ -171,8 +171,6 @@ private: * maintenance. */ // Other settings - std::string m_script; /**< Script to call when state changes occur on servers */ - uint64_t m_events; /**< enabled events */ bool m_log_no_master; /**< Should it be logged that there is no master */ bool m_warn_no_valid_in_cycle; /**< Log a warning when a replication cycle has no valid master */ bool m_warn_no_valid_outside_cycle; /**< Log a warning when a replication topology has no valid master diff --git a/server/modules/monitor/mmmon/mmmon.cc b/server/modules/monitor/mmmon/mmmon.cc index a16806013..7efe090f4 100644 --- a/server/modules/monitor/mmmon/mmmon.cc +++ b/server/modules/monitor/mmmon/mmmon.cc @@ -433,19 +433,6 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE() NULL, /* Thread finish. */ { {"detect_stale_master", MXS_MODULE_PARAM_BOOL, "false"}, - { - "script", - MXS_MODULE_PARAM_PATH, - NULL, - MXS_MODULE_OPT_PATH_X_OK - }, - { - "events", - MXS_MODULE_PARAM_ENUM, - MXS_MONITOR_EVENT_DEFAULT_VALUE, - MXS_MODULE_OPT_NONE, - mxs_monitor_event_enum_values - }, {MXS_END_MODULE_PARAMS} } }; diff --git a/server/modules/monitor/ndbclustermon/ndbclustermon.cc b/server/modules/monitor/ndbclustermon/ndbclustermon.cc index 225e5c67d..3b4e577f5 100644 --- a/server/modules/monitor/ndbclustermon/ndbclustermon.cc +++ b/server/modules/monitor/ndbclustermon/ndbclustermon.cc @@ -148,19 +148,6 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE() NULL, /* Thread init. */ NULL, /* Thread finish. */ { - { - "script", - MXS_MODULE_PARAM_PATH, - NULL, - MXS_MODULE_OPT_PATH_X_OK - }, - { - "events", - MXS_MODULE_PARAM_ENUM, - MXS_MONITOR_EVENT_DEFAULT_VALUE, - MXS_MODULE_OPT_NONE, - mxs_monitor_event_enum_values - }, {MXS_END_MODULE_PARAMS} // No parameters } };