Skip to content

Commit

Permalink
HPCC-31775 Hook jlog to use api to log operator messages
Browse files Browse the repository at this point in the history
Signed-off-by: Shamser Ahmed <[email protected]>
  • Loading branch information
shamser committed May 30, 2024
1 parent 78a3976 commit 7e305d4
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dali/base/daclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -177,6 +180,7 @@ void removeShutdownHook(IDaliClientShutdown &shutdown)

void closedownClientProcess()
{
UseDaliForOperatorMessages(false);
if (!daliClientIsActive)
return;
while (shutdownHooks.ordinality())
Expand Down
78 changes: 78 additions & 0 deletions dali/base/sysinfologger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,3 +646,81 @@ unsigned deleteOlderThanLogSysInfoMsg(bool visibleOnly, bool hiddenOnly, unsigne
}
return count;
}

class DaliMsgLoggerHandler : public CInterfaceOf<ILogMsgHandler>
{
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();
}

2 changes: 2 additions & 0 deletions dali/base/sysinfologger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions esp/services/ws_workunits/ws_wudetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "workunit.hpp"
#include "jset.hpp"
#include "jstatcodes.h"
#include "sysinfologger.hpp"

typedef std::pair<WuAttr, StringBuffer> AttribValuePair;
bool operator==(const AttribValuePair & p1, const AttribValuePair & p2)
Expand Down Expand Up @@ -504,6 +505,22 @@ void WUDetails::processRequest(IEspWUDetailsRequest &req, IEspWUDetailsResponse
espWuResponseNote->setCost(0);
espWuResponseNotes.append(*espWuResponseNote.getClear());
}
Owned<ISysInfoLoggerMsgFilter> msgFilter = createSysInfoLoggerMsgFilter();
msgFilter->setVisibleOnly();
Owned<ISysInfoLoggerMsgIterator> msgIter = createSysInfoLoggerMsgIterator(msgFilter);
ForEach(*msgIter)
{
ISysInfoLoggerMsg & sysInfoMsg = msgIter->query();
Owned<IEspWUResponseNote> 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<IEspWUResponseScope> respScope = createWUResponseScope("","");
respScope->setScopeName("");
respScope->setNotes(espWuResponseNotes);
Expand Down
1 change: 1 addition & 0 deletions testing/unittests/dalitests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3183,6 +3183,7 @@ class CSysInfoLoggerTester : public CppUnit::TestFixture
void testInit()
{
daliClientInit();
UseDaliForOperatorMessages(false);
}
void testWrite()
{
Expand Down

0 comments on commit 7e305d4

Please sign in to comment.