-
Notifications
You must be signed in to change notification settings - Fork 0
/
zbx-symantec-be.ps1
115 lines (98 loc) · 6.22 KB
/
zbx-symantec-be.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
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
function Convert-Encoding
{
[CmdletBinding()]
param
(
[Parameter(ValueFromPipeline = $true)]
$InputObject,
[Parameter(Position = 0)]
[String]
$From,
[Parameter(Position = 1)]
[String]
$To
)
begin
{
if ($From)
{
$EncodingFrom = [System.Text.Encoding]::GetEncoding($From)
}
else
{
$EncodingFrom = $OutputEncoding
}
if ($To)
{
$EncodingTo = [System.Text.Encoding]::GetEncoding($To)
}
else
{
$EncodingTo = $OutputEncoding
}
$Content = @()
}
process
{
$Content += $InputObject
}
end
{
$Content = $Content | Out-String
$Bytes = $EncodingTo.GetBytes($Content)
$Bytes = [System.Text.Encoding]::Convert($EncodingFrom, $EncodingTo, $Bytes)
$Content = $EncodingTo.GetString($Bytes)
return $Content
}
}
Import-Module BEMCLI
$OPERATION = [string]$args[0]
$JOBNAME = [string]$args[1]
Switch($OPERATION) {
"discovery" {
$jobsched = Get-BEJob -Jobtype Backup
$i = 1
write-host "{"
write-host " `"data`":["
write-host
foreach($job in $jobsched){
if($i -lt $jobsched.count){
$line = " { `"{#JOBNAME}`":`"" + $job.Name + "`" }," | Convert-Encoding CP866 UTF-8
}
else {
$line = " { `"{#JOBNAME}`":`"" + $job.Name + "`" }" | Convert-Encoding CP866 UTF-8
}
$i++
write-host $line
}
write-host
write-host " ]"
write-host "}"
write-host
}
"status" {
$status = Get-BEJobHistory -Name "$JOBNAME" -JobType "Backup" | Select -last 1
$state = $status.JobStatus
$state = $state -replace 'Error','0' -replace 'Warning','1' -replace 'SucceededWithExceptions','2' -replace 'Succeeded','2' -replace 'None','2' -replace 'idle','3' -Replace 'Canceled','4' -Replace 'Missed','5' -Replace 'Active','6'
write-host $state
}
"lastendtime" {
$job = Get-BEJobHistory -Name "$JOBNAME" -JobType "Backup"| Select -last 1
$job_Result = $job.EndTime
$date = get-date -date "01/01/1970"
# минус 3часа (10800 секунд) для корректирования временной зоны
$job_Result1 = (New-TimeSpan -Start $date -end $job_Result).TotalSeconds - 10800
Write-host ($job_Result1)
}
"tasktype" {
$job = Get-BEJob -Name "$JOBNAME"
$job_type = $job.TaskType
$job_type = $job_type -replace 'Full','0' -replace 'Differential','1' -replace 'Incremental','2'
Write-host ($job_type)
}
"libraryspace" {
$device = Get-BEStorageDevice | where {$_.StorageType -eq "RoboticLibraryDevice"} | select Name
$media = Get-BEMedia | Where {$_.LocationName -eq $device.Name} | measure AvailableCapacityBytes -Sum
write-host $media.Sum
}
}