Amazon web services Python-使用getopt处理警告和关键参数

Amazon web services Python-使用getopt处理警告和关键参数,amazon-web-services,nagios,Amazon Web Services,Nagios,我正试图编写一个脚本来警告某些警告和严重级别。到目前为止,无论输出如何,它都只显示ok。它忽视了警告和批评。我需要改变什么 /检查\u sqs-p前缀-q队列-s xxx-a xxx-w 5-c 10 OK:深度=33;|前缀_队列=33 for o, a in opts: if o in ('-q', '--queue'): queue_name = a if o in ('-a', '--access_key'): access_key = a

我正试图编写一个脚本来警告某些警告和严重级别。到目前为止,无论输出如何,它都只显示ok。它忽视了警告和批评。我需要改变什么

/检查\u sqs-p前缀-q队列-s xxx-a xxx-w 5-c 10

OK:深度=33;|前缀_队列=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)

谢谢,这很有帮助。临界值和警告值是字符串,这就是为什么比较不起作用。把它们改成int就成功了

临界=int(临界)
warning=int(warning)

您有两个OK块返回相同的消息。把它们区分开来,看看哪个在开火;这会给你更多的信息。为了进行调试,还需要在比较之前打印出“关键”(etc)的值和类型。