IPMIConfigurator.cpp 2.37 KB
Newer Older
1
2
3
4
/*
 * IPMIConfigurator.cpp
 *
 *  Created on: 26 Jan 2017
5
 *      Author: Michael Ott (original), Micha Mueller
6
7
8
9
10
11
 */

#include "IPMIConfigurator.h"

#include <boost/optional.hpp>
#include <iostream>
12
13
#include <iomanip>
#include <sstream>
14

15
16
17
IPMIConfigurator::IPMIConfigurator() {
	_globalHost.sessionTimeout = 0;
	_globalHost.retransmissionTimeout = 0;
18
19
20
21

	_entityName = "host";
	_groupName = "group";
	_baseName = "sensor";
22
}
23

24
IPMIConfigurator::~IPMIConfigurator() {}
25

26
27
28
void IPMIConfigurator::sensorBase(IPMISensorBase& s, CFG_VAL config) {
	ADD {
		ATTRIBUTE("cmd", setRawCmd);
29
30
		ATTRIBUTE("lsb", setLsb);
		ATTRIBUTE("msb", setMsb);
31
32
		ATTRIBUTE("recordId", setRecordId);
		ATTRIBUTE("factor", setFactor);
33
	}
34
	
35
36
37
38
	if (s.getLsb() < s.getMsb()) {
		if (s.getMsb() - s.getLsb() >= 8) {
			s.setMsb(s.getLsb() + 7);
			LOG(warning) << "Maximum length of IPMI raw response interval is 8 bytes, setting msb offset to " << (int) s.getMsb();
39
40
		}
	} else {
41
42
43
		if (s.getLsb() - s.getMsb() >= 8) {
			s.setLsb(s.getMsb() + 7);
			LOG(warning) << "Maximum length of IPMI raw response interval is 8 bytes, setting lsb offset to " << (int) s.getLsb();
44
45
46
		}

	}
47
}
48

49
50
51
void IPMIConfigurator::sensorGroup(IPMISensorGroup& s, CFG_VAL config) {
	ADD {
		//no group attributes currently
52
53
54
	}
}

55
56
57
58
59
60
61
62
63
void IPMIConfigurator::sensorEntity(IPMIHost& s, CFG_VAL config) {
	s.setHostName(config.data());
	s.setSessionTimeout(_globalHost.sessionTimeout);
	s.setRetransmissionTimeout(_globalHost.retransmissionTimeout);
	s.setCache(_tempdir);
	ADD {
		ATTRIBUTE("username", setUserName);
		ATTRIBUTE("password", setPassword);
		ATTRIBUTE("mqttPart", setMqttPart);
64
65
		ATTRIBUTE("cipher", setCipher);
		ATTRIBUTE("ipmiVersion", setIpmiVersion);
66
	}
67
}
68

69
70
bool IPMIConfigurator::isEntityOfGroup(IPMIHost& e, IPMISensorGroup& g) {
	return (g.getHost() == &e);
71
}
72

73
74
75
void IPMIConfigurator::setEntityForGroup(IPMIHost& e, IPMISensorGroup& g) {
	g.setHost(&e);
}
76

77
78
void IPMIConfigurator::finalizeGroup(IPMISensorGroup& g) {
	g.setMqttPart(g.getHost()->getMqttPart() + g.getMqttPart());
79
}
80

81
void IPMIConfigurator::global(CFG_VAL config) {
Micha Mueller's avatar
Micha Mueller committed
82
83
84
	ADD {
		SETTING("SessionTimeout") {
			_globalHost.sessionTimeout = stoi(val.second.data());
85
			LOG(debug)<< "  SessionTimeout " << _globalHost.sessionTimeout;
Micha Mueller's avatar
Micha Mueller committed
86
87
88
		}
		SETTING("RetransmissionTimeout") {
			_globalHost.retransmissionTimeout = stoi(val.second.data());
89
90
91
			LOG(debug) << "  RetransmissionTimeout " << _globalHost.retransmissionTimeout;
		}
	}
92
}