forked from jorgedlcruz/veeam-enterprise_manager-grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
veeam-stats_EM.ps1
86 lines (70 loc) · 3.2 KB
/
veeam-stats_EM.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<#
.SYNOPSIS
Grafana, Telegrad and InfluxhDB Veeam Monitor
.DESCRIPTION
This Script will Report Statistics about Backups, Repositories usage and much more during the time interval selected on the configuration . It will then convert them into JSON, ready to add into InfluxDB and show it with Grafana in an easier way
.Notes
NAME: veeam-stats_EM.ps1
ORIGINAL NAME: PRTG-Veeam-SessionStats.ps1
LASTEDIT: 26/07/2017
VERSION: 0.1
KEYWORDS: Veeam, Grafana, InfluxDB, Telegraf
.Link
http://mycloudrevolution.com/
Edist, JSON output for Grafana, and Repository section by https://jorgedelacruz.es/
#Requires Veeam Enterprise Manager, and access to the RESTfulAPI
#>
$user = "YOURUSER"
$password = "YOURPASS"
$BRHost = "YOURVEEAMENTERPRISEMANAGER"
# POST - Authorization
$Auth = @{uri = "http://" + $BRHost + ":9399/api/sessionMngr/?v=v1_2";
Method = 'POST'; #(or POST, or whatever)
Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($user):$($password)"));
} #end headers hash table
} #end $params hash table
$AuthXML = Invoke-WebRequest @Auth
#region: GET - Session Statistics
$Sessions = @{uri = "http://" + $BRHost + ":9399/api/reports/summary/job_statistics";
Method = 'GET';
Headers = @{'X-RestSvcSessionId' = $AuthXML.Headers['X-RestSvcSessionId'];
} #end headers hash table
}
[xml]$SessionsXML = invoke-restmethod @Sessions
$SuccessfulJobRuns = $SessionsXML.JobStatisticsReportFrame.SuccessfulJobRuns
$WarningsJobRuns = $SessionsXML.JobStatisticsReportFrame.WarningsJobRuns
$FailedJobRuns = $SessionsXML.JobStatisticsReportFrame.FailedJobRuns
$RunningJobs = $SessionsXML.JobStatisticsReportFrame.RunningJobs
#region: GET - VM Statistics
$VMs = @{uri = "http://" + $BRHost + ":9399/api/reports/summary/vms_overview";
Method = 'GET';
Headers = @{'X-RestSvcSessionId' = $AuthXML.Headers['X-RestSvcSessionId'];
} #end headers hash table
}
[xml]$VMsXML = invoke-restmethod @VMs
$ProtectedVms = $VMsXML.VmsOverviewReportFrame.ProtectedVms
$SourceVmsSize = [Math]::round((($VMsXML.VmsOverviewReportFrame.SourceVmsSize) / 1073741824),0)
#region: GET - Repository
$Repository = @{uri = "http://" + $BRHost + ":9399/api/reports/summary/repository";
Method = 'GET';
Headers = @{'X-RestSvcSessionId' = $AuthXML.Headers['X-RestSvcSessionId'];
} #end headers hash table
}
[xml]$RepositoryXML = invoke-restmethod @Repository
$Repos = $RepositoryXML.RepositoryReportFrame.Period
# JSON Output for Telegraf
Write-Host "{"
Write-Host "`"SuccessfulJobRuns`"": "$SuccessfulJobRuns,"
Write-Host "`"ProtectedVms`"": "$ProtectedVms,"
Write-Host "`"SourceVmsSize`"": "$SourceVmsSize,"
Write-Host "`"WarningsJobRuns`"": "$WarningsJobRuns,"
Write-Host "`"FailedJobRuns`"": "$FailedJobRuns,"
foreach ($Repo in $Repos){
$Name = "REPO - " + $Repo."Name"
$FreeP = ($Repo."FreeSpace"/$Repo."Capacity").tostring("P")
$Free = $FreeP -replace '[%]',''
Write-Host "`"$Name`"": "$Free,"
}
Write-Host "`"RunningJobs`"": "$RunningJobs"
Write-Host "}"
#endregion