zabbix-cloudwatch 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +24 -0
- data/LICENSE +20 -0
- data/README.md +74 -0
- data/bin/zabbix-cloudwatch +66 -0
- data/lib/zabbix-cloudwatch.rb +121 -0
- data/lib/zabbix-cloudwatch/version.rb +4 -0
- data/zabbix-cloudwatch.gemspec +23 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA512:
|
3
|
+
metadata.gz: 1f1af98510d9a03961e30e98ca5f7f74a4d94dc5f86d7a987735d7d307b0584763f175dcfdc64a9e663e6303f1027c49fa19befd9d09984b38932d718e8c2dd0
|
4
|
+
data.tar.gz: 20c109761c48187c3d90a7eb831cea90542381c6528256ebb16fd5d5e9496d3fd8e5b96e00cd4f28bde249e22d1d5b080766fd711d55e0aea83e5852fabf0d88
|
5
|
+
SHA1:
|
6
|
+
metadata.gz: bc4b6e0406f4614781ee2dddc679d7387a30b2fe
|
7
|
+
data.tar.gz: 6d29fa50fe3a095e30cc1435c8348131c0dc41dc
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
zabbix-cloudwatch (0.0.1)
|
5
|
+
aws-sdk (~> 1.21.0)
|
6
|
+
getopt (~> 1.4.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
aws-sdk (1.21.0)
|
12
|
+
json (~> 1.4)
|
13
|
+
nokogiri (>= 1.4.4, < 1.6.0)
|
14
|
+
uuidtools (~> 2.1)
|
15
|
+
getopt (1.4.1)
|
16
|
+
json (1.8.0)
|
17
|
+
nokogiri (1.5.10)
|
18
|
+
uuidtools (2.1.4)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
zabbix-cloudwatch!
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Randy D. Wallace Jr.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# zabbix-cloudwatch
|
2
|
+
|
3
|
+
|
4
|
+
An external script for getting cloudwatch metrics into Zabbix
|
5
|
+
|
6
|
+
```
|
7
|
+
Usage: get_aws_cloudwatch_metric.rb
|
8
|
+
|
9
|
+
-h, --help This Message
|
10
|
+
-n, --namespace Namespace (AWS/Autoscaling, AWS/EC2, etc...)
|
11
|
+
-m, --metricname Metric Name (GroupInServiceInstances,EstimatedCharges, etc...)
|
12
|
+
-d, --dimension-name Dimension Name (AutoScalingGroupName, etc...)
|
13
|
+
-v, --dimension-value Dimension Value
|
14
|
+
-t, --monitoring-type detailed|basic Default: basic
|
15
|
+
-s, --statistic Minimum|Maximum|Average|Sum|SampleCount Default: Average
|
16
|
+
```
|
17
|
+
|
18
|
+
## Getting it running
|
19
|
+
|
20
|
+
* It is only guaranteed to work on ruby 1.8.7 at this time.
|
21
|
+
* for some of the gem dependencies, you will need the ruby development packages, gcc, libxml2, and libxslt
|
22
|
+
|
23
|
+
Modify these steps to taste (examples given running on the Amazon AMI 2013.03):
|
24
|
+
```
|
25
|
+
# git clone git@github.com:randywallace/zabbix-cloudwatch.git /usr/local/zabbix-cloudwatch
|
26
|
+
# cd /usr/local/zabbix-cloudwatch
|
27
|
+
# chown zabbix:zabbix get_aws_cloudwatch_metric.rb
|
28
|
+
# yum install ruby ruby-devel rubygems gcc libxml2-devel libxslt-devel
|
29
|
+
# gem install bundler
|
30
|
+
# bundle install
|
31
|
+
# ln -s /usr/local/zabbix-cloudwatch/get_aws_cloudwatch_metric.rb /var/lib/zabbixsrv/externalscripts/get_aws_cloudwatch_metric.rb
|
32
|
+
```
|
33
|
+
|
34
|
+
## Examples
|
35
|
+
|
36
|
+
```
|
37
|
+
/usr/local/zabbix-cloudwatch/get_aws_cloudwatch_metric.rb -n AWS/EC2 \
|
38
|
+
-m CPUUtilization \
|
39
|
+
-d AutoScalingGroupName \
|
40
|
+
-v your-auto-scaling-group \
|
41
|
+
-t detailed \
|
42
|
+
-s Sum
|
43
|
+
```
|
44
|
+
|
45
|
+
## Creating the IAM User
|
46
|
+
|
47
|
+
The following actions need to be allowed in IAM for this script to work with the keys you provide:
|
48
|
+
|
49
|
+
```
|
50
|
+
"cloudwatch:DescribeAlarms"
|
51
|
+
"cloudwatch:GetMetricStatistics"
|
52
|
+
```
|
53
|
+
|
54
|
+
## Notes
|
55
|
+
|
56
|
+
The class variables within get_aws_cloudwatch_metric.rb should be set if you do not (or don't want to) set environment
|
57
|
+
variables for your AWS Credentials.
|
58
|
+
|
59
|
+
The default behavior is to use the Environment variables *only* if the variables in the script are not set.
|
60
|
+
|
61
|
+
### Setting the Environment variables
|
62
|
+
```
|
63
|
+
export AWS_ACCESS_KEY_ID="YOUR ACCESS KEY"
|
64
|
+
export AWS_SECRET_ACCESS_KEY="YOUR SECRET ACCESS KEY"
|
65
|
+
export AWS_REGION="YOUR AWS REGION"
|
66
|
+
```
|
67
|
+
|
68
|
+
### Class variables at the top of get_aws_cloudwatch_metric.rb
|
69
|
+
```
|
70
|
+
@@aws_access_key=''
|
71
|
+
@@aws_secret_key=''
|
72
|
+
@@aws_region=''
|
73
|
+
```
|
74
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'getopt/long'
|
6
|
+
require 'zabbix-cloudwatch'
|
7
|
+
|
8
|
+
@@aws_access_key=''
|
9
|
+
@@aws_secret_key=''
|
10
|
+
@@aws_region=''
|
11
|
+
|
12
|
+
|
13
|
+
class RubyVersionException < StandardError; end
|
14
|
+
|
15
|
+
raise RubyVersionException, "Ruby version must be 1.8.7" unless RUBY_VERSION == "1.8.7"
|
16
|
+
|
17
|
+
opts = Getopt::Long.getopts(
|
18
|
+
["--help"],
|
19
|
+
["--namespace", Getopt::REQUIRED],
|
20
|
+
["--metricname", Getopt::REQUIRED],
|
21
|
+
["--dimension-name", Getopt::REQUIRED],
|
22
|
+
["--dimension-value","-v", Getopt::REQUIRED],
|
23
|
+
["--monitoring-type", "-t", Getopt::REQUIRED],
|
24
|
+
["--statistic",Getopt::REQUIRED],
|
25
|
+
["--aws-access-key", Getopt::REQUIRED],
|
26
|
+
["--aws-secret-key", Getopt::REQUIRED],
|
27
|
+
["--aws-region", Getopt::REQUIRED]
|
28
|
+
)
|
29
|
+
|
30
|
+
|
31
|
+
def usage
|
32
|
+
puts <<EOF
|
33
|
+
Usage: #{$0}
|
34
|
+
|
35
|
+
-h, --help This Message
|
36
|
+
-n, --namespace Namespace (AWS/Autoscaling, AWS/EC2, etc...)
|
37
|
+
-m, --metricname Metric Name (GroupInServiceInstances,EstimatedCharges, etc...)
|
38
|
+
-d, --dimension-name Dimension Name (AutoScalingGroupName, etc...)
|
39
|
+
-v, --dimension-value Dimension Value
|
40
|
+
-t, --monitoring-type detailed|basic Default: basic
|
41
|
+
-s, --statistic Minimum|Maximum|Average|Sum|SampleCount Default: Average
|
42
|
+
--aws-access-key AWS Access Key
|
43
|
+
--aws-secret-key AWS Secret Key
|
44
|
+
--aws-region AWS Region (us-east-1) Default: us-east-1
|
45
|
+
|
46
|
+
EOF
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
|
50
|
+
if opts.key?"help" or opts.empty?
|
51
|
+
usage
|
52
|
+
exit 0
|
53
|
+
end
|
54
|
+
|
55
|
+
unless opts.key?"aws-access-key"
|
56
|
+
opts["aws-access-key"] = (@@aws_access_key == '' && ENV["AWS_ACCESS_KEY_ID"]) || @@aws_access_key
|
57
|
+
end
|
58
|
+
unless opts.key?"aws-secret-key"
|
59
|
+
opts["aws-secret-key"] = (@@aws_secret_key == '' && ENV["AWS_SECRET_ACCESS_KEY"]) || @@aws_secret_key
|
60
|
+
end
|
61
|
+
unless opts.key?"aws-region"
|
62
|
+
opts["aws-region"] = (@@aws_region == '' && ENV["AWS_REGION"]) || @@aws_region
|
63
|
+
end
|
64
|
+
|
65
|
+
inst = ZabbixCloudwatch::GetCloudwatchMetric.new(opts)
|
66
|
+
inst.run!
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'zabbix-cloudwatch/version'
|
2
|
+
require 'aws-sdk'
|
3
|
+
|
4
|
+
module ZabbixCloudwatch
|
5
|
+
class GetCloudwatchMetric
|
6
|
+
class NamespaceArgumentMissingException < StandardError; end
|
7
|
+
class MetricnameArgumentMissingException < StandardError; end
|
8
|
+
class DimensionArgumentMissingException < StandardError; end
|
9
|
+
class MonitoringTypeArgumentException < StandardError; end
|
10
|
+
class StatisticTypeArgumentException < StandardError; end
|
11
|
+
class AwsAccessKeyMissingException < StandardError; end
|
12
|
+
class AwsSecretKeyMissingException < StandardError; end
|
13
|
+
class BadAWSAccessKeysException < StandardError; end
|
14
|
+
|
15
|
+
attr_accessor :options, :aws, :start_time, :end_time, :period, :statistic
|
16
|
+
|
17
|
+
def initialize options
|
18
|
+
self.options = options
|
19
|
+
usage if options.key?"help"
|
20
|
+
raise NamespaceArgumentMissingException unless options.key?"namespace"
|
21
|
+
raise MetricnameArgumentMissingException unless options.key?"metricname"
|
22
|
+
raise DimensionArgumentMissingException unless options.key?"dimension-name"
|
23
|
+
raise DimensionArgumentMissingException unless options.key?"dimension-value"
|
24
|
+
self.aws = AWS::CloudWatch.new(get_aws_options).client
|
25
|
+
test_aws_connectivity
|
26
|
+
set_time_range
|
27
|
+
set_statistic
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_aws_options
|
31
|
+
raise AwsAccessKeyMissingException unless options.key?"aws-access-key"
|
32
|
+
raise AwsSecretKeyMissingException unless options.key?"aws-secret-key"
|
33
|
+
if options.key?"aws-region" && options['aws-region'] != ''
|
34
|
+
region = options["aws-region"]
|
35
|
+
else
|
36
|
+
region = 'us-east-1'
|
37
|
+
end
|
38
|
+
puts options.inspect
|
39
|
+
{:access_key_id => options["aws-access-key"], :secret_access_key => options["aws-secret-key"], :region => region}
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_statistic
|
43
|
+
unless options.key?"statistic"
|
44
|
+
self.statistic = "Average"
|
45
|
+
else
|
46
|
+
if options["statistic"] =~ /Minimum|Maximum|Average|Sum|SampleCount/
|
47
|
+
self.statistic = options["statistic"]
|
48
|
+
else
|
49
|
+
raise StatisticTypeArgumentException, "Statistic type must be one of: Minimum, Maximum, Average, Sum, SampleCount. "
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def set_time_range
|
55
|
+
unless options.key?"monitoring-type"
|
56
|
+
detailed = false
|
57
|
+
else
|
58
|
+
if options["monitoring-type"] =~ /detailed|basic/
|
59
|
+
detailed = true if options["monitoring-type"] == 'detailed'
|
60
|
+
detailed = false if options["monitoring-type"] == 'basic'
|
61
|
+
else
|
62
|
+
raise MonitoringTypeArgumentException, "Monitoring type must be either 'detailed' or 'basic'. "
|
63
|
+
end
|
64
|
+
end
|
65
|
+
if detailed
|
66
|
+
self.start_time = time_one_minute_ago
|
67
|
+
self.period = 60
|
68
|
+
else
|
69
|
+
self.start_time = time_five_minutes_ago
|
70
|
+
self.period = 360
|
71
|
+
end
|
72
|
+
self.end_time = time_now
|
73
|
+
end
|
74
|
+
|
75
|
+
def time_now
|
76
|
+
Time.now.utc.iso8601
|
77
|
+
end
|
78
|
+
|
79
|
+
def time_one_minute_ago
|
80
|
+
# Not really 1 minute ago, but adds a bit of buffer for amazon's silliness
|
81
|
+
(Time.now - 90).utc.iso8601
|
82
|
+
end
|
83
|
+
|
84
|
+
def time_five_minutes_ago
|
85
|
+
# Not really 5 minutes ago, but adds a bit of buffer for amazon's silliness
|
86
|
+
(Time.now - (60*7+30)).utc.iso8601
|
87
|
+
end
|
88
|
+
|
89
|
+
def run!
|
90
|
+
ret = aws.get_metric_statistics({
|
91
|
+
:namespace => options["namespace"],
|
92
|
+
:metric_name => options["metricname"],
|
93
|
+
:dimensions => [{:name => options["dimension-name"],:value => options["dimension-value"]}],
|
94
|
+
:period => period,
|
95
|
+
:start_time => start_time,
|
96
|
+
:end_time => end_time,
|
97
|
+
:statistics => [statistic]})
|
98
|
+
begin
|
99
|
+
symbol = statistic.downcase.to_sym
|
100
|
+
symbol = :sample_count if symbol == :samplecount
|
101
|
+
puts ret[:datapoints][0][symbol]
|
102
|
+
rescue
|
103
|
+
exit 1
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_aws_connectivity
|
108
|
+
begin
|
109
|
+
aws.describe_alarms(:max_records => 1)
|
110
|
+
rescue
|
111
|
+
raise BadAWSAccessKeysException, <<-EOF
|
112
|
+
|
113
|
+
You cannot access AWS due to one of the following reasons:
|
114
|
+
- The AWS keys provided do not have access to Cloudwatch
|
115
|
+
- your server is not synced with NTP
|
116
|
+
- The Region setting is missing or incorrect
|
117
|
+
EOF
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
require "zabbix-cloudwatch/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "zabbix-cloudwatch"
|
7
|
+
s.version = ZabbixCloudwatch::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.license = "MIT"
|
10
|
+
s.authors = ["Randy D. Wallace Jr."]
|
11
|
+
s.email = ["randy@randywallace.com"]
|
12
|
+
s.homepage = "http://github.com/randywallace/zabbix-cloudwatch"
|
13
|
+
s.summary = %q{A library for getting cloudwatch metrics into Zabbix}
|
14
|
+
s.description = %q{A library for getting cloudwatch metrics into Zabbix\nPlease see http://github.com/randywallace/zabbix-cloudwatch for more details}
|
15
|
+
|
16
|
+
s.add_runtime_dependency "aws-sdk", "~> 1.21.0"
|
17
|
+
s.add_runtime_dependency "getopt", "~> 1.4.1"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zabbix-cloudwatch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Randy D. Wallace Jr.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2013-10-26 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: aws-sdk
|
16
|
+
prerelease: false
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.21.0
|
22
|
+
type: :runtime
|
23
|
+
version_requirements: *id001
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: getopt
|
26
|
+
prerelease: false
|
27
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 1.4.1
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id002
|
34
|
+
description: A library for getting cloudwatch metrics into Zabbix\nPlease see http://github.com/randywallace/zabbix-cloudwatch for more details
|
35
|
+
email:
|
36
|
+
- randy@randywallace.com
|
37
|
+
executables:
|
38
|
+
- zabbix-cloudwatch
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- Gemfile.lock
|
47
|
+
- LICENSE
|
48
|
+
- README.md
|
49
|
+
- bin/zabbix-cloudwatch
|
50
|
+
- lib/zabbix-cloudwatch.rb
|
51
|
+
- lib/zabbix-cloudwatch/version.rb
|
52
|
+
- zabbix-cloudwatch.gemspec
|
53
|
+
homepage: http://github.com/randywallace/zabbix-cloudwatch
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- &id003
|
66
|
+
- ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- *id003
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.0.12
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: A library for getting cloudwatch metrics into Zabbix
|
79
|
+
test_files: []
|
80
|
+
|