-
-
Save darrenjrobinson/30db0f65c4538959b6900328b0ab98f4 to your computer and use it in GitHub Desktop.
Import Validation on FIM/MIM Authoritative Source Management Agent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Lithnet Module | |
import-module LithnetMIISAutomation | |
# Authoratative Source Management Agent | |
$AuthMAName = "SSF MA" | |
# Import Profile Name | |
$ImportRunProfileName = "FISO" | |
# Delta Sync Only Run Profile | |
$DeltaSyncRunProfileName = 'DS' | |
# Full Sync Only Run Profile | |
$FullSyncRunProfileName = 'FS' | |
# Validation Settings | |
[int]$maxChangesInPercent = '1' | |
# Abort flag | |
$blnAbort = $false | |
# SMTP Settings | |
$fromAddress = 'Customer MIM Sync Engine <identity@customer.com.au>' | |
$smtpServer = 'smtp.customer.com.au' | |
[string[]]$toAddress = 'helpdesk@customer.com.au','mimadmin@customer.com.au' | |
$smtpSubject = 'Customer MIM SSF Fuse Triggered' | |
$smtpBodyBase = '<h1>Customer Success Factors Import Sync Halted</h1> </br>The SSF Import has been evaluated and it has failed based on too high a variation from the previous sync.</br>' | |
# Get Authoratative Source MA Details from the last run | |
$AuthMA = Get-ManagementAgent -Name $AuthMAName | |
$previousRun = Get-LastRunDetails -MA $AuthMAName | |
[int]$previousRunNumber = $previousRun.RunNumber | |
# Check to make sure previous run was an import (not export). If not find last Import based on RunProfileName | |
if (!$previousRun.RunProfileName.Equals($ImportRunProfileName)){ | |
[int]$Run = $previousRun.RunNumber - 1 | |
do { | |
$previousRun = Get-RunDetail -MA $AuthMAName -RunNumber $Run | |
$Run-- | |
} until ($previousRun.RunProfileName.Equals($ImportRunProfileName)) | |
} | |
if ($previousRun){ | |
# Previous Import Counters | |
$PrevStagingCounters = $previousRun.StepDetails.StagingCounters | |
[int]$PrevStageAdd = $previousRun.StepDetails.StagingCounters.StageAdd | |
[int]$PrevStageUpdate = $previousRun.StepDetails.StagingCounters.StageUpdate | |
[int]$PrevStageDelete = $previousRun.StepDetails.StagingCounters.StageDelete | |
[int]$PrevStageRename = $previousRun.StepDetails.StagingCounters.StageRename | |
[int]$PrevStageNoChange = $previousRun.StepDetails.StagingCounters.StageNoChange | |
# Previous Total Objects | |
[int]$PrevStagingTotal = $PrevStageNoChange + $PrevStageAdd + $PrevStageUpdate + $PrevStageRename - $PrevStageDelete | |
# Run an Import (Stage Only) | |
Start-ManagementAgent -RunProfileName $ImportRunProfileName -MA $AuthMAName | |
$newImport = Get-LastRunDetails -MA $AuthMAName | |
# Current Details | |
[int]$CurrentStageAdd = $newImport.StepDetails.StagingCounters.StageAdd | |
[int]$CurrentStageUpdate = $newImport.StepDetails.StagingCounters.StageUpdate | |
[int]$CurrentStageDelete = $newImport.StepDetails.StagingCounters.StageDelete | |
[int]$CurrentStageRename = $newImport.StepDetails.StagingCounters.StageRename | |
[int]$CurrentStageNoChange = $newImport.StepDetails.StagingCounters.StageNoChange | |
# Current Total Objects | |
[int]$CurrentStagingTotal = $CurrentStageNoChange + $CurrentStageAdd + $CurrentStageUpdate + $CurrentStageRename - $CurrentStageDelete | |
# Check number of UPDATES | |
# Send email if outside of threshold | |
if ($CurrentStageUpdate -gt ($PrevStagingTotal * ($maxChangesInPercent/100))){ | |
$smtpBody = $smtpBodyBase | |
$smtpBody += "There are $($CurrentStageUpdate) connector updates incoming from $($AuthMAName)</br>" | |
$smtpBody += "This in excess of the $($maxChangesInPercent)% threshold which is $($PrevStagingTotal * ($maxChangesInPercent/100)).</br>" | |
$smtpBody += "</br>Connect to the MIM Sync Server and validate the import before manually running a Delta or Full Synchronisation.</br>" | |
# Import Details | |
$smtpDetails = $newImport.StepDetails.StagingCounters | ConvertTo-Html | |
$smtpBody += $smtpDetails | |
$blnAbort = $true | |
Send-MailMessage -SmtpServer $smtpServer -To $toAddress -From $fromAddress -Subject $smtpSubject -Body $smtpBody -BodyAsHtml | |
} | |
# Check number of ADDS | |
# Send email if outside of threshold | |
if ($CurrentStageAdd -gt ($PrevStagingTotal * ($maxChangesInPercent/100))){ | |
$smtpBody = $smtpBodyBase | |
$smtpBody += "There are $($CurrentStageAdd) NEW connectors incoming from $($AuthMAName)</br>" | |
$smtpBody += "This in excess of the $($maxChangesInPercent)% threshold which is $($PrevStagingTotal * ($maxChangesInPercent/100)).</br>" | |
$smtpBody += "</br>Connect to the MIM Sync Server and validate the import before manually running a Delta or Full Synchronisation.</br>" | |
# Import Details | |
$smtpDetails = $newImport.StepDetails.StagingCounters | ConvertTo-Html | |
$smtpBody += $smtpDetails | |
$blnAbort = $true | |
Send-MailMessage -SmtpServer $smtpServer -To $toAddress -From $fromAddress -Subject $smtpSubject -Body $smtpBody -BodyAsHtml | |
} | |
# Check number of DELETES | |
# Send email if outside of threshold | |
if ($CurrentStageDelete -gt ($PrevStagingTotal * ($maxChangesInPercent/100))){ | |
$smtpBody = $smtpBodyBase | |
$smtpBody += "There are $($CurrentStageDelete) DELETES incoming from $($AuthMAName)</br>" | |
$smtpBody += "This in excess of the $($maxChangesInPercent)% threshold which is $($PrevStagingTotal * ($maxChangesInPercent/100)).</br>" | |
$smtpBody += "</br>Connect to the MIM Sync Server and validate the import before manually running a Delta or Full Synchronisation.</br>" | |
# Import Details | |
$smtpDetails = $newImport.StepDetails.StagingCounters | ConvertTo-Html | |
$smtpBody += $smtpDetails | |
$blnAbort = $true | |
Send-MailMessage -SmtpServer $smtpServer -To $toAddress -From $fromAddress -Subject $smtpSubject -Body $smtpBody -BodyAsHtml | |
} | |
# If we don't have a reason to Abort, run the Delta Sync | |
if (!$blnAbort) { | |
Start-ManagementAgent -MA $AuthMAName -RunProfileName $DeltaSyncRunProfileName | |
} | |
} else { | |
# Run History Cleared or first run. | |
Send-MailMessage -SmtpServer $smtpServer -To $toAddress -From $fromAddress -Subject $smtpSubject -Body '<h1>Customer Success Factors Import Sync Halted</h1> </br>The SSF Import will be skipped as there is no Run History to validate against. </br>This is probably because the Run History has been cleared, or the Management Agent has never been run. If so perform execute an Import Run Profile manually.</br>' -BodyAsHtml | |
} | |
# Exit | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment