ILO Support working
authorAlex Kirhenshtein <alk@netxms.org>
Mon, 3 Jun 2013 10:33:48 +0000 (10:33 +0000)
committerAlex Kirhenshtein <alk@netxms.org>
Mon, 3 Jun 2013 10:33:48 +0000 (10:33 +0000)
src/server/core/node.cpp
src/server/core/smclp.cpp
src/server/include/nxcore_smclp.h

index 8479397..b996ca3 100644 (file)
@@ -3385,48 +3385,28 @@ DWORD Node::getItemFromILO(const TCHAR *path, const TCHAR *param, DWORD bufSize,
 {
    DWORD result = DCE_COMM_ERROR;
 
-   /*
    const char *login = getCustomAttribute(_T("iLO.login"));
    const char *password = getCustomAttribute(_T("iLO.password"));
 
+   SMCLP_Connection *connection = new SMCLP_Connection(this->IpAddr(), 23);
+
    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"));
-               }
-            }
+      if (connection->connect(login, password))
+      {
+         TCHAR *value = connection->get(path, param);
+         if (value != NULL)
+         {
+            nx_strncpy(buffer, value, bufSize);
+            free(value);
+            result = DCE_SUCCESS;
+         }
+         else
+         {
+            result = DCE_NOT_SUPPORTED;
          }
-         conn->disconnect();
       }
    }
-   */
 
    DbgPrintf(7, _T("Node(%s)->GetItemFromILO(%s, %s): result=%d"), m_szName, path, param, result);
 
index 0fa65c8..7147567 100644 (file)
 /**\r
  * Constructor\r
  */\r
-SMCLP_Connection::SMCLP_Connection(const TCHAR *host, WORD port, int protocol)\r
+SMCLP_Connection::SMCLP_Connection(DWORD ip, WORD port)\r
 {\r
-       m_host = _tcsdup(host);\r
+       m_ip = ip;\r
        m_port = htons(port);\r
-       m_protocol = protocol;\r
        m_timeout = 5000;\r
        m_conn = NULL;\r
 }\r
@@ -41,7 +40,6 @@ SMCLP_Connection::SMCLP_Connection(const TCHAR *host, WORD port, int protocol)
 SMCLP_Connection::~SMCLP_Connection()\r
 {\r
        disconnect();\r
-       safe_free(m_host);\r
 }\r
 \r
 /**\r
@@ -51,35 +49,47 @@ bool SMCLP_Connection::connect(const TCHAR *login, const TCHAR *password)
 {\r
        bool success = false;\r
 \r
+   nx_strncpy(m_login, login, sizeof(m_login));\r
+   nx_strncpy(m_password, password, sizeof(m_login));\r
+\r
        if (m_conn != NULL)\r
+   {\r
                delete m_conn;\r
+   }\r
 \r
-       m_conn = SocketConnection::createTCPConnection(m_host, m_port, 30000);\r
-       if (m_conn != NULL)\r
-       {\r
-               if (m_conn->waitForText("username:", m_timeout))\r
-               {\r
-//                     m_conn->writeLine(login);\r
-                       if (m_conn->waitForText("password:", m_timeout))\r
-                       {\r
-//                             m_conn->writeLine(password);\r
-                               if (m_conn->waitForText("-> ", m_timeout))\r
-                               {\r
-                                       success = true;\r
-                               }\r
-                       }\r
-               }\r
-\r
-               if (!success)\r
-               {\r
-                       m_conn->disconnect();\r
-                       delete_and_null(m_conn);\r
-               }\r
-       }\r
+   TelnetConnection *m_conn = new TelnetConnection();\r
+   if (m_conn->connect(htonl(m_ip), m_port, m_timeout))\r
+   {\r
+#ifdef UNICODE\r
+      char *_login = UTF8StringFromWideString(m_lo);\r
+      char *_password = UTF8StringFromWideString(password);\r
+#else\r
+      char *_login = m_login;\r
+      char *_password = m_password;\r
+#endif\r
+\r
+      if (m_conn->waitForText(":", m_timeout))\r
+      {\r
+         m_conn->writeLine(_login);\r
+         if (m_conn->waitForText(":", m_timeout)) {\r
+            m_conn->writeLine(_password);\r
+            if (m_conn->waitForText("iLO->", m_timeout)) {\r
+               success = true;\r
+            }\r
+         }\r
+      }\r
 \r
-       return success;\r
+#ifdef UNICODE\r
+      safe_free(_login);\r
+      safe_free(_password);\r
+#endif\r
+   }\r
+\r
+\r
+   return success;\r
 }\r
 \r
+\r
 /**\r
  * Disconnect from target\r
  */\r
@@ -87,7 +97,58 @@ void SMCLP_Connection::disconnect()
 {\r
        if (m_conn != NULL)\r
        {\r
+      m_conn->writeLine("quit");\r
                m_conn->disconnect();\r
-               delete m_conn;\r
+      delete_and_null(m_conn);\r
        }\r
 }\r
+\r
+\r
+/**\r
+ * Get parameter from target\r
+ */\r
+TCHAR *SMCLP_Connection::get(const TCHAR *path, const TCHAR *parameter)\r
+{\r
+   TCHAR *ret = NULL;\r
+#ifdef UNICODE\r
+   char *_path = UTF8StringFromWideString(path);\r
+#else\r
+   const char *_path = path;\r
+#endif\r
+   char buffer[1024];\r
+   snprintf(buffer, 1024, "show -o format=text %s", path);\r
+   m_conn->writeLine(buffer);\r
+#ifdef UNICODE\r
+   free(_path);\r
+#endif\r
+\r
+   while (m_conn->readLine(buffer, 1024, m_timeout / 10) > 0)\r
+   {\r
+      if (strstr(buffer, "iLO->") != NULL)\r
+      {\r
+         break;\r
+      }\r
+\r
+#ifdef UNICODE\r
+      TCHAR _buffer;\r
+      char *_buffer = WideStringFromUTF8String(buffer);\r
+#else\r
+      char *_buffer = buffer;\r
+#endif\r
+\r
+      StrStripA(_buffer);\r
+      int numStrings = 0;\r
+      TCHAR **splitted = SplitString(_buffer, _T('='), &numStrings);\r
+      if (numStrings == 2 && !_tcsicmp(splitted[0], parameter))\r
+      {\r
+         ret = _tcsdup(splitted[1]);\r
+         break;\r
+      }\r
+\r
+#ifdef UNICODE\r
+      free(_buffer);\r
+#endif\r
+   }\r
+\r
+   return ret;\r
+}\r
index dd3d864..15ca20a 100644 (file)
 class NXCORE_EXPORTABLE SMCLP_Connection\r
 {\r
 private:\r
-       TCHAR *m_host;\r
+       DWORD m_ip;\r
        WORD m_port;\r
-       int m_protocol;\r
        DWORD m_timeout;\r
-       SocketConnection *m_conn;\r
+       TelnetConnection *m_conn;\r
+   TCHAR *m_login;\r
+   TCHAR *m_password;\r
 \r
 public:\r
-       SMCLP_Connection(const TCHAR *host, WORD port, int protocol);\r
+       SMCLP_Connection(DWORD ip, WORD port);\r
        ~SMCLP_Connection();\r
 \r
        bool connect(const TCHAR *login, const TCHAR *password);\r
        void disconnect();\r
+\r
+   TCHAR *get(const TCHAR *path, const TCHAR *parameter);\r
 };\r
 \r
 #endif\r