Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- #python module.py 36947 41.221.20.0/24 to test
- #python module.py -V -h -v 1 36947 41.221.20.0/24 to test
- #
- import sys
- import time
- import procedure
- state = " "
- #ASN = 36947
- #prefix = "41.221.20.0/24"
- def scr(ASN, prefix):
- global state
- try:
- L1, L2 = procedure.procedure(prefix)
- #f = open(path, 'r')
- lst1 = []
- #L1 = f.readline()
- for x in L1.split():
- lst1.append(int(x))
- print (lst1)
- lst2 = []
- #L2 = f.readline()
- for x in L2.split():
- lst2.append(x)
- print (lst2)
- c = 0
- if search(lst1, ASN) & search(lst2, prefix):
- c = 1
- if c == 1:
- if (len(lst1) == 1) & (len(lst2) == 1):
- output("OK")
- elif (len(lst1) == 1) & (len(lst2) != 1):
- output("CRITICAL_1")
- elif (len(lst1) != 1) & (len(lst2) == 1):
- output("CRITICAL_2")
- else:
- output("UNKNOWN")
- else:
- output("UNKNOWN")
- #f.close()
- except Exception:
- sys.stdout.write("STATUS: WARNING\n")
- exit(1)
- def search(A, key):
- i = 0
- while i < len(A) and A[i] != key:
- i += 1
- return i < len(A)
- def output(state):
- if state == "OK": # в списке more specific будет только один префикс, в списке as-origin будет только один номер
- print "STATUS: OK\n"
- exit(0)
- elif state == "CRITICAL_1": # в списке more specific будет/будут префикс/ы отличные от заданного
- print "STATUS: CRITICAL, type = 1\n"
- exit(2)
- elif state == "CRITICAL_2": # в списке as-origin будет/будут номер/а отличные от заданого
- print "STATUS: CRITICAL, type = 2\n"
- exit(2)
- else:
- print "STATUS: UNKNOWN\n"
- exit(3)
- #print "Input data: ASN --", ASN, ", prefix --", prefix
- #parse_key = sys.argv
- def parser (key, k):
- if key == '-V' or key == '--version':
- print "monitoring module 1.0"
- elif key == '-h' or key == '--help':
- #сделать красиво
- print "usage: python module.py [options] <ASN> <prefix> "
- print "General Options:"
- print " -h, --help Show help."
- print " -V, --version Show version."
- print " -v [level], --verbose [level] Give more output. "
- print " levels:"
- print " 0 is for minimal"
- print " 1 is for normal"
- print " 2 is for detailed"
- print " 3 is for diagnostic"
- elif k == 1:
- if key == '0':
- print "Single line, minimal output. Summary"
- elif key == '1':
- print "Single line, additional information (eg list processes that fail)"
- elif key == '2':
- print "Multi line, configuration debug output (eg ps command used)"
- elif key == '3':
- print "Lots of detail for plugin problem diagnosis"
- else:
- print "try again"
- exit(0)
- else:
- print "try again"
- exit(0)
- st = 1
- def keys():
- k = 0
- global st
- if len(sys.argv) > 3:
- st = 0
- c = 0
- while c < (len(sys.argv) - 2):
- if k == 1:
- parser(sys.argv[c], k)
- else:
- if sys.argv[c] != 'module.py':
- if (sys.argv[c] == '-v') or (sys.argv[c] == '--version'):
- k = 1
- else:
- parser(sys.argv[c], k)
- c+=1
- keys()
- if st == 0:
- output("UNKNOWN")
- else:
- scr(int(sys.argv[len(sys.argv) - 2]), sys.argv[len(sys.argv) - 1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement