ElasticStackLogAccess.hpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2021 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. #pragma once
  14. #include "jlog.hpp"
  15. #include "jptree.hpp"
  16. #include "jstring.hpp"
  17. #include "jfile.ipp"
  18. #ifndef ELASTICSTACKLOGACCESS_EXPORTS
  19. #define ELASTICSTACKLOGACCESS_API DECL_IMPORT
  20. #else
  21. #define ELASTICSTACKLOGACCESS_API DECL_EXPORT
  22. #endif
  23. #define COMPONENT_NAME "ES Log Access"
  24. /* undef verify definitions to avoid collision in cpr submodule */
  25. #ifdef verify
  26. //#pragma message("UNDEFINING 'verify' - Will be redefined by cpr" )
  27. #undef verify
  28. #endif
  29. #include <cpr/response.h>
  30. #include <elasticlient/client.h>
  31. using namespace elasticlient;
  32. class ELASTICSTACKLOGACCESS_API ElasticStackLogAccess : public CInterfaceOf<IRemoteLogAccess>
  33. {
  34. private:
  35. static constexpr const char * type = "elasticstack";
  36. Owned<IPropertyTree> m_pluginCfg;
  37. StringBuffer m_globalIndexSearchPattern;
  38. StringBuffer m_globalSearchColName;
  39. StringBuffer m_globalIndexTimestampField;
  40. StringBuffer m_workunitSearchColName;
  41. StringBuffer m_workunitIndexSearchPattern;
  42. StringBuffer m_componentsSearchColName;
  43. StringBuffer m_componentsIndexSearchPattern;
  44. StringBuffer m_audienceSearchColName;
  45. StringBuffer m_audienceIndexSearchPattern;
  46. StringBuffer m_classSearchColName;
  47. StringBuffer m_classIndexSearchPattern;
  48. StringBuffer m_defaultDocType; //default doc type to query
  49. elasticlient::Client m_esClient;
  50. StringBuffer m_esConnectionStr;
  51. // Elastic Stack specific
  52. cpr::Response performESQuery(const LogAccessConditions & options);
  53. const IPropertyTree * getESStatus();
  54. const IPropertyTree * getIndexSearchStatus(const char * indexpattern);
  55. const IPropertyTree * getTimestampTypeFormat(const char * indexpattern, const char * fieldname);
  56. const IPropertyTree * performAndLogESRequest(Client::HTTPMethod httpmethod, const char * url, const char * reqbody, const char * logmessageprefix, LogMsgCategory reqloglevel, LogMsgCategory resploglevel);
  57. public:
  58. ElasticStackLogAccess(const std::vector<std::string> &hostUrlList, IPropertyTree & logAccessPluginConfig);
  59. virtual ~ElasticStackLogAccess() override = default;
  60. // IRemoteLogAccess methods
  61. virtual bool fetchLog(const LogAccessConditions & options, StringBuffer & returnbuf, LogAccessLogFormat format) override;
  62. virtual const char * getRemoteLogAccessType() const override { return type; }
  63. virtual IPropertyTree * queryLogMap() const override { return m_pluginCfg->queryPropTree("logmap");}
  64. virtual const char * fetchConnectionStr() const override { return m_esConnectionStr.str();}
  65. };