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. how use configuration poll hook

how use configuration poll hook

Scheduled Pinned Locked Moved Support
1 Posts 1 Posters 20.8k 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.
  • S
    S
    SKYnv
    wrote on last edited by
    #1

    Configuration poll hook is new feature of NetXMS 1.2.3
    How it use?

    1. create script in script library with Hook::ConfigurationPoll name.
    2. write your script.

    This script will be executed for node after each configuration poll

    simple script example

    //rename node after configuration poll to snmp sysLocation
    //if sysLocation is null then rename to node ip address
    //also 3 custom attributes will be setted
    // you can use this attributes in events with %{attribute_name} macros
    //uncomment trace line and run netxmsd with -D1 param for logging
    
    sub main()
    {
      if ($node->isSNMP)
       {
      //trace(1,"hook executed for ".$node->ipAddr);
       transport = CreateSNMPTransport($node);
        if (transport == null)
        {
        //trace(1,"snmp transport error on ".$node->ipAddr);
        return -1;
        }
    
        location = SNMPGetValue(transport, ".1.3.6.1.2.1.1.6.0"); // sysLocation
        sysname = SNMPGetValue(transport, ".1.3.6.1.2.1.1.5.0");  // sysname
        uptime = SNMPGetValue(transport, ".1.3.6.1.2.1.1.3.0");   // uptime
    
        //trace(1,"[".location."], [".sysname."], [".uptime."]");
    
        if (location != null && location !="" && location!=" ")
         {
             //trace(1,"attr location changed to ".location);
             RenameObject($node, location);
         }
        else
        {
             //trace(1,"error in location block");
             RenameObject($node, $node->ipAddr); //change name to node ip address
        }
        if (sysname != null && sysname !="" && sysname !=" ")
        {
             SetCustomAttribute($node, "sysname", sysname); //set custom attribute for node snmp sysName
             //trace(1,"attr sysname changed to ".location);
        }
        else
        {
             //trace(1,"error in sysname block");
        }
    
        if (uptime != null)
        {
             SetCustomAttribute($node, "uptime", SecondsToUptime(uptime/100)); //set custom attribute uptime for node
             //trace(1,"attr uptime changed to ".SecondsToUptime(uptime/100));
        }
        else
        {
            //trace(1,"error in uptime block");
        }
    
        //trace(1,"end execution");
        SetCustomAttribute($node, "last_update",localtime(time())->mday.".".localtime(time())->mon.".".localtime(time())->year.", ".localtime(time())->hour.":".localtime(time())->min.":".localtime(time())->sec);
      }
    }
    
    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