Skip to content

Instantly share code, notes, and snippets.

@joelwiesmann
Last active December 11, 2017 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelwiesmann/e6246f5e5b87e41dc53cc087da5b3ca5 to your computer and use it in GitHub Desktop.
Save joelwiesmann/e6246f5e5b87e41dc53cc087da5b3ca5 to your computer and use it in GitHub Desktop.
EDDA / IA Automic Integration in Powershell
# Backend API key required to create new application keys (C:\Automic\External.Resources\apache-tomcat-7.0.81\webapps\awi\config\webui-plugin-analytics\plugin.properties).
$backend_api_key = '02c13da1-1cf3-4424-8b13-4468fdae9c88'
# REST URL
$backend_rest_url = 'http://localhost:8090'
# Application-key metadata
$backend_key_body = @{
'scope' = 'EVENTS'
'description' = 'key for IA experiments.'
'client' = 1000
}
# Where to store the created app key
$backend_keystore = ($env:USERPROFILE + '\aeApp.key')
if (Get-ChildItem $backend_keystore -ErrorAction SilentlyContinue) {
throw('Key file ' + $backend_keystore + ' does already exist.')
}
# Create Application-Key (one-time)
try {
$myKey = Invoke-RestMethod -Headers @{'Authorization' = $backend_api_key} `
-Uri ($backend_rest_url + '/analytics/api/v1/apikeys') `
-Body (ConvertTo-Json $backend_key_body) `
-Method Post `
-ContentType 'Application/JSON'
}
catch {
Write-Error ('Could not get application key. Please check your configuration: ' + $_)
}
Write-Host ('New application key: ' + $myKey.key + ' will be stored in ' + $backend_keystore)
$myKey > $backend_keystore
# Where get the app key from (created with edda_createkey.ps1)
$backend_keystore = ($env:USERPROFILE + '\aeApp.key')
# REST URL
$backend_rest_url = 'http://localhost:8090'
# Define event
$event_body = @{
# Type must be equal to event definition vara name
'type' = 'SIMPLE_EVENT#VA'
# Based on what Brendan wrote, this is required but not used. So just leave it as it is and you should be fine.
'timestamp' = [datetime]::now.ToString('yyyy-MM-ddTHH:mm:ssZ')
# Stuff that the event can process.
'values' = @{
'text' = 'Some String.'
'random_number' = 12
'crap' = 'Might not be of interest.'
}
}
# Get the App key from the keystore or die tryin'.
$backend_app_key = (Get-Content $backend_keystore -ErrorAction Stop)
# Send event to the IA system
try {
$myevent = Invoke-RestMethod -Headers @{'Authorization' = $backend_app_key} `
-Uri ($backend_rest_url + '/analytics/api/v1/events') `
-Body (ConvertTo-Json $event_body -Depth 2) `
-Method Post `
-ContentType 'Application/JSON'
}
catch {
write-error ('Sending event to AE failed: ' + $_)
}
# Yet this is fire & forget. We do not know if any AE-event was active that processed out REST call.
write-host '* Event sent to the AE.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment