OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sandesh.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 //
6 // sandesh.cc
7 //
8 // Sandesh Implementation
9 //
10 
11 #include <boost/filesystem.hpp>
12 #include <boost/bind.hpp>
13 #include <boost/foreach.hpp>
14 #include <boost/format.hpp>
15 #include <boost/algorithm/string/predicate.hpp>
16 
17 #include <base/logging.h>
18 #include <base/parse_object.h>
19 #include <base/queue_task.h>
20 #include <base/address_util.h>
21 #include <http/http_session.h>
22 #include <io/tcp_session.h>
23 
24 #include <sandesh/transport/TBufferTransports.h>
25 #include <sandesh/transport/TSimpleFileTransport.h>
26 #include <sandesh/protocol/TBinaryProtocol.h>
27 #include <sandesh/protocol/TProtocol.h>
28 
29 #include <sandesh/sandesh_types.h>
30 #include <sandesh/sandesh.h>
31 #include <sandesh/sandesh_trace.h>
32 #include <sandesh/sandesh_uve_types.h>
33 #include "sandesh_statistics.h"
34 #include "sandesh_uve.h"
35 #include "sandesh_session.h"
36 #include "sandesh_http.h"
37 #include "sandesh_client.h"
38 #include "sandesh_connection.h"
39 #include "sandesh_state_machine.h"
40 
41 #include <log4cplus/helpers/pointer.h>
42 #include <log4cplus/configurator.h>
43 #include <log4cplus/fileappender.h>
44 #include <log4cplus/syslogappender.h>
45 
46 using boost::asio::ip::tcp;
47 using boost::asio::ip::address;
48 
49 using namespace contrail::sandesh::protocol;
50 using namespace contrail::sandesh::transport;
51 using namespace log4cplus;
52 
53 // Statics
54 Sandesh::SandeshRole::type Sandesh::role_ = SandeshRole::Invalid;
55 bool Sandesh::enable_local_log_ = false;
56 bool Sandesh::enable_flow_log_ = false;
58 int Sandesh::http_port_ = 0;
59 bool Sandesh::enable_trace_print_ = false;
66 bool Sandesh::slo_to_collector_ = false;
68 bool Sandesh::slo_to_logger_ = false;
69 bool Sandesh::sampled_to_logger_ = false;
72 std::unique_ptr<Sandesh::SandeshRxQueue> Sandesh::recv_queue_;
73 std::string Sandesh::module_;
74 std::string Sandesh::source_;
75 std::string Sandesh::node_type_;
76 std::string Sandesh::instance_id_;
77 int Sandesh::recv_task_id_ = -1;
82  getenv("SANDSH_UT_DEBUG") ? SandeshLevel::SYS_DEBUG : SandeshLevel::UT_DEBUG;
83 std::string Sandesh::logging_category_;
86 tbb::mutex Sandesh::stats_mutex_;
87 log4cplus::Logger Sandesh::logger_ =
88  log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("SANDESH"));
89 log4cplus::Logger Sandesh::slo_logger_ =
90  log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("SLO_SESSION"));
91 log4cplus::Logger Sandesh::sampled_logger_ =
92  log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("SAMPLED_SESSION"));
93 
95 tbb::atomic<uint32_t> Sandesh::sandesh_send_ratelimit_;
96 
97 const char *loggingPattern = "%D{%Y-%m-%d %a %H:%M:%S:%Q %Z} "
98  " %h [Thread %t, Pid %i]: %m%n";
99 
101  switch (role) {
102  case SandeshRole::Generator:
103  return "Generator";
104  case SandeshRole::Collector:
105  return "Collector";
106  case SandeshRole::Test:
107  return "Test";
108  case SandeshRole::Invalid:
109  return "Invalid";
110  default:
111  return "Unknown";
112  }
113 }
114 
115 void Sandesh::InitReceive(int recv_task_inst) {
116  assert(recv_task_id_ == -1);
118  recv_task_id_ = scheduler->GetTaskId("sandesh::RecvQueue");
119  recv_queue_.reset(new SandeshRxQueue(recv_task_id_, recv_task_inst,
121 }
122 
124  const SandeshConfig &config, bool periodicuve) {
125  connect_to_collector_ = true;
126  SANDESH_LOG(INFO, "SANDESH: CONNECT TO COLLECTOR: " <<
127  connect_to_collector_);
128  // Create and initialize the client
129  assert(client_ == NULL);
130  std::vector<Endpoint> collector_endpoints = boost::assign::list_of(server);
131  client_ = new SandeshClient(evm, collector_endpoints, config,
132  periodicuve);
133  client_->Initiate();
134 }
135 
136 static int32_t SandeshHttpCallback(SandeshRequest *rsnh) {
137  return rsnh->Enqueue(Sandesh::recv_queue());
138 }
139 
140 extern int PullSandeshGenStatsReq;
141 extern int PullSandeshUVE;
142 extern int PullSandeshTraceReq;
143 
145  const std::string &module,
146  const std::string &source,
147  const std::string &node_type,
148  const std::string &instance_id,
149  EventManager *evm,
150  unsigned short http_port,
151  SandeshContext *client_context,
152  const SandeshConfig &config) {
154  PullSandeshUVE = 1;
156 
157  if (role_ != SandeshRole::Invalid || role == SandeshRole::Invalid) {
158  return true;
159  }
160 
161  SANDESH_LOG(INFO, "SANDESH: ROLE : " << SandeshRoleToString(role));
162  SANDESH_LOG(INFO, "SANDESH: MODULE : " << module);
163  SANDESH_LOG(INFO, "SANDESH: SOURCE : " << source);
164  SANDESH_LOG(INFO, "SANDESH: NODE TYPE : " << node_type);
165  SANDESH_LOG(INFO, "SANDESH: INSTANCE ID : " << instance_id);
166  SANDESH_LOG(INFO, "SANDESH: HTTP SERVER PORT : " << http_port);
167 
168  role_ = role;
169  module_ = module;
170  source_ = source;
171  node_type_ = node_type;
172  instance_id_ = instance_id;
173  client_context_ = client_context;
174  config_ = config;
175  event_manager_ = evm;
176 
177  set_send_rate_limit(config.system_logs_rate_limit);
178  DisableSendingObjectLogs(config.disable_object_logs);
179  InitReceive(Task::kTaskInstanceAny);
180  bool success(SandeshHttp::Init(evm, module, http_port,
181  &SandeshHttpCallback, &http_port_, config_));
182  if (!success) {
183  SANDESH_LOG(ERROR, "SANDESH: HTTP INIT FAILED (PORT " <<
184  http_port << ")");
185  return false;
186  }
187  RecordPort("http", module_, http_port_);
188  return true;
189 }
190 
191 void Sandesh::RecordPort(const std::string& name, const std::string& module, unsigned short port) {
192  int fd;
193  std::ostringstream myfifoss;
194  myfifoss << "/tmp/" << module << "." << getppid() << "." << name << "_port";
195  std::string myfifo = myfifoss.str();
196  std::ostringstream hss;
197  hss << port << "\n";
198  std::string hstr = hss.str();
199 
200  fd = open(myfifo.c_str(), O_WRONLY | O_NONBLOCK);
201  if (fd != -1) {
202  SANDESH_LOG(INFO, "SANDESH: Write " << name << "_port " << port <<
203  "TO : " << myfifo);
204  write(fd, hstr.c_str(), hstr.length());
205  close(fd);
206  } else {
207  SANDESH_LOG(INFO, "SANDESH: NOT Writing " << name << "_port " << port <<
208  "TO : " << myfifo);
209  }
210 }
211 
212 bool Sandesh::ConnectToCollector(const std::string &collector_ip,
213  int collector_port, bool periodicuve) {
214  boost::system::error_code ec;
215  address collector_addr = AddressFromString(collector_ip, &ec);
216  if (ec) {
217  SANDESH_LOG(ERROR, __func__ << ": Invalid collector address: " <<
218  collector_ip << " Error: " << ec);
219  return false;
220  }
221 
222  SANDESH_LOG(INFO, "SANDESH: COLLECTOR : " << collector_ip);
223  SANDESH_LOG(INFO, "SANDESH: COLLECTOR PORT : " << collector_port);
224 
225  tcp::endpoint collector(collector_addr, collector_port);
226  InitClient(event_manager_, collector, Sandesh::config(), periodicuve);
227  return true;
228 }
229 
230 void Sandesh::ReConfigCollectors(const std::vector<std::string>& collector_list) {
231  if (client_) {
232  client_->ReConfigCollectors(collector_list);
233  }
234 }
235 
237  const std::vector<std::string> &collectors,
238  const SandeshConfig &config) {
239  connect_to_collector_ = true;
240  SANDESH_LOG(INFO, "SANDESH: CONNECT TO COLLECTOR: " <<
241  connect_to_collector_);
242  std::vector<Endpoint> collector_endpoints;
243  BOOST_FOREACH(const std::string &collector, collectors) {
244  Endpoint ep;
245  if (!MakeEndpoint(&ep, collector)) {
246  SANDESH_LOG(ERROR, __func__ << ": Invalid collector address: " <<
247  collector);
248  return false;
249  }
250  collector_endpoints.push_back(ep);
251  }
252  client_ = new SandeshClient(evm, collector_endpoints, config, true);
253  client_->Initiate();
254  return true;
255 }
256 
257 bool Sandesh::InitGenerator(const std::string &module,
258  const std::string &source,
259  const std::string &node_type,
260  const std::string &instance_id,
261  EventManager *evm,
262  unsigned short http_port,
263  SandeshContext *client_context,
264  DerivedStats ds,
265  const SandeshConfig &config) {
267  return Initialize(SandeshRole::Generator, module, source, node_type,
268  instance_id, evm, http_port, client_context, config);
269 }
270 
271 bool Sandesh::InitGenerator(const std::string &module,
272  const std::string &source,
273  const std::string &node_type,
274  const std::string &instance_id,
275  EventManager *evm,
276  unsigned short http_port,
277  const std::vector<std::string> &collectors,
278  SandeshContext *client_context,
279  DerivedStats ds,
280  const SandeshConfig &config) {
282  bool success(Initialize(SandeshRole::Generator, module, source, node_type,
283  instance_id, evm, http_port, client_context,
284  config));
285  if (!success) {
286  return false;
287  }
288  return InitClient(evm, collectors, config);
289 }
290 
291 // Collector
292 bool Sandesh::InitCollector(const std::string &module,
293  const std::string &source,
294  const std::string &node_type,
295  const std::string &instance_id,
296  EventManager *evm,
297  const std::string &collector_ip, int collector_port,
298  unsigned short http_port,
299  SandeshContext *client_context,
300  const SandeshConfig &config) {
301  bool success(Initialize(SandeshRole::Collector, module, source, node_type,
302  instance_id, evm, http_port, client_context,
303  config));
304  if (!success) {
305  return false;
306  }
307  return ConnectToCollector(collector_ip, collector_port, true);
308 }
309 
310 bool Sandesh::InitGeneratorTest(const std::string &module,
311  const std::string &source,
312  const std::string &node_type,
313  const std::string &instance_id,
314  EventManager *evm,
315  unsigned short http_port,
316  SandeshContext *client_context,
317  const SandeshConfig &config) {
318  return Initialize(SandeshRole::Test, module, source, node_type,
319  instance_id, evm, http_port, client_context, config);
320 }
321 
322 static void WaitForIdle() {
323  static const int kTimeout = 15;
325 
326  for (int i = 0; i < (kTimeout * 1000); i++) {
327  if (scheduler->IsEmpty()) {
328  break;
329  }
330  usleep(1000);
331  }
332 }
333 
334 void Sandesh::SetDscpValue(uint8_t value) {
335  SandeshClient *client = Sandesh::client();
336  if (client) {
337  client->SetDscpValue(value);
338  }
339 }
340 
342 
343  // Wait until all pending http session based tasks are cleaned up.
344  long count = 60000;
345  while (count--) {
346  if (HttpSession::GetPendingTaskCount() == 0) break;
347  usleep(1000);
348  }
350  role_ = SandeshRole::Invalid;
351  if (recv_queue_.get() != NULL) {
352  recv_queue_->Shutdown();
353  recv_queue_.reset(NULL);
354  assert(recv_task_id_ != -1);
355  recv_task_id_ = -1;
356  } else {
357  assert(recv_task_id_ == -1);
358  }
359  if (client_ != NULL) {
360  client_->Shutdown();
361  while (client()->IsSession()) usleep(100);
362  WaitForIdle();
363  client_->ClearSessions();
365  client_ = NULL;
366  }
367 }
368 
369 void Sandesh::SetLoggingParams(bool enable_local_log, std::string category,
370  std::string level, bool enable_trace_print, bool enable_flow_log,
371  bool enable_session_syslog) {
372  SetLocalLogging(enable_local_log);
373  SetLoggingCategory(category);
374  SetLoggingLevel(level);
375  SetTracePrint(enable_trace_print);
376  SetFlowLogging(enable_flow_log);
377  SetSessionSyslogging(enable_session_syslog);
378 }
379 
380 void Sandesh::SetLoggingParams(bool enable_local_log, std::string category,
381  SandeshLevel::type level, bool enable_trace_print,
382  bool enable_flow_log) {
383  SetLocalLogging(enable_local_log);
384  SetLoggingCategory(category);
385  SetLoggingLevel(level);
386  SetTracePrint(enable_trace_print);
387  SetFlowLogging(enable_flow_log);
388 }
389 
390 void Sandesh::SetLoggingLevel(std::string level) {
391  SandeshLevel::type nlevel = StringToLevel(level);
392  SetLoggingLevel(nlevel);
393 }
394 
395 log4cplus::LogLevel SandeshLevelTolog4Level(
396  SandeshLevel::type slevel) {
397  switch (slevel) {
398  case SandeshLevel::SYS_EMERG:
399  case SandeshLevel::SYS_ALERT:
400  case SandeshLevel::SYS_CRIT:
401  return log4cplus::FATAL_LOG_LEVEL;
402  case SandeshLevel::SYS_ERR:
403  return log4cplus::ERROR_LOG_LEVEL;
404  case SandeshLevel::SYS_WARN:
405  case SandeshLevel::SYS_NOTICE:
406  return log4cplus::WARN_LOG_LEVEL;
407  case SandeshLevel::SYS_INFO:
408  return log4cplus::INFO_LOG_LEVEL;
409  case SandeshLevel::SYS_DEBUG:
410  return log4cplus::DEBUG_LOG_LEVEL;
411  default:
413  return log4cplus::ALL_LOG_LEVEL;
414  }
415 }
416 
418  log4cplus::LogLevel log4_new_level(SandeshLevelTolog4Level(level));
419  log4cplus::LogLevel log4_old_level(logger_.getLogLevel());
420  if (logging_level_ != level ||
421  log4_old_level != log4_new_level) {
422  const log4cplus::LogLevelManager &log4level_manager(
423  log4cplus::getLogLevelManager());
424  SANDESH_LOG(INFO, "SANDESH: Logging: LEVEL: " << "[ " <<
425  LevelToString(logging_level_) << " ] -> [ " <<
426  LevelToString(level) << " ] log4level: [ " <<
427  log4level_manager.toString(log4_old_level) <<
428  " ] -> [ " <<
429  log4level_manager.toString(log4_new_level) <<
430  " ]");
431  logging_level_ = level;
432  logger_.setLogLevel(log4_new_level);
433  // Set the LogLevel on rootLogger
434  ::SetLoggingLevel(log4_new_level);
435  }
436 }
437 
438 void Sandesh::SetLoggingCategory(std::string category) {
439  if (logging_category_ != category) {
440  SANDESH_LOG(INFO, "SANDESH: Logging: CATEGORY: " <<
441  (logging_category_.empty() ? "*" : logging_category_) << " -> " <<
442  (category.empty() ? "*" : category));
443  logging_category_ = category;
444  }
445 }
446 
447 void Sandesh::SetLocalLogging(bool enable_local_log) {
448  if (enable_local_log_ != enable_local_log) {
449  SANDESH_LOG(INFO, "SANDESH: Logging: " <<
450  (enable_local_log_ ? "ENABLED" : "DISABLED") << " -> " <<
451  (enable_local_log ? "ENABLED" : "DISABLED"));
452  enable_local_log_ = enable_local_log;
453  }
454 }
455 
456 void Sandesh::SetTracePrint(bool enable_trace_print) {
457  if (enable_trace_print_ != enable_trace_print) {
458  SANDESH_LOG(INFO, "SANDESH: Trace: PRINT: " <<
459  (enable_trace_print_ ? "ENABLED" : "DISABLED") << " -> " <<
460  (enable_trace_print ? "ENABLED" : "DISABLED"));
461  enable_trace_print_ = enable_trace_print;
462  }
463 }
464 
465 void Sandesh::SetFlowLogging(bool enable_flow_log) {
466  if (enable_flow_log_ != enable_flow_log) {
467  SANDESH_LOG(INFO, "SANDESH: Flow Logging: " <<
468  (enable_flow_log_ ? "ENABLED" : "DISABLED") << " -> " <<
469  (enable_flow_log ? "ENABLED" : "DISABLED"));
470  enable_flow_log_ = enable_flow_log;
471  }
472 }
473 
474 void Sandesh::SetSessionSyslogging(bool enable_session_syslog) {
475  if (enable_session_syslog_ != enable_session_syslog) {
476  SANDESH_LOG(INFO, "SANDESH: Flow Logging: " <<
477  (enable_session_syslog_ ? "ENABLED" : "DISABLED") << " -> " <<
478  (enable_session_syslog ? "ENABLED" : "DISABLED"));
479  enable_session_syslog_ = enable_session_syslog;
480  }
481 
482 }
483 
484 void Sandesh::DisableFlowCollection(bool disable) {
485  if (disable_flow_collection_ != disable) {
486  SANDESH_LOG(INFO, "SANDESH: Disable Flow Collection: " <<
487  disable_flow_collection_ << " -> " << disable);
488  disable_flow_collection_ = disable;
489  }
490 }
491 
493  if (disable_sending_all_ != disable) {
494  SANDESH_LOG(INFO, "SANDESH: Disable Sending ALL Messages: " <<
495  disable_sending_all_ << " -> " << disable);
496  disable_sending_all_ = disable;
497  }
498 }
499 
501  return disable_sending_all_;
502 }
503 
505  if (disable_sending_object_logs_ != disable) {
506  SANDESH_LOG(INFO, "SANDESH: Disable Sending Object Logs: " <<
507  disable_sending_object_logs_ << " -> " << disable);
508  disable_sending_object_logs_ = disable;
509  }
510 }
511 
513  return disable_sending_object_logs_;
514 }
515 
516 void Sandesh::DisableSendingFlows(bool disable) {
517  if (disable_sending_flows_ != disable) {
518  SANDESH_LOG(INFO, "SANDESH: Disable Sending Flows: " <<
519  disable_sending_flows_ << " -> " << disable);
520  disable_sending_flows_ = disable;
521  }
522 }
523 
525  return disable_sending_flows_;
526 }
527 
529  return sandesh_send_ratelimit_ == 0;
530 }
531 
532 void Sandesh::set_send_rate_limit(int rate_limit) {
533  if (rate_limit >= 0) {
534  SANDESH_LOG(INFO, "SANDESH: System Log Send Rate Limit: " <<
535  sandesh_send_ratelimit_ << " -> " << rate_limit);
536  sandesh_send_ratelimit_ = rate_limit;
537  }
538 }
539 
541  return sandesh_send_ratelimit_;
542 }
543 
545  if (!queue) {
546  if (IsLoggingDroppedAllowed(type())) {
547  SANDESH_LOG(ERROR, __func__ << ": SandeshQueue NULL : Dropping Message: "
548  << ToString());
549  }
550  UpdateTxMsgFailStats(name_, 0, SandeshTxDropReason::NoQueue);
551  Release();
552  return false;
553  }
554  //Frame an elemet object and enqueue it
555  SandeshElement elem(this);
556  if (!queue->Enqueue(elem)) {
557  // XXX Change when WorkQueue implements bounded queues
558  return true;
559  }
560  return true;
561 }
562 
564  rsnh->HandleRequest();
565  rsnh->Release();
566  return true;
567 }
568 
569 void SandeshRequest::Release() { self_.reset(); }
570 
571 int32_t Sandesh::WriteBinary(u_int8_t *buf, u_int32_t buf_len,
572  int *error) {
573  int32_t xfer;
574  boost::shared_ptr<TMemoryBuffer> btrans =
575  boost::shared_ptr<TMemoryBuffer>(
576  new TMemoryBuffer(buf, buf_len));
577  btrans->setWriteBuffer(buf, buf_len);
578  boost::shared_ptr<TBinaryProtocol> prot =
579  boost::shared_ptr<TBinaryProtocol>(new TBinaryProtocol(btrans));
580  xfer = Write(prot);
581  if (xfer < 0) {
582  SANDESH_LOG(DEBUG, __func__ << "Write sandesh to " << buf_len <<
583  " bytes FAILED" << std::endl);
584  *error = EINVAL;
585  return xfer;
586  }
587  return xfer;
588 }
589 
590 int32_t Sandesh::ReadBinary(u_int8_t *buf, u_int32_t buf_len,
591  int *error) {
592  int32_t xfer = 0;
593  boost::shared_ptr<TMemoryBuffer> btrans =
594  boost::shared_ptr<TMemoryBuffer>(
595  new TMemoryBuffer(buf, buf_len));
596  boost::shared_ptr<TBinaryProtocol> prot =
597  boost::shared_ptr<TBinaryProtocol>(new TBinaryProtocol(btrans));
598  xfer = Read(prot);
599  if (xfer < 0) {
600  SANDESH_LOG(DEBUG, __func__ << "Read sandesh from " << buf_len <<
601  " bytes FAILED" << std::endl);
602  *error = EINVAL;
603  return xfer;
604  }
605  return xfer;
606 }
607 
608 int32_t Sandesh::WriteBinaryToFile(const std::string& path, int *error) {
609  int32_t xfer;
610  boost::shared_ptr<TSimpleFileTransport> btrans =
611  boost::shared_ptr<TSimpleFileTransport>(
612  new TSimpleFileTransport(path, false, true));
613  boost::shared_ptr<TBinaryProtocol> prot =
614  boost::shared_ptr<TBinaryProtocol>(new TBinaryProtocol(btrans));
615  xfer = Write(prot);
616  if (xfer < 0) {
617  SANDESH_LOG(DEBUG, __func__ << "Write sandesh to file FAILED"
618  << std::endl);
619  *error = EINVAL;
620  return xfer;
621  }
622  return xfer;
623 }
624 
625 int32_t Sandesh::ReadBinaryFromFile(const std::string& path, int *error) {
626  int32_t xfer;
627  boost::shared_ptr<TSimpleFileTransport> btrans =
628  boost::shared_ptr<TSimpleFileTransport>(
629  new TSimpleFileTransport(path));
630  boost::shared_ptr<TBinaryProtocol> prot =
631  boost::shared_ptr<TBinaryProtocol>(new TBinaryProtocol(btrans));
632  xfer = Read(prot);
633  if (xfer < 0) {
634  SANDESH_LOG(DEBUG, __func__ << "Read sandesh from file FAILED"
635  << std::endl);
636  *error = EINVAL;
637  return xfer;
638  }
639  return xfer;
640 }
641 
642 int32_t Sandesh::ReceiveBinaryMsgOne(u_int8_t *buf, u_int32_t buf_len,
643  int *error, SandeshContext *client_context) {
644  int32_t xfer;
645  std::string sandesh_name;
646  boost::shared_ptr<TMemoryBuffer> btrans =
647  boost::shared_ptr<TMemoryBuffer>(
648  new TMemoryBuffer(buf, buf_len));
649  boost::shared_ptr<TBinaryProtocol> prot =
650  boost::shared_ptr<TBinaryProtocol>(new TBinaryProtocol(btrans));
651  // Extract sandesh name
652  xfer = prot->readSandeshBegin(sandesh_name);
653  if (xfer < 0) {
654  SANDESH_LOG(DEBUG, __func__ << "Read sandesh begin from " << buf_len <<
655  " bytes FAILED" << std::endl);
656  *error = EINVAL;
657  return xfer;
658  }
659  // Create and process the sandesh
660  Sandesh *sandesh = SandeshBaseFactory::CreateInstance(sandesh_name);
661  if (sandesh == NULL) {
662  SANDESH_LOG(DEBUG, __func__ << " Unknown sandesh:" <<
663  sandesh_name << std::endl);
664  *error = EINVAL;
665  return -1;
666  }
667  // Reinitialize buffer and protocol
668  btrans = boost::shared_ptr<TMemoryBuffer>(
669  new TMemoryBuffer(buf, buf_len));
670  prot = boost::shared_ptr<TBinaryProtocol>(new TBinaryProtocol(btrans));
671  xfer = sandesh->Read(prot);
672  if (xfer < 0) {
673  SANDESH_LOG(DEBUG, __func__ << " Decoding " << sandesh_name << " FAILED" <<
674  std::endl);
675  *error = EINVAL;
676  return xfer;
677  }
678  SandeshBuffer * bsnh = dynamic_cast<SandeshBuffer *>(sandesh);
679  if (bsnh) bsnh->Process(client_context);
680  sandesh->Release();
681  return xfer;
682 }
683 
684 int32_t Sandesh::ReceiveBinaryMsg(u_int8_t *buf, u_int32_t buf_len,
685  int *error, SandeshContext *client_context) {
686  u_int32_t xfer = 0;
687  int ret;
688  while (xfer < buf_len) {
689  ret = ReceiveBinaryMsgOne(buf + xfer, buf_len - xfer, error,
690  client_context);
691  if (ret < 0) {
692  SANDESH_LOG(DEBUG, __func__ << "Read sandesh from " << buf_len <<
693  " bytes at offset " << xfer << " FAILED (" <<
694  error << ")");
695  return ret;
696  }
697  xfer += ret;
698  }
699  return xfer;
700 }
701 
703  if (!client_) {
704  if (IsLoggingDroppedAllowed(type())) {
705  if (IsConnectToCollectorEnabled()) {
706  SANDESH_LOG(ERROR, "SANDESH: No client: " << ToString());
707  } else {
708  Log();
709  }
710  }
711  UpdateTxMsgFailStats(name_, 0, SandeshTxDropReason::NoClient);
712  Release();
713  return false;
714  }
715  if (!client_->SendSandesh(this)) {
716  if (IsLoggingDroppedAllowed(type())) {
717  SANDESH_LOG(ERROR, "SANDESH: Send FAILED: " << ToString());
718  }
719  UpdateTxMsgFailStats(name_, 0,
720  SandeshTxDropReason::ClientSendFailed);
721  Release();
722  return false;
723  }
724  return true;
725 }
726 
728  // Sandesh client does not have a connection
729  if (sconn) {
730  return sconn->SendSandesh(this);
731  } else {
732  return SendEnqueue();
733  }
734 }
735 
737  assert(sconn == NULL);
738  if ((context().find("http%") == 0) ||
739  (context().find("https%") == 0)) {
740  SandeshHttp::Response(this, context());
741  return true;
742  }
743  if (response_callback_) {
744  response_callback_(this);
745  }
746  return Sandesh::Dispatch(sconn);
747 }
748 
750  assert(sconn == NULL);
751  if ((0 == context().find("http%")) ||
752  (0 == context().find("https%"))) {
753  SandeshHttp::Response(this, context());
754  return true;
755  }
756  return Sandesh::Dispatch();
757 }
758 
760  assert(sconn == NULL);
761  if ((0 == context().find("http%")) ||
762  (0 == context().find("https%"))) {
763  SandeshHttp::Response(this, context());
764  return true;
765  }
766  if (client_) {
767  if (IsSendingAllMessagesDisabled()) {
768  Log();
769  UpdateTxMsgFailStats(Name(), 0,
770  SandeshTxDropReason::SendingDisabled);
771  Release();
772  return false;
773  }
774  // SandeshUVE has an implicit send level of SandeshLevel::SYS_UVE
775  // which is irrespective of the level set by the user in the Send.
776  // This is needed so that the send queue does not grow unbounded.
777  // Once the send queue's sending level reaches SandeshLevel::SYS_UVE
778  // we will reset the connection to the collector to initiate resync
779  // of the UVE cache
780  if (SandeshLevel::SYS_UVE >= SendingLevel()) {
781  client_->CloseSMSession();
782  }
783  if (!client_->SendSandeshUVE(this)) {
784  SANDESH_LOG(ERROR, "SandeshUVE : Send FAILED: " << ToString());
785  UpdateTxMsgFailStats(Name(), 0,
786  SandeshTxDropReason::ClientSendFailed);
787  Release();
788  return false;
789  }
790  return true;
791  }
792  if (IsConnectToCollectorEnabled()) {
793  SANDESH_LOG(ERROR, "SANDESH: No Client: " << ToString());
794  } else {
795  Log();
796  }
797  UpdateTxMsgFailStats(Name(), 0, SandeshTxDropReason::NoClient);
798  Release();
799  return false;
800 }
801 
803  if (!queue) {
804  SANDESH_LOG(ERROR, "SandeshRequest: No RxQueue: " << ToString());
805  UpdateRxMsgFailStats(Name(), 0, SandeshRxDropReason::NoQueue);
806  Release();
807  return false;
808  }
809  if (!queue->Enqueue(this)) {
810  // XXX Change when WorkQueue implements bounded queues
811  return true;
812  }
813  return true;
814 }
815 
817  return level >= SandeshLevel::UT_START &&
818  level <= SandeshLevel::UT_END;
819 }
820 
822  SandeshLevel::type level,
823  const std::string& category) {
824  // Do not log UVEs unless explicitly configured via setting log_level
825  // to INVALID. This is to avoid flooding the log files with UVEs
826  if (type == SandeshType::UVE) {
827  level = SandeshLevel::INVALID;
828  }
829  bool level_allowed = logging_level_ >= level;
830  bool category_allowed = !logging_category_.empty() ?
831  logging_category_ == category : true;
832  return level_allowed && category_allowed;
833 }
834 
836  if (type_ == SandeshType::FLOW || type_ == SandeshType::SESSION) {
837  return enable_flow_log_;
838  } else {
839  return IsLocalLoggingEnabled() &&
840  IsLevelCategoryLoggingAllowed(type_, level_, category_);
841  }
842 }
843 
845  if (type == SandeshType::FLOW || type == SandeshType::SESSION) {
846  return enable_flow_log_;
847  } else {
848  return true;
849  }
850 }
851 
853  std::map<int, const char*>::const_iterator it = _SandeshLevel_VALUES_TO_NAMES.find(level);
854  if (it != _SandeshLevel_VALUES_TO_NAMES.end()) {
855  return it->second;
856  } else {
857  return "UNKNOWN";
858  }
859 }
860 
862  std::map<int, const char*>::const_iterator it = _SandeshLevel_VALUES_TO_NAMES.begin();
863  while (it != _SandeshLevel_VALUES_TO_NAMES.end()) {
864  if (strncmp(level.c_str(), it->second, strlen(it->second)) == 0) {
865  return static_cast<SandeshLevel::type>(it->first);
866  }
867  it++;
868  }
869  return SandeshLevel::INVALID;
870 }
871 
872 void Sandesh::UpdateRxMsgStats(const std::string &msg_name,
873  uint64_t bytes) {
874  tbb::mutex::scoped_lock lock(stats_mutex_);
875  msg_stats_.UpdateRecv(msg_name, bytes);
876 }
877 
878 void Sandesh::UpdateRxMsgFailStats(const std::string &msg_name,
879  uint64_t bytes, SandeshRxDropReason::type dreason) {
880  tbb::mutex::scoped_lock lock(stats_mutex_);
881  msg_stats_.UpdateRecvFailed(msg_name, bytes, dreason);
882 }
883 
884 void Sandesh::UpdateTxMsgStats(const std::string &msg_name,
885  uint64_t bytes) {
886  tbb::mutex::scoped_lock lock(stats_mutex_);
887  msg_stats_.UpdateSend(msg_name, bytes);
888 }
889 
890 void Sandesh::UpdateTxMsgFailStats(const std::string &msg_name,
891  uint64_t bytes, SandeshTxDropReason::type dreason) {
892  tbb::mutex::scoped_lock lock(stats_mutex_);
893  msg_stats_.UpdateSendFailed(msg_name, bytes, dreason);
894 }
895 
897  std::vector<SandeshMessageTypeStats> *mtype_stats,
898  SandeshMessageStats *magg_stats) {
899  tbb::mutex::scoped_lock lock(stats_mutex_);
900  msg_stats_.Get(mtype_stats, magg_stats);
901 }
902 
904  boost::ptr_map<std::string, SandeshMessageTypeStats> *mtype_stats,
905  SandeshMessageStats *magg_stats) {
906  tbb::mutex::scoped_lock lock(stats_mutex_);
907  msg_stats_.Get(mtype_stats, magg_stats);
908 }
909 
910 void Sandesh::SetSendQueue(bool enable) {
911  if (send_queue_enabled_ != enable) {
912  SANDESH_LOG(INFO, "SANDESH: CLIENT: SEND QUEUE: " <<
913  (send_queue_enabled_ ? "ENABLED" : "DISABLED") << " -> " <<
914  (enable ? "ENABLED" : "DISABLED"));
915  send_queue_enabled_ = enable;
916  if (enable) {
917  if (client_ && client_->IsSession()) {
918  client_->session()->send_queue()->MayBeStartRunner();
919  }
920  }
921  }
922 }
923 
924 // In sandesh state machine on collector, we can only drop systemlog,
925 // objectlog, and flow. UVEs can only be dropped after being dequeued from
926 // the state machine and published on redis/kafka
927 bool DoDropSandeshMessage(const SandeshHeader &header,
928  const SandeshLevel::type drop_level) {
929  SandeshType::type stype(header.get_Type());
930  if (stype == SandeshType::SYSTEM ||
931  stype == SandeshType::OBJECT ||
932  stype == SandeshType::FLOW ||
933  stype == SandeshType::SESSION) {
934  // Is level above drop level?
935  SandeshLevel::type slevel(
936  static_cast<SandeshLevel::type>(header.get_Level()));
937  if (slevel >= drop_level) {
938  return true;
939  }
940  }
941  // Drop flow message if flow collection is disabled
943  (stype == SandeshType::FLOW || stype == SandeshType::SESSION)) {
944  return true;
945  }
946  return false;
947 }
948 
949 SandeshContext *Sandesh::module_context(const std::string &module_name) {
950  ModuleContextMap::const_iterator loc = module_context_.find(module_name);
951  if (loc != module_context_.end()) {
952  return loc->second;
953  }
954  return NULL;
955 }
956 
957 void Sandesh::set_module_context(const std::string &module_name,
958  SandeshContext *context) {
959  std::pair<ModuleContextMap::iterator, bool> result =
960  module_context_.insert(std::make_pair(module_name, context));
961  if (!result.second) {
962  result.first->second = context;
963  }
964 }
965 
967  const std::string& category) {
968  // Handle unit test scenario
969  if (IsUnitTest() || IsLevelUT(level)) {
970  return true;
971  }
972  return false;
973 }
974 
976  if (client_) {
977  SandeshSession *sess = client_->session();
978  if (sess) {
979  return sess->SendingLevel();
980  }
981  }
982  return SandeshLevel::INVALID;
983 }
984 
985 template<>
987  SandeshElement *element)
988  {
989  size_t sandesh_size = element->GetSize();
990  return count_.fetch_and_add(sandesh_size) + sandesh_size;
991 }
992 
993 template<>
995  SandeshElement *element) {
996  size_t sandesh_size = element->GetSize();
997  return count_.fetch_and_add((size_t)(0-sandesh_size)) - sandesh_size;
998 }
999 
1000 /*
1001  * Add the configured appenders for the sample logger
1002  */
1003 void Sandesh::set_logger_appender(const std::string &file_name, long max_file_size,
1004  int max_backup_index,
1005  const std::string &syslog_facility,
1006  const std::vector<std::string> &destn,
1007  const std::string &ident,
1008  bool is_sampled_logger) {
1009  log4cplus::Logger logger;
1010  if (is_sampled_logger) {
1011  logger = Sandesh::sampled_logger();
1012  } else {
1013  logger = Sandesh::slo_logger();
1014  }
1015  logger.setAdditivity(false);
1016  // Session messages log level is
1017  logger.setLogLevel(SandeshLevel::SYS_NOTICE);
1018  // Local logging for SLO logger
1019  if (std::find(destn.begin(), destn.end(), "file") !=
1020  destn.end()) {
1021  // Append file appender to SLO logger
1022  SharedAppenderPtr fileappender(new RollingFileAppender(file_name,
1023  max_file_size, max_backup_index));
1024  logger.addAppender(fileappender);
1025  if (is_sampled_logger) {
1027  } else {
1028  Sandesh::slo_to_logger_ = true;
1029  }
1030  }
1031  // SYSLOG appender for SLO logger
1032  if (std::find(destn.begin(), destn.end(), "syslog") !=
1033  destn.end()) {
1034  helpers::Properties props;
1035  std::string syslogident = boost::str(
1036  boost::format("%1%[%2%]") % ident % getpid());
1037  props.setProperty(LOG4CPLUS_TEXT("facility"),
1038  boost::starts_with(syslog_facility, "LOG_")
1039  ? syslog_facility.substr(4)
1040  : syslog_facility);
1041  props.setProperty(LOG4CPLUS_TEXT("ident"), syslogident);
1042  props.setProperty(LOG4CPLUS_TEXT("additivity"), "false");
1043  SharedAppenderPtr syslogappender(new SysLogAppender(props));
1044  std::unique_ptr<Layout> syslog_layout_ptr(new PatternLayout(
1045  loggingPattern));
1046  syslogappender->setLayout(std::move(syslog_layout_ptr));
1047  logger.addAppender(syslogappender);
1048  if (is_sampled_logger) {
1050  } else {
1051  Sandesh::slo_to_logger_ = true;
1052  }
1053  }
1054 }
1055 
1057  const std::vector<std::string> &sampled_destn,
1058  const std::vector<std::string> &slo_destn) {
1059  if (std::find(slo_destn.begin(), slo_destn.end(), "collector") !=
1060  slo_destn.end()) {
1062  }
1063  if (std::find(sampled_destn.begin(), sampled_destn.end(), "collector") !=
1064  sampled_destn.end()) {
1066  }
1067 }
bool MakeEndpoint(TcpServer::Endpoint *ep, const std::string &epstr)
Definition: sandesh_util.cc:18
boost::asio::ip::tcp::endpoint Endpoint
Definition: p/sandesh.h:137
log4cplus::LogLevel SandeshLevelTolog4Level(SandeshLevel::type slevel)
Definition: sandesh.cc:395
static void InitClient(EventManager *evm, Endpoint server, const SandeshConfig &config, bool periodicuve)
Definition: sandesh.cc:123
size_t GetSize() const
Definition: p/sandesh.h:459
static SandeshContext * module_context(const std::string &module_name)
Definition: sandesh.cc:949
static bool disable_sending_object_logs_
Definition: p/sandesh.h:434
static std::string instance_id_
Definition: p/sandesh.h:410
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:178
static bool sampled_to_collector_
Definition: p/sandesh.h:448
uint32_t system_logs_rate_limit
static void WaitForIdle()
Definition: sandesh.cc:322
static SandeshRole::type role_
Definition: p/sandesh.h:406
static SandeshLevel::type StringToLevel(std::string level)
Definition: sandesh.cc:861
bool Dispatch(SandeshConnection *sconn=NULL)
Definition: sandesh.cc:749
static void InitReceive(int recv_task_inst=-1)
Definition: sandesh.cc:115
int PullSandeshTraceReq
static SandeshLevel::type SendingLevel()
Definition: sandesh.cc:975
static bool InitDerivedStats(const std::map< std::string, ds_conf_elem > &)
Definition: sandesh_uve.cc:25
static const int kTaskInstanceAny
Definition: task.h:102
virtual int32_t WriteBinary(u_int8_t *buf, u_int32_t buf_len, int *error)
Definition: sandesh.cc:571
virtual void HandleRequest() const =0
static void ReConfigCollectors(const std::vector< std::string > &collector_list)
Definition: sandesh.cc:230
static Sandesh * CreateInstance(std::string const &s)
Definition: p/sandesh.h:623
int PullSandeshGenStatsReq
Definition: sandesh_req.cc:21
static void SetLoggingParams(bool enable_local_log, std::string category, std::string level, bool enable_trace_print=false, bool enable_flow_log=false, bool enable_session_syslog=false)
Definition: sandesh.cc:369
static bool HandleTest(SandeshLevel::type level, const std::string &category)
Definition: sandesh.cc:966
static tbb::atomic< long > GetPendingTaskCount()
Definition: http_session.h:45
int PullSandeshUVE
Definition: sandesh_uve.cc:21
static void SetSendQueue(bool enable)
Definition: sandesh.cc:910
static void set_send_rate_limit(int rate_limit)
Definition: sandesh.cc:532
static bool enable_trace_print_
Definition: p/sandesh.h:422
const char * loggingPattern
Definition: sandesh.cc:97
static std::unique_ptr< SandeshRxQueue > recv_queue_
Definition: p/sandesh.h:412
std::map< std::string, SandeshContext * > ModuleContextMap
Definition: p/sandesh.h:388
virtual int32_t ReadBinaryFromFile(const std::string &path, int *error)
Definition: sandesh.cc:625
static const char * SandeshRoleToString(SandeshRole::type role)
Definition: sandesh.cc:100
static void SetDscpValue(uint8_t value)
Definition: sandesh.cc:334
static log4cplus::Logger sampled_logger_
Definition: p/sandesh.h:430
#define SANDESH_LOG(_Level, _Msg)
Definition: p/sandesh.h:474
static log4cplus::Logger & sampled_logger()
Definition: p/sandesh.h:325
std::map< std::string, std::map< std::string, std::string > > DerivedStats
Definition: p/sandesh.h:148
static void UpdateRxMsgStats(const std::string &msg_name, uint64_t bytes)
Definition: sandesh.cc:872
void SetDscpValue(uint8_t value)
static void SetLoggingCategory(std::string category)
Definition: sandesh.cc:438
static bool ProcessRecv(SandeshRequest *)
Definition: sandesh.cc:563
static bool ConnectToCollector(const std::string &collector_ip, int collector_port, bool periodicuve=false)
Definition: sandesh.cc:212
int GetTaskId(const std::string &name)
Definition: task.cc:856
static int http_port_
Definition: p/sandesh.h:411
SandeshLevel::type SendingLevel() const
static void DisableSendingObjectLogs(bool disable)
Definition: sandesh.cc:504
static tbb::mutex stats_mutex_
Definition: p/sandesh.h:427
static void UpdateRxMsgFailStats(const std::string &msg_name, uint64_t bytes, SandeshRxDropReason::type dreason)
Definition: sandesh.cc:878
static log4cplus::Logger & slo_logger()
Definition: p/sandesh.h:324
static void UpdateTxMsgStats(const std::string &msg_name, uint64_t bytes)
Definition: sandesh.cc:884
boost::function< void(Sandesh *)> SandeshCallback
Definition: p/sandesh.h:138
static string ToString(PhysicalDevice::ManagementProtocol proto)
static SandeshLevel::type logging_ut_level_
Definition: p/sandesh.h:420
bool Enqueue(SandeshRxQueue *queue)
Definition: sandesh.cc:802
static void SetLocalLogging(bool enable)
Definition: sandesh.cc:447
static tbb::atomic< uint32_t > sandesh_send_ratelimit_
Definition: p/sandesh.h:446
static bool InitCollector(const std::string &module, const std::string &source, const std::string &node_type, const std::string &instance_id, EventManager *evm, const std::string &collector_ip, int collector_port, unsigned short http_port, SandeshContext *client_context=NULL, const SandeshConfig &config=SandeshConfig())
Definition: sandesh.cc:292
static bool disable_sending_flows_
Definition: p/sandesh.h:435
static void UpdateTxMsgFailStats(const std::string &msg_name, uint64_t bytes, SandeshTxDropReason::type dreason)
Definition: sandesh.cc:890
uint8_t type
Definition: load_balance.h:109
static bool IsSendingObjectLogsDisabled()
Definition: sandesh.cc:512
static bool disable_flow_collection_
Definition: p/sandesh.h:431
static const char * LevelToString(SandeshLevel::type level)
Definition: sandesh.cc:852
static void SetSessionSyslogging(bool enable_session_syslog)
Definition: sandesh.cc:474
static void SetLoggingLevel(std::string level)
Definition: sandesh.cc:390
static std::string node_type_
Definition: p/sandesh.h:409
virtual int32_t Read(boost::shared_ptr< contrail::sandesh::protocol::TProtocol > iprot)=0
static SandeshLevel::type logging_level_
Definition: p/sandesh.h:419
static TaskScheduler * GetInstance()
Definition: task.cc:547
bool Dispatch(SandeshConnection *sconn=NULL)
Definition: sandesh.cc:736
static bool enable_flow_log_
Definition: p/sandesh.h:417
static std::string module_
Definition: p/sandesh.h:407
static bool enable_session_syslog_
Definition: p/sandesh.h:418
static bool send_queue_enabled_
Definition: p/sandesh.h:425
static log4cplus::Logger slo_logger_
Definition: p/sandesh.h:429
static bool IsFlowCollectionDisabled()
Definition: p/sandesh.h:199
bool IsLoggingAllowed() const
Definition: sandesh.cc:835
bool DoDropSandeshMessage(const SandeshHeader &header, const SandeshLevel::type drop_level)
Definition: sandesh.cc:927
static SandeshClient * client_
Definition: p/sandesh.h:379
static int32_t ReceiveBinaryMsgOne(u_int8_t *buf, u_int32_t buf_len, int *error, SandeshContext *client_context)
Definition: sandesh.cc:642
static SandeshConfig config_
Definition: p/sandesh.h:432
static SandeshClient * client()
Definition: p/sandesh.h:306
virtual bool SendEnqueue()
Definition: sandesh.cc:702
static std::string logging_category_
Definition: p/sandesh.h:421
TBinaryProtocolT< TTransport > TBinaryProtocol
virtual void Release()
Definition: p/sandesh.h:266
bool IsEmpty(bool running_only=false)
Returns true if there are no tasks running and/or enqueued If running_only is true, enqueued tasks are ignored i.e. return true if there are no running tasks. Ignore TaskGroup or TaskEntry if it is disabled.
Definition: task.cc:823
static void DeleteServer(TcpServer *server)
Definition: tcp_server.cc:656
static log4cplus::Logger logger_
Definition: p/sandesh.h:428
static int32_t ReceiveBinaryMsg(u_int8_t *buf, u_int32_t buf_len, int *error, SandeshContext *client_context)
Definition: sandesh.cc:684
static bool IsSendingSystemLogsDisabled()
Definition: sandesh.cc:528
static void set_module_context(const std::string &module_name, SandeshContext *context)
Definition: sandesh.cc:957
static bool connect_to_collector_
Definition: p/sandesh.h:423
static bool InitGeneratorTest(const std::string &module, const std::string &source, const std::string &node_type, const std::string &instance_id, EventManager *evm, unsigned short http_port, SandeshContext *client_context=NULL, const SandeshConfig &config=SandeshConfig())
Definition: sandesh.cc:310
size_t AtomicIncrementQueueCount(QueueEntryT *entry)
Definition: queue_task.h:431
static bool IsSendingAllMessagesDisabled()
Definition: sandesh.cc:500
void Release()
Definition: sandesh.cc:569
IpAddress AddressFromString(const std::string &ip_address_str, boost::system::error_code *ec)
static bool InitGenerator(const std::string &module, const std::string &source, const std::string &node_type, const std::string &instance_id, EventManager *evm, unsigned short http_port, const std::vector< std::string > &collectors, SandeshContext *client_context=NULL, DerivedStats ds=DerivedStats(), const SandeshConfig &config=SandeshConfig())
Definition: sandesh.cc:271
size_t AtomicDecrementQueueCount(QueueEntryT *entry)
Definition: queue_task.h:435
virtual int32_t ReadBinary(u_int8_t *buf, u_int32_t buf_len, int *error)
Definition: sandesh.cc:590
static bool enable_local_log_
Definition: p/sandesh.h:416
static uint32_t get_send_rate_limit()
Definition: sandesh.cc:540
static int32_t SandeshHttpCallback(SandeshRequest *rsnh)
Definition: sandesh.cc:136
static SandeshRxQueue * recv_queue()
Definition: p/sandesh.h:298
bool Dispatch(SandeshConnection *sconn=NULL)
Definition: sandesh.cc:759
static bool IsLoggingDroppedAllowed(SandeshType::type)
Definition: sandesh.cc:844
static bool disable_sending_all_
Definition: p/sandesh.h:433
static SandeshCallback response_callback_
Definition: p/sandesh.h:378
static bool IsLevelUT(SandeshLevel::type level)
Definition: sandesh.cc:816
static void DisableFlowCollection(bool disable)
Definition: sandesh.cc:484
static void Uninit()
Definition: sandesh.cc:341
static void SetFlowLogging(bool enable)
Definition: sandesh.cc:465
static void set_logger_appender(const std::string &file_name, long max_file_size, int max_backup_index, const std::string &syslog_facility, const std::vector< std::string > &destn, const std::string &ident, bool is_sampled_logger)
Definition: sandesh.cc:1003
static SandeshMessageStatistics msg_stats_
Definition: p/sandesh.h:426
static bool Init(EventManager *evm, const std::string module, short port, RequestCallbackFn reqcb, int *hport, const SandeshConfig &config=SandeshConfig())
static bool Initialize(SandeshRole::type role, const std::string &module, const std::string &source, const std::string &node_type, const std::string &instance_id, EventManager *evm, unsigned short http_port, SandeshContext *client_context=NULL, const SandeshConfig &config=SandeshConfig())
Definition: sandesh.cc:144
virtual bool Dispatch(SandeshConnection *sconn=NULL)
Definition: sandesh.cc:727
static void RecordPort(const std::string &name, const std::string &module, unsigned short port)
Definition: sandesh.cc:191
bool disable_object_logs
static bool sampled_to_logger_
Definition: p/sandesh.h:450
static bool slo_to_collector_
Definition: p/sandesh.h:447
void SetLoggingLevel(LogLevel logLevel)
Definition: logging.cc:46
static std::string source_
Definition: p/sandesh.h:408
static void Response(Sandesh *snh, std::string context)
static void DisableSendingAllMessages(bool disable)
Definition: sandesh.cc:492
static EventManager * event_manager_
Definition: p/sandesh.h:424
static void GetMsgStats(std::vector< SandeshMessageTypeStats > *mtype_stats, SandeshMessageStats *magg_stats)
Definition: sandesh.cc:896
bool Enqueue(QueueEntryT entry)
Definition: queue_task.h:248
static SandeshContext * client_context_
Definition: p/sandesh.h:414
bool SendSandesh(Sandesh *snh)
static bool IsSendingFlowsDisabled()
Definition: sandesh.cc:524
static bool slo_to_logger_
Definition: p/sandesh.h:449
static bool IsLevelCategoryLoggingAllowed(SandeshType::type type, SandeshLevel::type level, const std::string &category)
Definition: sandesh.cc:821
static void DisableSendingFlows(bool disable)
Definition: sandesh.cc:516
static int recv_task_id_
Definition: p/sandesh.h:413
static void set_send_to_collector_flags(const std::vector< std::string > &sampled_destination, const std::vector< std::string > &slo_destination)
Definition: sandesh.cc:1056
static void SetTracePrint(bool enable)
Definition: sandesh.cc:456
static void Uninit(void)
static ModuleContextMap module_context_
Definition: p/sandesh.h:415
static EventManager evm
virtual int32_t WriteBinaryToFile(const std::string &path, int *error)
Definition: sandesh.cc:608
virtual void Process(SandeshContext *context)=0
static SandeshConfig & config()
Definition: p/sandesh.h:307
bool Enqueue(SandeshQueue *queue)
Definition: sandesh.cc:544