Hi all,
Please use blow script to send procedure logs to specified email addresses,
Input details:
sendto=the recipient’s email addresses
sendfrom == the sender’s email address
username- Set username if it is different from email address
password-sender email password
s_server= smtp server’s host name( sender mail settings)
s_port=smtp server’s port number (sender mail settings)
sendto='xxxxxxx@gmail.com,yyyyyyy@gmail.com,zzzzzzz@gmail.com'
sendfrom='yyyyy@gmail.com'
username=sendfrom;
password='yyyyy'
s_server='smtp.gmail.com'
s_port='465'
#Required inputs
#sendto=the recipient's email addresses
#sendfrom == the sender's email address
#username- Set username if it is different from email address
#password-sender email password
#s_server= smtp server's host name( sender mail settings)
#s_port=smtp server's port number (sender mail settings)
import os
import re
import smtplib
from email.mime.text import MIMEText
drive=os.environ['SYSTEMDRIVE']
device=os.environ['COMPUTERNAME']
if 'PROGRAMW6432' in os.environ.keys():
path=drive+'\\Program Files (x86)\\COMODO\\Comodo ITSM\\rmmlogs'
else:
path=drive+'\\Program Files\\COMODO\\Comodo ITSM\rmmlogs'
temp=os.environ['TEMP']
filelist = [f for f in os.listdir(path) if re.match( r'Rmm_dll.*' , f)]
num=list(range(1,len(filelist)))
out=open(path+'\ emp1.txt','w')
fo=open(path+'\\Rmm_dll.log', "r+")
out.write(fo.read())
for file in num:
fo=open(path+'\\Rmm_dll.log.'+str(file), "r+")
out.write(fo.read())
fo.close()
out.close()
t1=open(path+'\ emp1.txt',"r+")
log=t1.readlines()
t1.close()
t2=open(path+'\ emp2.txt',"w+")
for i in list(range(len(log))):
if 'MsgProcedureRule/name:' in log[i]:
t2.write(log[i])
elif 'MsgProcedureReply: status: PROCEDURE_FINISHED' in log[i]:
t2.write(log[i])
for j in log[i:]:
if 'MsgProcedureReply: runnerUsername' in j:
t2.write(j)
break
elif 'MsgProcedureResult: procedureData:' in log[i]:
(count,find)=(i,i)
for k in log[count+1:]:
find=find +1
if 'Session ID' in k:
t2.write('
'.join(log[count:find]))
t2.write('
')
break
t2.close()
new=open(path+'\ emp3.txt','w')
with open(path+'\ emp2.txt','r+') as file1:
for line in file1:
if 'MsgProcedureRule/name' in line:
new.write('
')
new.write("############################ PROCEDURE EXECUTION STATUS!!################################
")
new.write(line)
elif not line.isspace():
new.write(line)
file1.close()
new.close()
with open(path+'\ emp3.txt','r+') as fb:
msg = MIMEText(fb.read())
fb.close()
msg['Subject'] = 'Procedure logs from the device '+device
msg['From'] = sendfrom
msg['To'] = sendto
try:
os.remove(path+'\ emp1.txt')
os.remove(path+'\ emp2.txt')
os.remove(path+'\ emp3.txt')
except:
pass
try:
s=smtplib.SMTP_SSL(s_server,s_port)
s.login(username,password)
s.sendmail(sendfrom,[sendto],msg.as_string())
s.quit()
print('Successfully sent email');
except Exception as e:
print(e)
Sample output :