loggingagent.hpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2014 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef __ESPSERVERLOGGINGAGENT__HPP__
  14. #define __ESPSERVERLOGGINGAGENT__HPP__
  15. #include "loggingcommon.hpp"
  16. #include "datafieldmap.hpp"
  17. #ifdef WIN32
  18. #ifdef ESPSERVERLOGGINGAGENT_EXPORTS
  19. #define ESPSERVERLOGGINGAGENT_API __declspec(dllexport)
  20. #else
  21. #define ESPSERVERLOGGINGAGENT_API __declspec(dllimport)
  22. #endif
  23. #else
  24. #define ESPSERVERLOGGINGAGENT_API
  25. #endif
  26. enum ESPLogContentGroup
  27. {
  28. ESPLCGESPContext = 0,
  29. ESPLCGUserContext = 1,
  30. ESPLCGUserReq = 2,
  31. ESPLCGUserResp = 3,
  32. ESPLCGBackEndResp = 4,
  33. ESPLCGAll = 5
  34. };
  35. static const char * const espLogContentGroupNames[] = { "ESPContext", "UserContext", "UserRequest", "UserResponse", "BackEndResponse", "", NULL };
  36. class CTransIDBuilder : public CInterface, implements IInterface
  37. {
  38. StringAttr seed;
  39. bool localSeed;
  40. unsigned __int64 seq;
  41. void add(StringAttrMapping* transIDFields, const char* key, StringBuffer& id)
  42. {
  43. StringAttr* value = transIDFields->getValue(key);
  44. if (value)
  45. id.append(value->get()).append('-');
  46. else
  47. {
  48. const char* ptr = key;
  49. if (strlen(key) > 11) //skip the "transaction" prefix of the key
  50. ptr += 11;
  51. id.append('?').append(ptr).append('-');
  52. }
  53. }
  54. public:
  55. IMPLEMENT_IINTERFACE;
  56. CTransIDBuilder(const char* _seed, bool _localSeed) : seed(_seed), localSeed(_localSeed), seq(0) { };
  57. virtual ~CTransIDBuilder() {};
  58. virtual const char* getTransSeed() { return seed.get(); };
  59. virtual void getTransID(StringAttrMapping* transIDFields, StringBuffer& id)
  60. {
  61. id.clear();
  62. if (transIDFields)
  63. {
  64. add(transIDFields, sTransactionDateTime, id);
  65. add(transIDFields, sTransactionMethod, id);
  66. add(transIDFields, sTransactionIdentifier, id);
  67. }
  68. if (localSeed)
  69. id.append(seed.get()).append("-X").append(++seq);
  70. else
  71. id.append(seed.get()).append('-').append(++seq);
  72. };
  73. };
  74. class CESPLogContentGroupFilters : public CInterface, implements IInterface
  75. {
  76. ESPLogContentGroup group;
  77. StringArray filters;
  78. public:
  79. IMPLEMENT_IINTERFACE;
  80. CESPLogContentGroupFilters(ESPLogContentGroup _group) : group(_group) {};
  81. ESPLogContentGroup getGroup() { return group; };
  82. StringArray& getFilters() { return filters; };
  83. void clearFilters() { filters.clear(); };
  84. unsigned getFilterCount() { return filters.length(); };
  85. void addFilter(const char* filter)
  86. {
  87. if (filter && *filter)
  88. filters.append(filter);
  89. };
  90. };
  91. class CESPServerLoggingAgent : public CInterface, implements IEspLogAgent
  92. {
  93. StringBuffer serviceName, loggingAgentName, defaultGroup;
  94. StringBuffer serverUrl, serverUserID, serverPassword;
  95. unsigned maxServerWaitingSeconds; //time out value for HTTP connection to logging server
  96. unsigned maxGTSRetries;
  97. StringArray logContentFilters;
  98. CIArrayOf<CESPLogContentGroupFilters> groupFilters;
  99. bool logBackEndResp;
  100. MapStringToMyClass<CTransIDBuilder> transIDMap;
  101. MapStringToMyClass<CLogSource> logSources;
  102. void readAllLogFilters(IPropertyTree* cfg);
  103. bool readLogFilters(IPropertyTree* cfg, unsigned groupID);
  104. void filterLogContentTree(StringArray& filters, IPropertyTree* originalContentTree, IPropertyTree* newLogContentTree, bool& logContentEmpty);
  105. void filterAndAddLogContentBranch(StringArray& branchNamesInFilter, unsigned idx, StringArray& branchNamesInLogContent,
  106. IPropertyTree* in, IPropertyTree* updateLogRequestTree, bool& logContentEmpty);
  107. void addLogContentBranch(StringArray& branchNames, IPropertyTree* contentToLogBranch, IPropertyTree* updateLogRequestTree);
  108. bool sendHTTPRequest(StringBuffer& req, StringBuffer& resp, StringBuffer& status);
  109. int getTransactionSeed(const char* source, StringBuffer& transactionSeed, StringBuffer& statusMessage);
  110. bool getTransactionSeed(StringBuffer& soapreq, int& statusCode, StringBuffer& statusMessage, StringBuffer& seedID);
  111. virtual void createLocalTransactionSeed(StringBuffer& transactionSeed);
  112. public:
  113. IMPLEMENT_IINTERFACE;
  114. CESPServerLoggingAgent() {};
  115. virtual ~CESPServerLoggingAgent() {};
  116. bool init(const char* name, const char* type, IPropertyTree* cfg, const char* process);
  117. virtual bool getTransactionSeed(IEspGetTransactionSeedRequest& req, IEspGetTransactionSeedResponse& resp);
  118. virtual void getTransactionID(StringAttrMapping* transFields, StringBuffer& transactionID);
  119. virtual bool updateLog(IEspUpdateLogRequestWrap& req, IEspUpdateLogResponse& resp);
  120. virtual void filterLogContent(IEspUpdateLogRequestWrap* req);
  121. };
  122. #endif //__ESPSERVERLOGGINGAGENT__HPP__