Dynamically Download a Recordset of Lacework Alert Types and Store Them as a Custom Object in Zendesk Using PowerShell

 # API keys and credentials
$lwApiKey = "your_lacework_api_key"
$zdEmail = "your_zendesk_email"
$zdPassword = "your_zendesk_password"
$zdSubdomain = "your_zendesk_subdomain"

# Lacework API endpoint
$lwApiEndpoint = "https://api.lacework.net/api/v1/AlertTypes"

# Zendesk API endpoint
$zdApiEndpoint = "https://$zdSubdomain.zendesk.com/api/v2/objects/records"

# Create authentication header for Zendesk
$zdAuthHeader = @{
    'Authorization' = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$zdEmail:$zdPassword"))
}

# Get Lacework alert types
$response = Invoke-RestMethod -Uri $lwApiEndpoint -Headers @{ "X-Api-Key" = $lwApiKey } -Method Get
$alertTypes = $response.data

# Create a custom object in Zendesk for each Lacework alert type
foreach ($alertType in $alertTypes) {
    $customObject = @{
        'data' = @{
            'type' = 'custom_object'
            'attributes' = @{
                'name' = $alertType.AlertName
                'alert_type' = $alertType.AlertType
                'event_model' = $alertType.EventModel
                'alert_subcategory' = $alertType.AlertSubcategory
                'connection' = $alertType.Connection
            }
        }
    }

    $customObjectJson = $customObject | ConvertTo-Json -Depth 10

    # Create the custom object in Zendesk
    try {
        Invoke-RestMethod -Uri $zdApiEndpoint -Headers $zdAuthHeader -Method Post -ContentType 'application/json' -Body $customObjectJson
    } catch {
        Write-Error "Error creating custom object in Zendesk: $_"
    }
}

Comments

Popular posts from this blog

Unveiling the Power of PowerShell Regions: A Comprehensive Guide

PowerShell Script to Remotely Update Firmware on Brother Printers Microsoft

PowerShell Script to Reset Permissions on all Documents in a Document Library in SharePoint Online.