/* * RestAPI.h * * Created on: 22.05.2019 * Author: Micha Mueller */ #ifndef DCDBPUSHER_RESTAPI_H_ #define DCDBPUSHER_RESTAPI_H_ #include "RESTHttpsServer.h" #include #include "includes/PluginDefinitions.h" #include "globalconfiguration.h" #include "../analytics/AnalyticsManager.h" #include "mqttchecker.h" #include "MQTTPusher.h" class RestAPI : public RESTHttpsServer { public: RestAPI(serverSettings_t settings, pluginVector_t& plugins, MQTTPusher* mqttPusher, AnalyticsManager* manager, boost::asio::io_service& io); virtual ~RestAPI() {} // String used as a response for the REST GET /help command const string restCheatSheet = "dcdbpusher RESTful API cheatsheet:\n" " -GET: /help This help message.\n" " /analytics/help An help message for data analytics commands.\n" " /plugins?[json] D List of currently loaded plugins.\n" " /sensors?plugin;[json]\n" " D List of currently running sensors which belong to\n" " the specified plugin.\n" " /average?plugin;sensor;[interval]\n" " Average of last sensor readings from the last\n" " [interval] seconds or of all cached readings if no\n" " interval is given.\n" " -PUT: /start?plugin Start the sensors of the plugin.\n" " /stop?plugin Stop the sensors of the plugin.\n" " /reload?plugin Reload the plugin configuration.\n" "\n"; private: /** * GET "/help" * * @brief Return a cheatsheet of possible REST API endpoints. * * Queries | key | possible values | explanation * ------------------------------------------------------------------------- * Required | - | - | - * Optional | - | - | - */ void GET_help(endpointArgs); /** * GET "/plugins" * * @brief List all loaded dcdbpusher plugins. * * Queries | key | possible values | explanation * ------------------------------------------------------------------------- * Required | - | - | - * Optional | json | true | format response as json */ void GET_plugins(endpointArgs); /** * GET "/sensors" * * @brief List all sensors of a specific plugin. * * Queries | key | possible values | explanation * ------------------------------------------------------------------------- * Required | plugin | all plugin names | specify the plugin * Optional | json | true | format response as json */ void GET_sensors(endpointArgs); /** * GET "/average" * * @brief Get the average of the last readings of a sensor. Also allows * access to analytics sensors. * * Queries | key | possible values | explanation * ------------------------------------------------------------------------- * Required | plugin | all plugin names | specify the plugin * | sensor | all sensor names of | specify the sensor within the * | | the plugin or the | plugin * | | analytics manager | * Optional | interval| number of seconds | use only readings more recent * | | | than (now - interval) for * | | | average calculation */ void GET_average(endpointArgs); /******************************************************************************/ /** * PUT "/start" * * @brief Start a plugin. * * Queries | key | possible values | explanation * ------------------------------------------------------------------------- * Required | plugin | all plugin names | specify the plugin * Optional | - | - | - */ void PUT_start(endpointArgs); /** * PUT "/stop" * * @brief Stop a plugin. * * Queries | key | possible values | explanation * ------------------------------------------------------------------------- * Required | plugin | all plugin names | specify the plugin * Optional | - | - | - */ void PUT_stop(endpointArgs); /** * PUT "/reload" * * @brief Reload a plugin's configuration (includes plugin restart). * * Queries | key | possible values | explanation * ------------------------------------------------------------------------- * Required | plugin | all plugin names | specify the plugin * Optional | - | - | - */ void PUT_reload(endpointArgs); /** * PUT "/analytics/reload" * * @brief Reload configuration and initialization of all or only a specific * analytics plugin. * * @detail Overwrites the method from the AnalyticsManager to ensure that * MQTTPusher is stopped before reloading plugins. * * Queries | key | possible values | explanation * ------------------------------------------------------------------------- * Required | - | - | - * Optional | plugin | all analyzer plugin | reload only the specified * | | names | plugin */ void PUT_analytics_reload(endpointArgs); /******************************************************************************/ // Utility method to remove all MQTT topics associated to a plugin from the used set void removeTopics(dl_t p); // Utility method to check for the validity of all MQTT topics in a plugin bool checkTopics(dl_t p); pluginVector_t& _plugins; MQTTPusher* _mqttPusher; AnalyticsManager* _manager; boost::asio::io_service& _io; }; #endif /* DCDBPUSHER_RESTAPI_H_ */