create programmatically application insights alert with webhook - webhooks

We start to have a bunch of manually created alerts and for consistency I would like to maintain them with script preventing human errors.
There are different approaches which are perfect such powershell
https://learn.microsoft.com/en-us/azure/application-insights/app-insights-powershell-alerts
or template approach.
however, something is missing, the ability to set up webhook with these approaches
I had a look into json schema but action only supports sendToServiceOwners and/or customEmails
(http://schema.management.azure.com/schemas/2014-04-01/Microsoft.Insights.json)
I searched if a newer schema version exists (schema : 2014, webhook functionality : 2015), but with no luck https://github.com/Azure/azure-resource-manager-schemas/search?utf8=%E2%9C%93&q=Microsoft.Insights.json&type=Code
any suggestion ?

The initial powershell article was already a little bit outdated (not the article itself). focusing on AzureRM API I was able to find this article : https://learn.microsoft.com/en-us/azure/monitoring-and-diagnostics/insights-powershell-samples
which give an example on 2 steps with
$actionWebhook = New-AzureRmAlertRuleWebhook -ServiceUri https://example.com?token=mytoken
and
Add-AzureRmMetricAlertRule -Name vmcpu_gt_1 -Location "East US" -ResourceGroup myrg1 -TargetResourceId /subscriptions/s1/resourceGroups/myrg1/providers/Microsoft.ClassicCompute/virtualMachines/my_vm1 -MetricName "Percentage CPU" -Operator GreaterThan -Threshold 1 -WindowSize 00:05:00 -TimeAggregationOperator Average -Actions $actionEmail, $actionWebhook -Description "alert on CPU > 1%"

Related

Can Custom Action Buttons run javascript in handler? Sharepoint add-in

I created a Custom Action Ribbon button for sharepoint online and i want to run a javascript code when the button is clicked.
Sharepoint documentation even provides an example of it: https://learn.microsoft.com/en-us/sharepoint/dev/schema/commanduihandler-element?redirectedfrom=MSDN#example
but when i'm trying it always returns an error Custom action urls must start with "http:", "https:", "~appWebUrl" or "~remoteAppUrl".
Another part of the documentation says that it is not possible https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/sharepoint-add-ins-ux-design-guidelines?redirectedfrom=MSDN#figure-4-a-custom-action-in-the-contextual-menu
So how do i make it work? is not possible anymore and only can do redirections?
or it deppends of the location? i have it defined as <CommandUIDefinition Location="Ribbon.Documents.Actions.Controls._children"> so it is displayed in the command bar.
is it possible? ... I suppose no
Unfortunately it is not possible to add a custom ribbon action with a javascript logic with a provider hosted add-in 🤔. I think the articles/links where you found it is possible refer to the Server ribbon xml custom action that could be modified using sandbox solutions (like the old school SharePoint days 😊), but now the sandbox is rather not supported in SP online.
For the Ribbon custom actions that are added with the add-in you should specify the direct link. This is already what needs to be specified when we add a Ribbon action in VS to the Add-in project (we should specify were we navigate to)
I also found this MSDN article (quite up to date - from 2020) where we may find:
CustomAction cannot contain JavaScript: Any UrlActions or CommandActions must be a URL to navigate to. (...)
So I am like 95% sure it should 😉 not be possible... but I leave the 5% as I am not like an SP PRO (I think it is hard to be one as it is like sooooo much to know 😋)
possible solution you might take
What you might do is to add the custom Ribbion xml using PowerShell and attach any javascript logic to it also using PowerShell 😋. The only drawback is that the javascript file needs to be also somehow added to the page (like it could be stored in the SiteAssets library).
So to do that we need to:
create an xml file locally with our Ribbon command button like:
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.Library.ViewFormat.Controls._children">
<Button Id="Ribbon.Library.ViewFormat.About"
Command="TestButton"
LabelText="Test"
Image32by32="{SiteUrl}/_layouts/15/1033/Images/formatmap32x32.png?rev=23"
Image32by32Top="-273"
Image32by32Left="-1"
Description="Test"
TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="TestButton"
CommandAction="javascript:test({SelectedItemId});"
EnabledScript="javascript:checkOneItemSelected();" />
</CommandUIHandlers>
</CommandUIExtension>
the output of the above will be a button like this
Next create a js file (also locally) with functions for the CommandAction and EnabledScript (so we need a test() function and checkOneItemSelected()). So the contents like
function test(itemId) {
alert(itemId);
}
function checkOneItemSelected() {
return (SP.ListOperation.Selection.getSelectedItems().length == 1)
}
... so locally I have two files
Now we need to connect to the site we want to add the Ribbon button using PowerShell (best would be to use PnP Powershell 👍)
connect to site using Connect-PnPOnline -Url <SiteUrl>
now lets add the JS local file to the site assets library like Add-PnPFile -Path .\customJS.js -Folder "SiteAssets"
so the output is (the file in the library)
now lets add the Ribbon button to the site (using xml) like
$ribbon = Get-Content .\CustomRibbonButton.xml
$ribbon = [string]$ribbon
Add-PnPCustomAction -Name "RibbonTester" -Title "RibbonTester" -Description "-" -Group "Tester" -Location "CommandUI.Ribbon" -CommandUIExtension $ribbon -RegistrationType ContentType -RegistrationId 0x0101
so the output of the above will be our button in the ribbon (also we need to turn on classic UI /off modern UI, to see the ribbon 😉)
now lets attach our JS to the button like Add-PnPJavaScriptLink -Name "AboutButtonScript" -Url https://tenanttocheck.sharepoint.com/sites/ClassicDeveloperSite/SiteAssets/customJS.js -Scope Web please be aware the change url to your tenant😉
and the output is like
did you consider🤔
Also did you consider to use spfx extensions and modern UI to be more up to date? In extensions you may use JS and maybe do some http request to some endpoint you want to target with the ids array (but this is only a suggestion)
hope my post will be of any help 👍
BR

Azure Event Hub : Create Logger - 400 Invalid Hostname

I am trying to create a proof of concept with Azure APIM and am stuck at a 400 invalid hostname error.
I have tried following this example
https://learn.microsoft.com/en-gb/azure/api-management/api-management-howto-log-event-hubs
which leads me to this page
https://learn.microsoft.com/en-us/rest/api/apimanagement/2019-12-01/logger/createorupdate
I have in postman the put command with the following url, edited out the personal details
https://management.azure.com/subscriptions/xxxxx-yyyy-zzz-a4ed-b0b5ddddddd/resourceGroups/xx-Trial/providers/Microsoft.ApiManagement/service/xxx-API-Management-Services/loggers/loggerId?api-version=2019-12-01
This is being sent as a PUT command
This is the body that is also being sent
{
"type": "AzureEventHub",
"description": "xx Poc description",
"credentials": {
"name": "apim",
"connectionString": "Endpoint=sb://xx-poc.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=yyyyyyK/ixxxxxxxxxxxxxxc="
}
}
The response that comes back is
<h2>Bad Request - Invalid Hostname</h2>
<hr>
<p>HTTP Error 400. The request hostname is invalid.</p>
I would be grateful if anyone can help me progress this forward as I cannot see what I have missed.
Thanks
After hours of searching I finally stumbled across this url https://www.svenmalvik.com/azure-apim-with-eventhub/ which has resolve my issue.
I had done everything right in terms of setup, but this was the final step that was missing
$apimCtx = New-AzApiManagementContext -ResourceGroupName "xx-Trial" -ServiceName "xx-API-Management-Services"
$ehConnection = (Get-AzEventHubKey -ResourceGroupName "xx-Trial" -NamespaceName "xx-yyy-zzz-eh-ns" -AuthorizationRuleName "xx-yyy-zzz-eh-auth-rule").PrimaryConnectionString
New-AzApiManagementLogger -Context $apimCtx -LoggerId "simon-logger" -Name "simon-logger" -ConnectionString "$ehConnection;EntityPath=xx-yyy-eh"
I believe there'are something wrong with the request body.
{
"type": "AzureEventHub",
"description": "xx Poc description",
"credentials": {
"name": "apim",
"connectionString": "Endpoint=sb://xx-poc.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=yyyyyyK/ixxxxxxxxxxxxxxc="
}
}
Please check the following settings in your request body:
For name, please make sure it's the Event hub instance name, not the Eventhub namespace name. And you can refer to this doc for more details about them.
For connectionString, please make sure it's the Eventhub namespace connectiong string(do not use the Eventhub instance level connection string). For more details, please refer to this doc.
At the end, please also check if the eventhub instance is disabled or not.

Empty "Parsed-HTML" field on using "invoke-webrequest" in Azure Powershell Runbook

I am trying to make a rest API call using "invoke-webrequest" in azure powershell runbook.
At first, I got the error message regarding the Internet Explorer Engine. When I searched about it, I found that using **-UseBasicParsing** would solve the problem. However, after using it, I am not facing the error message anymore but I am getting empty "**Parsed-Html**".
The code is running fine when I am running it locally.
$result = invoke-webrequest -uri $url -Headers $Header -UseBasicParsing
I expect the output of Parsed-Html to be an object, but it is null.
In Automation, when we use cmdlet Invoke-WebRequest we need to use the–UseBasicParsing option as we do not have the Internet Explorer in Azure Automation sandboxes.
In this scenario you should use **HtmlAgilityPack**. Upload the **HtmlAgilityPack.dll** as module and use command "add-type -Path .\HtmlAgilityPack.dll " in runbook to generate the **HtmlDocument**
Code would look something like below:
$URI = "https://www.google.fr/search?q=googe&rlz=1C1CHBF_frFR711FR711&oq=googe&aqs=chrome..69i57j69i60l5.912j0j7&sourceid=chrome&ie=UTF-8#q=google"
$wc = New-Object System.Net.WebClient
$htmlString=$wc.DownloadString($URI)
cd C:\Modules\User\HtmlAgilityPack
add-type -Path .\HtmlAgilityPack.dll
$doc = New-Object HtmlAgilityPack.HtmlDocument
$doc.LoadHtml($htmlString)
$root= $doc.DocumentNode
$root.SelectSingleNode("//head/title").Innertext
You can check this link for further reference.
Hope it helps.

SharePoint Quick Launch not opening

I want to edit a link on the left side of a SharePoint 2013 Standard site. Clicking on Edit Links and changing the link to a desired site and then saving shows error "This operation has timed out. Please try again." and clicking on Quick launch keeps spinning. I have full access to the site.
What could be the cause ?
did You consider using PowerShell as a workaround solution? If something in SharePoint that is OOB and does not work I always consider PS to fix something :).
For Your case something like this may do the trick (example to delete and update):
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$SPWeb = Get-SPWeb "[URL]";
$QuickLaunch = $SPWeb.Navigation.QuickLaunch;
foreach($item in $QuickLaunch)
{
$item.Title;
if($item.Title -eq '[quickLunchItemTitleToDelete]')
{
$SPWeb.Navigation.GetNodeById($item.Id).Delete();
}
if($item.Title -eq '[quickLunchItemTitleToModify]')
{
$item.Title = "[NewName]";
$item.Update();
}
}
also I saw You have in site settings link to Quick Lunch. But You may turn on a feature in web to get the more advanced 'Navigation' link and maybe from there You will be able to modify the link You need.
Go to Site settings > Under Site collection admin > Site collection
features
Click Activate in-front of SharePoint Server Publishing
Infrastructure
BUT please be aware that turning on this feature will add also other components to Your which may be not desired.
I hope this will be of any help to You :)

