From e4ec00dd8d255f6bf1b326ceb902721d2f6010fa Mon Sep 17 00:00:00 2001 From: Seth Kingry Date: Wed, 17 Sep 2014 21:40:10 -0400 Subject: [PATCH 1/2] Changes to allow monitoring for mixed private/public environments --- attributes/default.rb | 2 ++ libraries/default.rb | 43 ++++++++++++++++++++++++++++++++ metadata.rb | 2 +- templates/default/munin.conf.erb | 2 +- 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 libraries/default.rb diff --git a/attributes/default.rb b/attributes/default.rb index 939801c..eaf9690 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -27,6 +27,8 @@ default['munin']['web_server_port'] = 80 default['munin']['public_domain'] = nil +default['munin']['monitoring_interface'] = nil + case node['platform'] when 'arch' default['munin']['basedir'] = '/etc/munin' diff --git a/libraries/default.rb b/libraries/default.rb new file mode 100644 index 0000000..488aa11 --- /dev/null +++ b/libraries/default.rb @@ -0,0 +1,43 @@ +# +# Original Author:: Joshua Sierles +# Original Author:: Tim Smith +# Original Source:: https://github.com/tas50/nagios/blob/master/libraries/default.rb +# +# Cookbook Name:: munin +# Library:: default +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# decide whether to use internal or external IP addresses for this node +# if the munin server is not in the cloud, always use public IP addresses for cloud nodes. +# if the munin server is in the cloud, use private IP addresses for any +# cloud servers in the same cloud, public IPs for servers in other clouds +# (where other is defined by node['cloud']['provider']) +# if the cloud IP is nil then use the standard IP address attribute. This is a work around +# for OHAI incorrectly identifying systems on Cisco hardware as being in Rackspace +def ip_to_monitor(monitored_host, server_host = node) + # if interface to monitor is specified implicitly use that + if node['munin']['monitoring_interface'] && node['network']["ipaddress_#{node['munin']['monitoring_interface']}"] + node['network']["ipaddress_#{node['munin']['monitoring_interface']}"] + # if server is not in the cloud and the monitored host is + elsif server_host['cloud'].nil? && monitored_host['cloud'] + monitored_host['cloud']['public_ipv4'].include?('.') ? monitored_host['cloud']['public_ipv4'] : monitored_host['ipaddress'] + # if server host is in the cloud and the monitored node is as well, but they are not on the same provider + elsif server_host['cloud'] && monitored_host['cloud'] && monitored_host['cloud']['provider'] != server_host['cloud']['provider'] + monitored_host['cloud']['public_ipv4'].include?('.') ? monitored_host['cloud']['public_ipv4'] : monitored_host['ipaddress'] + else + monitored_host['ipaddress'] + end +end + diff --git a/metadata.rb b/metadata.rb index 23e4f78..c1900e8 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache 2.0' description 'Installs and configures munin' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '1.4.3' +version '1.5.0' depends 'apache2', '>= 1.7' depends 'nginx', '>= 1.8' diff --git a/templates/default/munin.conf.erb b/templates/default/munin.conf.erb index 2747e55..127338a 100644 --- a/templates/default/munin.conf.erb +++ b/templates/default/munin.conf.erb @@ -27,7 +27,7 @@ includedir <%= node['munin']['basedir'] %>/munin-conf.d # a simple host tree <% @munin_nodes.each do |system| -%> [<%= system['fqdn'] %>] - address <%= system['ipaddress'] %> + address <%= ip_to_monitor(system) %> use_node_name yes <% end -%> From 72c8d46a8423ab8f2aa20ee122b9d1706d595cf0 Mon Sep 17 00:00:00 2001 From: Seth Kingry Date: Wed, 17 Sep 2014 23:23:39 -0400 Subject: [PATCH 2/2] Added the ability to override the users group search for htpasswd --- attributes/default.rb | 1 + recipes/server.rb | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/attributes/default.rb b/attributes/default.rb index eaf9690..9515e3f 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -28,6 +28,7 @@ default['munin']['public_domain'] = nil default['munin']['monitoring_interface'] = nil +default['munin']['users_group'] = 'sysadmins' case node['platform'] when 'arch' diff --git a/recipes/server.rb b/recipes/server.rb index 57feaf0..85b751b 100644 --- a/recipes/server.rb +++ b/recipes/server.rb @@ -51,10 +51,12 @@ include_recipe 'munin::client' sysadmins = [] +users_group = node['munin']['users_group'] + if Chef::Config[:solo] sysadmins = data_bag('users').map { |user| data_bag_item('users', user) } else - sysadmins = search(:users, 'groups:sysadmin') + sysadmins = search(:users, "groups:#{users_group}") end if Chef::Config[:solo]