Hints on NXSL for acquiring list of ReponsibleUsers' email address

Started by blazarov, March 05, 2021, 10:57:35 AM

Previous topic - Next topic

blazarov

Hello,

On yesterday Q&A Webex session i've got a great idea on how to solve a challenge that i have for years - have generic EPP & Email notification actions, while selecting email recipients based on user's email addresses and group membership.

Apparently this can be implemented elegantly using the new feature Responsible Users.

Users and group objects can be set as Responsible Users on nodes and containers.
Then NXSL have the necessary functionality to write a script that finds the responsible users for a given node and return a list of their email addresses.
Then this script can be run through a macro in email notification action recipient address field - hopefully with a $node parameter. So that this script always returns the full list of email recepients for this particular node.

All above combined together will deliver exactly what i need - if i understand it correctly.

I spent few hours trying to develop such a NXSL script, but failed miserably. Can someone help with some hints? I am sure this will be beneficial for the community, not just me.

Thanks!

Filipp Sudanov

Hi!

Here's an example of such script:
global emails = "";

sub parseGroupsOrUsers(arr)
{
  for (i : arr)
  {
    if (i->isGroup)
    {
      parseGroupsOrUsers(i->members);
    }
    else
    {
      if (i->email != "")
      {
        if (emails != "") emails = emails . "; ";
        emails = emails . i->email;
      }
    }
  }
}

parseGroupsOrUsers($node -> responsibleUsers);
println(emails);


In NetXMS users groups can contain not only users, but also user groups, hence the script is recursive.

Here's a not-yet-documented way to print all attributes and values of responsible users/gropus:
for (r : $node->responsibleUsers)
{
  for(a : r->__class->attributes)
     println(a . " = " . r->__get(a));
  println;
}