Part 3 - Azure Logic App that downloads XMC environment logs and sends to Splunk for ingestion
In my earlier blog post, I setup a windows task scheduler that runs in an interval to pull XMC logs then sends the logs to Splunk endpoint for ingestion. In this blog post, i have utilised the same PS scripts in an Azure logic app that does the same job. The PowerShell scripts definitely need some clean-up but this is more of a PoC to showcase that Azure logic app is indeed useful for this scenario of Sitecore XMC to Splunk ingestion of log files. I also realised that Azure logic apps are limitless. Moreover I love the affordable pay-as-you-go model that Azure offers - useful for people like me, who don't spend money on other gratifications but instead use it to experiment something without depending on the company/client. I know what you are thinking, but this is poor me, no bank balance, no dog, no life :D
1. Create Azure logic app from Azure marketplace.
2. Select Workflow Service Plan.
3. Give a suitable name for the logic app and select a region that is relevant to you then click Review+create button.
5. Once resource is created, go to resource and click workflow designer to create the workflow.
6. In the workflows pane, add a Stateful workflow and click Create button.
7. Click the refresh button to see the created workflow reflect in the bottom pane.
8. Click on the workflow name in the pane to subsequently open the much-needed designer.
10. Set a suitable duration for the trigger to fire.
11. Next add an action that should recur and pick Execute Powershell Code under Inline Code category.
12. Once the inline Powershell code action is added to the designer, you can see the PowerShell code window wherein you can write your code.
13. Since write-host function is every PS developer's friend, uncomment the write-host code line to see if it first of all gets logged to Application insights but yes, after saving the workflow
15. Now, you could use the run button (from the Overview left menu) in the adjacent tab to execute the logic app workflow to see the write-host message appear in the duplicated tab' log stream.
16. In a separate window/tab, Go to Kudu via Advanced tools.17. Kudu > Debug console > CMD.
18. Now, within C:\home\site\wwwroot\ you can view the workflow artifacts including the inline PS script file.
19. Back in the designer, since logging is visible via log stream, you can now confidently modify the PowerShell inline code - connect to Sitecore XMC as first step, then pull XMC environment logs before sending to Spunk as per earlier blog post.
One of the vital changes I made in the download script was to register the nuget source for Sitecore via PS code since I did the same manually via Visual Studio nuget package manager in my local environment. I also ensured that the envlogs directory is created only when if it doesn't exist since locally, i created the envlogs and deploylogs directories manually.
Register-PackageSource -Name Sitecore -Location https://nuget.sitecore.com/resources/v3/index.json -ProviderName NuGet #equivalent for Visual Studio Package Sources nuget registration
20. You can check that PS script logging and Application Insights integrate quite well via Log stream.
21 Finally, add another Inline Code action to upload the log files to Splunk endpoint.
Comments
Post a Comment