diff --git a/plugins/monitor/monitor.json b/plugins/monitor/monitor.json index f12b887f..f70db11c 100644 --- a/plugins/monitor/monitor.json +++ b/plugins/monitor/monitor.json @@ -9,6 +9,16 @@ "length": 255 } }, + "heartbeat-interval": { + "name": "heartbeat interval (seconds)", + "description": "Interval in seconds between two heartbeat messages. Setting to zero will disable heartbeat monitoring.", + "attribute": "required", + "type": "int", + "default": 0, + "valid": { + "min": 0 + } + }, "heartbeat-topic": { "name": "heartbeat topic", "description": "Topic to which publish heartbeat messages.", diff --git a/plugins/monitor/monitor_config.c b/plugins/monitor/monitor_config.c index 40a35120..0153ebe3 100644 --- a/plugins/monitor/monitor_config.c +++ b/plugins/monitor/monitor_config.c @@ -126,25 +126,27 @@ int monitor_config_parse(neu_plugin_t *plugin, const char *setting, const char *placeholder = "********"; neu_json_elem_t client_id = { .name = "client-id", .t = NEU_JSON_STR }; - neu_json_elem_t heartbeat_topic = { .name = "heartbeat-topic", + neu_json_elem_t heartbeat_interval = { .name = "heartbeat-interval", + .t = NEU_JSON_INT }; + neu_json_elem_t heartbeat_topic = { .name = "heartbeat-topic", .t = NEU_JSON_STR }; - neu_json_elem_t host = { .name = "host", .t = NEU_JSON_STR }; - neu_json_elem_t port = { .name = "port", .t = NEU_JSON_INT }; - neu_json_elem_t username = { .name = "username", .t = NEU_JSON_STR }; - neu_json_elem_t password = { .name = "password", .t = NEU_JSON_STR }; - neu_json_elem_t ssl = { .name = "ssl", .t = NEU_JSON_BOOL }; - neu_json_elem_t ca = { .name = "ca", .t = NEU_JSON_STR }; - neu_json_elem_t cert = { .name = "cert", .t = NEU_JSON_STR }; - neu_json_elem_t key = { .name = "key", .t = NEU_JSON_STR }; - neu_json_elem_t keypass = { .name = "keypass", .t = NEU_JSON_STR }; + neu_json_elem_t host = { .name = "host", .t = NEU_JSON_STR }; + neu_json_elem_t port = { .name = "port", .t = NEU_JSON_INT }; + neu_json_elem_t username = { .name = "username", .t = NEU_JSON_STR }; + neu_json_elem_t password = { .name = "password", .t = NEU_JSON_STR }; + neu_json_elem_t ssl = { .name = "ssl", .t = NEU_JSON_BOOL }; + neu_json_elem_t ca = { .name = "ca", .t = NEU_JSON_STR }; + neu_json_elem_t cert = { .name = "cert", .t = NEU_JSON_STR }; + neu_json_elem_t key = { .name = "key", .t = NEU_JSON_STR }; + neu_json_elem_t keypass = { .name = "keypass", .t = NEU_JSON_STR }; if (NULL == setting || NULL == config) { plog_error(plugin, "invalid argument, null pointer"); return -1; } - ret = neu_parse_param(setting, &err_param, 4, &client_id, &heartbeat_topic, - &host, &port); + ret = neu_parse_param(setting, &err_param, 5, &client_id, + &heartbeat_interval, &heartbeat_topic, &host, &port); if (0 != ret) { plog_error(plugin, "parsing setting fail, key: `%s`", err_param); goto error; @@ -156,6 +158,13 @@ int monitor_config_parse(neu_plugin_t *plugin, const char *setting, goto error; } + // heartbeat-interval, required + if (0 > heartbeat_interval.v.val_int) { + plog_error(plugin, "setting negative heartbeat-interval:%" PRIi64, + heartbeat_interval.v.val_int); + goto error; + } + // heartbeat-topic, required if (0 == strlen(heartbeat_topic.v.val_str)) { plog_error(plugin, "setting empty heartbeat-topic"); @@ -191,40 +200,43 @@ int monitor_config_parse(neu_plugin_t *plugin, const char *setting, goto error; } - config->client_id = client_id.v.val_str; - config->heartbeat_topic = heartbeat_topic.v.val_str; - config->host = host.v.val_str; - config->port = port.v.val_int; - config->username = username.v.val_str; - config->password = password.v.val_str; - config->ca = ca.v.val_str; - config->cert = cert.v.val_str; - config->key = key.v.val_str; - config->keypass = keypass.v.val_str; + config->client_id = client_id.v.val_str; + config->heartbeat_interval = heartbeat_interval.v.val_int; + config->heartbeat_topic = heartbeat_topic.v.val_str; + config->host = host.v.val_str; + config->port = port.v.val_int; + config->username = username.v.val_str; + config->password = password.v.val_str; + config->ca = ca.v.val_str; + config->cert = cert.v.val_str; + config->key = key.v.val_str; + config->keypass = keypass.v.val_str; - plog_info(plugin, "config client-id : %s", config->client_id); - plog_info(plugin, "config heartbeat-topic: %s", config->heartbeat_topic); - plog_info(plugin, "config host : %s", config->host); - plog_info(plugin, "config port : %" PRIu16, config->port); + plog_info(plugin, "config client-id : %s", config->client_id); + plog_info(plugin, "config heartbeat-interval: %" PRIu64, + config->heartbeat_interval); + plog_info(plugin, "config heartbeat-topic : %s", config->heartbeat_topic); + plog_info(plugin, "config host : %s", config->host); + plog_info(plugin, "config port : %" PRIu16, config->port); if (config->username) { - plog_info(plugin, "config username : %s", config->username); + plog_info(plugin, "config username : %s", config->username); } if (config->password) { - plog_info(plugin, "config password : %s", + plog_info(plugin, "config password : %s", 0 == strlen(config->password) ? "" : placeholder); } if (config->ca) { - plog_info(plugin, "config ca : %s", placeholder); + plog_info(plugin, "config ca : %s", placeholder); } if (config->cert) { - plog_info(plugin, "config cert : %s", placeholder); + plog_info(plugin, "config cert : %s", placeholder); } if (config->key) { - plog_info(plugin, "config key : %s", placeholder); + plog_info(plugin, "config key : %s", placeholder); } if (config->keypass) { - plog_info(plugin, "config keypass : %s", placeholder); + plog_info(plugin, "config keypass : %s", placeholder); } return 0; diff --git a/plugins/monitor/monitor_config.h b/plugins/monitor/monitor_config.h index 63d26518..230f1f5e 100644 --- a/plugins/monitor/monitor_config.h +++ b/plugins/monitor/monitor_config.h @@ -30,16 +30,17 @@ extern "C" { #include "plugin.h" typedef struct { - char * client_id; // client id - char * heartbeat_topic; // heartbeat topic - char * host; // broker host - uint16_t port; // broker port - char * username; // user name - char * password; // user password - char * ca; // CA - char * cert; // client cert - char * key; // client key - char * keypass; // client key password + char * client_id; // client id + uint64_t heartbeat_interval; // heartbeat interval + char * heartbeat_topic; // heartbeat topic + char * host; // broker host + uint16_t port; // broker port + char * username; // user name + char * password; // user password + char * ca; // CA + char * cert; // client cert + char * key; // client key + char * keypass; // client key password } monitor_config_t; int monitor_config_parse(neu_plugin_t *plugin, const char *setting,