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.
1 2 |
$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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
#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