LCOV - code coverage report
Current view: top level - root/contrail/src/contrail-analytics/contrail-collector - usrdef_counters.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 5 83 6.0 %
Date: 2026-08-03 02:19:58 Functions: 3 8 37.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : 
       6             : #include <sstream>
       7             : #include <boost/make_shared.hpp>
       8             : #include <analytics/analytics_types.h>
       9             : #include "usrdef_counters.h"
      10             : #include "http/client/vncapi.h"
      11             : #include "options.h"
      12             : 
      13           7 : UserDefinedCounters::UserDefinedCounters() {
      14           7 : }
      15             : 
      16          14 : UserDefinedCounters::~UserDefinedCounters() {
      17           7 :     config_.erase(config_.begin(), config_.end());
      18          14 : }
      19             : 
      20             : void
      21           0 : UserDefinedCounters::UDCHandler(const contrail_rapidjson::Document &jdoc, bool add_change)
      22             : {
      23           0 :     if (!add_change) {
      24           0 :         return;
      25             :     }
      26             : 
      27           0 :     if (jdoc.IsObject() 
      28           0 :                  && jdoc.HasMember("global_system_config")) {
      29           0 :         if (!jdoc["global_system_config"].HasMember(
      30             :                   "user_defined_log_statistics")) {
      31           0 :             Cfg_t::iterator cit=config_.begin();
      32           0 :             while (cit != config_.end()) {
      33           0 :                 Cfg_t::iterator dit = cit++;
      34           0 :                 if (!dit->second->IsRefreshed()) {
      35           0 :                     UserDefinedLogStatistic udc;
      36           0 :                     udc.set_name(dit->first);
      37           0 :                     udc.set_deleted(true);
      38           0 :                     UserDefinedLogStatisticUVE::Send(udc);
      39           0 :                     config_.erase(dit);
      40           0 :                 }
      41             :             }    
      42           0 :             return;
      43             :         }
      44             : 
      45           0 :         if (!jdoc["global_system_config"]
      46           0 :                  ["user_defined_log_statistics"].IsObject()) {
      47           0 :             return;
      48             :         }
      49             : 
      50           0 :         if (!jdoc["global_system_config"]
      51           0 :                  ["user_defined_log_statistics"].HasMember("statlist")) {
      52           0 :             return;
      53             :         }
      54             : 
      55             :         const contrail_rapidjson::Value& gsc = jdoc
      56           0 :                 ["global_system_config"]["user_defined_log_statistics"]["statlist"];
      57           0 :         if (!gsc.IsArray()) {
      58           0 :             return;
      59             :         }
      60             : 
      61           0 :         for (contrail_rapidjson::SizeType i = 0; i < gsc.Size(); i++) {
      62           0 :             if (!gsc[i].IsObject() || !gsc[i].HasMember("name") ||
      63           0 :                     !gsc[i].HasMember("pattern")) {
      64           0 :                 continue;
      65             :             }
      66           0 :             std::string name = gsc[i]["name"].GetString(),
      67           0 :                         patrn = gsc[i]["pattern"].GetString();
      68           0 :             AddConfig(name, patrn);
      69             :             std::cout << "\nname: " << name << "\npattern: "
      70           0 :                 << patrn << "\n";
      71           0 :         }
      72             : 
      73           0 :         Cfg_t::iterator cit=config_.begin();
      74           0 :         while (cit != config_.end()) {
      75           0 :             Cfg_t::iterator dit = cit++;
      76           0 :             if (!dit->second->IsRefreshed()) {
      77           0 :                 UserDefinedLogStatistic udc;
      78           0 :                 udc.set_name(dit->first);
      79           0 :                 udc.set_deleted(true);
      80           0 :                 UserDefinedLogStatisticUVE::Send(udc);
      81           0 :                 config_.erase(dit);
      82           0 :             }
      83             :         }
      84             :     }
      85             : 
      86           0 :     return;
      87             : }
      88             : 
      89             : void
      90           0 : UserDefinedCounters::MatchFilter(std::string text, LineParser::WordListType *w)
      91             : {
      92           0 :     for(Cfg_t::iterator it=config_.begin(); it != config_.end(); ++it) {
      93           0 :         if (LineParser::SearchPattern(it->second->regexp(), text)) {
      94           0 :             UserDefinedLogStatistic udc;
      95           0 :             udc.set_name(it->first);
      96           0 :             udc.set_rx_event(1);
      97           0 :             UserDefinedLogStatisticUVE::Send(udc);
      98           0 :             w->insert(it->first);
      99           0 :         }
     100             :     }
     101           0 : }
     102             : 
     103             : void
     104           0 : UserDefinedCounters::AddConfig(std::string name, std::string pattern)
     105             : {
     106           0 :     Cfg_t::iterator it=config_.find(name);
     107           0 :     if (it  != config_.end()) {
     108           0 :         if (pattern == it->second->pattern()) {
     109             :             // ignore
     110             :         } else {
     111           0 :             it->second->SetPattern(pattern);
     112             :         }
     113           0 :         it->second->Refresh();
     114             :     } else {
     115             :         boost::shared_ptr<UserDefinedCounterData> c(new UserDefinedCounterData(
     116           0 :                     name, pattern));
     117             :         //config_.insert(std::make_pair<std::string,
     118             :         //        boost::shared_ptr<UserDefinedCounterData> >(name, c));
     119           0 :          config_.insert(std::make_pair(name, c));
     120             : 
     121           0 :     }
     122           0 : }
     123             : 
     124             : bool
     125           0 : UserDefinedCounters::FindByName(std::string name) {
     126           0 :     Cfg_t::iterator it=config_.find(name);
     127           0 :     return it  != config_.end();
     128             : }
     129             : 
     130             : void 
     131           0 : UserDefinedCounters::GetUDCConfig(std::vector<LogStatisticConfigInfo> 
     132             :                                               *config_info) {
     133           0 :     for (Cfg_t::iterator it = config_.begin(); 
     134           0 :                  it != config_.end(); it++) {
     135           0 :         LogStatisticConfigInfo config;
     136           0 :         config.set_name(it->second->name());
     137           0 :         config.set_pattern(it->second->pattern());
     138           0 :         config_info->push_back(config);
     139           0 :     }
     140           0 : }

Generated by: LCOV version 1.14