]> granicus.if.org Git - icinga2/commitdiff
Livestatus: Fix "class" filter for log table
authorMichael Friedrich <michael.friedrich@netways.de>
Thu, 26 Nov 2015 18:15:54 +0000 (19:15 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Thu, 26 Nov 2015 18:18:05 +0000 (19:18 +0100)
fixes #10449

lib/livestatus/livestatuslogutility.cpp
test/livestatus/queries/log/class [new file with mode: 0644]
test/livestatus/run_queries

index f41a4404c8f3d0c81e241e157a3fc1742a3b9147..2459608bcc9be866c3ab139bba8015654538db80 100644 (file)
@@ -146,8 +146,8 @@ Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text)
        boost::algorithm::split(tokens, options, boost::is_any_of(";"));
 
        /* set default values */
-       bag->Set("log_class", LogEntryClassInfo);
-       bag->Set("log_type", 0);
+       bag->Set("class", LogEntryClassInfo);
+       bag->Set("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 */
@@ -165,16 +165,16 @@ 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("log_type", LogEntryTypeHostInitialState);
+                       bag->Set("class", LogEntryClassState);
+                       bag->Set("type", LogEntryTypeHostInitialState);
                }
                else if (type.Contains("CURRENT HOST STATE")) {
-                       bag->Set("log_class", LogEntryClassState);
-                       bag->Set("log_type", LogEntryTypeHostCurrentState);
+                       bag->Set("class", LogEntryClassState);
+                       bag->Set("type", LogEntryTypeHostCurrentState);
                }
                else {
-                       bag->Set("log_class", LogEntryClassAlert);
-                       bag->Set("log_type", LogEntryTypeHostAlert);
+                       bag->Set("class", LogEntryClassAlert);
+                       bag->Set("type", LogEntryTypeHostAlert);
                }
 
                return bag;
@@ -188,11 +188,11 @@ 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("log_type", LogEntryTypeHostFlapping);
+                       bag->Set("class", LogEntryClassAlert);
+                       bag->Set("type", LogEntryTypeHostFlapping);
                } else {
-                       bag->Set("log_class", LogEntryClassAlert);
-                       bag->Set("log_type", LogEntryTypeHostDowntimeAlert);
+                       bag->Set("class", LogEntryClassAlert);
+                       bag->Set("type", LogEntryTypeHostDowntimeAlert);
                }
 
                return bag;
@@ -210,16 +210,16 @@ 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("log_type", LogEntryTypeServiceInitialState);
+                       bag->Set("class", LogEntryClassState);
+                       bag->Set("type", LogEntryTypeServiceInitialState);
                }
                else if (type.Contains("CURRENT SERVICE STATE")) {
-                       bag->Set("log_class", LogEntryClassState);
-                       bag->Set("log_type", LogEntryTypeServiceCurrentState);
+                       bag->Set("class", LogEntryClassState);
+                       bag->Set("type", LogEntryTypeServiceCurrentState);
                }
                else {
-                       bag->Set("log_class", LogEntryClassAlert);
-                       bag->Set("log_type", LogEntryTypeServiceAlert);
+                       bag->Set("class", LogEntryClassAlert);
+                       bag->Set("type", LogEntryTypeServiceAlert);
                }
 
                return bag;
@@ -234,11 +234,11 @@ 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("log_type", LogEntryTypeServiceFlapping);
+                       bag->Set("class", LogEntryClassAlert);
+                       bag->Set("type", LogEntryTypeServiceFlapping);
                } else {
-                       bag->Set("log_class", LogEntryClassAlert);
-                       bag->Set("log_type", LogEntryTypeServiceDowntimeAlert);
+                       bag->Set("class", LogEntryClassAlert);
+                       bag->Set("type", LogEntryTypeServiceDowntimeAlert);
                }
 
                return bag;
@@ -246,8 +246,8 @@ Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text)
                if (tokens.size() < 4)
                        return bag;
 
-               bag->Set("log_class", LogEntryClassState);
-               bag->Set("log_type", LogEntryTypeTimeperiodTransition);
+               bag->Set("class", LogEntryClassState);
+               bag->Set("type", LogEntryTypeTimeperiodTransition);
 
                bag->Set("host_name", tokens[0]);
                bag->Set("service_description", tokens[1]);
@@ -264,8 +264,8 @@ 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("log_type", LogEntryTypeHostNotification);
+               bag->Set("class", LogEntryClassNotification);
+               bag->Set("type", LogEntryTypeHostNotification);
 
                return bag;
        } else if (type.Contains("SERVICE NOTIFICATION")) {
@@ -280,8 +280,8 @@ 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("log_type", LogEntryTypeServiceNotification);
+               bag->Set("class", LogEntryClassNotification);
+               bag->Set("type", LogEntryTypeServiceNotification);
 
                return bag;
        } else if (type.Contains("PASSIVE HOST CHECK")) {
@@ -292,7 +292,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")) {
@@ -304,27 +304,27 @@ 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("log_type", LogEntryTypeVersion);
+               bag->Set("class", LogEntryClassProgram);
+               bag->Set("type", LogEntryTypeVersion);
 
                return bag;
        } else if (type.Contains("logging initial states")) {
-               bag->Set("log_class", LogEntryClassProgram);
-               bag->Set("log_type", LogEntryTypeInitialStates);
+               bag->Set("class", LogEntryClassProgram);
+               bag->Set("type", LogEntryTypeInitialStates);
 
                return bag;
        } else if (type.Contains("starting... (PID=")) {
-               bag->Set("log_class", LogEntryClassProgram);
-               bag->Set("log_type", LogEntryTypeProgramStarting);
+               bag->Set("class", LogEntryClassProgram);
+               bag->Set("type", LogEntryTypeProgramStarting);
 
                return bag;
        }
@@ -334,7 +334,7 @@ Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text)
                 type.Contains("Bailing out") ||
                 type.Contains("active mode...") ||
                 type.Contains("standby mode...")) {
-               bag->Set("log_class", LogEntryClassProgram);
+               bag->Set("class", LogEntryClassProgram);
 
                return bag;
        }
diff --git a/test/livestatus/queries/log/class b/test/livestatus/queries/log/class
new file mode 100644 (file)
index 0000000..c534980
--- /dev/null
@@ -0,0 +1,5 @@
+GET log
+Filter: time >= 1348657741
+Filter: class = 1
+ResponseHeader: fixed16
+
index 11fc274323a8ddd131409083188d9cf4e4e3deb7..c80aa593fcc30f26887b613f6b2947a5aac9b62d 100755 (executable)
@@ -9,6 +9,8 @@ LIVESTATUSQUERIES="./queries"
 
 LIVESTATUSTABLE=$1
 
+echo -e "Querying Livestatus socket: $LIVESTATUSSOCKET"
+
 if [ -n "$LIVESTATUSTABLE" ]; then
        cat "$LIVESTATUSTABLE"
        (cat "$LIVESTATUSTABLE"; sleep 1) | $NC -U $LIVESTATUSSOCKET