Question Monitoring du backup de la base AD

Plus d'informations
il y a 6 ans 10 mois #15742 par nicoh
Ce script permet de monitorer le backup de la base AD sur les dcs de la forêt ( http://powershell.nicoh.me/project/monitor-active-directory-database-backup-report-sent-by-email )

Voici le script :
[code:1]repadmin /showbackup * > c:\temp\systemstate_backup_status.txt

Function send_mail([string]$message,[string]$subject) {
$emailFrom = \"emailfrom@domain.local\"
$emailTo = \"rcpTo@domain.local\"
$emailCC = \"rcp1@domain.local,rcp2@domain.local\"
$smtpServer = \"smtp_srv.domain.local\"
Send-MailMessage -SmtpServer $smtpServer -To $emailTo -Cc $emailCC -From $emailFrom -Subject $subject -Body $message -BodyAsHtml
}

$date = Get-Date -Format \"yyyy-MM-dd\"
$report = gc c:\temp\systemstate_backup_status.txt
$message = \"<HTML><HEAD>
<style type='text/css'>
table.tftable {font-family:verdana,arial,sans-serif;font-size:12px;color:#333333;border-width: 1px;border-color: #729ea5;border-collapse: collapse;}
table.tftable th {font-family:verdana,arial,sans-serif;font-size:12px;background-color:#acc8cc;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;text-align:left;}
table.tftable tr {font-family:verdana,arial,sans-serif;background-color:#d4e3e5;}
table.tftable td {font-family:verdana,arial,sans-serif;font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;}
</style>
</HEAD><body>\"

$message_ok = @()
$message_ok += \"<table class='tftable' border='1'><tr><th><p>Domain</p></th><th><p>Hostname</p></th><th><p>AD Partition</p></th><th><p>Last backup</p></th></tr>\"
$message_ko = \"<table class='tftable' border='1'><tr><th><p>Hostname</p></th><th><p>AD Partition</p></th><th><p>Last backup</p></th></tr>\"
$message_error = \"<table class='tftable' border='1'><tr><th><p>Hostname</p></th><th><p>Error message</p></th></tr>\"

foreach ($line in $report) {
if ($line -ne \"\"«») {
if ($line -like \"Repadmin: *\"«») {
$fqdn = $line.Split(\" \"«»)[-1]
}
if ($line -like \"*dSASignature\"«») {
$index = [array]::IndexOf($report, $line)
if ($line -like \"*dSASignature\"«») {
$zone = $report[($index-2)]
}
$backup_date = $line.Split(\" \",[StringSplitOptions]'RemoveEmptyEntries')[3]
$diff = ((Get-Date $date) - (Get-Date $backup_date)).days

if ($diff -lt 2) {
$Hostname = $fqdn.split(\".\"«»)[0]
$Domain = $fqdn.split(\".\"«»)[1..(($fqdn.length) -1)] -join \".\"
$message_ok += \"<tr><td><p><font color=green>\" + $Domain + \"</p></td><td><p>\" + $Hostname + \"</p></td><td><p>\" + $zone + \"</p></td><td><p>\" + $backup_date + \"</p></td></tr>\"
}
else {
$message_ko += \"<tr><td><font color=red>\" + $fqdn + \"<td>\" + $zone + \"<td>\" + $backup_date
}
}
if ($line -like \"*error*\"«») {
$message_error += \"<tr><td><font color=red>\" + $fqdn + \"<td>\" + $line
}
}
}

$message_ok = $message_ok | sort

if ($message_ko -eq \"<table class='tftable' border='1'><tr><th><p>Hostname</p></th><th><p>AD Partition</p></th><th><p>Last backup</p></th></tr>\"«») {
$message_ko = \"<table style='color:gray;font-family:verdana,arial,sans-serif;font-size:11px;'>No problem detected</table>\"
}
$subject = \"Active Directory backup status : \"+$date
$message += \"<font face='Calibri' color='black'><i><b>AD backup problem (more than 2 days) :</b></i><br>\" + `
$message_ko + \"</table><br>\" + `
\"<font face='Calibri' color='black'><i><b>Problem to contact the following domain controller(s) :</b></i><br>\" + `
$message_error + \"</table><br>\" + `
\"<font face='Calibri' color='black'><i><b>AD backup OK :</b></i><br>\" + `
$message_ok + \"</table><br></body>\"
send_mail $message $subject


[/code:1]

My Powershell IT Script Library http://powershell.nicoh.me

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.149 secondes
Propulsé par Kunena