-
Notifications
You must be signed in to change notification settings - Fork 27
/
wuam.py
101 lines (72 loc) · 2.37 KB
/
wuam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#! python3
# ************************************************************
# Imports
# ************************************************************
import sys
import csv
import sqlite3
# Verify Python version
if sys.version_info[0] <= 3 and sys.version_info[1] < 7:
sys.exit("This script requires at least Python version 3.7.")
from importlib import util
pyodbc_spec = util.find_spec("pyodbc")
if pyodbc_spec is None:
sys.exit("Requires Python SQL Driver (pyodbc) - https://docs.microsoft.com/en-us/sql/connect/python/pyodbc/python-sql-driver-pyodbc?view=sql-server-2017")
import pyodbc
import globs
import argparse
import sqlite3
import wuapis
import BamLogger
import logging
import multiprocessing as mp
from support.utils import exitfunction, util_logconfig
try:
globs.DBWSUSCONN = pyodbc.connect(globs.connstr)
except pyodbc.OperationalError as error:
print(error)
sys.exit("Must be able to connect to WSUS")
def displayhelp(parserh):
'''
displays help prompt
'''
parserh.print_help()
def parsecommandline(parser):
'''
parses arguments given to commandline
'''
parser.add_argument(
"-wu", "--winupdateinfo",
help="Optional (Requires pyodbc)."
"should be added to database.",
action='store_true')
if len(sys.argv) == 1:
displayhelp(parser)
exitfunction()
return parser.parse_args()
if __name__ == "__main__":
PARSER = argparse.ArgumentParser()
ARGS = parsecommandline(PARSER)
print("Connected to: " + globs.connstr)
globqueue = mp.Manager().Queue(-1)
mainlogger = logging.getLogger("BAM.wuam")
qh = logging.handlers.QueueHandler(globqueue)
mainlogger.addHandler(qh)
mainlogger.setLevel(logging.DEBUG)
loggerProcess = mp.Process(target=BamLogger.log_listener, args=(globqueue, BamLogger.log_config))
loggerProcess.start()
wuapis.db_logconfig(globqueue)
if ARGS.winupdateinfo:
try:
'''
Update the BAM DB with superseding and superseded information
'''
wuapis.updatewuentrysecedenceinfo()
except sqlite3.Error as error:
print("Error caught: ", error.args[0])
except Exception as e:
print("Error caught", str(e))
globs.DBCONN.close()
globs.DBWSUSCONN.close()
globqueue.put_nowait(None)
loggerProcess.join()