#declare the txt we may seek from
$dir="E:\wget\sureProbe"
$probsumA="probesummary_A.txt"
$probsumB="probesummary_B.txt"
$probsumTR="probesummary_TR.txt"
$return_status=@{ "OK"="0";"WARNING"="1";"CRITICAL"="2";"UNKNOWN"="3" }
#declare the grep function
function grep_failed_sites
{
param([string]$keyword)
$stream = $input | Out-String -Stream
$stream | Select-String $keyword
}
#get the failed_sites and put it into list
$sumA_res=$(cat $dir\$probsumA | grep_failed_sites ".TXT: 0")
$lengthA=$sumA_res.length
$return_value=""
#judge wether there is failed sites in txt
if ( $lengthA -eq 0 )
{
Write-Host "OK--All sites are OK!"
return $return_status["OK"]
}
elseif ( $lengthA -ge 1 )
{
foreach ($i in $sumA_res)
{
#Write-Host $i
$pooltmp=$i.toString().split("\")
$pool=$pooltmp[0].split(" ")[1]
$sitestmp=$i.toString().split("_")
$sitetp=$sitestmp[2].split(":")[0]
$site=$sitetp.split(".")[0].ToLower()
#Write-Host "pool:"$pool" site:"$site
$return_value=$return_value+"< Pool:"+$pool+" Site:"+$site+" >"
}
Write-Host "Critical--$lengthA sites down.<$return_value>"
return $return_status["CRITICAL"]
}
else
{
Write-Host "UNKNOWN--exception unknown"
return $return_status["UNKNOWN"]
}