Class: HQ::AWS::CheckSqsQueue::Script

Inherits:
Tools::CheckScript
  • Object
show all
Includes:
Tools::Escape
Defined in:
lib/hq/aws/check-sqs-queue/script.rb

Instance Method Summary collapse

Constructor Details

#initializeScript

Returns a new instance of Script.



18
19
20
21
# File 'lib/hq/aws/check-sqs-queue/script.rb', line 18

def initialize
	super
	@name = "SQS queue"
end

Instance Method Details

#perform_checksObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/hq/aws/check-sqs-queue/script.rb', line 82

def perform_checks

	queue =
		@sqs.queues.named @opts[:queue_name]

	message_count = [
		queue.approximate_number_of_messages,
		queue.approximate_number_of_messages_delayed,
		queue.approximate_number_of_messages_not_visible,
	].inject(:+)

	if message_count >= @opts[:critical]

		critical "%s messages (critical is %s)" % [
			message_count,
			@opts[:critical],
		]

	elsif message_count >= @opts[:warning]

		warning "%s messages (warning is %s)" % [
			message_count,
			@opts[:warning],
		]

	else

		message "%s messages" % [
			message_count,
		]

	end

end

#prepareObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/hq/aws/check-sqs-queue/script.rb', line 52

def prepare

	config_doc =
		XML::Document.file \
			@opts[:config]

	@config =
		config_doc.root

	@account =
		@config.find_first "
			aws-account [
				@name = #{esc_xp @opts[:account]}
			]
		"

	raise "No such account" \
		unless @account

	@sqs =
		::AWS::SQS.new \
			:access_key_id =>
				@account.attributes["access-key-id"],
			:secret_access_key =>
				@account.attributes["secret-access-key"],
			:http_open_timeout => 10,
			:http_read_timeout => 10

end

#process_argsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/hq/aws/check-sqs-queue/script.rb', line 23

def process_args

	@opts, @args =
		Tools::Getopt.process @args, [

			{ :name => :warning,
				:required => true,
				:convert => :to_i },

			{ :name => :critical,
				:required => true,
				:convert => :to_i },

			{ :name => :config,
				:required => true },

			{ :name => :account,
				:required => true },

			{ :name => :queue_name,
				:required => true },

		]

	@args.empty? \
		or raise "Extra args on command line"

end