The next report dumps all notifications, all alarms available in the environment and all the alarms that have been triggered into alerts still retained in vRops.
The report can be run against one or multiple vRops environments and will merge the results into one report.
So to the script..
So that I don’t keep being prompted for credentials I save the service account user and password with the powershell Get-Credential command.
$cred = Get-Credential $cred | Export-Clixml -Path "d:\vRops\Config\vc.xml"
Make sure to update the variables to match your environment / config.
$vRopsAddress : IP or DNS name of vRops environment to pull data from. (Single or array of vRops environments to target.)
$Creds : HOME is the name of the XML file to pull the credentials from IE: HOME.xml (make sure to store it in a sub-directory called config)
$Report : The file to output to.
Make sure to install https://github.com/dfinke/ImportExcel otherwise the output will fail.
Note: if you have more than 5000 Resources per vRops environment you will need to adapt the script to loop through the multiple pages of suite-api results like I have done for Alerts.
#Powershell collector script for vRops Suite-api to get Alert and Notification configuration #v1.0 vMan.ch, 20.03.2016 - Initial Version <# Script requires Powershell v4 and install https://github.com/dfinke/ImportExcel Run the command below to store user and pass in secure credential XML for each environment $cred = Get-Credential $cred | Export-Clixml -Path "d:\vRops\vMan.xml" #> #Variables $ScriptPath = (Get-Item -Path ".\" -Verbose).FullName $Report = "$ScriptPath\Alarms-Alerts-Notifications.xlsx" $vRopsAddress = @('vRops-1-vMan.ch','vRops-2-vMan.ch') $creds = 'HOME' if($creds -gt ""){ $cred = Import-Clixml -Path "$ScriptPath\config\$creds.xml" $vRopsUser = $cred.GetNetworkCredential().Username $vRopsPassword = $cred.GetNetworkCredential().Password } else { echo "Creds not specified!" Exit } #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 $notifications = @() $alerts = @() $alerttype = @() $alertsubtypes = @() $alertList = @() ForEach ($vRops in $vRopsAddress){ Echo "Collecting Alert and Notification configuration from $vRops" $Notif = Invoke-RestMethod -Method Get -Uri "https://$vRops/suite-api/api/notifications/rules/?pageSize=5000" -Credential $cred $alert = Invoke-RestMethod -Method Get -Uri "https://$vRops/suite-api/api/alertdefinitions/?pageSize=5000" -Credential $cred $types = Invoke-RestMethod -Method Get -Uri "https://$vRops/suite-api/api/alerts/types/?pageSize=5000" -Credential $cred $AList = Invoke-RestMethod -Method Get -Uri "https://$vRops/suite-api/api/alerts?pageSize=1" -Credential $cred $RList = Invoke-RestMethod -Method Get -Uri "https://$vRops/suite-api/api/resources?pageSize=1" -Credential $cred If ($AList.alerts.pageInfo.totalCount -lt 5001){ $AListCount = 1 } Else { [int]$AListCount = [math]::Round($AList.alerts.pageInfo.totalCount/5000) } If ($RList.alerts.pageInfo.totalCount -lt 5001){ $RListCount = 1 } Else { [int]$RListCount = [math]::Round($RList.resources.pageInfo.totalCount/5000) } $resourceIdLookupTable = @{} $i=0 While ($i -ine $RListCount) { $RListURL = 'https://' + $vRops + '/suite-api/api/resources?page=' + $i + '&pageSize=5000' $RList = Invoke-RestMethod -Method Get -Uri $RListURL -Credential $cred ForEach ($Item in $Rlist.resources.resource){ $resourceIdLookupTable += @{$Item.identifier = $Item.resourceKey.name} } $i++ } $resourceTypeLookupTable = @{} $i=0 While ($i -ine $RListCount) { $RListURL = 'https://' + $vRops + '/suite-api/api/resources?page=' + $i + '&pageSize=5000' $RList = Invoke-RestMethod -Method Get -Uri $RListURL -Credential $cred ForEach ($Item in $Rlist.resources.resource){ $resourceTypeLookupTable += @{$Item.identifier = $Item.resourceKey.resourceKindKey} } $i++ } ForEach ($Note in $notif.'notification-rules'.'notification-rule' ){ ForEach ($Crit in $Note.criticalities -split ' '){ ForEach ($AlrType in $Note.alertTypeFilters.alertType -split ','){ ForEach ($AlrSubType in $Note.alertTypeFilters.alertSubTypes -split ','){ $notifications += New-Object PSObject -Property @{ vRops = $vRops Name = $Note.name id = $Note.id Email = $Note.properties | where name -eq 'emailaddr' | Select '#text' resend = $Note.properties | where name -eq 'resend' | Select '#text' maxNotify = $Note.properties | where name -eq 'maxNotify' | Select '#text' alertControlStates = $Note.alertControlStates alertStatuses = $Note.alertStatuses resourceKind = $Note.resourceKindFilter.resourceKind adapterKind = $Note.resourceKindFilter.adapterKind criticalities = $Crit alertType = $AlrType alertSubTypes = $AlrSubType } } } } } ForEach ($lrt in $alert.'alert-definitions'.'alert-definition' ){ $alerts += New-Object PSObject -Property @{ vRops = $vRops Name = $lrt.name description = $lrt.description Adapter = $lrt.adapterKindKey ResourceKindKey = $lrt.ResourceKindKey Type = $lrt.Type Subtype = $lrt.Subtype Severity = $lrt.states.state.severity Impact = ($lrt.states.state.Impact.detail).ToUpper() } } ForEach ($typ in $types.'alert-types'.'alert-type' ){ $alerttype += New-Object PSObject -Property @{ vRops = $vRops name = $typ.name description = $typ.description id = $typ.id subtypes = $typ.subtypes } } ForEach ($Subtyp in $alerttype.subtypes ){ $alertsubtypes += New-Object PSObject -Property @{ vRops = $vRops Name = $Subtyp.name Description = $Subtyp.description id = $Subtyp.id } } $Alerti=0 While ($Alerti -ine $AListCount) { $AListURL = 'https://' + $vRops + '/suite-api/api/alerts?page=' + $Alerti + '&pageSize=5000' $AList = Invoke-RestMethod -Method Get -Uri $AListURL -Credential $cred -TimeoutSec 120 ForEach ($ActiveAlert in $AList.alerts.alert ){ $alertList += New-Object PSObject -Property @{ vRops = $vRops Name = $resourceIdLookupTable.Item($ActiveAlert.resourceId) ResourceKind = $resourceTypeLookupTable.Item($ActiveAlert.resourceId) alertId = $ActiveAlert.alertId resourceId = $ActiveAlert.resourceId alertLevel = $ActiveAlert.alertLevel type = $ActiveAlert.type subType = $ActiveAlert.subType status = $ActiveAlert.status startTime = If ([int64]$ActiveAlert.startTimeUTC -gt '') {([TimeZone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddMilliSeconds([int64]$ActiveAlert.startTimeUTC))).tostring("dd/MM/yyyy HH:mm:ss")} else {} cancelTime = If ([int64]$ActiveAlert.cancelTimeUTC -gt '') {([TimeZone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddMilliSeconds([int64]$ActiveAlert.cancelTimeUTC))).tostring("dd/MM/yyyy HH:mm:ss")} else {} updateTime = If ([int64]$ActiveAlert.updateTimeUTC -gt '') {([TimeZone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddMilliSeconds([int64]$ActiveAlert.updateTimeUTC))).tostring("dd/MM/yyyy HH:mm:ss")} else {} suspendUntilTime = If ([int64]$ActiveAlert.suspendUntilTimeUTC -gt ''){([TimeZone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddMilliSeconds([int64]$ActiveAlert.suspendUntilTimeUTC))).tostring("dd/MM/yyyy HH:mm:ss")} else {} controlState = $ActiveAlert.controlState alertDefinitionId = $ActiveAlert.alertDefinitionId alertDefinitionName = $ActiveAlert.alertDefinitionName } } $Alerti++ } } $notifications | sort vRops,Name,Email,resend,maxNotify,id,alertControlStates,alertStatuses,criticalities,resourceKind,adapterKind,alertType,alertSubTypes –Unique | Select vRops,Name,@{Name="Email";Expression={$_.email.'#text'}},@{Name="resend";Expression={$_.resend.'#text'}},@{Name="maxNotify ";Expression={$_.maxNotify.'#text'}},id,alertControlStates,alertStatuses,criticalities,resourceKind,adapterKind,alertType,alertSubTypes | Export-Excel $Report -WorkSheetname notifications $alerts | sort vRops,Name,Description,Adapter,ResourceKindKey,Type,Subtype,Severity,Impact –Unique | Select vRops,Name,ResourceKindKey,Adapter,Type,Subtype,Severity,Impact,Description | Export-Excel $Report -WorkSheetname alerts $alerttype | sort vRops,id,name,description –Unique | select vRops,id,name,description | Export-Excel $Report -WorkSheetname alerttype $alertsubtypes | sort vRops,id,name,description –Unique | select vRops,id,name,description | Export-Excel $Report -WorkSheetname alertsubtypes $alertList | sort vRops,name,ResourceKind,resourceId,alertDefinitionName,alertDefinitionId,alertId,alertLevel,type,subType,status,startTime,cancelTime,updateTime,controlState,suspendUntilTime -unique | select vRops,name,ResourceKind,resourceId,alertDefinitionName,alertDefinitionId,alertId,alertLevel,type,subType,status,startTime,cancelTime,updateTime,controlState,suspendUntilTime | Export-Excel $Report -WorkSheetname ActiveAlerts
vMan
Recent Comments