├── examples ├── v0.12 │ ├── plugin │ │ └── .gitkeep │ ├── versions.tf │ ├── .gitignore │ ├── grok_pattern.tf │ ├── terraform.tfvars │ ├── stream_output.tf │ ├── stream.tf │ ├── stream_rule.tf │ ├── user.tf │ ├── common.tf │ ├── README.md │ ├── alert_condition.tf │ ├── pipeline.tf │ ├── role.tf │ ├── input.tf │ ├── index_set.tf │ ├── output.tf │ └── docker-compose.yml └── v0.11 │ ├── .gitignore │ ├── stream.tf │ ├── stream_rule.tf │ ├── alarm_callback.tf │ ├── README.md │ ├── common.tf │ ├── alert_condition.tf │ ├── input.tf │ ├── pipeline.tf │ ├── role.tf │ ├── index_set.tf │ ├── docker-compose.yml │ └── extractor.tf ├── graylog ├── testdata │ ├── alert │ │ ├── alert.json │ │ └── alerts.json │ ├── stream │ │ ├── create_response.json │ │ ├── create_stream.json │ │ ├── create.tf │ │ ├── update.tf │ │ ├── stream.json │ │ └── updated_stream.json │ ├── dashboard │ │ ├── create_dashboard.json │ │ ├── create_dashboard_response.json │ │ ├── update_dashboard.json │ │ ├── dashboard.tf │ │ ├── update_dashboard.tf │ │ └── dashboard.json │ ├── stream_rule │ │ ├── create_response.json │ │ ├── create_stream_rule.json │ │ ├── create.tf │ │ ├── stream_rule.json │ │ ├── update.tf │ │ ├── updated_stream_rule.json │ │ └── stream_rules.json │ ├── index_set_stat │ │ └── index_set_stat.json │ ├── output │ │ ├── request_create_stream_outputs.json │ │ ├── stdout_output.json │ │ └── gelf_output.json │ ├── event_notification │ │ ├── request_create_event_notification.json │ │ └── response_create_event_notification.json │ ├── role │ │ ├── update_role.json │ │ ├── update_role.tf │ │ ├── role.json │ │ └── role.tf │ ├── index_set_stat.go │ ├── input │ │ ├── create_input.json │ │ ├── input.json │ │ └── inputs.json │ ├── stream_alarm_callback │ │ ├── http_stream_alarm_callback.json │ │ ├── slack_stream_alarm_callback.json │ │ └── email_stream_alarm_callback.json │ ├── create_stream_rule.go │ ├── create_stream.go │ ├── request_create_event_notification.go │ ├── create_input.go │ ├── response_create_event_notification.go │ ├── stream_alert_condition │ │ ├── message_count_stream_alert_condition.json │ │ └── stream_alert_conditions.json │ ├── stdout_output.go │ ├── update_input.go │ ├── role.go │ ├── ldap_setting │ │ ├── create.json │ │ └── create.tf │ ├── stream_rules.go │ ├── user │ │ └── user.json │ ├── http_stream_alarm_callback.go │ ├── ldap_setting.go │ ├── alert_condition │ │ └── alert_conditions.json │ ├── dashboard_widget │ │ └── stacked_chart │ │ │ ├── get.json │ │ │ ├── update.json │ │ │ ├── update.tf │ │ │ ├── create.json │ │ │ └── create.tf │ ├── input.go │ ├── inputs.go │ ├── user.go │ ├── stream_alert_conditions.go │ ├── index_set │ │ ├── update_index_set.json │ │ ├── create_index_set.json │ │ ├── create_index_set_response.json │ │ ├── update_response.json │ │ ├── index_set.json │ │ ├── update.tf │ │ └── create.tf │ ├── stream_rule.go │ ├── event_definition │ │ ├── create │ │ │ ├── request.json │ │ │ ├── response.json │ │ │ └── request.go │ │ ├── update │ │ │ ├── request.json │ │ │ ├── response.json │ │ │ ├── request.go │ │ │ └── response.go │ │ ├── event_definition.json │ │ └── get │ │ │ └── response.json │ ├── slack_stream_alarm_callback.go │ ├── create_index_set.go │ ├── email_stream_alarm_callback.go │ ├── dashboard_widget.go │ └── stream.go ├── client │ ├── doc.go │ ├── endpoint │ │ ├── doc.go │ │ ├── alarm_callback.go │ │ ├── alert_condition.go │ │ ├── alert.go │ │ ├── input.go │ │ ├── pipeline.go │ │ ├── pipeline_rule.go │ │ ├── event_definition.go │ │ ├── event_notification.go │ │ ├── stream_output.go │ │ ├── alarm_callback_test.go │ │ ├── alert_condition_test.go │ │ ├── output.go │ │ ├── grok_pattern.go │ │ ├── endpoint_test.go │ │ ├── extractor.go │ │ ├── input_static_fields.go │ │ ├── ldap_setting.go │ │ ├── stream_alarm_callback.go │ │ ├── stream_alert_condition.go │ │ ├── user_test.go │ │ ├── dashboard.go │ │ ├── input_test.go │ │ ├── alert_test.go │ │ ├── dashboard_test.go │ │ ├── user.go │ │ ├── role.go │ │ ├── stream_rule.go │ │ ├── stream.go │ │ ├── index_set.go │ │ ├── pipeline_connection.go │ │ ├── stream_rule_test.go │ │ ├── dashboard_widget.go │ │ ├── role_test.go │ │ ├── stream_test.go │ │ └── index_set_test.go │ ├── README.md │ ├── util_test.go │ ├── alarm_callback.go │ ├── alert_condition.go │ ├── error.go │ ├── index_set_stats.go │ ├── alert.go │ ├── ldap_setting.go │ ├── input_static_field.go │ ├── ldap_group.go │ ├── alarm_callback_test.go │ ├── alert_condition_test.go │ ├── stream_output.go │ ├── client_test.go │ ├── role_member.go │ ├── user_token.go │ ├── example_test.go │ ├── pipeline.go │ └── pipeline_rule.go ├── terraform │ ├── doc.go │ ├── config.go │ ├── resource_ldap_setting_test.go │ ├── resource_dashboard_test.go │ └── resource_stream_rule_test.go ├── graylog │ ├── doc.go │ ├── version.go │ ├── index_set_stats.go │ ├── user_token.go │ ├── pipeline_connection.go │ ├── role_test.go │ ├── stream_test.go │ ├── stream_rule_test.go │ ├── input_unknown_attrs.go │ ├── grok_pattern.go │ ├── input_test.go │ ├── pipeline_rule.go │ ├── user_test.go │ ├── output.go │ ├── event_notification.go │ ├── input_syslog_tcp.go │ ├── pipeline.go │ ├── input_fake_http_message.go │ ├── alert.go │ ├── input_aws_flow_logs.go │ ├── input_cef_udp.go │ ├── input_gelf_udp.go │ ├── input_json_path.go │ ├── input_raw_kafka.go │ ├── input_net_flow_udp.go │ ├── input_aws_logs.go │ ├── input_cef_kafka.go │ ├── input_gelf_kafka.go │ ├── input_data_test.go │ ├── input_cloud_trail.go │ ├── input_syslog_kafka.go │ ├── input_beats.go │ ├── input_raw_tcp.go │ ├── role.go │ ├── input_raw_amqp.go │ ├── input_gelf_tcp.go │ ├── ldap_setting.go │ ├── input_cef_tcp.go │ ├── input_syslog_udp.go │ ├── input_gelf_amqp.go │ └── input_gelf_http.go ├── util │ ├── decode.go │ └── decode_test.go └── testutil │ └── util.go ├── renovate.json ├── .editorconfig ├── githooks └── pre-commit.sh ├── .yamllint.yml ├── scripts ├── durl.sh ├── fmt.sh ├── codecov.sh ├── shellcheck.sh ├── yamllint.sh ├── githook.sh ├── install_local_terraform.sh ├── jsonlint.sh ├── test.sh ├── codecov_test.sh ├── coverage.sh └── release.sh ├── env.sh.tmpl ├── .gitignore ├── .git-rm-branch.yml ├── .goreleaser.yml ├── CONTRIBUTING.md ├── .github └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── .golangci.yml ├── cmd └── terraform-provider-graylog │ └── main.go ├── docs ├── resources │ ├── pipeline.md │ ├── pipeline_rule.md │ ├── stream_output.md │ ├── input_static_fields.md │ ├── dashboard.md │ ├── role.md │ ├── dashboard_widget_positions.md │ ├── stream.md │ ├── stream_rule.md │ ├── output.md │ ├── pipeline_connection.md │ ├── event_notification.md │ ├── user.md │ ├── grok_pattern.md │ ├── event_definition.md │ └── index_set.md └── data-sources │ ├── dashboard.md │ ├── stream.md │ └── index_set.md ├── go.mod ├── .durl.yml └── LICENSE /examples/v0.12/plugin/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /graylog/testdata/alert/alert.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /examples/v0.11/.gitignore: -------------------------------------------------------------------------------- 1 | terraform.tfstate 2 | terraform.tfstate.backup 3 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /graylog/testdata/alert/alerts.json: -------------------------------------------------------------------------------- 1 | { 2 | "total": 0, 3 | "alerts": [] 4 | } 5 | -------------------------------------------------------------------------------- /examples/v0.12/versions.tf: -------------------------------------------------------------------------------- 1 | 2 | terraform { 3 | required_version = ">= 0.12" 4 | } 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.sh] 2 | indent_style = space 3 | indent_size = 2 4 | space_redirects = true 5 | -------------------------------------------------------------------------------- /githooks/pre-commit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | 5 | cmdx test 6 | cmdx lint 7 | -------------------------------------------------------------------------------- /.yamllint.yml: -------------------------------------------------------------------------------- 1 | --- 2 | rules: 3 | indentation: 4 | spaces: 2 5 | indent-sequences: false 6 | -------------------------------------------------------------------------------- /graylog/client/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package client provides Graylog API client. 3 | */ 4 | package client 5 | -------------------------------------------------------------------------------- /graylog/testdata/stream/create_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "stream_id": "000000000000000000000003" 3 | } 4 | -------------------------------------------------------------------------------- /graylog/testdata/dashboard/create_dashboard.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "test", 3 | "description": "test" 4 | } 5 | -------------------------------------------------------------------------------- /graylog/testdata/stream_rule/create_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "streamrule_id": "5d84c1a92ab79c000d35d6d7" 3 | } 4 | -------------------------------------------------------------------------------- /graylog/client/endpoint/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package endpoint provides Graylog API endpoints. 3 | */ 4 | package endpoint 5 | -------------------------------------------------------------------------------- /graylog/testdata/dashboard/create_dashboard_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "dashboard_id": "5d84c1a92ab79c000d35d6c7" 3 | } 4 | -------------------------------------------------------------------------------- /examples/v0.12/.gitignore: -------------------------------------------------------------------------------- 1 | terraform.tfstate 2 | terraform.tfstate.backup 3 | plugin/* 4 | !plugin/.gitkeep 5 | *.backup 6 | -------------------------------------------------------------------------------- /examples/v0.12/grok_pattern.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_grok_pattern" "test" { 2 | name = "test" 3 | pattern = "test" 4 | } 5 | -------------------------------------------------------------------------------- /graylog/terraform/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package terraform provides the terraform provider for Graylog. 3 | */ 4 | package terraform 5 | -------------------------------------------------------------------------------- /graylog/testdata/index_set_stat/index_set_stat.json: -------------------------------------------------------------------------------- 1 | { 2 | "indices": 1, 3 | "documents": 0, 4 | "size": 1044 5 | } 6 | -------------------------------------------------------------------------------- /graylog/testdata/dashboard/update_dashboard.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "updated title", 3 | "description": "updated description" 4 | } 5 | -------------------------------------------------------------------------------- /graylog/testdata/dashboard/dashboard.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_dashboard" "foo" { 2 | title = "test" 3 | description = "test" 4 | } 5 | -------------------------------------------------------------------------------- /scripts/durl.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | set -o pipefail 5 | 6 | cd "$(dirname "$0")/.." 7 | 8 | git ls-files | durl check 9 | -------------------------------------------------------------------------------- /graylog/graylog/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package graylog provides Golang's structs which represents Graylog resource such as roles and users. 3 | */ 4 | package graylog 5 | -------------------------------------------------------------------------------- /graylog/testdata/output/request_create_stream_outputs.json: -------------------------------------------------------------------------------- 1 | { 2 | "outputs": [ 3 | "5de4fcf8a1de1800127e2fc4", 4 | "5de4fcf7a1de1800127e2fc0" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /env.sh.tmpl: -------------------------------------------------------------------------------- 1 | # shellcheck shell=sh 2 | export GRAYLOG_AUTH_NAME=admin 3 | export GRAYLOG_AUTH_PASSWORD=admin 4 | export GRAYLOG_WEB_ENDPOINT_URI=http://localhost:9000/api 5 | -------------------------------------------------------------------------------- /examples/v0.12/terraform.tfvars: -------------------------------------------------------------------------------- 1 | web_endpoint_uri = "http://127.0.0.1:9000/api" 2 | auth_name = "admin" 3 | auth_password = "admin" 4 | api_version = "v3" 5 | -------------------------------------------------------------------------------- /graylog/testdata/dashboard/update_dashboard.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_dashboard" "foo" { 2 | title = "updated title" 3 | description = "updated description" 4 | } 5 | -------------------------------------------------------------------------------- /scripts/fmt.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | set -o pipefail 5 | 6 | cd "$(dirname "$0")/.." 7 | 8 | git ls-files | grep -E ".*\.go$" | xargs gofmt -l -s -w 9 | -------------------------------------------------------------------------------- /graylog/client/README.md: -------------------------------------------------------------------------------- 1 | # go-graylog client 2 | 3 | [Graylog](https://www.graylog.org/) API client for Golang. 4 | 5 | See https://github.com/suzuki-shunsuke/go-graylog 6 | -------------------------------------------------------------------------------- /graylog/testdata/stream_rule/create_stream_rule.json: -------------------------------------------------------------------------------- 1 | { 2 | "field": "tag", 3 | "description": "test", 4 | "type": 1, 5 | "inverted": false, 6 | "value": "4" 7 | } 8 | -------------------------------------------------------------------------------- /scripts/codecov.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | set -o pipefail 5 | 6 | if [ -n "$CODECOV_TOKEN" ]; then 7 | bash <(curl -s https://codecov.io/bash) 8 | fi 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | coverage.txt 2 | coverage 3 | *.log 4 | graylog-mock-server 5 | dist 6 | env.sh 7 | .vendor-new 8 | 9 | .git-rm-branch.yml 10 | .terraform 11 | 12 | .idea/ 13 | -------------------------------------------------------------------------------- /scripts/shellcheck.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | set -o pipefail 5 | 6 | cd "$(dirname "$0")/.." 7 | 8 | git ls-files | grep -E ".*\.sh$" | xargs shellcheck env.sh.tmpl 9 | -------------------------------------------------------------------------------- /scripts/yamllint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | set -o pipefail 5 | 6 | cd "$(dirname "$0")/.." 7 | 8 | git ls-files | grep -E ".*\.ya?ml$" | xargs yamllint -c .yamllint.yml 9 | -------------------------------------------------------------------------------- /.git-rm-branch.yml: -------------------------------------------------------------------------------- 1 | local: 2 | protected: 3 | - master 4 | merged: 5 | - origin/master 6 | remote: 7 | origin: 8 | protected: 9 | - master 10 | merged: 11 | - origin/master 12 | -------------------------------------------------------------------------------- /graylog/graylog/version.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | // Don't edit this file. 4 | // This file is generated by the release command. 5 | 6 | // Version is the go-graylog's version. 7 | const Version = "12.0.0" 8 | -------------------------------------------------------------------------------- /examples/v0.12/stream_output.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_stream_output" "stdout" { 2 | stream_id = graylog_stream.test.id 3 | output_ids = [ 4 | graylog_output.stdout.id, 5 | graylog_output.gelf.id, 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /graylog/client/endpoint/alarm_callback.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // AlarmCallbacks returns AlarmCallbacks API's endpoint url. 4 | func (ep *Endpoints) AlarmCallbacks() string { 5 | return ep.alarmCallbacks 6 | } 7 | -------------------------------------------------------------------------------- /graylog/client/endpoint/alert_condition.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // AlertConditions returns an Alert Condition API's endpoint url. 4 | func (ep *Endpoints) AlertConditions() string { 5 | return ep.alertConditions 6 | } 7 | -------------------------------------------------------------------------------- /examples/v0.11/stream.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_stream" "test" { 2 | title = "test" 3 | index_set_id = "${graylog_index_set.test.id}" 4 | disabled = true 5 | matching_type = "AND" 6 | description = "test" 7 | } 8 | -------------------------------------------------------------------------------- /examples/v0.12/stream.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_stream" "test" { 2 | title = "test" 3 | index_set_id = data.graylog_index_set.default.id 4 | disabled = true 5 | matching_type = "AND" 6 | description = "test" 7 | } 8 | -------------------------------------------------------------------------------- /graylog/testdata/event_notification/request_create_event_notification.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "http", 3 | "description": "", 4 | "config": { 5 | "type": "http-notification-v1", 6 | "url": "http://example.com" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/v0.11/stream_rule.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_stream_rule" "test" { 2 | field = "tag" 3 | value = "4" 4 | stream_id = "${graylog_stream.test.id}" 5 | description = "test" 6 | type = 1 7 | inverted = false 8 | } 9 | -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | --- 2 | builds: 3 | - binary: terraform-provider-graylog 4 | main: ./cmd/terraform-provider-graylog/main.go 5 | env: 6 | - CGO_ENABLED=0 7 | goos: 8 | - windows 9 | - darwin 10 | - linux 11 | goarch: 12 | - amd64 13 | -------------------------------------------------------------------------------- /examples/v0.12/stream_rule.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_stream_rule" "test" { 2 | field = "tag" 3 | value = "4" 4 | stream_id = graylog_stream.test.id 5 | description = "test" 6 | type = 1 7 | inverted = false 8 | } 9 | 10 | -------------------------------------------------------------------------------- /graylog/testdata/stream_rule/create.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_stream_rule" "test" { 2 | field = "tag" 3 | value = "4" 4 | stream_id = "5d84c1a92ab79c000d35d6ca" 5 | description = "test" 6 | type = 1 7 | inverted = false 8 | } 9 | -------------------------------------------------------------------------------- /graylog/graylog/index_set_stats.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | // IndexSetStats represents a Graylog's Index Set Stats. 4 | type IndexSetStats struct { 5 | Indices int `json:"indices"` 6 | Documents int `json:"documents"` 7 | Size int `json:"size"` 8 | } 9 | -------------------------------------------------------------------------------- /graylog/testdata/stream_rule/stream_rule.json: -------------------------------------------------------------------------------- 1 | { 2 | "field": "tag", 3 | "stream_id": "5d84c1a92ab79c000d35d6ca", 4 | "description": "test", 5 | "id": "5d84c1a92ab79c000d35d6d7", 6 | "type": 1, 7 | "inverted": false, 8 | "value": "4" 9 | } 10 | -------------------------------------------------------------------------------- /graylog/testdata/stream_rule/update.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_stream_rule" "test" { 2 | field = "tag" 3 | value = "4" 4 | stream_id = "5d84c1a92ab79c000d35d6ca" 5 | description = "updated description" 6 | type = 1 7 | inverted = false 8 | } 9 | -------------------------------------------------------------------------------- /examples/v0.12/user.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_user" "test" { 2 | username = "test" 3 | email = "test@example.com" 4 | full_name = "test test" 5 | password = "password" 6 | roles = [ 7 | "Reader", 8 | graylog_role.read-stream-test.name, 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /graylog/graylog/user_token.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | type ( 4 | // UserToken is an access token for a user 5 | UserToken struct { 6 | Name string `json:"name"` 7 | Token string `json:"token"` 8 | LastAccess string `json:"last_access,omitempty"` 9 | } 10 | ) 11 | -------------------------------------------------------------------------------- /graylog/testdata/event_notification/response_create_event_notification.json: -------------------------------------------------------------------------------- 1 | { 2 | "id" : "5de5a365a1de18000cdfdf49", 3 | "title" : "http", 4 | "description" : "", 5 | "config" : { 6 | "type" : "http-notification-v1", 7 | "url" : "http://example.com" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /graylog/testdata/stream_rule/updated_stream_rule.json: -------------------------------------------------------------------------------- 1 | { 2 | "field": "tag", 3 | "stream_id": "5d84c1a92ab79c000d35d6ca", 4 | "description": "updated description", 5 | "id": "5d84c1a92ab79c000d35d6d7", 6 | "type": 1, 7 | "inverted": false, 8 | "value": "4" 9 | } 10 | -------------------------------------------------------------------------------- /graylog/testdata/stream/create_stream.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "All system events", 3 | "index_set_id": "5d84bfbe2ab79c000d35d4a9", 4 | "description": "Stream containing all system events created by Graylog", 5 | "matching_type": "AND", 6 | "remove_matches_from_default_stream": false 7 | } 8 | -------------------------------------------------------------------------------- /examples/v0.11/alarm_callback.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_alarm_callback" "test" { 2 | type = "org.graylog2.alarmcallbacks.HTTPAlarmCallback" 3 | stream_id = "${graylog_stream.test.id}" 4 | title = "test" 5 | 6 | http_configuration { 7 | url = "https://example.com" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /graylog/testdata/role/update_role.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "foo", 3 | "description": "updated description", 4 | "permissions": [ 5 | "extendedsearch:create", 6 | "extendedsearch:use", 7 | "view:edit", 8 | "view:read", 9 | "view:use" 10 | ], 11 | "read_only": false 12 | } 13 | -------------------------------------------------------------------------------- /graylog/client/util_test.go: -------------------------------------------------------------------------------- 1 | package client_test 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | func getTestHeader() http.Header { 8 | return http.Header{ 9 | "Content-Type": []string{"application/json"}, 10 | "X-Requested-By": []string{"go-graylog"}, 11 | "Authorization": nil, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /graylog/graylog/pipeline_connection.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | type ( 4 | // PipelineConnection is a pipeline connection. 5 | PipelineConnection struct { 6 | ID string `json:"id"` 7 | StreamID string `json:"stream_id"` 8 | PipelineIDs []string `json:"pipeline_ids"` 9 | } 10 | ) 11 | -------------------------------------------------------------------------------- /graylog/testdata/index_set_stat.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func IndexSetStats() graylog.IndexSetStats { 8 | return graylog.IndexSetStats{ 9 | Indices: 1, 10 | Documents: 0, 11 | Size: 1044, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ## Requirements 4 | 5 | * [Golang](https://golang.org/) 6 | * [golangci-lint](https://github.com/golangci/golangci-lint) 7 | * [cmdx](https://github.com/suzuki-shunsuke/cmdx) 8 | 9 | ```console 10 | $ cmdx i # setup git hooks 11 | $ cmdx -l # show task list 12 | ``` 13 | -------------------------------------------------------------------------------- /scripts/githook.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | set -o pipefail 5 | 6 | ee() { 7 | echo "+ $*" 8 | eval "$@" 9 | } 10 | 11 | cd "$(dirname "$0")/.." 12 | if [ ! -f .git/hooks/pre-commit ]; then 13 | ee ln -s ../../githooks/pre-commit.sh .git/hooks/pre-commit 14 | fi 15 | ee chmod a+x githooks/* 16 | -------------------------------------------------------------------------------- /graylog/client/endpoint/alert.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // Alert returns an Alert API's endpoint url. 4 | func (ep *Endpoints) Alert(id string) string { 5 | return ep.alerts + "/" + id 6 | } 7 | 8 | // Alerts returns Alerts API's endpoint url. 9 | func (ep *Endpoints) Alerts() string { 10 | return ep.alerts 11 | } 12 | -------------------------------------------------------------------------------- /graylog/client/endpoint/input.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // Inputs returns an Input API's endpoint url. 4 | func (ep *Endpoints) Inputs() string { 5 | return ep.inputs 6 | } 7 | 8 | // Input returns an Input API's endpoint url. 9 | func (ep *Endpoints) Input(id string) string { 10 | return ep.inputs + "/" + id 11 | } 12 | -------------------------------------------------------------------------------- /graylog/testdata/input/create_input.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "gelf udp 2", 3 | "type": "org.graylog2.inputs.gelf.udp.GELFUDPInput", 4 | "global": true, 5 | "configuration": { 6 | "decompress_size_limit": 8388608, 7 | "bind_address": "0.0.0.0", 8 | "port": 12201, 9 | "recv_buffer_size": 262144 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /scripts/install_local_terraform.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | set -o pipefail 5 | 6 | ee() { 7 | echo "+ $*" 8 | eval "$@" 9 | } 10 | 11 | cd "$(dirname "$0")/.." 12 | 13 | ee mkdir -p ~/.terraform.d/plugins 14 | ee go build -o ~/.terraform.d/plugins/terraform-provider-graylog ./cmd/terraform-provider-graylog 15 | -------------------------------------------------------------------------------- /graylog/testdata/role/update_role.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_role" "foo" { 2 | name = "foo" 3 | description = "updated description" 4 | 5 | permissions = [ 6 | "view:edit", 7 | "extendedsearch:use", 8 | "extendedsearch:create", 9 | "view:read", 10 | "view:use" 11 | ] 12 | 13 | read_only = false 14 | } 15 | -------------------------------------------------------------------------------- /scripts/jsonlint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | set -o pipefail 5 | 6 | ee() { 7 | echo "+ $*" 8 | eval "$@" 9 | } 10 | 11 | cd "$(dirname "$0")/.." 12 | 13 | while read -r f; do 14 | if ! jsonlint -q "$f" > /dev/null 2>&1; then 15 | ee jsonlint "$f" 16 | fi 17 | done < <(git ls-files | grep -E ".*\.json") 18 | -------------------------------------------------------------------------------- /graylog/client/endpoint/pipeline.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // Pipelines returns a Pipeline API's endpoint url. 4 | func (ep *Endpoints) Pipelines() string { 5 | return ep.pipelines 6 | } 7 | 8 | // Pipeline returns a Pipeline API's endpoint url. 9 | func (ep *Endpoints) Pipeline(id string) string { 10 | return ep.pipelines + "/" + id 11 | } 12 | -------------------------------------------------------------------------------- /graylog/terraform/config.go: -------------------------------------------------------------------------------- 1 | package terraform 2 | 3 | // Config represents terraform provider's configuration. 4 | type Config struct { 5 | Endpoint string 6 | AuthName string 7 | AuthPassword string 8 | XRequestedBy string 9 | APIVersion string 10 | } 11 | 12 | func (c *Config) loadAndValidate() error { 13 | return nil 14 | } 15 | -------------------------------------------------------------------------------- /graylog/testdata/output/stdout_output.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "5de32c3edf46c6001233473f", 3 | "title": "test", 4 | "type": "org.graylog2.outputs.LoggingOutput", 5 | "creator_user_id": "admin", 6 | "created_at": "2019-12-01T02:58:06.801Z", 7 | "configuration": { 8 | "prefix": "Writing message: " 9 | }, 10 | "content_pack": null 11 | } 12 | -------------------------------------------------------------------------------- /graylog/testdata/stream/create.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_stream" "test" { 2 | title = "test" 3 | description = "test" 4 | 5 | index_set_id = "5d84bfbe2ab79c000d35d4a9" 6 | disabled = false 7 | matching_type = "AND" 8 | remove_matches_from_default_stream = true 9 | } 10 | -------------------------------------------------------------------------------- /examples/v0.11/README.md: -------------------------------------------------------------------------------- 1 | # example 2 | 3 | ## Requirement 4 | 5 | * Terraform v0.11 6 | * terraform-provider-graylog 7 | * Docker Engine 8 | * Docker Compose 9 | 10 | ## Getting Started 11 | 12 | ```console 13 | # It takes some time to launch Graylog. 14 | $ docker-compose up -d 15 | $ terraform init 16 | $ terraform plan 17 | $ terraform apply 18 | ``` 19 | -------------------------------------------------------------------------------- /graylog/testdata/stream_rule/stream_rules.json: -------------------------------------------------------------------------------- 1 | { 2 | "total": 1, 3 | "stream_rules": [ 4 | { 5 | "field": "tag", 6 | "stream_id": "5d84c1a92ab79c000d35d6ca", 7 | "description": "test", 8 | "id": "5d84c1a92ab79c000d35d6d7", 9 | "type": 1, 10 | "inverted": false, 11 | "value": "4" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /graylog/testdata/role/role.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "foo", 3 | "description": "Allows reading and writing all views and extended searches (built-in)", 4 | "permissions": [ 5 | "extendedsearch:create", 6 | "extendedsearch:use", 7 | "view:create", 8 | "view:edit", 9 | "view:read", 10 | "view:use" 11 | ], 12 | "read_only": true 13 | } 14 | -------------------------------------------------------------------------------- /examples/v0.11/common.tf: -------------------------------------------------------------------------------- 1 | provider "graylog" { 2 | web_endpoint_uri = "${var.web_endpoint_uri}" 3 | auth_name = "${var.auth_name}" 4 | auth_password = "${var.auth_password}" 5 | api_version = "${var.api_version}" 6 | } 7 | 8 | variable "web_endpoint_uri" {} 9 | variable "auth_name" {} 10 | variable "auth_password" {} 11 | variable "api_version" {} 12 | -------------------------------------------------------------------------------- /graylog/testdata/stream/update.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_stream" "test" { 2 | title = "updated title" 3 | description = "updated description" 4 | 5 | index_set_id = "5d84bfbe2ab79c000d35d4a9" 6 | disabled = true 7 | matching_type = "AND" 8 | remove_matches_from_default_stream = true 9 | } 10 | -------------------------------------------------------------------------------- /scripts/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | set -o pipefail 5 | 6 | cd "$(dirname "$0")/.." 7 | 8 | if [ -f env.sh ]; then 9 | # shellcheck disable=SC1091 10 | source env.sh 11 | fi 12 | 13 | for d in $(go list ./... | grep -v terraform); do 14 | go test -race -covermode=atomic "$d" 15 | done 16 | go test -v ./graylog/terraform/... -covermode=atomic 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## API Endpoints 11 | 12 | _Please check API endpoints by [Graylog API browser](https://docs.graylog.org/en/3.1/pages/configuration/rest_api.html#using-the-api-browser) and tell us them exactly._ 13 | -------------------------------------------------------------------------------- /graylog/client/endpoint/pipeline_rule.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // PipelineRules returns a Pipeline Rules API's endpoint url. 4 | func (ep *Endpoints) PipelineRules() string { 5 | return ep.pipelineRules 6 | } 7 | 8 | // PipelineRule returns a Pipeline Rule API's endpoint url. 9 | func (ep *Endpoints) PipelineRule(id string) string { 10 | return ep.pipelineRules + "/" + id 11 | } 12 | -------------------------------------------------------------------------------- /graylog/graylog/role_test.go: -------------------------------------------------------------------------------- 1 | package graylog_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/testdata" 7 | ) 8 | 9 | func TestRoleNewUpdateParams(t *testing.T) { 10 | role := testdata.Role 11 | prms := role.NewUpdateParams() 12 | if role.Name != prms.Name { 13 | t.Fatalf(`prms.Name = "%s", wanted "%s"`, prms.Name, role.Name) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/v0.12/common.tf: -------------------------------------------------------------------------------- 1 | provider "graylog" { 2 | web_endpoint_uri = var.web_endpoint_uri 3 | auth_name = var.auth_name 4 | auth_password = var.auth_password 5 | api_version = var.api_version 6 | } 7 | 8 | variable "web_endpoint_uri" { 9 | } 10 | 11 | variable "auth_name" { 12 | } 13 | 14 | variable "auth_password" { 15 | } 16 | 17 | variable "api_version" { 18 | } 19 | 20 | -------------------------------------------------------------------------------- /graylog/graylog/stream_test.go: -------------------------------------------------------------------------------- 1 | package graylog_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/testdata" 7 | ) 8 | 9 | func TestStreamNewUpdateParams(t *testing.T) { 10 | stream := testdata.Stream() 11 | prms := stream.NewUpdateParams() 12 | if stream.ID != prms.ID { 13 | t.Fatalf(`prms.ID = "%s", wanted "%s"`, prms.ID, stream.ID) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /graylog/testdata/role/role.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_role" "foo" { 2 | name = "foo" 3 | description = "Allows reading and writing all views and extended searches (built-in)" 4 | 5 | permissions = [ 6 | "view:edit", 7 | "extendedsearch:use", 8 | "view:create", 9 | "extendedsearch:create", 10 | "view:read", 11 | "view:use" 12 | ] 13 | 14 | read_only = true 15 | } 16 | -------------------------------------------------------------------------------- /graylog/graylog/stream_rule_test.go: -------------------------------------------------------------------------------- 1 | package graylog_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/testdata" 7 | ) 8 | 9 | func TestStreamRuleNewUpdateParams(t *testing.T) { 10 | rule := testdata.StreamRule() 11 | prms := rule.NewUpdateParams() 12 | if rule.ID != prms.ID { 13 | t.Fatalf(`prms.ID = "%s", wanted "%s"`, prms.ID, rule.ID) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /graylog/testdata/stream_alarm_callback/http_stream_alarm_callback.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "5d84c1a92ab79c000d35d6d4", 3 | "type": "org.graylog2.alarmcallbacks.HTTPAlarmCallback", 4 | "configuration": { 5 | "url": "https://example.com" 6 | }, 7 | "stream_id": "5d84c1a92ab79c000d35d6ca", 8 | "title": "test", 9 | "created_at": "2019-09-20T12:10:17.792+0000", 10 | "creator_user_id": "admin" 11 | } 12 | -------------------------------------------------------------------------------- /graylog/client/endpoint/event_definition.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // EventDefinitions returns a EventDefinition API's endpoint url. 4 | func (ep *Endpoints) EventDefinitions() string { 5 | return ep.eventDefinitions 6 | } 7 | 8 | // EventDefinition returns a EventDefinition API's endpoint url. 9 | func (ep *Endpoints) EventDefinition(id string) string { 10 | return ep.eventDefinitions + "/" + id 11 | } 12 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | linters: 3 | enable: 4 | - deadcode 5 | - gofmt 6 | - goimports 7 | - golint 8 | - gosimple 9 | - govet 10 | - interfacer 11 | - maligned 12 | - misspell 13 | - nakedret 14 | - staticcheck 15 | - structcheck 16 | - unconvert 17 | # https://github.com/golangci/golangci-lint/issues/827 18 | # - unused 19 | - varcheck 20 | # - errcheck 21 | disable-all: true 22 | -------------------------------------------------------------------------------- /graylog/testdata/create_stream_rule.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func CreateStreamRule() graylog.StreamRule { 8 | return graylog.StreamRule{ 9 | StreamID: "5d84c1a92ab79c000d35d6ca", 10 | Field: "tag", 11 | Value: "4", 12 | Description: "test", 13 | Type: 1, 14 | Inverted: false, 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /cmd/terraform-provider-graylog/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/hashicorp/terraform/plugin" 5 | "github.com/hashicorp/terraform/terraform" 6 | 7 | graylog "github.com/suzuki-shunsuke/go-graylog/v11/graylog/terraform" 8 | ) 9 | 10 | func main() { 11 | plugin.Serve(&plugin.ServeOpts{ 12 | ProviderFunc: func() terraform.ResourceProvider { 13 | return graylog.Provider() 14 | }, 15 | }) 16 | } 17 | -------------------------------------------------------------------------------- /docs/resources/pipeline.md: -------------------------------------------------------------------------------- 1 | # graylog_pipeline 2 | 3 | * [Example](../../examples/v0.12/pipeline.tf) 4 | * [Source code](../../graylog/terraform/resource_pipeline.go) 5 | 6 | ## Argument Reference 7 | 8 | ### Required Argument 9 | 10 | name | type | etc 11 | --- | --- | --- 12 | source | string | 13 | 14 | ### Optional Argument 15 | 16 | name | default | type | etc 17 | --- | --- | --- | --- 18 | description | string | 19 | -------------------------------------------------------------------------------- /graylog/testdata/create_stream.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func CreateStream() graylog.Stream { 8 | return graylog.Stream{ 9 | Title: "All system events", 10 | IndexSetID: "5d84bfbe2ab79c000d35d4a9", 11 | Description: "Stream containing all system events created by Graylog", 12 | MatchingType: "AND", 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /docs/data-sources/dashboard.md: -------------------------------------------------------------------------------- 1 | # Data source graylog_dashboard 2 | 3 | * [Example](../../examples/v0.12/dashboard.tf) 4 | * [Source code](../../graylog/terraform/data_source_dashboard.go) 5 | 6 | ## Required Argument 7 | 8 | One of `dashboard_id` or `title` must be set. 9 | 10 | ## Attributes 11 | 12 | name | type | description 13 | --- | --- | --- 14 | title | string | 15 | dashboard_id | string | 16 | description | string | 17 | -------------------------------------------------------------------------------- /graylog/client/endpoint/event_notification.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // EventNotifications returns a EventNotification API's endpoint url. 4 | func (ep *Endpoints) EventNotifications() string { 5 | return ep.eventNotifications 6 | } 7 | 8 | // EventNotification returns a EventNotification API's endpoint url. 9 | func (ep *Endpoints) EventNotification(id string) string { 10 | return ep.eventNotifications + "/" + id 11 | } 12 | -------------------------------------------------------------------------------- /docs/resources/pipeline_rule.md: -------------------------------------------------------------------------------- 1 | # graylog_pipeline_rule 2 | 3 | * [Example](../../examples/v0.12/pipeline.tf) 4 | * [Source code](../../graylog/terraform/resource_pipeline_rule.go) 5 | 6 | ## Argument Reference 7 | 8 | ### Required Argument 9 | 10 | name | type | etc 11 | --- | --- | --- 12 | source | string | 13 | 14 | ### Optional Argument 15 | 16 | name | default | type | etc 17 | --- | --- | --- | --- 18 | description | string | 19 | -------------------------------------------------------------------------------- /graylog/client/endpoint/stream_output.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // Outputs returns a Output API's endpoint url. 4 | func (ep *Endpoints) StreamOutputs(streamID string) string { 5 | return ep.streams + "/" + streamID + "/outputs" 6 | } 7 | 8 | // Output returns a Output API's endpoint url. 9 | func (ep *Endpoints) StreamOutput(streamID, outputID string) string { 10 | return ep.streams + "/" + streamID + "/outputs/" + outputID 11 | } 12 | -------------------------------------------------------------------------------- /docs/resources/stream_output.md: -------------------------------------------------------------------------------- 1 | # graylog_stream_output 2 | 3 | * [Example](../../examples/v0.12/stream_output.tf) 4 | * [Source Code](../../graylog/terraform/resource_stream_output.go) 5 | 6 | ## Argument Reference 7 | 8 | ### Required Argument 9 | 10 | name | type | description 11 | --- | --- | --- 12 | stream_id | string | 13 | output_ids | []string | 14 | 15 | ### Optional Argument 16 | 17 | None. 18 | 19 | ## Attrs Reference 20 | 21 | None. 22 | -------------------------------------------------------------------------------- /graylog/testdata/request_create_event_notification.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func RequestCreateEventNotification() *graylog.EventNotification { 8 | return &graylog.EventNotification{ 9 | Title: "http", 10 | Description: "", 11 | Config: map[string]interface{}{ 12 | "type": "http-notification-v1", 13 | "url": "http://example.com", 14 | }, 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /graylog/client/endpoint/alarm_callback_test.go: -------------------------------------------------------------------------------- 1 | package endpoint_test 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | 9 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/client/endpoint" 10 | ) 11 | 12 | func TestEndpoints_AlarmCallbacks(t *testing.T) { 13 | ep, err := endpoint.NewEndpoints(apiURL) 14 | require.Nil(t, err) 15 | require.Equal(t, fmt.Sprintf("%s/alerts/callbacks", apiURL), ep.AlarmCallbacks()) 16 | } 17 | -------------------------------------------------------------------------------- /graylog/client/endpoint/alert_condition_test.go: -------------------------------------------------------------------------------- 1 | package endpoint_test 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | 9 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/client/endpoint" 10 | ) 11 | 12 | func TestEndpoints_AlertConditions(t *testing.T) { 13 | ep, err := endpoint.NewEndpoints(apiURL) 14 | require.Nil(t, err) 15 | require.Equal(t, fmt.Sprintf("%s/alerts/conditions", apiURL), ep.AlertConditions()) 16 | } 17 | -------------------------------------------------------------------------------- /graylog/testdata/create_input.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func CreateInput() graylog.Input { 8 | return graylog.Input{ 9 | Title: "gelf udp 2", 10 | Attrs: &graylog.InputGELFUDPAttrs{ 11 | DecompressSizeLimit: 8388608, 12 | BindAddress: "0.0.0.0", 13 | Port: 12201, 14 | RecvBufferSize: 262144, 15 | }, 16 | Global: true, 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /docs/resources/input_static_fields.md: -------------------------------------------------------------------------------- 1 | # graylog_input_static_fields 2 | 3 | * [Example](../../examples/v0.12/input.tf) 4 | * [Source code](../../graylog/terraform/resource_input_static_fields.go) 5 | 6 | ## Argument Reference 7 | 8 | ### Required Argument 9 | 10 | name | type | description 11 | --- | --- | --- 12 | input_id | string | 13 | 14 | ### Optional Argument 15 | 16 | name | default | type | description 17 | --- | --- | --- | --- 18 | fields | | map[string]string | 19 | -------------------------------------------------------------------------------- /graylog/client/endpoint/output.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // Outputs returns a Output API's endpoint url. 4 | func (ep *Endpoints) Outputs() string { 5 | return ep.outputs 6 | } 7 | 8 | // AvailableOutputs returns a Output API's endpoint url. 9 | func (ep *Endpoints) AvailableOutputs() string { 10 | return ep.availableOutputs 11 | } 12 | 13 | // Output returns a Output API's endpoint url. 14 | func (ep *Endpoints) Output(id string) string { 15 | return ep.outputs + "/" + id 16 | } 17 | -------------------------------------------------------------------------------- /examples/v0.11/alert_condition.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_alert_condition" "test" { 2 | type = "field_content_value" 3 | stream_id = "${graylog_stream.test.id}" 4 | in_grace = false 5 | title = "test" 6 | 7 | field_content_value_parameters { 8 | field = "message" 9 | value = "hoge hoge" 10 | backlog = 2 11 | repeat_notifications = false 12 | query = "*" 13 | grace = 0 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/v0.12/README.md: -------------------------------------------------------------------------------- 1 | # example 2 | 3 | ## Requirement 4 | 5 | * Terraform v0.12 6 | * terraform-provider-graylog 7 | * [graylog-plugin-slack](https://github.com/graylog-labs/graylog-plugin-slack) 8 | * install a jar file on the `plugin` directory 9 | * Docker Engine 10 | * Docker Compose 11 | 12 | ## Getting Started 13 | 14 | ```console 15 | # It takes some time to launch Graylog. 16 | $ docker-compose up -d 17 | $ terraform init 18 | $ terraform plan 19 | $ terraform apply 20 | ``` 21 | -------------------------------------------------------------------------------- /examples/v0.12/alert_condition.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_alert_condition" "test" { 2 | type = "field_content_value" 3 | stream_id = graylog_stream.test.id 4 | in_grace = false 5 | title = "test" 6 | 7 | field_content_value_parameters { 8 | field = "message" 9 | value = "hoge hoge" 10 | backlog = 2 11 | repeat_notifications = false 12 | query = "*" 13 | grace = 0 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /docs/resources/dashboard.md: -------------------------------------------------------------------------------- 1 | # graylog_dashboard 2 | 3 | * [Example](../../examples/v0.12/dashboard.tf) 4 | * [Source code](../../graylog/terraform/resource_dashboard.go) 5 | 6 | ## Argument Reference 7 | 8 | ### Required Argument 9 | 10 | name | type | description 11 | --- | --- | --- 12 | title | string | 13 | description | string | 14 | 15 | ### Optional Argument 16 | 17 | None 18 | 19 | ## Attrs Reference 20 | 21 | name | type | etc 22 | --- | --- | --- 23 | created_at | string | computed 24 | -------------------------------------------------------------------------------- /graylog/testdata/response_create_event_notification.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func EventNotification() *graylog.EventNotification { 8 | return &graylog.EventNotification{ 9 | ID: "5de5a365a1de18000cdfdf49", 10 | Title: "http", 11 | Description: "", 12 | Config: map[string]interface{}{ 13 | "type": "http-notification-v1", 14 | "url": "http://example.com", 15 | }, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/suzuki-shunsuke/go-graylog/v11 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/AlecAivazis/survey/v2 v2.1.1 7 | github.com/hashicorp/terraform v0.12.24 8 | github.com/mitchellh/mapstructure v1.3.3 9 | github.com/sanity-io/litter v1.3.0 10 | github.com/stretchr/testify v1.6.1 11 | github.com/suzuki-shunsuke/flute v0.7.0 12 | github.com/suzuki-shunsuke/go-jsoneq v0.1.2 13 | github.com/suzuki-shunsuke/go-ptr v1.0.0 14 | github.com/suzuki-shunsuke/go-set/v6 v6.0.1 15 | ) 16 | -------------------------------------------------------------------------------- /graylog/testdata/stream_alert_condition/message_count_stream_alert_condition.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "6d3aafd0-b277-4b55-bfd9-f4a000000000", 3 | "type": "message_count", 4 | "creator_user_id": "admin", 5 | "created_at": "2018-12-06T05:59:33.215+0000", 6 | "parameters": { 7 | "backlog": 0, 8 | "repeat_notifications": true, 9 | "query": "*", 10 | "grace": 5, 11 | "threshold_type": "MORE", 12 | "threshold": 400, 13 | "time": 5 14 | }, 15 | "in_grace": false, 16 | "title": "hello: too many log" 17 | } 18 | -------------------------------------------------------------------------------- /examples/v0.11/input.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_input" "gelf_udp" { 2 | title = "gelf udp 2" 3 | type = "org.graylog2.inputs.gelf.udp.GELFUDPInput" 4 | global = "true" 5 | 6 | attributes { 7 | bind_address = "0.0.0.0" 8 | port = 12201 9 | recv_buffer_size = 262144 10 | decompress_size_limit = 8388608 11 | } 12 | } 13 | 14 | resource "graylog_input_static_fields" "gelf_udp" { 15 | input_id = "${graylog_input.gelf_udp.id}" 16 | 17 | fields = { 18 | foo = "bar" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /graylog/client/endpoint/grok_pattern.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // GrokPatterns returns a GrokPattern API's endpoint url. 4 | func (ep *Endpoints) GrokPatterns() string { 5 | return ep.grokPatterns 6 | } 7 | 8 | // GrokPattern returns a GrokPattern API's endpoint url. 9 | func (ep *Endpoints) GrokPattern(id string) string { 10 | return ep.grokPatterns + "/" + id 11 | } 12 | 13 | // GrokPatternMembers returns /system/grok/test endpoint url. 14 | func (ep *Endpoints) GrokPatternTest() string { 15 | return ep.grokPatternsTest 16 | } 17 | -------------------------------------------------------------------------------- /graylog/testdata/stdout_output.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func StdoutOutput() *graylog.Output { 8 | return &graylog.Output{ 9 | ID: "5de32c3edf46c6001233473f", 10 | Title: "test", 11 | Type: "org.graylog2.outputs.LoggingOutput", 12 | CreatorUserID: "admin", 13 | CreatedAt: "2019-12-01T02:58:06.801Z", 14 | Configuration: map[string]interface{}{ 15 | "prefix": "Writing message: ", 16 | }, 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /graylog/client/alarm_callback.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 7 | ) 8 | 9 | // GetAlarmCallbacksContext returns all alarm callbacks. 10 | func (client *Client) GetAlarmCallbacks(ctx context.Context) ( 11 | []graylog.AlarmCallback, int, *ErrorInfo, error, 12 | ) { 13 | body := &graylog.AlarmCallbacksBody{} 14 | ei, err := client.callGet( 15 | ctx, client.Endpoints().AlarmCallbacks(), nil, body) 16 | return body.AlarmCallbacks, body.Total, ei, err 17 | } 18 | -------------------------------------------------------------------------------- /graylog/testdata/update_input.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | "github.com/suzuki-shunsuke/go-ptr" 6 | ) 7 | 8 | func UpdateInput() graylog.InputUpdateParams { 9 | return graylog.InputUpdateParams{ 10 | Title: "gelf udp 2", 11 | Attrs: &graylog.InputGELFUDPAttrs{ 12 | DecompressSizeLimit: 8388608, 13 | BindAddress: "0.0.0.0", 14 | Port: 12201, 15 | RecvBufferSize: 262144, 16 | }, 17 | Global: ptr.PBool(true), 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /graylog/client/endpoint/endpoint_test.go: -------------------------------------------------------------------------------- 1 | package endpoint_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/client/endpoint" 7 | ) 8 | 9 | const ( 10 | apiURL = "http://localhost:9000/api" 11 | ID = "5a8c086fc006c600013ca6f5" 12 | ) 13 | 14 | func TestNewEndpoints(t *testing.T) { 15 | if _, err := endpoint.NewEndpoints(""); err == nil { 16 | t.Fatal("invalid argument") 17 | } 18 | if _, err := endpoint.NewEndpoints("http://localhost:9000/api"); err != nil { 19 | t.Fatal(err) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /graylog/client/endpoint/extractor.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // Extractors returns Stream Rules API's endpoint url. 4 | func (ep *Endpoints) Extractors(inputID string) string { 5 | // /system/inputs/{inputID}/extractors 6 | return ep.inputs + "/" + inputID + "/extractors" 7 | } 8 | 9 | // Extractor returns a Stream Rule API's endpoint url. 10 | func (ep *Endpoints) Extractor(inputID, extractorID string) string { 11 | // /system/inputs/{inputID}/extractors/{extractorID} 12 | return ep.inputs + "/" + inputID + "/extractors/" + extractorID 13 | } 14 | -------------------------------------------------------------------------------- /graylog/graylog/input_unknown_attrs.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | import ( 4 | "encoding/json" 5 | ) 6 | 7 | // InputUnknownAttrs represents unknown type's Input Attrs. 8 | type InputUnknownAttrs struct { 9 | inputType string 10 | Data map[string]interface{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputUnknownAttrs) InputType() string { 15 | return attrs.inputType 16 | } 17 | 18 | func (attrs *InputUnknownAttrs) MarshalJSON() ([]byte, error) { 19 | return json.Marshal(attrs.Data) 20 | } 21 | -------------------------------------------------------------------------------- /.durl.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # configuration file of durl, which is a CLI tool to check whether dead urls are included in files. 3 | # https://github.com/suzuki-shunsuke/durl 4 | ignore_urls: 5 | - https://github.com/suzuki-shunsuke/go-graylog/releases/download/v${GO_GRAYLOG_VERSION}/terraform-provider-graylog_v${GO_GRAYLOG_VERSION}_${GO_GRAYLOG_ARCH}.gz 6 | ignore_hosts: 7 | - graylog.example.com 8 | - hooks.slack.com 9 | - api.hipchat.com 10 | - goreportcard.com 11 | http_method: head,get 12 | max_request_count: 10 13 | max_failed_request_count: 5 14 | http_request_timeout: 10 15 | -------------------------------------------------------------------------------- /docs/resources/role.md: -------------------------------------------------------------------------------- 1 | # graylog_role 2 | 3 | * [Example](../../examples/v0.12/role.tf) 4 | * [Source Code](../../graylog/terraform/resource_role.go) 5 | 6 | ## Argument Reference 7 | 8 | ### Required Argument 9 | 10 | name | type | description 11 | --- | --- | --- 12 | name | string | 13 | permissions | []string | 14 | 15 | ### Optional Argument 16 | 17 | name | default | type | description 18 | --- | --- | --- | --- 19 | description | "" | string | 20 | 21 | ## Attrs Reference 22 | 23 | name | type | etc 24 | --- | --- | --- 25 | read_only | bool | computed 26 | -------------------------------------------------------------------------------- /graylog/testdata/role.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-set/v6" 5 | 6 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 7 | ) 8 | 9 | var ( 10 | Role = graylog.Role{ 11 | Name: "foo", 12 | Description: "Allows reading and writing all views and extended searches (built-in)", 13 | Permissions: set.NewStrSet( 14 | "extendedsearch:create", 15 | "extendedsearch:use", 16 | "view:create", 17 | "view:edit", 18 | "view:read", 19 | "view:use", 20 | ), 21 | ReadOnly: true, 22 | } 23 | ) 24 | -------------------------------------------------------------------------------- /graylog/client/alert_condition.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 7 | ) 8 | 9 | // GetAlertConditions returns all alert conditions. 10 | func (client *Client) GetAlertConditions(ctx context.Context) ( 11 | []graylog.AlertCondition, int, *ErrorInfo, error, 12 | ) { 13 | conditions := &graylog.AlertConditionsBody{} 14 | ei, err := client.callGet( 15 | ctx, client.Endpoints().AlertConditions(), nil, conditions) 16 | return conditions.AlertConditions, conditions.Total, ei, err 17 | } 18 | -------------------------------------------------------------------------------- /graylog/testdata/input/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "gelf udp 2", 3 | "global": true, 4 | "name": "GELF UDP", 5 | "content_pack": null, 6 | "created_at": "2019-09-20T12:10:18.010Z", 7 | "type": "org.graylog2.inputs.gelf.udp.GELFUDPInput", 8 | "creator_user_id": "admin", 9 | "attributes": { 10 | "recv_buffer_size": 262144, 11 | "decompress_size_limit": 8388608, 12 | "bind_address": "0.0.0.0", 13 | "port": 12201 14 | }, 15 | "static_fields": { 16 | "foo": "bar" 17 | }, 18 | "node": null, 19 | "id": "5d84c1aa2ab79c000d35d6d9" 20 | } 21 | -------------------------------------------------------------------------------- /graylog/testdata/ldap_setting/create.json: -------------------------------------------------------------------------------- 1 | { 2 | "enabled": true, 3 | "system_username": "", 4 | "ldap_uri": "ldap://localhost:389", 5 | "use_start_tls": false, 6 | "trust_all_certificates": false, 7 | "active_directory": false, 8 | "search_base": "", 9 | "search_pattern": "", 10 | "display_name_attribute": "", 11 | "default_group": "", 12 | "group_mapping": null, 13 | "group_search_base": null, 14 | "group_id_attribute": null, 15 | "additional_default_groups": null, 16 | "group_search_pattern": null, 17 | "system_password_set": false 18 | } 19 | -------------------------------------------------------------------------------- /graylog/testdata/stream_rules.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func StreamRules() *graylog.StreamRulesBody { 8 | return &graylog.StreamRulesBody{ 9 | Total: 1, 10 | StreamRules: []graylog.StreamRule{ 11 | { 12 | ID: "5d84c1a92ab79c000d35d6d7", 13 | StreamID: "5d84c1a92ab79c000d35d6ca", 14 | Field: "tag", 15 | Value: "4", 16 | Description: "test", 17 | Type: 1, 18 | Inverted: false, 19 | }, 20 | }, 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /graylog/testdata/user/user.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "local:admin", 3 | "username": "admin", 4 | "email": "", 5 | "full_name": "Administrator", 6 | "permissions": [ 7 | "*" 8 | ], 9 | "preferences": { 10 | "updateUnfocussed": false, 11 | "enableSmartSearch": true 12 | }, 13 | "timezone": "UTC", 14 | "session_timeout_ms": 28800000, 15 | "external": false, 16 | "startpage": null, 17 | "roles": [ 18 | "Admin" 19 | ], 20 | "read_only": true, 21 | "session_active": false, 22 | "last_activity": null, 23 | "client_address": null 24 | } 25 | -------------------------------------------------------------------------------- /graylog/client/endpoint/input_static_fields.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // InputStaticFields returns the StaticFields API's endpoint url. 4 | func (ep *Endpoints) InputStaticFields(inputID string) string { 5 | // /system/inputs/{inputId}/staticfields 6 | return ep.inputs + "/" + inputID + "/staticfields" 7 | } 8 | 9 | // InputStaticField returns the StaticFields API's endpoint url. 10 | func (ep *Endpoints) InputStaticField(inputID, key string) string { 11 | // /system/inputs/{inputId}/staticfields/{key} 12 | return ep.inputs + "/" + inputID + "/staticfields/" + key 13 | } 14 | -------------------------------------------------------------------------------- /graylog/testdata/http_stream_alarm_callback.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func HTTPStreamAlarmCallback() graylog.AlarmCallback { 8 | return graylog.AlarmCallback{ 9 | ID: "5d84c1a92ab79c000d35d6d4", 10 | StreamID: "5d84c1a92ab79c000d35d6ca", 11 | Title: "test", 12 | CreatorUserID: "admin", 13 | CreatedAt: "2019-09-20T12:10:17.792+0000", 14 | Configuration: &graylog.HTTPAlarmCallbackConfiguration{ 15 | URL: "https://example.com", 16 | }, 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /graylog/testdata/stream/stream.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "000000000000000000000003", 3 | "creator_user_id": "admin", 4 | "outputs": [], 5 | "matching_type": "AND", 6 | "description": "test", 7 | "created_at": "2019-09-20T12:02:06.078Z", 8 | "disabled": false, 9 | "rules": [], 10 | "alert_conditions": [], 11 | "alert_receivers": { 12 | "emails": [], 13 | "users": [] 14 | }, 15 | "title": "test", 16 | "content_pack": null, 17 | "remove_matches_from_default_stream": true, 18 | "index_set_id": "5d84bfbe2ab79c000d35d4a9", 19 | "is_default": false 20 | } 21 | -------------------------------------------------------------------------------- /examples/v0.12/pipeline.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_pipeline" "test" { 2 | source = < coverage.txt 15 | 16 | for d in $(go list ./... | grep -v terraform); do 17 | echo "$d" 18 | ee go test -race -coverprofile=profile.out -covermode=atomic "$d" 19 | if [ -f profile.out ]; then 20 | cat profile.out >> coverage.txt 21 | rm profile.out 22 | fi 23 | done 24 | 25 | ee go test -v -race -coverprofile=profile.out -covermode=atomic ./graylog/terraform/... 26 | if [ -f profile.out ]; then 27 | cat profile.out >> coverage.txt 28 | rm profile.out 29 | fi 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Note 11 | 12 | * About the problem of Graylog, please ask to the Graylog community https://community.graylog.org/ 13 | 14 | ## Environment 15 | 16 | * Terraform version: 17 | * Graylog version: 18 | * terraform-provider-graylog or go-graylog version: 19 | * please use latest version 20 | * OS (client side): 21 | * ex. Windows 10, Mac OS Mojave 10.14.6, Ubuntu 16.04 22 | 23 | ## Overview 24 | 25 | ## Expected behavior 26 | 27 | ## Actual behavior 28 | 29 | ## How to reproduce 30 | 31 | * command and result (error message) 32 | * configuration file such as *.tf 33 | -------------------------------------------------------------------------------- /docs/resources/stream.md: -------------------------------------------------------------------------------- 1 | # graylog_stream 2 | 3 | * [Example](../../examples/v0.12/stream.tf) 4 | * [Source code](../../graylog/terraform/resource_stream.go) 5 | 6 | ## Argument Reference 7 | 8 | ### Required Argument 9 | 10 | name | type | description 11 | --- | --- | --- 12 | title | string | 13 | index_set_id | string | 14 | 15 | ### Optional Argument 16 | 17 | name | default | type | description 18 | --- | --- | --- | --- 19 | disabled | | bool | 20 | matching_type | | string | 21 | description | | string | 22 | remove_matches_from_default_stream | | bool | 23 | is_default | | bool | 24 | 25 | ## Attrs Reference 26 | 27 | name | type | etc 28 | --- | --- | --- 29 | creator_user_id | string | computed 30 | created_at | string | computed 31 | -------------------------------------------------------------------------------- /docs/resources/stream_rule.md: -------------------------------------------------------------------------------- 1 | # graylog_stream_rule 2 | 3 | * [Example](../../examples/v0.12/stream_rule.tf) 4 | * [Source code](../../graylog/terraform/resource_stream_rule.go) 5 | 6 | ## How to import 7 | 8 | Specify `/` as ID. 9 | 10 | ```console 11 | $ terraform import graylog_stream_rule.test 5bb1b4b5c9e77bbbbbbbbbbb/5c4acaefc9e77bbbbbbbbbbb 12 | ``` 13 | 14 | ## Argument Reference 15 | 16 | ### Required Argument 17 | 18 | name | type | description 19 | --- | --- | --- 20 | field | string | 21 | value | string | 22 | description | string | 23 | type | int | 24 | stream_id | string | 25 | 26 | ### Optional Argument 27 | 28 | name | default | type | description 29 | --- | --- | --- | --- 30 | inverted | | bool | 31 | -------------------------------------------------------------------------------- /examples/v0.11/role.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_role" "terraform" { 2 | name = "terraform" 3 | description = "terraform" 4 | 5 | permissions = [ 6 | "dashboards:*", 7 | "indexsets:*", 8 | "inputs:*", 9 | "roles:*", 10 | "streams:*", 11 | "users:*", 12 | "pipeline_rule:*", 13 | ] 14 | } 15 | 16 | resource "graylog_role" "terraform-read" { 17 | name = "terraform-read" 18 | description = "terraform-read" 19 | 20 | permissions = [ 21 | "dashboards:read", 22 | "indexsets:read", 23 | "inputs:read", 24 | "roles:read", 25 | "streams:read", 26 | "users:list", 27 | "users:edit", 28 | "users:tokenlist", 29 | "users:tokencreate", 30 | "pipeline_rule:read", 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /docs/resources/output.md: -------------------------------------------------------------------------------- 1 | # graylog_output 2 | 3 | * [Example](../../examples/v0.12/output.tf) 4 | * [Source Code](../../graylog/terraform/resource_output.go) 5 | 6 | ## Argument Reference 7 | 8 | ### Required Argument 9 | 10 | name | type | description 11 | --- | --- | --- 12 | title | string | 13 | type | string | 14 | configuration | string | JSON string 15 | 16 | `configuration` is a JSON string. 17 | The format of `configuration` depends on the output type. 18 | Please see the [example](../../examples/v0.12/output.tf). 19 | Using the [Graylog's API browser](https://docs.graylog.org/en/3.1/pages/configuration/rest_api.html) you can check the format of `configuration`. 20 | 21 | ### Optional Argument 22 | 23 | None. 24 | 25 | ## Attrs Reference 26 | 27 | None. 28 | -------------------------------------------------------------------------------- /graylog/client/endpoint/stream_rule.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // StreamRules returns Stream Rules API's endpoint url. 4 | func (ep *Endpoints) StreamRules(streamID string) string { 5 | // /streams/{streamid}/rules 6 | return ep.streams + "/" + streamID + "/rules" 7 | } 8 | 9 | // StreamRuleTypes returns Stream Rule Types API's endpoint url. 10 | func (ep *Endpoints) StreamRuleTypes(streamID string) string { 11 | // /streams/{streamid}/rules/types 12 | return ep.streams + "/" + streamID + "/rules/types" 13 | } 14 | 15 | // StreamRule returns a Stream Rule API's endpoint url. 16 | func (ep *Endpoints) StreamRule(streamID, streamRuleID string) string { 17 | // /streams/{streamid}/rules/{streamRuleID} 18 | return ep.streams + "/" + streamID + "/rules/" + streamRuleID 19 | } 20 | -------------------------------------------------------------------------------- /graylog/graylog/user_test.go: -------------------------------------------------------------------------------- 1 | package graylog_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 7 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/testdata" 8 | ) 9 | 10 | func TestUserNewUpdateParams(t *testing.T) { 11 | user := testdata.User() 12 | prms := user.NewUpdateParams() 13 | if user.Username != prms.Username { 14 | t.Fatalf(`prms.Username = "%s", wanted "%s"`, prms.Username, user.Username) 15 | } 16 | } 17 | 18 | func TestUserSetDefaultValues(t *testing.T) { 19 | user := &graylog.User{} 20 | user.SetDefaultValues() 21 | if user.SessionTimeoutMs == 0 { 22 | t.Fatal("user.SessionTimeoutMs must be set") 23 | } 24 | if user.Timezone == "" { 25 | t.Fatal("user.Timezone must be set") 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /graylog/graylog/output.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | type ( 4 | // Output represents an output. 5 | Output struct { 6 | ID string `json:"id,omitempty"` 7 | Title string `json:"title"` 8 | Type string `json:"type"` 9 | CreatorUserID string `json:"creator_user_id,omitempty"` 10 | CreatedAt string `json:"created_at,omitempty"` 11 | Configuration interface{} `json:"configuration"` 12 | // ContentPack interface{} `json:"content_pack"` 13 | } 14 | 15 | // OutputsBody represents Get Outputs API's response body. 16 | // Basically users don't use this struct, but this struct is public because some sub packages use this struct. 17 | OutputsBody struct { 18 | Outputs []Output `json:"outputs"` 19 | Total int `json:"total"` 20 | } 21 | ) 22 | -------------------------------------------------------------------------------- /docs/resources/pipeline_connection.md: -------------------------------------------------------------------------------- 1 | # graylog_pipeline_connection 2 | 3 | * [Example](../../examples/v0.12/pipeline.tf) 4 | * [Source code](../../graylog/terraform/resource_pipeline_connection.go) 5 | 6 | ## Import 7 | 8 | Specify the stream id as ID. 9 | 10 | ```console 11 | $ terraform import graylog_pipeline_connection.test 12 | ``` 13 | 14 | ## Argument Reference 15 | 16 | ### Required Argument 17 | 18 | name | type | etc 19 | --- | --- | --- 20 | stream_id | string | 21 | pipeline_ids | []string | 22 | 23 | ### Optional Argument 24 | 25 | None. 26 | 27 | ## Note 28 | 29 | This resource treats the stream id as the resource id, 30 | because there is no Graylog API to operate resource by connection pipeline id. 31 | So please make the stream id unique in all `graylog_pipeline_connection` resources. 32 | -------------------------------------------------------------------------------- /graylog/client/endpoint/stream.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // Streams returns a Stream API's endpoint url. 4 | func (ep *Endpoints) Streams() string { 5 | return ep.streams 6 | } 7 | 8 | // Stream returns a Stream API's endpoint url. 9 | func (ep *Endpoints) Stream(id string) string { 10 | return ep.streams + "/" + id 11 | } 12 | 13 | // PauseStream returns PauseStream API's endpoint url. 14 | func (ep *Endpoints) PauseStream(id string) string { 15 | return ep.streams + "/" + id + "/pause" 16 | } 17 | 18 | // ResumeStream returns ResumeStream API's endpoint url. 19 | func (ep *Endpoints) ResumeStream(id string) string { 20 | return ep.streams + "/" + id + "/resume" 21 | } 22 | 23 | // EnabledStreams returns GetEnabledStreams API's endpoint url. 24 | func (ep *Endpoints) EnabledStreams() string { 25 | return ep.enabledStreams 26 | } 27 | -------------------------------------------------------------------------------- /graylog/testdata/inputs.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func Inputs() *graylog.InputsBody { 8 | return &graylog.InputsBody{ 9 | Inputs: []graylog.Input{ 10 | { 11 | Title: "gelf udp 2", 12 | Attrs: &graylog.InputGELFUDPAttrs{ 13 | DecompressSizeLimit: 8388608, 14 | OverrideSource: "", 15 | BindAddress: "0.0.0.0", 16 | Port: 12201, 17 | RecvBufferSize: 262144, 18 | }, 19 | ID: "5d84c1aa2ab79c000d35d6d9", 20 | Global: true, 21 | Node: "", 22 | CreatedAt: "2019-09-20T12:10:18.010Z", 23 | CreatorUserID: "admin", 24 | StaticFields: map[string]string{ 25 | "foo": "bar", 26 | }, 27 | }, 28 | }, 29 | Total: 1, 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /graylog/testdata/user.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-set/v6" 5 | 6 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 7 | ) 8 | 9 | func User() *graylog.User { 10 | return &graylog.User{ 11 | Username: "admin", 12 | Email: "", 13 | FullName: "Administrator", 14 | Password: "", 15 | ID: "local:admin", 16 | Timezone: "UTC", 17 | LastActivity: "", 18 | ClientAddress: "", 19 | SessionTimeoutMs: 28800000, 20 | External: false, 21 | ReadOnly: true, 22 | SessionActive: false, 23 | Preferences: &graylog.Preferences{ 24 | UpdateUnfocussed: false, 25 | EnableSmartSearch: true, 26 | }, 27 | Startpage: nil, 28 | Roles: set.NewStrSet("Admin"), 29 | Permissions: set.NewStrSet("*"), 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /graylog/testdata/stream_alert_conditions.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func StreamAlertConditions() *graylog.AlertConditionsBody { 8 | return &graylog.AlertConditionsBody{ 9 | AlertConditions: []graylog.AlertCondition{ 10 | { 11 | ID: "56f9f507-601d-4a54-a2f4-4bda93bb8492", 12 | CreatorUserID: "admin", 13 | CreatedAt: "2019-09-20T12:10:17.792+0000", 14 | Title: "test", 15 | InGrace: false, 16 | Parameters: graylog.FieldContentAlertConditionParameters{ 17 | Grace: 0, 18 | Backlog: 2, 19 | RepeatNotifications: false, 20 | Field: "message", 21 | Value: "hoge hoge", 22 | Query: "*", 23 | }, 24 | }, 25 | }, 26 | Total: 1, 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /docs/resources/event_notification.md: -------------------------------------------------------------------------------- 1 | # graylog_event_notification 2 | 3 | * [Example](../../examples/v0.12/event_notification.tf) 4 | * [Source Code](../../graylog/terraform/resource_event_notification.go) 5 | 6 | ## Argument Reference 7 | 8 | ### Required Argument 9 | 10 | name | type | description 11 | --- | --- | --- 12 | title | string | 13 | config | string | JSON string 14 | 15 | `config` is a JSON string. 16 | The format of `config` depends on the Event Notification type. 17 | Please see the [example](../../graylog/terraform/resource_event_notification.go). 18 | Using the [Graylog's API browser](https://docs.graylog.org/en/3.1/pages/configuration/rest_api.html) you can check the format of `config`. 19 | 20 | ### Optional Argument 21 | 22 | name | default | type | description 23 | --- | --- | --- | --- 24 | description | ""| string | 25 | 26 | ## Attrs Reference 27 | 28 | None. 29 | -------------------------------------------------------------------------------- /graylog/client/endpoint/index_set.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // IndexSet returns an IndexSet API's endpoint url. 4 | func (ep *Endpoints) IndexSet(id string) string { 5 | return ep.indexSets + "/" + id 6 | } 7 | 8 | // IndexSets returns an IndexSet API's endpoint url. 9 | func (ep *Endpoints) IndexSets() string { 10 | return ep.indexSets 11 | } 12 | 13 | // SetDefaultIndexSet returns SetDefaultIndexSet API's endpoint url. 14 | func (ep *Endpoints) SetDefaultIndexSet(id string) string { 15 | return ep.indexSets + "/" + id + "/default" 16 | } 17 | 18 | // IndexSetsStats returns all IndexSets stats API's endpoint url. 19 | func (ep *Endpoints) IndexSetsStats() string { 20 | return ep.indexSetStats 21 | } 22 | 23 | // IndexSetStats returns an IndexSet stats API's endpoint url. 24 | func (ep *Endpoints) IndexSetStats(id string) string { 25 | return ep.indexSets + "/" + id + "/stats" 26 | } 27 | -------------------------------------------------------------------------------- /graylog/client/endpoint/pipeline_connection.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // PipelineConnections returns a Pipeline Connections API's endpoint url. 4 | func (ep *Endpoints) PipelineConnections() string { 5 | return ep.pipelineConnections 6 | } 7 | 8 | // PipelineConnectionsOfStream returns a Pipeline Connections for a given stream API's endpoint url. 9 | func (ep *Endpoints) PipelineConnectionsOfStream(id string) string { 10 | return ep.pipelineConnections + "/" + id 11 | } 12 | 13 | // ConnectStreamsToPipeline returns a connect streams to a pipeline API's endpoint url. 14 | func (ep *Endpoints) ConnectStreamsToPipeline() string { 15 | return ep.connectStreamsToPipeline 16 | } 17 | 18 | // ConnectPipelinesToStream returns a connect processing pipelines to a stream API's endpoint url. 19 | func (ep *Endpoints) ConnectPipelinesToStream() string { 20 | return ep.connectPipelinesToStream 21 | } 22 | -------------------------------------------------------------------------------- /docs/resources/user.md: -------------------------------------------------------------------------------- 1 | # graylog_user 2 | 3 | * [Example](../../examples/v0.12/user.tf) 4 | * [Source code](../../graylog/terraform/resource_user.go) 5 | 6 | ## Argument Reference 7 | 8 | ### Required Argument 9 | 10 | name | type | etc 11 | --- | --- | --- 12 | username | string | force_new 13 | email | string | 14 | full_name | string | 15 | 16 | ### Optional Argument 17 | 18 | name | default | type | etc 19 | --- | --- | --- | --- 20 | password | string | sensitive 21 | permissions | string set | computed 22 | roles | [] | string set | 23 | timezone | "" | string | computed 24 | session_timeout_ms | 3600000 | int | 25 | 26 | ## Attrs Reference 27 | 28 | name | type | etc 29 | --- | --- | --- 30 | user_id | string | computed 31 | external | bool | computed 32 | read_only | bool | computed 33 | client_address | | string | computed 34 | session_active | bool | computed 35 | last_activity | string | computed 36 | -------------------------------------------------------------------------------- /graylog/graylog/event_notification.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | type ( 4 | // EventNotification represents an output. 5 | EventNotification struct { 6 | ID string `json:"id,omitempty"` 7 | Title string `json:"title"` 8 | Description string `json:"description"` 9 | Config interface{} `json:"config"` 10 | } 11 | 12 | // EventNotificationsBody represents Get EventNotifications API's response body. 13 | EventNotificationsBody struct { 14 | EventNotifications []EventNotification `json:"notifications"` 15 | Total int `json:"total"` 16 | Page int `json:"page"` 17 | PerPage int `json:"per_page"` 18 | Count int `json:"count"` 19 | GrandTotal int `json:"grand_total"` 20 | Query string `json:"query"` 21 | } 22 | ) 23 | -------------------------------------------------------------------------------- /graylog/client/endpoint/stream_rule_test.go: -------------------------------------------------------------------------------- 1 | package endpoint_test 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | 9 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/client/endpoint" 10 | ) 11 | 12 | func TestEndpoints_StreamRules(t *testing.T) { 13 | ep, err := endpoint.NewEndpoints(apiURL) 14 | require.Nil(t, err) 15 | require.Equal(t, fmt.Sprintf("%s/streams/%s/rules", apiURL, ID), ep.StreamRules(ID)) 16 | } 17 | 18 | func TestEndpoints_StreamRuleTypes(t *testing.T) { 19 | ep, err := endpoint.NewEndpoints(apiURL) 20 | require.Nil(t, err) 21 | require.Equal(t, fmt.Sprintf("%s/streams/%s/rules/types", apiURL, ID), ep.StreamRuleTypes(ID)) 22 | } 23 | 24 | func TestEndpoints_StreamRule(t *testing.T) { 25 | ep, err := endpoint.NewEndpoints(apiURL) 26 | require.Nil(t, err) 27 | require.Equal(t, fmt.Sprintf("%s/streams/%s/rules/%s", apiURL, ID, ID), ep.StreamRule(ID, ID)) 28 | } 29 | -------------------------------------------------------------------------------- /graylog/graylog/input_syslog_tcp.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeSyslogTCP is one of input types. 5 | InputTypeSyslogTCP string = "org.graylog2.inputs.syslog.tcp.SyslogTCPInput" 6 | ) 7 | 8 | // NewInputSyslogTCPAttrs is the constructor of InputSyslogTCPAttrs. 9 | func NewInputSyslogTCPAttrs() InputAttrs { 10 | return &InputSyslogTCPAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputSyslogTCPAttrs) InputType() string { 15 | return InputTypeSyslogTCP 16 | } 17 | 18 | // InputSyslogTCPAttrs represents SyslogTCP Input's attributes. 19 | type InputSyslogTCPAttrs struct { 20 | Port int `json:"port,omitempty" v-create:"required" v-update:"required"` 21 | BindAddress string `json:"bind_address,omitempty" v-create:"required" v-update:"required"` 22 | RecvBufferSize int `json:"recv_buffer_size,omitempty" v-create:"required" v-update:"required"` 23 | } 24 | -------------------------------------------------------------------------------- /graylog/graylog/pipeline.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | type ( 4 | // Pipeline represents a Graylog's Pipeline. 5 | // https://docs.graylog.org/en/latest/pages/pipelines/pipelines.html 6 | Pipeline struct { 7 | // required 8 | Source string `json:"source,omitempty" v-create:"required" v-update:"required"` 9 | ID string `json:"id,omitempty" v-create:"isdefault" v-update:"required"` 10 | Title string `json:"title,omitempty"` 11 | Stages []PipelineStage `json:"stages"` 12 | 13 | Description string `json:"description,omitempty"` 14 | // CreatedAt string `json:"created_at,omitempty"` 15 | // ModifiedAt string `json:"modified_at,omitempty"` 16 | // Errors string `json:"errors"` 17 | } 18 | 19 | // PipelineStage is a stage of pipelines. 20 | PipelineStage struct { 21 | Stage int `json:"stage"` 22 | MatchAll bool `json:"match_all"` 23 | Rules []string `json:"rules"` 24 | } 25 | ) 26 | -------------------------------------------------------------------------------- /graylog/testdata/index_set/update_index_set.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "updated title", 3 | "index_prefix": "1234-test", 4 | "rotation_strategy_class": "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy", 5 | "rotation_strategy": { 6 | "type": "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig", 7 | "max_docs_per_index": 20000000 8 | }, 9 | "retention_strategy_class": "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategy", 10 | "retention_strategy": { 11 | "type": "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig", 12 | "max_number_of_indices": 20 13 | }, 14 | "index_analyzer": "standard", 15 | "shards": 4, 16 | "index_optimization_max_num_segments": 1, 17 | "field_type_refresh_interval": 5000, 18 | "description": "updated description", 19 | "writable": true, 20 | "index_optimization_disabled": false, 21 | "replicas": 0 22 | } 23 | -------------------------------------------------------------------------------- /scripts/coverage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | set -o pipefail 5 | 6 | ee() { 7 | echo "+ $*" 8 | eval "$@" 9 | } 10 | 11 | cd "$(dirname "$0")/.." 12 | 13 | if [ $# -eq 0 ]; then 14 | target="$(go list ./... | fzf)" 15 | if [ "$target" = "" ]; then 16 | exit 0 17 | fi 18 | target="${target#github.com/suzuki-shunsuke/go-graylog/v11/graylog}" 19 | elif [ $# -eq 1 ]; then 20 | target="$1" 21 | else 22 | echo "too many arguments are given: $*" >&2 23 | exit 1 24 | fi 25 | 26 | if [ ! -d "$target" ]; then 27 | echo "$target is not found" >&2 28 | exit 1 29 | fi 30 | 31 | ee mkdir -p ".coverage/$target" 32 | if [ "$target" = "terraform/graylog" ]; then 33 | ee go test -v "./$target" -coverprofile=".coverage/$target/coverage.txt" -covermode=atomic 34 | else 35 | ee go test "./$target" -coverprofile=".coverage/$target/coverage.txt" -covermode=atomic 36 | fi 37 | ee go tool cover -html=".coverage/$target/coverage.txt" 38 | -------------------------------------------------------------------------------- /graylog/testdata/stream_alarm_callback/slack_stream_alarm_callback.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "5d84c1a92ab79c000d35d6d5", 3 | "type": "org.graylog2.plugins.slack.callback.SlackAlarmCallback", 4 | "configuration": { 5 | "graylog2_url": "https://graylog.example.com", 6 | "custom_message": "${alert_condition.title}\\n\\n${foreach backlog message}\\n ${message.message}\\n${end}", 7 | "link_names": true, 8 | "notify_channel": false, 9 | "color": "#FF0000", 10 | "webhook_url": "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", 11 | "user_name": "Graylog", 12 | "backlog_items": 5, 13 | "channel": "#general" 14 | }, 15 | "stream_id": "5d84c1a92ab79c000d35d6ca", 16 | "title": "test", 17 | "created_at": "2019-09-20T12:10:17.793+0000", 18 | "creator_user_id": "admin" 19 | } 20 | -------------------------------------------------------------------------------- /graylog/testdata/dashboard_widget/stacked_chart/update.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "updated description", 3 | "type": "STACKED_CHART", 4 | "config": { 5 | "interval": "minute", 6 | "timerange": { 7 | "type": "relative", 8 | "range": 86400 9 | }, 10 | "renderer": "area", 11 | "interpolation": "linear", 12 | "stream_id": "000000000000000000000003", 13 | "series": [ 14 | { 15 | "query": "labels_app: nginx-ingress AND response:[200 TO 399]", 16 | "field": "response", 17 | "statistical_function": "count" 18 | }, 19 | { 20 | "query": "labels_app: nginx-ingress AND response:[500 TO 599]", 21 | "field": "response", 22 | "statistical_function": "count" 23 | }, 24 | { 25 | "query": "labels_app: nginx-ingress AND response:[400 TO 499]", 26 | "field": "response", 27 | "statistical_function": "count" 28 | } 29 | ] 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /graylog/testdata/stream_rule.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func StreamRule() *graylog.StreamRule { 8 | return &graylog.StreamRule{ 9 | ID: "5d84c1a92ab79c000d35d6d7", 10 | StreamID: "5d84c1a92ab79c000d35d6ca", 11 | Field: "tag", 12 | Value: "4", 13 | Description: "test", 14 | Type: 1, 15 | Inverted: false, 16 | } 17 | } 18 | 19 | func CreateStreamRuleReqBodyMap() map[string]interface{} { 20 | return map[string]interface{}{ 21 | "field": "tag", 22 | "value": "4", 23 | "description": "test", 24 | "type": 1, 25 | "inverted": false, 26 | } 27 | } 28 | 29 | func UpdateStreamRuleReqBodyMap() map[string]interface{} { 30 | return map[string]interface{}{ 31 | "field": "tag", 32 | "value": "4", 33 | "description": "updated description", 34 | "type": 1, 35 | "inverted": false, 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /examples/v0.12/role.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_role" "terraform" { 2 | name = "terraform" 3 | description = "terraform" 4 | 5 | permissions = [ 6 | "dashboards:*", 7 | "indexsets:*", 8 | "inputs:*", 9 | "roles:*", 10 | "streams:*", 11 | "users:*", 12 | "pipeline_rule:*", 13 | ] 14 | } 15 | 16 | resource "graylog_role" "terraform-read" { 17 | name = "terraform-read" 18 | description = "terraform-read" 19 | 20 | permissions = [ 21 | "dashboards:read", 22 | "indexsets:read", 23 | "inputs:read", 24 | "roles:read", 25 | "streams:read", 26 | "users:list", 27 | "users:edit", 28 | "users:tokenlist", 29 | "users:tokencreate", 30 | "pipeline_rule:read", 31 | ] 32 | } 33 | 34 | resource "graylog_role" "read-stream-test" { 35 | name = "read-stream-test" 36 | description = "read the stream 'test'" 37 | 38 | permissions = [ 39 | "streams:read:${graylog_stream.test.id}", 40 | ] 41 | } 42 | 43 | -------------------------------------------------------------------------------- /graylog/testdata/index_set/create_index_set.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "test", 3 | "index_prefix": "1234-test", 4 | "rotation_strategy_class": "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy", 5 | "rotation_strategy": { 6 | "type": "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig", 7 | "max_docs_per_index": 20000000 8 | }, 9 | "retention_strategy_class": "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategy", 10 | "retention_strategy": { 11 | "type": "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig", 12 | "max_number_of_indices": 20 13 | }, 14 | "creation_date": "2019-09-20T11:59:32.219Z", 15 | "index_analyzer": "standard", 16 | "shards": 4, 17 | "index_optimization_max_num_segments": 1, 18 | "field_type_refresh_interval": 5000, 19 | "description": "The Graylog default index set", 20 | "writable": true, 21 | "index_optimization_disabled": false, 22 | "default": false 23 | } 24 | -------------------------------------------------------------------------------- /graylog/client/index_set_stats.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | 7 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 8 | ) 9 | 10 | // GetIndexSetStats returns a given Index Set statistics. 11 | func (client *Client) GetIndexSetStats( 12 | ctx context.Context, id string, 13 | ) (*graylog.IndexSetStats, *ErrorInfo, error) { 14 | if id == "" { 15 | return nil, nil, errors.New("id is empty") 16 | } 17 | indexSetStats := &graylog.IndexSetStats{} 18 | ei, err := client.callGet( 19 | ctx, client.Endpoints().IndexSetStats(id), nil, indexSetStats) 20 | return indexSetStats, ei, err 21 | } 22 | 23 | // GetTotalIndexSetsStats returns stats of all Index Sets. 24 | func (client *Client) GetTotalIndexSetsStats( 25 | ctx context.Context, 26 | ) (*graylog.IndexSetStats, *ErrorInfo, error) { 27 | indexSetStats := &graylog.IndexSetStats{} 28 | ei, err := client.callGet( 29 | ctx, client.Endpoints().IndexSetsStats(), nil, indexSetStats) 30 | return indexSetStats, ei, err 31 | } 32 | -------------------------------------------------------------------------------- /graylog/graylog/input_fake_http_message.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeFakeHTTPMessage is one of input types. 5 | InputTypeFakeHTTPMessage string = "org.graylog2.inputs.random.FakeHttpMessageInput" 6 | ) 7 | 8 | // NewInputFakeHTTPMessageAttrs is the constructor of InputFakeHTTPMessageAttrs. 9 | func NewInputFakeHTTPMessageAttrs() InputAttrs { 10 | return &InputFakeHTTPMessageAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputFakeHTTPMessageAttrs) InputType() string { 15 | return InputTypeFakeHTTPMessage 16 | } 17 | 18 | // InputFakeHTTPMessageAttrs represents fake HTTP message Input's attributes. 19 | type InputFakeHTTPMessageAttrs struct { 20 | Sleep int `json:"sleep,omitempty"` 21 | SleepDeviation int `json:"sleep_deviation,omitempty"` 22 | Source string `json:"source,omitempty"` 23 | OverrideSource string `json:"override_source,omitempty"` 24 | ThrottlingAllowed bool `json:"throttling_allowed"` 25 | } 26 | -------------------------------------------------------------------------------- /graylog/terraform/resource_dashboard_test.go: -------------------------------------------------------------------------------- 1 | package terraform 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/testdata" 7 | ) 8 | 9 | func TestAccDashboard(t *testing.T) { 10 | setEnv() 11 | 12 | ds := testdata.Dashboard() 13 | 14 | tc := &testCase{ 15 | t: t, 16 | Name: "dashboard", 17 | CreatePath: "/api/dashboards", 18 | GetPath: "/api/dashboards/" + ds.ID, 19 | 20 | CreateReqBodyMap: map[string]interface{}{ 21 | "title": "test", 22 | "description": "test", 23 | }, 24 | UpdateReqBodyMap: map[string]interface{}{ 25 | "title": "updated title", 26 | "description": "updated description", 27 | }, 28 | CreatedDataPath: "dashboard/dashboard.json", 29 | UpdatedDataPath: "dashboard/updated_dashboard.json", 30 | CreateRespBodyPath: "dashboard/create_dashboard_response.json", 31 | CreateTFPath: "dashboard/dashboard.tf", 32 | UpdateTFPath: "dashboard/update_dashboard.tf", 33 | } 34 | tc.Test() 35 | } 36 | -------------------------------------------------------------------------------- /docs/resources/grok_pattern.md: -------------------------------------------------------------------------------- 1 | # graylog_grok_pattern 2 | 3 | * [Example](../../examples/v0.12/grok_pattern.tf) 4 | * [Source code](../../graylog/terraform/resource_grok_pattern.go) 5 | 6 | ```hcl 7 | resource "graylog_grok_pattern" "datestamp" { 8 | name = "DATESTAMP" 9 | pattern = "%%{DATE}[- ]%%{TIME}" 10 | } 11 | ``` 12 | 13 | Note that currently this resource doesn't support content packs. 14 | 15 | And if you use the sequence `%{`, you have to escape it. 16 | 17 | https://github.com/hashicorp/hcl2/blob/57bd5f374f26cdb7ae1b1c92fd6eb71335b9805b/hcl/hclsyntax/spec.md#template-literals 18 | 19 | > The interpolation and directive introductions are escaped by doubling their leading characters. 20 | > The ${ sequence is escaped as $${ and the %{ sequence is escaped as %%{. 21 | 22 | ## Argument Reference 23 | 24 | ### Required Argument 25 | 26 | name | type | description 27 | --- | --- | --- 28 | name | string | 29 | pattern | string | 30 | 31 | ### Optional Argument 32 | 33 | Nothing. 34 | 35 | ## Attrs Reference 36 | 37 | Nothing. 38 | -------------------------------------------------------------------------------- /graylog/testdata/index_set/create_index_set_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "5d84bf242ab79c000d691b7f", 3 | "title": "test", 4 | "index_prefix": "1234-test", 5 | "rotation_strategy_class": "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy", 6 | "rotation_strategy": { 7 | "type": "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig", 8 | "max_docs_per_index": 20000000 9 | }, 10 | "retention_strategy_class": "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategy", 11 | "retention_strategy": { 12 | "type": "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig", 13 | "max_number_of_indices": 20 14 | }, 15 | "creation_date": "2019-09-20T11:59:32.219Z", 16 | "index_analyzer": "standard", 17 | "shards": 4, 18 | "index_optimization_max_num_segments": 1, 19 | "field_type_refresh_interval": 5000, 20 | "description": "The Graylog default index set", 21 | "writable": true, 22 | "index_optimization_disabled": false, 23 | "default": false 24 | } 25 | -------------------------------------------------------------------------------- /graylog/client/endpoint/dashboard_widget.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | // DashboardWidgets returns a Dashboard Widget API's endpoint url. 4 | func (ep *Endpoints) DashboardWidgets(dashboardID string) string { 5 | return ep.dashboards + "/" + dashboardID + "/widgets" 6 | } 7 | 8 | // DashboardWidget returns a Dashboard Widget API's endpoint url. 9 | func (ep *Endpoints) DashboardWidget(dashboardID, widgetID string) string { 10 | return ep.dashboards + "/" + dashboardID + "/widgets/" + widgetID 11 | } 12 | 13 | // DashboardWidgetCacheTime returns a Dashboard Widget cache time API's endpoint url. 14 | func (ep *Endpoints) DashboardWidgetCacheTime(dashboardID, widgetID string) string { 15 | return ep.dashboards + "/" + dashboardID + "/widgets/" + widgetID + "/cachetime" 16 | } 17 | 18 | // DashboardWidgetDescription returns a Dashboard Widget description API's endpoint url. 19 | func (ep *Endpoints) DashboardWidgetDescription(dashboardID, widgetID string) string { 20 | return ep.dashboards + "/" + dashboardID + "/widgets/" + widgetID + "/description" 21 | } 22 | -------------------------------------------------------------------------------- /graylog/graylog/alert.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | type ( 4 | // Alert represents an Alert. 5 | // https://docs.graylog.org/en/latest/pages/streams/alerts.html 6 | Alert struct { 7 | ID string `json:"id"` 8 | Description string `json:"description"` 9 | ConditionID string `json:"condition_id"` 10 | StreamID string `json:"stream_id"` 11 | TriggeredAt string `json:"triggered_at"` 12 | ResolvedAt string `json:"resolved_at"` 13 | IsInterval bool `json:"is_interval"` 14 | ConditionParameters *AlertConditionParameters `json:"condition_parameters"` 15 | } 16 | 17 | // AlertsBody represents Get Alerts API's response body. 18 | // Basically users don't use this struct, but this struct is public because some sub packages use this struct. 19 | AlertsBody struct { 20 | Alerts []Alert `json:"alerts"` 21 | Total int `json:"total"` 22 | } 23 | ) 24 | -------------------------------------------------------------------------------- /graylog/graylog/input_aws_flow_logs.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeAWSFlowLogs is one of input types. 5 | InputTypeAWSFlowLogs string = "org.graylog.aws.inputs.flowlogs.FlowLogsInput" 6 | ) 7 | 8 | // NewInputAWSFlowLogsAttrs is the constructor of InputAWSFlowLogsAttrs. 9 | func NewInputAWSFlowLogsAttrs() InputAttrs { 10 | return &InputAWSFlowLogsAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputAWSFlowLogsAttrs) InputType() string { 15 | return InputTypeAWSFlowLogs 16 | } 17 | 18 | // InputAWSFlowLogsAttrs represents AWS flow logs Input's attributes. 19 | type InputAWSFlowLogsAttrs struct { 20 | AWSRegion string `json:"aws_region,omitempty"` 21 | AWSAssumeRoleArn string `json:"aws_assume_role_arn,omitempty"` 22 | AWSAccessKey string `json:"aws_access_key,omitempty"` 23 | AWSSecretKey string `json:"aws_secret_key,omitempty"` 24 | KinesisStreamName string `json:"kinesis_stream_name,omitempty"` 25 | ThrottlingAllowed bool `json:"throttling_allowed"` 26 | } 27 | -------------------------------------------------------------------------------- /graylog/testdata/index_set/update_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "5d84bf242ab79c000d691b7f", 3 | "title": "updated title", 4 | "index_prefix": "1234-test", 5 | "rotation_strategy_class": "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy", 6 | "rotation_strategy": { 7 | "type": "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig", 8 | "max_docs_per_index": 20000000 9 | }, 10 | "retention_strategy_class": "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategy", 11 | "retention_strategy": { 12 | "type": "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig", 13 | "max_number_of_indices": 20 14 | }, 15 | "creation_date": "2019-09-20T11:59:32.219Z", 16 | "index_analyzer": "standard", 17 | "shards": 4, 18 | "replicas": 0, 19 | "index_optimization_max_num_segments": 1, 20 | "field_type_refresh_interval": 5000, 21 | "description": "updated description", 22 | "writable": true, 23 | "index_optimization_disabled": false, 24 | "default": false 25 | } 26 | -------------------------------------------------------------------------------- /graylog/graylog/input_cef_udp.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeCEFUDP is one of input types. 5 | InputTypeCEFUDP string = "org.graylog.plugins.cef.input.CEFUDPInput" 6 | ) 7 | 8 | // NewInputCEFUDPAttrs is the constructor of InputCEFUDPAttrs. 9 | func NewInputCEFUDPAttrs() InputAttrs { 10 | return &InputCEFUDPAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputCEFUDPAttrs) InputType() string { 15 | return InputTypeCEFUDP 16 | } 17 | 18 | // InputCEFUDPAttrs represents CEF UDP Input's attributes. 19 | type InputCEFUDPAttrs struct { 20 | Locale string `json:"locale,omitempty"` 21 | UseFullNames bool `json:"use_full_names"` 22 | Timezone string `json:"timezone,omitempty"` 23 | BindAddress string `json:"bind_address,omitempty" v-create:"required" v-update:"required"` 24 | Port int `json:"port,omitempty" v-create:"required" v-update:"required"` 25 | RecvBufferSize int `json:"recv_buffer_size,omitempty" v-create:"required" v-update:"required"` 26 | } 27 | -------------------------------------------------------------------------------- /graylog/testdata/index_set/index_set.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "5d84bf242ab79c000d691b7f", 3 | "title": "Default index set", 4 | "description": "The Graylog default index set", 5 | "index_prefix": "graylog", 6 | "shards": 4, 7 | "replicas": 0, 8 | "rotation_strategy_class": "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy", 9 | "rotation_strategy": { 10 | "type": "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig", 11 | "max_docs_per_index": 20000000 12 | }, 13 | "retention_strategy_class": "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategy", 14 | "retention_strategy": { 15 | "type": "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig", 16 | "max_number_of_indices": 20 17 | }, 18 | "creation_date": "2019-09-20T11:59:32.219Z", 19 | "index_analyzer": "standard", 20 | "index_optimization_max_num_segments": 1, 21 | "index_optimization_disabled": false, 22 | "field_type_refresh_interval": 5000, 23 | "writable": true, 24 | "default": true 25 | } 26 | -------------------------------------------------------------------------------- /graylog/graylog/input_gelf_udp.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeGELFUDP is one of input types. 5 | InputTypeGELFUDP string = "org.graylog2.inputs.gelf.udp.GELFUDPInput" 6 | ) 7 | 8 | // NewInputGELFUDPAttrs is the constructor of InputGELFUDPAttrs. 9 | func NewInputGELFUDPAttrs() InputAttrs { 10 | return &InputGELFUDPAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputGELFUDPAttrs) InputType() string { 15 | return InputTypeGELFUDP 16 | } 17 | 18 | // InputGELFUDPAttrs represents GELF UDP Input's attributes. 19 | type InputGELFUDPAttrs struct { 20 | DecompressSizeLimit int `json:"decompress_size_limit,omitempty"` 21 | OverrideSource string `json:"override_source,omitempty"` 22 | BindAddress string `json:"bind_address,omitempty" v-create:"required" v-update:"required"` 23 | Port int `json:"port,omitempty" v-create:"required" v-update:"required"` 24 | RecvBufferSize int `json:"recv_buffer_size,omitempty" v-create:"required" v-update:"required"` 25 | } 26 | -------------------------------------------------------------------------------- /graylog/testdata/dashboard_widget/stacked_chart/update.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_dashboard_widget" "http_response_codes" { 2 | dashboard_id = "5de4fcf7a1de1800127e2fbc" 3 | description = "updated description" 4 | type = "STACKED_CHART" 5 | json_configuration = <\\n${end}\\n", 9 | "sender": "graylog@example.org", 10 | "subject": "Graylog alert for stream: ${stream.title}: ${check_result.resultDescription}", 11 | "email_receivers": [ 12 | "graylog@example.com" 13 | ] 14 | }, 15 | "stream_id": "5d84c1a92ab79c000d35d6ca", 16 | "title": "test", 17 | "created_at": "2019-09-20T12:47:59.170+0000", 18 | "creator_user_id": "admin" 19 | } 20 | -------------------------------------------------------------------------------- /docs/data-sources/index_set.md: -------------------------------------------------------------------------------- 1 | # Data source graylog_index_set 2 | 3 | * [Source code](../../graylog/terraform/data_source_index_set.go) 4 | 5 | ```hcl 6 | data "graylog_index_set" "test-index-set" { 7 | index_prefix = "terraform-test" 8 | } 9 | ``` 10 | 11 | ## Required Argument 12 | 13 | One of `index_set_id` or `title` or `index_prefix` must be set. 14 | 15 | ## Attributes 16 | 17 | name | type | description 18 | --- | --- | --- 19 | title | string | 20 | index_prefix | string | `force new` 21 | rotation_strategy_class | string | 22 | rotation_strategy | | 23 | rotation_strategy.type | string | 24 | rotation_strategy.max_docs_per_index | int | 25 | rotation_strategy.max_size | int | 26 | rotation_strategy.rotation_period | string | 27 | retention_strategy_class | string | 28 | retention_strategy | | 29 | retention_strategy.type | string | 30 | retention_strategy.max_number_of_indices | int | 31 | index_analyzer | string | 32 | shards | int | 33 | index_optimization_max_num_segments | int | 34 | description | string | 35 | replicas | int | 36 | index_optimization_disabled | bool | 37 | writable | bool | 38 | default | bool | 39 | creation_date | string | 40 | id | string | 41 | -------------------------------------------------------------------------------- /graylog/graylog/input_aws_logs.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeAWSCloudWatchLogs is one of input types. 5 | InputTypeAWSCloudWatchLogs string = "org.graylog.aws.inputs.cloudwatch.CloudWatchLogsInput" 6 | ) 7 | 8 | // NewInputAWSCloudWatchLogsAttrs is the constructor of InputAWSCloudWatchLogsAttrs. 9 | func NewInputAWSCloudWatchLogsAttrs() InputAttrs { 10 | return &InputAWSCloudWatchLogsAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputAWSCloudWatchLogsAttrs) InputType() string { 15 | return InputTypeAWSCloudWatchLogs 16 | } 17 | 18 | // InputAWSCloudWatchLogsAttrs represents AWS logs Input's attributes. 19 | type InputAWSCloudWatchLogsAttrs struct { 20 | AWSRegion string `json:"aws_region,omitempty"` 21 | AWSAssumeRoleArn string `json:"aws_assume_role_arn,omitempty"` 22 | AWSAccessKey string `json:"aws_access_key,omitempty"` 23 | AWSSecretKey string `json:"aws_secret_key,omitempty"` 24 | KinesisStreamName string `json:"kinesis_stream_name,omitempty"` 25 | ThrottlingAllowed bool `json:"throttling_allowed"` 26 | OverrideSource string `json:"override_source,omitempty"` 27 | } 28 | -------------------------------------------------------------------------------- /graylog/testdata/event_definition/create/request.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "new-event-definition", 3 | "description": "", 4 | "priority": 2, 5 | "alert": true, 6 | "config": { 7 | "type": "aggregation-v1", 8 | "query": "test", 9 | "streams": [ 10 | "000000000000000000000001" 11 | ], 12 | "group_by": [], 13 | "series": [], 14 | "conditions": { 15 | "expression": null 16 | }, 17 | "search_within_ms": 60000, 18 | "execute_every_ms": 60000 19 | }, 20 | "field_spec": { 21 | "test": { 22 | "data_type": "string", 23 | "providers": [ 24 | { 25 | "type": "template-v1", 26 | "template": "test", 27 | "require_values": false 28 | } 29 | ] 30 | } 31 | }, 32 | "key_spec": ["test"], 33 | "notification_settings": { 34 | "grace_period_ms": 0, 35 | "backlog_size": 0 36 | }, 37 | "notifications": [ 38 | { 39 | "notification_id": "5de5a365a1de18000cdfdf49" 40 | } 41 | ], 42 | "storage": [ 43 | { 44 | "type": "persist-to-streams-v1", 45 | "streams": [ 46 | "000000000000000000000002" 47 | ] 48 | } 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /graylog/testdata/index_set/update.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_index_set" "test" { 2 | title = "updated title" 3 | description = "updated description" 4 | 5 | index_prefix = "1234-test" 6 | rotation_strategy_class = "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy" 7 | retention_strategy_class = "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategy" 8 | index_analyzer = "standard" 9 | index_optimization_disabled = false 10 | writable = true 11 | shards = 4 12 | replicas = 0 13 | index_optimization_max_num_segments = 1 14 | field_type_refresh_interval = 5000 15 | 16 | retention_strategy { 17 | max_number_of_indices = 20 18 | type = "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig" 19 | } 20 | 21 | rotation_strategy { 22 | max_docs_per_index = 20000000 23 | max_size = 0 24 | type = "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /docs/resources/event_definition.md: -------------------------------------------------------------------------------- 1 | # graylog_event_definition 2 | 3 | * [Example](../../examples/v0.12/event_definition.tf) 4 | * [Source Code](../../graylog/terraform/resource_event_definition.go) 5 | 6 | ## Argument Reference 7 | 8 | ### Required Argument 9 | 10 | name | type | description 11 | --- | --- | --- 12 | title | string | 13 | config | string | JSON string 14 | notifications[].notification_id | string | 15 | priority | int | 1 (Low), 2 (Normal), 3 (High) 16 | notification_settings | {} | 17 | 18 | `config` is a JSON string. 19 | The format of `config` depends on the Event Notification type. 20 | Please see the [example](../../examples/v0.12/event_definition.tf). 21 | Using the [Graylog's API browser](https://docs.graylog.org/en/3.1/pages/configuration/rest_api.html) you can check the format of `config`. 22 | 23 | ### Optional Argument 24 | 25 | name | default | type | description 26 | --- | --- | --- | --- 27 | description | "" | string | 28 | alert | false | bool | 29 | field_spec | "" | string | JSON string 30 | notification_settings.grace_period_ms | 0 | int | 31 | notification_settings.backlog_size | 0 | int | 32 | notifications | [] | []object | 33 | 34 | ## Attrs Reference 35 | 36 | None. 37 | -------------------------------------------------------------------------------- /graylog/testdata/slack_stream_alarm_callback.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func SlackStreamAlarmCallback() graylog.AlarmCallback { 8 | return graylog.AlarmCallback{ 9 | ID: "5d84c1a92ab79c000d35d6d5", 10 | StreamID: "5d84c1a92ab79c000d35d6ca", 11 | Title: "test", 12 | CreatorUserID: "admin", 13 | CreatedAt: "2019-09-20T12:10:17.793+0000", 14 | Configuration: &graylog.SlackAlarmCallbackConfiguration{ 15 | Color: "#FF0000", 16 | WebhookURL: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", 17 | Channel: "#general", 18 | IconURL: "", 19 | Graylog2URL: "https://graylog.example.com", 20 | IconEmoji: "", 21 | UserName: "Graylog", 22 | ProxyAddress: "", 23 | CustomMessage: "${alert_condition.title}\\n\\n${foreach backlog message}\\n ${message.message}\\n${end}", 24 | BacklogItems: 5, 25 | LinkNames: true, 26 | NotifyChannel: false, 27 | }, 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /graylog/testdata/event_definition/update/request.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "5de5aac1a1de18000cdfe2b3", 3 | "title": "new-event-definition", 4 | "description": "", 5 | "priority": 2, 6 | "alert": true, 7 | "config": { 8 | "type": "aggregation-v1", 9 | "query": "test", 10 | "streams": [ 11 | "000000000000000000000001" 12 | ], 13 | "group_by": [], 14 | "series": [], 15 | "conditions": { 16 | "expression": null 17 | }, 18 | "search_within_ms": 60000, 19 | "execute_every_ms": 60000 20 | }, 21 | "field_spec": { 22 | "test": { 23 | "data_type": "string", 24 | "providers": [ 25 | { 26 | "type": "template-v1", 27 | "template": "test", 28 | "require_values": false 29 | } 30 | ] 31 | } 32 | }, 33 | "key_spec": [], 34 | "notification_settings": { 35 | "grace_period_ms": 0, 36 | "backlog_size": 0 37 | }, 38 | "notifications": [ 39 | { 40 | "notification_id": "5de5a365a1de18000cdfdf49" 41 | } 42 | ], 43 | "storage": [ 44 | { 45 | "type": "persist-to-streams-v1", 46 | "streams": [ 47 | "000000000000000000000002" 48 | ] 49 | } 50 | ] 51 | } 52 | -------------------------------------------------------------------------------- /graylog/testdata/index_set/create.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_index_set" "test" { 2 | title = "test" 3 | index_prefix = "1234-test" 4 | rotation_strategy_class = "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy" 5 | retention_strategy_class = "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategy" 6 | description = "The Graylog default index set" 7 | index_analyzer = "standard" 8 | index_optimization_disabled = false 9 | writable = true 10 | shards = 4 11 | replicas = 0 12 | index_optimization_max_num_segments = 1 13 | field_type_refresh_interval = 5000 14 | 15 | retention_strategy { 16 | max_number_of_indices = 20 17 | type = "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig" 18 | } 19 | 20 | rotation_strategy { 21 | max_docs_per_index = 20000000 22 | max_size = 0 23 | type = "org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /docs/resources/index_set.md: -------------------------------------------------------------------------------- 1 | # graylog_index_set 2 | 3 | * [Example](../../examples/v0.12/index_set.tf) 4 | * [Source code](../../graylog/terraform/resource_index_set.go) 5 | 6 | ## Argument Reference 7 | 8 | ### Required Argument 9 | 10 | name | type | etc 11 | --- | --- | --- 12 | title | string | 13 | index_prefix | string | `force new` 14 | rotation_strategy_class | string | 15 | rotation_strategy | | 16 | rotation_strategy.type | string | 17 | rotation_strategy.max_docs_per_index | int | 18 | rotation_strategy.max_size | int | 19 | rotation_strategy.rotation_period | string | 20 | retention_strategy_class | string | 21 | retention_strategy | | 22 | retention_strategy.type | string | 23 | retention_strategy.max_number_of_indices | int | 24 | index_analyzer | string | 25 | shards | int | 26 | index_optimization_max_num_segments | int | 27 | 28 | ### Optional Argument 29 | 30 | name | default | type | description 31 | --- | --- | --- | --- 32 | description | "" | string | 33 | replicas | 0 | int | 34 | index_optimization_disabled | | bool | 35 | writable | | bool | 36 | default | | bool | 37 | creation_date | computed | string | 38 | 39 | ## Attrs Reference 40 | 41 | name | type | etc 42 | --- | --- | --- 43 | id | string | 44 | -------------------------------------------------------------------------------- /graylog/graylog/input_cef_kafka.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeCEFKafka is one of input types. 5 | InputTypeCEFKafka string = "org.graylog.plugins.cef.input.CEFKafkaInput" 6 | ) 7 | 8 | // NewInputCEFKafkaAttrs is the constructor of InputCEFKafkaAttrs. 9 | func NewInputCEFKafkaAttrs() InputAttrs { 10 | return &InputCEFKafkaAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputCEFKafkaAttrs) InputType() string { 15 | return InputTypeCEFKafka 16 | } 17 | 18 | // InputCEFKafkaAttrs represents CEF Kafka Input's attributes. 19 | type InputCEFKafkaAttrs struct { 20 | ThrottlingAllowed bool `json:"throttling_allowed"` 21 | UseFullNames bool `json:"use_full_names"` 22 | Locale string `json:"locale,omitempty"` 23 | Zookeeper string `json:"zookeeper,omitempty"` 24 | Timezone string `json:"timezone,omitempty"` 25 | TopicFilter string `json:"topic_filter,omitempty"` 26 | OffsetReset string `json:"offset_reset,omitempty"` 27 | Threads int `json:"threads,omitempty"` 28 | FetchWaitMax int `json:"fetch_wait_max,omitempty"` 29 | FetchMinBytes int `json:"fetch_min_bytes,omitempty"` 30 | } 31 | -------------------------------------------------------------------------------- /graylog/graylog/input_gelf_kafka.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeGELFKafka is one of input types. 5 | InputTypeGELFKafka string = "org.graylog2.inputs.gelf.kafka.GELFKafkaInput" 6 | ) 7 | 8 | // NewInputGELFKafkaAttrs is the constructor of InputGELFKafkaAttrs. 9 | func NewInputGELFKafkaAttrs() InputAttrs { 10 | return &InputGELFKafkaAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputGELFKafkaAttrs) InputType() string { 15 | return InputTypeGELFKafka 16 | } 17 | 18 | // InputGELFKafkaAttrs represents GELF Kafka Input's attributes. 19 | type InputGELFKafkaAttrs struct { 20 | OverrideSource string `json:"override_source,omitempty"` 21 | DecompressSizeLimit int `json:"decompress_size_limit,omitempty"` 22 | TopicFilter string `json:"topic_filter,omitempty"` 23 | ThrottlingAllowed bool `json:"throttling_allowed"` 24 | FetchWaitMax int `json:"fetch_wait_max,omitempty"` 25 | FetchMinBytes int `json:"fetch_min_bytes,omitempty"` 26 | OffsetReset string `json:"offset_reset,omitempty"` 27 | Threads int `json:"threads,omitempty"` 28 | Zookeeper string `json:"zookeeper,omitempty"` 29 | } 30 | -------------------------------------------------------------------------------- /graylog/testdata/dashboard_widget/stacked_chart/create.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_dashboard_widget" "http_response_codes" { 2 | dashboard_id = "5de4fcf7a1de1800127e2fbc" 3 | description = "ingress response codes" 4 | type = "STACKED_CHART" 5 | json_configuration = <&2 30 | exit 1 31 | fi 32 | 33 | ee cd "$(dirname "$0")/.." 34 | 35 | VERSION_FILE=graylog/graylog/version.go 36 | echo "create $VERSION_FILE" 37 | cat << EOS > "$VERSION_FILE" 38 | package graylog 39 | 40 | // Don't edit this file. 41 | // This file is generated by the release command. 42 | 43 | // Version is the go-graylog's version. 44 | const Version = "$VERSION" 45 | EOS 46 | 47 | ee git add "$VERSION_FILE" 48 | echo "+ git commit -m \"build: update version to $TAG\"" 49 | git commit -m "build: update version to $TAG" 50 | ee git tag "$TAG" 51 | ee git push "$REMOTE" "$BRANCH" 52 | ee git push "$REMOTE" "$TAG" 53 | -------------------------------------------------------------------------------- /graylog/client/endpoint/stream_test.go: -------------------------------------------------------------------------------- 1 | package endpoint_test 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | 9 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/client/endpoint" 10 | ) 11 | 12 | func TestEndpoints_Streams(t *testing.T) { 13 | ep, err := endpoint.NewEndpoints(apiURL) 14 | require.Nil(t, err) 15 | require.Equal(t, fmt.Sprintf("%s/streams", apiURL), ep.Streams()) 16 | } 17 | 18 | func TestEndpoints_Stream(t *testing.T) { 19 | ep, err := endpoint.NewEndpoints(apiURL) 20 | require.Nil(t, err) 21 | require.Equal(t, fmt.Sprintf("%s/streams/%s", apiURL, ID), ep.Stream(ID)) 22 | } 23 | 24 | func TestEndpoints_PauseStream(t *testing.T) { 25 | ep, err := endpoint.NewEndpoints(apiURL) 26 | require.Nil(t, err) 27 | require.Equal(t, fmt.Sprintf("%s/streams/%s/pause", apiURL, ID), ep.PauseStream(ID)) 28 | } 29 | 30 | func TestEndpoints_ResumeStream(t *testing.T) { 31 | ep, err := endpoint.NewEndpoints(apiURL) 32 | require.Nil(t, err) 33 | require.Equal(t, fmt.Sprintf("%s/streams/%s/resume", apiURL, ID), ep.ResumeStream(ID)) 34 | } 35 | 36 | func TestEndpoints_EnabledStreams(t *testing.T) { 37 | ep, err := endpoint.NewEndpoints(apiURL) 38 | require.Nil(t, err) 39 | require.Equal(t, fmt.Sprintf("%s/streams/enabled", apiURL), ep.EnabledStreams()) 40 | } 41 | -------------------------------------------------------------------------------- /graylog/client/alarm_callback_test.go: -------------------------------------------------------------------------------- 1 | package client_test 2 | 3 | import ( 4 | "context" 5 | "io/ioutil" 6 | "net/http" 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | "github.com/suzuki-shunsuke/flute/flute" 11 | 12 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/client" 13 | ) 14 | 15 | func TestClient_GetAlarmCallbacks(t *testing.T) { 16 | ctx := context.Background() 17 | 18 | cl, err := client.NewClient("http://example.com/api", "admin", "admin") 19 | require.Nil(t, err) 20 | 21 | buf, err := ioutil.ReadFile("../testdata/alarm_callback/alarm_callbacks.json") 22 | require.Nil(t, err) 23 | bodyStr := string(buf) 24 | 25 | cl.SetHTTPClient(&http.Client{ 26 | Transport: &flute.Transport{ 27 | T: t, 28 | Services: []flute.Service{ 29 | { 30 | Endpoint: "http://example.com", 31 | Routes: []flute.Route{ 32 | { 33 | Tester: &flute.Tester{ 34 | Method: "GET", 35 | Path: "/api/alerts/callbacks", 36 | PartOfHeader: getTestHeader(), 37 | }, 38 | Response: &flute.Response{ 39 | Base: http.Response{ 40 | StatusCode: 200, 41 | }, 42 | BodyString: bodyStr, 43 | }, 44 | }, 45 | }, 46 | }, 47 | }, 48 | }, 49 | }) 50 | 51 | _, _, _, err = cl.GetAlarmCallbacks(ctx) 52 | require.Nil(t, err) 53 | } 54 | -------------------------------------------------------------------------------- /examples/v0.12/output.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_output" "stdout" { 2 | title = "stdout" 3 | type = "org.graylog2.outputs.LoggingOutput" 4 | 5 | configuration = jsonencode({ 6 | prefix = "Writing message: " 7 | }) 8 | } 9 | 10 | resource "graylog_output" "gelf" { 11 | title = "gelf" 12 | type = "org.graylog2.outputs.GelfOutput" 13 | 14 | configuration = jsonencode({ 15 | "hostname" : "localhost", 16 | "protocol" : "TCP", 17 | "connect_timeout" : 1000, 18 | "reconnect_delay" : 500, 19 | "queue_size" : 512, 20 | "port" : 12201, 21 | "max_inflight_sends" : 512, 22 | "tcp_no_delay" : false, 23 | "tcp_keep_alive" : false, 24 | "tls_trust_cert_chain" : "", 25 | "tls_verification_enabled" : false 26 | }) 27 | } 28 | 29 | resource "graylog_output" "slack" { 30 | title = "slack" 31 | type = "org.graylog2.plugins.slack.output.SlackMessageOutput" 32 | 33 | configuration = jsonencode({ 34 | "icon_url" : "", 35 | "graylog2_url" : "", 36 | "link_names" : true, 37 | "color" : "#FF0000", 38 | "webhook_url" : "http://example.com", 39 | "icon_emoji" : "", 40 | "user_name" : "Graylog", 41 | "proxy_address" : "", 42 | "channel" : "#channel", 43 | "custom_message" : "message", 44 | "notify_channel" : false, 45 | "short_mode" : false, 46 | "add_details" : true 47 | }) 48 | } 49 | -------------------------------------------------------------------------------- /graylog/client/alert_condition_test.go: -------------------------------------------------------------------------------- 1 | package client_test 2 | 3 | import ( 4 | "context" 5 | "io/ioutil" 6 | "net/http" 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | "github.com/suzuki-shunsuke/flute/flute" 11 | 12 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/client" 13 | ) 14 | 15 | func TestClient_GetAlertConditions(t *testing.T) { 16 | ctx := context.Background() 17 | 18 | cl, err := client.NewClient("http://example.com/api", "admin", "admin") 19 | require.Nil(t, err) 20 | 21 | buf, err := ioutil.ReadFile("../testdata/alert_condition/alert_conditions.json") 22 | require.Nil(t, err) 23 | 24 | cl.SetHTTPClient(&http.Client{ 25 | Transport: &flute.Transport{ 26 | T: t, 27 | Services: []flute.Service{ 28 | { 29 | Endpoint: "http://example.com", 30 | Routes: []flute.Route{ 31 | { 32 | Tester: &flute.Tester{ 33 | Method: "GET", 34 | Path: "/api/alerts/conditions", 35 | PartOfHeader: getTestHeader(), 36 | }, 37 | Response: &flute.Response{ 38 | Base: http.Response{ 39 | StatusCode: 200, 40 | }, 41 | BodyString: string(buf), 42 | }, 43 | }, 44 | }, 45 | }, 46 | }, 47 | }, 48 | }) 49 | 50 | _, _, _, err = cl.GetAlertConditions(ctx) 51 | if err != nil { 52 | t.Fatal(err) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /graylog/testdata/email_stream_alarm_callback.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-set/v6" 5 | 6 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 7 | ) 8 | 9 | func EmailStreamAlarmCallback() graylog.AlarmCallback { 10 | return graylog.AlarmCallback{ 11 | ID: "5d84ca7f2ab79c000d35e083", 12 | StreamID: "5d84c1a92ab79c000d35d6ca", 13 | Title: "test", 14 | CreatorUserID: "admin", 15 | CreatedAt: "2019-09-20T12:47:59.170+0000", 16 | Configuration: &graylog.EmailAlarmCallbackConfiguration{ 17 | Sender: "graylog@example.org", 18 | Subject: "Graylog alert for stream: ${stream.title}: ${check_result.resultDescription}", 19 | Body: "##########\\nAlert Description: ${check_result.resultDescription}\\nDate: ${check_result.triggeredAt}\\nStream ID: ${stream.id}\\nStream title: ${stream.title}\\nStream description: ${stream.description}\\nAlert Condition Title: ${alertCondition.title}\\n${if stream_url}Stream URL: ${stream_url}${end}\\n\\nTriggered condition: ${check_result.triggeredCondition}\\n##########\\n\\n${if backlog}Last messages accounting for this alert:\\n${foreach backlog message}${message}\\n\\n${end}${else}\\n${end}\\n", 20 | UserReceivers: set.NewStrSet("username"), 21 | EmailReceivers: set.NewStrSet("graylog@example.com"), 22 | }, 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /graylog/testdata/dashboard_widget.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func UpdateDashboardWidgetStackedChart() graylog.Widget { 8 | return graylog.Widget{ 9 | Description: "updated description", 10 | Config: &graylog.WidgetConfigUnknownType{ 11 | T: "STACKED_CHART", 12 | Fields: map[string]interface{}{ 13 | "interval": "minute", 14 | "timerange": map[string]interface{}{ 15 | "type": "relative", 16 | "range": 86400, 17 | }, 18 | "renderer": "area", 19 | "interpolation": "linear", 20 | "stream_id": "000000000000000000000003", 21 | "series": []interface{}{ 22 | map[string]interface{}{ 23 | "query": "labels_app: nginx-ingress AND response:[200 TO 399]", 24 | "field": "response", 25 | "statistical_function": "count", 26 | }, 27 | map[string]interface{}{ 28 | "query": "labels_app: nginx-ingress AND response:[500 TO 599]", 29 | "field": "response", 30 | "statistical_function": "count", 31 | }, 32 | map[string]interface{}{ 33 | "query": "labels_app: nginx-ingress AND response:[400 TO 499]", 34 | "field": "response", 35 | "statistical_function": "count", 36 | }, 37 | }, 38 | }, 39 | }, 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /graylog/client/stream_output.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | 7 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 8 | ) 9 | 10 | // CreateOutput creates a new output. 11 | func (client *Client) CreateStreamOutputs( 12 | ctx context.Context, streamID string, outputIDs []string, 13 | ) (*ErrorInfo, error) { 14 | if streamID == "" { 15 | return nil, errors.New("stream id is empty") 16 | } 17 | return client.callPost( 18 | ctx, client.Endpoints().StreamOutputs(streamID), 19 | map[string]interface{}{ 20 | "outputs": outputIDs, 21 | }, nil) 22 | } 23 | 24 | // GetOutputs returns all outputs. 25 | func (client *Client) GetStreamOutputs(ctx context.Context, streamID string) ( 26 | []graylog.Output, int, *ErrorInfo, error, 27 | ) { 28 | outputs := &graylog.OutputsBody{} 29 | ei, err := client.callGet(ctx, client.Endpoints().StreamOutputs(streamID), nil, outputs) 30 | return outputs.Outputs, outputs.Total, ei, err 31 | } 32 | 33 | // DeleteOutput deletes a given output. 34 | func (client *Client) DeleteStreamOutput( 35 | ctx context.Context, streamID, outputID string, 36 | ) (*ErrorInfo, error) { 37 | if streamID == "" { 38 | return nil, errors.New("stream id is empty") 39 | } 40 | if outputID == "" { 41 | return nil, errors.New("output id is empty") 42 | } 43 | return client.callDelete(ctx, client.Endpoints().StreamOutput(streamID, outputID), nil, nil) 44 | } 45 | -------------------------------------------------------------------------------- /graylog/client/endpoint/index_set_test.go: -------------------------------------------------------------------------------- 1 | package endpoint_test 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | 9 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/client/endpoint" 10 | ) 11 | 12 | func TestEndpoints_IndexSets(t *testing.T) { 13 | ep, err := endpoint.NewEndpoints(apiURL) 14 | require.Nil(t, err) 15 | require.Equal(t, fmt.Sprintf("%s/system/indices/index_sets", apiURL), ep.IndexSets()) 16 | } 17 | 18 | func TestEndpoints_IndexSet(t *testing.T) { 19 | ep, err := endpoint.NewEndpoints(apiURL) 20 | require.Nil(t, err) 21 | require.Equal(t, fmt.Sprintf("%s/system/indices/index_sets/%s", apiURL, ID), ep.IndexSet(ID)) 22 | } 23 | 24 | func TestEndpoints_SetDefaultIndexSet(t *testing.T) { 25 | ep, err := endpoint.NewEndpoints(apiURL) 26 | require.Nil(t, err) 27 | require.Equal(t, fmt.Sprintf("%s/system/indices/index_sets/%s/default", apiURL, ID), ep.SetDefaultIndexSet(ID)) 28 | } 29 | 30 | func TestEndpoints_IndexSetsStats(t *testing.T) { 31 | ep, err := endpoint.NewEndpoints(apiURL) 32 | require.Nil(t, err) 33 | require.Equal(t, fmt.Sprintf("%s/system/indices/index_sets/stats", apiURL), ep.IndexSetsStats()) 34 | } 35 | 36 | func TestEndpoints_IndexSetStats(t *testing.T) { 37 | ep, err := endpoint.NewEndpoints(apiURL) 38 | require.Nil(t, err) 39 | require.Equal(t, fmt.Sprintf("%s/system/indices/index_sets/%s/stats", apiURL, ID), ep.IndexSetStats(ID)) 40 | } 41 | -------------------------------------------------------------------------------- /graylog/graylog/input_syslog_kafka.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeSyslogKafka is one of input types. 5 | InputTypeSyslogKafka string = "org.graylog2.inputs.syslog.kafka.SyslogKafkaInput" 6 | ) 7 | 8 | // NewInputSyslogKafkaAttrs is the constructor of InputSyslogKafkaAttrs. 9 | func NewInputSyslogKafkaAttrs() InputAttrs { 10 | return &InputSyslogKafkaAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputSyslogKafkaAttrs) InputType() string { 15 | return InputTypeSyslogKafka 16 | } 17 | 18 | // InputSyslogKafkaAttrs represents SyslogKafka Input's attributes. 19 | type InputSyslogKafkaAttrs struct { 20 | ForceRDNS bool `json:"force_rdns"` 21 | StoreFullMessage bool `json:"store_full_message"` 22 | ExpandStructuredData bool `json:"expand_structured_data"` 23 | AllowOverrideDate bool `json:"allow_override_date"` 24 | ThrottlingAllowed bool `json:"throttling_allowed"` 25 | OverrideSource string `json:"override_source,omitempty"` 26 | TopicFilter string `json:"topic_filter,omitempty"` 27 | FetchWaitMax int `json:"fetch_wait_max,omitempty"` 28 | OffsetReset string `json:"offset_reset,omitempty"` 29 | Zookeeper string `json:"zookeeper,omitempty"` 30 | FetchMinBytes int `json:"fetch_min_bytes,omitempty"` 31 | Threads int `json:"threads,omitempty"` 32 | } 33 | -------------------------------------------------------------------------------- /graylog/graylog/input_beats.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeBeats is one of input types. 5 | InputTypeBeats string = "org.graylog.plugins.beats.BeatsInput" 6 | ) 7 | 8 | // NewInputBeatsAttrs is the constructor of InputBeatsAttrs. 9 | func NewInputBeatsAttrs() InputAttrs { 10 | return &InputBeatsAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputBeatsAttrs) InputType() string { 15 | return InputTypeBeats 16 | } 17 | 18 | // InputBeatsAttrs represents Beats Input's attributes. 19 | type InputBeatsAttrs struct { 20 | BindAddress string `json:"bind_address,omitempty" v-create:"required" v-update:"required"` 21 | OverrideSource string `json:"override_source,omitempty"` 22 | TLSKeyFile string `json:"tls_key_file,omitempty"` 23 | TLSKeyPassword string `json:"tls_key_password,omitempty"` 24 | TLSClientAuthCertFile string `json:"tls_client_auth_cert_file,omitempty"` 25 | TLSClientAuth string `json:"tls_client_auth,omitempty"` 26 | TLSCertFile string `json:"tls_cert_file,omitempty"` 27 | TLSEnable bool `json:"tls_enable"` 28 | TCPKeepAlive bool `json:"tcp_keepalive"` 29 | Port int `json:"port,omitempty" v-create:"required" v-update:"required"` 30 | RecvBufferSize int `json:"recv_buffer_size,omitempty" v-create:"required" v-update:"required"` 31 | } 32 | -------------------------------------------------------------------------------- /examples/v0.11/docker-compose.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: '2' 3 | services: 4 | # MongoDB: https://hub.docker.com/_/mongo/ 5 | mongodb: 6 | image: mongo:3 7 | # Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/6.6/docker.html 8 | elasticsearch: 9 | image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.6.1 10 | environment: 11 | - http.host=0.0.0.0 12 | - transport.host=localhost 13 | - network.host=0.0.0.0 14 | - "ES_JAVA_OPTS=-Xms1024m -Xmx1024m" 15 | ulimits: 16 | memlock: 17 | soft: -1 18 | hard: -1 19 | mem_limit: 1g 20 | # Graylog: https://hub.docker.com/r/graylog/graylog/ 21 | graylog: 22 | image: graylog/graylog:3.1.2 23 | environment: 24 | # CHANGE ME (must be at least 16 characters)! 25 | - GRAYLOG_PASSWORD_SECRET=somepasswordpepper 26 | # Password: admin 27 | - GRAYLOG_ROOT_PASSWORD_SHA2=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918 28 | - GRAYLOG_HTTP_EXTERNAL_URI=http://127.0.0.1:9000/ 29 | links: 30 | - mongodb:mongo 31 | - elasticsearch 32 | depends_on: 33 | - mongodb 34 | - elasticsearch 35 | ports: 36 | # Graylog web interface and REST API 37 | - 9000:9000 38 | # Syslog TCP 39 | - 1514:1514 40 | # Syslog UDP 41 | - 1514:1514/udp 42 | # GELF TCP 43 | - 12201:12201 44 | # GELF UDP 45 | - 12201:12201/udp 46 | volumes: 47 | - ./plugin:/usr/share/graylog/plugin 48 | -------------------------------------------------------------------------------- /graylog/client/client_test.go: -------------------------------------------------------------------------------- 1 | package client_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/client" 7 | ) 8 | 9 | const ( 10 | endpoint = "http://localhost:9000/api" 11 | ) 12 | 13 | func TestNewClient(t *testing.T) { 14 | client, err := client.NewClient(endpoint, "admin", "password") 15 | if err != nil { 16 | t.Fatal("Failed to NewClient", err) 17 | } 18 | if client == nil { 19 | t.Fatal("client == nil") 20 | } 21 | } 22 | 23 | func TestClient_Name(t *testing.T) { 24 | name := "admin" 25 | client, err := client.NewClient(endpoint, name, "password") 26 | if err != nil { 27 | t.Fatal("Failed to NewClient", err) 28 | } 29 | if client == nil { 30 | t.Fatal("client == nil") 31 | } 32 | act := client.Name() 33 | if act != name { 34 | t.Fatalf("client.Name() == %s, wanted %s", act, name) 35 | } 36 | 37 | exp := "http://localhost:9000/api/roles" 38 | act = client.Endpoints().Roles() 39 | if act != exp { 40 | t.Fatalf("client.Endpoints().Roles == %s, wanted %s", act, exp) 41 | } 42 | } 43 | 44 | func TestClient_Password(t *testing.T) { 45 | password := "password" 46 | client, err := client.NewClient(endpoint, "admin", password) 47 | if err != nil { 48 | t.Fatal("Failed to NewClient", err) 49 | } 50 | if client == nil { 51 | t.Fatal("client == nil") 52 | } 53 | real := client.Password() 54 | if real != password { 55 | t.Fatalf("client.Password() == %s, wanted %s", real, password) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /graylog/client/role_member.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | 7 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 8 | ) 9 | 10 | // GetRoleMembers returns a given role's members. 11 | func (client *Client) GetRoleMembers( 12 | ctx context.Context, name string, 13 | ) ([]graylog.User, *ErrorInfo, error) { 14 | if name == "" { 15 | return nil, nil, errors.New("name is empty") 16 | } 17 | users := &graylog.UsersBody{} 18 | ei, err := client.callGet(ctx, client.Endpoints().RoleMembers(name), nil, users) 19 | return users.Users, ei, err 20 | } 21 | 22 | // AddUserToRole adds a user to a role. 23 | func (client *Client) AddUserToRole( 24 | ctx context.Context, userName, roleName string, 25 | ) (*ErrorInfo, error) { 26 | if userName == "" { 27 | return nil, errors.New("userName is empty") 28 | } 29 | if roleName == "" { 30 | return nil, errors.New("roleName is empty") 31 | } 32 | return client.callPut(ctx, client.Endpoints().RoleMember(userName, roleName), nil, nil) 33 | } 34 | 35 | // RemoveUserFromRole removes a user from a role. 36 | func (client *Client) RemoveUserFromRole( 37 | ctx context.Context, userName, roleName string, 38 | ) (*ErrorInfo, error) { 39 | if userName == "" { 40 | return nil, errors.New("userName is empty") 41 | } 42 | if roleName == "" { 43 | return nil, errors.New("roleName is empty") 44 | } 45 | return client.callDelete(ctx, client.Endpoints().RoleMember(userName, roleName), nil, nil) 46 | } 47 | -------------------------------------------------------------------------------- /graylog/testdata/event_definition/update/request.go: -------------------------------------------------------------------------------- 1 | package update 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func Request() *graylog.EventDefinition { 8 | return &graylog.EventDefinition{ 9 | ID: "5de5aac1a1de18000cdfe2b3", 10 | Title: "new-event-definition", 11 | Priority: 2, 12 | Alert: true, 13 | FieldSpec: map[string]graylog.EventDefinitionFieldSpec{ 14 | "test": { 15 | DataType: "string", 16 | Providers: []interface{}{ 17 | map[string]interface{}{ 18 | "require_values": false, 19 | "template": "test", 20 | "type": "template-v1", 21 | }, 22 | }, 23 | }, 24 | }, 25 | Notifications: []graylog.EventDefinitionNotification{ 26 | { 27 | NotificationID: "5de5a365a1de18000cdfdf49", 28 | }, 29 | }, 30 | Storage: []interface{}{ 31 | map[string]interface{}{ 32 | "streams": []interface{}{ 33 | "000000000000000000000002", 34 | }, 35 | "type": "persist-to-streams-v1", 36 | }, 37 | }, 38 | Config: map[string]interface{}{ 39 | "conditions": map[string]interface{}{ 40 | "expression": nil, 41 | }, 42 | "execute_every_ms": 60000, 43 | "group_by": []interface{}{}, 44 | "query": "test", 45 | "search_within_ms": 60000, 46 | "series": []interface{}{}, 47 | "streams": []interface{}{ 48 | "000000000000000000000001", 49 | }, 50 | "type": "aggregation-v1", 51 | }, 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /graylog/testdata/event_definition/update/response.go: -------------------------------------------------------------------------------- 1 | package update 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func Response() *graylog.EventDefinition { 8 | return &graylog.EventDefinition{ 9 | ID: "5de5aac1a1de18000cdfe2b3", 10 | Title: "new-event-definition", 11 | Priority: 2, 12 | Alert: true, 13 | FieldSpec: map[string]graylog.EventDefinitionFieldSpec{ 14 | "test": { 15 | DataType: "string", 16 | Providers: []interface{}{ 17 | map[string]interface{}{ 18 | "require_values": false, 19 | "template": "test", 20 | "type": "template-v1", 21 | }, 22 | }, 23 | }, 24 | }, 25 | Notifications: []graylog.EventDefinitionNotification{ 26 | { 27 | NotificationID: "5de5a365a1de18000cdfdf49", 28 | }, 29 | }, 30 | Storage: []interface{}{ 31 | map[string]interface{}{ 32 | "streams": []interface{}{ 33 | "000000000000000000000002", 34 | }, 35 | "type": "persist-to-streams-v1", 36 | }, 37 | }, 38 | Config: map[string]interface{}{ 39 | "conditions": map[string]interface{}{ 40 | "expression": nil, 41 | }, 42 | "execute_every_ms": 60000, 43 | "group_by": []interface{}{}, 44 | "query": "test", 45 | "search_within_ms": 60000, 46 | "series": []interface{}{}, 47 | "streams": []interface{}{ 48 | "000000000000000000000001", 49 | }, 50 | "type": "aggregation-v1", 51 | }, 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /graylog/graylog/input_raw_tcp.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeRawTCP is one of input types. 5 | InputTypeRawTCP string = "org.graylog2.inputs.raw.tcp.RawTCPInput" 6 | ) 7 | 8 | // NewInputRawTCPAttrs is the constructor of InputRawTCPAttrs. 9 | func NewInputRawTCPAttrs() InputAttrs { 10 | return &InputRawTCPAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputRawTCPAttrs) InputType() string { 15 | return InputTypeRawTCP 16 | } 17 | 18 | // InputRawTCPAttrs represents raw TCP Input's attributes. 19 | type InputRawTCPAttrs struct { 20 | TLSEnable bool `json:"tls_enable"` 21 | TCPKeepAlive bool `json:"tcp_keepalive"` 22 | UseNullDelimiter bool `json:"use_null_delimiter"` 23 | Port int `json:"port,omitempty"` 24 | RecvBufferSize int `json:"recv_buffer_size,omitempty"` 25 | NumberWorkerThreds int `json:"number_worker_threads,omitempty"` 26 | MaxMessageSize int `json:"max_message_size,omitempty"` 27 | BindAddress string `json:"bind_address,omitempty"` 28 | TLSCertFile string `json:"tls_cert_file,omitempty"` 29 | TLSKeyFile string `json:"tls_key_file,omitempty"` 30 | TLSKeyPassword string `json:"tls_key_password,omitempty"` 31 | TLSClientAuth string `json:"tls_client_auth,omitempty"` 32 | TLSClientAuthCertFile string `json:"tls_client_auth_cert_file,omitempty"` 33 | OverrideSource string `json:"override_source,omitempty"` 34 | } 35 | -------------------------------------------------------------------------------- /examples/v0.12/docker-compose.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: '3' 3 | services: 4 | # MongoDB: https://hub.docker.com/_/mongo/ 5 | mongo: 6 | image: mongo:3.6.17-xenial 7 | networks: 8 | - graylog 9 | # Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/6.x/docker.html 10 | elasticsearch: 11 | image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.8.5 12 | environment: 13 | - http.host=0.0.0.0 14 | - transport.host=localhost 15 | - network.host=0.0.0.0 16 | - "ES_JAVA_OPTS=-Xms1024m -Xmx1024m" 17 | ulimits: 18 | memlock: 19 | soft: -1 20 | hard: -1 21 | networks: 22 | - graylog 23 | # Graylog: https://hub.docker.com/r/graylog/graylog/ 24 | graylog: 25 | image: graylog/graylog:3.2.1 26 | environment: 27 | # CHANGE ME (must be at least 16 characters)! 28 | - GRAYLOG_PASSWORD_SECRET=somepasswordpepper 29 | # Password: admin 30 | - GRAYLOG_ROOT_PASSWORD_SHA2=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918 31 | - GRAYLOG_HTTP_EXTERNAL_URI=http://127.0.0.1:9000/ 32 | networks: 33 | - graylog 34 | depends_on: 35 | - mongo 36 | - elasticsearch 37 | ports: 38 | # Graylog web interface and REST API 39 | - 9000:9000 40 | # Syslog TCP 41 | - 1514:1514 42 | # Syslog UDP 43 | - 1514:1514/udp 44 | # GELF TCP 45 | - 12201:12201 46 | # GELF UDP 47 | - 12201:12201/udp 48 | volumes: 49 | - ./plugin:/usr/share/graylog/plugin 50 | networks: 51 | graylog: 52 | driver: bridge 53 | -------------------------------------------------------------------------------- /graylog/testdata/event_definition/get/response.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "5dea491ba1de18000d4bbcce", 3 | "title": "new-event-definition", 4 | "description": "", 5 | "priority": 1, 6 | "alert": true, 7 | "config": { 8 | "type": "aggregation-v1", 9 | "query": "test", 10 | "streams": [ 11 | "000000000000000000000001" 12 | ], 13 | "group_by": [ 14 | "alert" 15 | ], 16 | "series": [ 17 | { 18 | "id": "9dfd012c-4f4d-417b-80d8-f7ebda2020a3", 19 | "function": "avg", 20 | "field": "alert" 21 | } 22 | ], 23 | "conditions": { 24 | "expression": { 25 | "expr": "<", 26 | "left": { 27 | "expr": "number-ref", 28 | "ref": "9dfd012c-4f4d-417b-80d8-f7ebda2020a3" 29 | }, 30 | "right": { 31 | "expr": "number", 32 | "value": 0 33 | } 34 | } 35 | }, 36 | "search_within_ms": 60000, 37 | "execute_every_ms": 60000 38 | }, 39 | "field_spec": { 40 | "test": { 41 | "data_type": "string", 42 | "providers": [ 43 | { 44 | "type": "template-v1", 45 | "template": "test", 46 | "require_values": false 47 | } 48 | ] 49 | } 50 | }, 51 | "key_spec": [], 52 | "notification_settings": { 53 | "grace_period_ms": 0, 54 | "backlog_size": 0 55 | }, 56 | "notifications": [], 57 | "storage": [ 58 | { 59 | "type": "persist-to-streams-v1", 60 | "streams": [ 61 | "000000000000000000000002" 62 | ] 63 | } 64 | ] 65 | } 66 | -------------------------------------------------------------------------------- /graylog/client/user_token.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | 7 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 8 | ) 9 | 10 | // CreateUserToken generates a new access token for a user 11 | func (client *Client) CreateUserToken( 12 | ctx context.Context, userName, tokenName string, 13 | ) (*graylog.UserToken, *ErrorInfo, error) { 14 | if userName == "" { 15 | return nil, nil, errors.New("user name is required") 16 | } 17 | if tokenName == "" { 18 | return nil, nil, errors.New("token name is required") 19 | } 20 | token := &graylog.UserToken{} 21 | 22 | ei, err := client.callPost(ctx, client.Endpoints().UserToken(userName, tokenName), map[string]interface{}{}, token) 23 | return token, ei, err 24 | } 25 | 26 | // GetUserTokens returns the list of access tokens for a user. 27 | func (client *Client) GetUserTokens(ctx context.Context, name string) ([]graylog.UserToken, *ErrorInfo, error) { 28 | tokens := map[string][]graylog.UserToken{} 29 | ei, err := client.callGet(ctx, client.Endpoints().UserTokens(name), nil, &tokens) 30 | if a, ok := tokens["tokens"]; ok { 31 | return a, ei, err 32 | } 33 | return nil, ei, err 34 | } 35 | 36 | // DeleteUserToken removes a token for a user. 37 | func (client *Client) DeleteUserToken( 38 | ctx context.Context, name, token string, 39 | ) (*ErrorInfo, error) { 40 | if name == "" { 41 | return nil, errors.New("name is empty") 42 | } 43 | if token == "" { 44 | return nil, errors.New("name is empty") 45 | } 46 | return client.callDelete(ctx, client.Endpoints().UserToken(name, token), nil, nil) 47 | } 48 | -------------------------------------------------------------------------------- /graylog/client/example_test.go: -------------------------------------------------------------------------------- 1 | package client_test 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | "net/http" 8 | 9 | "github.com/suzuki-shunsuke/flute/flute" 10 | 11 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/client" 12 | ) 13 | 14 | func ExampleClient() { 15 | ctx := context.Background() 16 | 17 | // Create a client 18 | cl, err := client.NewClient("http://example.com/api", "admin", "admin") 19 | if err != nil { 20 | log.Fatal(err) 21 | } 22 | 23 | setExampleMock(cl) 24 | 25 | // get a role "Admin" 26 | // ei.Response.Body is closed 27 | role, ei, err := cl.GetRole(ctx, "Admin") 28 | if err != nil { 29 | log.Fatal(err) 30 | } 31 | fmt.Println(ei.Response.StatusCode) 32 | fmt.Println(role.Name) 33 | // Output: 34 | // 200 35 | // Admin 36 | } 37 | 38 | func setExampleMock(cl *client.Client) { 39 | cl.SetHTTPClient(&http.Client{ 40 | Transport: &flute.Transport{ 41 | Services: []flute.Service{ 42 | { 43 | Endpoint: "http://example.com", 44 | Routes: []flute.Route{ 45 | { 46 | Tester: &flute.Tester{ 47 | Method: "GET", 48 | Path: "/api/roles/Admin", 49 | PartOfHeader: getTestHeader(), 50 | }, 51 | Response: &flute.Response{ 52 | Base: http.Response{ 53 | StatusCode: 200, 54 | }, 55 | BodyString: `{ 56 | "name": "Admin", 57 | "description": "Grants all permissions for Graylog administrators (built-in)", 58 | "permissions": [ 59 | "*" 60 | ], 61 | "read_only": true 62 | }`, 63 | }, 64 | }, 65 | }, 66 | }, 67 | }, 68 | }, 69 | }) 70 | } 71 | -------------------------------------------------------------------------------- /graylog/graylog/role.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-ptr" 5 | "github.com/suzuki-shunsuke/go-set/v6" 6 | ) 7 | 8 | type ( 9 | // Role represents a role. 10 | Role struct { 11 | Name string `json:"name,omitempty" v-create:"required" v-update:"required"` 12 | Description string `json:"description,omitempty"` 13 | // ex. ["clusterconfigentry:read", "users:edit"] 14 | Permissions set.StrSet `json:"permissions,omitempty" v-create:"required" v-update:"required"` 15 | ReadOnly bool `json:"read_only"` 16 | } 17 | 18 | // RoleUpdateParams represents Update Role API's parameters. 19 | RoleUpdateParams struct { 20 | Name string `json:"name,omitempty" v-create:"required" v-update:"required"` 21 | Description *string `json:"description,omitempty"` 22 | // ex. ["clusterconfigentry:read", "users:edit"] 23 | Permissions set.StrSet `json:"permissions,omitempty" v-create:"required" v-update:"required"` 24 | ReadOnly *bool `json:"read_only"` 25 | } 26 | 27 | // RolesBody represents Get Roles API's response body. 28 | // Basically users don't use this struct, but this struct is public because some sub packages use this struct. 29 | RolesBody struct { 30 | Roles []Role `json:"roles"` 31 | Total int `json:"total"` 32 | } 33 | ) 34 | 35 | // NewUpdateParams returns Update Role API's parameters. 36 | func (role *Role) NewUpdateParams() *RoleUpdateParams { 37 | return &RoleUpdateParams{ 38 | Name: role.Name, 39 | Description: ptr.PStr(role.Description), 40 | Permissions: role.Permissions, 41 | ReadOnly: ptr.PBool(role.ReadOnly), 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /graylog/client/pipeline.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 7 | ) 8 | 9 | // GetPipelines returns all pipeline. 10 | func (client *Client) GetPipelines(ctx context.Context) ( 11 | []graylog.Pipeline, *ErrorInfo, error, 12 | ) { 13 | pipe := []graylog.Pipeline{} 14 | ei, err := client.callGet(ctx, client.Endpoints().Pipelines(), nil, &pipe) 15 | return pipe, ei, err 16 | } 17 | 18 | // GetPipeline returns a pipeline. 19 | func (client *Client) GetPipeline(ctx context.Context, id string) ( 20 | *graylog.Pipeline, *ErrorInfo, error, 21 | ) { 22 | pipe := &graylog.Pipeline{} 23 | ei, err := client.callGet(ctx, client.Endpoints().Pipeline(id), nil, pipe) 24 | return pipe, ei, err 25 | } 26 | 27 | // CreatePipeline creates a pipeline. 28 | func (client *Client) CreatePipeline( 29 | ctx context.Context, pipeline *graylog.Pipeline, 30 | ) (*ErrorInfo, error) { 31 | return client.callPost( 32 | ctx, client.Endpoints().Pipelines(), pipeline, &pipeline) 33 | } 34 | 35 | // UpdatePipeline updates a pipeline. 36 | func (client *Client) UpdatePipeline( 37 | ctx context.Context, pipeline *graylog.Pipeline, 38 | ) (*ErrorInfo, error) { 39 | return client.callPut(ctx, client.Endpoints().Pipeline(pipeline.ID), map[string]interface{}{ 40 | "source": pipeline.Source, 41 | "description": pipeline.Description, 42 | }, pipeline) 43 | } 44 | 45 | // DeletePipeline deletes a pipeline. 46 | func (client *Client) DeletePipeline( 47 | ctx context.Context, id string, 48 | ) (*ErrorInfo, error) { 49 | return client.callDelete(ctx, client.Endpoints().Pipeline(id), nil, nil) 50 | } 51 | -------------------------------------------------------------------------------- /graylog/graylog/input_raw_amqp.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeRawAMQP is one of input types. 5 | InputTypeRawAMQP string = "org.graylog2.inputs.raw.amqp.RawAMQPInput" 6 | ) 7 | 8 | // NewInputRawAMQPAttrs is the constructor of InputRawAMQPAttrs. 9 | func NewInputRawAMQPAttrs() InputAttrs { 10 | return &InputRawAMQPAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputRawAMQPAttrs) InputType() string { 15 | return InputTypeRawAMQP 16 | } 17 | 18 | // InputRawAMQPAttrs represents raw AMQP Input's attributes. 19 | type InputRawAMQPAttrs struct { 20 | ParallelQueues int `json:"parallel_queues,omitempty"` 21 | HeartBeat int `json:"heartbeat,omitempty"` 22 | BrokerPort int `json:"broker_port,omitempty"` 23 | Prefetch int `json:"prefetch,omitempty"` 24 | RequeueInvalidMessages bool `json:"requeue_invalid_messages"` 25 | TLS bool `json:"tls"` 26 | ExchangeBind bool `json:"exchange_bind"` 27 | ThrottlingAllowed bool `json:"throttling_allowed"` 28 | Exchange string `json:"exchange,omitempty"` 29 | RoutingKey string `json:"routing_key,omitempty"` 30 | BrokerHostname string `json:"broker_hostname,omitempty"` 31 | Queue string `json:"queue,omitempty"` 32 | BrokerPassword string `json:"broker_password,omitempty"` 33 | BrokerVHost string `json:"broker_vhost,omitempty"` 34 | BrokerUsername string `json:"broker_username,omitempty"` 35 | OverrideSource string `json:"override_source,omitempty"` 36 | } 37 | -------------------------------------------------------------------------------- /graylog/graylog/input_gelf_tcp.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeGELFTCP is one of input types. 5 | InputTypeGELFTCP string = "org.graylog2.inputs.gelf.tcp.GELFTCPInput" 6 | ) 7 | 8 | // NewInputGELFTCPAttrs is the constructor of InputGELFTCPAttrs. 9 | func NewInputGELFTCPAttrs() InputAttrs { 10 | return &InputGELFTCPAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputGELFTCPAttrs) InputType() string { 15 | return InputTypeGELFTCP 16 | } 17 | 18 | // InputGELFTCPAttrs represents GELF TCP Input's attributes. 19 | type InputGELFTCPAttrs struct { 20 | MaxMessageSize int `json:"max_message_size,omitempty"` 21 | DecompressSizeLimit int `json:"decompress_size_limit,omitempty"` 22 | Port int `json:"port,omitempty" v-create:"required" v-update:"required"` 23 | RecvBufferSize int `json:"recv_buffer_size,omitempty" v-create:"required" v-update:"required"` 24 | BindAddress string `json:"bind_address,omitempty" v-create:"required" v-update:"required"` 25 | OverrideSource string `json:"override_source,omitempty"` 26 | TLSKeyFile string `json:"tls_key_file,omitempty"` 27 | TLSKeyPassword string `json:"tls_key_password,omitempty"` 28 | TLSClientAuthCertFile string `json:"tls_client_auth_cert_file,omitempty"` 29 | TLSClientAuth string `json:"tls_client_auth,omitempty"` 30 | TLSCertFile string `json:"tls_cert_file,omitempty"` 31 | UseNullDelimiter bool `json:"use_null_delimiter"` 32 | TLSEnable bool `json:"tls_enable"` 33 | TCPKeepAlive bool `json:"tcp_keepalive"` 34 | } 35 | -------------------------------------------------------------------------------- /graylog/graylog/ldap_setting.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-set/v6" 5 | ) 6 | 7 | // LDAPSetting represents a ldap settings. 8 | type LDAPSetting struct { 9 | Enabled bool `json:"enabled"` 10 | UseStartTLS bool `json:"use_start_tls"` 11 | TrustAllCertificates bool `json:"trust_all_certificates"` 12 | ActiveDirectory bool `json:"active_directory"` 13 | SystemUsername string `json:"system_username" v-create:"required" v-update:"required"` 14 | SystemPassword string `json:"system_password" v-create:"required" v-update:"required"` 15 | LDAPURI string `json:"ldap_uri" v-create:"required" v-update:"required"` 16 | SearchBase string `json:"search_base" v-create:"required" v-update:"required"` 17 | SearchPattern string `json:"search_pattern" v-create:"required" v-update:"required"` 18 | DisplayNameAttribute string `json:"display_name_attribute" v-create:"required" v-update:"required"` 19 | DefaultGroup string `json:"default_group" v-create:"required" v-update:"required"` 20 | GroupSearchBase string `json:"group_search_base,omitempty"` 21 | GroupIDAttribute string `json:"group_id_attribute,omitempty"` 22 | GroupSearchPattern string `json:"group_search_pattern,omitempty"` 23 | GroupMapping map[string]string `json:"group_mapping,omitempty"` 24 | AdditionalDefaultGroups set.StrSet `json:"additional_default_groups,omitempty"` 25 | } 26 | -------------------------------------------------------------------------------- /graylog/testdata/stream.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | ) 6 | 7 | func Stream() *graylog.Stream { 8 | return &graylog.Stream{ 9 | ID: "000000000000000000000003", 10 | Title: "test", 11 | IndexSetID: "5d84bfbe2ab79c000d35d4a9", 12 | CreatedAt: "2019-09-20T12:02:06.078Z", 13 | CreatorUserID: "admin", 14 | Description: "test", 15 | MatchingType: "AND", 16 | Outputs: []graylog.Output{}, 17 | Rules: []graylog.StreamRule{}, 18 | AlertConditions: []graylog.AlertCondition{}, 19 | AlertReceivers: &graylog.AlertReceivers{ 20 | Emails: []string{}, 21 | Users: []string{}, 22 | }, 23 | Disabled: false, 24 | RemoveMatchesFromDefaultStream: true, 25 | IsDefault: false, 26 | } 27 | } 28 | 29 | func CreateStreamReqBodyMap() map[string]interface{} { 30 | return map[string]interface{}{ 31 | "title": "test", 32 | "description": "test", 33 | "index_set_id": "5d84bfbe2ab79c000d35d4a9", 34 | "matching_type": "AND", 35 | "remove_matches_from_default_stream": true, 36 | } 37 | } 38 | 39 | func UpdateStreamReqBodyMap() map[string]interface{} { 40 | return map[string]interface{}{ 41 | "title": "updated title", 42 | "description": "updated description", 43 | "index_set_id": "5d84bfbe2ab79c000d35d4a9", 44 | "matching_type": "AND", 45 | "remove_matches_from_default_stream": true, 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /graylog/graylog/input_cef_tcp.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeCEFTCP is one of input types. 5 | InputTypeCEFTCP string = "org.graylog.plugins.cef.input.CEFTCPInput" 6 | ) 7 | 8 | // NewInputCEFTCPAttrs is the constructor of InputCEFTCPAttrs. 9 | func NewInputCEFTCPAttrs() InputAttrs { 10 | return &InputCEFTCPAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputCEFTCPAttrs) InputType() string { 15 | return InputTypeCEFTCP 16 | } 17 | 18 | // InputCEFTCPAttrs represents CEF TCP Input's attributes. 19 | type InputCEFTCPAttrs struct { 20 | UseNullDelimiter bool `json:"use_null_delimiter"` 21 | UseFullNames bool `json:"use_full_names"` 22 | TLSEnable bool `json:"tls_enable"` 23 | TCPKeepAlive bool `json:"tcp_keepalive"` 24 | MaxMessageSize int `json:"max_message_size,omitempty"` 25 | Port int `json:"port,omitempty" v-create:"required" v-update:"required"` 26 | RecvBufferSize int `json:"recv_buffer_size,omitempty" v-create:"required" v-update:"required"` 27 | Timezone string `json:"timezone,omitempty"` 28 | Locale string `json:"locale,omitempty"` 29 | BindAddress string `json:"bind_address,omitempty" v-create:"required" v-update:"required"` 30 | TLSKeyFile string `json:"tls_key_file,omitempty"` 31 | TLSClientAuth string `json:"tls_client_auth,omitempty"` 32 | TLSKeyPassword string `json:"tls_key_password,omitempty"` 33 | TLSClientAuthCertFile string `json:"tls_client_auth_cert_file,omitempty"` 34 | TLSCertFile string `json:"tls_cert_file,omitempty"` 35 | } 36 | -------------------------------------------------------------------------------- /graylog/testdata/event_definition/create/request.go: -------------------------------------------------------------------------------- 1 | package create 2 | 3 | import ( 4 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 5 | "github.com/suzuki-shunsuke/go-set/v6" 6 | ) 7 | 8 | func Request() *graylog.EventDefinition { 9 | return &graylog.EventDefinition{ 10 | ID: "", 11 | Title: "new-event-definition", 12 | Description: "", 13 | Priority: 2, 14 | Alert: true, 15 | FieldSpec: map[string]graylog.EventDefinitionFieldSpec{ 16 | "test": { 17 | DataType: "string", 18 | Providers: []interface{}{ 19 | map[string]interface{}{ 20 | "require_values": false, 21 | "template": "test", 22 | "type": "template-v1", 23 | }, 24 | }, 25 | }, 26 | }, 27 | KeySpec: set.NewStrSet("test"), 28 | NotificationSettings: graylog.EventDefinitionNotificationSettings{ 29 | GracePeriodMS: 0, 30 | BacklogSize: 0, 31 | }, 32 | Notifications: []graylog.EventDefinitionNotification{ 33 | { 34 | NotificationID: "5de5a365a1de18000cdfdf49", 35 | }, 36 | }, 37 | Storage: []interface{}{ 38 | map[string]interface{}{ 39 | "streams": []interface{}{ 40 | "000000000000000000000002", 41 | }, 42 | "type": "persist-to-streams-v1", 43 | }, 44 | }, 45 | Config: map[string]interface{}{ 46 | "conditions": map[string]interface{}{ 47 | "expression": nil, 48 | }, 49 | "execute_every_ms": 60000, 50 | "group_by": []interface{}{}, // p0 51 | "query": "test", 52 | "search_within_ms": 60000, 53 | "series": []interface{}{}, 54 | "streams": []interface{}{ 55 | "000000000000000000000001", 56 | }, 57 | "type": "aggregation-v1", 58 | }, 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /examples/v0.11/extractor.tf: -------------------------------------------------------------------------------- 1 | resource "graylog_extractor" "test_grok" { 2 | input_id = "${graylog_input.gelf_udp.id}" 3 | title = "test_grok" 4 | type = "grok" 5 | cursor_strategy = "copy" 6 | source_field = "message" 7 | target_field = "none" 8 | condition_type = "none" 9 | condition_value = "" 10 | order = 0 11 | 12 | grok_type_extractor_config { 13 | grok_pattern = "%%{DATA}" 14 | } 15 | } 16 | 17 | resource "graylog_extractor" "test_json" { 18 | input_id = "${graylog_input.gelf_udp.id}" 19 | title = "test" 20 | type = "json" 21 | cursor_strategy = "copy" 22 | source_field = "message" 23 | target_field = "none" 24 | condition_type = "none" 25 | condition_value = "" 26 | order = 0 27 | 28 | json_type_extractor_config { 29 | list_separator = ", " 30 | kv_separator = "=" 31 | key_prefix = "visit_" 32 | key_separator = "_" 33 | replace_key_whitespace = false 34 | key_whitespace_replacement = "_" 35 | } 36 | } 37 | 38 | resource "graylog_extractor" "test_regex" { 39 | input_id = "${graylog_input.gelf_udp.id}" 40 | title = "test_regex" 41 | type = "regex" 42 | cursor_strategy = "copy" 43 | 44 | source_field = "message" 45 | condition_type = "none" 46 | condition_value = "" 47 | order = 0 48 | 49 | regex_type_extractor_config { 50 | regex_value = ".*" 51 | } 52 | 53 | converters { 54 | type = "date" 55 | 56 | config { 57 | date_format = "yyyy/MM/ddTHH:mm:ss" 58 | time_zone = "Japan" 59 | locale = "en" 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /graylog/graylog/input_syslog_udp.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeSyslogUDP is one of input types. 5 | InputTypeSyslogUDP string = "org.graylog2.inputs.syslog.udp.SyslogUDPInput" 6 | ) 7 | 8 | // NewInputSyslogUDPAttrs is the constructor of InputSyslogUDPAttrs. 9 | func NewInputSyslogUDPAttrs() InputAttrs { 10 | return &InputSyslogUDPAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputSyslogUDPAttrs) InputType() string { 15 | return InputTypeSyslogUDP 16 | } 17 | 18 | // InputSyslogUDPAttrs represents SyslogUDP Input's attributes. 19 | type InputSyslogUDPAttrs struct { 20 | BindAddress string `json:"bind_address,omitempty" v-create:"required" v-update:"required"` 21 | Port int `json:"port,omitempty" v-create:"required" v-update:"required"` 22 | RecvBufferSize int `json:"recv_buffer_size,omitempty" v-create:"required" v-update:"required"` 23 | TCPKeepAlive bool `json:"tcp_keepalive"` 24 | TLSEnable bool `json:"tls_enable"` 25 | ThrottlingAllowed bool `json:"throttling_allowed"` 26 | EnableCORS bool `json:"enable_cors"` 27 | UseNullDelimiter bool `json:"use_null_delimiter"` 28 | ExchangeBind bool `json:"exchange_bind"` 29 | ForceRDNS bool `json:"force_rdns"` 30 | StoreFullMessage bool `json:"store_full_message"` 31 | ExpandStructuredData bool `json:"expand_structured_data"` 32 | AllowOverrideDate bool `json:"allow_override_date"` 33 | RequeueInvalidMessages bool `json:"requeue_invalid_messages"` 34 | UseFullNames bool `json:"use_full_names"` 35 | TLS bool `json:"tls"` 36 | } 37 | -------------------------------------------------------------------------------- /graylog/client/pipeline_rule.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/suzuki-shunsuke/go-graylog/v11/graylog/graylog" 7 | ) 8 | 9 | // GetPipelineRules returns all pipeline rules. 10 | func (client *Client) GetPipelineRules(ctx context.Context) ( 11 | []graylog.PipelineRule, *ErrorInfo, error, 12 | ) { 13 | rules := []graylog.PipelineRule{} 14 | ei, err := client.callGet( 15 | ctx, client.Endpoints().PipelineRules(), nil, &rules) 16 | return rules, ei, err 17 | } 18 | 19 | // GetPipelineRule returns a pipeline rule. 20 | func (client *Client) GetPipelineRule(ctx context.Context, id string) ( 21 | *graylog.PipelineRule, *ErrorInfo, error, 22 | ) { 23 | rule := &graylog.PipelineRule{} 24 | ei, err := client.callGet(ctx, client.Endpoints().PipelineRule(id), nil, rule) 25 | return rule, ei, err 26 | } 27 | 28 | // CreatePipelineRule creates a pipeline rule. 29 | func (client *Client) CreatePipelineRule( 30 | ctx context.Context, rule *graylog.PipelineRule, 31 | ) (*ErrorInfo, error) { 32 | return client.callPost( 33 | ctx, client.Endpoints().PipelineRules(), rule, rule) 34 | } 35 | 36 | // UpdatePipelineRule updates a pipeline rule. 37 | func (client *Client) UpdatePipelineRule( 38 | ctx context.Context, rule *graylog.PipelineRule, 39 | ) (*ErrorInfo, error) { 40 | u := client.Endpoints().PipelineRule(rule.ID) 41 | defer func(id string) { 42 | rule.ID = id 43 | }(rule.ID) 44 | rule.ID = "" 45 | return client.callPut(ctx, u, rule, rule) 46 | } 47 | 48 | // DeletePipelineRule deletes a pipeline rule. 49 | func (client *Client) DeletePipelineRule( 50 | ctx context.Context, id string, 51 | ) (*ErrorInfo, error) { 52 | return client.callDelete(ctx, client.Endpoints().PipelineRule(id), nil, nil) 53 | } 54 | -------------------------------------------------------------------------------- /graylog/graylog/input_gelf_amqp.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeGELFAMQP is one of input types. 5 | InputTypeGELFAMQP string = "org.graylog2.inputs.gelf.amqp.GELFAMQPInput" 6 | ) 7 | 8 | // NewInputGELFAMQPAttrs is the constructor of InputGELFAMQPAttrs. 9 | func NewInputGELFAMQPAttrs() InputAttrs { 10 | return &InputGELFAMQPAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputGELFAMQPAttrs) InputType() string { 15 | return InputTypeGELFAMQP 16 | } 17 | 18 | // InputGELFAMQPAttrs represents GELF AMQP Input's attributes. 19 | type InputGELFAMQPAttrs struct { 20 | ExchangeBind bool `json:"exchange_bind"` 21 | ThrottlingAllowed bool `json:"throttling_allowed"` 22 | TLS bool `json:"tls"` 23 | RequeueInvalidMessages bool `json:"requeue_invalid_messages"` 24 | BrokerVHost string `json:"broker_vhost,omitempty"` 25 | BrokerUsername string `json:"broker_username,omitempty"` 26 | Queue string `json:"queue,omitempty"` 27 | RoutingKey string `json:"routing_key,omitempty"` 28 | OverrideSource string `json:"override_source,omitempty"` 29 | BrokerHostname string `json:"broker_hostname,omitempty"` 30 | Exchange string `json:"exchange,omitempty"` 31 | BrokerPassword string `json:"broker_password,omitempty"` 32 | Prefetch int `json:"prefetch,omitempty"` 33 | Heartbeat int `json:"heartbeat,omitempty"` 34 | DecompressSizeLimit int `json:"decompress_size_limit,omitempty"` 35 | BrokerPort int `json:"broker_port,omitempty"` 36 | ParallelQueues int `json:"parallel_queues,omitempty"` 37 | } 38 | -------------------------------------------------------------------------------- /graylog/testdata/dashboard/dashboard.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "5d84c1a92ab79c000d35d6c7", 3 | "title": "test", 4 | "description": "test", 5 | "creator_user_id": "admin", 6 | "created_at": "2019-09-20T12:10:17.486Z", 7 | "positions": { 8 | "78ae7029-0eb4-4064-b3a0-c51306093877": { 9 | "width": 2, 10 | "col": 1, 11 | "row": 0, 12 | "height": 2 13 | }, 14 | "ede5fd51-6286-40ee-9b82-249207808344": { 15 | "width": 1, 16 | "col": 0, 17 | "row": 0, 18 | "height": 1 19 | } 20 | }, 21 | "widgets": [ 22 | { 23 | "creator_user_id": "admin", 24 | "cache_time": 10, 25 | "description": "Quick values", 26 | "id": "78ae7029-0eb4-4064-b3a0-c51306093877", 27 | "type": "QUICKVALUES", 28 | "config": { 29 | "timerange": { 30 | "type": "relative", 31 | "range": 300 32 | }, 33 | "field": "status", 34 | "stream_id": "5d84c1a92ab79c000d35d6ca", 35 | "query": "", 36 | "show_data_table": true, 37 | "limit": 5, 38 | "sort_order": "desc", 39 | "show_pie_chart": true, 40 | "data_table_limit": 60 41 | } 42 | }, 43 | { 44 | "creator_user_id": "admin", 45 | "cache_time": 10, 46 | "description": "Stream search result count change", 47 | "id": "ede5fd51-6286-40ee-9b82-249207808344", 48 | "type": "STREAM_SEARCH_RESULT_COUNT", 49 | "config": { 50 | "timerange": { 51 | "type": "relative", 52 | "range": 400 53 | }, 54 | "lower_is_better": true, 55 | "stream_id": "5d84c1a92ab79c000d35d6ca", 56 | "trend": true, 57 | "query": "" 58 | } 59 | } 60 | ] 61 | } 62 | -------------------------------------------------------------------------------- /graylog/graylog/input_gelf_http.go: -------------------------------------------------------------------------------- 1 | package graylog 2 | 3 | const ( 4 | // InputTypeGELFHTTP is one of input types. 5 | InputTypeGELFHTTP string = "org.graylog2.inputs.gelf.http.GELFHttpInput" 6 | ) 7 | 8 | // NewInputGELFHTTPAttrs is the constructor of InputGELFHTTPAttrs. 9 | func NewInputGELFHTTPAttrs() InputAttrs { 10 | return &InputGELFHTTPAttrs{} 11 | } 12 | 13 | // InputType is the implementation of the InputAttrs interface. 14 | func (attrs InputGELFHTTPAttrs) InputType() string { 15 | return InputTypeGELFHTTP 16 | } 17 | 18 | // InputGELFHTTPAttrs represents GELF HTTP Input's attributes. 19 | type InputGELFHTTPAttrs struct { 20 | IdleWriterTimeOut int `json:"idle_writer_timeout,omitempty"` 21 | RecvBufferSize int `json:"recv_buffer_size,omitempty" v-create:"required" v-update:"required"` 22 | MaxChunkSize int `json:"max_chunk_size,omitempty"` 23 | Port int `json:"port,omitempty" v-create:"required" v-update:"required"` 24 | DecompressSizeLimit int `json:"decompress_size_limit,omitempty"` 25 | TLSClientAuthCertFile string `json:"tls_client_auth_cert_file,omitempty"` 26 | BindAddress string `json:"bind_address,omitempty" v-create:"required" v-update:"required"` 27 | TLSCertFile string `json:"tls_cert_file,omitempty"` 28 | TLSKeyFile string `json:"tls_key_file,omitempty"` 29 | TLSKeyPassword string `json:"tls_key_password,omitempty"` 30 | TLSClientAuth string `json:"tls_client_auth,omitempty"` 31 | OverrideSource string `json:"override_source,omitempty"` 32 | TCPKeepAlive bool `json:"tcp_keepalive"` 33 | EnableCORS bool `json:"enable_cors"` 34 | TLSEnable bool `json:"tls_enable"` 35 | } 36 | --------------------------------------------------------------------------------