Agent environment variables can be set in configuration file
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 15 Sep 2016 09:03:48 +0000 (12:03 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 15 Sep 2016 09:03:48 +0000 (12:03 +0300)
ChangeLog
src/agent/core/nxagentd.cpp

index fe6673d..0d0a778 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -21,6 +21,7 @@
 - Default "admin" account now is ordinary member of "Admins" group without built-in privileges
 - New method "enableDiscoveryPolling" in NXSL class "Node"
 - Agent effective user and group can be set in configuration file
+- Agent environment variables can be set in configuration file
 - New agent metrics for self-monitoring:
        Agent.SyslogProxy.IsEnabled, Agent.SyslogProxy.ReceivedMessages, Agent.SyslogProxy.QueueSize
 - Management console
index 7c27bd8..4f03714 100644 (file)
@@ -1343,6 +1343,36 @@ static int GetGroupId(char *name)
 
 #endif
 
+/**
+ * Update agent environment from config
+ */
+static void UpdateEnvironment()
+{
+   ObjectArray<ConfigEntry> *entrySet = g_config->getSubEntries(_T("/ENV"), _T("*"));
+   if (entrySet == NULL)
+      return;
+   for(int i = 0; i < entrySet->size(); i++)
+   {
+      ConfigEntry *e = entrySet->get(i);
+      size_t len = _tcslen(e->getName()) + _tcslen(e->getValue()) + 2;
+      char *env = (char *)malloc(len);
+      if (env != NULL)
+      {
+#ifdef UNICODE
+         char *mbName = MBStringFromWideString(e->getName());
+         char *mbValue = MBStringFromWideString(e->getValue());
+         snprintf(env, len, "%s=%s", mbName, mbValue);
+         free(mbName);
+         free(mbValue);
+#else
+         sprintf(env, "%s=%s", e->getName(), e->getValue());
+#endif
+         putenv(env);
+      }
+   }
+   delete entrySet;
+}
+
 /**
  * Application entry point
  */
@@ -1815,6 +1845,8 @@ int main(int argc, char *argv[])
                   }
 #endif
 
+                  UpdateEnvironment();
+
                                                s_pid = getpid();
                                                if (Initialize())
                                                {