Delete azureiptracker directory

This commit is contained in:
Bruno Rodrigues 2021-11-23 10:08:05 +00:00 коммит произвёл GitHub
Родитель 20ed10c654
Коммит 0f02f422a0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 0 добавлений и 189 удалений

Просмотреть файл

@ -1 +0,0 @@

Просмотреть файл

@ -1,105 +0,0 @@
import os
import shutil
import time
import getfileloop
import create_files
import listcompare
import teams
import create_folders
#Create folders
downloads = create_folders.CreateFolder('downloads')
archieve = create_folders.CreateFolder('archieve')
compare_files_new = create_folders.CreateFolder('compare_files_new')
compare_files_old = create_folders.CreateFolder('compare_files_old')
try:
downloads.createfolder()
except FileExistsError:
print('Folder downloads already exists')
try:
archieve.createfolder()
except FileExistsError:
print('Folder archieve already exists')
try:
compare_files_new.createfolder()
except FileExistsError:
print('Folder compare_files_new already exists')
try:
compare_files_old.createfolder()
except FileExistsError:
print('Folder compare_files_old already exists')
#Get baseline to archieve
baseline_file = input('Enter the baseline filename: ')
shutil.copy(f'./{baseline_file}', f'./downloads/{baseline_file}')
shutil.move(f'./{baseline_file}', f'./archieve/{baseline_file}')
#Test Teams connectivity
webhook = input('Please enter your Microsoft Teams webhook link: ')
send_teams_test = teams.Teams(webhook, 'Azure IP Tracker is now reporting to your Teams Channel')
send_teams_test.teams()
#Create the files with subnets
try:
old_filenames = create_files.Createfile('archieve', 'compare_files_old')
old_filenames.createfile()
new_filenames = create_files.Createfile('downloads', 'compare_files_new')
new_filenames.createfile()
except Exception as e:
print(e)
#Loop non stop
while True:
#Download new file and replace old one in archieve
try:
if not os.listdir('./downloads'):
getfileloop.Downloadloop.downloadloop()
else:
getfileloop.Downloadloop.downloadcleanup()
getfileloop.Downloadloop.downloadloop()
except Exception as e:
print(f'{e} - Waiting for new file')
time.sleep(28800)
continue
#Create the files with subnets
try:
old_filenames = create_files.Createfile('archieve', 'compare_files_old')
old_filenames.createfile()
new_filenames = create_files.Createfile('downloads', 'compare_files_new')
new_filenames.createfile()
except Exception as e:
print(e)
#compare the files and send them to teams
try:
files = os.listdir('./compare_files_new')
for filename in files:
ActionGroup_new = listcompare.Listcompare('compare_files_new', filename)
ActionGroup_old = listcompare.Listcompare('compare_files_old', filename)
list_new = set(ActionGroup_new.compare())
list_old = set(ActionGroup_old.compare())
subnets_added = set(list_new) - set(list_old)
subnets_removed = set(list_old) - set(list_new)
if not subnets_added:
continue
elif not subnets_removed:
continue
else:
send_teams_added = teams.Teams(webhook, f'subnets added to {filename}: {subnets_added}')
send_teams_added.teams()
print(f'Subnets added to {filename}: ')
print(subnets_added)
send_teams_removed = teams.Teams(webhook, f'subnets removed to {filename}: {subnets_removed}')
send_teams_removed.teams()
print(f'Subnets removed from {filename}: ')
print(subnets_removed)
except Exception as e:
send_teams_created = teams.Teams(webhook, f'New group of subnets added - {filename}')
send_teams_created.teams()
print(f'New group of subnets added - {filename}')
print(f'#{time.asctime(time.localtime(time.time()))} - Waiting for new file')

Просмотреть файл

@ -1,26 +0,0 @@
import os
import json
class Createfile:
def __init__(self, read_dir, write_dir):
self.read_dir = read_dir
self.write_dir = write_dir
def createfile(self):
try:
json_file = os.listdir(f'./{self.read_dir}')
with open(f'./{self.read_dir}/{json_file[0]}') as js:
data_new = json.load(js)
for value in data_new['values']:
filename_new = value['name']
create_filename_new = open(f'./{self.write_dir}/{filename_new}', 'w')
for subnet in value['properties']['addressPrefixes']:
create_filename_new.writelines(f'\n{subnet}')
except Exception as e:
print(e)
old_filename = Createfile('downloads', 'compare_files_new')
old_filename.createfile()
new_filename = Createfile('archieve', 'compare_files_old')
new_filename.createfile()

Просмотреть файл

@ -1,9 +0,0 @@
import os
class CreateFolder:
def __init__(self, folder):
self.folder = folder
def createfolder(self):
os.mkdir(self.folder)

Просмотреть файл

@ -1,20 +0,0 @@
import urllib.request
import time
import os
class Downloadloop:
def downloadloop():
today = time.strftime('%Y%m%d')
url = f'https://download.microsoft.com/download/7/1/D/71D86715-5596-4529-9B13-DA13A5DE5B63/ServiceTags_Public_{today}.json'
urllib.request.urlretrieve(url, f'./downloads/ServiceTags_Public_{today}.json')
r = urllib.request.urlopen(url)
print(f'ServiceTags_Public_{today}.json created #{time.asctime(time.localtime(time.time()))}')
def downloadcleanup():
archievefoler = os.listdir('./archieve')
for file in archievefoler:
os.remove(f'./archieve/{file}')
downloadfolder = os.listdir('./downloads')
for file in downloadfolder:
os.rename(f'downloads/{file}', f'archieve/{file}')

Просмотреть файл

@ -1,16 +0,0 @@
class Listcompare:
def __init__(self, directory, filename):
self.directory = directory
self.filename = filename
self.list = []
def compare(self):
filename = open(f'./{self.directory}/{self.filename}')
lines = filename.readlines()
for line in lines:
if not line.strip():
continue
else:
self.list.append(line)
return self.list

Просмотреть файл

@ -1 +0,0 @@
pymsteams

Просмотреть файл

@ -1,11 +0,0 @@
import pymsteams
class Teams:
def __init__(self, webhook, message):
self.webhook = webhook
self.message = message
def teams(self):
myTeamsMessage = pymsteams.connectorcard(f"{self.webhook}")
myTeamsMessage.text(f"{self.message}")
myTeamsMessage.send()