Script: Deployment_Failure_email.ps1

$var1 = $args[0]
#$var1 = “TEST_Log”

if ($? -ne “True”)
{
Write-Host “arguments passed are invalid”
exit -3
}

$time = get-date
$smtpServer = “mail.int.XXX.com”
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer,25)

$msg.From = “INFA961_DEV_no_reply@XXXX.com”

$msg.To.Add(“XXXX.XXXX@XXXX.com”)

$msg.Body = ”
Hi Team,
The Execution of the automated ETL code deployment script has failed for the deployment group $var1 at $time.
Please find the attachemnts.

Regards,
Informatica Admin

********* Please Don’t Replay to this email ***********

write-host “var1=$var1”

$msg.Subject = “Automated ETL code deployment Script failed..”
#your file location
$files=Get-ChildItem “D:\Informatica\9.6.1\server\infa_shared\log\AUTOMATED_DEPLOY_LOGS\”

Foreach($file in $files)
{
if($file -match “$var1”)
{
Do {
$lockstatus = 0
$file1 = $null
$status = $null
Try {
#Un-Lock File

$file1=[System.io.File]::Open(“D:\Informatica\9.6.1\server\infa_shared\log\AUTOMATED_DEPLOY_LOGS\$file”,’Open’,’ReadWrite’,’None’)
$status = “Success”
}
Catch {
Write-Warning $_
$status = “Fail”
}
Write-Host “Status = ” $status
If ($status -eq “Success”) {
#Check for open handle. If valid, then lock was successful.
If ($file1.Handle -ne $null) {
$lockstatus = 1
}
}
else
{        Write-Host “Sleeping”
Sleep (Get-Random -Minimum 2 -Maximum 10)
}
Write-Host “LockStatus = ” $lockstatus
}
Until ($lockstatus -eq 1)
#Do Somthing… #Unlock
$file1.Close()
Write-Host $file
Write-Host “Attaching File :- ” $file
$attachment = New-Object System.Net.Mail.Attachment –ArgumentList “D:\Informatica\9.6.1\server\infa_shared\log\AUTOMATED_DEPLOY_LOGS\$file”
$msg.Attachments.Add($attachment)
}
}
$smtp.Send($msg)
$attachment.Dispose();
$msg.Dispose();
$smtp.Dispose();

exit

Advertisements