1 #ifndef _ots_ConsoleSupervisor_h_
2 #define _ots_ConsoleSupervisor_h_
4 #include <boost/regex.hpp>
5 #include <boost/tokenizer.hpp>
6 #include "otsdaq/CoreSupervisors/CoreSupervisorBase.h"
27 virtual void defaultPage(xgi::Input* in, xgi::Output* out)
override;
28 virtual void request(
const std::string& requestType,
30 HttpXmlDocument& xmlOut,
31 const WebUsers::RequestUserInfo& userInfo)
override;
33 virtual void forceSupervisorPropertyValues(
void)
override;
40 void insertMessageRefresh(HttpXmlDocument* xmldoc,
const size_t lastUpdateCount);
45 struct ConsoleMessageStruct
47 ConsoleMessageStruct(
const std::string& msg,
const size_t count)
50 std::string hostname, category, application, message, hostaddr, file, line,
52 mf::ELseverityLevel sev;
57 boost::regex timestamp_regex_(
"(\\d{2}-[^-]*-\\d{4}\\s\\d{2}:\\d{2}:\\d{2})");
58 boost::regex file_line_regex_(
"^\\s*([^:]*\\.[^:]{1,3}):(\\d+)(.*)");
60 boost::char_separator<char> sep(
"|",
"", boost::keep_empty_tokens);
61 typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
62 tokenizer tokens(msg, sep);
63 tokenizer::iterator it = tokens.begin();
67 while(it != tokens.end() && !boost::regex_search(*it, res, timestamp_regex_))
74 std::string value(res[1].first, res[1].second);
75 strptime(value.c_str(),
"%d-%b-%Y %H:%M:%S", &tm);
83 if(it != tokens.end() && ++it != tokens.end() )
85 seqNum = std::stoi(*it);
88 catch(
const std::invalid_argument& e)
92 if(it != tokens.end() && ++it != tokens.end() )
96 if(it != tokens.end() && ++it != tokens.end() )
100 if(it != tokens.end() && ++it != tokens.end() )
102 sev = mf::ELseverityLevel(*it);
104 if(it != tokens.end() && ++it != tokens.end() )
108 if(it != tokens.end() && ++it != tokens.end() )
115 if(it != tokens.end() && ++it != tokens.end() )
117 pid = std::stol(*it);
120 catch(
const std::invalid_argument& e)
124 if(it != tokens.end() && ++it != tokens.end() )
128 if(it != tokens.end() && ++it != tokens.end() )
132 if(it != tokens.end() && ++it != tokens.end() )
136 if(it != tokens.end() && ++it != tokens.end() )
140 std::ostringstream oss;
142 while(it != tokens.end() && ++it != tokens.end() )
158 fields[FieldType::TIMESTAMP].set(
"Timestamp", 1, std::to_string(tv.tv_sec));
159 fields[FieldType::SEQID].set(
"SequenceID", 2, std::to_string(seqNum));
160 fields[FieldType::LEVEL].set(
"Level", 5, sev.getName());
161 fields[FieldType::LABEL].set(
"Label", 6, category);
162 fields[FieldType::SOURCEID].set(
163 "SourceID", 7, std::to_string(pid));
164 fields[FieldType::SOURCE].set(
"Source", 9, application);
165 fields[FieldType::FILE].set(
"File", 10, file);
166 fields[FieldType::LINE].set(
"Line", 11, line);
167 fields[FieldType::MSG].set(
"Msg", 12, message);
170 for (
auto& field : fields) {
171 std::cout <<
"Field " << field.second.fieldName <<
": " << field.second.fieldValue
177 std::string getTime()
const {
return fields[FieldType::TIMESTAMP].fieldValue; }
178 std::string getMsg()
const {
return fields[FieldType::MSG].fieldValue; }
179 std::string getLabel()
const {
return fields[FieldType::LABEL].fieldValue; }
180 std::string getLevel()
const {
return fields[FieldType::LEVEL].fieldValue; }
182 std::string getFile()
const {
return fields[FieldType::FILE].fieldValue; }
183 std::string getLine()
const {
return fields[FieldType::LINE].fieldValue; }
185 std::string getSourceID()
const {
return fields[FieldType::SOURCEID].fieldValue; }
186 uint32_t getSourceIDAsNumber()
const
188 auto val = fields[FieldType::SOURCEID].fieldValue;
191 return std::stoul(val);
195 std::string getSource()
const {
return fields[FieldType::SOURCE].fieldValue; }
196 std::string getSequenceID()
const {
return fields[FieldType::SEQID].fieldValue; }
197 size_t getSequenceIDAsNumber()
const
199 auto val = fields[FieldType::SEQID].fieldValue;
202 return std::stoul(val);
207 size_t getCount()
const {
return countStamp; }
212 void set(
const std::string& fn,
const int mc,
const std::string& fv)
219 std::string fieldName;
220 std::string fieldValue;
238 mutable std::unordered_map<FieldType, FieldStruct> fields;
244 std::deque<ConsoleMessageStruct> messages_;
245 std::mutex messageMutex_;
246 size_t messageCount_;
247 size_t maxMessageCount_;
250 xercesc::DOMElement* refreshParent_;