-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_config.py
48 lines (41 loc) · 1.16 KB
/
git_config.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
from netmiko import ConnectHandler
import os, errno
import csv
import smtplib
from email.mime.text import MIMEText
cisco_2 = {
'device_type': 'cisco_ios',
'ip': '0.0.0.0',
'username': 'max',
'password': '****',
}
net_connect = ConnectHandler(**cisco_2)
output = net_connect.send_command("show config | include ! NVRAM config")
nvramTime = output[31:43]
nvramDate = output[44:59]
def comparrison():
with open(r'C:\test.csv') as file:
last_line = file.readlines()[-1]
final = last_line.rstrip('\n')
file.close()
compare = "%s,%s" % (nvramTime,nvramDate)
if final != compare:
def writeLine():
fields=[nvramTime,nvramDate]
with open(r'C:\test.csv','ab') as f:
writer = csv.writer(f)
writer.writerow(fields)
f.close()
writeLine()
def sendMail():
with open(r'c:\test.txt', 'rb') as fp:
msg = MIMEText(fp.read())
msg['Subject'] = 'Configuration updated %s' % (compare)
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
s = smtplib.SMTP('SMTP.server.com')
s.sendmail('[email protected]','[email protected]', msg.as_string())
sendMail()
else:
print("goodbye")
comparrison()