configuration.cpp 5.35 KB
Newer Older
1
2
3
//================================================================================
// Name        : configuration.cpp
// Author      : Alessio Netti
Micha Müller's avatar
Micha Müller committed
4
// Contact     : info@dcdb.it
5
6
7
8
9
10
11
12
13
14
15
16
// Copyright   : Leibniz Supercomputing Centre
// Description : Class responsible for reading collectagent specific configuration.
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2018-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
17
//
18
19
20
21
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
22
//
23
24
25
26
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//================================================================================
27
28
29

#include "configuration.h"

Alessio Netti's avatar
Alessio Netti committed
30
31
32
bool Configuration::readAdditionalValues(boost::property_tree::iptree::value_type &global) {
    // ----- READING ADDITIONAL GLOBAL SETTINGS -----
    if (boost::iequals(global.first, "mqttListenAddress")) {
Alessio Netti's avatar
Alessio Netti committed
33
34
        mqttListenHost = parseNetworkHost(global.second.data());
        mqttListenPort = parseNetworkPort(global.second.data());
35
        if(mqttListenPort=="") mqttListenPort = string(DEFAULT_LISTENPORT);
Alessio Netti's avatar
Alessio Netti committed
36
37
38
39
40
41
42
    } else if (boost::iequals(global.first, "cleaningInterval")) {
        cleaningInterval = stoul(global.second.data());
    } else if (boost::iequals(global.first, "messageThreads")) {
        messageThreads = stoul(global.second.data());
    } else if (boost::iequals(global.first, "messageSlots")) {
        messageSlots = stoul(global.second.data());
    } else {
43
44
        return false;
    }
Alessio Netti's avatar
Alessio Netti committed
45
46
    return true;
}
47

Alessio Netti's avatar
Alessio Netti committed
48
49
50
51
52
void Configuration::readAdditionalBlocks(boost::property_tree::iptree& cfg) {
    // ----- READING CASSANDRA SETTINGS -----
    if(cfg.find("cassandra") != cfg.not_found()) {
        BOOST_FOREACH(boost::property_tree::iptree::value_type & global, cfg.get_child("cassandra")) {
            if (boost::iequals(global.first, "address")) {
Alessio Netti's avatar
Alessio Netti committed
53
54
                cassandraSettings.host = parseNetworkHost(global.second.data());
                cassandraSettings.port = parseNetworkPort(global.second.data());
55
                if(cassandraSettings.port=="") cassandraSettings.port = string(DEFAULT_CASSANDRAPORT);
Alessio Netti's avatar
Alessio Netti committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
            } else if (boost::iequals(global.first, "username")) {
                cassandraSettings.username = global.second.data();
            } else if (boost::iequals(global.first, "password")) {
                cassandraSettings.password = global.second.data();
            } else if (boost::iequals(global.first, "ttl")) {
                cassandraSettings.ttl = stoul(global.second.data());
            } else if (boost::iequals(global.first, "numThreadsIo")) {
                cassandraSettings.numThreadsIo = stoul(global.second.data());
            } else if (boost::iequals(global.first, "queueSizeIo")) {
                cassandraSettings.queueSizeIo = stoul(global.second.data());
            } else if (boost::iequals(global.first, "coreConnPerHost")) {
                cassandraSettings.coreConnPerHost = stoul(global.second.data());
            } else if (boost::iequals(global.first, "debugLog")) {
                cassandraSettings.debugLog = to_bool(global.second.data());
            } else {
                LOG(warning) << "  Value \"" << global.first << "\" not recognized. Omitting";
72
            }
73
74
        }
    }
75
76
77
78
79
80
81
82
83
    
    // ----- READING INFLUXDB LINE PROTOCOL SETTINGS -----
    if (cfg.find("influx") != cfg.not_found()) {
	BOOST_FOREACH(boost::property_tree::iptree::value_type & global, cfg.get_child("influx")) {
	    if (boost::iequals(global.first, "measurement")) {
		influx_t influx;
		BOOST_FOREACH(boost::property_tree::iptree::value_type &m, global.second) {
		    if (boost::iequals(m.first, "tag")) {
			influx.tag = m.second.data();
84
85
86
87
88
89
90
91
92
93
94
95
96
97
		    } else if (boost::iequals(m.first, "tagfilter")) {
			//check if input has sed format of "s/.../.../" for substitution
			boost::regex  checkSubstitute("s([^\\\\]{1})([\\S|\\s]*)\\1([\\S|\\s]*)\\1");
			boost::smatch matchResults;
			
			if (regex_match(m.second.data(), matchResults, checkSubstitute)) {
			    //input has substitute format
			    influx.tagRegex = boost::regex(matchResults[2].str(), boost::regex_constants::extended);
			    influx.tagSubstitution = matchResults[3].str();
			} else {
			    //input is only a regex
			    influx.tagRegex = boost::regex(m.second.data(), boost::regex_constants::extended);
			    influx.tagSubstitution = "&";
			}
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
		    } else if (boost::iequals(m.first, "mqttprefix")) {
			influx.mqttPrefix = m.second.data();
		    } else if (boost::iequals(m.first, "fields")) {
			std::stringstream ss(m.second.data());
			while (ss.good()) {
			    std::string s;
			    getline(ss, s, ',');
			    influx.fields.insert(s);
			}
		    }
		}
		influxMap[global.second.data()] = influx;
	    }
	}
    }
113
}