Help with Java API
-
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 said in Help with Java API:
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
-
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); -
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. -
@tomaskir said in Help with Java API:
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.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
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