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

(#597) Add sensu::contact type (Enterprise Only) #728

Merged
merged 1 commit into from
Jul 11, 2017

Conversation

jeffmccune
Copy link
Collaborator

Without this patch the Puppet module doesn't provide an affordance for contact
routing
This
patch addresses the problem by adding a new defined type, sensu::contact backed
by a custom type and provider for sensu_contact.

Example usage:

sensu::contact { 'support':
  config => { 'email'  => { 'to' => 'support@example.com' } },
}
sensu::contact { 'ops':
  config => { 'email'  => { 'to' => 'ops@example.com' } },
}
sensu::check { 'check_ntp':
  command  => 'PATH=$PATH:/usr/lib64/nagios/plugins check_ntp_time -H pool.ntp.org -w 30 -c 60',
  handlers => 'email',
  contacts => ['ops', 'support'],
}

Resolves #597

@jeffmccune
Copy link
Collaborator Author

Tested in Vagrant using sensu-server-enterprise

@@ -69,6 +69,15 @@ def insync?(is)
end
end

newproperty(:contacts, :array_matching => :all, :parent => SensuCheckArrayProperty) do
desc "Contact names to override handler configuration via Contact Routing"
newvalues(/.*/, :absent)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Regex has been added both to sensu_check's contacts property and sensu_contact's name parameter. Spec tests have been updated to exercise the expected behavior of invalid names throwing Puppet::ResourceError's.

before => Sensu_contact[$name],
}

sensu_contact { $name:
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of a type/provider, what about using sensu_sorted_json() as is done in sensu::write_json? The current layout is to used defined types that then call custom type/providers. What about still calling defined types, but then replacing the type/provider code with sensu_sorted_json()? If possible, I think that would greatly simplify things.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we still use resources {} to purge?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll take a look. This also reminds me, self.instances needs to be implemented in the type if we don't implement this using sensu_sorted_json().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Filed #729 to track this independently of this PR and related enhancement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added this documentation to the sensu::contact defined type:

Note: If the sensu::purge_config class parameter is true, unmanaged sensu::contact resources located in /etc/sensu/conf.d/contacts will be purged.

ensure => 'present',
config => { 'email' => { 'to' => 'ops@example.com' } },
}
sensu::contact { 'hacker':
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggest using another name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to “departed"

@jeffmccune jeffmccune force-pushed the 597_add_contact_routing_type branch from 2cd45f6 to 3cfe2a8 Compare July 11, 2017 17:36
@@ -144,7 +144,7 @@
}
}

file { [ $::sensu::conf_dir, "${sensu::conf_dir}/handlers", "${sensu::conf_dir}/checks", "${sensu::conf_dir}/filters", "${sensu::conf_dir}/extensions", "${sensu::conf_dir}/mutators" ]:
file { [ $::sensu::conf_dir, "${sensu::conf_dir}/handlers", "${sensu::conf_dir}/checks", "${sensu::conf_dir}/filters", "${sensu::conf_dir}/extensions", "${sensu::conf_dir}/mutators", "${sensu::conf_dir}/contacts" ]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

purge is there

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Got it, added documentation to sensu::contact to note this purge behavior.

ensure => $ensure,
config => $config,
base_path => $base_path,
require => File['/etc/sensu/conf.d/contacts'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this notify the service?

Copy link
Collaborator

Choose a reason for hiding this comment

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

i see it is in the type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct

@ghoneycutt
Copy link
Collaborator

Please add the example usage to the README. Besides that, else I think it's ready.

@jeffmccune
Copy link
Collaborator Author

Please add the example usage to the README. Besides that, else I think it's ready.

README updated with a similar example to the vagrant manifest in tests/sensu-server-enterprise.pp.

# = Define: sensu::routing
#
# Manage [Contact
# Routing](https://sensuapp.org/docs/0.26/enterprise/contact-routing.html)
Copy link
Collaborator

Choose a reason for hiding this comment

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

we're on 0.29. Best to use latest here though

https://sensuapp.org/docs/latest/enterprise/contact-routing.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated to latest.

Without this patch the Puppet module doesn't provide an affordance for [contact
routing](https://sensuapp.org/docs/0.29/enterprise/contact-routing.html)  This
patch addresses the problem by adding a new defined type, sensu::contact backed
by a custom type and provider for sensu_contact.

Example usage:

    sensu::contact { 'support':
      config => { 'email'  => { 'to' => 'support@example.com' } },
    }
    sensu::contact { 'ops':
      config => { 'email'  => { 'to' => 'ops@example.com' } },
    }
    sensu::check { 'check_ntp':
      command     => 'PATH=$PATH:/usr/lib64/nagios/plugins check_ntp_time -H pool.ntp.org -w 30 -c 60',
      handlers    => 'email',
      contacts    => ['ops', 'support'],
    }

Resolves sensu#597
@jeffmccune jeffmccune force-pushed the 597_add_contact_routing_type branch from fae56f7 to 4d767b2 Compare July 11, 2017 19:19
@ghoneycutt ghoneycutt merged commit 1f46028 into sensu:master Jul 11, 2017
@ghoneycutt
Copy link
Collaborator

Released in v2.20.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants