]> granicus.if.org Git - icinga2/blobdiff - lib/livestatus/livestatuslogutility.cpp
Merge pull request #6509 from gunnarbeutner/feature/real-constants
[icinga2] / lib / livestatus / livestatuslogutility.cpp
index de70a2be7d3fa2f73a29f84c7f37061b540de1bc..91db16253374029a6cd4a44a98325545ad126deb 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * Icinga 2                                                                   *
- * Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org)    *
+ * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)  *
  *                                                                            *
  * This program is free software; you can redistribute it and/or              *
  * modify it under the terms of the GNU General Public License                *
 #include "base/utility.hpp"
 #include "base/convert.hpp"
 #include "base/logger.hpp"
-#include <boost/foreach.hpp>
 #include <boost/tuple/tuple.hpp>
 #include <boost/algorithm/string.hpp>
-#include <boost/algorithm/string/split.hpp>
-#include <boost/algorithm/string/classification.hpp>
 #include <boost/algorithm/string/replace.hpp>
 #include <boost/algorithm/string/predicate.hpp>
 #include <fstream>
@@ -40,8 +37,8 @@ using namespace icinga;
 
 void LivestatusLogUtility::CreateLogIndex(const String& path, std::map<time_t, String>& index)
 {
-       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);
+       Utility::Glob(path + "/icinga.log", std::bind(&LivestatusLogUtility::CreateLogIndexFileHandler, _1, std::ref(index)), GlobFile);
+       Utility::Glob(path + "/archives/*.log", std::bind(&LivestatusLogUtility::CreateLogIndexFileHandler, _1, std::ref(index)), GlobFile);
 }
 
 void LivestatusLogUtility::CreateLogIndexFileHandler(const String& path, std::map<time_t, String>& index)
