Skip to content

Commit

Permalink
Merge pull request #18 from chrisdonlan/cdln-improved-webrequest-succ…
Browse files Browse the repository at this point in the history
…ess-check

improved the web request success handling.
  • Loading branch information
TrevorSquillario authored Feb 23, 2024
2 parents 468722b + 070430d commit 1a26275
Show file tree
Hide file tree
Showing 46 changed files with 88 additions and 88 deletions.
4 changes: 2 additions & 2 deletions DellOpenManage/Private/Get-ApiAllData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Get-ApiAllData {
$Data = @()
$ContentType = "application/json"
$Response = Invoke-WebRequest -UseBasicParsing -Uri $Url -Headers $Headers -Method Get
if ($Response.StatusCode -eq 200) {
if ($Response.StatusCode -in (200,201)) {
$Info = $Response.Content | ConvertFrom-Json
if ($Info.value) {
foreach ($Value in $Info.value) {
Expand All @@ -33,7 +33,7 @@ function Get-ApiAllData {
}
while($NextLinkUrl) {
$NextLinkResponse = Invoke-WebRequest -Uri $NextLinkUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $ContentType
if($NextLinkResponse.StatusCode -eq 200)
if($NextLinkResponse.StatusCode -in (200,201))
{
$NextLinkData = $NextLinkResponse.Content | ConvertFrom-Json
foreach ($NextLink in $NextLinkData.'value') {
Expand Down
2 changes: 1 addition & 1 deletion DellOpenManage/Private/Wait-OnConfigurationBaseline.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Process {
$Ctr++
Start-Sleep -Seconds $SLEEP_INTERVAL
$BaselineResponse = Invoke-WebRequest -Uri $BaselineUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if ($BaselineResponse.StatusCode -eq 200) {
if ($BaselineResponse.StatusCode -in (200,201)) {
$BaselineInfo = $BaselineResponse.Content | ConvertFrom-Json
foreach ($Baseline in $BaselineInfo.'value') {
if ($Baseline.Id -eq $BaselineId) {
Expand Down
2 changes: 1 addition & 1 deletion DellOpenManage/Private/Wait-OnFirmwareBaseline.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Process {
$Ctr++
Start-Sleep -Seconds $SLEEP_INTERVAL
$BaselineResponse = Invoke-WebRequest -Uri $BaselineUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if ($BaselineResponse.StatusCode -eq 200) {
if ($BaselineResponse.StatusCode -in (200,201)) {
$BaselineInfo = $BaselineResponse.Content | ConvertFrom-Json
foreach ($Baseline in $BaselineInfo.'value') {
if ($Baseline.Name -eq $BaselineName) {
Expand Down
2 changes: 1 addition & 1 deletion DellOpenManage/Private/Wait-OnTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Process {
$Ctr++
Start-Sleep -Seconds $SLEEP_INTERVAL
$TemplateResponse = Invoke-WebRequest -Uri $TemplateUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if ($TemplateResponse.StatusCode -eq 200) {
if ($TemplateResponse.StatusCode -in (200,201)) {
$TemplateInfo = $TemplateResponse.Content | ConvertFrom-Json
$Status = [int]$TemplateInfo.value[0].Status
Write-Verbose "Iteration $($Ctr): Status of $($TemplateId) is $($JOB_STATUS_MAP.$Status)"
Expand Down
6 changes: 3 additions & 3 deletions DellOpenManage/Public/OME/Connect-OMEServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ param(
$UserDetails = @{"UserName"=$OMEUserName;"Password"=$OMEPassword;"SessionType"="API"} | ConvertTo-Json

$SessResponse = Invoke-WebRequest -Uri $SessionUrl -UseBasicParsing -Method Post -Body $UserDetails -ContentType $Type
if ($SessResponse.StatusCode -eq 200 -or $SessResponse.StatusCode -eq 201) {
if ($SessResponse.StatusCode -in 200, 201) {
$SessResponseData = $SessResponse.Content | ConvertFrom-Json

$Token = [String]$SessResponse.Headers["X-Auth-Token"]
Expand All @@ -91,7 +91,7 @@ param(
$AppInfoUrl = "https://$($OMEHost)/api/ApplicationService/Info"
$AppInfoResponse = Invoke-WebRequest -Uri $AppInfoUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
$AppVersion = [System.Version]"1.0.0"
if ($AppInfoResponse.StatusCode -eq 200 -or $AppInfoResponse.StatusCode -eq 201) {
if ($AppInfoResponse.StatusCode -in 200, 201) {
$AppInfoResponseData = $AppInfoResponse.Content | ConvertFrom-Json
Write-Verbose $($AppInfoResponseData)
$AppVersion = [System.Version]$AppInfoResponseData.Version
Expand All @@ -108,4 +108,4 @@ param(
} else {
Write-Error "Unable to create a session with appliance $($OMEHost)"
}
}
}
6 changes: 3 additions & 3 deletions DellOpenManage/Public/OME/Copy-OMETemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function Get-TemplateVlan($BaseUri, $ContentType, $Headers, $Template) {
$NETWORK_HIERARCHY_VIEW = 4 # For Network hierarchy View in a Template
$TemplateVlanUrl = $BaseUri + "/api/TemplateService/Templates($($Template.Id))/Views($($NETWORK_HIERARCHY_VIEW))/AttributeViewDetails"
$TemplateVlanResponse = Invoke-WebRequest -Uri $TemplateVlanUrl -UseBasicParsing -Method Get -ContentType $ContentType -Headers $Headers
if ($TemplateVlanResponse.StatusCode -eq 200) {
if ($TemplateVlanResponse.StatusCode -in 200, 201) {
$TemplateVlans = $TemplateVlanResponse.Content | ConvertFrom-Json
$NICGroups = @()
$NICBondingList = @()
Expand Down Expand Up @@ -188,7 +188,7 @@ Process {
$NewTemplateId = $null
Write-Verbose "Clone Template..."
$TemplateResponse = Invoke-WebRequest -Uri $TemplateUrl -UseBasicParsing -Method Post -Body $TemplatePayload -ContentType $ContentType -Headers $Headers
if ($TemplateResponse.StatusCode -eq 200) {
if ($TemplateResponse.StatusCode -in 200, 201) {
$NewTemplateId = [int]$TemplateResponse.Content
Write-Verbose "Clone Template Success - Id $($NewTemplateId)"
}
Expand All @@ -203,7 +203,7 @@ Process {
Write-Verbose $CloneTemplateVlanPayload
$TemplateUpdateNetworkUrl = $BaseUri + "/api/TemplateService/Actions/TemplateService.UpdateNetworkConfig"
$TemplateVlanResponse = Invoke-WebRequest -Uri $TemplateUpdateNetworkUrl -UseBasicParsing -Method Post -Body $CloneTemplateVlanPayload -ContentType $ContentType -Headers $Headers
if ($TemplateVlanResponse.StatusCode -eq 200) {
if ($TemplateVlanResponse.StatusCode -in 200, 201) {
Write-Verbose "Clone Template Success - VLANs"
}
}
Expand Down
4 changes: 2 additions & 2 deletions DellOpenManage/Public/OME/Edit-OMEDiscovery.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function Get-JobId($BaseUri, $Headers, $DiscoverConfigGroupId) {
$JobId = -1
$JobUrl = $BaseUri + "/api/DiscoveryConfigService/Jobs"
$JobResponse = Invoke-WebRequest -UseBasicParsing -Uri $JobUrl -Headers $Headers -Method Get
if ($JobResponse.StatusCode -eq 200) {
if ($JobResponse.StatusCode -in 200, 201) {
$JobInfo = $JobResponse.Content | ConvertFrom-Json
$JobValues = $JobInfo.value
foreach ($value in $JobValues) {
Expand Down Expand Up @@ -282,7 +282,7 @@ Process {
$DiscoveryId = $Discovery.Id
$DiscoverUrl = $BaseUri + "/api/DiscoveryConfigService/DiscoveryConfigGroups(" + $DiscoveryId + ")"
$DiscoverResponse = Invoke-WebRequest -Uri $DiscoverUrl -UseBasicParsing -Method Put -Body $Payload -Headers $Headers -ContentType $Type
if ($DiscoverResponse.StatusCode -eq 200) {
if ($DiscoverResponse.StatusCode -in 200, 201) {
Write-Verbose "Discovering devices...."
Start-Sleep -Seconds 10
$DiscoverInfo = $DiscoverResponse.Content | ConvertFrom-Json
Expand Down
2 changes: 1 addition & 1 deletion DellOpenManage/Public/OME/Edit-OMEGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Process {

$GroupResponse = Invoke-WebRequest -Uri $GroupURL -UseBasicParsing -Headers $Headers -ContentType $Type -Method POST -Body $GroupPayload
Write-Verbose "Updating group..."
if ($GroupResponse.StatusCode -eq 200) {
if ($GroupResponse.StatusCode -in 200, 201) {
Write-Verbose "Group update successful!"
return $GroupResponse.Content | ConvertFrom-Json
}
Expand Down
2 changes: 1 addition & 1 deletion DellOpenManage/Public/OME/Edit-OMESecurityBanner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Process {
Write-Verbose $BannerPayload
$BannerResponse = Invoke-WebRequest -Uri $BannerURL -UseBasicParsing -Headers $Headers -ContentType $Type -Method POST -Body $BannerPayload
Write-Verbose "Updating banner text..."
if ($BannerResponse.StatusCode -eq 200) {
if ($BannerResponse.StatusCode -in 200, 201) {
Write-Verbose "Banner update successfull!"
return $true
}
Expand Down
4 changes: 2 additions & 2 deletions DellOpenManage/Public/OME/Get-OMEAlertDefinition.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Process {

$DefinitionCountUrl = $BaseUri + "/api/AlertService/AlertMessageDefinitions"
$DeviceResponse = Invoke-WebRequest -Uri $DefinitionCountUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if ($DeviceResponse.StatusCode -eq 200)
if ($DeviceResponse.StatusCode -in 200, 201)
{
$DefinitionCountData = $DeviceResponse.Content | ConvertFrom-Json
foreach ($Definition in $DefinitionCountData.'value') {
Expand All @@ -69,7 +69,7 @@ Process {
while($NextLinkUrl)
{
$NextLinkResponse = Invoke-WebRequest -Uri $NextLinkUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if($NextLinkResponse.StatusCode -eq 200)
if($NextLinkResponse.StatusCode -in 200, 201)
{
$NextLinkData = $NextLinkResponse.Content | ConvertFrom-Json
foreach ($Definition in $NextLinkData.'value') {
Expand Down
4 changes: 2 additions & 2 deletions DellOpenManage/Public/OME/Get-OMEAlertPolicy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Process {
}
Write-Verbose $AlertPolicyUrl
$AlertPolicyResponse = Invoke-WebRequest -Uri $AlertPolicyUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if ($AlertPolicyResponse.StatusCode -eq 200)
if ($AlertPolicyResponse.StatusCode -in 200, 201)
{
$AlertPolicyCountData = $AlertPolicyResponse.Content | ConvertFrom-Json
foreach ($AlertPolicy in $AlertPolicyCountData.'value') {
Expand All @@ -94,7 +94,7 @@ Process {
{
Write-Verbose $NextLinkUrl
$NextLinkResponse = Invoke-WebRequest -Uri $NextLinkUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if($NextLinkResponse.StatusCode -eq 200)
if($NextLinkResponse.StatusCode -in 200, 201)
{
$NextLinkData = $NextLinkResponse.Content | ConvertFrom-Json
foreach ($AlertPolicy in $NextLinkData.'value') {
Expand Down
4 changes: 2 additions & 2 deletions DellOpenManage/Public/OME/Get-OMEApplicationSettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ limitations under the License.

$JobURL = $BaseUri + "/api/ApplicationService/Actions/ApplicationService.GetConfiguration"
$JobResp = Invoke-WebRequest -Uri $JobURL -UseBasicParsing -Headers $Headers -ContentType $Type -Method POST -Body $null
if ($JobResp.StatusCode -eq 200) {
if ($JobResp.StatusCode -in 200, 201) {
Write-Verbose "Application settings job submitted successful..."
$JobInfo = $JobResp.Content | ConvertFrom-Json
$JobInfo
Expand All @@ -61,4 +61,4 @@ limitations under the License.

End {}

}
}
2 changes: 1 addition & 1 deletion DellOpenManage/Public/OME/Get-OMECatalog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Process {

$CatalogData = @()
$CatalogResp = Invoke-WebRequest -Uri $CatalogUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if ($CatalogResp.StatusCode -eq 200) {
if ($CatalogResp.StatusCode -in 200, 201) {
$CatalogInfo = $CatalogResp.Content | ConvertFrom-Json
foreach ($Catalog in $CatalogInfo.'value') {
if ($Value.Count -gt 0 -and $FilterBy -eq "Id") {
Expand Down
4 changes: 2 additions & 2 deletions DellOpenManage/Public/OME/Get-OMEConfigurationBaseline.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Process {

$BaselineData = @()
$BaselineResp = Invoke-WebRequest -Uri $BaselineUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if ($BaselineResp.StatusCode -eq 200) {
if ($BaselineResp.StatusCode -in 200, 201) {
$BaselineInfo = $BaselineResp.Content | ConvertFrom-Json
foreach ($Baseline in $BaselineInfo.'value') {
if ($Value.Count -gt 0 -and $FilterBy -eq "Id") {
Expand Down Expand Up @@ -93,4 +93,4 @@ Process {

End {}

}
}
4 changes: 2 additions & 2 deletions DellOpenManage/Public/OME/Get-OMEConfigurationCompliance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Process {
# 2 = "Not Compliant"
#}

if ($Response.StatusCode -eq 200) {
if ($Response.StatusCode -in 200, 201) {
$ComplData = $Response | ConvertFrom-Json
$ComplianceDeviceList = $ComplData.'value'

Expand All @@ -92,7 +92,7 @@ Process {
while($NextLinkUrl)
{
$NextLinkResponse = Invoke-WebRequest -Uri $NextLinkUrl -UseBasicParsing -Method GET -Headers $Headers -ContentType $Type
if($NextLinkResponse.StatusCode -eq 200) {
if($NextLinkResponse.StatusCode -in 200, 201) {
$NextLinkData = $NextLinkResponse.Content | ConvertFrom-Json
$ComplianceDeviceList = $ComplianceDeviceList + $NextLinkData.'value'
if($NextLinkData.'@odata.nextLink')
Expand Down
8 changes: 4 additions & 4 deletions DellOpenManage/Public/OME/Get-OMEDevice.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Process {
$GroupUrl = "https://$($SessionAuth.Host)/api/GroupService/Groups"
$GroupUrl += "(" + [String]($Group.Id) + ")/Devices"
$GroupResp = Invoke-WebRequest -Uri $GroupUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if ($GroupResp.StatusCode -eq 200) {
if ($GroupResp.StatusCode -in 200, 201) {
$GroupInfo = $GroupResp.Content | ConvertFrom-Json
$GroupData = $GroupInfo.'value'
$DeviceCount = $GroupInfo.'@odata.count'
Expand All @@ -127,7 +127,7 @@ Process {
$delta = $DeviceCount-$currDeviceCount
$RemainingDeviceUrl = $GroupUrl+"?`$skip=$($currDeviceCount)&`$top=$($delta)"
$RemainingDeviceResp = Invoke-WebRequest -Uri $RemainingDeviceUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if($RemainingDeviceResp.StatusCode -eq 200){
if($RemainingDeviceResp.StatusCode -in 200, 201){
$RemainingDeviceInfo = $RemainingDeviceResp.Content | ConvertFrom-Json
foreach ($Device in $RemainingDeviceInfo.'value') {
$DeviceData += New-DeviceFromJson -Device $Device
Expand Down Expand Up @@ -157,7 +157,7 @@ Process {
$DeviceCountUrl = $DeviceCountUrl + "?" + $Filter
Write-Verbose $DeviceCountUrl
$DeviceResponse = Invoke-WebRequest -Uri $DeviceCountUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if ($DeviceResponse.StatusCode -eq 200)
if ($DeviceResponse.StatusCode -in 200, 201)
{
$DeviceCountData = $DeviceResponse.Content | ConvertFrom-Json
foreach ($Device in $DeviceCountData.'value') {
Expand All @@ -171,7 +171,7 @@ Process {
{
Write-Verbose $NextLinkUrl
$NextLinkResponse = Invoke-WebRequest -Uri $NextLinkUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if($NextLinkResponse.StatusCode -eq 200)
if($NextLinkResponse.StatusCode -in 200, 201)
{
$NextLinkData = $NextLinkResponse.Content | ConvertFrom-Json
foreach ($Device in $NextLinkData.'value') {
Expand Down
4 changes: 2 additions & 2 deletions DellOpenManage/Public/OME/Get-OMEDeviceDetail.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Process {
$InventoryUrl = $BaseUri + "/api/DeviceService/Devices($($Devices.Id))/InventoryDetails('$($InventoryType)')"
}
$InventoryResp = Invoke-WebRequest -Uri $InventoryUrl -UseBasicParsing -Headers $Headers -Method Get -ContentType $Type
if ($InventoryResp.StatusCode -eq 200) {
if ($InventoryResp.StatusCode -in 200, 201) {
$InventoryInfo = $InventoryResp.Content | ConvertFrom-Json
if ($InventoryInfo.'value') {
$InventoryData = $InventoryInfo.'value'
Expand Down Expand Up @@ -102,4 +102,4 @@ Process {

End {}

}
}
2 changes: 1 addition & 1 deletion DellOpenManage/Public/OME/Get-OMEDiscovery.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Process {

$DiscoveryData = @()
$DiscoveryResp = Invoke-WebRequest -Uri $DiscoveryUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if ($DiscoveryResp.StatusCode -eq 200) {
if ($DiscoveryResp.StatusCode -in 200, 201) {
$DiscoveryInfo = $DiscoveryResp.Content | ConvertFrom-Json
foreach ($Discovery in $DiscoveryInfo.'value') {
if ($Value.Count -gt 0 -and $FilterBy -eq "Id") {
Expand Down
4 changes: 2 additions & 2 deletions DellOpenManage/Public/OME/Get-OMEFirmwareBaseline.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Process {

$BaselineData = @()
$BaselineResp = Invoke-WebRequest -Uri $BaselineUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if ($BaselineResp.StatusCode -eq 200) {
if ($BaselineResp.StatusCode -in 200, 201) {
$BaselineInfo = $BaselineResp.Content | ConvertFrom-Json
foreach ($Baseline in $BaselineInfo.'value') {
if ($Value.Count -gt 0 -and $FilterBy -eq "Id") {
Expand Down Expand Up @@ -94,4 +94,4 @@ Process {

End {}

}
}
4 changes: 2 additions & 2 deletions DellOpenManage/Public/OME/Get-OMEFirmwareCompliance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Process {
$UpdateActionSet += $UpdateAction
}

if ($Response.StatusCode -eq 200) {
if ($Response.StatusCode -in 200, 201) {
$ComplData = $Response | ConvertFrom-Json
$ComplianceDeviceList = $ComplData.'value'

Expand All @@ -147,7 +147,7 @@ Process {
while($NextLinkUrl)
{
$NextLinkResponse = Invoke-WebRequest -Uri $NextLinkUrl -UseBasicParsing -Method GET -Headers $Headers -ContentType $Type
if($NextLinkResponse.StatusCode -eq 200) {
if($NextLinkResponse.StatusCode -in 200, 201) {
$NextLinkData = $NextLinkResponse.Content | ConvertFrom-Json
$ComplianceDeviceList = $ComplianceDeviceList + $NextLinkData.'value'
if($NextLinkData.'@odata.nextLink')
Expand Down
6 changes: 3 additions & 3 deletions DellOpenManage/Public/OME/Get-OMEGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Process {
$GroupUrl = $GroupUrl + "?" + $Filter
Write-Verbose $GroupUrl
$GrpResp = Invoke-WebRequest -Uri $GroupUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if ($GrpResp.StatusCode -eq 200) {
if ($GrpResp.StatusCode -in 200, 201) {
$GroupInfo = $GrpResp.Content | ConvertFrom-Json
foreach ($Group in $GroupInfo.'value') {
$GroupData += New-GroupFromJson $Group
Expand All @@ -90,7 +90,7 @@ Process {
{
Write-Verbose $NextLinkUrl
$NextLinkResponse = Invoke-WebRequest -Uri $NextLinkUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if($NextLinkResponse.StatusCode -eq 200)
if($NextLinkResponse.StatusCode -in 200, 201)
{
$NextLinkData = $NextLinkResponse.Content | ConvertFrom-Json
foreach ($Group in $NextLinkData.'value') {
Expand Down Expand Up @@ -124,4 +124,4 @@ Process {

End {}

}
}
Loading

0 comments on commit 1a26275

Please sign in to comment.