Sha256: 3d8f6eb77ebba1dbaba376f8d128d1581000b18a9e76055c12ade1f86dc0d6f3

Contents?: true

Size: 1.4 KB

Versions: 10

Compression:

Stored size: 1.4 KB

Contents

require 'chef/log'
require 'chef/search/query'

# Simplify access to list of all valid Nagios users
class NagiosUsers
  attr_accessor :users

  def initialize(node)
    @node = node
    @users = []

    user_databag = node['nagios']['users_databag'].to_sym
    group = node['nagios']['users_databag_group']

    if node['nagios']['server']['use_encrypted_data_bags']
      load_encrypted_databag(user_databag)
    else
      search_databag(user_databag, group)
    end
  end

  def return_user_contacts
    contacts = []
    # add base contacts from nagios_users data bag
    @users.each do |s|
      contacts << s['id']
    end
    contacts
  end

  private

  def fail_search(user_databag)
    Chef::Log.fatal("\"#{user_databag}\" databag could not be found.")
    raise "\"#{user_databag}\" databag could not be found."
  end

  def load_encrypted_databag(user_databag)
    Chef::DataBag.load(user_databag).each do |u, _|
      d = Chef::EncryptedDataBagItem.load(user_databag, u) # ~FC086
      @users << d unless d['nagios'].nil? || d['nagios']['email'].nil?
    end
  rescue Net::HTTPServerException
    fail_search(user_databag)
  end

  def search_databag(user_databag, group)
    Chef::Search::Query.new.search(user_databag, "groups:#{group} NOT action:remove") do |d|
      @users << d unless d['nagios'].nil? || d['nagios']['email'].nil?
    end
  rescue Net::HTTPServerException
    fail_search(user_databag)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
cloud-mu-2.0.4 cookbooks/nagios/libraries/users_helper.rb
cloud-mu-2.1.0beta cookbooks/nagios/libraries/users_helper.rb
cloud-mu-2.0.3 cookbooks/nagios/libraries/users_helper.rb
cloud-mu-2.0.2 cookbooks/nagios/libraries/users_helper.rb
cloud-mu-2.0.1 cookbooks/nagios/libraries/users_helper.rb
cloud-mu-2.0.0.pre.beta3 cookbooks/nagios/libraries/users_helper.rb
cloud-mu-2.0.0.pre.beta2 cookbooks/nagios/libraries/users_helper.rb
cloud-mu-2.0.0.pre.beta1 cookbooks/nagios/libraries/users_helper.rb
cloud-mu-2.0.0.pre.alpha9 cookbooks/nagios/libraries/users_helper.rb
cloud-mu-2.0.0.pre.alpha8 cookbooks/nagios/libraries/users_helper.rb