Skip to content

Commit

Permalink
Merge pull request #14 from aholiveira/main
Browse files Browse the repository at this point in the history
Change SQL queries and fix TotalJob
  • Loading branch information
romainsi authored Jun 29, 2022
2 parents 8e76de2 + 092db4b commit 6adaba7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion EN-Template Veeam Backup And Replication.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ zabbix_export:
template: 'Veeam Backup And Replication'
name: 'Veeam Backup And Replication'
description: |
Version: 2.6
Version: 2.7
Monitor Veeam Backup and Replication job and repository information
It uses SQL queries to the Veeam database to obtain the information
To use the template:
Expand Down
2 changes: 1 addition & 1 deletion FR-Template Veeam Backup And Replication.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<uuid>6f3da5aef0d44e2692bfb3949628da5e</uuid>
<template>Veeam Backup And Replication</template>
<name>Veeam Backup And Replication</name>
<description>Version: 2.6
<description>Version: 2.7
Monitor Veeam Backup and Replication job and repository information
It uses SQL queries to the Veeam database to obtain the information
To use the template:
Expand Down
2 changes: 1 addition & 1 deletion FR-Template Veeam Backup And Replication.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ zabbix_export:
template: 'Veeam Backup And Replication'
name: 'Veeam Backup And Replication'
description: |
Version: 2.6
Version: 2.7
Monitor Veeam Backup and Replication job and repository information
It uses SQL queries to the Veeam database to obtain the information
To use the template:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ NOTE: When importing the new template version on an existing installation please
Ajust Zabbix Agent & Server/Proxy timeout for userparameter, you can use this powershell command to determine the execution time :
```powershell
(Measure-Command -Expression{ powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Program Files\Zabbix Agent 2\scripts\zabbix_vbr_job.ps1" "StartJobs"}).TotalSeconds
(Measure-Command -Expression{ & "C:\Program Files\Zabbix Agent 2\scripts\zabbix_vbr_job.ps1" "StartJobs"}).TotalSeconds
```
41 changes: 25 additions & 16 deletions zabbix_vbr_job.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ JobsInfo - Get job information
TotalJob - The number of Veeam active jobs
.OUTPUTS
None. Information is directly sent to Zabbix agent using zabbix_sender.exe
System.String. Information requested depending on the parameter given
The output is JSON formated for RepoInfo and JobsInfo parameters.
TotalJob outputs a single string with the number of active jobs.
.EXAMPLE
zabbix_vbr_jobs.ps1 RepoInfo
Expand All @@ -54,7 +56,7 @@ Sends total number of active Veeam jobs to Zabbix
Created by : Romainsi https://github.com/romainsi
Contributions: aholiveira https://github.com/aholiveira
xtonousou https://github.com/xtonousou
Version : 2.6
Version : 2.7
.LINK
https://github.com/romainsi/zabbix-VB-R-SQL
Expand Down Expand Up @@ -183,7 +185,7 @@ function Get-SqlCommand {
catch {
$retval = $null
# We output the error message. This gets sent to Zabbix.
Write-Host $_.Exception.Message
Write-Output $_.Exception.Message
}
finally {
# Make sure the connection is closed
Expand Down Expand Up @@ -252,10 +254,8 @@ function Get-JobInfo {
[System.Object]$backupsessions
)

$Object = $null

# Get last job session
$lastsession = $backupsessions | Where-Object { $_.job_name -eq $jobname } | Sort-Object creation_time -Descending | Select-Object -First 1
$lastsession = $backupsessions

# Return $null if there is no session data
if (!$lastsession) {
Expand Down Expand Up @@ -297,20 +297,24 @@ None
Job information in JSON format
#>
function Get-AllJobsInfo() {
# Get backup jobs session information
$BackupSessions = Get-SqlCommand -Command "SELECT * FROM [VeeamBackup].[dbo].[Backup.Model.JobSessions]
INNER JOIN [VeeamBackup].[dbo].[Backup.Model.BackupJobSessions]
ON [VeeamBackup].[dbo].[Backup.Model.JobSessions].[id] = [VeeamBackup].[dbo].[Backup.Model.BackupJobSessions].[id]
WHERE job_type IN $jobTypes
ORDER BY creation_time DESC, job_type, job_name"

# Get all active jobs
$BackupJobs = Get-SqlCommand -Command "SELECT name, options FROM [VeeamBackup].[dbo].[JobsView] WHERE [Schedule_Enabled] = 'true' AND [type] IN $jobTypes ORDER BY [type], [name]"
$BackupJobs = Get-SqlCommand -Command "SELECT id, name, options FROM [BJobs] WHERE [schedule_enabled] = 'true' AND [type] IN $jobTypes ORDER BY [type], [name]"

$return = @()
# Get information for each active job
foreach ($job in $BackupJobs) {
if (([Xml]$job.options).JobOptionsRoot.RunManually -eq "False") {
$job_id = $job.id;

# Get backup jobs session information
$BackupSessions = Get-SqlCommand -Command "SELECT TOP 1
job_id, job_type, job_name, result, is_retry, progress, creation_time, end_time, log_xml, reason
FROM [Backup.Model.JobSessions]
INNER JOIN [Backup.Model.BackupJobSessions]
ON [Backup.Model.JobSessions].[id] = [Backup.Model.BackupJobSessions].[id]
WHERE job_id='$job_id'
ORDER BY creation_time DESC"

$jobinfo = Get-JobInfo -jobname $job.Name -backupsessions $BackupSessions
$return += ($jobinfo)
}
Expand Down Expand Up @@ -372,9 +376,14 @@ switch ([string]$args[0]) {
Get-AllJobsInfo
}
"TotalJob" {
$BackupJobs = Get-SqlCommand -Command "SELECT jobs.name FROM [VeeamBackup].[dbo].[JobsView] jobs WHERE [Schedule_Enabled] = 'true' AND [type] IN $jobTypes"
$BackupJobs = Get-SqlCommand -Command "SELECT COUNT(jobs.name) as JobCount
FROM [VeeamBackup].[dbo].[JobsView] jobs
WHERE [Schedule_Enabled] = 'true' AND [type] IN $jobTypes"
if ($null -ne $BackupJobs) {
Write-Host $BackupJobs.Rows.Count
Write-Output $BackupJobs.JobCount
}
else {
Write-Output "-- ERROR -- : No data available. Check configuration"
}
}
default {
Expand Down

0 comments on commit 6adaba7

Please sign in to comment.