tas50/nagios — pull request #282 by oponder (2014-06-11 14:41:41+00:00)
Title: Refactor and merge wpietri's "just one host" branch into master. 

wpietri did some work in #212, but that was a while ago. Thanks again @wpietri! :D

Now I needed that functionality, but also wanted the latest from tas50/master.. So I went ahead and merged it.
While doing so I made an attempt to refactor the logic a bit.

**A question about hostgroup_name validity:**

In the original code there are some lines that check if the service is valid before it tries to define it.
It starts with this:
```
<% unless service['hostgroup_name'].nil? || service['hostgroup_name'] == "all" || (service['activate_check_in_environment'] && service['activate_check_in_environment'] != node.chef_environment )
```
My interpretation of that is that it does not want to allow hostgroup_names that == "all"

However, wpietri's code seems to have the opposite, and allow for a hostgroup_name that == 'all'
```
valid_hostgroup = !service['hostgroup_name'].nil? && (@hostgroups.include?(service['hostgroup_name']) || @search_hostgroups.include?(service['hostgroup_name']) || service['hostgroup_name'] == "all")
```

My brain is having a bit of a hard time with the "unless ||'s" though, but I sided in my refactoring with my understanding of the original code:

```
valid_hostgroup = service['hostgroup_name'] && service['hostgroup_name'] != "all" && host_groups_exist
````