Add Status information for Fan

This commit is to add Fan State/Health status according to the
Redfish Fan schema.

If the `xyz.openbmc_project.Inventory.Item`
interface does not exist, the state status property is set to
default "Present".

If the `xyz.openbmc_project.State.Decorator.OperationalStatus`
interface does not exist, the health status property is set to
default "OK".

ref: https://redfish.dmtf.org/schemas/v1/Fan.v1_3_0.json

Code that updates the OperationalStatus for all the inventory
https://github.com/openbmc/openpower-vpd-parser/blob/3fb026386546cfd288ab4f86156c9aa0ffa145d6/ibm_vpd_app.cpp#L620

Tested: Validator passes
'''
1.doGet method to get Fan
curl -k https://${bmc}/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan0
{
  "@odata.id": "/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan0",
  "@odata.type": "#Fan.v1_3_0.Fan",
  "Id": "fan0",
  "Name": "Fan",
  "Status": {
    "Health": "OK",
    "State": "Enabled"
  }
}

2.Enter the wrong fanId with the doGet method to get fan
{
  "error": {
    "@Message.ExtendedInfo": [
      {
        "@odata.type": "#Message.v1_1_1.Message",
        "Message": "The requested resource of type Fan named 'fanx' was not found.",
        "MessageArgs": [
          "Fan",
          "fanx"
        ],
        "MessageId": "Base.1.13.0.ResourceNotFound",
        "MessageSeverity": "Critical",
        "Resolution": "Provide a valid resource identifier and resubmit the request."
      }
    ],
    "code": "Base.1.13.0.ResourceNotFound",
    "message": "The requested resource of type Fan named 'fanx' was not found."
  }
}
'''

Signed-off-by: Albert Zhang <zhanghaodi@inspur.com>
Change-Id: I52c465f745587233e43a2947c392d1435b2d980b
Signed-off-by: Lakshmi Yadlapati <lakshmiy@us.ibm.com>
diff --git a/Redfish.md b/Redfish.md
index 4607589..8584673 100644
--- a/Redfish.md
+++ b/Redfish.md
@@ -320,6 +320,12 @@
 - Members
 - Members@odata.count
 
+#### /redfish/v1/Chassis/{ChassisId}/ThermalSubsystem/Fans/{FanName}/
+
+#### Fan
+
+- Status
+
 ### /redfish/v1/Chassis/{ChassisId}/Power#/PowerControl/{ControlName}/
 
 #### PowerControl
diff --git a/redfish-core/lib/fan.hpp b/redfish-core/lib/fan.hpp
index 47d65ee..fb2ba20 100644
--- a/redfish-core/lib/fan.hpp
+++ b/redfish-core/lib/fan.hpp
@@ -7,7 +7,9 @@
 #include "registries/privilege_registry.hpp"
 #include "utils/chassis_utils.hpp"
 
+#include <boost/system/error_code.hpp>
 #include <boost/url/format.hpp>
+#include <sdbusplus/asio/property.hpp>
 #include <sdbusplus/message/types.hpp>
 
 #include <functional>
@@ -222,6 +224,58 @@
     resp.jsonValue["Id"] = fanId;
     resp.jsonValue["@odata.id"] = boost::urls::format(
         "/redfish/v1/Chassis/{}/ThermalSubsystem/Fans/{}", chassisId, fanId);
+    resp.jsonValue["Status"]["State"] = "Enabled";
+    resp.jsonValue["Status"]["Health"] = "OK";
+}
+
+inline void getFanHealth(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+                         const std::string& fanPath, const std::string& service)
+{
+    sdbusplus::asio::getProperty<bool>(
+        *crow::connections::systemBus, service, fanPath,
+        "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional",
+        [asyncResp](const boost::system::error_code& ec, const bool value) {
+        if (ec)
+        {
+            if (ec.value() != EBADR)
+            {
+                BMCWEB_LOG_ERROR << "DBUS response error for Health "
+                                 << ec.value();
+                messages::internalError(asyncResp->res);
+            }
+            return;
+        }
+
+        if (!value)
+        {
+            asyncResp->res.jsonValue["Status"]["Health"] = "Critical";
+        }
+        });
+}
+
+inline void getFanState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+                        const std::string& fanPath, const std::string& service)
+{
+    sdbusplus::asio::getProperty<bool>(
+        *crow::connections::systemBus, service, fanPath,
+        "xyz.openbmc_project.Inventory.Item", "Present",
+        [asyncResp](const boost::system::error_code& ec, const bool value) {
+        if (ec)
+        {
+            if (ec.value() != EBADR)
+            {
+                BMCWEB_LOG_ERROR << "DBUS response error for State "
+                                 << ec.value();
+                messages::internalError(asyncResp->res);
+            }
+            return;
+        }
+
+        if (!value)
+        {
+            asyncResp->res.jsonValue["Status"]["State"] = "Absent";
+        }
+        });
 }
 
 inline void
@@ -229,8 +283,9 @@
                          const std::string& chassisId, const std::string& fanId,
                          const std::string& fanPath, const std::string& service)
 {
-    BMCWEB_LOG_DEBUG << "fanPath = " << fanPath << " service = " << service;
     addFanCommonProperties(asyncResp->res, chassisId, fanId);
+    getFanState(asyncResp, fanPath, service);
+    getFanHealth(asyncResp, fanPath, service);
 }
 
 inline void doFanGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,