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. Automatic Apply rules based on OS type

Automatic Apply rules based on OS type

Scheduled Pinned Locked Moved Support
7 Posts 2 Posters 66.2k 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.
  • M
    M
    maliodpalube
    wrote on last edited by
    #1

    Hello,

    we are trying to apply templates based on OS type (linux/windows)

    We have created and applied following filtering script on Automatic Apply Rules tab on Template Object properties, but no targets have been added. Is there anything we are doing wrong?

    if (!$object || !$object.isNode())
       return false;
    
    pn = LowerCase($object.platformName);
    if ((pn != null) && StrStartsWith(pn, "windows"))
       return true;
    
    sd = LowerCase($object.snmpSysDescription);
    return (sd != null) && (StrFind(sd, "windows") != -1);
    
    1 Reply Last reply
    0
    • F
      F
      Filipp Sudanov
      wrote on last edited by
      #2

      Here's a fixed version:

      if (!$node)
         return false;
      
      pn = $object.platformName.toLowerCase();
      if (pn != null && pn.startsWith("windows"))
         return true;
      
      sd = $object.sysDescription.toLowerCase();
      return (sd != null && sd.contains("windows"));
      

      $object always exists, so there's no need to check for that. NXSL never had LowerCase() or StrStartsWith() functions, did you use an AI to generate this?

      1 Reply Last reply
      0
      • M
        M
        maliodpalube
        wrote on last edited by
        #3

        Yes,Ai was used to create snippet.

        Also How can we test it/force it to show results? Or is the only option to wait?

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

          You can easily test it - just take any node, select Execute script from the context menu and paste your script there. Your script will be executed in the same way as when a template executes it on nodes.

          In addition, when you execute it that way you can use println() commands to print, so you can use it for debugging purposes.

          1 Reply Last reply
          0
          • M
            M
            maliodpalube
            wrote on last edited by
            #5

            We were able tu use shorter code snippet

            return $node->isAgent && $node->platformName like "windows-*";
            

            It returns the same output.

            Thx for the help

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

              It's better to add check for $node:

              return $node && $node->isAgent && $node->platformName like "windows-*";

              the reason is that there are some other types of object - clusters, sensors, collectors on which templates can also be applied, but there will be no $node on these objects.

              1 Reply Last reply
              0
              • M
                M
                maliodpalube
                wrote on last edited by
                #7

                Ok, changed the code, thx again for the info 😉

                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