So i Decided to do a complete overhaul of the script and the functionality is OK.
But i have 1 question with baffles me at this time because i can not seem to understand the way PRTG handels EXIT 1 and error values.
Situation. Lets say the backup has a warning ( Event log ID: 5001) -> Exit 1 -> But The sensor in PRTG says Down. Is theire a way that i can tell PRTG when it exits with 1 it only displays a warning and not the value "Down" ?
# Altaro Backup Monitoring
#-------------------
# ------------------
param(
[string]$ComputerName
)
$ret = Invoke-Command -ComputerName S-TEC-MGMT -ScriptBlock {
$Yesterday = ((Get-Date) - (New-TimeSpan -Day 1))
try {
$Geteventlog_Success = (Get-WinEvent -ErrorAction Stop -FilterHashtable @{LogName='Application';StartTime=$Yesterday;Id=5000,5001,5005,5007,5002})
}
catch {
$_.Exception.GetType().FullName
$Geteventlog_Success = 0
}
$array_Successfull = @()
$array_Failed = @()
$array_FailedOffsite = @()
$array_Warning = @()
$array_SuccessfullOffsite = @()
for($i = 0 ; $i -le $Geteventlog_Success.Length; $i++){
$Id = $Geteventlog_Success[$i].Id
Switch ($Id) {
5007 {
$array_FailedOffsite += $Geteventlog_Success[$i]
}
5002 {
$array_Failed += $Geteventlog_Success[$i]
}
5001 {
$array_Warning += $Geteventlog_Success[$i]
}
5005 {
$array_SuccessfullOffsite += $Geteventlog_Success[$i]
}
5000 {
$array_Successfull += $Geteventlog_Success[$i]
}
0 {
write-host "<prtg>"
write-host "<error>1</error>"
write-host "<text>No Backups for the last 24 hours</text>"
write-host "</prtg>"
Exit 2
}
}
}
if($array_FailedOffsite -ne " "){
for ($j = 0; $j -le $array_FailedOffsite.Length; $j++){
$Id2 = $array_FailedOffsite[$j].Id
$Message = $array_FailedOffsite[$j].Message
if ($Id2 = 5007) {
write-host "<prtg>"
write-host "<error>1</error>"
write-host "<text>$Message</text>"
write-host "</prtg>"
Exit 2
}
}
}
if($array_Failed -ne " "){
for ($k = 0; $k -le $array_Failed.Length; $k++){
$Id3 = $array_Failed[$k].Id
$Message = $array_Failed[$k].Message
if ($Id3 = 5002) {
write-host "<prtg>"
write-host "<error>1</error>"
write-host "<text>$Message</text>"
write-host "</prtg>"
Exit 2
}
}
}
if($array_Warning -ne " "){
for ($l = 0; $l -le $array_Warning.Length; $l++){
$Id4 = $array_Warning[$l].Id
$Message = $array_Warning[$l].Message
if ($Id4 = 5001) {
write-host "<prtg>"
write-host "<error>1</error>"
write-host "<text>$Message</text>"
write-host "</prtg>"
Exit 1
}
}
}
if($array_Successfull -ne " "){
for ($m = 0; $m -le $array_SuccessfullOffsite.Length; $m++){
$Id5 = $array_SuccessfullOffsite[$m].Id
$Message = $array_SuccessfullOffsite[$m].Message
if ($Id5 = 5005) {
write-host "<prtg>"
write-host "<error>1</error>"
write-host "<text>$Message</text>"
write-host "</prtg>"
Exit 0
}
}
}
if($array_Successfull -ne " " ) {
for ($n = 0; $n -le $array_Successfull.Length; $n++){
$Id6 = $array_Successfull[$n].Id
$Message = $array_Successfull[$n].Message
if ($Id6 = 5000) {
write-host "<prtg>"
write-host "<error>0</error>"
write-host "<text>$Message</text>"
write-host "</prtg>"
Exit 0
}
}
}
}
Add comment