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. Development
  3. Help with Java API

Help with Java API

Scheduled Pinned Locked Moved Development
6 Posts 3 Posters 20.0k 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.
  • A
    A
    Andrew
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • T
      T
      tomaskir
      wrote on last edited by
      #2

      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 🙂

      1 Reply Last reply
      0
      • A
        A
        Andrew
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        0
        • A
          A
          Alex Kirhenshtein
          wrote on last edited by
          #4

          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);
          
          1 Reply Last reply
          0
          • T
            T
            tomaskir
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • A
              A
              Andrew
              wrote on last edited by
              #6

              @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.

              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

              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