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

Add custom variables to subscriptions #225

Merged
merged 2 commits into from
Oct 3, 2014

Conversation

bodgit
Copy link
Contributor

@bodgit bodgit commented Aug 19, 2014

This PR adds the ability to define custom variables with subscriptions. The use case for this is when I'm using sensu::subscription's in my various modules to subscribe to classes of checks that are scheduled on the server, but the server might not necessarily be pointing to the same resources as the client and so I'd like to make use of Sensu's :::parameter.name::: syntax. Trying to set all of the module-specific variables in my one class that installs the base Sensu client becomes messy and polluted with variables that don't belong there so it's tidier if they can be defined with the subscription that will ultimately use them.

I copied the code in the other types and also added some tests, (the sensu_subscription_spec.rb was empty previously so I just based them off the other definition tests).

@jamtur01
Copy link
Contributor

@jlambert121 Any thoughts?

@bodgit
Copy link
Contributor Author

bodgit commented Sep 30, 2014

Bueller?

@jamtur01
Copy link
Contributor

@bodgit Waiting for some input from @jlambert121 although @rodjek might also have views.

@jlambert121
Copy link
Contributor

Sorry for the delay. After a year of writing javascript my ruby is getting rusty. I like the concept of what this is doing by utilizing the sensu variables. Are you not able to put the variable you're looking for in the command parameter in puppet?

@bodgit
Copy link
Contributor Author

bodgit commented Sep 30, 2014

Putting the variables directly into Puppet doesn't really help. Assume the following horribly contrived classes on a Sensu client that happens to be a RabbitMQ broker:

class mysensu {
  class { '::sensu':
    client => true,
  }

  ensure_packages(['nagios-plugin-http', 'nagios-plugin-...'])

  ...
}

class myrabbitmq (
  my_default_user,
  my_default_pass,
) {
  class { '::rabbitmq':
    default_user => $my_default_user,
    default_pass => $my_default_pass,
  }

  ::sensu::subscription { 'rabbitmq':
    custom => {
      rabbitmq => {
        check_user => $my_default_user,
        check_pass => $my_default_pass,
      },
    },
  }
}

Then on my Sensu server I have the following check defined:

::sensu::check { 'rabbitmq':
  command => 'check_http -I 127.0.0.1 -u /api/aliveness-test/%2f -p 15672 -a ":::rabbitmq.check_user:::":":::rabbitmq.check_pass:::"',
  subscribers => [
    'rabbitmq',
  ],
  ...
}

I can build multiple RabbitMQ servers each with different credentials and the Sensu server doesn't need to know what they are, nor do I need to define multiple checks with the credentials hardcoded for each permutation.

While I could add the custom parameters in the main sensu client class, it doesn't make sense to pollute it with RabbitMQ-specific parameters.

Does that help explain things?

jamtur01 added a commit that referenced this pull request Oct 3, 2014
Add custom variables to subscriptions
@jamtur01 jamtur01 merged commit 64214df into sensu:master Oct 3, 2014
@jamtur01
Copy link
Contributor

jamtur01 commented Oct 3, 2014

Thanks!

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

Successfully merging this pull request may close these issues.

3 participants