lib/zabbix-cloudwatch.rb in zabbix-cloudwatch-0.0.5 vs lib/zabbix-cloudwatch.rb in zabbix-cloudwatch-0.0.6
- old
+ new
@@ -12,32 +12,28 @@
class AwsSecretKeyMissingException < StandardError; end
class BadAWSAccessKeysException < StandardError; end
attr_accessor :options, :aws, :start_time, :end_time, :period, :statistic
- def initialize options
+ def initialize options = {}
self.options = options
usage if options.key?"help"
raise NamespaceArgumentMissingException unless options.key?"namespace"
raise MetricnameArgumentMissingException unless options.key?"metricname"
raise DimensionArgumentMissingException unless options.key?"dimension-name"
raise DimensionArgumentMissingException unless options.key?"dimension-value"
self.aws = AWS::CloudWatch.new(get_aws_options).client
- test_aws_connectivity
- set_time_range
- set_statistic
end
def get_aws_options
raise AwsAccessKeyMissingException unless options.key?"aws-access-key"
raise AwsSecretKeyMissingException unless options.key?"aws-secret-key"
if options.key?"aws-region" && options['aws-region'] != ''
region = options["aws-region"]
else
region = 'us-east-1'
end
- puts options.inspect
{:access_key_id => options["aws-access-key"], :secret_access_key => options["aws-secret-key"], :region => region}
end
def set_statistic
unless options.key?"statistic"
@@ -85,9 +81,12 @@
# Not really 5 minutes ago, but adds a bit of buffer for amazon's silliness
(Time.now - (60*7+30)).utc.iso8601
end
def run!
+ test_aws_connectivity
+ set_time_range
+ set_statistic
ret = aws.get_metric_statistics({
:namespace => options["namespace"],
:metric_name => options["metricname"],
:dimensions => [{:name => options["dimension-name"],:value => options["dimension-value"]}],
:period => period,