No output from ExternalParameterShellExec

Started by vijayrana, June 15, 2017, 06:35:17 PM

Previous topic - Next topic

vijayrana

I am trying to get CPU usage of a process on Microsoft Windows Server 2008 R2 using dos script. When I run dos script I am getting value. But on NetXMS server I am getting blank value. My dos script  is as following :-

@echo off
wmic path Win32_PerfFormattedData_PerfProc_Process get Name,PercentProcessorTime | findstr /i /c:w3wp >%temp%\cpu.txt
set /p cph=<%temp%\cpu.txt
for /f "delims=" %%2 in (%temp%\cpu.txt) do set CpuUsage=%%2
set CpuUsage=%CpuUsage:w3wp=%
set CpuUsage=%CpuUsage: =%
rem set "%~1=%CpuUsage%"
echo %CpuUsage%

When I run this dos script from command prompt I get following value :-
30

I have configured ExternalParameterShellExecin on agent configuration file as following :-

#
# NetXMS agent configuration file
# Created by agent installer at Sat May 20 17:52:36 2017
#

MasterServers = netxms.kochartech.com
ConfigIncludeDir = C:\NetXMS\etc\nxagentd.conf.d
LogFile = C:\NetXMS\Log.txt
DebugLevel = 9
AgentCommandTimeout = 40000
FileStore = C:\NetXMS\var
SubAgent = ecs.nsm
SubAgent = filemgr.nsm
SubAgent = ping.nsm
SubAgent = logwatch.nsm
SubAgent = portcheck.nsm
SubAgent = winperf.nsm
SubAgent = wmi.nsm
ExternalParameterShellExec=w3wpcpu:C:\NetXMS\scripts\CpuUsage.cmd


I have restarted the agent. Run Poll full configuration on Node from server console.
When I run following command from server I got blank value
c:\NetXMS\bin>nxget X.X.X.X w3wpcpu

On agent debug log file I got this

[15-Jun-2017 20:57:54.262] [DEBUG] [session:1] Received message CMD_GET_PARAMETER
[15-Jun-2017 20:57:54.262] [DEBUG] [session:1] Requesting parameter "w3wpcpu"
[15-Jun-2017 20:57:54.262] [DEBUG] H_ExternalParameter called for "w3wpcpu" "SC:\NetXMS\scripts\CpuUsage.cmd"
[15-Jun-2017 20:57:54.262] [DEBUG] RunExternal called for "w3wpcpu" "SC:\NetXMS\scripts\CpuUsage.cmd"
[15-Jun-2017 20:57:54.262] [DEBUG] RunExternal: command line is "C:\NetXMS\scripts\CpuUsage.cmd"
[15-Jun-2017 20:57:54.262] [DEBUG] RunExternal (shell exec): worker thread created
[15-Jun-2017 20:57:54.730] [DEBUG] RunExternal (shell exec): execution status 0
[15-Jun-2017 20:57:54.730] [DEBUG] [session:1] GetParameterValue(): result is 0 (SUCCESS)
[15-Jun-2017 20:57:54.730] [DEBUG] [session:1] Sending message CMD_REQUEST_COMPLETED (size 48)
[15-Jun-2017 20:57:54.730] [DEBUG] [session:1] Outgoing message dump:
  ** 001D0000000000300000000200000002
  ** 0000001C000000000000000000000000
  ** 00000015010000000000000000000000
  ** code=0x001D (CMD_REQUEST_COMPLETED) flags=0x0000 id=2 size=48 numFields=2
  ** [    28] INT32    0
  ** [    21] STRING   ""

[15-Jun-2017 20:57:54.746] [DEBUG] [session:1] Message receiving error (MSGRECV_CLOSED)
[15-Jun-2017 20:57:54.746] [DEBUG] [session:1] Session with X.X.X.X closed
[15-Jun-2017 20:57:55.448] [DEBUG] [session:0] Message dump:
  ** 00410000000000300000003700000001
  ** 00000055010000000000000E00770033
  ** 00770070006300700075000000000000
  ** code=0x0041 (CMD_GET_PARAMETER) flags=0x0000 id=55 size=48 numFields=1
  ** [    85] STRING   "w3wpcpu"

[15-Jun-2017 20:57:55.448] [DEBUG] [session:0] Received message CMD_GET_PARAMETER
[15-Jun-2017 20:57:55.448] [DEBUG] [session:0] Requesting parameter "w3wpcpu"
[15-Jun-2017 20:57:55.448] [DEBUG] H_ExternalParameter called for "w3wpcpu" "SC:\NetXMS\scripts\CpuUsage.cmd"
[15-Jun-2017 20:57:55.448] [DEBUG] RunExternal called for "w3wpcpu" "SC:\NetXMS\scripts\CpuUsage.cmd"
[15-Jun-2017 20:57:55.448] [DEBUG] RunExternal: command line is "C:\NetXMS\scripts\CpuUsage.cmd"
[15-Jun-2017 20:57:55.448] [DEBUG] RunExternal (shell exec): worker thread created
[15-Jun-2017 20:57:55.900] [DEBUG] RunExternal (shell exec): execution status 0
[15-Jun-2017 20:57:55.900] [DEBUG] [session:0] GetParameterValue(): result is 0 (SUCCESS)
[15-Jun-2017 20:57:55.900] [DEBUG] [session:0] Sending message CMD_REQUEST_COMPLETED (size 48)
[15-Jun-2017 20:57:55.900] [DEBUG] [session:0] Outgoing message dump:
  ** 001D0008000000300000003700000002
  ** 0000001C000000000000000000000000
  ** 00000015010000000000000000000000
  ** code=0x001D (CMD_REQUEST_COMPLETED) flags=0x0008 id=55 size=48 numFields=2
  ** [    28] INT32    0
  ** [    21] STRING   ""


Kindly help how to resolve the issue and get value on server.

Victor Kirhenshtein

Hi!

Agent usually runs under local system account. Are you sure that your script will work correctly under local system?

Best regards,
Victor

vijayrana

Hi,

Yes, script is working under local system account. It is writing output to txt file. I have tried vb-script to get desired results, VB script is working fine and I am able to get results from ExternalParamaterShellExec.  But DOS script is not giving any results.

Regards,
Vijay.