@@ -69,20 +66,21 @@ void LivestatusLogUtility::CreateLogIndexFileHandler(const String& path, std::ma
        stream.close();
 
        Log(LogDebug, "LivestatusLogUtility")
-           << "Indexing log file: '" << path << "' with timestamp start: '" << ts_start << "'.";
+               << "Indexing log file: '" << path << "' with timestamp start: '" << ts_start << "'.";
 
        index[ts_start] = path;
 }
 
 void LivestatusLogUtility::CreateLogCache(std::map<time_t, String> index, HistoryTable *table,
-    time_t from, time_t until, const AddRowFunction& addRowFn)
+       time_t from, time_t until, const AddRowFunction& addRowFn)
 {
        ASSERT(table);
 
        /* m_LogFileIndex map tells which log files are involved ordered by their start timestamp */
-       unsigned int ts;
        unsigned long line_count = 0;
-       BOOST_FOREACH(boost::tie(ts, boost::tuples::ignore), index) {
+       for (const auto& kv : index) {
+               unsigned int ts = kv.first;
+
                /* skip log files not in range (performance optimization) */
                if (ts < from || ts > until)
                        continue;
@@ -106,7 +104,7 @@ void LivestatusLogUtility::CreateLogCache(std::map<time_t, String> index, Histor
                        /* no attributes available - invalid log line */
                        if (!log_entry_attrs) {
                                Log(LogDebug, "LivestatusLogUtility")
-                                   << "Skipping invalid log line: '" << line << "'.";
+                                       << "Skipping invalid log line: '" << line << "'.";
                                continue;
                        }
 
@@ -130,34 +128,30 @@ Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text)
        unsigned long time = atoi(text.SubStr(1, 11).CStr());
 
        Log(LogDebug, "LivestatusLogUtility")
-           << "Processing log line: '" << text << "'.";
+               << "Processing log line: '" << text << "'.";
        bag->Set("time", time);
 
        size_t colon = text.FindFirstOf(':');
        size_t colon_offset = colon - 13;
 
-       String type = String(text.SubStr(13, colon_offset));
-       String options = String(text.SubStr(colon + 1));
-
-       type.Trim();
-       options.Trim();
+       String type = String(text.SubStr(13, colon_offset)).Trim();
+       String options = String(text.SubStr(colon + 1)).Trim();
 
        bag->Set("type", type);
        bag->Set("options", options);
 
-       std::vector<String> tokens;
-       boost::algorithm::split(tokens, options, boost::is_any_of(";"));
+       std::vector<String> tokens = options.Split(";");
 
        /* set default values */
-       bag->Set("log_class", LogEntryClassInfo);
+       bag->Set("class", LogEntryClassInfo);
        bag->Set("log_type", 0);
        bag->Set("state", 0);
        bag->Set("attempt", 0);
        bag->Set("message", text); /* used as 'message' in log table, and 'log_output' in statehist table */
 
        if (type.Contains("INITIAL HOST STATE") ||
-           type.Contains("CURRENT HOST STATE") ||
-           type.Contains("HOST ALERT")) {
+               type.Contains("CURRENT HOST STATE") ||
+               type.Contains("HOST ALERT")) {
                if (tokens.size() < 5)
                        return bag;
 
@@ -168,21 +162,20 @@ Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text)
                bag->Set("plugin_output", tokens[4]);
 
                if (type.Contains("INITIAL HOST STATE")) {
-                       bag->Set("log_class", LogEntryClassState);
+                       bag->Set("class", LogEntryClassState);
                        bag->Set("log_type", LogEntryTypeHostInitialState);
                }
                else if (type.Contains("CURRENT HOST STATE")) {
-                       bag->Set("log_class", LogEntryClassState);
+                       bag->Set("class", LogEntryClassState);
                        bag->Set("log_type", LogEntryTypeHostCurrentState);
                }
                else {
-                       bag->Set("log_class", LogEntryClassAlert);
+                       bag->Set("class", LogEntryClassAlert);
                        bag->Set("log_type", LogEntryTypeHostAlert);
                }
 
                return bag;
-       } else if (type.Contains("HOST DOWNTIME ALERT") ||
-                type.Contains("HOST FLAPPING ALERT")) {
+       } else if (type.Contains("HOST DOWNTIME ALERT") ||  type.Contains("HOST FLAPPING ALERT")) {
                if (tokens.size() < 3)
                        return bag;
 
@@ -191,17 +184,17 @@ Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text)
                bag->Set("comment", tokens[2]);
 
                if (type.Contains("HOST FLAPPING ALERT")) {
-                       bag->Set("log_class", LogEntryClassAlert);
+                       bag->Set("class", LogEntryClassAlert);
                        bag->Set("log_type", LogEntryTypeHostFlapping);
                } else {
-                       bag->Set("log_class", LogEntryClassAlert);
+                       bag->Set("class", LogEntryClassAlert);
                        bag->Set("log_type", LogEntryTypeHostDowntimeAlert);
                }
 
                return bag;
        } else if (type.Contains("INITIAL SERVICE STATE") ||
-                type.Contains("CURRENT SERVICE STATE") ||
-                type.Contains("SERVICE ALERT")) {
+               type.Contains("CURRENT SERVICE STATE") ||
+               type.Contains("SERVICE ALERT")) {
                if (tokens.size() < 6)
                        return bag;
 
@@ -213,21 +206,21 @@ Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text)
                bag->Set("plugin_output", tokens[5]);
 
                if (type.Contains("INITIAL SERVICE STATE")) {
-                       bag->Set("log_class", LogEntryClassState);
+                       bag->Set("class", LogEntryClassState);
                        bag->Set("log_type", LogEntryTypeServiceInitialState);
                }
                else if (type.Contains("CURRENT SERVICE STATE")) {
-                       bag->Set("log_class", LogEntryClassState);
+                       bag->Set("class", LogEntryClassState);
                        bag->Set("log_type", LogEntryTypeServiceCurrentState);
                }
                else {
-                       bag->Set("log_class", LogEntryClassAlert);
+                       bag->Set("class", LogEntryClassAlert);
                        bag->Set("log_type", LogEntryTypeServiceAlert);
                }
 
                return bag;
        } else if (type.Contains("SERVICE DOWNTIME ALERT") ||
-                type.Contains("SERVICE FLAPPING ALERT")) {
+               type.Contains("SERVICE FLAPPING ALERT")) {
                if (tokens.size() < 4)
                        return bag;
 
@@ -237,10 +230,10 @@ Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text)
                bag->Set("comment", tokens[3]);
 
                if (type.Contains("SERVICE FLAPPING ALERT")) {
-                       bag->Set("log_class", LogEntryClassAlert);
+                       bag->Set("class", LogEntryClassAlert);
                        bag->Set("log_type", LogEntryTypeServiceFlapping);
                } else {
-                       bag->Set("log_class", LogEntryClassAlert);
+                       bag->Set("class", LogEntryClassAlert);
                        bag->Set("log_type", LogEntryTypeServiceDowntimeAlert);
                }
 
