Permalink
Browse files

Added support for specifying the alerting thresholds via arguments.

  • Loading branch information...
calebgroom authored and root committed Dec 12, 2010
1 parent 7f70dbe commit 54c2bb22cc69f964fca172bb33ee8c8cc4bad7c0
Showing with 16 additions and 2 deletions.
  1. +16 −2 sqs.py
View
18 sqs.py
@@ -3,20 +3,34 @@
Count the approximate number of messaages in your Amazon SQS queue(s).
Requires the boto python library (http://code.google.com/p/boto/).
-Set the aws_key and aws_secret values before enabling using the plugin.
+Set the aws_key and aws_secret values before using the plugin.
+
+Usage:
+ sqs.py [minimum_count] [maximum_count]
LICENSE: http://www.opensource.org/licenses/mit-license.php
AUTHOR: Caleb Groom <http://github.com/calebgroom>
"""
from boto.sqs.connection import SQSConnection
from boto.exception import SQSError
+import sys
MAX_MESSAGES = 100
MIN_MESSAGES = 0
aws_key = ''
aws_secret = ''
+# The alerting thresholds can be overridden via command line arguments
+limits = [MIN_MESSAGES, MAX_MESSAGES]
+for i in [2,3]:
+ if len(sys.argv) >= i:
+ try:
+ limits[i-2] = int(sys.argv[i-1])
+ except ValueError:
+ print 'status err argument "%s" is not a valid integer' % sys.argv[i-1]
+ sys.exit(1)
+
try:
conn = SQSConnection(aws_key, aws_secret)
queues = conn.get_all_queues()
@@ -25,7 +39,7 @@
for queue in queues:
count = queue.count()
total += count
- if count > MAX_MESSAGES or count < MIN_MESSAGES:
+ if count < limits[0] or count > limits[1]:
error_queues.append(queue.name)
print 'metric %s int %d' % (queue.name, count)

0 comments on commit 54c2bb2

Please sign in to comment.