Graylog REST API – Creating User Token with Powershell

In order to access the Graylog REST api you need to do the folllowing:

  1. Create a new user within the User UI
  2. Temporarily assign the user the Admin role (Permission needed to create a token) , or use the REST API to assign the users:tokenlist, users:tokencreate, and users:tokenremovepermissions at this link.
  3. Using powershell, execute the following commands
#The exact username and password for the new user created
$username="myuser"
$password="mypassword"
$hash= [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($username):$($password)"));
#Define your server uri. Note: myuser is name of my new user and mytoken is the name of new token
$uri = 'https://yourgraylogserver.company.com:12900/api/users/myuser/tokens/mytoken?pretty=true'
#Create the token, and save the response into the $token variable
$token = Invoke-RestMethod -Uri $uri -Method POST -Headers @{"Content-Type"="application/json";"Authorization" = "Basic $hash"}
#Now output the token and save it
$token

3. Now that you have created the token, remove the Admin role from the the User UI for your api user.

 

Advertisements

About Parker Jardine

Manager of Systems Administration in the Information Technology Higher Education space. I enjoy biking, climbing, hockey, camping, mountaineering, hunting, paragliding, and just being outdoors. You can read my Make Magazine project articles about a diy solar panel and solar systems design in volumes 12 and 14.
This entry was posted in Graylog, Powershell and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s