From 90cf04f0881e0075a05208b2007ec92c41a25921 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 6 Nov 2013 18:43:03 +0100 Subject: [PATCH] Additional fixes for log table including test queries. Refs #4433 --- components/livestatus/logtable.cpp | 8 ++++-- .../queries/custom/thruk_alert_history | 19 ++++++++++++++ test/livestatus/queries/custom/thruk_comments | 7 +++++ test/livestatus/queries/log/avail | 12 +++++++++ test/livestatus/queries/log/avail_svc | 13 ++++++++++ test/livestatus/queries/log/trend | 26 +++++++++++++++++++ 6 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 test/livestatus/queries/custom/thruk_alert_history create mode 100644 test/livestatus/queries/custom/thruk_comments create mode 100644 test/livestatus/queries/log/avail create mode 100644 test/livestatus/queries/log/avail_svc create mode 100644 test/livestatus/queries/log/trend diff --git a/components/livestatus/logtable.cpp b/components/livestatus/logtable.cpp index 8af7f13df..c5f9a67bb 100644 --- a/components/livestatus/logtable.cpp +++ b/components/livestatus/logtable.cpp @@ -55,7 +55,7 @@ LogTable::LogTable(const unsigned long& from, const unsigned long& until) /* store from & until for FetchRows */ m_TimeFrom = from; m_TimeUntil = until; - + /* create log file index - TODO config option */ CreateLogIndex(Application::GetLocalStateDir() + "/log/icinga2/compat"); @@ -97,6 +97,9 @@ LogTable::LogTable(const unsigned long& from, const unsigned long& until) Dictionary::Ptr bag = GetLogEntryAttributes(type, options); + if (!bag) + continue; + bag->Set("time", time); bag->Set("lineno", lineno); bag->Set("message", String(line)); /* complete line */ @@ -549,7 +552,8 @@ Dictionary::Ptr LogTable::GetLogEntryAttributes(const String& type, const String boost::algorithm::contains(type, "active mode...") || boost::algorithm::contains(type, "standby mode...")) { log_class = LogClassProgram; - } + } else + return Dictionary::Ptr(); Dictionary::Ptr bag = boost::make_shared(); diff --git a/test/livestatus/queries/custom/thruk_alert_history b/test/livestatus/queries/custom/thruk_alert_history new file mode 100644 index 000000000..de04c46d9 --- /dev/null +++ b/test/livestatus/queries/custom/thruk_alert_history @@ -0,0 +1,19 @@ +GET log +Columns: class time type state host_name service_description plugin_output message options state_type contact_name +Filter: time >= 1383692400 +Filter: time <= 1383778800 +Filter: type = SERVICE ALERT +And: 1 +Filter: type = HOST ALERT +And: 1 +Filter: type = SERVICE FLAPPING ALERT +Filter: type = HOST FLAPPING ALERT +Filter: type = SERVICE DOWNTIME ALERT +Filter: type = HOST DOWNTIME ALERT +Filter: message ~ starting\.\.\. +Filter: message ~ shutting\ down\.\.\. +Or: 8 +And: 3 +OutputFormat: json +ResponseHeader: fixed16 + diff --git a/test/livestatus/queries/custom/thruk_comments b/test/livestatus/queries/custom/thruk_comments new file mode 100644 index 000000000..fc454ab65 --- /dev/null +++ b/test/livestatus/queries/custom/thruk_comments @@ -0,0 +1,7 @@ +GET comments +Columns: author comment entry_time entry_type expires expire_time host_name id persistent service_description source type +Filter: host_name = localhost +Filter: service_description = processes +OutputFormat: json +ResponseHeader: fixed16 + diff --git a/test/livestatus/queries/log/avail b/test/livestatus/queries/log/avail new file mode 100644 index 000000000..b37162c65 --- /dev/null +++ b/test/livestatus/queries/log/avail @@ -0,0 +1,12 @@ +GET log +Columns: time type message class +Filter: type = HOST ALERT +Filter: state_type = HARD +Filter: type = INITIAL HOST STATE +Filter: state_type = HARD +Filter: type = CURRENT HOST STATE +Filter: state_type = HARD +Filter: type = HOST DOWNTIME ALERT +Or: 7 +ResponseHeader: fixed16 + diff --git a/test/livestatus/queries/log/avail_svc b/test/livestatus/queries/log/avail_svc new file mode 100644 index 000000000..9e3712ba9 --- /dev/null +++ b/test/livestatus/queries/log/avail_svc @@ -0,0 +1,13 @@ +GET log +Columns: time type message class +Filter: type = HOST DOWNTIME ALERT +Filter: type = SERVICE ALERT +Filter: state_type = HARD +Filter: type = INITIAL SERVICE STATE +Filter: state_type = HARD +Filter: type = CURRENT SERVICE STATE +Filter: state_type = HARD +Filter: type = SERVICE DOWNTIME ALERT +Or: 8 +ResponseHeader: fixed16 + diff --git a/test/livestatus/queries/log/trend b/test/livestatus/queries/log/trend new file mode 100644 index 000000000..bd44d89bf --- /dev/null +++ b/test/livestatus/queries/log/trend @@ -0,0 +1,26 @@ +GET log +Columns: time type message +Filter: host_name = localhost +Filter: type = HOST ALERT +Filter: state_type = HARD +Filter: type = INITIAL HOST STATE +Filter: state_type = HARD +Filter: type = CURRENT HOST STATE +Filter: state_type = HARD +Filter: type = HOST DOWNTIME ALERT +Or: 7 +And: 2 +Filter: host_name = localhost +Filter: type = SERVICE ALERT +Filter: state_type = HARD +Filter: type = INITIAL SERVICE STATE +Filter: state_type = HARD +Filter: type = CURRENT SERVICE STATE +Filter: state_type = HARD +Filter: type = SERVICE DOWNTIME ALERT +Or: 7 +And: 2 +Filter: class = 2 +Or: 3 +ResponseHeader: fixed16 +