Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/check subdue #141

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .delivery/project.toml

This file was deleted.

2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: 2.5
Exclude:
- files/default/vendor/**/*
Style/FrozenStringLiteralComment:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This CHANGELOG follows the format located [here](https://github.com/sensu-plugin

## [Unreleased]

### Added

- Add support for new check subdue functionaltiy

## [1.4.0] - 2020-03-10

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ The sensu_check resource is used to define check objects.
* `runtime_assets` An array of [Sensu assets](https://docs.sensu.io/sensu-go/latest/reference/assets/) required at runtime for the execution of the `command`
* `secrets` An array of hashes of name/secret pairs to use with command execution
* `stdin` If the Sensu agent writes JSON serialized entity and check data to the command process' STDIN
* `subdues` An array of hashes to schedule a period when Sensu should not execute the check
* `subscriptions` **required** an array of Sensu entity subscriptions that check requests will be sent to
* `timeout` The check execution duration timeout in seconds
* `ttl` The value in seconds until check results are considered stale
Expand All @@ -308,6 +309,7 @@ sensu_check 'cron' do
publish false
ttl 100
secrets [{ "name": "AGGREGATE_USER_KEY", "secret": 'sensu-aggregate-key'}]
subdues [{ 'begin' => '2022-04-18T16:00:00-07:00', 'end' => '2022-04-18T17:00:00-07:00', 'repeat' => ['daily']}]
high_flap_threshold 60
low_flap_threshold 20
action :create
Expand Down
2 changes: 1 addition & 1 deletion libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def check_from_resource
spec['runtime_assets'] = new_resource.runtime_assets if new_resource.runtime_assets
spec['secrets'] = new_resource.secrets if new_resource.secrets
spec['stdin'] = new_resource.stdin
spec['subdue'] = new_resource.subdue if new_resource.subdue
spec['subdues'] = new_resource.subdues if new_resource.subdues
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are both valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion no, but it's unclear how the folks at Sensu intended to resolve this as the original subdue implementation still appears as null in the CheckConfig reference. See the YML output from their cron example check vs the actual subdues documentation section.

In practice one of my example checks using this new functionality lists both but I'm unable to set the original subdue as anything other than null:

type: Check
api_version: core/v2
metadata:
  created_by: s_sensu
  labels:
    sensu.io/managed_by: sensuctl
  name: check_process
  namespace: default
spec:
  check_hooks: null
  command: check_process.rb
  env_vars: null
  executed: 0
  handlers:
  high_flap_threshold: 0
  history: null
  interval: 15
  is_silenced: false
  issued: 0
  last_ok: 0
  low_flap_threshold: 0
  occurrences: 0
  occurrences_watermark: 0
  output: ""
  output_metric_format: ""
  output_metric_handlers: null
  pipelines: []
  proxy_entity_name: ""
  publish: true
  round_robin: false
  runtime_assets:
  - runtime_ruby
  scheduler: ""
  secrets: null
  status: 0
  stdin: false
  subdue: null
  subdues:
  - begin: "2022-04-18T16:00:00-05:00"
    end: "2022-04-18T17:00:00-05:00"
    repeat:
    - weekdays
  - begin: "2022-04-22T16:00:00-05:00"
    end: "2022-04-22T17:00:00-05:00"
    repeat:
    - fridays
  - begin: "2022-04-23T00:00:00-05:00"
    end: "2022-04-23T23:59:59-05:00"
    repeat:
    - saturdays
  - begin: "2022-04-24T00:00:00-05:00"
    end: "2022-04-24T17:00:00-05:00"
    repeat:
    - sundays
  subscriptions:
  - check_process
  timeout: 0
  total_state_change: 0
  ttl: 0

spec['subscriptions'] = new_resource.subscriptions
spec['timeout'] = new_resource.timeout if new_resource.timeout
spec['ttl'] = new_resource.ttl if new_resource.ttl
Expand Down
1 change: 1 addition & 0 deletions resources/active_directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_active_directory
provides :sensu_active_directory
unified_mode true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the min version of chef is required to use this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unified Mode is unavailable prior to 14.14 according to the docs. I've been adding these to appease cookstyle in my dev environment but isn't strictly necessary for this change.


action_class do
include SensuCookbook::Helpers
Expand Down
1 change: 1 addition & 0 deletions resources/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

resource_name :sensu_agent
provides :sensu_agent
unified_mode true

include SensuCookbook::Helpers
include SensuCookbook::SensuPackageProperties
Expand Down
1 change: 1 addition & 0 deletions resources/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_asset
provides :sensu_asset
unified_mode true
provides :sensu_go_asset

property :filters, Array
Expand Down
1 change: 1 addition & 0 deletions resources/auth_ldap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_auth_ldap
provides :sensu_auth_ldap
unified_mode true

action_class do
include SensuCookbook::Helpers
Expand Down
1 change: 1 addition & 0 deletions resources/auth_oidc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_auth_oidc
provides :sensu_auth_oidc
unified_mode true

action_class do
include SensuCookbook::Helpers
Expand Down
1 change: 1 addition & 0 deletions resources/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

resource_name :sensu_backend
provides :sensu_backend
unified_mode true

include SensuCookbook::Helpers
include SensuCookbook::SensuPackageProperties
Expand Down
3 changes: 2 additions & 1 deletion resources/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_check
provides :sensu_check
unified_mode true
provides :sensu_go_check

property :check_hooks, Array
Expand All @@ -44,7 +45,7 @@
property :runtime_assets, Array
property :secrets, Array
property :stdin, [true, false], default: false
property :subdue, Hash
property :subdues, Array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if they are both supported then we should add rather than change an interface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my previous comment. I wanted to avoid confusion by aligning with the actual Check Resource name.

property :subscriptions, Array, required: true
property :timeout, Integer
property :ttl, Integer
Expand Down
1 change: 1 addition & 0 deletions resources/cluster_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_cluster_role
provides :sensu_cluster_role
unified_mode true

# rubocop:disable Style/TrailingCommaInHashLiteral
property :rules, Array, required: true, callbacks: {
Expand Down
1 change: 1 addition & 0 deletions resources/cluster_role_binding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_cluster_role_binding
provides :sensu_cluster_role_binding
unified_mode true

property :role_name, String, required: true
property :role_type, String, required: true, equal_to: %w(Role ClusterRole)
Expand Down
1 change: 1 addition & 0 deletions resources/ctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

resource_name :sensu_ctl
provides :sensu_ctl
unified_mode true

include SensuCookbook::SensuPackageProperties

Expand Down
1 change: 1 addition & 0 deletions resources/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_entity
provides :sensu_entity
unified_mode true

action_class do
include SensuCookbook::Helpers
Expand Down
1 change: 1 addition & 0 deletions resources/etcd_replicator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_etcd_replicator
provides :sensu_etcd_replicator
unified_mode true

action_class do
include SensuCookbook::Helpers
Expand Down
1 change: 1 addition & 0 deletions resources/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_filter
provides :sensu_filter
unified_mode true
provides :sensu_go_filter

property :filter_action, String, equal_to: %w(allow deny), required: true
Expand Down
1 change: 1 addition & 0 deletions resources/global_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_global_config
provides :sensu_global_config
unified_mode true

action_class do
include SensuCookbook::Helpers
Expand Down
1 change: 1 addition & 0 deletions resources/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_handler
provides :sensu_handler
unified_mode true
provides :sensu_go_handler

property :command, String # only allowed if type == pipe
Expand Down
1 change: 1 addition & 0 deletions resources/hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_hook
provides :sensu_hook
unified_mode true

property :command, String, required: true
property :timeout, Integer
Expand Down
1 change: 1 addition & 0 deletions resources/mutator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_mutator
provides :sensu_mutator
unified_mode true
provides :sensu_go_mutator

property :command, String, required: true
Expand Down
1 change: 1 addition & 0 deletions resources/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

resource_name :sensu_namespace
provides :sensu_namespace
unified_mode true

action_class do
include SensuCookbook::Helpers
Expand Down
1 change: 1 addition & 0 deletions resources/postgres_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_postgres_config
provides :sensu_postgres_config
unified_mode true

property :dsn, String, required: true
property :pool_size, Integer
Expand Down
1 change: 1 addition & 0 deletions resources/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_role
provides :sensu_role
unified_mode true

property :namespace, String, default: 'default'
# rubocop:disable Style/TrailingCommaInHashLiteral
Expand Down
1 change: 1 addition & 0 deletions resources/role_binding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_role_binding
provides :sensu_role_binding
unified_mode true

property :namespace, String, default: 'default'
property :role_name, String, required: true
Expand Down
1 change: 1 addition & 0 deletions resources/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_search
provides :sensu_search
unified_mode true

property :namespace, String, default: 'default'
property :parameters, Array, required: true, callbacks: {
Expand Down
1 change: 1 addition & 0 deletions resources/secret.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_secret
provides :sensu_secret
unified_mode true

action_class do
include SensuCookbook::Helpers
Expand Down
1 change: 1 addition & 0 deletions resources/secrets_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_secrets_provider
provides :sensu_secrets_provider
unified_mode true

action_class do
include SensuCookbook::Helpers
Expand Down
1 change: 1 addition & 0 deletions resources/tessen_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

resource_name :sensu_tessen_config
provides :sensu_tessen_config
unified_mode true

action_class do
include SensuCookbook::Helpers
Expand Down
1 change: 1 addition & 0 deletions resources/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

resource_name :sensu_user
provides :sensu_user
unified_mode true

include SensuCookbook::Helpers::SensuCtl
include SensuCookbook::SensuCommonProperties
Expand Down
18 changes: 14 additions & 4 deletions test/cookbooks/sensu_test/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@
ttl 100
high_flap_threshold 60
low_flap_threshold 20
subdue(days: { all: [{ begin: '12:00 AM', end: '11:59 PM' },
{ begin: '11:00 PM', end: '1:00 AM' }] })
subdues [
{
'begin' => '2022-04-18T16:00:00-07:00',
'end' => '2022-04-18T17:00:00-07:00',
'repeat' => ['daily'],
},
]
action :create
end

Expand All @@ -57,8 +62,13 @@
ttl 100
high_flap_threshold 60
low_flap_threshold 20
subdue(days: { all: [{ begin: '12:00 AM', end: '11:59 PM' },
{ begin: '11:00 PM', end: '1:00 AM' }] })
subdues [
{
'begin' => '2022-04-18T16:00:00-07:00',
'end' => '2022-04-18T17:00:00-07:00',
'repeat' => ['daily'],
},
]
action :create
end

Expand Down
12 changes: 4 additions & 8 deletions test/integration/default/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@
its(%w(spec subscriptions)) { should include 'production' }
its(%w(spec handlers)) { should include 'pagerduty' }
its(%w(spec handlers)) { should include 'email' }
its(['spec', 'subdue', 'days', 'all', 0, 'begin']) { should eq '12:00 AM' }
its(['spec', 'subdue', 'days', 'all', 0, 'end']) { should eq '11:59 PM' }
its(['spec', 'subdue', 'days', 'all', 1, 'begin']) { should eq '11:00 PM' }
its(['spec', 'subdue', 'days', 'all', 1, 'end']) { should eq '1:00 AM' }
its(['spec', 'subdues', 0, 'begin']) { should eq '2022-04-18T16:00:00-07:00' }
its(['spec', 'subdues', 0, 'end']) { should eq '2022-04-18T17:00:00-07:00' }
end

describe json('/etc/sensu/checks/cron-test-org.json') do
Expand All @@ -80,10 +78,8 @@
its(%w(spec subscriptions)) { should include 'production' }
its(%w(spec handlers)) { should include 'pagerduty' }
its(%w(spec handlers)) { should include 'email' }
its(['spec', 'subdue', 'days', 'all', 0, 'begin']) { should eq '12:00 AM' }
its(['spec', 'subdue', 'days', 'all', 0, 'end']) { should eq '11:59 PM' }
its(['spec', 'subdue', 'days', 'all', 1, 'begin']) { should eq '11:00 PM' }
its(['spec', 'subdue', 'days', 'all', 1, 'end']) { should eq '1:00 AM' }
its(['spec', 'subdues', 0, 'begin']) { should eq '2022-04-18T16:00:00-07:00' }
its(['spec', 'subdues', 0, 'end']) { should eq '2022-04-18T17:00:00-07:00' }
end

%w(http docker postgres).each do |p|
Expand Down