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. Simple question - variable which holds result of icmp when doing status polls

Simple question - variable which holds result of icmp when doing status polls

Scheduled Pinned Locked Moved Support
3 Posts 2 Posters 25.1k 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.
  • P
    P
    paul
    wrote on last edited by
    #1

    I have my nodeUpDown custom variable auto binding and unbinding working - except for the last piece - updating this custom variable when status polling.

    I do NOT want to just use the event and do it via event processing - Event Policy processing can get behind so this way avoids waiting - it updates what we look at immediately.

    I want to add to the Status hook the setting of the nodeUpDown based on the ICMP ping response.
    If I can ping the device - set it to up. If I cannot ping it, set it to down.

    Something like this below added to the status polling hook script - once I know the variable that holds the ICMP response.

    if (($node->icmpresponse == "no")) {
       newstate = "Down";
       oldstate = GetCustomAttribute($node, "nodeUpDown");
    
             if (newstate != null)
                {
                 if ((newstate imatch "Down"))
                     {
                      BindObject(FindObject("AllDown"), $node);
                      SetCustomAttribute($node, "nodeUpDown", newstate);
                     }
       }
    if (($node->icmpresponse = "yes")) {
       newstate = "Up";
       oldstate = GetCustomAttribute($node, "nodeUpDown");
    
             if (newstate != null)
                {
                 if ((newstate imatch "Up"))
                     {
                       SetCustomAttribute($node, "nodeUpDown", newstate);
                       UnbindObject(FindObject("AllDown"), $node);
             }
       }
    
    }
    
    1 Reply Last reply
    0
    • V
      V
      Victor Kirhenshtein
      wrote on last edited by
      #2

      I recommend using runtimeFlags field to determine that node is completely unreachable, like this:

      if (($node->icmpresponse & 4) != 0)
         // state is "down"
      

      Also few comments on script itself - purely style/clarity, not functionality:

      1. You may use direct comparison instead of regexp match if you are loking for exact match, i.e.

      (newstate == "Down")

      instead of

      (newstate imatch "Down")

      1. No need for checking status twice, just can just use else:
      if ($node->icmpresponse == "no") {
      }
      else {
      }
      

      Best regards,
      Victor

      1 Reply Last reply
      0
      • P
        P
        paul
        wrote on last edited by
        #3

        Fantastic - thanks Victor.

        Coding style - mine is mostly a hack and slash approach to something else I have seen as an example or that I know works. Once it works, rather than go back and clean it up - more trial and error - I move onto the next highest priority task.

        The more I do with NetXMS, the better I will get.

        Between this and the runtime flag for unreachable - very, very happy person I am today 🙂

        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