Adding new users to Synthetics Permissions groups

Hello,

I’ve recently automated the user provisioning of user access to New Relic using the partnership API but since we use Synthetics Permissions, I couldn’t get the new users added to the “Users” group I have that provides Read access to all synthetics monitors using the same automation as that’s not available using the API.

I was however able to get this automated using a Synthetics Script itself. I thought there would be other folks facing this and would have to manually add new users to synthetics groups so I thought I’ll share the script.

The following code is for four accounts we have and can be modified to work for a different number. The script logs in using a New Relic user with synthetics manager permissions to adds all the users to a Users group so that they at least have read permissions to synthetics.

var username = '<Username for the New Relic account>';

var url_list = [
  {
    "url": "https://synthetics.newrelic.com/accounts/<account 1 ID>/permissions",
    "name": "Account 1"
  },
{
    "url": "https://synthetics.newrelic.com/accounts/<account 2 ID>/permissions",
    "name": "Account 2"
  },
  {
    "url": "https://synthetics.newrelic.com/accounts/<account 3 ID>/permissions",
    "name": "Account 3"
  },
  {
    "url": "https://synthetics.newrelic.com/accounts/<account 4 ID>/permissions",
    "name": "Account 4"
  }
 ];
 
 
var addAllUsers = function(table) {

	table.forEach(function(elem) {
		var URL = elem['url'];
		var AccountName = elem['name'];
		$browser.get(URL).then(function(){
			console.log("************************BEGIN**************************");
			console.log("Adding users for account:" + AccountName);
			console.log("New Relic URL successfully loaded");
			console.log("Waiting for the Login Screen");
			return $browser.waitForAndFindElement($driver.By.id("login_email"));
		}).then(function(el){
			console.log("Entering username");
			return el.sendKeys(username);
		}).then(function(){
			console.log("Waiting for passoword prompt");
			return $browser.waitForAndFindElement($driver.By.id("login_password"));
		}).then(function(el){
			console.log("Entering password");
			return el.sendKeys($secure.<Secure Credential Name>);
		}).then(function(){
			console.log("Waiting for sign in button")
			return $browser.waitForAndFindElement($driver.By.id("login_submit"));
		}).then(function(el){
			console.log("Clicking on Sign In");
			return el.click();
		}).then(function(){
			console.log("Waiting for page to load before clicking ")
			return $browser.waitForAndFindElement($driver.By.linkText("Permissions"));
		}).then(function(){
			console.log("Waiting for all the groups to load ")
      return $browser.waitForAndFindElement($driver.By.linkText("Users"));
		}).then(function(el){
			console.log("Clicking on Users Group");
			return el.click();
		}).then(function(){
			console.log("Waiting the user group to load")
			return $browser.waitForAndFindElement($driver.By.css(".userPane > div:nth-child(1) > div:nth-child(1) > a:nth-child(1) > span:nth-child(1) > svg:nth-child(1)"));
		}).then(function(el){
			console.log("Clicking on the add icon for the Users Group");
			return el.click();
		}).then(function(){
			console.log("Waiting for the Add all button to be available")
			return $browser.waitForAndFindElement($driver.By.css(".currentItems > div:nth-child(1) > div:nth-child(2) > a:nth-child(1)"));
		}).then(function(el){
			console.log("Clicking on the add all button for the Users Group");
			return el.click();
		}).then(function(){
      $browser.takeScreenshot();
			console.log("Waiting for the Add users button to be available")
			return $browser.waitForAndFindElement($driver.By.css("button.synthetics-button"));
		}).then(function(el){
			console.log("Clicking on the add users button for the Users Group");
			return el.click();
		}).then(function(){
			console.log("clicking on the user menu")
			return $browser.findElement($driver.By.css(".dropdown_trigger")).click();
		}).then(function(){
			console.log("clicking on the logout button menu")
			return $browser.findElement($driver.By.css(".logout > a:nth-child(1)")).click();
		});
	})
};

addAllUsers(url_list);

I would have preferred to do this via the API but that’s not possible right now.

Let me know if there’s a better way to get this done.

Thanks,
Karan

8 Likes

This is awesome, @karanpreet.singh - Thanks so much for sharing this great script. We love when people take scripting to the next level!

With the hope of simplifying things in the future, I have filed a feature request for you for a Permissions Groups API. Could you post a Feature Idea over on that side of the community? There we can add a poll for others to vote on.

My one curiosity in your script is that it looks like you’re adding all users to a group and I’m not certain why? Perhaps for script simplicity, but surely the benefit of Permissions is to limit access, rather than adding all users to a group.
Maybe you have more fine grained permissions in another group that you are manually managing, and this is just one group that everyone is put in, with higher access levels being manual. I’d love to learn a little more about your method here. :smiley:

1 Like

Hi Ryan,

You’re correct, this is just adding the new users to a group for all users that has only View permissions to the monitors.

We have other groups where we maintain the more fine grained permissions to edit the monitor/secure credentials/maintenance windows etc.

The requirement we have it to basically allow everyone who has access to the account to see the monitors but changing them is restricted to only a few users maintained in the other groups.

Since I automated the user access to the account, the users would often complain that they cannot see their monitors in Synthetics and I would have to go and manually add them to the “Users” group. This script solves that problem and automatically adds them with view permissions and if they require more, they reach out to us.

I will post a feature request for both the synthetics group permissions API and the add-on permissions to be added to the users using the API.

Thanks,
Karan

6 Likes

Excellent @karanpreet.singh this has inspired me to think about using Synthetics for many other workarounds :smiley:

2 Likes

This is very clever. We have a need for it as we add new synthetic monitors we will have to add each monitor to the various groups.

It looks like I can modify this and use a group of monitors as my input and not users.

Thanks!

2 Likes

Thanks, This helped me !

1 Like

Glad to know it’s still relevant after a year!

2 Likes