Getting value from ExternalParameter / ExternalMetric not working after update

Started by stoffmann, December 13, 2023, 02:08:46 PM

Previous topic - Next topic

stoffmann

Hi,
I updated our NetXMS installation from 4.2 to 4.4.5 today and have a problem with getting values from ExternalParameter.

I used the following line in 4.2 to get the value of a registry key:
ExternalParameter=RegQuery.EBTransfer720:"D:\Program Files\NetXMSAgent\custom\CheckRegKey\CheckRegKey.exe" "HKLM\SOFTWARE\WOW6432Node\Aucotec\Engineering Base\7.2.0\Server\Files" "ImageFilePath"

After update the showed the following in value:
'D:\Program' is not recognized as an internal or external command

After some reading I found that  ExternalParameter is replaced by ExternalMetric,
so I tried:

ExternalMetric=RegQuery.EBTransfer720:"D:\Program Files\NetXMS\custom\CheckRegKey\CheckRegKey.exe" "HKLM\SOFTWARE\WOW6432Node\Aucotec\Engineering Base\7.2.0\Server\Files" "ImageFilePath"
But the result us the same:  'D:\Program' is not recognized as an internal or external command

Any idea what could be the reason?

Regards

Stefan

stoffmann

I checked the agent log and after invreasing the debug level to 7; found thi. Maybe it can help identify the reason:
2023.12.13 13:02:47.458 *D* [comm.cs.1          ] Requesting metric "RegQuery.EBTransfer720"
2023.12.13 13:02:47.458 *D* [comm.cs.1          ] H_ExternalMetric called for "RegQuery.EBTransfer720" ""D:\Program Files\NetXMSAgent\custom\CheckRegKey\CheckRegKey.exe" "HKLM\SOFTWARE\WOW6432Node\Aucotec\Engineering Base\7.2.0\Server\Files" "ImageFilePath""
2023.12.13 13:02:47.458 *D* [exec              ] RunExternal called for "RegQuery.EBTransfer720" ""D:\Program Files\NetXMSAgent\custom\CheckRegKey\CheckRegKey.exe" "HKLM\SOFTWARE\WOW6432Node\Aucotec\Engineering Base\7.2.0\Server\Files" "ImageFilePath""
2023.12.13 13:02:47.458 *D* [exec              ] RunExternal: command line is ""D:\Program Files\NetXMSAgent\custom\CheckRegKey\CheckRegKey.exe" "HKLM\SOFTWARE\WOW6432Node\Aucotec\Engineering Base\7.2.0\Server\Files" "ImageFilePath""
2023.12.13 13:02:47.473 *D* [procexec.13        ] ProcessExecutor::executeWithOutput(): process "CMD.EXE /C "D:\Program Files\NetXMSAgent\custom\CheckRegKey\CheckRegKey.exe" "HKLM\SOFTWARE\WOW6432Node\Aucotec\Engineering Base\7.2.0\Server\Files" "ImageFilePath"" started (PID=14800)
2023.12.13 13:02:47.739 *D* [procexec.13        ] ProcessExecutor::readOutput(): stopped on GetOverlappedResult (The pipe has been ended.)
2023.12.13 13:02:47.739 *D* [procexec.13        ] ProcessExecutor::stop(): cannot terminate process (Access is denied.)
2023.12.13 13:02:47.739 *D* [comm.cs.1          ] GetMetricValue("RegQuery.EBTransfer720"): 0 (SUCCESS) value = "'D:\Program' is not recognized as an internal or external command,"
2023.12.13 13:02:47.739 *D* [comm.cs.1          ] Sending message CMD_REQUEST_COMPLETED (ID 3839; size 112; uncompressed)


To me it looks like Net XMS is adding a CMD.EXE /C before my command, witch I don't understand. Shoudn't this be only the case if I use ExternalMetricShellExec?

Filipp Sudanov

The problem is that single quotes are get lost somewhere during all this process. You can specify using "" which will be escaped to " in the end, e.g.:
ExternalMetric=RegQuery.EBTransfer720:""D:\Program
 Files\NetXMS\custom\CheckRegKey\CheckRegKey.exe""
"HKLM\SOFTWARE\WOW6432Node\Aucotec\Engineering Base\7.2.0\Server\Files"
"ImageFilePath"

But better way is to use new (and not yet documented) docker-style syntax:
ExternalMetric=RegQuery.EBTransfer720:['D:\Program
 Files\NetXMS\custom\CheckRegKey\CheckRegKey.exe', 
'HKLM\SOFTWARE\WOW6432Node\Aucotec\Engineering Base\7.2.0\Server\Files', 
'ImageFilePath']

currently that works with single quotes (') only, but in next patch release double quotes (") will also be supported.