I have a dictionary as follows (dict is named channel_info):
{'flume02': u'98.94420000000001', 'flume03': u'32.562999999999995', 'flume01': u'2.15'}
Im trying to loop through the dictionary and report back the values a warning or critical. I have to arguments to 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 the program like myprog.py -w 80 -c 90
, i want
flume02 as critical( in this case that would be the only output). 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 the case 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 put if the last if condition (if args.warning and args.critical
) so to make sure that the program is able to run with either 1 ( -w
or -c
) or both arguments. Any help with what im doing wrong will be greatly appreciated