00001 #include "otsdaq-core/ConfigurationPluginDataFormats/MessageFacilityConfiguration.h"
00002 #include "otsdaq-core/Macros/ConfigurationPluginMacros.h"
00003 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
00004
00005 #include <iostream>
00006 #include <fstream>
00007 #include <stdio.h>
00008 using namespace ots;
00009
00010 #define MF_CFG_FILE std::string(getenv("USER_DATA")) + "/MessageFacilityConfigurations/MessageFacilityGen.fcl"
00011 #define QT_CFG_FILE std::string(getenv("USER_DATA")) + "/MessageFacilityConfigurations/QTMessageViewerGen.fcl"
00012 #define QUIET_CFG_FILE std::string(getenv("USER_DATA")) + "/MessageFacilityConfigurations/QuietForwarderGen.cfg"
00013 #define USE_WEB_BOOL_FILE std::string(getenv("USER_DATA")) + "/MessageFacilityConfigurations/UseWebConsole.bool"
00014 #define USE_QT_BOOL_FILE std::string(getenv("USER_DATA")) + "/MessageFacilityConfigurations/UseQTViewer.bool"
00015
00016
00017 #define COL_NAME "UID"
00018 #define COL_STATUS "Status"
00019 #define COL_ENABLE_FWD "EnableUDPForwarding"
00020
00021 #define COL_USE_WEB "ForwardToWebConsoleGUI"
00022 #define COL_WEB_IP "WebConsoleForwardingIPAddress"
00023 #define COL_WEB_PORT0 "WebConsoleForwardingPort0"
00024 #define COL_WEB_PORT1 "WebConsoleForwardingPort1"
00025
00026 #define COL_USE_QT "ForwardToQTViewerGUI"
00027 #define COL_QT_IP "QTViewerForwardingIPAddress"
00028 #define COL_QT_PORT "QTViewerForwardingPort"
00029
00030
00031
00032 MessageFacilityConfiguration::MessageFacilityConfiguration(void) :
00033 ConfigurationBase("MessageFacilityConfiguration")
00034 {
00036
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 }
00063
00064 MessageFacilityConfiguration::~MessageFacilityConfiguration(void)
00065 {}
00066
00067 void MessageFacilityConfiguration::init(ConfigurationManager *configManager)
00068 {
00069 __MOUT__ << "*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << std::endl;
00070
00071 __MOUT__ << configManager->__SELF_NODE__ << std::endl;
00072
00073
00074 bool status,enableFwd,useWeb,useQT;
00075 int fwdPort;
00076 std::string fwdIP;
00077
00078 auto childrenMap = configManager->__SELF_NODE__.getChildren();
00079
00080
00081
00082 std::fstream fs;
00083 fs.open(MF_CFG_FILE, std::fstream::out | std::fstream::trunc);
00084 if(fs.fail())
00085 {
00086 __SS__ << "Failed to open Message Facility configuration file: " << MF_CFG_FILE << std::endl;
00087 throw std::runtime_error(ss.str());
00088 }
00089
00090
00091
00092 for(auto &child:childrenMap)
00093 {
00094 child.second.getNode(COL_STATUS ).getValue(status);
00095
00096 if(!status) continue;
00097
00098 child.second.getNode(COL_ENABLE_FWD ).getValue(enableFwd);
00099
00100 child.second.getNode(COL_USE_WEB ).getValue(useWeb);
00101 child.second.getNode(COL_USE_QT ).getValue(useQT);
00102
00103 if(useWeb && useQT)
00104 {
00105 fs.close();
00106 __SS__ << "Illegal Message Facility configuration: " <<
00107 "Can only enable Web Console or QT Viewer, not both." << std::endl;
00108 throw std::runtime_error(ss.str());
00109 }
00110
00111 std::fstream bfs;
00112
00113 bfs.open(USE_WEB_BOOL_FILE, std::fstream::out | std::fstream::trunc);
00114 if(bfs.fail())
00115 {
00116 fs.close();
00117 __SS__ << "Failed to open boolean Use of Web Console configuration file: " <<
00118 USE_WEB_BOOL_FILE << std::endl;
00119 throw std::runtime_error(ss.str());
00120 }
00121 bfs << (useWeb?1:0);
00122 bfs.close();
00123
00124
00125 bfs.open(USE_QT_BOOL_FILE, std::fstream::out | std::fstream::trunc);
00126 if(bfs.fail())
00127 {
00128 fs.close();
00129 __SS__ << "Failed to open boolean Use of QT Viewer configuration file: " <<
00130 USE_QT_BOOL_FILE << std::endl;
00131 throw std::runtime_error(ss.str());
00132 }
00133 bfs << (useQT?1:0);
00134 bfs.close();
00135
00136 if(enableFwd)
00137 {
00138
00139
00140 if(useWeb)
00141 {
00142 __MOUT__ << "Forwarding to Web GUI with UDP forward MesageFacility configuration." << std::endl;
00143
00144 child.second.getNode(COL_WEB_PORT0 ).getValue(fwdPort);
00145 child.second.getNode(COL_WEB_IP ).getValue(fwdIP);
00146
00147 fs << "udp: {\n";
00148 fs << "\t" << "type: UDP\n";
00149 fs << "\t" << "threshold: DEBUG\n";
00150 fs << "\t" << "port: " << fwdPort << "\n";
00151 fs << "\t" << "host: \"" << fwdIP << "\"\n";
00152 fs << "}\n";
00153
00154
00155 std::fstream qtfs;
00156 qtfs.open(QUIET_CFG_FILE, std::fstream::out | std::fstream::trunc);
00157 if(qtfs.fail())
00158 {
00159 fs.close();
00160 __SS__ << "Failed to open Web Console's 'Quiet Forwarder' configuration file: " <<
00161 QUIET_CFG_FILE << std::endl;
00162 throw std::runtime_error(ss.str());
00163 }
00164 qtfs << "RECEIVE_PORT \t " << fwdPort << "\n";
00165 child.second.getNode(COL_WEB_PORT1 ).getValue(fwdPort);
00166 qtfs << "DESTINATION_PORT \t " << fwdPort << "\n";
00167 qtfs.close();
00168 }
00169
00170
00171 if(useQT)
00172 {
00173 __MOUT__ << "Forwarding to Web GUI with UDP forward MesageFacility configuration." << std::endl;
00174
00175 child.second.getNode(COL_QT_PORT ).getValue(fwdPort);
00176 child.second.getNode(COL_QT_IP ).getValue(fwdIP);
00177
00178 fs << "udp: {\n";
00179 fs << "\t" << "type: UDP\n";
00180 fs << "\t" << "threshold: DEBUG\n";
00181 fs << "\t" << "port: " << fwdPort << "\n";
00182 fs << "\t" << "host: \"" << fwdIP << "\"\n";
00183 fs << "}\n";
00184
00185
00186 std::fstream qtfs;
00187 qtfs.open(QT_CFG_FILE, std::fstream::out | std::fstream::trunc);
00188 if(qtfs.fail())
00189 {
00190 fs.close();
00191 __SS__ << "Failed to open QT Message Viewer configuration file: " <<
00192 QT_CFG_FILE << std::endl;
00193 throw std::runtime_error(ss.str());
00194 }
00195 qtfs << "receivers: \n{\n";
00196 qtfs << "\t" << "syslog: \n{\n";
00197 qtfs << "\t\t" << "receiverType: " << "\"UDP\"" << "\n";
00198 qtfs << "\t\t" << "port: " << fwdPort << "\n";
00199 qtfs << "\t}\n";
00200 qtfs << "}\n";
00201 qtfs << "\n";
00202 qtfs << "threshold: " << "DEBUG" << "\n";
00203 qtfs.close();
00204 }
00205 }
00206 else
00207 {
00208 __MOUT__ << "Using cout-only MesageFacility configuration." << std::endl;
00209 fs << "console: {\n";
00210 fs << "\t" << "type: \"cout\"\n";
00211 fs << "\t" << "threshold: \"DEBUG\"\n";
00212 fs << "\t" << "noTimeStamps: true\n";
00213 fs << "\t" << "noLineBreaks: true\n";
00214 fs << "}\n";
00215 }
00216
00217 break;
00218 }
00219
00220
00221 fs.close();
00222 }
00223
00224 DEFINE_OTS_CONFIGURATION(MessageFacilityConfiguration)