1
我想寫一個腳本來提醒某些警告和關鍵的水平。到目前爲止,無論輸出如何,它都只顯示正常。它忽視了警告和批評。我需要改變什麼?Python處理警告和關鍵參數與getopt
./check_sqs -p前綴-q隊列-s XXX XXX -a -w 5 -C 10
OK:深度= 33; | Prefix_Queue = 33
for o, a in opts:
if o in ('-q', '--queue'):
queue_name = a
if o in ('-a', '--access_key'):
access_key = a
if o in ('-s', '--secret_key'):
secret_key = a
if o in ('-p', '--prefix'):
prefix = a
if o in ('-w', '--warning'):
warning = a
if o in ('-c', '--critical'):
critical = a
if access_key == "_none_":
c = SQSConnection()
else:
c = SQSConnection(access_key, secret_key)
cnt = 0
if queue_name != '':
q = c.get_queue(queue_name)
if q == None:
print "ERROR: Invalid queue name " + queue_name
sys.exit(3)
cnt = q.count()
if cnt >= critical:
print 'Critical: depth =', str(cnt) + ';|', q.id.split('/')[2] + "=" + str(cnt)
sys.exit(2)
if cnt >= warning:
print 'Warning: depth =', str(cnt) + ';|', q.id.split('/')[2] + "=" + str(cnt)
sys.exit(1)
if isinstance(cnt, int) and cnt >= 0:
print 'OK: depth =', str(cnt) + ';|', q.id.split('/')[2] + "=" + str(cnt)
sys.exit(0)
else:
print 'Unknown: depth =', str(cnt) + ';|', q.id.split('/')[2] + "=" + str(cnt)
sys.exit(3)
rs = c.get_all_queues()
resp = ''
for q in rs:
name = q.id.split('/')[2]
if name.startswith(prefix):
cnt = cnt + q.count()
resp = resp + name + "=" + str(q.count()) + " "
print 'OK: depth =', str(cnt) + ';|', resp
sys.exit(0)
您必須返回相同的信息有兩種確定塊。讓他們清楚,看看哪一個正在射擊;這會給你更多的信息。爲了調試,還要在比較之前打印出'critical'(等)的值和類型。 – 2015-03-15 19:29:22