Graylog2 / graylog2-server

Free and open log management
https://www.graylog.org
Other
7.41k stars 1.07k forks source link

Export all stream, outputs and dashboards unsing curl with POST #3874

Closed mf-bmihaescu closed 7 years ago

mf-bmihaescu commented 7 years ago

I try to automate the process of exporting a Content Pack and I'm not able to select all of them . The script that I'm using is something like this:

!/bin/sh

GRAYLOG_URL="http://user:pass@server-name:12900" GRAYLOG_CONTENT='{ "name": "staging", "description": "descir", "category": "test", "inputs": [], "streams": [], "outputs": [], "dashboards": [], "grok_patterns": [] }'

curl -XPOST -H "Content-Type: application/json" ${GRAYLOG_URL}/system/bundles/export -d "${GRAYLOG_CONTENT}" > content.json

What should I do to export all stream and dashboards using something like this ?

Anyone can help ?

Thanks

gruselglatz commented 7 years ago

I've done a skipt for this and the essential part you are asking for is this:

# Content-Pack erstellen
input_ids=$(curl -s -u ${api_user}:${api_user_pw} -H application/json http://${HOST}:12900/system/inputs | jq '[.inputs[].id]')
output_ids=$(curl -s -u ${api_user}:${api_user_pw} -H application/json http://${HOST}:12900/system/outputs | jq '[.outputs[].id]')
stream_ids=$(curl -s -u ${api_user}:${api_user_pw} -H application/json http://${HOST}:12900/streams | jq '[.streams[].id]')
dashboard_ids=$(curl -s -u ${api_user}:${api_user_pw} -H application/json http://${HOST}:12900/dashboards | jq '[.dashboards[].id]')
grok_ids=$(curl -s -u ${api_user}:${api_user_pw} -H application/json http://${HOST}:12900/system/grok | jq '[.patterns[].id]')

http -j -a ${api_user}:${api_user_pw} POST http://${HOST}:12900/system/bundles/export  name='My-Content-Pack' description='Content-Pack für syslog.xyz.local' category='Backup' inputs:="${input_ids}" streams:="${stream_ids}" outputs:="${output_ids}" dashboards:="${dashboard_ids}" grok_patterns:="${grok_ids}" > ${backup_path}temp/contentpack_${_now}.json
jalogisch commented 7 years ago

thank you @gruselglatz for that contribution.

do you mind to contribute that to the documentation?

@mf-bmihaescu

We are using GitHub issues for tracking bugs in Graylog itself, but this doesn't look like one. Please post this issue to our discussion forum or join the #graylog channel on freenode IRC.

Thank you!

gruselglatz commented 7 years ago

@jalogisch It's a Bash Script to Backup as much as possible from the Graylog-Server in a convinient way. I will create a Pull-Request when i have some sparetime next week or so.

mf-bmihaescu commented 7 years ago

Thank you @gruselglatz very nice done.

@jalogisch No luck on the discussion forum. I opened there a topic and it just stays with no reply for days. Next time I will try IRC channel. You should also thinking of using slack. Thanks for support.