]> granicus.if.org Git - icinga2/blob - lib/perfdata/perfdatawriter.hpp
Merge pull request #7527 from Icinga/bugfix/checkable-command-endpoint-zone
[icinga2] / lib / perfdata / perfdatawriter.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef PERFDATAWRITER_H
4 #define PERFDATAWRITER_H
5
6 #include "perfdata/perfdatawriter-ti.hpp"
7 #include "icinga/service.hpp"
8 #include "base/configobject.hpp"
9 #include "base/timer.hpp"
10 #include <fstream>
11
12 namespace icinga
13 {
14
15 /**
16  * An Icinga perfdata writer.
17  *
18  * @ingroup icinga
19  */
20 class PerfdataWriter final : public ObjectImpl<PerfdataWriter>
21 {
22 public:
23         DECLARE_OBJECT(PerfdataWriter);
24         DECLARE_OBJECTNAME(PerfdataWriter);
25
26         static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
27
28         void ValidateHostFormatTemplate(const Lazy<String>& lvalue, const ValidationUtils& utils) override;
29         void ValidateServiceFormatTemplate(const Lazy<String>& lvalue, const ValidationUtils& utils) override;
30
31 protected:
32         void OnConfigLoaded() override;
33         void Resume() override;
34         void Pause() override;
35
36 private:
37         Timer::Ptr m_RotationTimer;
38         std::ofstream m_ServiceOutputFile;
39         std::ofstream m_HostOutputFile;
40         boost::mutex m_StreamMutex;
41
42         void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
43         static Value EscapeMacroMetric(const Value& value);
44
45         void RotationTimerHandler();
46         void RotateAllFiles();
47         void RotateFile(std::ofstream& output, const String& temp_path, const String& perfdata_path);
48 };
49
50 }
51
52 #endif /* PERFDATAWRITER_H */