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. Calling curl from inside script library?

Calling curl from inside script library?

Scheduled Pinned Locked Moved Support
4 Posts 2 Posters 22.3k 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.
  • G
    G
    graeChris
    wrote on last edited by
    #1

    I'm trying to build a series of scripts that send curl requests via command line to an external API. I've gone through the Docs multiple times but I haven't been able to find any documentation on how to use NSXL to send a curl command. I was able to get it to work under Actions Configuration, but I need this to occur during Hook::AlarmStateChange. 

    For Curl to work via Actions I had to specify C:\\Windows\\System32\\curl.exe

    Is it possible to call this using NSXL?
    If it is not possible, should we be calling the server action instead?

    1 Reply Last reply
    0
    • F
      F
      Filipp Sudanov
      wrote on last edited by
      #2

      First of all, there is built-in support for web services in NetXMS. It's possible to set up DCIs that get data from web services, but there's also ability to use them from NXSL scripts https://www.netxms.org/documentation/nxsl-latest/#class-webservice

      It's probably not a good idea to have long operations in hook scrips, so I would call PostEvent() from NXSL and then have a rule in EPP that catches that event and calls server action which calls NXSL script.

      1 Reply Last reply
      0
      • G
        G
        graeChris
        wrote on last edited by
        #3

        Hi Filipp,

        Thank you for your help! I was able to call postevent() during the hook using the following:

        sub main()
        {
            eventserver = FindNodeObject($node, 100);
            global alarmstate = $alarm->state;
            switch(alarmstate)
            {
        /* Alarm State is Outstanding */
                case "0":
                    break;
        /* Alarm State is Acknowledged */
                case "1":
                    PostEvent(eventserver, "Xms_Alarm_Ack");
                    break;
        /* Alarm State is Resolved */
                case "2":
                    PostEvent(eventserver, "Xms_Alarm_Resolve");
                    break;
        /* Alarm State is Sticky Acknowledged */
                case "17":
                    PostEvent(eventserver, "Xms_Alarm_StickyAck");
                    break;
            }
        }
        

        I then created the following webservice with the following parameters:

        URL: https://api.opsgenie.com/v2/alerts/**%[OGAckAlarmID]**/acknowledge?identifierType=alias
        HTTP request method: POST
        Request data:

        [
        	{
        		"user": "netXMS Admin",
        		"source\\": "netXMS",
        		"note": "Acknowledged via Alert API from netXMS - Time: %t"
        	}
        ]
        

        I added the Authentication and the Content-Type:application/json in the Headers.

        Now the problem I am running into- The EPP script does not want to run the Webservice without the data argument being passed. I tried to use a variety of Macro schemes to pull the data from the webservice configuration data field but I keep coming up empty. using trace() provided no information either.

        Here are my questions:

        • Can I call a script inside the url field of the webservice configuration?
        • How do I reference the "Request Data" field in the webservice configuration when calling the post function?

        I am attempting to call the post() function found here: https://www.netxms.org/documentation/nxsl-latest/#class-webservice

        1 Reply Last reply
        0
        • F
          F
          Filipp Sudanov
          wrote on last edited by
          #4

          Yes, URL field supports macros, so %[OGAckAlarmID] should work. I am not sure how you are getting alarm ID in that script, may be you should pass the ID as parameter in your PostEvent() calls.

          Request Data field is employed when web service is used as data source for a DCI. When using post() method of web service object, that field is ignored, so you have to pass the whole request in post() call.

          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