@@ -249,7 +242,7 @@ Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text)
                if (tokens.size() < 4)
                        return bag;
 
-               bag->Set("log_class", LogEntryClassState);
+               bag->Set("class", LogEntryClassState);
                bag->Set("log_type", LogEntryTypeTimeperiodTransition);
 
                bag->Set("host_name", tokens[0]);
@@ -267,7 +260,7 @@ Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text)
                bag->Set("command_name", tokens[4]);
                bag->Set("plugin_output", tokens[5]);
 
-               bag->Set("log_class", LogEntryClassNotification);
+               bag->Set("class", LogEntryClassNotification);
                bag->Set("log_type", LogEntryTypeHostNotification);
 
                return bag;
@@ -283,7 +276,7 @@ Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text)
                bag->Set("command_name", tokens[5]);
                bag->Set("plugin_output", tokens[6]);
 
-               bag->Set("log_class", LogEntryClassNotification);
+               bag->Set("class", LogEntryClassNotification);
                bag->Set("log_type", LogEntryTypeServiceNotification);
 
                return bag;
@@ -295,7 +288,7 @@ Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text)
                bag->Set("state", Host::StateFromString(tokens[1]));
                bag->Set("plugin_output", tokens[2]);
 
-               bag->Set("log_class", LogEntryClassPassive);
+               bag->Set("class", LogEntryClassPassive);
 
                return bag;
        } else if (type.Contains("PASSIVE SERVICE CHECK")) {
@@ -307,37 +300,37 @@ Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text)
                bag->Set("state", Host::StateFromString(tokens[2]));
                bag->Set("plugin_output", tokens[3]);
 
-               bag->Set("log_class", LogEntryClassPassive);
+               bag->Set("class", LogEntryClassPassive);
 
                return bag;
        } else if (type.Contains("EXTERNAL COMMAND")) {
-               bag->Set("log_class", LogEntryClassCommand);
+               bag->Set("class", LogEntryClassCommand);
                /* string processing not implemented in 1.x */
 
                return bag;
        } else if (type.Contains("LOG VERSION")) {
-               bag->Set("log_class", LogEntryClassProgram);
+               bag->Set("class", LogEntryClassProgram);
                bag->Set("log_type", LogEntryTypeVersion);
 
                return bag;
        } else if (type.Contains("logging initial states")) {
-               bag->Set("log_class", LogEntryClassProgram);
+               bag->Set("class", LogEntryClassProgram);
                bag->Set("log_type", LogEntryTypeInitialStates);
 
                return bag;
        } else if (type.Contains("starting... (PID=")) {
-               bag->Set("log_class", LogEntryClassProgram);
+               bag->Set("class", LogEntryClassProgram);
                bag->Set("log_type", LogEntryTypeProgramStarting);
 
                return bag;
        }
        /* program */
        else if (type.Contains("restarting...") ||
-                type.Contains("shutting down...") ||
-                type.Contains("Bailing out") ||
-                type.Contains("active mode...") ||
-                type.Contains("standby mode...")) {
-               bag->Set("log_class", LogEntryClassProgram);
+               type.Contains("shutting down...") ||
+               type.Contains("Bailing out") ||
+               type.Contains("active mode...") ||
+               type.Contains("standby mode...")) {
+               bag->Set("class", LogEntryClassProgram);
 
                return bag;
        }