$Components = @("virtualserver", "services", "servicegroup", "contentswitch") $exclusionpattern = @("dev","qa") -join "|" $netscalerexclusion = @("nsexsrefax6201") -join "|" $failures = $false foreach ($component in $Components){ $Metrics = Invoke-RestMethod "https://graphvip100.com/metrics/find?query=metrics.winops.netscalers.components.nsexsre*.$component.*.2m.status" -ErrorAction Stop $Raw = foreach ($metric in $Metrics) { Invoke-RestMethod "https://graphvip100.com/render?target=$($metric.id)&from=-10min&format=csv" -ErrorAction Stop } $Data = $Raw | ConvertFrom-Csv -Header "Metric","Time","Value" | Where-Object { -not [string]::IsNullOrEmpty($_.Value) } | Group-Object -Property Metric foreach ($group in $Data) { $NetscalerName = $group.Name.Split(".")[4] $Componentname = $group.name.split(".")[5] $Name = $group.Name.Split(".")[6] If (($group.Group[-1].Value -eq "0.0") -and ($group.Group[-2].Value -eq "0.0") -and ($name -notmatch $exclusionpattern) -and ($netscalername -match $netscalerexclusion)) { [PSCustomObject]@{ NetscalerName = $NetscalerName Componentname = $Componentname Name = $Name } $failures = $true } ElseIf (($group.Group[-1].Value -eq "1.0") -and ($group.Group[-2].Value -eq "1.0") -and ($name -notmatch $exclusionpattern) -and ($netscalername -match $netscalerexclusion)) { Write-Verbose "$NetscalerName $Componentname $Name is UP" -Verbose } ElseIf (($group.Group[-1].Value -eq "2.0") -and ($group.Group[-2].Value -eq "2.0") -and ($name -notmatch $exclusionpattern) -and ($netscalername -match $netscalerexclusion)) { Write-Verbose "$NetscalerName $Componentname $Name is OUT OF SERVICE" -Verbose } } } if ($failures){ Throw "Issue with EASREnetsclaer!" }