-
Notifications
You must be signed in to change notification settings - Fork 20
Added existing entity support and configuration hash support #52
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
base: master
Are you sure you want to change the base?
Changes from all commits
020ec56
4dcdd39
4c0738f
2fa7baf
6c95547
97a3d65
ae4e7ec
ddcc138
912fd06
fcf6dc9
d204b3f
c25b867
c7f5bd2
d632771
69837e5
bd55a4a
32cdcbc
43dba57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| site :opscode | ||
|
|
||
| metadata | ||
| cookbook "yum", "~> 2.0" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # | ||
| # Cookbook Name:: cloud_monitoring | ||
| # Recipe:: entity | ||
| # | ||
| # Configure the cloud_monitoring_entity LWRP to use the existing entity | ||
| # for the node by matching the server IP. | ||
| # | ||
| # Copyright 2014, Rackspace | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| # cm is defined in libraries/cloud_monitoring.rb | ||
| class Chef::Recipe | ||
| include Opscode::Rackspace::Monitoring | ||
| end | ||
|
|
||
| cm(defined?(node['cloud_monitoring']['rackspace_api_key']) ? node['cloud_monitoring']['rackspace_api_key'] : nil, | ||
| defined?(node['cloud_monitoring']['rackspace_username']) ? node['cloud_monitoring']['rackspace_username'] : nil, | ||
| defined?(node['cloud_monitoring']['rackspace_auth_url']) ? node['cloud_monitoring']['rackspace_auth_url'] : nil) | ||
|
|
||
| response = cm.list_entities.body | ||
|
|
||
|
|
||
| response["values"].each do |value| | ||
| unless value["ip_addresses"].nil? || node["cloud"].nil? | ||
| if value["ip_addresses"]["private0_v4"].eql? node["cloud"]["local_ipv4"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we check the ["cloud"]["local_ipv4"] for nil? to avoid breaking this on non-cloud servers?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. Perhaps
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Working on this one.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in bd55a4a |
||
| node.set['cloud_monitoring']['label'] = value["label"] | ||
| end | ||
| end | ||
| end | ||
|
|
||
| if node['cloud_monitoring']['label'].nil? | ||
| node.set['cloud_monitoring']['label'] = node.hostname | ||
| end | ||
|
|
||
| cloud_monitoring_entity node['cloud_monitoring']['label'] do | ||
| label node['cloud_monitoring']['label'] | ||
| agent_id node['cloud_monitoring']['agent']['id'] | ||
| rackspace_username node['cloud_monitoring']['rackspace_username'] | ||
| rackspace_api_key node['cloud_monitoring']['rackspace_api_key'] | ||
| action :create | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # | ||
| # Cookbook Name:: cloud_monitoring | ||
| # Recipe:: monitors | ||
| # | ||
| # Configure checks and alarms for Rackspace MaaS | ||
| # | ||
| # Copyright 2014, Rackspace | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| # Include dependency recipes | ||
| include_recipe "cloud_monitoring" | ||
| include_recipe "cloud_monitoring::agent" | ||
| include_recipe "cloud_monitoring::entity" | ||
|
|
||
| node['cloud_monitoring']['monitors'].each do |key, value| | ||
| cloud_monitoring_check key do | ||
| type "agent.#{value['type']}" | ||
| period value.has_key?('period') ? value['period'] : node['cloud_monitoring']['check_default']['period'] | ||
| timeout value.has_key?('timeout') ? value['timeout'] : node['cloud_monitoring']['check_default']['timeout'] | ||
| rackspace_username node['cloud_monitoring']['rackspace_username'] | ||
| rackspace_api_key node['cloud_monitoring']['rackspace_api_key'] | ||
| retries 2 | ||
| details value.has_key?('details') ? value['details'] : nil | ||
| action :create | ||
| end | ||
|
|
||
| if value.has_key?('alarm') | ||
| value["alarm"].each do |alarm, alarm_value| | ||
| # TODO: Add customizable messages, abstract the conditional more, etcetera... | ||
| criteria = "if (#{alarm_value["conditional"]}) { return #{alarm}, '#{key} is past #{alarm} threshold' }" | ||
|
|
||
| cloud_monitoring_alarm "#{value['type']} #{alarm} alarm" do | ||
| check_label key | ||
| criteria criteria | ||
| notification_plan_id node['cloud_monitoring']['notification_plan_id'] | ||
| action :create | ||
| end | ||
|
|
||
| end # alarm loop | ||
| end # has_key?('alarm') | ||
| end # monitors loop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd have gone with something like
next if value["ip_addresses"].nil? || node["cloud"].nil?, so that the next 3 lines aren't indented another level.