CloudException: Please register the subscription with Microsoft.Insights

While trying to connect Azure Automation and log Analytics I came across this error:

CloudException: Please register the subscription {your sub ID} with Microsoft.Insights

Message is clear, but how do I do this?? Took me a while to figure out.

  1. In your Azure portal head to your Subscriptions, pick the required subscription
  2. Inside of a subscription pick “Resource providers” – you’ll be presented with a list of providers.
  3. From the list of providers pick microsoft.insights and click Register.
  4. This fixed my problem

Protect your your Azure Resources from accidental deletion

Last week I’ve messed up a big time. I was doing Azure Storage Account migrations via a PowerShell script, part of that script was deletion of old resource group. That group was meant to be empty every time because I was moving resources out of it.

At one point script threw exception and last storage account was not moved out of the resource group, but last line of the script was to delete that resource group. And it deleted the storage account. OOOOPSSS!

We had backups of data, but that accident made us think twice about our practices. So as part of a response to that accident we decided to use RM locks on all resources.

Azure Resource Management allows to lock subscription, resource group or individual resource to prevent users from accidentally deleting critical resources. Locks can be CanNotDelete or ReadOnly. Read more about locks in official documentation. If you put a subscription lock it covers all resources and groups within this subscription, but for our purposes this was too generic – you remove a lock and all of your resources are open for accidental deletion. So I settle on adding locks per Resource Group.

Continue reading

Amazon Alexa. First impressions

Recently I purchased Amazon Alexa, just for fun. Initially wife wanted a radio or a Bluetooth speaker on kitchen. And Alexa was cheap enough to use as a speaker/radio.

On the first day I’ve asked it a bunch of questions and got a lot of rather disappointing “hm.. I don’t know that one”. Yeah, sure it can tell me weather and news briefing. Kitchen timer is rather useful (unless it mishears you and resets it instead of pausing).

I’ve tried a bunch of skills and none of them were particularly good/useful. Idea was to get a cook-book, but nothing descent was available (there are Allrecipies, but not available in UK).

And for listening to a music – that’s another disappointment. Turns out that all my MP3s I’ve collected over the years are worthless here. To be able to listen to a music I need to purchase one of the streaming services (Amazon Music or Spotify). But I want my music, not streamed. I’ve wasted a lot of time searching for solution. There were a few options. There is Synology (of which I’m an owner) skill, but that’s been only released in October 2017 and not yet available. There is Plex server, but the this skill does not let me stream music through Alexa – it is a merely voice remote control for other existing player.

I’ve seen a lot of developers telling their way of enabling Alexa to stream their music, but none of it was ever approved to Alexa skills market (why would Amazon allow for that? they sell music service!). And to get that working, involved a lot of work that I did not want to do.

Another thing that I did not like was a way of activating the skills – I had to call it by name and ask for the exact specific command: i.e. Alexa, tell Hive to boost heating to 21 degrees. That’s rather a mouthful. Given I does not always work from the first time, I can turn on my heating on my phone faster. I’d much rather prefer Alexa, boost heating, but that did not always work. Same goes for other skills: Alexa, ask Radioplayer to suggest a station or Alexa, ask [skillname] to do [command-name].
Well, yes, I understand that we are dealing with computers here where precise commands are required, but the last thing I want to remember is that silly skillname to get myself some radio. Granted, there is a built-in TuneIn online radio with hundreds of radios to choose from – problem here to remember (or rather know) the station name I’d like to listen to.

Also I was hoping for advertised shopping list and to-do list to be voice-activated. But my preferred service Wunderlist was supported as a second-class citizen and to add items to my Groceries list I had to go like Alexa, tell Wunder Link to add eggs to my Groceries list. I was hoping for Alexa, add eggs to my shopping list but that is not available. However Todoist.com had a better integration, but I’m not sure I like it better. I grew fond of Wunderlist simplicity and bells-and-whistles of Todoist are overkill for my simple lists.

