News:

We really need your input in this questionnaire

Main Menu

Help with Java API

Started by Andrew, August 09, 2016, 12:33:31 AM

Previous topic - Next topic

Andrew

Hello, I am trying write a simple Java program to help automate some tasks, and I am having some difficulty working with the API.  I wrote this test program:

// NetXMS API Version 2.0.4

import org.netxms.client.*;
import org.netxms.base.*;
import org.netxms.client.objects.*;

public class xmstool
{
    public static void main(String[] args)
   {
      
      try
      {
         NXCSession s = new NXCSession("NetXMS server");
         s.connect();
         s.login("user", "password");
         
         if(s.isConnected())
         {
            System.out.println("Connected");
         }
         else
         {
            System.out.println("Not connected");
         }
         
         AbstractObject node = s.findObjectByName("name of node");
         
         if(node == null)
         {
            System.out.printf("Did not find node\n");
         }
                  
      } catch(Exception e)
      {
         System.out.println("Fail");
         
      }      
    }   
}

I the program runs, and connects to the server, but I am not able to get a valid node object no matter what name I search for.  Am I missing something? Andrew

tomaskir

#1
You need to call "s.syncObjects();" after login, so it syncs server objects to the local client.

Also, please use [code] tags when pasting code next time :)

Andrew

Quote from: tomaskir on August 09, 2016, 02:32:22 AM
You need to call "s.syncObjects();" after login, so it syncs server objects to the local client.

Also, please use [code] tags when pasting code next time :)
THANK YOU!!! that was the pierce to the puzzle I was looking for, and I will use the code tag in the future.

Second question, I see a getGeolocation() method for getting the geolocation, but how does one go about setting the geolocation?  Andrew

Alex Kirhenshtein

Something like this:


final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
GeoLocation location = GeoLocation.parseGeoLocation(latitude.getText(), longitude.getText());
md.setGeolocation(location);

final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
session.modifyObject(md);

tomaskir

Just a side note:
If you just need to modify GeoLocation data, consider using just a NXSL script, the "Node" object in NXSL has methods for GeoLocation retrieval and manipulation.

https://wiki.netxms.org/wiki/NXSL:Node

Andrew

Quote from: tomaskir on August 09, 2016, 02:41:33 PM
Just a side note:
If you just need to modify GeoLocation data, consider using just a NXSL script, the "Node" object in NXSL has methods for GeoLocation retrieval and manipulation.

https://wiki.netxms.org/wiki/NXSL:Node

The 'setGeoLocation' method doesn't seem to work in NXSL, but I was able to successfully use a simple Java program to export the node names with their latitude and longitude from an older NetXMS server to a newer one.  Thank you for all your help!  Andrew