Add users to VMware Pulse by script

Posted by

The last couple of weeks I have done several workshops with our customers to get them educated on working with VMware Pulse IoT Center. For all the participants we have to create user accounts in the workshop environment and incase it is for a customer that does a PoC, most of these accounts need to be created in the trial environment as well.

To make my life easier I leverage the API capabilities that come with VMware Pulse IoT Center.

This article we will take you to the process to prepare a script to create multiple user accounts from an input file. I have already prepared a script, but there is still some input required to make it work. What you will learn is where to find the information that is required.

When you have followed through the steps of this article, at the end you will have a working script, the knowledge how the script works and how to adapt it to your needs.

Requirements and assumptions:
  • You need to have access to a VMware Pulse environment
  • You need to have permissions to create accounts
  • The VMware Pulse environment is configured so it can send email notifications.
  • httpie is installed on the system where you execute the script

Let’s get started. Step by step we will go over the script and use the Pulse console to access information.


Step 1 – Get the script and ready to edit it

Requirement of httpie:

# To install Httpie on an Debian based system:
sudo apt-get update && sudo apt-get install -y httpie

The script is available as part from my public Github repository:

# Download the respository to your computer:
# Change to the folder of the repository:
cd pulse-public

Open the createPulseUsers.sh with your favourite script editor.

Step 2 – Log in to your Pulse environment

We will need it to acquire some information for the script.

Login with your credentials

Step 3 – Collect the required details from your Pulse environment

The first section in the script is to set some variables that are required.

To assign the appropriate rights for the workshop we need to assign two groups. For that we need the IDs of the groups and with the following procedure:

Click on the Groups section under Identity and Access in the left column of the Pulse console:

You will then see all the groups that are available in your environment. We are interested in the IDs of these two groups shown here:

Click on the group to bring up the details. Copy the ID like shown here:
Note: The ID is in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Paste it to the variable as show here between the double-quotes:

Repeat for the System Administrators group:

Paste it to the variable as show here between the double-quotes:

Last thing to change in this section is the password you want to assign to the account upon creation.

Note: When the account is created, the user will receive an email that contains a link where the user can set his/her password.

Change the password to to a strong password with Capitals, numbers and special characters. Else the API will not accept the creation of the account.

Step 4 – User input part of the script

To make the script more dynamic (for system engineers like myself) that work with multiple environments, this part of the script asks for input during execution.

It will ask for:

  1. The pulse environment the script needs to be executed against.
  2. The username with the privileges to create accounts
  3. The password to that username

I have added the possibility to hard-code the variables in the script in case you do not need to access different environments frequently like I do.

Just comment out the interactive part and uncomment the variables you want to set.

Step 5 – Preparing communication with the Pulse API server

The next part of the script is to get the system ready to work with the Pulse API.

To work with the secured API server, we need two pieces:

  1. The version of the API. This defines what the API is capable of.
  2. We need to authenticate to the API to be able to modify later in the script.

This is what the two steps look like:

Step 6 – Prepare the input file

In the git repository you can also find an example input file:  users-list.

On Github the content looks like this:

It is important to note the following:

  1. This file may only contain lines with information to create the user accounts. Meaning: no empty lines after the last user.
  2. The column separator I use is the ;

If you want to change the separator character to another, you have to change the script to accept the other character.

I have specified it like this in the script:

Step 7 – Execution part of the script

Now that all is set, let’s have a look into the actual execution part of the script.

It consist of two parts. The first part is the function that is called for each line of input in the users-list file:

The first part of the function builds the information in a specific format so that the API server can consume the information that is presented to it.

The second part starts with http. The echoed information is piped into the tool httpie that is addressable by typing http.

It will use the information from the previous parts of the script defined by the variables, user input and the authentication BearerToken.

These both parts of the function are called by the loop that goes through the input file:

The first line defines the separator character used in the users-list file

The while loop iterates through each line of the input file and combines it with information provided to the variables.

The script reports when it is finished and will show the content of the log file. The log file will contain the IDs of the accounts that have been created. Good way to check if all went as expected.


Sources

Github: MTijbout/pulse-public: Repository to share scripts to the public
https://github.com/MTijbout/pulse-public

Github: pulse-public/createPulseUsers.sh
https://github.com/MTijbout/pulse-public/blob/master/createPulseUsers.sh

# To clone the scripts from Github:

Leave a Reply

Your email address will not be published. Required fields are marked *