-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVeeam_BackupAndReplication_RestorePoints_Backup.xml
716 lines (613 loc) · 36.8 KB
/
Veeam_BackupAndReplication_RestorePoints_Backup.xml
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
<?xml version="1.0" encoding="UTF-8" ?>
<feed version="1.0" hasPendingRequests="false" >
<company></company>
<status>200</status>
<errmsg>OK</errmsg>
<interval>0</interval>
<entry type="predatasource">
<version>1565911170</version>
<name>Veeam_BackupAndReplication_RestorePoints_Backup</name>
<displayedas>Veeam_BackupAndReplication_RestorePoints_Backup-</displayedas>
<description>Pulls Backup Job restore points for Veeam Backup and Replication VMs that are included in all Backup Jobs.</description>
<collector>batchscript</collector>
<hasMultiInstances>true</hasMultiInstances>
<schedule>3600</schedule>
<appliesTo>system.displayname == "Veeam Backup - bc-veeam01"</appliesTo>
<wildcardauto>true</wildcardauto>
<wildcardpersist>false</wildcardpersist>
<wildcardlinuxscript>ad_script</wildcardlinuxscript>
<wildcardlinuxcmdline>type="powerShell" </wildcardlinuxcmdline>
<wildcardwinscript>ad_script</wildcardwinscript>
<wildcardwincmdline>type="powerShell" </wildcardwincmdline>
<wildcardgroovyscript><# © 2007-2019 - LogicMonitor, Inc. All rights reserved. #>
$hostname = '##system.hostname##'
# If the hostname is an IP address query DNS for the FQDN
if($hostname -match "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"){
$hostname = [System.Net.Dns]::GetHostbyAddress($hostname).HostName
}
if ([string]::IsNullOrEmpty('##veeam.user##')) { $veeam_user = '##wmi.user##' } else { $veeam_user = '##veeam.user##' }
if ([string]::IsNullOrEmpty('##veeam.pass##')) { $veeam_pass = '##wmi.pass##' } else { $veeam_pass = '##veeam.pass##' }
# Store a date stamp for calculating the age of the restore points
[datetime]$Now = Get-Date
$Now = $Now.ToUniversalTime()
## ******** Beginning of LM Helper Methods *****************************************************************************************
function Make-NotNaN {
param( $Metric )
if ( [string]::IsNullOrEmpty($Metric) -or [string]::IsNullOrWhiteSpace($Metric) ) {
return "0"
} else {
return $Metric
}
}
function Get-LMActiveDiscoveryOutput {
Param (
# Custom Hashtable of Objects representing the Veeam Jobs.
[Parameter(Mandatory = $true)]
$VeeamObjects
)
$lm_output = ""
# Now Print out the AD-Formatted output
ForEach ($VeeamObject in $VeeamObjects) {
$tmp_VmID = $VeeamObject.ObjectID
$tmp_VmName = $VeeamObject.VmName
$tmp_Location = $VeeamObject.Location
$tmp_propprefix = "auto.veeam.backupandreplication"
$lm_output += "$($tmp_VmID)##$($tmp_VmName)##$($tmp_Location)####$($tmp_propprefix).vmobjectid=$($tmp_VmID)&$($tmp_propprefix).virtualmachinename=$($tmp_VmName)&$($tmp_propprefix).vmlocation=$($tmp_Location)`n"
}
return $lm_output
}
$Lookup = @{}
$Lookup.Add('Full',0)
$Lookup.Add('Increment',1)
## ******** Beginning of LM Helper Methods *********************************************************************************************
function Get-VeeamConnection {
Param (
# Hostname of the Veeam Server we are connecting to.
[Parameter(Mandatory = $true)]
[string]
$VeeamHostname,
# Veeam Username
[Parameter(Mandatory = $true)]
[string]
$VeeamUsername,
# Veeam Password
[Parameter(Mandatory = $true)]
[String]
$VeeamPassword
)
$max_attempts = 2
$attempt_sleep = 2
$current_attempt_count = 0
## Build credential object
If (($VeeamUsername -like "*veeam.user*") -or ($VeeamUsername -like "*wmi.user*")) {
# The user has not provided any creds. Let's try with whatever user this thing has.
while (-Not$veeam_session -and ($current_attempt_count -le $max_attempts)) {
$current_attempt_count++
$veeam_session = New-PSSession -ComputerName $VeeamHostname
Start-Sleep -Seconds $attempt_sleep
}
}
else {
$secure_pass = ConvertTo-SecureString -String $VeeamPassword -AsPlainText -Force
$creds = New-Object -typename System.Management.Automation.PSCredential($VeeamUsername, $secure_pass)
## Attempt to acquire a persistent session object. Keep trying until we hit the $max_attempts value.
while (-Not$veeam_session -and ($current_attempt_count -le $max_attempts)) {
$current_attempt_count++
$veeam_session = New-PSSession -ComputerName $VeeamHostname -Credential $creds
Start-Sleep -Seconds $attempt_sleep
}
}
## Ensure that the session was successfully created, otherwise exit.
if ( -Not $veeam_session ) {
Write-Host "Error connecting session. Terminating."
Exit
}
Invoke-Command -Session $veeam_session -ScriptBlock {Add-PSSnapin -Name VeeamPSSnapIn -WarningAction SilentlyContinue -ErrorAction SilentlyContinue}
return $veeam_session
}
function Get-VeeamVirtualMachines {
Param (
[Parameter(Mandatory = $true)]
[System.Management.Automation.Runspaces.PSSession]
$VeeamSession,
[Parameter(Mandatory= $true)]
[string]$JobType
)
$tmp_veeam_objects = @()
<#
## Make the call to the Veeam PS cmdlet to retrieve the backup jobs
$vjs = Invoke-Command -Session $VeeamSession -ScriptBlock {
Add-PSSnapin -Name VeeamPSSnapIn -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
$RemoteJobs = Get-VBRJob -WarningAction SilentlyContinue | Where-Object { $_.JobType -eq "Backup" } | Select-Object -Property *
ForEach ($Job in $RemoteJobs) {Get-VBRJobObject -Job $Job.Name | ? {$_.Type -eq "Include"}}
}#> #Replace this section with a PS Session. Working on code below.
# $RemoteJobs = Get-VBRJob -WarningAction SilentlyContinue | Where-Object { $_.JobType -eq $JobType } | Select-Object -Property *
$RemoteJobs = Invoke-Command -Session $VeeamSession -ScriptBlock {Get-VBRJob -WarningAction SilentlyContinue | Where-Object { $_.JobType -eq $Using:JobType } | Select-Object -Property *}
ForEach ($Job in $RemoteJobs) {
$JobName = $Job.Name
#Collect the Job Objects and build a table of virtual machines
$JobObjects = Invoke-Command -Session $VeeamSession -ScriptBlock {Get-VBRJobObject -Job $Using:JobName | ? {$_.Type -eq "Include"}}
ForEach ($vm in $JobObjects) {
$new_veeam_vm = New-Object -TypeName psobject
$new_veeam_vm | Add-Member NoteProperty -Name ObjectID -Value $vm.ObjectId
$new_veeam_vm | Add-Member NoteProperty -Name VmName -Value $vm.Name
$new_veeam_vm | Add-Member NoteProperty -Name Location -Value $vm.Location
$new_veeam_vm | Add-Member NoteProperty -Name BackupJobId -Value $vm.JobID
$new_veeam_vm | Add-Member NoteProperty -Name BackupJobName -Value $JobName
$new_veeam_vm | Add-Member NoteProperty -Name BackupJobType -Value $JobType
$tmp_veeam_objects += $new_veeam_vm
}
}
return $tmp_veeam_objects
}
## ******** Beginning of the main routine *********************************************************************************************
# Add-PSSnapin -Name VeeamPSSnapIn -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
$veeam_session = Get-VeeamConnection -VeeamHostname $hostname -VeeamUsername $veeam_user -VeeamPassword $veeam_pass
# Get the Veeam Virtual Machines included in Backup Jobs
$veeam_objects = Get-VeeamVirtualMachines -VeeamSession $veeam_session -JobType "Backup"
Get-LMActiveDiscoveryOutput -VeeamObjects $veeam_objects
Exit</wildcardgroovyscript>
<wildcardschedule>1440</wildcardschedule>
<wildcarddisable>false</wildcarddisable>
<wildcarddeleteinactive>false</wildcarddeleteinactive>
<agdmethod>none</agdmethod>
<agdparams></agdparams>
<group></group>
<tags></tags>
<technology></technology>
<adlist><![CDATA[{"agdmethod":"none","method":"ad_script","agdparams":"","id":0,"filters":[],"params":{"type":"powerShell","groovyscript":"<# © 2007-2019 - LogicMonitor, Inc. All rights reserved. #>\n\n$hostname = '##system.hostname##'\n\n# If the hostname is an IP address query DNS for the FQDN\nif($hostname -match \"\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b\"){\n $hostname = [System.Net.Dns]::GetHostbyAddress($hostname).HostName\n}\n\nif ([string]::IsNullOrEmpty('##veeam.user##')) { $veeam_user = '##wmi.user##' } else { $veeam_user = '##veeam.user##' }\nif ([string]::IsNullOrEmpty('##veeam.pass##')) { $veeam_pass = '##wmi.pass##' } else { $veeam_pass = '##veeam.pass##' }\n\n# Store a date stamp for calculating the age of the restore points\n[datetime]$Now = Get-Date\n$Now = $Now.ToUniversalTime()\n\n\n## ******** Beginning of LM Helper Methods *****************************************************************************************\n\nfunction Make-NotNaN {\n param( $Metric )\n\n if ( [string]::IsNullOrEmpty($Metric) -or [string]::IsNullOrWhiteSpace($Metric) ) {\n return \"0\" \n } else {\n return $Metric \n }\n}\n\nfunction Get-LMActiveDiscoveryOutput {\n Param (\n # Custom Hashtable of Objects representing the Veeam Jobs.\n [Parameter(Mandatory = $true)]\n $VeeamObjects\n )\n\n $lm_output = \"\"\n\n # Now Print out the AD-Formatted output\n ForEach ($VeeamObject in $VeeamObjects) {\n $tmp_VmID = $VeeamObject.ObjectID\n $tmp_VmName = $VeeamObject.VmName\n $tmp_Location = $VeeamObject.Location\n $tmp_propprefix = \"auto.veeam.backupandreplication\"\n \n $lm_output += \"$($tmp_VmID)##$($tmp_VmName)##$($tmp_Location)####$($tmp_propprefix).vmobjectid=$($tmp_VmID)&$($tmp_propprefix).virtualmachinename=$($tmp_VmName)&$($tmp_propprefix).vmlocation=$($tmp_Location)`n\"\n\n }\n\nreturn $lm_output\n}\n\n$Lookup = @{}\n$Lookup.Add('Full',0)\n$Lookup.Add('Increment',1)\n\n## ******** Beginning of LM Helper Methods *********************************************************************************************\n\nfunction Get-VeeamConnection {\n Param (\n # Hostname of the Veeam Server we are connecting to.\n [Parameter(Mandatory = $true)]\n [string]\n $VeeamHostname,\n\n # Veeam Username\n [Parameter(Mandatory = $true)]\n [string]\n $VeeamUsername,\n\n # Veeam Password\n [Parameter(Mandatory = $true)]\n [String]\n $VeeamPassword\n )\n\n $max_attempts = 2\n $attempt_sleep = 2\n $current_attempt_count = 0\n\n ## Build credential object\n If (($VeeamUsername -like \"*veeam.user*\") -or ($VeeamUsername -like \"*wmi.user*\")) {\n # The user has not provided any creds. Let's try with whatever user this thing has.\n while (-Not$veeam_session -and ($current_attempt_count -le $max_attempts)) {\n $current_attempt_count++\n $veeam_session = New-PSSession -ComputerName $VeeamHostname\n Start-Sleep -Seconds $attempt_sleep\n }\n }\n\n else {\n $secure_pass = ConvertTo-SecureString -String $VeeamPassword -AsPlainText -Force\n $creds = New-Object -typename System.Management.Automation.PSCredential($VeeamUsername, $secure_pass)\n\n ## Attempt to acquire a persistent session object. Keep trying until we hit the $max_attempts value.\n while (-Not$veeam_session -and ($current_attempt_count -le $max_attempts)) {\n $current_attempt_count++\n $veeam_session = New-PSSession -ComputerName $VeeamHostname -Credential $creds\n Start-Sleep -Seconds $attempt_sleep\n }\n }\n\n ## Ensure that the session was successfully created, otherwise exit.\n if ( -Not $veeam_session ) {\n Write-Host \"Error connecting session. Terminating.\"\n Exit\n }\n Invoke-Command -Session $veeam_session -ScriptBlock {Add-PSSnapin -Name VeeamPSSnapIn -WarningAction SilentlyContinue -ErrorAction SilentlyContinue}\n return $veeam_session\n}\n\nfunction Get-VeeamVirtualMachines {\n \n Param (\n [Parameter(Mandatory = $true)]\n [System.Management.Automation.Runspaces.PSSession]\n $VeeamSession,\n\n [Parameter(Mandatory= $true)]\n [string]$JobType\n \n )\n\n $tmp_veeam_objects = @()\n <#\n ## Make the call to the Veeam PS cmdlet to retrieve the backup jobs\n $vjs = Invoke-Command -Session $VeeamSession -ScriptBlock {\n Add-PSSnapin -Name VeeamPSSnapIn -WarningAction SilentlyContinue -ErrorAction SilentlyContinue\n \n \n $RemoteJobs = Get-VBRJob -WarningAction SilentlyContinue | Where-Object { $_.JobType -eq \"Backup\" } | Select-Object -Property *\n ForEach ($Job in $RemoteJobs) {Get-VBRJobObject -Job $Job.Name | ? {$_.Type -eq \"Include\"}}\n \n }#> #Replace this section with a PS Session. Working on code below.\n\n # $RemoteJobs = Get-VBRJob -WarningAction SilentlyContinue | Where-Object { $_.JobType -eq $JobType } | Select-Object -Property *\n $RemoteJobs = Invoke-Command -Session $VeeamSession -ScriptBlock {Get-VBRJob -WarningAction SilentlyContinue | Where-Object { $_.JobType -eq $Using:JobType } | Select-Object -Property *}\n \n ForEach ($Job in $RemoteJobs) {\n $JobName = $Job.Name\n #Collect the Job Objects and build a table of virtual machines\n $JobObjects = Invoke-Command -Session $VeeamSession -ScriptBlock {Get-VBRJobObject -Job $Using:JobName | ? {$_.Type -eq \"Include\"}}\n ForEach ($vm in $JobObjects) {\n $new_veeam_vm = New-Object -TypeName psobject\n $new_veeam_vm | Add-Member NoteProperty -Name ObjectID -Value $vm.ObjectId\n $new_veeam_vm | Add-Member NoteProperty -Name VmName -Value $vm.Name\n $new_veeam_vm | Add-Member NoteProperty -Name Location -Value $vm.Location\n $new_veeam_vm | Add-Member NoteProperty -Name BackupJobId -Value $vm.JobID\n $new_veeam_vm | Add-Member NoteProperty -Name BackupJobName -Value $JobName\n $new_veeam_vm | Add-Member NoteProperty -Name BackupJobType -Value $JobType\n $tmp_veeam_objects += $new_veeam_vm\n }\n \n }\n return $tmp_veeam_objects\n}\n\n\n\n## ******** Beginning of the main routine *********************************************************************************************\n# Add-PSSnapin -Name VeeamPSSnapIn -WarningAction SilentlyContinue -ErrorAction SilentlyContinue\n$veeam_session = Get-VeeamConnection -VeeamHostname $hostname -VeeamUsername $veeam_user -VeeamPassword $veeam_pass\n\n# Get the Veeam Virtual Machines included in Backup Jobs\n$veeam_objects = Get-VeeamVirtualMachines -VeeamSession $veeam_session -JobType \"Backup\"\n\nGet-LMActiveDiscoveryOutput -VeeamObjects $veeam_objects\n\nExit"}}]]></adlist>
<schemaVersion>2</schemaVersion>
<dataSourceType>1</dataSourceType>
<attributes>
<attribute>
<name>scripttype</name>
<value>powerShell</value>
<comment></comment>
</attribute>
<attribute>
<name>scriptgroovy</name>
<value><# © 2007-2019 - LogicMonitor, Inc. All rights reserved. #>
$hostname = '##system.hostname##'
# If the hostname is an IP address query DNS for the FQDN
if($hostname -match "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"){
$hostname = [System.Net.Dns]::GetHostbyAddress($hostname).HostName
}
if ([string]::IsNullOrEmpty('##veeam.user##')) { $veeam_user = '##wmi.user##' } else { $veeam_user = '##veeam.user##' }
if ([string]::IsNullOrEmpty('##veeam.pass##')) { $veeam_pass = '##wmi.pass##' } else { $veeam_pass = '##veeam.pass##' }
# Store a date stamp for calculating the age of the restore points
[datetime]$Now = Get-Date
$Now = $Now.ToUniversalTime()
## ******** Beginning of LM Helper Methods *****************************************************************************************
function Make-NotNaN {
param( $Metric )
if ( [string]::IsNullOrEmpty($Metric) -or [string]::IsNullOrWhiteSpace($Metric) ) {
return "0"
} else {
return $Metric
}
}
function Get-LMActiveDiscoveryOutput {
Param (
# Custom Hashtable of Objects representing the Veeam Jobs.
[Parameter(Mandatory = $true)]
$VeeamObjects
)
$lm_output = ""
# Now Print out the AD-Formatted output
ForEach ($VeeamObject in $VeeamObjects) {
$tmp_VmID = $VeeamObject.ObjectID
$tmp_VmName = $VeeamObject.VmName
$tmp_Location = $VeeamObject.Location
$tmp_propprefix = "auto.veeam.backupandreplication"
$lm_output += "$($tmp_VmID)##$($tmp_VmName)##$($tmp_Location)####$($tmp_propprefix).vmobjectid=$($tmp_VmID)&$($tmp_propprefix).virtualmachinename=$($tmp_VmName)&$($tmp_propprefix).vmlocation=$($tmp_Location)`n"
}
return $lm_output
}
$Lookup = @{}
$Lookup.Add('Full',0)
$Lookup.Add('Increment',1)
## ******** Beginning of LM Helper Methods *********************************************************************************************
function Get-VeeamConnection {
Param (
# Hostname of the Veeam Server we are connecting to.
[Parameter(Mandatory = $true)]
[string]
$VeeamHostname,
# Veeam Username
[Parameter(Mandatory = $true)]
[string]
$VeeamUsername,
# Veeam Password
[Parameter(Mandatory = $true)]
[String]
$VeeamPassword
)
$max_attempts = 2
$attempt_sleep = 2
$current_attempt_count = 0
## Build credential object
If (($VeeamUsername -like "*veeam.user*") -or ($VeeamUsername -like "*wmi.user*")) {
# The user has not provided any creds. Let's try with whatever user this thing has.
while (-Not$veeam_session -and ($current_attempt_count -le $max_attempts)) {
$current_attempt_count++
$veeam_session = New-PSSession -ComputerName $VeeamHostname
Start-Sleep -Seconds $attempt_sleep
}
}
else {
$secure_pass = ConvertTo-SecureString -String $VeeamPassword -AsPlainText -Force
$creds = New-Object -typename System.Management.Automation.PSCredential($VeeamUsername, $secure_pass)
## Attempt to acquire a persistent session object. Keep trying until we hit the $max_attempts value.
while (-Not$veeam_session -and ($current_attempt_count -le $max_attempts)) {
$current_attempt_count++
$veeam_session = New-PSSession -ComputerName $VeeamHostname -Credential $creds
Start-Sleep -Seconds $attempt_sleep
}
}
## Ensure that the session was successfully created, otherwise exit.
if ( -Not $veeam_session ) {
Write-Host "Error connecting session. Terminating."
Exit
}
# Load the Veeam PSSnapIn in the remote session
Invoke-Command -Session $veeam_session -ScriptBlock {Add-PSSnapin -Name VeeamPSSnapIn -WarningAction SilentlyContinue -ErrorAction SilentlyContinue}
return $veeam_session
}
function Get-VeeamVirtualMachines {
Param (
[Parameter(Mandatory = $true)]
[System.Management.Automation.Runspaces.PSSession]
$VeeamSession,
[Parameter(Mandatory= $true)]
[string]$JobType
)
$tmp_veeam_objects = @()
<#
## Make the call to the Veeam PS cmdlet to retrieve the backup jobs
$vjs = Invoke-Command -Session $VeeamSession -ScriptBlock {
Add-PSSnapin -Name VeeamPSSnapIn -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
$RemoteJobs = Get-VBRJob -WarningAction SilentlyContinue | Where-Object { $_.JobType -eq "Backup" } | Select-Object -Property *
ForEach ($Job in $RemoteJobs) {Get-VBRJobObject -Job $Job.Name | ? {$_.Type -eq "Include"}}
}#> #Replace this section with a PS Session. Working on code below.
# $RemoteJobs = Get-VBRJob -WarningAction SilentlyContinue | Where-Object { $_.JobType -eq $JobType } | Select-Object -Property *
$RemoteJobs = Invoke-Command -Session $VeeamSession -ScriptBlock {Get-VBRJob -WarningAction SilentlyContinue | Where-Object { $_.JobType -eq $Using:JobType } | Select-Object -Property *}
ForEach ($Job in $RemoteJobs) {
$JobName = $Job.Name
#Collect the Job Objects and build a table of virtual machines
$JobObjects = Invoke-Command -Session $VeeamSession -ScriptBlock {Get-VBRJobObject -Job $Using:JobName | ? {$_.Type -eq "Include"}}
ForEach ($vm in $JobObjects) {
$new_veeam_vm = New-Object -TypeName psobject
$new_veeam_vm | Add-Member NoteProperty -Name ObjectID -Value $vm.ObjectId
$new_veeam_vm | Add-Member NoteProperty -Name VmName -Value $vm.Name
$new_veeam_vm | Add-Member NoteProperty -Name Location -Value $vm.Location
$new_veeam_vm | Add-Member NoteProperty -Name BackupJobId -Value $vm.JobID
$new_veeam_vm | Add-Member NoteProperty -Name BackupJobName -Value $JobName
$new_veeam_vm | Add-Member NoteProperty -Name BackupJobType -Value $JobType
$tmp_veeam_objects += $new_veeam_vm
}
}
return $tmp_veeam_objects
}
Function Get-VeeamRestorePoints {
Param (
[Parameter(Mandatory = $true)]
[System.Management.Automation.Runspaces.PSSession]
$VeeamSession,
# GUID of the Veeam Virtual Machine.
[Parameter(Mandatory = $true)]
[string]$VmId,
[Parameter(Mandatory = $true)]
[string]$JobName
)
# Retrieve the restore points by VMiD and JobName
# $RestorePoints = Get-VBRRestorePoint -ObjectId $VmId -Backup $JobName | Select-Object *
$RestorePoints = Invoke-Command -Session $VeeamSession -ScriptBlock {Get-VBRRestorePoint -ObjectId $Using:VmId -Backup $Using:JobName | Select-Object *}
# Get a count of restore points.
[int]$RestorePointCount = $RestorePoints.count
# If there is more than 1 RP, find the latest restore point, the fulls, and the increments
if ($RestorePointCount -gt 1) {
# Find the latest consistent Full or Simple restore point and report its size in bytes, type 1=Full 2=Increment 3=Debug, and age in seconds
$LatestRp = $RestorePoints | ? {$_.IsConsistent -eq "True"} | Sort-Object CreationTimeUtc | Select-Object -Last 1
[datetime]$LatestCreationTimeUtc = $LatestRp.CreationTimeUtc
[int64]$LatestAgeSec = (New-Timespan -Start $LatestCreationTimeUtc -End $Now).TotalSeconds
[string]$LatestType = $LatestRp.Type
[string]$TypeReturn = $Lookup.$($LatestType)
[string]$LatestSize = $LatestRp.ApproxSize
# Find the Full restore points and count them. Excluded "inconsistent/incomplete" fulls
$Fulls = $RestorePoints | ? {$_.Type.Value -eq "Full"} | ? {$_.IsConsistent -eq "True"}
$FullCount = $Fulls.Count
# Find the backup increments and cound them. Exclude "inconsistent/incomplete" increments
$Increments = $RestorePoints | ? {$_.Type.Value -eq "Increment"} | ? {$_.IsConsistent -eq "True"}
$IncrementCount = $Increments.Count
# Sort the fulls so we can pull the newest and oldest
$Fulls = $Fulls | Sort-Object CreationTimeUtc
$OldestFull = $Fulls | Select-Object -First 1
$NewestFull = $Fulls | Select-Object -Last 1
# Find the creationdata of the oldest full and return in in epoch time
[datetime]$OldFullCreationUtc = $OldestFull.CreationTimeUtc
[int64]$OldFullAgeSec = (New-Timespan -Start $OldFullCreationUtc -End $Now).TotalSeconds
# Find the creationdate of the newest full and return it in Unix Epoch time
[datetime]$NewFullCreationUtc = $NewestFull.CreationTimeUtc
[int64]$NewFullAgeSec = (New-Timespan -Start $NewFullCreationUtc -End $Now).TotalSeconds
# Sort the incremenets so we can pull the newest and oldest
$Increments = $Increments | Sort-Object CreationTimeUtc
$OldestIncrement = $Increments | Select-Object -First 1
$NewestIncrement = $Increments | Select-Object -Last 1
#Find the creationdate of the oldest increment and return in epoch time
[datetime]$OldIncrementCreationUtc = $OldestIncrement.CreationTimeUtc
[int64]$OldIncAgeSec = (New-Timespan -Start $OldIncrementCreationUtc -End $Now).TotalSeconds
# Find the creationdate of the newest increment and return in epoch time
[datetime]$NewIncrementCreationUtc = $NewestIncrement.CreationTimeUtc
[int64]$NewIncAgeSec = (New-Timespan -Start $NewIncrementCreationUtc -End $Now).TotalSeconds
# Write out the data to return to Logicmonitor
# Write-Host "$( $wildvalue ).Status=$( Sanitize-Output $task.Status )"
Write-Host "$( $VmId ).LatestType=$( Sanitize-Output $TypeReturn )"
Write-Host "$( $VmId ).LatestSize=$( Sanitize-Output $LatestSize )"
Write-Host "$( $VmId ).LatestAge=$( Sanitize-Output $LatestAgeSec )"
Write-Host "$( $VmId ).FullCount=$( Sanitize-Output $FullCount )"
Write-Host "$( $VmId ).IncCount=$( Sanitize-Output $IncrementCount )"
Write-Host "$( $VmId ).OldestFull=$( Sanitize-Output $OldFullAgeSec )"
Write-Host "$( $VmId ).NewestFull=$( Sanitize-Output $NewFullAgeSec )"
Write-Host "$( $VmId ).OldestIncrement=$( Sanitize-Output $OldIncAgeSec )"
Write-Host "$( $VmId ).NewestIncrement=$( Sanitize-Output $NewIncAgeSec )"
}
# Else, pull stats for the single restore point
else {
$LatestRp = $RestorePoints
[datetime]$LatestCreationTimeUtc = $LatestRp.CreationTimeUtc
[int64]$LatestAgeSec = (New-Timespan -Start $LatestCreationTimeUtc -End $Now).TotalSeconds
[string]$LatestType = $LatestRp.Type
[string]$TypeReturn = $Lookup.$($LatestType)
[string]$LatestSize = $LatestRp.ApproxSize
Write-Host "$( $VmId ).LatestType=$( Sanitize-Output $TypeReturn )"
Write-Host "$( $VmId ).LatestSize=$( Sanitize-Output $LatestSize )"
Write-Host "$( $VmId ).LatestAge=$( Sanitize-Output $LatestAgeSec )"
Write-Host "$( $VmId ).FullCount=$( Sanitize-Output "1" )"
Write-Host "$( $VmId ).IncCount=$( Sanitize-Output "0" )"
Write-Host "$( $VmId ).OldestFull=$( Sanitize-Output $LatestAgeSec )"
Write-Host "$( $VmId ).NewestFull=$( Sanitize-Output $LatestAgeSec )"
Write-Host "$( $VmId ).OldestIncrement=$( Sanitize-Output "0" )"
Write-Host "$( $VmId ).NewestIncrement=$( Sanitize-Output "0" )"
}
}
## ******** Beginning of the main routine *********************************************************************************************
# Add-PSSnapin -Name VeeamPSSnapIn -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
$veeam_session = Get-VeeamConnection -VeeamHostname $hostname -VeeamUsername $veeam_user -VeeamPassword $veeam_pass
# Get the Veeam Virtual Machines included in Backup Jobs
$veeam_objects = Get-VeeamVirtualMachines -VeeamSession $veeam_session -JobType "Backup"
Foreach ($vm in $veeam_objects) {
# Write-Warning "Starting VM $($vm.VmName)"
Get-VeeamRestorePoints -VeeamSession $veeam_session -VmId $vm.ObjectID -JobName $vm.BackupJobName
}
Exit</value>
<comment></comment>
</attribute>
<attribute>
<name>windowsscript</name>
<value></value>
<comment></comment>
</attribute>
<attribute>
<name>linuxscript</name>
<value></value>
<comment></comment>
</attribute>
<attribute>
<name>windowscmdline</name>
<value></value>
<comment></comment>
</attribute>
<attribute>
<name>linuxcmdline</name>
<value></value>
<comment></comment>
</attribute>
</attributes>
<datapoints>
<datapoint>
<name>FullCount</name>
<dataType>7</dataType>
<type>2</type>
<postprocessormethod>namevalue</postprocessormethod>
<postprocessorparam>FullCount</postprocessorparam>
<usevalue>output</usevalue>
<alertexpr></alertexpr>
<alertmissing>1</alertmissing>
<alertsubject></alertsubject>
<alertbody></alertbody>
<description>A count of full restore points</description>
<maxvalue></maxvalue>
<minvalue></minvalue>
<userparam1></userparam1>
<userparam2></userparam2>
<userparam3></userparam3>
<iscomposite>false</iscomposite>
<rpn></rpn>
<alertTransitionIval>0</alertTransitionIval>
<alertClearTransitionIval>0</alertClearTransitionIval>
</datapoint>
<datapoint>
<name>IncrementCount</name>
<dataType>7</dataType>
<type>2</type>
<postprocessormethod>namevalue</postprocessormethod>
<postprocessorparam>IncCount</postprocessorparam>
<usevalue>output</usevalue>
<alertexpr></alertexpr>
<alertmissing>1</alertmissing>
<alertsubject></alertsubject>
<alertbody></alertbody>
<description>A count of the incremental restore points (simple restore points)</description>
<maxvalue></maxvalue>
<minvalue></minvalue>
<userparam1></userparam1>
<userparam2></userparam2>
<userparam3></userparam3>
<iscomposite>false</iscomposite>
<rpn></rpn>
<alertTransitionIval>0</alertTransitionIval>
<alertClearTransitionIval>0</alertClearTransitionIval>
</datapoint>
<datapoint>
<name>LatestAgeSec</name>
<dataType>7</dataType>
<type>2</type>
<postprocessormethod>namevalue</postprocessormethod>
<postprocessorparam>LatestAge</postprocessorparam>
<usevalue>output</usevalue>
<alertexpr></alertexpr>
<alertmissing>1</alertmissing>
<alertsubject></alertsubject>
<alertbody></alertbody>
<description>The age of the latest restore point of either type expressed in seconds</description>
<maxvalue></maxvalue>
<minvalue></minvalue>
<userparam1></userparam1>
<userparam2></userparam2>
<userparam3></userparam3>
<iscomposite>false</iscomposite>
<rpn></rpn>
<alertTransitionIval>0</alertTransitionIval>
<alertClearTransitionIval>0</alertClearTransitionIval>
</datapoint>
<datapoint>
<name>LatestSizeBytes</name>
<dataType>7</dataType>
<type>2</type>
<postprocessormethod>namevalue</postprocessormethod>
<postprocessorparam>LatestSize</postprocessorparam>
<usevalue>output</usevalue>
<alertexpr></alertexpr>
<alertmissing>1</alertmissing>
<alertsubject></alertsubject>
<alertbody></alertbody>
<description>The approximate size of the most recent restore point in bytes.</description>
<maxvalue></maxvalue>
<minvalue></minvalue>
<userparam1></userparam1>
<userparam2></userparam2>
<userparam3></userparam3>
<iscomposite>false</iscomposite>
<rpn></rpn>
<alertTransitionIval>0</alertTransitionIval>
<alertClearTransitionIval>0</alertClearTransitionIval>
</datapoint>
<datapoint>
<name>LatestType</name>
<dataType>7</dataType>
<type>2</type>
<postprocessormethod>namevalue</postprocessormethod>
<postprocessorparam>LatestType</postprocessorparam>
<usevalue>output</usevalue>
<alertexpr></alertexpr>
<alertmissing>1</alertmissing>
<alertsubject></alertsubject>
<alertbody></alertbody>
<description>The type of the most recent restore point. 0 = Full; 1 = Increment</description>
<maxvalue>1</maxvalue>
<minvalue>0</minvalue>
<userparam1></userparam1>
<userparam2></userparam2>
<userparam3></userparam3>
<iscomposite>false</iscomposite>
<rpn></rpn>
<alertTransitionIval>0</alertTransitionIval>
<alertClearTransitionIval>0</alertClearTransitionIval>
</datapoint>
<datapoint>
<name>NewestFullSeconds</name>
<dataType>7</dataType>
<type>2</type>
<postprocessormethod>namevalue</postprocessormethod>
<postprocessorparam>NewestFull</postprocessorparam>
<usevalue>output</usevalue>
<alertexpr></alertexpr>
<alertmissing>1</alertmissing>
<alertsubject></alertsubject>
<alertbody></alertbody>
<description>The age of the newest Full restore point expressed in seconds</description>
<maxvalue></maxvalue>
<minvalue></minvalue>
<userparam1></userparam1>
<userparam2></userparam2>
<userparam3></userparam3>
<iscomposite>false</iscomposite>
<rpn></rpn>
<alertTransitionIval>0</alertTransitionIval>
<alertClearTransitionIval>0</alertClearTransitionIval>
</datapoint>
<datapoint>
<name>NewestIncrementSec</name>
<dataType>7</dataType>
<type>2</type>
<postprocessormethod>namevalue</postprocessormethod>
<postprocessorparam>NewestIncrement</postprocessorparam>
<usevalue>output</usevalue>
<alertexpr></alertexpr>
<alertmissing>1</alertmissing>
<alertsubject></alertsubject>
<alertbody></alertbody>
<description>The age of the newest incremental (simple) restore point expressed in seconds</description>
<maxvalue></maxvalue>
<minvalue></minvalue>
<userparam1></userparam1>
<userparam2></userparam2>
<userparam3></userparam3>
<iscomposite>false</iscomposite>
<rpn></rpn>
<alertTransitionIval>0</alertTransitionIval>
<alertClearTransitionIval>0</alertClearTransitionIval>
</datapoint>
<datapoint>
<name>OldestFullSeconds</name>
<dataType>7</dataType>
<type>2</type>
<postprocessormethod>namevalue</postprocessormethod>
<postprocessorparam>OldestFull</postprocessorparam>
<usevalue>output</usevalue>
<alertexpr></alertexpr>
<alertmissing>1</alertmissing>
<alertsubject></alertsubject>
<alertbody></alertbody>
<description>The age of the oldest Full restore point expressed in seconds</description>
<maxvalue></maxvalue>
<minvalue></minvalue>
<userparam1></userparam1>
<userparam2></userparam2>
<userparam3></userparam3>
<iscomposite>false</iscomposite>
<rpn></rpn>
<alertTransitionIval>0</alertTransitionIval>
<alertClearTransitionIval>0</alertClearTransitionIval>
</datapoint>
<datapoint>
<name>OldestIncrementSeconds</name>
<dataType>7</dataType>
<type>2</type>
<postprocessormethod>namevalue</postprocessormethod>
<postprocessorparam>OldestIncrement</postprocessorparam>
<usevalue>output</usevalue>
<alertexpr></alertexpr>
<alertmissing>1</alertmissing>
<alertsubject></alertsubject>
<alertbody></alertbody>
<description>The age of the oldest incremental (simple) restore point expressed in seconds</description>
<maxvalue></maxvalue>
<minvalue></minvalue>
<userparam1></userparam1>
<userparam2></userparam2>
<userparam3></userparam3>
<iscomposite>false</iscomposite>
<rpn></rpn>
<alertTransitionIval>0</alertTransitionIval>
<alertClearTransitionIval>0</alertClearTransitionIval>
</datapoint>
</datapoints>
<graphs>
</graphs>
<overviewgraphs>
</overviewgraphs>
<scripts>
</scripts>
</entry>
</feed>