diff --git a/dali/base/daclient.cpp b/dali/base/daclient.cpp index b8ef382995b..a61926c7b80 100644 --- a/dali/base/daclient.cpp +++ b/dali/base/daclient.cpp @@ -29,6 +29,7 @@ #include "dautils.hpp" #include "daclient.hpp" +#include "sysinfologger.hpp" extern bool registerClientProcess(ICommunicator *comm, IGroup *& retcoven,unsigned timeout,DaliClientRole role); extern void stopClientProcess(); @@ -141,6 +142,8 @@ bool initClientProcess(IGroup *servergrp, DaliClientRole role, unsigned mpport, covengrp->Release(); queryLogMsgManager()->setSession(myProcessSession()); + if (getGlobalConfigSP()->getPropBool("@enableGlobalSysLog", true)) + UseDaliForOperatorMessages(); if (!isContainerized()) // The Environment is bare-metal only { // auto install environment monitor for server roles @@ -177,6 +180,7 @@ void removeShutdownHook(IDaliClientShutdown &shutdown) void closedownClientProcess() { + UseDaliForOperatorMessages(false); if (!daliClientIsActive) return; while (shutdownHooks.ordinality()) diff --git a/dali/base/sysinfologger.cpp b/dali/base/sysinfologger.cpp index 3e28326280c..0142e8fa312 100644 --- a/dali/base/sysinfologger.cpp +++ b/dali/base/sysinfologger.cpp @@ -646,3 +646,81 @@ unsigned deleteOlderThanLogSysInfoMsg(bool visibleOnly, bool hiddenOnly, unsigne } return count; } + +class DaliMsgLoggerHandler : public CInterfaceOf +{ +public: + DaliMsgLoggerHandler(unsigned _messageFields=MSGFIELD_all) : messageFields(_messageFields) + { + } + virtual void handleMessage(const LogMsg & msg) override + { + LogMsgSysInfo sysInfo = msg.querySysInfo(); + time_t timeNum = sysInfo.queryTime(); + unsigned __int64 ts = sysInfo.queryTime() * 1000000 + sysInfo.queryUSecs(); + logSysInfoError(msg.queryCategory(), msg.queryCode(), queryComponentName(), msg.queryText(), ts); + } + virtual bool needsPrep() const override + { + return false; + } + virtual void prep() override + { + } + virtual unsigned queryMessageFields() const override + { + return messageFields; + } + virtual void setMessageFields(unsigned _fields = MSGFIELD_all) override + { + messageFields = _fields; + } + virtual void addToPTree(IPropertyTree * parent) const override + { + IPropertyTree * handlerTree = createPTree(ipt_caseInsensitive); + handlerTree->setProp("@type", "globalmessages"); + handlerTree->setPropInt("@fields", messageFields); + parent->addPropTree("handler", handlerTree); + } + virtual int flush() override + { + return 0; + } + virtual bool getLogName(StringBuffer &name) const override + { + return false; + } + virtual offset_t getLogPosition(StringBuffer &logFileName) const override + { + return 0; + } +private: + unsigned messageFields = MSGFIELD_all; +}; + +void UseDaliForOperatorMessages(bool use) +{ + static ILogMsgHandler *msgHandler=NULL; + if (use==(msgHandler!=NULL)) + return; + if (use) + { + msgHandler = getDaliMsgLoggerHandler(); + ILogMsgFilter * operatorFilter = getCategoryLogMsgFilter(MSGAUD_operator, + MSGCLS_disaster|MSGCLS_error|MSGCLS_warning, + WarnMsgThreshold, + true); + queryLogMsgManager()->addMonitorOwn(msgHandler, operatorFilter); + } + else + { + queryLogMsgManager()->removeMonitor(msgHandler); + msgHandler = NULL; + } +} + +ILogMsgHandler * getDaliMsgLoggerHandler() +{ + return new DaliMsgLoggerHandler(); +} + diff --git a/dali/base/sysinfologger.hpp b/dali/base/sysinfologger.hpp index 8e090c1d2a9..f78e3658975 100644 --- a/dali/base/sysinfologger.hpp +++ b/dali/base/sysinfologger.hpp @@ -89,4 +89,6 @@ SYSINFO_API unsigned deleteLogSysInfoMsg(ISysInfoLoggerMsgFilter * msgFilter); SYSINFO_API bool deleteLogSysInfoMsg(unsigned __int64 msgId); SYSINFO_API unsigned deleteOlderThanLogSysInfoMsg(bool visibleOnly, bool hiddenOnly, unsigned year, unsigned month, unsigned day); +SYSINFO_API ILogMsgHandler * getDaliMsgLoggerHandler(); +SYSINFO_API void UseDaliForOperatorMessages(bool use=true); #endif diff --git a/esp/services/ws_workunits/ws_wudetails.cpp b/esp/services/ws_workunits/ws_wudetails.cpp index bd295fbab37..e37f5c79408 100644 --- a/esp/services/ws_workunits/ws_wudetails.cpp +++ b/esp/services/ws_workunits/ws_wudetails.cpp @@ -22,6 +22,7 @@ #include "workunit.hpp" #include "jset.hpp" #include "jstatcodes.h" +#include "sysinfologger.hpp" typedef std::pair AttribValuePair; bool operator==(const AttribValuePair & p1, const AttribValuePair & p2) @@ -504,6 +505,22 @@ void WUDetails::processRequest(IEspWUDetailsRequest &req, IEspWUDetailsResponse espWuResponseNote->setCost(0); espWuResponseNotes.append(*espWuResponseNote.getClear()); } + Owned msgFilter = createSysInfoLoggerMsgFilter(); + msgFilter->setVisibleOnly(); + Owned msgIter = createSysInfoLoggerMsgIterator(msgFilter); + ForEach(*msgIter) + { + ISysInfoLoggerMsg & sysInfoMsg = msgIter->query(); + Owned espWuResponseNote = createWUResponseNote("",""); + StringBuffer tmpbuf; + encodeXML(sysInfoMsg.queryMsg(), tmpbuf, ENCODE_NEWLINES, strlen(sysInfoMsg.queryMsg()), true); + espWuResponseNote->setSource(sysInfoMsg.querySource()); + espWuResponseNote->setMessage(tmpbuf.str()); + espWuResponseNote->setErrorCode(sysInfoMsg.queryLogMsgCode()); + espWuResponseNote->setSeverity(LogMsgClassToVarString(sysInfoMsg.queryClass())); + espWuResponseNote->setCost(0); + espWuResponseNotes.append(*espWuResponseNote.getClear()); + } Owned respScope = createWUResponseScope("",""); respScope->setScopeName(""); respScope->setNotes(espWuResponseNotes); diff --git a/testing/unittests/dalitests.cpp b/testing/unittests/dalitests.cpp index 339d51d1f51..3dd5bd3cb05 100644 --- a/testing/unittests/dalitests.cpp +++ b/testing/unittests/dalitests.cpp @@ -3183,6 +3183,7 @@ class CSysInfoLoggerTester : public CppUnit::TestFixture void testInit() { daliClientInit(); + UseDaliForOperatorMessages(false); } void testWrite() {