Graylog 3.2 create streams and dashboards via API

Hi,

Is there a way to create users and dashboards via API calls ? It would be nice to have a script
that can do that and i have tried to call the API for it.
Can’t really get it right so i wonder if someone here has some tips or examples ?

Check Graylog Rest API Browser, it’s a best way to try API calls:
https://docs.graylog.org/en/3.2/pages/configuration/rest_api.html?highlight=API#graylog-rest-api

Example of user creation:

curl -i -X POST -u user_token:token -H ‘Content-Type: application/json’ -H ‘X-Requested-By: cli’ ‘http://graylog.domain.com:9000/api/users’ -d @user.json

File user.json can contains information about user:

{
“username”: “data”,
“password”: “password”,
“email”: “data@graylog.com”,
“full_name”: “Data User”,
“permissions”: [
“metrics:read”
],
“timezone”: “UTC”
}

2 Likes

Thanks @shoothub

I didn’t mean to type users and streams. We have user management via LDAP. I meant to create dashboards and streams via API

If you use LDAP, you don’t need create users in graylog. Just use role map, ans set the rights for roles.

True, the question was about creating streams and dashboards.
I have figured out how to create streams via the API now. But the dashboards are tricky, there seems to be dashboards, legacy dashboards and views

ok, in this case I suggest use the browsers inspector view, and Graylog’s API browser, to check it.
If you do a manual dashboard creation, you can see in the inspection view the traffic.

In 3.2 there is dashboards, legacy dashboards and views.Via dashboards i can only get a list and via Legacy dashboards i can add but they don’t show up in the GUI (but i see them in the ‘get all dashboards’ in the Legacy section but not in the Views section). The dashboards are also in ‘Views’ which i guess is the 3.2 way of handling dashboards but the parameters needed are not very clear

You have also another option to create dashboard. First export dashboard to content pack, edit it and than import it through API:

Import content pack:

curl -i -X POST -u user_token:token -H ‘Content-Type: application/json’ -H ‘X-Requested-By: cli’ ‘http://graylog.domain.com:9000/api/system/content_packs’ -d @dashboard.json

Installation of content pack:

curl -i -X POST -u user_token:token -H ‘Content-Type: application/json’ -H ‘X-Requested-By: cli’ ‘http://graylog.domain.com:9000/api/system/content_packs/52436b10-26f9-445d-b3bb-6f1f3c1ceafb/1/installations’ -d ‘{“parameters”: {},“comment”: “”}’

1 Like

Thanks @shoothub but that way’s too complicated :slight_smile:

@jan Do you have any tips on how to add dashboards via REST API ?

Using the REST API : https://FQDN/api/api-browser/global/index.html#!/Views/create_post_0
i try this string :

{
“type”:“DASHBOARD”,
“title”:“JfATest”,
“summary”:“This dashboard is a test.”,
“description”:“Test dashboard”,
“search_id”:"",
“state”:"
{“900f81d4-9aa6-11ea-aa01-7365fc383f8c”: {
“selected_fields”:null,
“static_message_list_id”:null,
“titles”: {
“widget”:{ },
“tab”:{
“title”:“JfATest”
}
},
“widgets”:,
“widget_mapping”:{ },
“positions”:{ },
“formatting”:null,
“display_mode_settings”:{
“positions”:{ }
}
}
}
}

But i get this error :
{
“type”: “ApiError”,
“message”: “Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 7, column: 13] (through reference chain: org.graylog.plugins.views.search.views.$AutoValue_ViewDTO$Builder[“state”])”
}

Which character has to be escaped ?

The data you send isn’t a valid JSON. You need to remove the double quote after state:
“state”:
{“900f81d4-9aa6-11ea-aa01-7365fc383f8c”:

Hi,
Thanks for the info, removed it and got this :
“type”: “ApiError”,
“message”: “invalid hexadecimal representation of an ObjectId:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.