sensor-monitor: support skip power checking

The threshold event is binding with power state currently.
Due to some sensors access will not depend on the power state.
Provide a new option to let user to disable it.

Change-Id: Ib232b889cde70082e3bd630ffbe6939eede474f8
Signed-off-by: Jerry C Chen <jerry.c.chen.wiwynn@gmail.com>
diff --git a/README.md b/README.md
index ff438c1..2648321 100644
--- a/README.md
+++ b/README.md
@@ -222,6 +222,8 @@
     - Default = 900000
   - `use-host-power-state` - Use the host state for the power state as opposed
     to the PGOOD state.
+  - `skip-power-checking` - Skip power state checking while sending threshold
+    alarm event.
 
 [README](docs/sensor-monitor/README.md)
 
diff --git a/meson.build b/meson.build
index c17fcdb..731d85f 100644
--- a/meson.build
+++ b/meson.build
@@ -136,6 +136,10 @@
     conf.set('ENABLE_HOST_STATE', '')
 endif
 
+if get_option('skip-power-checking').allowed()
+    conf.set('SKIP_POWER_CHECKING', '')
+endif
+
 conf.set(
     'SHUTDOWN_ALARM_HARD_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-hard-shutdown-delay'))
 conf.set(
diff --git a/meson.options b/meson.options
index 3344cbd..21e3362 100644
--- a/meson.options
+++ b/meson.options
@@ -128,3 +128,9 @@
     'use-host-power-state', type: 'feature', value: 'disabled',
     description: 'Enable using the host power state for power state checks.'
 )
+
+option(
+    'skip-power-checking', type: 'feature', value: 'disabled',
+    description: 'Skip power state checking while sending threshold alarm event.'
+)
+
diff --git a/sensor-monitor/threshold_alarm_logger.cpp b/sensor-monitor/threshold_alarm_logger.cpp
index 6d78c0a..6b20e77 100644
--- a/sensor-monitor/threshold_alarm_logger.cpp
+++ b/sensor-monitor/threshold_alarm_logger.cpp
@@ -13,6 +13,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "config.h"
+
 #include "threshold_alarm_logger.hpp"
 
 #include "sdbusplus.hpp"
@@ -218,8 +220,9 @@
             if (alarmValue != alarms[key][propertyName])
             {
                 alarms[key][propertyName] = alarmValue;
-
+#ifndef SKIP_POWER_CHECKING
                 if (_powerState->isPowerOn())
+#endif
                 {
                     createEventLog(sensorPath, interface, propertyName,
                                    alarmValue);
@@ -249,7 +252,11 @@
 
             // This is just for checking alarms on startup,
             // so only look for active alarms.
+#ifdef SKIP_POWER_CHECKING
+            if (alarmValue)
+#else
             if (alarmValue && _powerState->isPowerOn())
+#endif
             {
                 createEventLog(sensorPath, interface, property, alarmValue);
             }