Sep-19-2018, 06:02 AM
Hi,
Below is the code, Please look into it.
Below is the code, Please look into it.
if __name__ == "__main__": try: opts, args = getopt.getopt(sys.argv[1:],"i:w:c:") except getopt.GetoptError: print("Usage: v2.py -i name -w 10 -c 20") sys.exit(2) for opt, arg in opts: if opt == '-i': input_value = arg elif opt == '-w': w_value = int(arg) elif opt == '-c': c_value = int(arg) # parse command line args def test_tuple(input_value, t, idx): if input_value in ["desert", "ocean"]: if t[idx] > c_value: print("CRITICAL - Active: ",t[idx]) sys.exit(2) elif t[idx] > w_value: print("WARNING - Active:",t[idx]) sys.exit(1) else: print("OK - Active:",t[idx]) sys.exit(0) else: print("Invalid input") # validate args if len(sys.argv)==1: print("# Usage:\t -w <warn> -c <crit>") sys.exit("No argument pass") else: idx = 0 test_tuple(input_value, t, idx)