PDF File not opening in browser for sharepoint 2010

Recently we have moved our web application from one server to another in Sharepoint 2010. Back up of entire web application was taken and restored in another server. But in the new server , the PDF files in the document library is not getting opened in browser. it always open in browser
I have already made following changes but didn,t work
Set browser file handling to Permissive from central admin
Set "open in browser" in setting s of doc library
Set the doc library file handling property using
$docLib = $web.lists["Your Document Library Title"]
$docLib.BrowserFileHandling = "Permissive"
$docLib.Update()
Added "AllowedInlineDownloadedMimeType.Add("Application/Pdf") in web app
Installed Adober eader in client machine
Even after trying all these, the PDF files are still opening in Client application(Adobe reader) but not in the browser
It would have been great help if anybody provide a solution for this. I have been banging head on this for two days
Regards
Vishnu
You need to add the MIME type to SharePoint 2010 to enable this - and it needs to be done at Farm level.
The powershell on here will do it; (I've not run it, but it is Technet so source should be good)
# <#
# .DESCRIPTION
#
# This script adds new MIME type to "AllowedInlineDownloadedMimeTypes" property list of defined SharePoint 2010 Web Application.
#
# Script prompts you for MIME type and Web Application URL.
#
# Code shall run in context of Farm Administrators group member.
#
# .NOTES
# File Name : Add_MIME_Type.ps1
# Author : Kamil Jurik, WBI Systems a.s.
# Created : 11/12/2011
#
If ( (Get-PSSnapin -Name "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null ) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
Get-SPWebApplication
$WebApp = Get-SPWebApplication $(Read-Host "`nEnter Web Application URL")
Write-Host `n"Mime Type Examples:"`n"application/pdf, text/html, text/xml"`n
If ($WebApp.AllowedInlineDownloadedMimeTypes -notcontains ($MimeType = Read-Host "Enter a required mime type"))
{
Write-Host -ForegroundColor White `n"Adding" $MimeType "MIME Type to defined Web Application"$WebApp.url
$WebApp.AllowedInlineDownloadedMimeTypes.Add($MimeType)
$WebApp.Update()
Write-Host -ForegroundColor Green `n"The" $MimeType "MIME type has been successfully added."
} Else {
Write-Host -ForegroundColor Red `n"The" $MimeType "MIME type has already been added."
}
You can set the Browse file handling property to permissive
http://technet.microsoft.com/en-us/library/cc262107(v=office.14).aspx

Resources