I have a dictionary as follows (the dict is called channel_info):
{'flume02': u'98.94420000000001', 'flume03': u'32.562999999999995', 'flume01': u'2.15'}
I am trying to scroll through a dictionary and tell the values โโwarning or critical. I have arguments in the program
parser.add_argument('-w', '--warning', type=int, help='Warning threshold', default=85) parser.add_argument('-c', '--critical', type=int, help='Critical threshold', default=95)
so basically when I run a program like myprog.py -w 80 -c 90 , I want flume02 as critical (in this case it will be the only way out). If any other key had a value greater than 80 or 90, they would be reported as warning or critical, respectively.
However, this is not so, and I get all the values โโunder critical.
Relevant Code:
if args.warning and not args.critical: for each in channel_info.items(): if float(each[1]) > float(args.warning): print 'WARNING | {} is {} percent full'.format(*each) exit(1) if args.critical and not args.warning: for each in channel_info.items(): if float(each[1]) > float(args.critical): print 'CRITICAL | {} is {} percent full'.format(*each) exit(2) if args.warning and args.critical: for each in channel_info.items(): if float(args.warning) < each[1] < float(args.critical): print 'WARNING | {} is {} percent full'.format(*each) elif each[1] > float(args.critical): print 'CRITICAL | {} is {} percent full'.format(*each)
Output:
CRITICAL | flume02 is 99.9892 percent full CRITICAL | flume03 is 51.4497 percent full CRITICAL | flume01 is 7.95 percent full
I set if the last condition is if ( if args.warning and args.critical ), to make sure that the program can work with 1 ( -w or -c ) or both arguments. Any help with what I'm doing wrong will be greatly appreciated.