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. Assigning a Template based on installed software

Assigning a Template based on installed software

Scheduled Pinned Locked Moved Support
5 Posts 3 Posters 29.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.
  • T
    T
    Tursiops
    wrote on last edited by
    #1

    Hi,

    While I can easily apply a template to a Windows system with a NetXMS Agent on it, I am having trouble narrowing this down further to, for example, systems running Microsoft Exchange, SQL or other software.
    NetXMS has the required data for this, but how do I test for this within the Template's Automatic Apply Rules?

    Of course I can apply a DCI to all Windows systems with a NetXMS Agent, run a test and use that, but I want to avoid having to add a DCI for this in the first place as the data already exists in NetXMS (why check twice?).

    Any ideas?

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

      Hi,

      To answer my own question somewhat, I managed to do what I had planned by creating a script that checks System.InstalledProducts, returns "OK" (no matter what) and assigning this to a DCI.
      Along the way of checking that table, it sets custom attributes for any installed product that I want to monitor.
      That then allows me to apply templates to systems with those custom attributes set.

      Script below (for testing I only checked for Microsoft Exchange Server, but can be adjusted to other things):

      sub main()
      {
      	table=AgentReadTable($node,"System.InstalledProducts");
      	idxName = table->getColumnIndex("NAME");
      	for (row = 0; row < table->rowCount; row++)
      	{
       		value = table->get(row, idxName);
       		switch (value)
      		{
       			case "Microsoft Exchange Server": SetCustomAttribute($node,"Microsoft Exchange Server","Installed");
      		}
      	}
      	return "OK";
      }
      

      Now I have a couple more problems:

      1. My NetXMS server now keeps throwing up alarms against itself all the time: "Script (System::SetInstalledPackageAttributes) execution error: Error 14 in line 4: Function or operation argument is not an object". "System::SetInstalledPackageAttributes" being the name of the script. The script is not actually called against the server itself, so this appears to be an issue when the server calls it against a node? This DCI is only applied to systems with the NetXMS agent installed and running Windows. All of which should have System.InstalledPackages?

      2. This only works for software showing in that table, which doesn't include Remote Desktop Session Hosts or any other "Windows Feature". I could check for thos via (deprecated) WMI Query (which may also run into timeouts) or I would have to call PowerShell's Get-WindowsFeature cmdlet. Unfortunately I have currently no idea how to do that one in NetXMS... maybe an idea for a subagent? Together with uploading PowerShell scripts, that could be quite powerful?

      1 Reply Last reply
      0
      • T
        T
        tomaskir
        wrote on last edited by
        #3

        I have modified the script for you so you can use it directly as a bind script.

        So use this as an auto-bind script on a template, and you dont need DCIs or custom attributes.
        It will also solve your issue no. 1.

        if (! $node->isAgent)
          return false;
        
        table = AgentReadTable($node, "System.InstalledProducts");
        
        colName = table->getColumnIndex("NAME");
        
        for (currentRow = 0; currentRow < table->rowCount; currentRow++)
        {
          value = table->get(currentRow, colName);
        
          if (value == "Microsoft Exchange Server")
            return true;
        }
        
        return false;
        
        1 Reply Last reply
        0
        • T
          T
          Tursiops
          wrote on last edited by
          #4

          Thanks! That worked without having to go through custom attributes. 🙂

          I still had some issues with problem no. 1, as it "moved" from the DCI script to template auto-bind one.
          However adding another line of code resolved that. I also changed the script it to only apply to Windows systems.
          So now it looks like this and does not throw any more errors:

          if ( (! $node->isAgent) && (! $node->platformName ~= "windows.*") )
          	return false;
          
          table = AgentReadTable($node, "System.InstalledProducts");
          
          if ( table == null )
          	return false;
          
          colName = table->getColumnIndex("NAME");
          
          for (currentRow = 0; currentRow < table->rowCount; currentRow++)
          {
          	if ( table->get(currentRow, colName) == "Microsoft Exchange Server" )
          		return true;
          }
          
          return false;
          

          Still not quite sure what to do in regards to installed Windows Features.  😕

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

            Hi,

            it requires changes in how Windows agent reads list of installed software. I'll try to fix that before 2.0 release.

            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