Commit 746484e5 authored by Alessio Netti's avatar Alessio Netti
Browse files

WIP: string MQTT topics in collectagent

parent 2b89e833
......@@ -140,8 +140,7 @@ void AnalyticsController::run() {
bool AnalyticsController::publishSensors() {
// Performing auto-publish (if required) for the sensors instantiated by the data analytics framework
if(_settings.pluginSettings.sensorPattern=="")
return false;
if(!_settings.pluginSettings.autoPublish) return false;
DCDB::SCError err;
vector<an_dl_t>& _analyticsPlugins = _manager->getPlugins();
......
......@@ -264,9 +264,7 @@ struct httpHandler_t {
//try getting the latest value
try {
//TODO: switch from SID input to sensor name input
int64_t val = mySensorCache.getSensor(pathStrs[0], (uint64_t) time * 1000000000);
connection->set_status(httpServer_t::connection::ok);
response = "collectagent::" + pathStrs[0] + " Average of last " +
std::to_string(time) + " seconds is " + std::to_string(val);
......@@ -437,12 +435,11 @@ void usage() {
012345678901234567890123456789012345678901234567890123456789012345678901234567890
*/
cout << "Usage:" << endl;
cout << " collectagent [-d] [-s] [-x] [-a<string>] [-m<host>] [-c<host>] [-u<username>] [-p<password>] [-t<ttl>] [-v<verbosity>] <path/to/configfiles/>" << endl;
cout << " collectagent [-d] [-s] [-x] [-a] [-m<host>] [-c<host>] [-u<username>] [-p<password>] [-t<ttl>] [-v<verbosity>] <path/to/configfiles/>" << endl;
cout << " collectagent -h" << endl;
cout << endl;
cout << "Options:" << endl;
cout << " -a <string> Auto-publish pattern [default: none]" << endl;
cout << " -m<host> MQTT listen address [default: " << config.mqttListenHost << ":" << config.mqttListenPort << "]" << endl;
cout << " -c<host> Cassandra host [default: " << config.cassandraSettings.host << ":" << config.cassandraSettings.port << "]" << endl;
cout << " -u<username> Cassandra username [default: none]" << endl;
......@@ -454,6 +451,7 @@ void usage() {
cout << " -d Daemonize" << endl;
cout << " -s Print message stats" <<endl;
cout << " -x Parse and print the config but do not actually start collectagent" << endl;
cout << " -a Enable sensor auto-publish" << endl;
cout << " -h This help page" << endl;
cout << endl;
}
......@@ -471,7 +469,7 @@ int main(int argc, char* const argv[]) {
}
// Defining options
const char* opts = "a:m:r:c:C:u:p:t:v:dDsxh";
const char* opts = "m:r:c:C:u:p:t:v:dDsaxh";
// Same mechanism as in DCDBPusher - checking if help string is requested before loading config
char ret;
......@@ -508,7 +506,7 @@ int main(int argc, char* const argv[]) {
while ((ret=getopt(argc, argv, opts))!=-1) {
switch(ret) {
case 'a':
pluginSettings.sensorPattern = optarg;
pluginSettings.autoPublish = true;
break;
case 'm':
settings.mqttListenHost = parseNetworkHost(optarg);
......@@ -631,6 +629,7 @@ int main(int argc, char* const argv[]) {
LOG(info) << " Daemonize: " << (settings.daemonize ? "Enabled" : "Disabled");
LOG(info) << " Statistics: " << (settings.statistics ? "Enabled" : "Disabled");
LOG(info) << " MQTT-prefix: " << pluginSettings.mqttPrefix;
LOG(info) << " Auto-publish: " << (pluginSettings.autoPublish ? "Enabled" : "Disabled");
LOG(info) << " Write-Dir: " << pluginSettings.tempdir;
LOG(info) << (settings.validateConfig ? " Only validating config files." : " ValidateConfig: Disabled");
......
......@@ -51,7 +51,7 @@ int64_t SensorCache::getSensor(SensorId sid, uint64_t avg) {
}
int64_t SensorCache::getSensor(std::string topic, uint64_t avg) {
topic.erase(std::remove(topic.begin(), topic.end(), '/'), topic.end());
//topic.erase(std::remove(topic.begin(), topic.end(), '/'), topic.end());
size_t wp = topic.find("*");
if (wp == std::string::npos) {
......@@ -60,6 +60,7 @@ int64_t SensorCache::getSensor(std::string topic, uint64_t avg) {
int wl = 29 - topic.length();
//TODO: the wildcard part will likely not be supported with string topics
/* Create SensorIds with the lowest and highest values matching the wildcard */
DCDB::SensorId sidLow(std::string(topic).replace(wp, 1, std::string(wl, '0')));
DCDB::SensorId sidHi(std::string(topic).replace(wp, 1, std::string(wl, 'f')));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment