diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 61b19805aaff99325a0a2e8fb9ea0cdc5ebd3611..b7b2fa8d520a3685de0fdbabb44fe2a1627c8684 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -1587,10 +1587,12 @@ class LUDiagnoseOS(NoHooksLU):
 
     """
     node_list = self.acquired_locks[locking.LEVEL_NODE]
-    node_data = self.rpc.call_os_diagnose(node_list)
+    valid_nodes = [node for node in self.cfg.GetOnlineNodeList()
+                   if node in node_list]
+    node_data = self.rpc.call_os_diagnose(valid_nodes)
     if node_data == False:
       raise errors.OpExecError("Can't gather the list of OSes")
-    pol = self._DiagnoseByOS(node_list, node_data)
+    pol = self._DiagnoseByOS(valid_nodes, node_data)
     output = []
     for os_name, os_data in pol.iteritems():
       row = []
diff --git a/lib/config.py b/lib/config.py
index 5fd410be8dac62bbd09558aa4bc131607efabe04..986b03a4c303dd787adf4720a6b5bdfcaa781c19 100644
--- a/lib/config.py
+++ b/lib/config.py
@@ -786,6 +786,15 @@ class ConfigWriter:
     """
     return self._UnlockedGetNodeList()
 
+  @locking.ssynchronized(_config_lock, shared=1)
+  def GetOnlineNodeList(self):
+    """Return the list of nodes which are online.
+
+    """
+    all_nodes = [self._UnlockedGetNodeInfo(node)
+                 for node in self._UnlockedGetNodeList()]
+    return [node.name for node in all_nodes if not node.offline]
+
   @locking.ssynchronized(_config_lock, shared=1)
   def GetAllNodesInfo(self):
     """Get the configuration of all nodes.