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. Instance discovery method: script

Instance discovery method: script

Scheduled Pinned Locked Moved Support
4 Posts 2 Posters 17.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.
  • T
    T
    twenrich
    wrote on last edited by
    #1

    Hi,

    I'm having troubles to get the instance-discovery by script working.

    I have:

    • Instance Discovery Method: Script
    • a Filter script (in the moment just tracing)

    However, the filter script doesn't get called - I assume the array returned by list_attributes_by_key() does not find it's way to the instance discovery.
    When running the script via "Execute server script", I get the debugs (trace, println) printed.

    Can someone point out my error with this ?

    Kind regards,
    Thomas

    edited: this is NetXMS 2.1M2

    Script "list_attributes_like_http"

    // Works!
    // array a;
    // a[0] = "Entry 1";
    // a[1] = "Entry 2";
    // return a;
    
    use list_attributes;
    
    a = list_attributes_by_key("http:.*");
    foreach (entry: a)
    	{
    	msg = "like http: " . $node->name . " " . entry;
    	trace(1, msg);
    	println "P " . msg;
    	}
    return a;
    

    "list_attributes"

    // list_attributes
    //
    // retrieving attribute values.
    //
    //
    // Parameter:
    //		$1: regex to check the attribute key for.
    //
    // Returns:
    //		List of all attributes matching the attribute
    
    sub list_attributes_by_key(pattern)
    	{
    	array r;
    	if (pattern == null)
    		{
    		msg = $node->name .  " list_attribute_by_key: no pattern!";
    		println msg;
    		trace(1, msg);
    		return a;
    		}
    	test = "http://12345.678/";
    	if (test match pattern)
    		println "pattern: ". pattern . " test matched OK".
    
    	r_i = 0;
    	attr = $node->customAttributes;
    	foreach (key: attr->keys)
    		{
    		println a;
    		if (key ~= pattern)
    			{
    			println $node->name . " return key=" . key;
    			r[r_i++] = key;
    			}
    		else
    			{
    			println $node->name . " no match for " . key . ". pattern=". pattern;
    			}
    		}
    	return r;
    	}
    

    netxms01.PNG

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

      Hi,

      I found this out:

      In the template, the "Source Node" is set.
      Within the scripts, $node is set to the "Source Node", not to the node where the actual instance discovery happens (see screenshot).
      When trying the scripts using "Execute Server Script", $node is the "Discovery Node" and everything is fine.

      This is OK, I think, as most of the discovery will be done on the "Source Node" (and it's agent) anyway.

      Is there an easy way to get the "discovery" node into the scripts so I have access to the custom attributes of the discovery node ?

      I want to create some checks on behalf node A and running on node B, controlled by node A's custom attributes.

      Thank you very much,

      Thomas


      netxms03.PNG

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

        Hi,

        I've added a feature request for that: https://track.radensolutions.com/issue/NX-1234. Should be an easy fix.

        Best regards,
        Victor

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

          Fixed in upcoming 2.1 release. DCI owner can be accessed in instance discovery and data collection scripts via $targetObject global variable.

          Best regards,
          Victor

          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