Anyway, that device turned out to be not that useful as I was hoping it to be.

Here are useful stuff for myself (your mileage may vary):

  • Kitchen timer (rather expensive one)
  • Bluetooth speaker (again, on the expensive side)
  • Online radio (if you know stations names you like)
  • Hive heating control (somewhat flaky)

Disappointments:

  • Unable to play my music without buying a service subscription
  • Voice commands have to be in certain format and having to remember application names and exact format expected is a pain
  • Not clever at all when answering non-wiki questions

So now I’m pondering should I try and build a skill for Alexa (and what should it be?) or just send it back to Amazon?

GitVersion vs dotnet pack on VSTS

Last night I run into a problem with GitVersion and dotnet pack command while running my builds on VSTS

The probem came up when I tried to specify a version number I’d like the package to have. There are answers on SO telling me how to do it and I’ve used it in the past. But this time it did not work for some reason, so I had to investigate.

Here is the way it worked for me.
To begin, edit your *.csproj file and make sure your package information is there:

<PropertyGroup>
    <OutputType>Library</OutputType>
    <PackageId>MyPackageNaem</PackageId>
    <Authors>AuthorName</Authors>
    <Description>Some description</Description>
    <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
    <PackageReleaseNotes>This is a first release</PackageReleaseNotes>
    <Copyright>Copyright 2017 (c) Trailmax. All rights reserved.</Copyright>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

Continue reading

PC wakes up at night

Microsoft has a strange idea that anybody would want their PC to be woken up during the night to do the maintenance task. WHY???

All my PCs have encrypted drives and password is required for windows to boot. So even if PC manages to wake itself up – it is stuck on password prompt. DUH!

Way to check it:

powercfg -waketimers

If you see Reason: Windows will execute 'Maintenance Activator' scheduled task that requested waking the computer.

Head to Control Panel -> Security and Maintenance -> Expand Maintenance. There will be an option to disable waking your PC for Maintenance.

And here is another discussion with some answers, though people do report that Windows 10 is notoriously bad for ignoring any/all of these settings and you will still get your PC woken up at night, barring all but unplugging it from the mains

And another discussion with a lot of details.

User impersonation in Asp.Net Core

I’ve blogged about user impersonation in Asp.Net MVC three years ago and this article has been in top 10 of most visited pages in my blog.

Since Asp.Net Core is out and more or less ready for production, it is time to review the article and give guidance how to do the same thing in Core. Approach have not changed at all, we do same steps as before, only some API been changed and it took me a bit of time to figure out all the updated API parts.

Impersonation Process

Impersonation is when an admin user is logged in with the same privileges as a user, but without knowing their password or other credentials. I’ve used this in couple applications and it was invaluable for support cases and debugging user permissions.

The process of impersonation in Asp.Net core is pretty simple – we create cookie for potential user and give this to the current admin user. Also we need to add some information to the cookie that impersonation is happening and give admin a way to go back to their own account without having to log-in again.

Continue reading

General Rules When Building OSS Libraries

In the last couple years I’ve built a few libraries for public and internal consumption. Mostly these have been internal things, but they are not much different from OSS libraries.

So far the most popular libarary I’ve released open-sourced is Cake.SqlServer but I’m mostly proud of NSaga though it is not as used, mostly due to lack of marketing effort on my part. Both of these are still on v1.x though these are young libraries – both under 1 year of age at the moment of writing.

In a sense libraries for internal consumption are easier to build – you can break things and then fix the broken things in the downstream projects (or tell people how to fix). If your library is publicly released you need to be much more careful in how you handle breaking changes and how you define your public API surface. Semantic versioning is supposed to help you manage the breaking changes, but you still need to minimise the possibilities of breaking things for other people. If you are not careful and break a lot of stuff, people will be pissed off and eventually move away from your library.

While building OSS libraries I had to excersise a lot of care to cater for wider audience and rules I draw below are mostly coming from OSS. So here they are:

