1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #ifndef LIVESTATUSQUERY_H
4 #define LIVESTATUSQUERY_H
6 #include "livestatus/filter.hpp"
7 #include "livestatus/aggregator.hpp"
8 #include "base/object.hpp"
9 #include "base/array.hpp"
10 #include "base/stream.hpp"
11 #include "base/scriptframe.hpp"
14 using namespace icinga;
21 LivestatusErrorOK = 200,
22 LivestatusErrorNotFound = 404,
23 LivestatusErrorQuery = 452
29 class LivestatusQuery final : public Object
32 DECLARE_PTR_TYPEDEFS(LivestatusQuery);
34 LivestatusQuery(const std::vector<String>& lines, const String& compat_log_path);
36 bool Execute(const Stream::Ptr& stream);
38 static int GetExternalCommands();
45 /* Parameters for GET queries. */
47 std::vector<String> m_Columns;
48 std::vector<String> m_Separators;
51 std::deque<Aggregator::Ptr> m_Aggregators;
53 String m_OutputFormat;
57 String m_ResponseHeader;
59 /* Parameters for COMMAND/SCRIPT queries. */
63 /* Parameters for invalid queries. */
65 String m_ErrorMessage;
67 unsigned long m_LogTimeFrom;
68 unsigned long m_LogTimeUntil;
69 String m_CompatLogPath;
71 void BeginResultSet(std::ostream& fp) const;
72 void EndResultSet(std::ostream& fp) const;
73 void AppendResultRow(std::ostream& fp, const Array::Ptr& row, bool& first_row) const;
74 void PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level) const;
75 void PrintPythonArray(std::ostream& fp, const Array::Ptr& array) const;
76 static String QuoteStringPython(const String& str);
78 void ExecuteGetHelper(const Stream::Ptr& stream);
79 void ExecuteCommandHelper(const Stream::Ptr& stream);
80 void ExecuteErrorHelper(const Stream::Ptr& stream);
82 void SendResponse(const Stream::Ptr& stream, int code, const String& data);
83 void PrintFixed16(const Stream::Ptr& stream, int code, const String& data);
85 static Filter::Ptr ParseFilter(const String& params, unsigned long& from, unsigned long& until);
90 #endif /* LIVESTATUSQUERY_H */