Assigning a Template based on installed software

Started by Tursiops, November 14, 2015, 10:17:57 AM

Previous topic - Next topic

Tursiops

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?

Tursiops

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?

tomaskir

#2
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;

Tursiops

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.  :-\

Victor Kirhenshtein

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