Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 580 - Get-RubrikEventSeries #585

Merged
merged 12 commits into from
Mar 15, 2020
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
* Updated `Get-RubrikAPIData` with formatted objecttypes for `New-RubrikSLA` and `Set-RubrikSLA`
* Updated `New-RubrikSLA` and `Set-RubrikSLA` functions to add type names and decorate output similar to `Get-RubrikSLA`
* Error handing in private function `Get-RubrikAPIData`, now displays error when no matching endpoint is found.
* Changed `Get-RubrikEvent`, adding parametersets to isolate eventSeriesId. When cmdlet is called with eventSeriesId the `Get-RubrikEventSeries` cmdlet is now called rather than filtering through a giant, unindexed table. Details in [Issue 580](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/580)

### Added

* Added `Suspend-RubrikSLA` and `Resume-RubrikSLA`
* Added `Get-RubrikEventSeries` to now parse the event_series API rather than events as per [Issue 580](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/580)
* Added unit tests to cover `Get-RubrikEventSeries` and changes to `Get-RubrikEvent`

## [5.0.1](https://github.com/rubrikinc/rubrik-sdk-for-powershell/tree/5.0.1) - 2020-03-05

Expand Down Expand Up @@ -151,9 +154,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
* Changed the output of the user agent string to display platform information with double-dashed separated key-value pairs.
* The link to `quick-start.md` in the `readme.md` has been updated to a relative link
* The private function `Test-RubrikSLA` had a hard coded local variable
* Renamed Get-RubrikVAppExportOptions to `Get-RubrikVAppExportOption` to use singular nouns
* Renamed Get-RubrikVAppRecoverOptions to `Get-RubrikVAppRecoverOption` to use singular nouns
* Renamed Get-RubrikVcdTemplateExportOptions to `Get-RubrikVcdTemplateExportOption` to use singular nouns
* Renamed Get-RubrikVAppExportOptions to `Get-RubrikVAppExportOption` to use singular nouns
* Renamed Get-RubrikVAppRecoverOptions to `Get-RubrikVAppRecoverOption` to use singular nouns
* Renamed Get-RubrikVcdTemplateExportOptions to `Get-RubrikVcdTemplateExportOption` to use singular nouns
* Changed [parameter type from boolean to switch] for all functions
* Modified private function Submit-Request.ps1 to support adding in success/error information for empty POST, PUT and PATCH responses
* Modified status return code for Remove-RubrikManagedObject
Expand Down
51 changes: 51 additions & 0 deletions Rubrik/ObjectDefinitions/Rubrik.EventSeries.ps1xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<ViewDefinitions>
<View>
<Name>Default</Name>
<ViewSelectedBy>
<TypeName>Rubrik.EventSeries</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>Time</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Status</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Object Type</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Object Location</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>ID</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>eventDate</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>status</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>taskType</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>location</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>eventId</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>
39 changes: 29 additions & 10 deletions Rubrik/Private/Get-RubrikAPIData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function Get-RubrikAPIData {
Body = @{
exportMode = 'exportMode'
networksToRestore = [System.Collections.ArrayList]@()
vmsToExport = @(
vmsToExport = @(
@{
name = 'name'
vcdMoid = 'vcdMoid'
Expand Down Expand Up @@ -186,7 +186,7 @@ function Get-RubrikAPIData {
Success = '200'
ObjectTName = 'Rubrik.APIToken'
}
}
}
'Get-RubrikAPIVersion' = @{
'1.0' = @{
Description = 'Retrieves software version of the Rubrik cluster'
Expand All @@ -206,7 +206,7 @@ function Get-RubrikAPIData {
Method = 'Get'
Body = ''
Query = @{
'ArchiveType' = 'location_type'
'ArchiveType' = 'location_type'
}
Result = 'data'
Filter = @{
Expand Down Expand Up @@ -484,6 +484,25 @@ function Get-RubrikAPIData {
ObjectTName = 'Rubrik.Event'
}
}
'Get-RubrikEventSeries' = @{
'1.0' = @{
Description = 'Retrieve information for event series within Rubrik.'
URI = '/api/internal/event_series'
Method = 'Get'
Body = ''
Query = @{
status = 'status'
event_type = 'event_type'
object_ids = 'object_ids'
object_name = 'object_name'
object_type = 'object_type'
}
Result = 'data'
Filter = ''
Success = '200'
ObjectTName = 'Rubrik.EventSeries'
}
}
'Get-RubrikFileset' = @{
'1.0' = @{
Description = 'Retrieve summary information for each fileset. Optionally, filter the retrieved information.'
Expand Down Expand Up @@ -595,7 +614,7 @@ function Get-RubrikAPIData {
Result = 'data'
Filter = @{
id = 'id'
vmId = 'vmId'
vmId = 'vmId'
}
Success = '200'
}
Expand Down Expand Up @@ -746,7 +765,7 @@ function Get-RubrikAPIData {
Result = 'data'
Filter = @{
id = 'id'
vmId = 'vmId'
vmId = 'vmId'
}
Success = '200'
}
Expand Down Expand Up @@ -1944,7 +1963,7 @@ function Get-RubrikAPIData {
replicationSpecs = @{
locationId = 'locationId'
retentionLimit = 'retentionLimit'
}
}
}
Query = ''
Result = ''
Expand Down Expand Up @@ -1991,7 +2010,7 @@ function Get-RubrikAPIData {
replicationSpecs = @{
locationId = 'locationId'
retentionLimit = 'retentionLimit'
}
}
}
Query = ''
Result = ''
Expand Down Expand Up @@ -2187,7 +2206,7 @@ function Get-RubrikAPIData {
Result = ''
Filter = ''
Success = '204'
}
}
}
'Remove-RubrikAPIToken' = @{
'5.0' = @{
Expand Down Expand Up @@ -2348,7 +2367,7 @@ function Get-RubrikAPIData {
Result = 'data'
Filter = ''
Success = '200'
}
}
'5.1' = @{
Description = 'Revokes an organization authorization for principal(s)'
URI = '/api/internal/authorization/role/organization'
Expand Down Expand Up @@ -3302,7 +3321,7 @@ function Get-RubrikAPIData {
} else {
Write-Verbose -Message "Selected $key API Data for $endpoint"
# Add the function name to resolve issue #480
$api.$endpoint.$key.Add('Function',$endpoint)
$api.$endpoint.$key.Add('Function',$endpoint)
return $api.$endpoint.$key
}
} # End of function
81 changes: 45 additions & 36 deletions Rubrik/Public/Get-RubrikEvent.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#requires -Version 3
function Get-RubrikEvent
{
<#
<#
.SYNOPSIS
Retrieve information for events that match the value specified in any of the following categories: type, status, or ID, and limit events by date.

.DESCRIPTION
The Get-RubrikEvent cmdlet is used to pull a event data set from a Rubrik cluster. There are a vast number of arguments
that can be supplied to narrow down the event query.
The Get-RubrikEvent cmdlet is used to pull a event data set from a Rubrik cluster. There are a vast number of arguments
that can be supplied to narrow down the event query.

.NOTES
Written by J.R. Phillips for community usage
GitHub: JayAreP
GitHub: JayAreP

.LINK
https://rubrik.gitbook.io/rubrik-sdk-for-powershell/command-documentation/reference/get-rubrikevent
Expand All @@ -30,59 +30,63 @@ function Get-RubrikEvent

.EXAMPLE
Get-RubrikHost -Name SQLFoo.demo.com | Get-RubrikEvent -EventType Archive
This will feed any Archive events against the Rubrik Host object 'SQLFoo.demo.com' via a piped query.
This will feed any Archive events against the Rubrik Host object 'SQLFoo.demo.com' via a piped query.

.EXAMPLE
Get-RubrikEvent -EventSeriesId '1111-2222-3333'
This will retrieve all of the events belonging to the specified EventSeriesId. *Note - This will call Get-RubrikEventSeries*

#>

[CmdletBinding()]
Param(
# Maximum number of events retrieved, default is to return 50 objects
[parameter()]
[Parameter(ParameterSetName="eventByID")]
[int]$Limit = 50,
# Earliest event retrieved
[Alias('after_id')]
[parameter()]
[Parameter(ParameterSetName="eventByID")]
[string]$AfterId,
# Filter by Event Series ID
# Filter by Event Series ID
[Alias('event_series_id')]
[parameter()]
[Parameter(ParameterSetName='EventSeries',Mandatory=$true)]
[string]$EventSeriesId,
# Filter by Status. Enter any of the following values: 'Failure', 'Warning', 'Running', 'Success', 'Canceled', 'Canceling’.
[ValidateSet('Failure', 'Warning', 'Running', 'Success', 'Canceled', 'Canceling', 'Queued', IgnoreCase = $false)]
[parameter()]
[Parameter(ParameterSetName="eventByID")]
[string]$Status,
# Filter by Event Type.
[ValidateSet('Archive', 'Audit', 'AuthDomain', 'Backup', 'CloudNativeSource', 'Configuration', 'Diagnostic', 'Discovery', 'Instantiate', 'Maintenance', 'NutanixCluster', 'Recovery', 'Replication', 'StorageArray', 'StormResource', 'System', 'Vcd', 'VCenter', IgnoreCase = $false)]
[Alias('event_type')]
[parameter()]
[Parameter(ParameterSetName="eventByID")]
[string]$EventType,
# Filter by a comma separated list of object IDs.
[Alias('object_ids')]
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Parameter(ValueFromPipelineByPropertyName = $true,ParameterSetName="eventByID")]
[array]$id,
# Filter all the events according to the provided name using infix search for resources and exact search for usernames.
# Filter all the events according to the provided name using infix search for resources and exact search for usernames.
[Alias('object_name')]
[parameter()]
[Parameter(ParameterSetName="eventByID")]
[string]$ObjectName,
# Filter all the events before a date.
[Alias('before_date')]
[parameter()]
[Parameter(ParameterSetName="eventByID")]
[System.DateTime]$BeforeDate,
# Filter all the events after a date.
[Alias('after_date')]
[parameter()]
[Parameter(ParameterSetName="eventByID")]
[System.DateTime]$AfterDate,
# Filter all the events by object type. Enter any of the following values: 'VmwareVm', 'Mssql', 'LinuxFileset', 'WindowsFileset', 'WindowsHost', 'LinuxHost', 'StorageArrayVolumeGroup', 'VolumeGroup', 'NutanixVm', 'Oracle', 'AwsAccount', and 'Ec2Instance'. WindowsHost maps to both WindowsFileset and VolumeGroup, while LinuxHost maps to LinuxFileset and StorageArrayVolumeGroup.
[Alias('object_type')]
[parameter()]
[Parameter(ParameterSetName="eventByID")]
[string]$ObjectType,
# A switch value that determines whether to show only on the most recent event in the series. When 'true' only the most recent event in the series are shown. When 'false' all events in the series are shown. The default value is 'true'.
[Alias('show_only_latest')]
[parameter()]
[Parameter(ParameterSetName="eventByID")]
[Switch]$ShowOnlyLatest,
# A Switch value that determines whether to filter only on the most recent event in the series. When 'true' only the most recent event in the series are filtered. When 'false' all events in the series are filtered. The default value is 'true'.
[Alias('filter_only_on_latest')]
[parameter()]
[Parameter(ParameterSetName="eventByID")]
[Switch]$FilterOnlyOnLatest,
# Rubrik server IP or FQDN
[String]$Server = $global:RubrikConnection.server,
Expand All @@ -94,47 +98,52 @@ function Get-RubrikEvent

# The Begin section is used to perform one-time loads of data necessary to carry out the function's purpose
# If a command needs to be run with each iteration or pipeline input, place it in the Process section

# Check to ensure that a session to the Rubrik cluster exists and load the needed header data for authentication
Test-RubrikConnection

# API data references the name of the function
# For convenience, that name is saved here to $function
$function = $MyInvocation.MyCommand.Name

# Retrieve all of the URI, method, body, query, result, filter, and success details for the API endpoint
Write-Verbose -Message "Gather API Data for $function"
$resources = Get-RubrikAPIData -endpoint $function
Write-Verbose -Message "Load API data for $($resources.Function)"
Write-Verbose -Message "Description: $($resources.Description)"

}

Process {

# If the switch parameter was not explicitly specified remove from query params
if(-not $PSBoundParameters.ContainsKey('ShowOnlyLatest')) { $Resources.Query.Remove('show_only_latest') }
if(-not $PSBoundParameters.ContainsKey('FilterOnlyOnLatest')) { $Resources.Query.Remove('filter_only_on_latest') }

$uri = New-URIString -server $Server -endpoint ($resources.URI)
$uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri
$body = New-BodyString -bodykeys ($resources.Body.Keys) -parameters ((Get-Command $function).Parameters.Values)
$result = Submit-Request -uri $uri -header $Header -method $($resources.Method) -body $body
$result = Test-ReturnFormat -api $api -result $result -location $resources.Result
$result = Test-FilterObject -filter ($resources.Filter) -result $result


if (-not $EventSeriesId) {
# If the switch parameter was not explicitly specified remove from query params
if(-not $PSBoundParameters.ContainsKey('ShowOnlyLatest')) { $Resources.Query.Remove('show_only_latest') }
if(-not $PSBoundParameters.ContainsKey('FilterOnlyOnLatest')) { $Resources.Query.Remove('filter_only_on_latest') }

$uri = New-URIString -server $Server -endpoint ($resources.URI)
$uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri
$body = New-BodyString -bodykeys ($resources.Body.Keys) -parameters ((Get-Command $function).Parameters.Values)
$result = Submit-Request -uri $uri -header $Header -method $($resources.Method) -body $body
$result = Test-ReturnFormat -api $api -result $result -location $resources.Result
$result = Test-FilterObject -filter ($resources.Filter) -result $result
}
else {
# Adding property for TypeName support
$result = ((Get-RubrikEventSeries -id $EventSeriesId).eventDetailList) | Select-Object *,@{N="eventStatus";E={$_.status}}
}
# Add 'date' property to the output by converting 'time' property to datetime object
if (($null -ne $result) -and ($null -ne ($result | Select-Object -First 1).time)) {
$result = $result | ForEach-Object {
Select-Object -InputObject $_ -Property *,@{
name = 'date'
expression = {Convert-APIDateTime -DateTimeString $_.time}
}
}
}
}
$result = Set-ObjectTypeName -TypeName $resources.ObjectTName -result $result
return $result


} # End of process
} # End of function
Loading