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

Changes to allow monitoring for mixed private/public environments #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
default['munin']['web_server_port'] = 80
default['munin']['public_domain'] = nil

default['munin']['monitoring_interface'] = nil
default['munin']['users_group'] = 'sysadmins'

case node['platform']
when 'arch'
default['munin']['basedir'] = '/etc/munin'
Expand Down
43 changes: 43 additions & 0 deletions libraries/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Original Author:: Joshua Sierles <[email protected]>
# Original Author:: Tim Smith <[email protected]>
# 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

2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 3 additions & 1 deletion recipes/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion templates/default/munin.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
Expand Down