-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from rundeck/log-filters
Log filters implemented by #131 Tested and worked great.
- Loading branch information
Showing
5 changed files
with
223 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -268,6 +268,44 @@ func TestAccJobOptions_secure_choice(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccJob_plugins(t *testing.T) { | ||
var job JobDetail | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccJobCheckDestroy(&job), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccJobConfig_plugins, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccJobCheckExists("rundeck_job.test", &job), | ||
func(s *terraform.State) error { | ||
jobCommand := job.CommandSequence.Commands[0] | ||
if jobCommand.Plugins == nil { | ||
return fmt.Errorf("JobCommands[0].plugins shouldn't be nil") | ||
} | ||
keyValuePlugin := jobCommand.Plugins.LogFilterPlugins[0] | ||
if expected := "key-value-data"; keyValuePlugin.Type != expected { | ||
return fmt.Errorf("wrong plugin type; expected %v, got %v", expected, keyValuePlugin.Type) | ||
} | ||
if expected := "\\s|\\$|\\{|\\}|\\\\"; (*keyValuePlugin.Config)["invalidKeyPattern"] != expected { | ||
return fmt.Errorf("failed to set plugin config; expected %v for \"invalidKeyPattern\", got %v", expected, (*keyValuePlugin.Config)["invalidKeyPattern"]) | ||
} | ||
if expected := "true"; (*keyValuePlugin.Config)["logData"] != expected { | ||
return fmt.Errorf("failed to set plugin config; expected %v for \"logData\", got %v", expected, (*keyValuePlugin.Config)["logData"]) | ||
} | ||
if expected := "^RUNDECK:DATA:\\s*([^\\s]+?)\\s*=\\s*(.+)$"; (*keyValuePlugin.Config)["regex"] != expected { | ||
return fmt.Errorf("failed to set plugin config; expected %v for \"regex\", got %v", expected, (*keyValuePlugin.Config)["regex"]) | ||
} | ||
return nil | ||
}, | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccJobConfig_basic = ` | ||
resource "rundeck_project" "test" { | ||
name = "terraform-acc-test-job" | ||
|
@@ -711,3 +749,57 @@ resource "rundeck_project" "test" { | |
} | ||
} | ||
` | ||
|
||
const testAccJobConfig_plugins = ` | ||
resource "rundeck_project" "test" { | ||
name = "terraform-acc-test-job" | ||
description = "parent project for job acceptance tests" | ||
resource_model_source { | ||
type = "file" | ||
config = { | ||
format = "resourcexml" | ||
file = "/tmp/terraform-acc-tests.xml" | ||
} | ||
} | ||
} | ||
resource "rundeck_job" "test" { | ||
project_name = "${rundeck_project.test.name}" | ||
name = "basic-job" | ||
description = "A basic job" | ||
execution_enabled = true | ||
node_filter_query = "example" | ||
allow_concurrent_executions = true | ||
nodes_selected_by_default = true | ||
success_on_empty_node_filter = true | ||
max_thread_count = 1 | ||
rank_order = "ascending" | ||
timeout = "42m" | ||
schedule = "0 0 12 * * * *" | ||
schedule_enabled = true | ||
option { | ||
name = "foo" | ||
default_value = "bar" | ||
} | ||
command { | ||
description = "Prints Hello World" | ||
shell_command = "echo Hello World" | ||
plugins { | ||
log_filter_plugin { | ||
config = { | ||
invalidKeyPattern = "\\s|\\$|\\{|\\}|\\\\" | ||
logData = "true" | ||
regex = "^RUNDECK:DATA:\\s*([^\\s]+?)\\s*=\\s*(.+)$" | ||
} | ||
type = "key-value-data" | ||
} | ||
} | ||
} | ||
notification { | ||
type = "on_success" | ||
email { | ||
recipients = ["[email protected]"] | ||
} | ||
} | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,21 +18,58 @@ Each job belongs to a project. A project can be created with the `rundeck_projec | |
|
||
```hcl | ||
resource "rundeck_job" "bounceweb" { | ||
name = "Bounce All Web Servers" | ||
project_name = "${rundeck_project.terraform.name}" | ||
node_filter_query = "tags: web" | ||
description = "Restart the service daemons on all the web servers" | ||
name = "Bounce All Web Servers" | ||
project_name = "${rundeck_project.terraform.name}" | ||
node_filter_query = "tags: web" | ||
description = "Restart the service daemons on all the web servers" | ||
command { | ||
shell_command = "sudo service anvils restart" | ||
} | ||
notification { | ||
type = "on_success" | ||
email { | ||
recipients = ["[email protected]"] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Example Usage (Key-Value Data Log filter to pass data between jobs) | ||
|
||
```hcl | ||
resource "rundeck_job" "update_review_environments" { | ||
name = "Update review environments" | ||
project_name = "${rundeck_project.terraform.name}" | ||
node_filter_query = "tags: dev_server" | ||
description = "Update the code in review environments checking out the given branch" | ||
command { | ||
description = null | ||
inline_script = "#!/bin/sh\nenvironment_numbers=$(find /var/review_environments -mindepth 3 -maxdepth 4 -name '$1' | awk -F/ -vORS=, '{ print $3 }' | sed 's/.$//')\necho \"RUNDECK:DATA:environment_numbers=\"$environment_numbers\"" | ||
script_file_args = "$${option.git_branch}" | ||
plugins { | ||
log_filter_plugin { | ||
config = { | ||
invalidKeyPattern = "\\s|\\$|\\{|\\}|\\\\" | ||
logData = "true" | ||
regex = "^RUNDECK:DATA:\\s*([^\\s]+?)\\s*=\\s*(.+)$" | ||
} | ||
type = "key-value-data" | ||
} | ||
} | ||
} | ||
command { | ||
shell_command = "sudo service anvils restart" | ||
job { | ||
args = "-environment_numbers $${data.environment_numbers}" | ||
name = "git_pull_review_environments" | ||
} | ||
} | ||
notification { | ||
type = "on_success" | ||
email { | ||
recipients = ["[email protected]"] | ||
} | ||
option { | ||
name = "git_branch" | ||
required = true | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
@@ -209,9 +246,10 @@ The following arguments are supported: | |
|
||
* A `job` block, described below, causes another job within the same project to be executed as | ||
a command. | ||
|
||
* A `step_plugin` block, described below, causes a step plugin to be executed as a command. | ||
|
||
* A `plugins` block, described below, contains a list of plugins to add to the command. At the moment, only [Log Filters](https://docs.rundeck.com/docs/manual/log-filters/) are supported | ||
|
||
* A `node_step_plugin` block, described below, causes a node step plugin to be executed once for | ||
each node. | ||
|
||
|
@@ -247,7 +285,11 @@ A command's `node_filters` block has the following structure: | |
|
||
* `exclude_filter`: (Optional) The query string for nodes ***not to use***. | ||
|
||
A command's `step_plugin` or `node_step_plugin` block both have the following structure, as does the job's | ||
A command's `plugins` block has the following structure: | ||
|
||
* `log_filter_plugin`: A log filter plugin to add to the command. Can be repeated to add multiple log filters. See below for the structure. | ||
|
||
A command's `log_filter_plugin`, `step_plugin` or `node_step_plugin` block both have the following structure, as does the job's | ||
`global_log_filter` blocks: | ||
|
||
* `type`: (Required) The name of the plugin to execute. | ||
|