1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ 2 3 #ifndef STATUSDATAWRITER_H 4 #define STATUSDATAWRITER_H 5 6 #include "compat/statusdatawriter-ti.hpp" 7 #include "icinga/customvarobject.hpp" 8 #include "icinga/host.hpp" 9 #include "icinga/service.hpp" 10 #include "icinga/command.hpp" 11 #include "icinga/compatutility.hpp" 12 #include "base/timer.hpp" 13 #include "base/utility.hpp" 14 #include <iostream> 15 16 namespace icinga 17 { 18 19 /** 20 * @ingroup compat 21 */ 22 class StatusDataWriter final : public ObjectImpl<StatusDataWriter> 23 { 24 public: 25 DECLARE_OBJECT(StatusDataWriter); 26 DECLARE_OBJECTNAME(StatusDataWriter); 27 28 static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata); 29 30 protected: 31 void Start(bool runtimeCreated) override; 32 void Stop(bool runtimeRemoved) override; 33 34 private: 35 Timer::Ptr m_StatusTimer; 36 bool m_ObjectsCacheOutdated; 37 38 void DumpCommand(std::ostream& fp, const Command::Ptr& command); 39 void DumpTimePeriod(std::ostream& fp, const TimePeriod::Ptr& tp); 40 void DumpDowntimes(std::ostream& fp, const Checkable::Ptr& owner); 41 void DumpComments(std::ostream& fp, const Checkable::Ptr& owner); 42 void DumpHostStatus(std::ostream& fp, const Host::Ptr& host); 43 void DumpHostObject(std::ostream& fp, const Host::Ptr& host); 44 45 void DumpCheckableStatusAttrs(std::ostream& fp, const Checkable::Ptr& checkable); 46 47 template<typename T> DumpNameList(std::ostream & fp,const T & list)48 void DumpNameList(std::ostream& fp, const T& list) 49 { 50 bool first = true; 51 for (const auto& obj : list) { 52 if (!first) 53 fp << ","; 54 else 55 first = false; 56 57 fp << obj->GetName(); 58 } 59 } 60 61 template<typename T> DumpStringList(std::ostream & fp,const T & list)62 void DumpStringList(std::ostream& fp, const T& list) 63 { 64 bool first = true; 65 for (const auto& str : list) { 66 if (!first) 67 fp << ","; 68 else 69 first = false; 70 71 fp << str; 72 } 73 } 74 75 void DumpServiceStatus(std::ostream& fp, const Service::Ptr& service); 76 void DumpServiceObject(std::ostream& fp, const Service::Ptr& service); 77 78 void DumpCustomAttributes(std::ostream& fp, const CustomVarObject::Ptr& object); 79 80 void UpdateObjectsCache(); 81 void StatusTimerHandler(); 82 void ObjectHandler(); 83 84 static String GetNotificationOptions(const Checkable::Ptr& checkable); 85 }; 86 87 } 88 89 #endif /* STATUSDATAWRITER_H */ 90