Merge remote-tracking branch 'origin/main'
# Conflicts: # README.md
This commit is contained in:
93
NotifyOfDisabledJobs.ps1
Normal file
93
NotifyOfDisabledJobs.ps1
Normal file
@@ -0,0 +1,93 @@
|
||||
<#
|
||||
************************************************************************************
|
||||
PowerShell script that checks for disabled jobs and sends an e-mail containing the list
|
||||
of disabled Veeam jobs.
|
||||
************************************************************************************
|
||||
#>
|
||||
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
|
||||
$ScriptDir = 'C:\setup\script'
|
||||
$JobExclusionFilterFile = "$ScriptDir\NotifyOfDisabledJobs_EXCLUSIONS.IN"
|
||||
$MailTo = @(
|
||||
"KrapivinAA@nornik.ru"
|
||||
"RudenkoVV@nornik.ru"
|
||||
"smolinmv@nornik.ru"
|
||||
)
|
||||
$MailFrom = "smolinmv@nornik.ru"
|
||||
$MailSubject = "ALERT: Veeam jobs disabled"
|
||||
$SMTPServer = ""
|
||||
$SMTPPort = 587
|
||||
$SMTPUser = "smolinmv@nornik.ru"
|
||||
$SMTPPass = ""
|
||||
$SMTPUseSSL = $true
|
||||
# Использовать TLS 1.2
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$DisabledJobs = Get-VBRJob | Where-Object {
|
||||
$_.Info.IsScheduleEnabled -eq $false
|
||||
}
|
||||
if ($DisabledJobs) {
|
||||
if ((Test-Path $JobExclusionFilterFile) -and
|
||||
(-not [string]::IsNullOrWhiteSpace((Get-Content $JobExclusionFilterFile)))) {
|
||||
$JobsToExclude = Get-Content $JobExclusionFilterFile
|
||||
$DisabledJobsWithExclusions = $DisabledJobs.Name |
|
||||
Select-String -Pattern $JobsToExclude -NotMatch |
|
||||
Out-String
|
||||
$JobsToExclude = $JobsToExclude | Out-String
|
||||
$FinalReport = $DisabledJobsWithExclusions
|
||||
}
|
||||
else {
|
||||
Write-Host "No job exclusion filter set"
|
||||
$JobsToExclude = "None"
|
||||
$FinalReport = $DisabledJobs.Name | Out-String
|
||||
}
|
||||
$EmailBody = @"
|
||||
Пожалуйста, проверьте следующие отключенные задания Veeam и повторно включите их, повторно включите или удалите расписание, либо добавьте их в файл списка исключений.:
|
||||
$FinalReport
|
||||
Задания, имеющие следующие поисковые фильтры, исключаются из отчета.:
|
||||
$JobsToExclude
|
||||
"@
|
||||
Write-Host $EmailBody
|
||||
$SMTPCredential = New-Object System.Management.Automation.PSCredential(
|
||||
$SMTPUser,
|
||||
(ConvertTo-SecureString $SMTPPass -AsPlainText -Force)
|
||||
)
|
||||
# Отключаем проверку сертификата
|
||||
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {
|
||||
param($sender, $certificate, $chain, $sslPolicyErrors)
|
||||
return $true
|
||||
}
|
||||
try {
|
||||
$mail = New-Object System.Net.Mail.MailMessage
|
||||
$mail.From = $MailFrom
|
||||
foreach ($Recipient in $MailTo) {
|
||||
$mail.To.Add($Recipient)
|
||||
}
|
||||
$mail.Subject = $MailSubject
|
||||
$mail.Body = $EmailBody
|
||||
$mail.IsBodyHtml = $false
|
||||
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort)
|
||||
$smtp.EnableSsl = $SMTPUseSSL
|
||||
$smtp.Credentials = $SMTPCredential
|
||||
$smtp.Send($mail)
|
||||
Write-Host "E-mail sent successfully." -ForegroundColor Green
|
||||
}
|
||||
catch {
|
||||
Write-Host "SMTP Error:" -ForegroundColor Red
|
||||
Write-Host $_.Exception.Message -ForegroundColor Red
|
||||
if ($_.Exception.InnerException) {
|
||||
Write-Host $_.Exception.InnerException.Message -ForegroundColor Yellow
|
||||
}
|
||||
}
|
||||
finally {
|
||||
# Возвращаем стандартную проверку сертификатов
|
||||
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null
|
||||
if ($mail) {
|
||||
$mail.Dispose()
|
||||
}
|
||||
if ($smtp) {
|
||||
$smtp.Dispose()
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Host "No disabled jobs"
|
||||
}
|
||||
35
README.md
35
README.md
@@ -1,9 +1,12 @@
|
||||
# Veeam Backup Jobs for Zabbix
|
||||
|
||||
This repository contains a PowerShell collector and a Zabbix 7.0 template for
|
||||
monitoring Veeam Backup & Replication jobs.
|
||||
This repository contains PowerShell scripts for Veeam Backup & Replication:
|
||||
|
||||
## Collector output
|
||||
- `Monitor-VeeamJobs.ps1` collects job metrics for Zabbix.
|
||||
- `NotifyOfDisabledJobs.ps1` sends an email when disabled jobs are detected.
|
||||
- `zabbix-templete-veeam-jobs.xml` imports the Zabbix 7.0 template.
|
||||
|
||||
## Zabbix collector output
|
||||
|
||||
`Monitor-VeeamJobs.ps1` prints one compressed JSON object by default:
|
||||
|
||||
@@ -61,3 +64,29 @@ Use a red threshold for `veeam.jobs.error`, yellow for `veeam.jobs.warning`, and
|
||||
keep `veeam.jobs.disabled` aligned with the existing exclusion policy. The
|
||||
template intentionally keeps `veeam.jobs.disabled.excluded.names`, because some
|
||||
disabled policies are expected.
|
||||
|
||||
## Email notification script
|
||||
|
||||
`NotifyOfDisabledJobs.ps1` sends an email if one or more Veeam jobs are disabled.
|
||||
To exclude expected disabled jobs, add keywords to:
|
||||
|
||||
```text
|
||||
C:\Scripts\Veeam\NotifyOfDisabledJobs_EXCLUSIONS.IN
|
||||
```
|
||||
|
||||
Example exclusions:
|
||||
|
||||
```text
|
||||
Backup_FILE01
|
||||
Backup_FILE47
|
||||
Replication_FILE
|
||||
```
|
||||
|
||||
Example batch launch:
|
||||
|
||||
```bat
|
||||
powershell.exe c:\scripts\Veeam\NotifyOfDisabledJobs.ps1
|
||||
```
|
||||
|
||||
The original workflow runs this check every four hours, so intentionally disabled
|
||||
jobs can be excluded while unexpected disabled jobs still raise a notification.
|
||||
|
||||
Reference in New Issue
Block a user