Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef __VIZ_MESSAGE_H__ 6 : #define __VIZ_MESSAGE_H__ 7 : 8 : #include <string> 9 : #include <boost/uuid/uuid.hpp> 10 : #include <boost/ptr_container/ptr_map.hpp> 11 : #include <pugixml/pugixml.hpp> 12 : 13 : #include <sandesh/sandesh_types.h> 14 : 15 : #define VIZD_ASSERT(condition) assert((condition)); 16 : 17 : class SandeshMessage; 18 : 19 : /* message format used to store in the cassandra */ 20 : struct VizMsg { 21 11 : VizMsg(const SandeshMessage *msg, 22 11 : boost::uuids::uuid unm) : 23 11 : msg(msg), 24 11 : unm(unm) {} 25 11 : ~VizMsg() {} 26 : 27 : const SandeshMessage *msg; 28 : boost::uuids::uuid unm; /* uuid key for this message in the global table */ 29 : std::string keyword_doc_; 30 : }; 31 : 32 : class SandeshStats; 33 : class SandeshLogLevelStats; 34 : class SandeshMessageInfo; 35 : 36 : struct VizMsgStats { 37 0 : VizMsgStats() : messages(0), bytes(0), last_msg_timestamp(0) {} 38 : 39 : void Update(const VizMsg *vmsg); 40 : template <typename K, typename T> void Get(const K &key, T *stats) const; 41 : 42 : uint64_t messages; 43 : uint64_t bytes; 44 : uint64_t last_msg_timestamp; 45 : }; 46 : 47 : struct VizMsgStatistics { 48 9 : VizMsgStatistics() {} 49 : 50 : void Update(const VizMsg *vmsg); 51 : void Get(std::vector<SandeshStats> *ssv) const; 52 : void Get(std::vector<SandeshLogLevelStats> *lsv) const; 53 : void Get(std::vector<SandeshMessageInfo> *sms); 54 : 55 : typedef boost::ptr_map<std::string, VizMsgStats> TypeMap; 56 : TypeMap type_map; 57 : 58 : typedef boost::ptr_map<std::string, VizMsgStats> LevelMap; 59 : LevelMap level_map; 60 : 61 : typedef std::pair<std::string, std::string> TypeLevelKey; 62 : typedef boost::ptr_map<TypeLevelKey, VizMsgStats> TypeLevelMap; 63 : TypeLevelMap type_level_map; 64 : }; 65 : 66 : /* generic message for ruleeng processing */ 67 : struct RuleMsg { 68 : public: 69 : RuleMsg(const VizMsg *vmsgp); 70 : ~RuleMsg(); 71 : 72 : int field_value(const std::string& field_id, std::string& type, 73 : std::string& value) const; 74 : 75 : struct RuleMsgPredicate { 76 7 : RuleMsgPredicate(const std::string &name) : tmp_(name) { } 77 : bool operator()(pugi::xml_attribute attr) const { 78 : return (strcmp(attr.name(), tmp_.c_str()) == 0); 79 : } 80 0 : bool operator()(pugi::xml_node node) const { 81 0 : return (strcmp(node.name(), tmp_.c_str()) == 0); 82 : } 83 : std::string tmp_; 84 : }; 85 : 86 : SandeshHeader hdr; 87 : std::string messagetype; 88 : 89 : private: 90 : int field_value_recur(const std::string& field_id, std::string& type, 91 : std::string& value, pugi::xml_node doc) const; 92 : 93 : pugi::xml_node message_node_; 94 : }; 95 : 96 : #endif // __VIZ_MESSAGE_H__ 97 :