我想添加警告和严重警告条件if inputfile == "android":通过,然后检查存储在变量e and f中的数字,并检查它是否处于正常、警告或严重级别,不管我们传递的参数是什么。
其次,这个脚本在python3.6中运行时没有输出#!/usr/bin/python
import requests, os, json, sys, getopt
f = 10
e = 20
def main(argv):
inputfile = ''
try:
opts, args = getopt.getopt(argv,"hi:o:w:c:",["ent","lable","help","warning","critical"])
except getopt.GetoptError:
print ("Usage: test.py -i ")
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print ("test.py -i ")
sys.exit()
# elif opt in ("-i", "--app"):
elif opt == '-i':
inputfile = arg
if inputfile == "android":
'''call a function here (hiding sensitive information) Using e and f variable instead'''
print ("Input is"), inputfile
print("Active:"), f
else:
print("Parameter not found")
sys.exit(2)
# elif opt in ("-o", "--lable"):
elif opt == '-o':
inputfile = arg
print("Active:"), e
if __name__ == "__main__":
main(sys.argv[1:])
现在:
#python script -i android
输出
Active: 10
期望:
#python script -i android -w 5 -c 20
输出
WARNING - Active: 10