adding work scripts
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
$StartTime = (Get-Date).AddMinutes(-<minutes>)
|
||||
$ID=<event_id>
|
||||
Get-WinEvent -FilterHashtable @{
|
||||
LogName='Application'
|
||||
ProviderName='Qlik Enterprise Manager'
|
||||
Id=$ID
|
||||
StartTime=$StartTime
|
||||
} | fl * | Out-File -FilePath events.log -Append
|
||||
@@ -0,0 +1,120 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Email Template</title>
|
||||
<style type="text/css">
|
||||
table.basic_lines {
|
||||
height:300px;
|
||||
width:900px;
|
||||
border: 3px solid #000;
|
||||
}
|
||||
|
||||
.header {
|
||||
height: 40px;
|
||||
color: white;
|
||||
background: #022664;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#logo {
|
||||
float: right;
|
||||
margin-top: -45px;
|
||||
}
|
||||
|
||||
.row_label {
|
||||
height: 45px;
|
||||
}
|
||||
|
||||
.odd_row_data {
|
||||
background: #B6DCFC;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
padding-left: 2%;
|
||||
}
|
||||
|
||||
.even_row_data {
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
padding-left: 2%;
|
||||
}
|
||||
|
||||
a {
|
||||
color: white;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.col_label {
|
||||
width: 175px;
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
background: #2967AE;
|
||||
padding-left: 2%;
|
||||
}
|
||||
|
||||
#contact_info {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
#footer {
|
||||
height: 35px;
|
||||
text-align: center;
|
||||
font: bold;
|
||||
font-size: 10px;
|
||||
color: white;
|
||||
background: #022664;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table class="basic_lines">
|
||||
<caption>Qlik Replicate Performance Alert</caption>
|
||||
<th>
|
||||
<tr>
|
||||
<td class="header" colspan="2">GRM US - Information Management Technology Alert<br/>Qlik Replicate Performance Alert</td>
|
||||
</tr>
|
||||
<tr class="row_label">
|
||||
<td class="col_label">Date</td>
|
||||
<td class = "odd_row_data">DateNow</td>
|
||||
</tr>
|
||||
<tr class="row_label">
|
||||
<td class="col_label">Affected Application(s)</td>
|
||||
<td class = "even_row_data">Attunity Qlik Replicate</td>
|
||||
</tr>
|
||||
<tr class="row_label">
|
||||
<td class="col_label">Event</td>
|
||||
<td class = "odd_row_data">Errors reported for the following objects below:</td>
|
||||
</tr>
|
||||
<tr class="row_label">
|
||||
<td class="col_label">Impact</td>
|
||||
<td class = "even_row_data">Objects listed below are currently in an ERRORED state.</td>
|
||||
</tr>
|
||||
<tr class="row_label">
|
||||
<td class="col_label">Action Required</td>
|
||||
<td class = "odd_row_data">This is an informational notification and no action is required by the users.</td>
|
||||
</tr>
|
||||
<tr class="row_label">
|
||||
<td class="col_label">Contact & Additional Information</td>
|
||||
<td class = "even_row_data">Support teams have been notified of the issue and are working to address it.<br/>If you have any questions, please email: PM EDW Prod Support</td>
|
||||
</tr>
|
||||
</th>
|
||||
|
||||
</table>
|
||||
ContentHere
|
||||
<table class="basic_lines">
|
||||
<caption> No Reply Notice</caption>
|
||||
<th>
|
||||
<tr class="row_label">
|
||||
<td id="footer" colspan="2">Please do not reply to this message. All replies to this message are routed to an unmonitored mailbox.</td>
|
||||
</tr>
|
||||
<tr class="row_label">
|
||||
<td id="footer" colspan="2"><a href="https://libertymutual.sharepoint.com/:x:/r/sites/InformationManagement/_layouts/15/Doc.aspx?sourcedoc=%7BCDD784EF-E954-41AC-9A1E-3E0AC1BB095B%7D&file=Data%20Recovery%20Master%20Runbook.xlsx&wdOrigin=TEAMS-ELECTRON.p2p.mw&action=default&mobileredirect=true">Support Link: Data Recovery Master Runbook</a></td>
|
||||
</tr>
|
||||
<tr class="row_label">
|
||||
<td id="footer" colspan="2"><a href="https://libertymutual.sharepoint.com/:w:/r/sites/InformationManagement/_layouts/15/Doc.aspx?sourcedoc=%7BCF7C233A-A02C-4511-9C21-1F7DD62E658E%7D&file=TRANS%20layer%20Data-recovery%20Runbook.docx&wdOrigin=TEAMS-ELECTRON.p2p.mw&action=default&mobileredirect=true">Support Link: TRANS Layer Data Recovery Runbook</a></td>
|
||||
</tr>
|
||||
</th>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,201 @@
|
||||
"""
|
||||
Copyright 2018 Attunity
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
"""
|
||||
Copyright 2018 Attunity
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
# coding: utf-8
|
||||
import os, datetime, fileinput, shutil
|
||||
import smtplib
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
def emailsupport(messagetype, messagefile):
|
||||
"""Send to Email"""
|
||||
me = GGENV = "Qlik_Admin@LibertyMutual.com"
|
||||
you = ['HTTP_509@LibertyMutual.com', 'PMEDW_Prod_Support@LibertyMutual.com', 'QLIK_ADMIN@LibertyMutual.com']
|
||||
#you = ['Wendell.Jones@libertymutual.com']
|
||||
#you = CONFIG.get('global', 'receivers').split()
|
||||
|
||||
# Open a plain text file for reading. For this example, assume that
|
||||
# the text file contains only ASCII characters.
|
||||
message_part = open(messagefile, 'r')
|
||||
part2 = MIMEText(message_part.read(), 'html')
|
||||
# Create a text/plain message
|
||||
message_part.close()
|
||||
|
||||
msg = MIMEMultipart('alternative')
|
||||
|
||||
msg['Subject'] = messagetype
|
||||
|
||||
msg['From'] = me
|
||||
msg['To'] = ",".join(you)
|
||||
|
||||
msg.attach(part2)
|
||||
|
||||
# Send the message via our own SMTP server, but don't include the envelope header.
|
||||
sendmail(me, you, msg.as_string())
|
||||
|
||||
|
||||
# Set header automation statement for email
|
||||
def openemail(emailfile):
|
||||
emailfile.write("<p>THIS IS AN AUTOMATED NOTIFICATION. PLEASE DO NOT RESPOND TO THIS E-MAIL.</p>")
|
||||
emailfile.write("<html>\n")
|
||||
emailfile.write("<table border='1'>\n")
|
||||
|
||||
|
||||
# Set footer automation statement for email
|
||||
def closeemail(emailfile):
|
||||
emailfile.write("</table>\n")
|
||||
emailfile.write("<p>THIS IS AN AUTOMATED NOTIFICATION. PLEASE DO NOT RESPOND TO THIS E-MAIL.</p>")
|
||||
emailfile.write("\t</body>")
|
||||
emailfile.write("</html>\n")
|
||||
|
||||
|
||||
def sendmail(me, you, mailmsg):
|
||||
# Send the message via our own SMTP server, but don't include the envelope header.
|
||||
try:
|
||||
s = smtplib.SMTP('smtprelay.lmig.com')
|
||||
s.sendmail(me, you, mailmsg)
|
||||
s.quit()
|
||||
except smtplib.SMTPException:
|
||||
print('Email was drafted but I was unable to send it. Unable to connect to mailserver')
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
CONFIG = configparser.RawConfigParser(allow_no_value=True)
|
||||
CONFIG.read('settings.ini')
|
||||
minutes = '180'
|
||||
|
||||
nowstamp = datetime.datetime.now()
|
||||
script_name = os.path.basename(__file__)
|
||||
temp_script_dir = os.path.realpath(__file__)
|
||||
script_dir = temp_script_dir.replace(script_name, '')
|
||||
print(script_dir)
|
||||
ps_template = f'{script_dir}error_check_template.ps1'
|
||||
print(f'Starttime: {nowstamp}')
|
||||
|
||||
# Server changes
|
||||
server_change_codes = ['300','303','320']
|
||||
# Server erors/warnings
|
||||
server_error_codes = ['301','302','321','322','323','340']
|
||||
# Normal Task Events
|
||||
task_change_codes = ['400','401','402','403','404','405','507','508']
|
||||
# Error/Warning Task Events
|
||||
task_error_codes = ['261','263','406','430','431','432','433','434','435']
|
||||
|
||||
# Table Suspended
|
||||
suspend_codes = ['502','506']
|
||||
|
||||
for event_id in server_error_codes:
|
||||
ps_file = f'{event_id}_error_check.ps1'
|
||||
shutil.copy(ps_template, ps_file)
|
||||
# with fileinput.FileInput(ps_file, inplace=True, backup=f'_bak') as file:
|
||||
with fileinput.FileInput(ps_file, inplace=True) as file:
|
||||
for line in file:
|
||||
if '<minutes>' in line:
|
||||
newline = line.replace('<minutes>', minutes)
|
||||
print(newline.rstrip())
|
||||
elif '<event_id>' in line:
|
||||
newline = line.replace('<event_id>', event_id)
|
||||
print(newline.rstrip())
|
||||
else:
|
||||
print(line.rstrip())
|
||||
subprocess.run(["powershell.exe", f".\{ps_file}"], shell=True)
|
||||
os.remove(ps_file)
|
||||
for event_id in task_error_codes:
|
||||
ps_file = f'{event_id}_error_check.ps1'
|
||||
shutil.copy(ps_template, ps_file)
|
||||
# with fileinput.FileInput(ps_file, inplace=True, backup=f'_bak') as file:
|
||||
with fileinput.FileInput(ps_file, inplace=True) as file:
|
||||
for line in file:
|
||||
if '<minutes>' in line:
|
||||
newline = line.replace('<minutes>', minutes)
|
||||
print(newline.rstrip())
|
||||
elif '<event_id>' in line:
|
||||
newline = line.replace('<event_id>', event_id)
|
||||
print(newline.rstrip())
|
||||
else:
|
||||
print(line.rstrip())
|
||||
subprocess.run(["powershell.exe", f".\{ps_file}"], shell=True)
|
||||
#os.remove(ps_file)
|
||||
for event_id in suspend_codes:
|
||||
ps_file = f'{event_id}_error_check.ps1'
|
||||
shutil.copy(ps_template, ps_file)
|
||||
#with fileinput.FileInput(ps_file, inplace=True, backup=f'_bak') as file:
|
||||
with fileinput.FileInput(ps_file, inplace=True) as file:
|
||||
for line in file:
|
||||
if '<minutes>' in line:
|
||||
newline = line.replace('<minutes>', minutes)
|
||||
print(newline.rstrip())
|
||||
elif '<event_id>' in line:
|
||||
newline = line.replace('<event_id>', event_id)
|
||||
print(newline.rstrip())
|
||||
else:
|
||||
print(line.rstrip())
|
||||
subprocess.run(["powershell.exe", f".\{ps_file}"], shell=True)
|
||||
os.remove(ps_file)
|
||||
|
||||
file_stats = os.stat('events.log')
|
||||
if file_stats.st_size > 0:
|
||||
events = ''
|
||||
eventfile = open('events.log', 'r')
|
||||
for line in eventfile:
|
||||
#print(line.rstrip())
|
||||
if len(line) > 23:
|
||||
events += f"{line.rstrip()}<br/>\n"
|
||||
eventfile.close()
|
||||
# print(events)
|
||||
# exit()
|
||||
environments = []
|
||||
timestamp = nowstamp.strftime("%m/%d/%Y, %H:%M:%S")
|
||||
html_report = open('error_template.html', 'r')
|
||||
latency_list = []
|
||||
latency = open('error.html', 'w')
|
||||
openemail(latency)
|
||||
for line in html_report:
|
||||
if 'DateNow' in line:
|
||||
latency.write(line.replace('DateNow', timestamp))
|
||||
elif 'ContentHere' in line:
|
||||
latency.write(line.replace('ContentHere', f'<p style="background: #B6DCFC;">{events}</p>'))
|
||||
else:
|
||||
latency.write(line)
|
||||
closeemail(latency)
|
||||
latency.close()
|
||||
subjectenvironment = ' & '.join(environments)
|
||||
emailsupport(f'ERROR EVENT(S) DETECTED IN {subjectenvironment} QLIK REPLICATE', 'error.html')
|
||||
print(f'ERROR EVENT(S) DETECTED IN {subjectenvironment} QLIK REPLICATE')
|
||||
nowstamp = datetime.datetime.now()
|
||||
os.remove('error.html')
|
||||
os.remove('events.log')
|
||||
nowstamp = datetime.datetime.now()
|
||||
print(f'Endtime: {nowstamp}')
|
||||
#print('errors_detected: ' + str(latency_detected))
|
||||
Reference in New Issue
Block a user