forked from VeriTeknik/mssqldbsbckp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmssqldbsbackup_check.ps1
40 lines (35 loc) · 990 Bytes
/
mssqldbsbackup_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
# SHELL ARGUMENTS
Set-Variable OK 0 -option Constant
Set-Variable WARNING 1 -option Constant
Set-Variable CRITICAL 2 -option Constant
Set-Variable UNKNOWN 3 -option Constant
# ASK STATUS
$nagiosFile = "C:\nagios_sql_backup.log"
$backupLog = "C:\backup.log"
$status = Get-Content -Path $nagiosFile
$modified = (Get-Item $nagiosFile).LastWriteTime
$prettyDate = $modified.ToString("yyyy-MM-dd_HH:MM:ss")
# NAGIOS OUTPUT
if ($status -eq "OK" -and (Get-Date).AddDays(-1) -lt $modified)
{
$status_str= 'DB BACKUP OK - LAST BACKUP: ' + $prettyDate
$exit_code = $OK
}
elseif ($status -eq "OK" -and (Get-Date).AddDays(-1) -gt $modified)
{
$status_str= 'DB BACKUP LATE - LAST BACKUP ' + $prettyDate
$exit_code = $WARNING
}
elseif ($status -eq "ERROR")
{
$errorLine = Get-Content $backupLog -Tail 1
$status_str= 'DB BACKUP FAILED - ' + $errorLine
$exit_code = $CRITICAL
}
else
{
$status_str='STATUS UNKNOWN'
$exit_code = $UNKNOWN
}
Write-Host $status_str
exit $exit_code