# along with this program; if not, write to the Free Software Foundation
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
-mkclass_target(listener.ti listener.thpp)
+mkclass_target(livestatuslistener.ti livestatuslistener.thpp)
mkembedconfig_target(livestatus-type.conf livestatus-type.cpp)
commentstable.cpp contactgroupstable.cpp contactstable.cpp countaggregator.cpp
downtimestable.cpp endpointstable.cpp filter.cpp historytable.cpp
hostgroupstable.cpp hoststable.cpp invavgaggregator.cpp invsumaggregator.cpp
- listener.cpp listener.thpp logutility.cpp logtable.cpp maxaggregator.cpp
- minaggregator.cpp negatefilter.cpp orfilter.cpp query.cpp
+ livestatuslistener.cpp livestatuslistener.thpp livestatusquery.cpp
+ livestatuslogutility.cpp logtable.cpp maxaggregator.cpp
+ minaggregator.cpp negatefilter.cpp orfilter.cpp
servicegroupstable.cpp servicestable.cpp statehisttable.cpp
statustable.cpp stdaggregator.cpp sumaggregator.cpp table.cpp
timeperiodstable.cpp livestatus-type.cpp)
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "livestatus/listener.hpp"
+#include "livestatus/livestatuslistener.hpp"
#include "config/configcompilercontext.hpp"
#include "base/utility.hpp"
#include "base/objectlock.hpp"
if (lines.empty())
break;
- Query::Ptr query = make_shared<Query>(lines, GetCompatLogPath());
+ LivestatusQuery::Ptr query = make_shared<LivestatusQuery>(lines, GetCompatLogPath());
if (!query->Execute(stream))
break;
}
#ifndef LIVESTATUSLISTENER_H
#define LIVESTATUSLISTENER_H
-#include "livestatus/listener.thpp"
-#include "livestatus/query.hpp"
+#include "livestatus/livestatuslistener.thpp"
+#include "livestatus/livestatusquery.hpp"
#include "base/socket.hpp"
#include <boost/thread/thread.hpp>
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "livestatus/logutility.hpp"
+#include "livestatus/livestatuslogutility.hpp"
#include "icinga/service.hpp"
#include "icinga/host.hpp"
#include "icinga/user.hpp"
using namespace icinga;
-void LogUtility::CreateLogIndex(const String& path, std::map<time_t, String>& index)
+void LivestatusLogUtility::CreateLogIndex(const String& path, std::map<time_t, String>& index)
{
- Utility::Glob(path + "/icinga.log", boost::bind(&LogUtility::CreateLogIndexFileHandler, _1, boost::ref(index)), GlobFile);
- Utility::Glob(path + "/archives/*.log", boost::bind(&LogUtility::CreateLogIndexFileHandler, _1, boost::ref(index)), GlobFile);
+ Utility::Glob(path + "/icinga.log", boost::bind(&LivestatusLogUtility::CreateLogIndexFileHandler, _1, boost::ref(index)), GlobFile);
+ Utility::Glob(path + "/archives/*.log", boost::bind(&LivestatusLogUtility::CreateLogIndexFileHandler, _1, boost::ref(index)), GlobFile);
}
-void LogUtility::CreateLogIndexFileHandler(const String& path, std::map<time_t, String>& index)
+void LivestatusLogUtility::CreateLogIndexFileHandler(const String& path, std::map<time_t, String>& index)
{
std::ifstream stream;
stream.open(path.CStr(), std::ifstream::in);
stream.close();
- Log(LogDebug, "LivestatusListener/LogUtility", "Indexing log file: '" + path + "' with timestamp start: '" + Convert::ToString(ts_start) + "'.");
+ Log(LogDebug, "LivestatusLogUtility", "Indexing log file: '" + path + "' with timestamp start: '" + Convert::ToString(ts_start) + "'.");
index[ts_start] = path;
}
-void LogUtility::CreateLogCache(std::map<time_t, String> index, HistoryTable *table,
+void LivestatusLogUtility::CreateLogCache(std::map<time_t, String> index, HistoryTable *table,
time_t from, time_t until, const AddRowFunction& addRowFn)
{
ASSERT(table);
if (line.empty())
continue; /* Ignore empty lines */
- Dictionary::Ptr log_entry_attrs = LogUtility::GetAttributes(line);
+ Dictionary::Ptr log_entry_attrs = LivestatusLogUtility::GetAttributes(line);
/* no attributes available - invalid log line */
if (!log_entry_attrs) {
- Log(LogDebug, "LivestatusListener/LogUtility", "Skipping invalid log line: '" + line + "'.");
+ Log(LogDebug, "LivestatusLogUtility", "Skipping invalid log line: '" + line + "'.");
continue;
}
}
}
-Dictionary::Ptr LogUtility::GetAttributes(const String& text)
+Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text)
{
Dictionary::Ptr bag = make_shared<Dictionary>();
*/
unsigned long time = atoi(text.SubStr(1, 11).CStr());
- Log(LogDebug, "LivestatusListener/LogUtility", "Processing log line: '" + text + "'.");
+ Log(LogDebug, "LivestatusLogUtility", "Processing log line: '" + text + "'.");
bag->Set("time", time);
size_t colon = text.FindFirstOf(':');
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#ifndef LOGUTILITY_H
-#define LOGUTILITY_H
+#ifndef LIVESTATUSLOGUTILITY_H
+#define LIVESTATUSLOGUTILITY_H
#include "livestatus/historytable.hpp"
/**
* @ingroup livestatus
*/
-class LogUtility
+class LivestatusLogUtility
{
public:
static Dictionary::Ptr GetAttributes(const String& text);
private:
- LogUtility(void);
+ LivestatusLogUtility(void);
};
}
-#endif /* LOGUTILITY_H */
+#endif /* LIVESTATUSLOGUTILITY_H */
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "livestatus/query.hpp"
+#include "livestatus/livestatusquery.hpp"
#include "livestatus/countaggregator.hpp"
#include "livestatus/sumaggregator.hpp"
#include "livestatus/minaggregator.hpp"
static int l_ExternalCommands = 0;
static boost::mutex l_QueryMutex;
-Query::Query(const std::vector<String>& lines, const String& compat_log_path)
+LivestatusQuery::LivestatusQuery(const std::vector<String>& lines, const String& compat_log_path)
: m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true),
m_LogTimeFrom(0), m_LogTimeUntil(static_cast<long>(Utility::GetTime()))
{
BOOST_FOREACH(const String& line, lines) {
msg += line + "\n";
}
- Log(LogDebug, "LivestatusListener/Query", msg);
+ Log(LogDebug, "LivestatusQuery", msg);
m_CompatLogPath = compat_log_path;
if (header == "Or" || header == "StatsOr") {
filter = make_shared<OrFilter>();
- Log(LogDebug, "LivestatusListener/Query", "Add OR filter for " + params + " column(s). " + Convert::ToString(deq.size()) + " filters available.");
+ Log(LogDebug, "LivestatusQuery", "Add OR filter for " + params + " column(s). " + Convert::ToString(deq.size()) + " filters available.");
} else {
filter = make_shared<AndFilter>();
- Log(LogDebug, "LivestatusListener/Query", "Add AND filter for " + params + " column(s). " + Convert::ToString(deq.size()) + " filters available.");
+ Log(LogDebug, "LivestatusQuery", "Add AND filter for " + params + " column(s). " + Convert::ToString(deq.size()) + " filters available.");
}
if (num > deq.size()) {
while (num > 0 && num--) {
filter->AddSubFilter(deq.back());
- Log(LogDebug, "LivestatusListener/Query", "Add " + Convert::ToString(num) + " filter.");
+ Log(LogDebug, "LivestatusQuery", "Add " + Convert::ToString(num) + " filter.");
deq.pop_back();
if (&deq == &stats)
aggregators.pop_back();
m_Aggregators.swap(aggregators);
}
-int Query::GetExternalCommands(void)
+int LivestatusQuery::GetExternalCommands(void)
{
boost::mutex::scoped_lock lock(l_QueryMutex);
return l_ExternalCommands;
}
-Filter::Ptr Query::ParseFilter(const String& params, unsigned long& from, unsigned long& until)
+Filter::Ptr LivestatusQuery::ParseFilter(const String& params, unsigned long& from, unsigned long& until)
{
/*
* time >= 1382696656
}
}
- Log(LogDebug, "LivestatusListener/Query", "Parsed filter with attr: '" + attr + "' op: '" + op + "' val: '" + val + "'.");
+ Log(LogDebug, "LivestatusQuery", "Parsed filter with attr: '" + attr + "' op: '" + op + "' val: '" + val + "'.");
return filter;
}
-void Query::PrintResultSet(std::ostream& fp, const Array::Ptr& rs)
+void LivestatusQuery::PrintResultSet(std::ostream& fp, const Array::Ptr& rs)
{
if (m_OutputFormat == "csv") {
ObjectLock olock(rs);
}
}
-void Query::PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level)
+void LivestatusQuery::PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level)
{
bool first = true;
}
}
-void Query::ExecuteGetHelper(const Stream::Ptr& stream)
+void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream)
{
- Log(LogInformation, "LivestatusListener/Query", "Table: " + m_Table);
+ Log(LogInformation, "LivestatusQuery", "Table: " + m_Table);
Table::Ptr table = Table::GetByName(m_Table, m_CompatLogPath, m_LogTimeFrom, m_LogTimeUntil);
SendResponse(stream, LivestatusErrorOK, result.str());
}
-void Query::ExecuteCommandHelper(const Stream::Ptr& stream)
+void LivestatusQuery::ExecuteCommandHelper(const Stream::Ptr& stream)
{
{
boost::mutex::scoped_lock lock(l_QueryMutex);
l_ExternalCommands++;
}
- Log(LogInformation, "LivestatusListener/Query", "Executing command: " + m_Command);
+ Log(LogInformation, "LivestatusQuery", "Executing command: " + m_Command);
ExternalCommandProcessor::Execute(m_Command);
SendResponse(stream, LivestatusErrorOK, "");
}
-void Query::ExecuteErrorHelper(const Stream::Ptr& stream)
+void LivestatusQuery::ExecuteErrorHelper(const Stream::Ptr& stream)
{
- Log(LogDebug, "LivestatusListener/Query", "ERROR: Code: '" + Convert::ToString(m_ErrorCode) + "' Message: '" + m_ErrorMessage + "'.");
+ Log(LogDebug, "LivestatusQuery", "ERROR: Code: '" + Convert::ToString(m_ErrorCode) + "' Message: '" + m_ErrorMessage + "'.");
SendResponse(stream, m_ErrorCode, m_ErrorMessage);
}
-void Query::SendResponse(const Stream::Ptr& stream, int code, const String& data)
+void LivestatusQuery::SendResponse(const Stream::Ptr& stream, int code, const String& data)
{
if (m_ResponseHeader == "fixed16")
PrintFixed16(stream, code, data);
std::ostringstream info;
info << "Exception thrown while writing to the livestatus socket: " << std::endl
<< DiagnosticInformation(ex);
- Log(LogCritical, "LivestatusListener/Query", info.str());
+ Log(LogCritical, "LivestatusQuery", info.str());
}
}
}
-void Query::PrintFixed16(const Stream::Ptr& stream, int code, const String& data)
+void LivestatusQuery::PrintFixed16(const Stream::Ptr& stream, int code, const String& data)
{
ASSERT(code >= 100 && code <= 999);
std::ostringstream info;
info << "Exception thrown while writing to the livestatus socket: " << std::endl
<< DiagnosticInformation(ex);
- Log(LogCritical, "LivestatusListener/Query", info.str());
+ Log(LogCritical, "LivestatusQuery", info.str());
}
}
-bool Query::Execute(const Stream::Ptr& stream)
+bool LivestatusQuery::Execute(const Stream::Ptr& stream)
{
try {
- Log(LogInformation, "LivestatusListener/Query", "Executing livestatus query: " + m_Verb);
+ Log(LogInformation, "LivestatusQuery", "Executing livestatus query: " + m_Verb);
if (m_Verb == "GET")
ExecuteGetHelper(stream);
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#ifndef QUERY_H
-#define QUERY_H
+#ifndef LIVESTATUSQUERY_H
+#define LIVESTATUSQUERY_H
#include "livestatus/filter.hpp"
#include "livestatus/aggregator.hpp"
/**
* @ingroup livestatus
*/
-class Query : public Object
+class LivestatusQuery : public Object
{
public:
- DECLARE_PTR_TYPEDEFS(Query);
+ DECLARE_PTR_TYPEDEFS(LivestatusQuery);
- Query(const std::vector<String>& lines, const String& compat_log_path);
+ LivestatusQuery(const std::vector<String>& lines, const String& compat_log_path);
bool Execute(const Stream::Ptr& stream);
}
-#endif /* QUERY_H */
+#endif /* LIVESTATUSQUERY_H */
******************************************************************************/
#include "livestatus/logtable.hpp"
-#include "livestatus/logutility.hpp"
+#include "livestatus/livestatuslogutility.hpp"
#include "livestatus/hoststable.hpp"
#include "livestatus/servicestable.hpp"
#include "livestatus/contactstable.hpp"
void LogTable::FetchRows(const AddRowFunction& addRowFn)
{
- Log(LogNotice, "LivestatusListener/LogTable", "Pre-selecting log file from " + Convert::ToString(m_TimeFrom) + " until " + Convert::ToString(m_TimeUntil));
+ Log(LogDebug, "LogTable", "Pre-selecting log file from " + Convert::ToString(m_TimeFrom) + " until " + Convert::ToString(m_TimeUntil));
/* create log file index */
- LogUtility::CreateLogIndex(m_CompatLogPath, m_LogFileIndex);
+ LivestatusLogUtility::CreateLogIndex(m_CompatLogPath, m_LogFileIndex);
/* generate log cache */
- LogUtility::CreateLogCache(m_LogFileIndex, this, m_TimeFrom, m_TimeUntil, addRowFn);
+ LivestatusLogUtility::CreateLogCache(m_LogFileIndex, this, m_TimeFrom, m_TimeUntil, addRowFn);
}
-/* gets called in LogUtility::CreateLogCache */
+/* gets called in LivestatusLogUtility::CreateLogCache */
void LogTable::UpdateLogEntries(const Dictionary::Ptr& log_entry_attrs, int line_count, int lineno, const AddRowFunction& addRowFn)
{
/* additional attributes only for log table */
******************************************************************************/
#include "livestatus/statehisttable.hpp"
-#include "livestatus/logutility.hpp"
+#include "livestatus/livestatuslogutility.hpp"
#include "livestatus/hoststable.hpp"
#include "livestatus/servicestable.hpp"
#include "livestatus/contactstable.hpp"
state_hist_service_states->Add(state_hist_bag);
- Log(LogDebug, "LivestatusListener/StateHistTable", "statehist: Adding new object '" + checkable->GetName() + "' to services cache.");
+ Log(LogDebug, "StateHistTable", "statehist: Adding new object '" + checkable->GetName() + "' to services cache.");
} else {
state_hist_service_states = m_CheckablesCache[checkable];
state_hist_bag = state_hist_service_states->Get(state_hist_service_states->GetLength()-1); /* fetch latest state from history */
state_hist_service_states->Add(state_hist_bag_new);
- Log(LogDebug, "LivestatusListener/StateHistTable", "statehist: State change detected for object '" +
+ Log(LogDebug, "StateHistTable", "statehist: State change detected for object '" +
checkable->GetName() + "' in '" + log_line + "'.");
}
break;
void StateHistTable::FetchRows(const AddRowFunction& addRowFn)
{
- Log(LogNotice, "LivestatusListener/StateHistTable", "Pre-selecting log file from " + Convert::ToString(m_TimeFrom) + " until " + Convert::ToString(m_TimeUntil));
+ Log(LogDebug, "StateHistTable", "Pre-selecting log file from " + Convert::ToString(m_TimeFrom) + " until " + Convert::ToString(m_TimeUntil));
/* create log file index */
- LogUtility::CreateLogIndex(m_CompatLogPath, m_LogFileIndex);
+ LivestatusLogUtility::CreateLogIndex(m_CompatLogPath, m_LogFileIndex);
/* generate log cache */
- LogUtility::CreateLogCache(m_LogFileIndex, this, m_TimeFrom, m_TimeUntil, addRowFn);
+ LivestatusLogUtility::CreateLogCache(m_LogFileIndex, this, m_TimeFrom, m_TimeUntil, addRowFn);
Checkable::Ptr checkable;
******************************************************************************/
#include "livestatus/statustable.hpp"
-#include "livestatus/listener.hpp"
+#include "livestatus/livestatuslistener.hpp"
#include "icinga/icingaapplication.hpp"
#include "icinga/cib.hpp"
#include "icinga/host.hpp"
Value StatusTable::ExternalCommandsAccessor(const Value&)
{
- return Query::GetExternalCommands();
+ return LivestatusQuery::GetExternalCommands();
}
Value StatusTable::ExternalCommandsRateAccessor(const Value&)
{
- return (Query::GetExternalCommands() / (Utility::GetTime() - Application::GetStartTime()));
+ return (LivestatusQuery::GetExternalCommands() / (Utility::GetTime() - Application::GetStartTime()));
}
Value StatusTable::NagiosPidAccessor(const Value&)