| 1 |
"""
|
| 2 |
|
| 3 |
EndoIGServerAnalyzer
|
| 4 |
|
| 5 |
Created by:
|
| 6 |
Emanuel Borges
|
| 7 |
07.28.2022
|
| 8 |
|
| 9 |
This program will take two CSV files and do a row to row compare. For this to work both CSVs need to have the same colums.
|
| 10 |
Set colOmitList to FALSE if you dont want it to parse at all and remove any columns. for that to work though you have to normalize the date
|
| 11 |
and number fields.
|
| 12 |
|
| 13 |
NOTE: the application List file HAS pipes in it, so carefully select which columns you use.
|
| 14 |
|
| 15 |
"""
|
| 16 |
|
| 17 |
import os
|
| 18 |
|
| 19 |
|
| 20 |
if __name__ == '__main__':
|
| 21 |
|
| 22 |
outputFileName = r"C:\Users\eborges\Documents\Cases\Endo\20220715 - IG Projects\4 - Develop Identification Process to Inventory NCDS stored in Endo IT\20220815-WindowsServer8_Matrix_Report.csv"
|
| 23 |
|
| 24 |
## This should all be csvs with pre-selected fields that are verified didnt already contain pipes. Also a headder row.
|
| 25 |
#win2kServersFile = r"C:\Users\eborges\Documents\Cases\Endo\20220715 - IG Projects\4 - Develop Identification Process to Inventory NCDS stored in Endo IT\_fromEndo\_csv\Win8Servers_filtered.csv"
|
| 26 |
win2kServersFile = r"C:\Users\eborges\Documents\Cases\Endo\20220715 - IG Projects\4 - Develop Identification Process to Inventory NCDS stored in Endo IT\_fromEndo\_csv\Win8Servers_NOFilter.csv"
|
| 27 |
|
| 28 |
appListServersFile = r"C:\Users\eborges\Documents\Cases\Endo\20220715 - IG Projects\4 - Develop Identification Process to Inventory NCDS stored in Endo IT\_fromEndo\_csv\AppInventory_extraFields.csv"
|
| 29 |
sqlServersListFile = r"C:\Users\eborges\Documents\Cases\Endo\20220715 - IG Projects\4 - Develop Identification Process to Inventory NCDS stored in Endo IT\_fromEndo\_csv\Endo SQL Servers List__As of July 2022.csv"
|
| 30 |
prevSqlServersListFile = r"C:\Users\eborges\Documents\Cases\Endo\20220715 - IG Projects\4 - Develop Identification Process to Inventory NCDS stored in Endo IT\_fromEndo\_csv\SQL Server Report 07212021.csv"
|
| 31 |
aspectDatabasesToServersFile = r"C:\Users\eborges\Documents\Cases\Endo\20220715 - IG Projects\4 - Develop Identification Process to Inventory NCDS stored in Endo IT\_fromEndo\_csv\All_endo_SQL_Server_databases.csv"
|
| 32 |
serviceNowToServersFile = r"C:\Users\eborges\Documents\Cases\Endo\20220715 - IG Projects\4 - Develop Identification Process to Inventory NCDS stored in Endo IT\_fromEndo\_csv\ServiceNow-PreParsed.txt"
|
| 33 |
|
| 34 |
win2kServersFileMatrix = {}
|
| 35 |
appListServersFileMatrix = {}
|
| 36 |
sqlServersListFileMatrix = {}
|
| 37 |
prevSqlServersListFileMatrix = {}
|
| 38 |
aspectDatabasesToServersMatrix = {}
|
| 39 |
serviceNowToServersMatrix = {}
|
| 40 |
|
| 41 |
## Start with ingesting the win2kservers file but be sure to save the headders on this one.
|
| 42 |
contents = open(win2kServersFile).readlines()
|
| 43 |
win2kServersFileHeadders = contents[0]
|
| 44 |
win2kServersFileHeadders = win2kServersFileHeadders.replace("\n","")
|
| 45 |
contents = contents[1:]
|
| 46 |
for line in contents:
|
| 47 |
line = line.replace("\n","")
|
| 48 |
parsedLine = line.split("|")
|
| 49 |
if parsedLine[0].upper() in list(win2kServersFileMatrix.keys()):
|
| 50 |
win2kServersFileMatrix[parsedLine[0].upper()].append(line)
|
| 51 |
else:
|
| 52 |
win2kServersFileMatrix[parsedLine[0].upper()] = [line,]
|
| 53 |
print("There are %s servers to start with."%len(list(win2kServersFileMatrix.keys())))
|
| 54 |
|
| 55 |
|
| 56 |
## Next ingest the SQL servers list
|
| 57 |
contents = open(sqlServersListFile).readlines()
|
| 58 |
contents = contents[1:]
|
| 59 |
for line in contents:
|
| 60 |
line = line.replace("\n","")
|
| 61 |
parsedLine = line.split("|")
|
| 62 |
if parsedLine[0].upper() in list(sqlServersListFileMatrix.keys()):
|
| 63 |
sqlServersListFileMatrix[parsedLine[0].upper()].append(line)
|
| 64 |
else:
|
| 65 |
sqlServersListFileMatrix[parsedLine[0].upper()] = [line,]
|
| 66 |
print("There are %s servers on the SQL Servers file."%len(list(sqlServersListFileMatrix.keys())))
|
| 67 |
|
| 68 |
|
| 69 |
## Next ingest the older SQL servers list
|
| 70 |
contents = open(prevSqlServersListFile).readlines()
|
| 71 |
contents = contents[1:]
|
| 72 |
for line in contents:
|
| 73 |
line = line.replace("\n","")
|
| 74 |
parsedLine = line.split("|")
|
| 75 |
if parsedLine[0].upper() in list(prevSqlServersListFileMatrix.keys()):
|
| 76 |
prevSqlServersListFileMatrix[parsedLine[0].upper()].append(line)
|
| 77 |
else:
|
| 78 |
prevSqlServersListFileMatrix[parsedLine[0].upper()] = [line,]
|
| 79 |
print("There are %s servers on the older SQL servers file."%len(list(prevSqlServersListFileMatrix.keys())))
|
| 80 |
|
| 81 |
|
| 82 |
## Next ingest the databasename to server list from aspect
|
| 83 |
contents = open(aspectDatabasesToServersFile).readlines()
|
| 84 |
contents = contents[1:]
|
| 85 |
for line in contents:
|
| 86 |
line = line.replace("\n","")
|
| 87 |
parsedLine = line.split("|")
|
| 88 |
if parsedLine[0].upper() in list(aspectDatabasesToServersMatrix.keys()):
|
| 89 |
aspectDatabasesToServersMatrix[parsedLine[0].upper()].append(line)
|
| 90 |
else:
|
| 91 |
aspectDatabasesToServersMatrix[parsedLine[0].upper()] = [line,]
|
| 92 |
print("There are %s servers on the aspect databases to servers file."%len(list(aspectDatabasesToServersMatrix.keys())))
|
| 93 |
|
| 94 |
## Next is the app inventory which must first be parsed.
|
| 95 |
contents = open(appListServersFile).readlines()
|
| 96 |
contents = contents[1:]
|
| 97 |
for line in contents:
|
| 98 |
line = line.replace("\n","")
|
| 99 |
parsedLine = line.split("|")
|
| 100 |
parsedServerList = parsedLine[4].replace("#","")
|
| 101 |
parsedServerList = parsedServerList.split(";")
|
| 102 |
for s in parsedServerList:
|
| 103 |
if s.isnumeric():
|
| 104 |
pass
|
| 105 |
else:
|
| 106 |
if s.upper() in list(appListServersFileMatrix.keys()):
|
| 107 |
appListServersFileMatrix[s.upper()].append(line)
|
| 108 |
else:
|
| 109 |
appListServersFileMatrix[s.upper()] = [line,]
|
| 110 |
print("There are %s servers on the application list."%len(list(appListServersFileMatrix.keys())))
|
| 111 |
|
| 112 |
## Next ingest the ServiceNow Export to server list. check that there is a chg number at all.
|
| 113 |
contents = open(serviceNowToServersFile).readlines()
|
| 114 |
contents = contents[1:]
|
| 115 |
for line in contents:
|
| 116 |
line = line.replace("\n","")
|
| 117 |
parsedLine = line.split("|")
|
| 118 |
## Dont add it to the matrix if there is no chg number.
|
| 119 |
if parsedLine[1]:
|
| 120 |
if parsedLine[0].upper() in list(serviceNowToServersMatrix.keys()):
|
| 121 |
serviceNowToServersMatrix[parsedLine[0].upper()].append(line)
|
| 122 |
else:
|
| 123 |
serviceNowToServersMatrix[parsedLine[0].upper()] = [line,]
|
| 124 |
print("There are %s servers on the ServiceNow Export to servers file."%len(list(serviceNowToServersMatrix.keys())))
|
| 125 |
|
| 126 |
outputFile = open(outputFileName,'w')
|
| 127 |
outputFile.write(win2kServersFileHeadders + "|Found on 2022 SQL Server Report?|Found on 2021 SQL Server Report?|Found DatabaseNames Server Report?|DB Names Found on AspectList|Found on Application Inventory?|Applications|App IT Leadership Owner|App IT System Owner|App Executive Leadership Owner|App Business Owner|Found on ServiceNow|ServiceNowChangeReqNumbers\n")
|
| 128 |
for i in list(win2kServersFileMatrix.keys()):
|
| 129 |
nl=outputFile.write(win2kServersFileMatrix[i][0])
|
| 130 |
|
| 131 |
if i in list(sqlServersListFileMatrix.keys()):
|
| 132 |
nl=outputFile.write("|YES")
|
| 133 |
else:
|
| 134 |
nl=outputFile.write("|NO")
|
| 135 |
if i in list(prevSqlServersListFileMatrix.keys()):
|
| 136 |
nl=outputFile.write("|YES")
|
| 137 |
else:
|
| 138 |
nl=outputFile.write("|NO")
|
| 139 |
dbNamesList = ""
|
| 140 |
if i in list(aspectDatabasesToServersMatrix.keys()):
|
| 141 |
nl=outputFile.write("|YES")
|
| 142 |
for dbNameLine in aspectDatabasesToServersMatrix[i]:
|
| 143 |
dbNameLine = dbNameLine.replace("\n","")
|
| 144 |
dbNameLine = dbNameLine.split("|")
|
| 145 |
if dbNamesList:
|
| 146 |
dbNamesList = dbNamesList + "; " +dbNameLine[1]
|
| 147 |
else:
|
| 148 |
dbNamesList = dbNameLine[1]
|
| 149 |
else:
|
| 150 |
nl=outputFile.write("|NO")
|
| 151 |
if dbNamesList:
|
| 152 |
nl=outputFile.write("|" + dbNamesList)
|
| 153 |
else:
|
| 154 |
nl=outputFile.write("|")
|
| 155 |
appList = set()
|
| 156 |
itLeadershipOwnerList = set()
|
| 157 |
itSystemOwnerList = set()
|
| 158 |
executiveLeadershipOwnerList = set()
|
| 159 |
businessOwnerList = set()
|
| 160 |
tempOwnerList = ""
|
| 161 |
if i in list(appListServersFileMatrix.keys()):
|
| 162 |
nl=outputFile.write("|YES")
|
| 163 |
for appLine in appListServersFileMatrix[i]:
|
| 164 |
appLine = appLine.replace("\n","")
|
| 165 |
appLine = appLine.split("|")
|
| 166 |
appList.add(appLine[1]+' [AppID=%s]'%appLine[0])
|
| 167 |
tempOwnerList = appLine[5].replace("#","")
|
| 168 |
tempOwnerList = tempOwnerList.split(";")
|
| 169 |
for o in tempOwnerList:
|
| 170 |
if o.isnumeric():
|
| 171 |
pass
|
| 172 |
else:
|
| 173 |
itLeadershipOwnerList.add(o+' [AppID=%s]'%appLine[0])
|
| 174 |
tempOwnerList = appLine[6].replace("#","")
|
| 175 |
tempOwnerList = tempOwnerList.split(";")
|
| 176 |
for o in tempOwnerList:
|
| 177 |
if o.isnumeric():
|
| 178 |
pass
|
| 179 |
else:
|
| 180 |
itSystemOwnerList.add(o+' [AppID=%s]'%appLine[0])
|
| 181 |
tempOwnerList = appLine[7].replace("#","")
|
| 182 |
tempOwnerList = tempOwnerList.split(";")
|
| 183 |
for o in tempOwnerList:
|
| 184 |
if o.isnumeric():
|
| 185 |
pass
|
| 186 |
else:
|
| 187 |
executiveLeadershipOwnerList.add(o+' [AppID=%s]'%appLine[0])
|
| 188 |
tempOwnerList = appLine[8].replace("#","")
|
| 189 |
tempOwnerList = tempOwnerList.split(";")
|
| 190 |
for o in tempOwnerList:
|
| 191 |
if o.isnumeric():
|
| 192 |
pass
|
| 193 |
else:
|
| 194 |
businessOwnerList.add(o+' [AppID=%s]'%appLine[0])
|
| 195 |
## if appList:
|
| 196 |
## appList = appList + '; ' + appLine[1]+' [AppID=%s]'%appLine[0]
|
| 197 |
## else:
|
| 198 |
## appList = appLine[1]+' [AppID=%s]'%appLine[0]
|
| 199 |
else:
|
| 200 |
nl=outputFile.write("|NO")
|
| 201 |
if appList:
|
| 202 |
nl=outputFile.write("|" + "; ".join(appList))
|
| 203 |
else:
|
| 204 |
nl=outputFile.write("|")
|
| 205 |
if itLeadershipOwnerList:
|
| 206 |
nl=outputFile.write("|" + "; ".join(itLeadershipOwnerList))
|
| 207 |
else:
|
| 208 |
nl=outputFile.write("|")
|
| 209 |
if itSystemOwnerList:
|
| 210 |
nl=outputFile.write("|" + "; ".join(itSystemOwnerList))
|
| 211 |
else:
|
| 212 |
nl=outputFile.write("|")
|
| 213 |
if executiveLeadershipOwnerList:
|
| 214 |
nl=outputFile.write("|" + "; ".join(executiveLeadershipOwnerList))
|
| 215 |
else:
|
| 216 |
nl=outputFile.write("|")
|
| 217 |
if businessOwnerList:
|
| 218 |
nl=outputFile.write("|" + "; ".join(businessOwnerList))
|
| 219 |
else:
|
| 220 |
nl=outputFile.write("|")
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
chngReqList = ""
|
| 225 |
snBusinessOwnerList = set()
|
| 226 |
if i in list(serviceNowToServersMatrix.keys()):
|
| 227 |
nl=outputFile.write("|YES")
|
| 228 |
for chngReqLine in serviceNowToServersMatrix[i]:
|
| 229 |
chngReqLine = chngReqLine.replace("\n","")
|
| 230 |
chngReqLine = chngReqLine.split("|")
|
| 231 |
chngReqDt = chngReqLine[2]
|
| 232 |
## Grab just the date for now but can change to date and time if needed
|
| 233 |
chngReqDt = chngReqDt.split(" ")[0]
|
| 234 |
chngReqNumbWDate = "%s [%s]"%(chngReqLine[1],chngReqDt)
|
| 235 |
if chngReqList:
|
| 236 |
chngReqList = chngReqList + "; " +chngReqNumbWDate
|
| 237 |
else:
|
| 238 |
chngReqList = chngReqNumbWDate
|
| 239 |
if chngReqLine[3]:
|
| 240 |
snBusinessOwnerList.add("%s [%s]"%(chngReqLine[3],chngReqLine[1]))
|
| 241 |
|
| 242 |
else:
|
| 243 |
nl=outputFile.write("|NO")
|
| 244 |
if chngReqList:
|
| 245 |
nl=outputFile.write("|" + chngReqList)
|
| 246 |
else:
|
| 247 |
nl=outputFile.write("|")
|
| 248 |
if snBusinessOwnerList:
|
| 249 |
nl=outputFile.write("|" + "; ".join(snBusinessOwnerList))
|
| 250 |
else:
|
| 251 |
nl=outputFile.write("|")
|
| 252 |
|
| 253 |
|
| 254 |
nl = outputFile.write("\n")
|
| 255 |
outputFile.close() |