.Net Framework Versions

You need to consider what framework version you build for. Nature of .Net framework – every version is an increment on the previous, so library built for v4.5 will work in v4.6.1. But not the other way. So you need to pick the lowest version of .Net you’d like to work with and stick with it. I think it is fare to say that no currently developed project should be below v4.5. There is no reason to stay on lower version and upgrade from v3.5 is relatively painful. So my rule of thumb is to target v4.5 as a baseline, unless I need framework features that are only available in later versions.

Continue reading

Another reason not to use TFS

TFS source control system has got some strange meaning of “Workspace”. I’ve run into this numerous times and tonight again. This time I’m trying to migrate a project from TFS into git and keep the project name intact. So I’ve renamed my old project in VSTS to be ProjectName.TFS. And created a new one called ProjectName. But was faced with this great error:

The Team Project name ProjectName was previously used and there are still TFVC workspaces referring to this name. Before you can use this name, the owner of each workspace should execute the Get command to update their workspaces. See renaming a team project for more details (https://go.microsoft.com/fwlinkip?Linkld=528893). Found 2 workspace(s) using this name: ws_1_1;b03e2eb0-22aa-1122-b692-30097a2fa824, ws_dd5f57e41;b2345678-98a0-4f29-13692-30097a2fa824

Well, yes. Thanks for letting me know that this project name was used before. And I obviously don’t care about these workspaces – the PC where these were used no longer exist.

Following the link I was advised to execute this command to delete the dead workspaces:

tf workspace /delete [/collection:TeamProjectCollectionUrl] workspacename[;workspaceowner]

Yeah, no problem. Only it took me a while to find tf.exe. It is in the most obvious place in VS2017:

c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\

And WTF is TeamProjectCollectionUrl? and what about workspacename[;workspaceowner]? took me a while to figure out the correct format expected. Here what worked for me:

.\tf workspace /delete /collection:mycompanyname.visualstudio.com\DefaultCollection “ws_1_1;b03e2eb0-22aa-1122-b692-30097a2fa824”

The last bit is coming from the error message in VSTS: ws_1_1;b03e2eb0-22aa-1122-b692-30097a2fa824, ws_dd5f57e41;b2345678-98a0-4f29-13692-30097a2fa824 Name from the owner is separated by ; and different namespaces are separated by ,.

All that bloody obvious!

Publish Core XUnit Test Results in VSTS

Following my previous post, I’m building Asp.Net Core web application and I’m running my tests in XUnit. Default VSTS template for Asp.Net Core application runs the tests but it does not publish any results of test execution, so going into Tests results panel can be sad:

And even if you have a task that publishes test results after dotnet test, you will not get far.

As it turns out command dotnet test does not publish any xml files with tests execution results. That was a puzzle for me.

Luckily there were good instructions on XUnit page that explained how to do XUnit with Dotnet Core properly. In *test.csproj file you need to add basically the following stuff:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="xunit" Version="2.3.0-beta2-build3683" />
    <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta2-build3683" />
  </ItemGroup>

</Project>

Continue reading

VSTS Private NuGet Feed and Building Dotnet Core Application

Honestly, VSTS private NuGet feeds will be a most blogged topic in this blog! I’ve already mentioned them at least twice. Here goes another post:

This time I’m building in VSTS Core application and the build literally goes:

  • dotnet restore
  • dotnet build
  • dotnet test
  • dotnet publish

And this worked really well for the basic application – I had it set up in minutes and got the resuilt I was looking for.

But during the life of the application I needed NuGet packages from my private feed and dotnet restore had no idea about my private feeds.

Even if supplied with nuget.config file I was getting 401 Unauthenticated – this is because I was not keeping my password(token) in this file.

Solution was to add this feed globally on the agent for every build. And this turned out to be easier than I thought.

In your build add a new task called Nuget Command:

Continue reading