iLO support
authorAlex Kirhenshtein <alk@netxms.org>
Sun, 5 May 2013 09:24:04 +0000 (09:24 +0000)
committerAlex Kirhenshtein <alk@netxms.org>
Sun, 5 May 2013 09:24:04 +0000 (09:24 +0000)
iLO support

include/nms_util.h
src/server/core/node.cpp

index d8c42b4..3260a58 100644 (file)
@@ -551,6 +551,8 @@ public:
        bool connect(DWORD ip, WORD port, DWORD timeout);
        int read(char *pBuff, int nSize, DWORD timeout = INFINITE);
        int readLine(char *buffer, int size, DWORD timeout = INFINITE);
+
+       static TelnetConnection *createConnection(const TCHAR *hostName, WORD port, DWORD timeout);
 };
 
 #endif   /* __cplusplus */
index eafec09..484f5bd 100644 (file)
@@ -3378,6 +3378,60 @@ DWORD Node::getInternalItem(const TCHAR *param, DWORD bufSize, TCHAR *buffer)
    return rc;
 }
 
+
+/**
+ * Get value from iLO board
+ */
+DWORD Node::getItemFromILO(const TCHAR *path, const TCHAR *param, DWORD bufSize, TCHAR *buffer)
+{
+   DWORD result = DCE_COMM_ERROR;
+
+   const TCHAR *login = getCustomAttribute(_T("iLO.login"));
+   const TCHAR *password = getCustomAttribute(_T("iLO.password"));
+
+   if (!(m_dwDynamicFlags & NDF_UNREACHABLE) && login != NULL && password != NULL)
+   {
+      TelnetConnection *conn = new TelnetConnection();
+      if (conn->connect(htonl(m_dwIpAddr), 23, 1000))
+      { 
+         if (conn->waitForText(":", 1000)) {
+            conn->writeLine(login);
+            if (conn->waitForText(":", 1000)) {
+               conn->writeLine(password);
+               if (conn->waitForText("iLO->", 1000)) {
+                  TCHAR tmp[1024];
+                  _sntprintf(tmp, 1024, "show -o format=text %s", path);
+                  // TODO: convert to multibyte!!!
+                  conn->writeLine(tmp);
+
+                  while (conn->readLine(tmp, 1024, 500) > 0) {
+                     if (_tcsstr(tmp, _T("iLO->")) != NULL)
+                     {
+                        break;
+                     }
+                     StrStrip(tmp);
+                     int numStrings = 0;
+                     TCHAR **splitted = SplitString(tmp, _T('='), &numStrings);
+                     if (numStrings == 2 && !_tcsicmp(splitted[0], param))
+                     {
+                        nx_strncpy(buffer, splitted[1], bufSize);
+                        result = DCE_SUCCESS;
+                        break;
+                     }
+                  }
+                  conn->writeLine(_T("quit"));
+               }
+            }
+         }
+         conn->disconnect();
+      }
+   }
+
+   DbgPrintf(7, _T("Node(%s)->GetItemFromILO(%s, %s): result=%d"), m_szName, path, param, result);
+
+   return result;
+}
+
 /**
  * Get value from iLO board
  */