Link to part 1
Link to part 2

Following on from Part 2 – How do I Identify the Actual Symptoms?

Armed with this information you can now focus on pulling out the actual Alarm data into a CSV file, start by focusing on the areas of high volume and then work your way down.

To do that we can use this script:

#####################################
# ScriptName:    vROPs-ExtractSymptomData
# Script Author: James Gill
# Last Updated:  28/05/17
# Version:       1
#####################################


$cred = Get-Credential

#Variables
$Report = "c:\temp\RPInfAlarms.csv"

# You can specify multiple vrops instances if you wish
$vRopsAddress = ('Enter vROPs server node here')

$CriticalityType = 'INFORMATION'
$ResourceType = 'VirtualMachine'



#vRops SSL certificate trust
add-type @"
     using System.Net;
     using System.Security.Cryptography.X509Certificates;
     public class TrustAllCertsPolicy : ICertificatePolicy {
         public bool CheckValidationResult(
             ServicePoint srvPoint, X509Certificate certificate,
             WebRequest request, int certificateProblem) {
             return true;
         }
     }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy


# Define required headers to supply to the Web request
$headers = @{
    		"Accept" = "application/xml"
            "Content-Type" = "application/json"
	        }
	
# Create the hash table that will be later converted to JSON
$JSONfile = @{
                  compositeOperator = 'AND';
                  resourcequery = @{
                    resourceKind = @("$ResourceType")
                  }
                  alarmCriticality =  @("$CriticalityType");
                  activeOnly = 'false'
                }

$BODY = ConvertTo-Json $JSONFile
$AlarmList = @()

ForEach ($vRops in $vRopsAddress){

    Echo "Collecting Alarm and Notification configuration from $vRops"  

   
    $AList = Invoke-RestMethod -Method post -Uri "https://$vRops/suite-api/api/symptoms/query" -Headers $headers -body $Body -Credential $cred
    $RList = Invoke-RestMethod -Method Get -Uri "https://$vRops/suite-api/api/resources/?pageSize=1" -Credential $cred

    [int]$Alarmcount = $AList.symptoms.pageInfo.totalCount
    
    write-output "Alarm count: $AlarmCount"
  
    If ($Alarmcount -lt 5001){   
        $AListCount = 1 }

    Else { 
        [int]$AListCount = [math]::Round($AlarmCount/5000)  
    }
    Write-Output "Alarm page count: $AListCount"


    [int]$ResourceCount = $RList.resources.pageInfo.totalCount
    write-output "Resource count: $ResourceCount"
    If ($ResourceCount -lt 5001){
 
        $RListCount = 1 }

    Else { 
        
        [int]$RListCount = [math]::Round($ResourceCount/5000) 
    
    }
    Write-Output "Resource page count: $RListCount"

    $resourceIdLookupTable = @{}
    $i=0
            While ($i -ine $RListCount) {

            Write-Output "Retreiving resource data for page $i"            
            $RListURL = 'https://' + $vRops + '/suite-api/api/resources?page=' + $i + '&pageSize=5000'
            Write-Output "Page $i RListURL: $RListURL"

            $RList = Invoke-RestMethod -Method Get -Uri $RListURL -Credential $cred

                Write-Output "Adding page $i results to ResourceIDLookupTable"
                ForEach ($Item in $Rlist.resources.resource){
                    $resourceIdLookupTable += @{$Item.identifier = $Item.resourceKey.name}
                   }              
            $i++
            }

    $Alarmi=0
            While ($Alarmi -ine $AListCount) {

            Write-Output "Retreiving alarm data for page $Alarmi"  
            $AListURL = 'https://' + $vRops + '/suite-api/api/symptoms/query?page=' + $Alarmi + '&pageSize=5000'
            Write-Output "AListURL: $AListURL"

              $Alist = Invoke-RestMethod -Method post -Uri $AListURL -Headers $headers -body $Body -Credential $cred -TimeoutSec 300
                 
                Write-Output "Adding page $Alarmi data to results"
                ForEach ($ActiveAlarm in $AList.symptoms.symptom){

                foreach ($AlarmLinks in $ActiveAlarm.links) { $link = $activeAlarm.links}

                    $AlarmList += New-Object PSObject -Property @{

                    vRopsNode           = $vRops
                    Name                = $resourceIdLookupTable.Item($ActiveAlarm.resourceId)
                    SymptomId           = $ActiveAlarm.Id 
                    #KPI                 = $ActiveAlarm.kpi
                    resourceId          = $ActiveAlarm.resourceId
                    startTime           = If ([int64]$ActiveAlarm.startTimeUTC -gt '') {([TimeZone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddMilliSeconds([int64]$ActiveAlarm.startTimeUTC))).tostring("dd/MM/yyyy HH:mm:ss")} else {}
                    cancelTime          = If ([int64]$ActiveAlarm.cancelTimeUTC -gt '') {([TimeZone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddMilliSeconds([int64]$ActiveAlarm.cancelTimeUTC))).tostring("dd/MM/yyyy HH:mm:ss")} else {}
                    updateTime          = If ([int64]$ActiveAlarm.updateTimeUTC -gt '') {([TimeZone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddMilliSeconds([int64]$ActiveAlarm.updateTimeUTC))).tostring("dd/MM/yyyy HH:mm:ss")} else {}
                    SymptomCriticality  = $ActiveAlarm.symptomCriticality 
                    SymptomDefinitionId = $ActiveAlarm.symptomDefinitionId 
                    SymptomMessage      = $ActiveAlarm.message
                    LinkToSelf          = "https://" + $vROPS + $link.link[0].href
                    SymptomOnResource   = "https://" + $vROPS + $link.link[1].href
                    SymptomDefinitionForSymptom     = "https://" + $vROPS + $link.link[2].href
                    }
                }

    $Alarmi++
     }
}

$AlarmList | sort vRopsNode,name,SymptomId,resourceID,startTime,cancelTime,updateTime,SymptomCriticality,SymptomDefinitionID, SymptomMessage,LinkToSelf,SymptomOnResource,SymptomDefinitionForSymptom | select vRopsNode,name,SymptomId,resourceID,startTime,cancelTime,updateTime,SymptomCriticality,SymptomDefinitionID, SymptomMessage,LinkToSelf,SymptomOnResource,SymptomDefinitionForSymptom | Export-Csv $Report -NoTypeInformation

 

Some sample outputPost8-Img1

*Thanks to a great post by vMAN covering the extraction of Alert data via the REST APIs, I was able to take some of the code he has kindly shared and change it to meet my needs for Symptom Data.  Hopefully he won’t mind! 🙂

You can read his original post here – http://vman.ch/vrops-suite-api-report-notifications-alarms/)

Link to part 1
Link to part 2