dpeters / puppet-opsview

Puppet types/providers to support Opsview resources
12 stars 10 forks source link

Hiera Support? #29

Open voxter opened 9 years ago

voxter commented 9 years ago

Hi there,

Just wondering if you could provide an example snippet of how this module would be configured via Hiera, if supported at all?

Thanks!

antaflos commented 9 years ago

What is it you'd like to do? There is no inherent Hiera support in this module but there shouldn't be any, anyway. This module is a component module or "base block" and provides types that do specific things within an Opsview installation. It doesn't do Hiera or anything else outside of that.

But you can wrap any of the opsview_* types in a profile or other kind of wrapper class and add Hiera support that way. See https://ask.puppetlabs.com/question/1655/an-end-to-end-roleprofile-example-using-hiera/ and http://garylarizza.com/blog/2014/02/17/puppet-workflow-part-2/ (and related articles) for good reads about the roles/profiles pattern.

An example Opsview server profile class could look like this (you might want to use better names):

class profile::opsview::server {
  $opsview_servicegroups = hiera_hash('profile::opsview::server::servicegroups', {})
  create_resources('opsview_servicegroup', $opsview_servicegroups)

  $opsview_hostgroups = hiera_hash('profile::opsview::server::hostgroups', {})
  create_resources('opsview_hostgroup', $opsview_hostgroups)

  $opsview_hosttemplates = hiera_hash('profile::opsview::server::hosttemplates', {})
  create_resources('opsview_hosttemplate', $opsview_hosttemplates)

  # ...

  # Collect and realize any exported opsview_monitored resources (from
  # Opsview agents, i.e. nodes that include `profile::opsview::agent`
  Opsview_monitored <<||>>
}

An example Opsview agent (client) profile could look like this:

class profile::opsview::agent {
  $hostgroup = hiera('profile::opsview::agent::hostgroup')
  $hosttemplates = hiera_array('profile::opsview::agent::hosttemplates', [])
  $servicechecks = hiera_array('profile::opsview::agent::servicechecks', [])
  # ...

  @@opsview_monitored { $::fqdn:
    ensure         => 'present',
    ip             => $::fqdn,
    hostgroup      => $hostgroup,
    hosttemplates  => $hosttemplates,
    servicechecks  => $servicechecks,
    parents        => $parents,
    reload_opsview => true,
    icon_name      => $icon_name,
  }
}

Note that these are examples only, incomplete and of course not functional as defined above. But they should help visualise the way we can use the power of abstraction to make this module (or rather, the types provided) more useful. We use something similar in our infrastructure, but a bit more complex (we should simplify a few things, actually).

Hope that helps. I'd love to contribute more to this module and make it a proper "base block" that can install Opsview server and client/agent and maybe provide sensible wrappers around the specific types (i.e. opsview::servicecheck wraps opsview_servicecheck but sets reload_opsview => true and notification_options = 'w,c,r,u,f'by default). I'd also like to provide an example "full-stack" profile (with Hiera support) that can be used or extended by others.

Alas, we are currently swamped with other, less fun projects and don't have much time for Opsview. It might take a few weeks or even months before we can contribute something useful :(