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

Filters throwing failed: 'undefined method `sort' for nil:NilClass' error #374

Closed
rk295 opened this issue Jun 23, 2015 · 2 comments
Closed

Comments

@rk295
Copy link
Contributor

rk295 commented Jun 23, 2015

Hi,

I'm pretty new to sensu and the sensu puppet module and I'm not sure if I've hit a bug or I have my configuration wrong.

I have a filter defined as follows:

sensu::filter { 'keepalive_failures':
  negate        => false,
  attributes    => { }
}

This creates what appears to be a valid sensu config json file. However when I alter a handler to use this filter with the following config:

  sensu::handler { 'mail':
    filters     => ['keepalive_failures'],
    command => 'mail -s \'sensu alert\' robin@foo.com',
  }

A puppet run throws the following errors:

Error: undefined method `sort' for nil:NilClass
Error: /Stage[main]/Ids-sensu::Handlers/Sensu::Handler[mail]/Sensu_handler[mail]/filters: change from  to keepalive_failures failed: undefined method `sort' for nil:NilClass
Notice: /Stage[main]/Sensu::Server::Service/Service[sensu-server]: Dependency Sensu_handler[mail] has failures: true
Warning: /Stage[main]/Sensu::Server::Service/Service[sensu-server]: Skipping because of failed dependencies
Notice: /Stage[main]/Sensu/Anchor[sensu::end]: Dependency Sensu_handler[mail] has failures: true
Warning: /Stage[main]/Sensu/Anchor[sensu::end]: Skipping because of failed dependencies
Notice: Finished catalog run in 14.14 seconds
@somic
Copy link
Contributor

somic commented Jun 25, 2015

Ran into this as well today.

The problem is that handler config file on the filesystem does not include "filters" key (because its current default is undef). As a result, variable "is" at https://github.com/sensu/sensu-puppet/blob/master/lib/puppet/type/sensu_handler.rb#L74 is nil.

There are many ways how this can be fixed. sensu_handler type (see above) can check for nil. Or https://github.com/sensu/sensu-puppet/blob/master/lib/puppet/provider/sensu_handler/json.rb#L104 can become "conf['handlers'][resource[:name]]['filters'] || [ ]". Or default for $filters at https://github.com/sensu/sensu-puppet/blob/master/manifests/handler.pp#L72 can be changed to [ ] instead of undef, and add validate_array($filters).

The latter approach could be the best in the long run but by itself it will break puppet on the first run for all existing handlers. So probably better to edit sensu_handler json provider?

Thoughts?

rk295 added a commit to rk295/sensu-puppet that referenced this issue Jun 26, 2015
@rk295
Copy link
Contributor Author

rk295 commented Jun 26, 2015

Hi @somic thanks for this. I tried the first suggested fix but I get ...for nil:NilClass errors again, but this time for all handlers, even on subsequent runs.

The second fix works fine however, I've fixed that in my fork and I'll continue to use that until it gets fixed in master.

Thanks again!

jlambert121 added a commit that referenced this issue Jun 30, 2015
change default for filters param of sensu::handler (fix #374)
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

No branches or pull requests

2 participants