Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Why? Because the execution of this command can take between 30 seconds and more
- Result of each jobs
- Execution status for each jobs
- Next run time of each jobs

### 5. Veeam Jobs Replication Backup:
- Result of each jobs
- Execution status for each jobs
Expand Down Expand Up @@ -112,6 +112,14 @@ Why? Because the execution of this command can take between 30 seconds and more

## Setup

### Automatic scripted installation
Run Setup.ps1 for installing the monitoring script on hosts.

### Manual installation

Your host must have PowerShell 3.0 or above. Install upgrade from [Microsoft Download](https://www.microsoft.com/en-us/download/details.aspx?id=34595) for
windows 7 and Windows 2008.

1. Install the Zabbix agent on your host
2. Copy `zabbix_vbr_job.ps1` in the directory : `C:\Program Files\Zabbix Agent\scripts\` (create folder if not exist)
3. Add the following line to your Zabbix agent configuration file:
Expand Down
118 changes: 118 additions & 0 deletions Setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
param(
[switch]$no_elevate
)

function Restart-Zabbix {
$Zabbix_Service = Get-Service -Name 'Zabbix Agent' -ErrorAction SilentlyContinue
if ($Zabbix_Service -ne $null -and $Zabbix_Service.Status -eq 'Running') {
$Zabbix_Service | Restart-Service
}
}

function Get-ZabbixAgent {
$service_config = Get-Item 'HKLM:\SYSTEM\CurrentControlSet\Services\Zabbix Agent' -ErrorAction SilentlyContinue
if ($service_config -ne $null) {
$image_path = $service_config.GetValue('ImagePath')
if ($image_path -match "^`"([^`"]*)`".*$") {
return $Matches[1]
}
return $image_path -replace "--config .*", ""
}

throw 'Zabbix not installed'
}

function Get-ZabbixPath {
$install_x64 = Get-Item 'HKLM:\SOFTWARE\Zabbix SIA\Zabbix Agent (64-bit)' -ErrorAction SilentlyContinue
if ($install_x64 -ne $null) {
return $install_x64.GetValue('InstallFolder')
}

$install_x86 = Get-Item 'HKLM:\SOFTWARE\Zabbix SIA\Zabbix Agent' -ErrorAction SilentlyContinue
if ($install_x86 -ne $null) {
return $install_x86.GetValue('InstallFolder')
}

return ((Get-ChildItem -Path (Get-ZabbixAgent)).DirectoryName + '/')
}

function Setup-VeeamAgent {
param(
[string]$zabbix_path = (Get-ZabbixPath)
)

$wmi_product = Get-WmiObject -Class Win32_Product -Filter 'Name = "Veeam Backup & Replication Server"'
if ($wmi_product -eq $null) {
Write-Debug 'Veeam server not installed. Skip.'
return
}

$zabbix_config = "
EnableRemoteCommands=1
UnsafeUserParameters=1
Alias=service.discovery.veeam:service.discovery
Timeout=30
UserParameter=vbr[*],powershell -NoProfile -ExecutionPolicy Bypass -File ""${zabbix_path}scripts\zabbix_vbr_job.ps1"" ""`$1"" ""`$2"" ""`$3""
" -replace "`r`n", "`n"

#$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
#[System.IO.File]::WriteAllLines($zabbix_path + 'zabbix_agentd.conf.d\veeam_agent.conf', $zabbix_config, $Utf8NoBomEncoding)
Set-Content -Path ($zabbix_path + 'zabbix_agentd.conf.d\veeam_agent.conf') -Value $zabbix_config -Encoding Ascii

$script_directory = $zabbix_path + 'scripts'
if (-not (Test-Path -Path $script_directory)) {
New-Item -ItemType Directory -Path $script_directory
}

$client = new-object System.Net.WebClient
$download_path = [System.IO.Path]::GetTempFileName()
$client.DownloadFile('https://raw.githubusercontent.com/bontiv/zabbix-VEEAM_B-R/master/zabbix_vbr_job.ps1', $download_path)

$script_content = Get-Content -Path $download_path
Set-Content -Path ($zabbix_path + 'scripts\zabbix_vbr_job.ps1') -Value ($script_content -replace "pathxml = 'C:\\Program Files\\Zabbix Agent\\scripts\\TempXmlVeeam'", "pathxml = '${zabbix_path}scripts\TempXmlVeeam'")
Remove-Item -Path $download_path

Restart-Zabbix
}

function Setup-PowerShell3 {
if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64") {
$arch = "x64"
} else {
$arch = "x86"
}

$win_version = (Get-WmiObject Win32_OperatingSystem).Version -split '\.'
$base_version = $win_version[0] + '.' + $win_version[1]

if ($base_version -eq '6.0') {
$package = 'Windows6.0-KB2506146'
} elseif ($base_version -eq '6.1') {
$package = 'Windows6.1-KB2506143'
}
$url = "https://download.microsoft.com/download/E/7/6/E76850B8-DA6E-4FF5-8CCE-A24FC513FD16/${package}-${arch}.msu"
$msu_file = $msi_file = [System.IO.Path]::GetTempPath() + "${package}-${arch}.msu"

$client = new-object System.Net.WebClient
$client.DownloadFile($url, $msu_file)

Start-Process WUSA -ArgumentList ($msu_file, '/quiet', '/norestart') -Wait
}

# If main script, launch setup
if ($MyInvocation.PSCommandPath -eq $null) {
if ([bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")) {
if ($PSVersionTable.PSCompatibleVersions -notcontains "3.0") {
Setup-PowerShell3
}
Setup-VeeamAgent
} elseif (-not $no_elevate.IsPresent) {
# PowerShell 2.0 do not set $PSCommandPath. So use current file invocation.
if ($PSCommandPath -eq $null) {
$PSCommandPath = $MyInvocation.InvocationName
}
Start-Process Powershell -Verb runAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -no_elevate"
} else {
throw "Cannot elevate setup."
}
}
2 changes: 1 addition & 1 deletion Template EN/TemplateVEEAM-BACKUP-eng.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>service.discovery</key>
<key>service.discovery.veeam</key>
<delay>3600</delay>
<status>0</status>
<allowed_hosts/>
Expand Down
2 changes: 1 addition & 1 deletion Template FR/Zabbix-V4.X-only-TemplateVEEAM-BACKUP-FR.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<discovery_rules>
<discovery_rule>
<name>VEEAM Services</name>
<key>service.discovery</key>
<key>service.discovery.veeam</key>
<delay>1h</delay>
<filter>
<conditions>
Expand Down