Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. Agent Actions parameters not working

Agent Actions parameters not working

Scheduled Pinned Locked Moved Support
4 Posts 3 Posters 41.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V
    V
    vlad.fratila
    wrote on last edited by
    #1

    I am trying to call an action from an agent with a parameter. I defined the action in the agent's config file like this:

    ActionShellExec = Echo: /tmp/script.sh $1
    

    The script only echo's it's first parameter to a file.

    I am trying to call the action from an Action Object Tool.
    If I define "Agent's Action" as: Echo, it works and I get in agent's log file with debug level 9 the following:

    [02-Sep-2014 09:48:19.708] [DEBUG] [session:1] Message dump:
      ** 00430000000000380000000200000002
      ** 00000057010000000000000800450063
      ** 0068006F6E205B3200000058007FF229
      ** 0000000000000000
      ** code=0x0043 (CMD_ACTION) flags=0x0000 id=2 size=56 numFields=2
      ** [    87] STRING "Echo"
      ** [    88] INT32  0
    
    [02-Sep-2014 09:48:19.708] [DEBUG] [session:1] Received message CMD_ACTION
    [02-Sep-2014 09:48:19.708] [DEBUG] Executing action Echo of type 3
    [02-Sep-2014 09:48:19.708] [DEBUG] SH_EXEC: Expanding command "/tmp/script.sh"
    [02-Sep-2014 09:48:19.708] [DEBUG] SH_EXEC: Executing "/tmp/script.sh"
    [02-Sep-2014 09:48:19.714] [DEBUG] [session:1] Sending message CMD_REQUEST_COMPLETED (size 32)
    [02-Sep-2014 09:48:19.715] [DEBUG] [session:1] Session with 10.20.1.7 closed
    

    But if I define "Agent's Action" as: Echo parameter1, it fails with a communication failure.
    The log looks like this:

    [02-Sep-2014 09:51:59.670] [DEBUG] [session:1] Message dump:
      ** 00430000000000500000000200000002
      ** 00000057010000000000001E00450063
      ** 0068006F00200070006100720061006D
      ** 0065007400650072003100004C000000
      ** 00000058007F00000000000041006700
      ** code=0x0043 (CMD_ACTION) flags=0x0000 id=2 size=80 numFields=2
      ** [    87] STRING "Echo parameter1"
      ** [    88] INT32  0
    
    [02-Sep-2014 09:51:59.670] [DEBUG] [session:1] Received message CMD_ACTION
    [02-Sep-2014 09:51:59.670] [DEBUG] [session:1] Sending message CMD_REQUEST_COMPLETED (size 32)
    [02-Sep-2014 09:51:59.671] [DEBUG] [session:1] Session with 10.20.1.7 closed
    

    This happens in version 1.2.14 and 1.2.16 also.

    Thank you,
    Vlad

    1 Reply Last reply
    0
    • V
      V
      Victor Kirhenshtein
      wrote on last edited by
      #2

      Yes, actually actions in object tools does not support parameters. Entire string interpreted as action name. I'll register this as a bug.

      Best regards,
      Victor

      1 Reply Last reply
      0
      • F
        F
        Benjamin Dill
        wrote on last edited by
        #3

        I've fixed this. After I fixed it I found out that the server doesn't pass the parameters to the agent, so I had to fix this to.
        And while I were at it I also added a dialog for passing parameters when invoking the action when (*) is used in action name  🙂

        Victor, can I provide you the code in any way or do want to fix it yourself?

        Best whishes,
        Ben

        1 Reply Last reply
        0
        • F
          F
          Benjamin Dill
          wrote on last edited by
          #4
          --- "a/C:\\Users\\VS2005\\AppData\\Local\\Temp\\TortoiseGit\\ses76AB.tmp\\session-b45e65c-left.cpp"
          +++ "b/C:\\Code\\netxms-v1.2.16\\src\\server\\core\\session.cpp"
          @@ -7269,7 +7269,15 @@ void ClientSession::executeAction(CSCPMessage *pRequest)
                       if (pConn != NULL)
                       {
                          pRequest->GetVariableStr(VID_ACTION_NAME, szAction, MAX_PARAM_NAME);
          -               dwResult = pConn->execAction(szAction, 0, NULL);
          +			   int argc = pRequest->getFieldAsInt32(VID_NUM_ARGS);
          +			   TCHAR **argv = new TCHAR*[argc];
          +			   for (int i = 0; i < argc; i++)
          +			   {
          +				   argv[i] = new TCHAR[256];
          +				   pRequest->GetVariableStr(VID_ACTION_ARG_BASE + i, argv[i], 256);
          +			   }
          +               dwResult = pConn->execAction(szAction, argc, argv);
          +			   free(argv);
          
                          switch(dwResult)
                          {
          
          --- "a/C:\\Users\\VS2005\\AppData\\Local\\Temp\\TortoiseGit\\NXC2518.tmp\\NXCSession-b45e65c-left.java"
          +++ "b/C:\\Code\\netxms-v1.2.16\\src\\java\\netxms-client\\src\\main\\java\\org\\netxms\\client\\NXCSession.java"
          @@ -4408,14 +4408,21 @@ public NetworkMapPage queryLayer2Topology(final long nodeId) throws IOException,
               *
               * @param nodeId Node object ID
               * @param action Action name
          +    * @param args Action arguments
               * @throws IOException  if socket I/O error occurs
               * @throws NXCException if NetXMS server returns an error or operation was timed out
               */
          -   public void executeAction(final long nodeId, final String action) throws IOException, NXCException
          +   public void executeAction(final long nodeId, final String action, String[] args) throws IOException, NXCException
              {
                 NXCPMessage msg = newMessage(NXCPCodes.CMD_EXECUTE_ACTION);
                 msg.setVariableInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
                 msg.setVariable(NXCPCodes.VID_ACTION_NAME, action);
          +      if (args != null)
          +      {
          +	      msg.setVariableInt32(NXCPCodes.VID_NUM_ARGS, args.length);
          +	      for (int i=0; i<args.length; i++)
          +	    	  msg.setVariable(NXCPCodes.VID_ACTION_ARG_BASE + i, args[i]);
          +      }
                 sendMessage(msg);
                 waitForRCC(msg.getMessageId());
              }
          
          --- "a/C:\\Users\\VS2005\\AppData\\Local\\Temp\\TortoiseGit\\Obj1C3B.tmp\\ObjectToolExecutor-b45e65c-left.java"
          +++ "b/C:\\Code\\netxms-v1.2.16\\src\\java\\netxms-eclipse\\ObjectTools\\src\\org\\netxms\\ui\\eclipse\\objecttools\\api\\ObjectToolExecutor.java"
          @@ -173,8 +173,30 @@ private static void executeTableTool(final NodeInfo node, final ObjectTool tool)
               */
              private static void executeAgentAction(final NodeInfo node, final ObjectTool tool)
              {
          -      final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
          -      final String action = substituteMacros(tool.getData(), node);
          +	  final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
          +	  String _action = substituteMacros(tool.getData(), node);
          +
          +	  if (_action.endsWith("(*)"))
          +	  {
          +			InputDialog dlg = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
          +					Messages.get().ObjectToolsDynamicMenu_Information, "Parameter", "", null); //$NON-NLS-1$
          +			if (dlg.open() != Window.OK)
          +				return;
          +
          +			_action = _action.replace("(*)", "(" + dlg.getValue() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          +	  }
          +
          +      String[] _args = null;
          +      if (_action.indexOf('(') > 0)
          +      {
          +    	  String a = _action.substring(_action.indexOf('(') + 1, _action.length() - 1);
          +    	  _args = a.split(",");
          +    	  for (int i = 0; i < _args.length; i++) _args[i] = _args[i].trim();
          +    	  _action = _action.substring(0, _action.indexOf('(') + 1) + "*)";
          +      }
          +      final String action = _action;
          +      final String[] args = _args;
          +
                 new ConsoleJob(String.format(Messages.get().ObjectToolsDynamicMenu_ExecuteOnNode, node.object.getObjectName()), null, Activator.PLUGIN_ID, null) {
                    @Override
                    protected String getErrorMessage()
          @@ -185,7 +207,7 @@ protected String getErrorMessage()
                    @Override
                    protected void runInternal(IProgressMonitor monitor) throws Exception
                    {
          -            session.executeAction(node.object.getObjectId(), action);
          +            session.executeAction(node.object.getObjectId(), action, args);
                       runInUIThread(new Runnable() {
                          @Override
                          public void run()
          
          1 Reply Last reply
          0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          Powered by NodeBB Contributors
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups