Added threshold sensor messages

Added correct messages for the threshold sensor.
Test: Started the system, disconnected the fan, plugged it back in
Behavior before:
Information message xyz.openbmc_project.Logging.SEL.Error.Created when
disconnected and the same when plugged back in
Behavior now:
Warning or error with text:
`<sensor_name> sensor crossed a <critical, warning> low threshold going low. Reading=<value_r> Threshold=<value_t>.`
And an information message with the text:
`<sensor_name> sensor crossed a <critical, warning> low threshold going high. Reading=<value_r> Threshold=<value_t>.`

Change-Id: I7426e126f738ff14e57368b99bd910872593d139
Signed-off-by: Glukhov Mikhail <mikl@greenfil.ru>
diff --git a/include/threshold_event_monitor.hpp b/include/threshold_event_monitor.hpp
index a8cf83c..ba2a20b 100644
--- a/include/threshold_event_monitor.hpp
+++ b/include/threshold_event_monitor.hpp
@@ -204,16 +204,26 @@
         std::string direction;
         std::string redfishMessageID =
             "OpenBMC." + openBMCMessageRegistryVersion;
+        enum EventType
+        {
+            eventNone,
+            eventInfo,
+            eventWarn,
+            eventErr
+        };
+        EventType eventType = eventNone;
         if (event == "CriticalLow")
         {
             threshold = "critical low";
             if (assert)
             {
+                eventType = eventErr;
                 direction = "low";
                 redfishMessageID += ".SensorThresholdCriticalLowGoingLow";
             }
             else
             {
+                eventType = eventInfo;
                 direction = "high";
                 redfishMessageID += ".SensorThresholdCriticalLowGoingHigh";
             }
@@ -223,11 +233,13 @@
             threshold = "warning low";
             if (assert)
             {
+                eventType = eventWarn;
                 direction = "low";
                 redfishMessageID += ".SensorThresholdWarningLowGoingLow";
             }
             else
             {
+                eventType = eventInfo;
                 direction = "high";
                 redfishMessageID += ".SensorThresholdWarningLowGoingHigh";
             }
@@ -237,11 +249,13 @@
             threshold = "warning high";
             if (assert)
             {
+                eventType = eventWarn;
                 direction = "high";
                 redfishMessageID += ".SensorThresholdWarningHighGoingHigh";
             }
             else
             {
+                eventType = eventInfo;
                 direction = "low";
                 redfishMessageID += ".SensorThresholdWarningHighGoingLow";
             }
@@ -251,11 +265,13 @@
             threshold = "critical high";
             if (assert)
             {
+                eventType = eventErr;
                 direction = "high";
                 redfishMessageID += ".SensorThresholdCriticalHighGoingHigh";
             }
             else
             {
+                eventType = eventInfo;
                 direction = "low";
                 redfishMessageID += ".SensorThresholdCriticalHighGoingLow";
             }
@@ -267,11 +283,53 @@
                                " Threshold=" + std::to_string(thresholdVal) +
                                ".");
 
+#ifdef SEL_LOGGER_SEND_TO_LOGGING_SERVICE
+        std::string LogLevel = "";
+        switch (eventType)
+        {
+            case eventInfo:
+            {
+                LogLevel =
+                    "xyz.openbmc_project.Logging.Entry.Level.Informational";
+                break;
+            }
+            case eventWarn:
+            {
+                LogLevel = "xyz.openbmc_project.Logging.Entry.Level.Warning";
+                break;
+            }
+            case eventErr:
+            {
+                LogLevel = "xyz.openbmc_project.Logging.Entry.Level.Critical";
+                break;
+            }
+            default:
+            {
+                LogLevel = "xyz.openbmc_project.Logging.Entry.Level.Debug";
+                break;
+            }
+        }
+        if (eventType != eventNone)
+        {
+            sdbusplus::message::message AddToLog = conn->new_method_call(
+                "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
+                "xyz.openbmc_project.Logging.Create", "Create");
+            AddToLog.append(journalMsg, LogLevel,
+                            std::map<std::string, std::string>(
+                                {{"SENSOR_PATH", std::string(msg.get_path())},
+                                 {"EVENT", threshold},
+                                 {"DIRECTION", direction},
+                                 {"THRESHOLD", std::to_string(thresholdVal)},
+                                 {"READING", std::to_string(assertValue)}}));
+            conn->call(AddToLog);
+        }
+#else
         selAddSystemRecord(
             journalMsg, std::string(msg.get_path()), eventData, assert,
             selBMCGenID, "REDFISH_MESSAGE_ID=%s", redfishMessageID.c_str(),
             "REDFISH_MESSAGE_ARGS=%.*s,%f,%f", sensorName.length(),
             sensorName.data(), assertValue, thresholdVal);
+#endif
     };
     sdbusplus::bus::match_t thresholdAssertMatcher(
         static_cast<sdbusplus::bus_t&>(*conn),