-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidp_log_check.ps1
109 lines (100 loc) · 5.3 KB
/
idp_log_check.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
## Configuration variables
$too_old_threshold = (86400 * 3)
$PreVstaFilePath = "C:\Documents and Settings\All Users\Application Data\Intuit\Intuit Data Protect\"
$PostVstaFilePath = "C:\ProgramData\Intuit\Intuit Data Protect\"
## Declaration of variables
[datetime]$origin = '1970-01-01 00:00:00'
[datetime]$last_successful_time = $origin
[datetime]$last_completion_time = $origin
[datetime]$last_failure_time = $origin.AddSeconds(-1)
## Creates an array of "events" from the log file
#Look for EventLog First
Remove-EventLog -Source IntuitDataProtect
try {Get-EventLog -LogName Application -Source IntuitDataProtect}
Catch {
New-EventLog -LogName Application -Source IntuitDataProtect
Write-Output "Log not found, creating Cartwheel log"
Write-EventLog -LogName Application -Source IntuitDataProtect -Message "Initialization Complete" -EventID 1001 -EntryType Information
}
finally {
Write-Output "Moving On"
}
Function Get-IntuitLog {
Param([Parameter(Mandatory=$true)]$logname)
if ($env:ProgramData) {
if (Test-Path ($PostVstaFilePath + $logname + ".0")) {$logfile = $PostVstaFilePath + $logname + ".0"}
elseif (Test-Path ($PostVstaFilePath + $logname)) {$logfile = $PostVstaFilePath + $logname}
else {
$error_msg = "The file " + $logname + " does not exist."
Write-EventLog -LogName Application -Source IntuitDataProtect -Message $error_msg -EventID 3 -EntryType Critical
Write-Host $error_msg
exit 1001
}
}
else {
if (Test-Path ($PreVstaFilePath + $logname + ".0")) {$logfile = $PreVstaFilePath + $logname + ".0"}
elseif (Test-Path ($PreVstaFilePath + $logname)) {$logfile = $PreVstaFilePath + $logname}
else {
$error_msg = "The file " + $logname + " does not exist."
Write-EventLog -LogName Application -Source IntuitDataProtect -Message $error_msg -EventID 3 -EntryType Critical
Write-Host $error_msg
exit 1001
}
}
return $logfile
}
Function Parse-DateTime {
Param([Parameter(Mandatory=$true)]$event)
$event_array = $event.split(" ")
$event_datestring = $event_array[1] + " " + $event_array[2] + ", " + $event_array[4].Replace(":","") + " " + $event_array[3]
$event_date = Get-Date $event_datestring
return $event_date
}
$events = Get-Content (Get-IntuitLog -logname "IBuEng.log")
if ($events -eq $null){Write-EventLog -LogName Application -Source IntuitDataProtect -Message $"Backup has never attempted to start." -EventID 3 -EntryType Critical; exit 1001}
## Validates and parses date/time strings in the format of "%m/%d/%y %I:%M%p".
$last_snapshot = Parse-DateTime -event ($events | ? {$_ -match "Result DoSnapshot: 0"})[-1]
$last_prepareforVSS = Parse-DateTime -event ($events | ? {$_ -match "Result PrepareForShadowCopy: 0"})[-1]
$last_prepareVSS = Parse-DateTime -event ($events | ? {$_ -match "Result PrepareShadowCopy: 0"})[-1]
$last_cleanupsnapshot = Parse-DateTime -event ($events | ? {$_ -match "Result CleanupSnapshot: 0"})[-1]
$last_cleanupVSS = Parse-DateTime -event ($events | ? {$_ -match "Result CleanShadowCopy: 0"})[-1]
$dates = $last_prepareforVSS, $last_cleanupsnapshot, $last_cleanupVSS, $last_prepareVSS, $last_snapshot
$last_successful_time = $dates | Sort-Object | Select-Object -First 1
$last_completion_time = $last_successful_time
## Determines success/failure based on completion, success, and failure times
if ($last_completion_time -eq $origin){
$output_msg = "Backup has never completed."
Write-EventLog -LogName Application -Source IntuitDataProtect -Message $output_msg -EventID 3 -EntryType Critical
Write-Host $output_msg
exit 1001
}
elseif ($last_successful_time -eq $origin){
$output_msg = "Backup has never been successful. Last completion: " + $last_completion_time.ToString("yyyy-MM-dd, HH:mm:ss") + "."
Write-EventLog -LogName Application -Source IntuitDataProtect -Message $output_msg -EventID 3 -EntryType Critical
Write-Host $output_msg
exit 1001
}
elseif (((Get-Date) - $last_completion_time).TotalSeconds -gt $too_old_threshold){
$output_msg = "Last backup is old. Last completion: " + $last_completion_time.ToString("yyyy-MM-dd, HH:mm:ss") + "."
Write-EventLog -LogName Application -Source IntuitDataProtect -Message $output_msg -EventID 2 -EntryType Warning
Write-Host $output_msg
exit 1001
}
elseif (((Get-Date) - $last_successful_time).TotalSeconds -gt $too_old_threshold){
$output_msg = "Last successful backup is old. Last success: " + $last_successful_time.ToString("yyyy-MM-dd, HH:mm:ss") + "."
Write-EventLog -LogName Application -Source IntuitDataProtect -Message $output_msg -EventID 2 -EntryType Warning
Write-Host $output_msg
exit 1001
}
elseif ($last_completion_time -gt $last_successful_time){
$output_msg = "Last backup had errors. Last success: " + $last_successful_time.ToString("yyyy-MM-dd, HH:mm:ss") + "."
Write-EventLog -LogName Application -Source IntuitDataProtect -Message $output_msg -EventID 2 -EntryType Warning
Write-Host $output_msg
exit 0
}
else {
$output_msg = "Last backup was successful. Last success:" + $last_successful_time.ToString("yyyy-MM-dd, HH:mm:ss") + "."
Write-EventLog -LogName Application -Source IntuitDataProtect -Message $output_msg -EventID 1 -EntryType Information
Write-Host $output_msg
exit 0
}