Line data Source code
1 : /* 2 : * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : #ifndef __USER_DEFINED_COUNTER_H__ 6 : #define __USER_DEFINED_COUNTER_H__ 7 : 8 : 9 : #include <map> 10 : #include <boost/shared_ptr.hpp> 11 : #include "http/client/vncapi.h" 12 : #include "parser_util.h" 13 : #include <analytics/analytics_types.h> 14 : #include "base/regex.h" 15 : #include "config_client_collector.h" 16 : 17 : using contrail::regex; 18 : using contrail::regex_match; 19 : using contrail::regex_search; 20 : 21 : class Options; 22 : 23 : class UserDefinedCounterData { 24 : public: 25 0 : explicit UserDefinedCounterData(std::string name, std::string pat): 26 0 : refreshed_(true), name_(name) { 27 0 : SetPattern(pat); 28 0 : } 29 0 : void SetPattern(std::string pat) { 30 0 : regexp_ = contrail::regex(pat); 31 0 : regexp_str_ = pat; 32 0 : } 33 : bool operator==(const UserDefinedCounterData &rhs) { 34 : return rhs.IsMe(name_) && rhs.pattern() == regexp_str_; 35 : } 36 0 : const contrail::regex& regexp() const { return regexp_; } 37 0 : const std::string name() { return name_; } 38 : bool IsMe(std::string name) const { return name == name_; } 39 0 : const std::string pattern() const { return regexp_str_; } 40 0 : void Refresh() { refreshed_ = true; } 41 0 : bool IsRefreshed() { bool r = refreshed_; refreshed_ = false; return r;} 42 : private: 43 : bool refreshed_; 44 : std::string name_; 45 : std::string regexp_str_; 46 : contrail::regex regexp_; 47 : }; 48 : 49 : typedef std::map<std::string, boost::shared_ptr<UserDefinedCounterData> > Cfg_t; 50 : 51 : class UserDefinedCounters { 52 : public: 53 : UserDefinedCounters(); 54 : virtual ~UserDefinedCounters(); 55 : virtual void MatchFilter(std::string text, LineParser::WordListType *words); 56 : void SendUVEs(); 57 : void AddConfig(std::string name, std::string pattern); 58 : bool FindByName(std::string name); 59 : void UDCHandler(const contrail_rapidjson::Document &jdoc, bool add_change); 60 : void GetUDCConfig(std::vector<LogStatisticConfigInfo> *config_info); 61 : private: 62 : Cfg_t config_; 63 : }; 64 : 65 : 66 : #endif