Sorry, we found 0 results. Please try another query.
Showing max 10 of results

Visual Studio Code Extension to see the Azure DevOps Agent Status

We are using Azure DevOps / Pipelines for build and release management in our team.
I wanted to have a quick look if the hosted build agent is currently free or in use, so I have created a Visual Studio Code Extension to display the info in the status bar.

/images/2019/devops-status.gif

DOWNLOAD EXTENSION

Extension

  • To get started you create a new project with yeoman: yo code
  • The docs are really helpful.
  • There are a lot of samples for the different use cases here

The source of my extension can be found here in my GitHub repo

DevOps API

To connect to the Azure DevOps REST API you need a personal access token, which can be obtained from https://dev.azure.com/YOUR_ORG -> Your Account -> Security

/images/2019/devops-pat.jpg

The API documentation can be found here.

The specific API I wanted to use is missing in the documentation which maybe means it is not for public use (yet?). However the DevOps portal is using the same API so it works for now:

GET https://dev.azure.com/[YOUR_ORG]/_apis/distributedtask/resourceusage?parallelismTag=Private&poolIsHosted=true&includeRunningRequests=true

The parameters are important to see all the running tasks from the hosted agents. The result contains a variable usedCount with the number of currently running jobs. However to get the details who is building what you need a second call to the details API, which comes back as a result from the first call. See here:

data.runningRequests[0].owner._links.self.href

To access the REST API you have to use BASIC auth with a dummy username and the PAT (personal access token) as the password as you can see here (I’m using the request HTTP client library to call the API).

Add Azure Search Service to my blog

I was using the Google site search as as search service for this blog for a long time now. However, after I saw this article from Max Melcher where he added the Azure Search Service to his blog, I thought I should give it a try as well.

Preparation

First of all, you need an Azure Subscription. Then in the Azure Portal click Create a resource then search for Azure Search.

/images/2019/azuresearch1_orig.jpg

Configuration

My blog is static HTML generated by Hexo. It also generates a content.json file containing all posts (titles, text, publish date, tags).
This file is stored in Azure Blob Storage where the Search Service easily can index it. Just click Import data.

Here is the configuration:

/images/2019/azuresearch2_orig.jpg

You can optional add some cognitive services to extract special entities like company names or do some text analysis. After that you have to specifiy what data you want in the index:

/images/2019/azuresearch3_orig.jpg

After the indexing is complete, you can query the search service via a REST API. You can test it in the search query explorer directly from within the Aure Portal.

/images/2019/azuresearch4_orig.jpg

I’ve added some lines of Javascript to my blog to fetch the search results and here we go.

/images/2019/azuresearch5_orig.jpg

TODOs

To make it easier to find what you are looking for, I shoud add a tag filter and some date sorting.

Restore my AzureVM from Backup

I have an Azure VM for development purposes. You can read how I’ve created it here.

Ok so you know how it is setup including the backup part. Backup in Azure is awesome because it is just a few clicks away.
I’m running Windows 10 on the VM and I’ve enabled Insider Previews in the “Slow Ring”.
Not a really good idea.

A few days after the update the VM stopped booting. Here is the Boot Diagnostics screen:

/images/2018/vm-automatic-repair-failed.png

It is a VM so there is no chance to click in this screenshot. Even a reboot did not fix it.
Thankfully, I have the VM backup configured so I can go back with the OS disk before the insider preview was installed.

Restore

Here are the steps to restore the OS disk, but without touching the existing VM and the VM configuration.

  1. Create a new storage account. It will be used as a temp storage for the restored disks. It must be a Standard (not Premium) tier storage account.

  2. Go to the Backup blade and select Restore VM

/images/2018/vm-restore1_orig.jpg

  1. If you want to keep all your VM settings select Restore disks as the restore type, then select the storage account created in step 1.

/images/2018/vm-restore2_orig.jpg

  1. Wait until the disks are restored. Now you need to create a new managed disk based on the restored vhd file.
    Click “Create a new resource” and search for Managed Disk.
    Create a new managed disk within the same resource group as your VM and select Storage blob as the source type. Make sure you select the correct OS type.

/images/2018/vm-restore3_orig.jpg

  1. Now there is only one challenge left: Swap the existing disk with the restored OS disk. A walkthrough can be found in the Azure docs
$vm = Get-AzureRmVM -ResourceGroupName myResourceGroup -Name myVM 

$disk = Get-AzureRmDisk -ResourceGroupName myResourceGroup -Name newDisk

Set-AzureRmVMOSDisk -VM $vm -ManagedDiskId $disk.Id -Name $disk.Name 

Update-AzureRmVM -ResourceGroupName myResourceGroup -VM $vm

If you do not have and or you do not want to install the Azure PowerShell commandlets, you can just visit https://shell.azure.com to have a shell directly in the browser.

/images/2018/vm-restore4_orig.jpg

Ultraschall Füllstandssensor für die Regenwasser Zisterne

Warum?

Ich habe im Garten eine Regenwasser Zisterne, etwa wie diese. Das Regenwasser vom Dach wird dort gesammelt und kann dann zum Gießen, Rasensprengen, o.ä. verwendet werden.

Ich möchte nun gerne wissen wie voll die Zisterne gerade ist, und das natürlich ohne rein zu sehen.

Die Idee ist, einen Ultraschallsensor (wie er am Auto zum Einparken verwendet wird) zu nutzen.

Hardware

Für die Realisierung habe ich mir folgende Teile besorgt:

Achtung: Vor dem genannten Ultraschallsensor hatte ich zunächst diesen probiert, da er eine längere Zuleitung hat und in einem Gehäuse verpackt ist. Entgegen der Beschreibung scheint es 2 verschieden Versionen zu geben, einmal mit dem Trigger Signal und einmal als Serielle Version. Das muss man bei der Anbindung wissen.

Ich habe das ganze mit einem Raspberry gelöst, geht aber natürlich auch auch mit einem Arduino (o.ä.). Ich hatte jedoch noch einen Raspberry Pi 2 mit USB WLAN Modul rumliegen.

Zusammengebaut sieht das ganze dann so aus:

Die Dose habe ich in der Zisterne am Deckel verschraubt, so dass der Ultraschallsensor auf die Wasseroberfläche zeigt und den Abstand misst.

Software

Softwareseitig habe ich, wie bereits bei anderen Projekten, auf die bewährte Lösung gesetzt: .NET Konsolenanwendung mit mono.

Diese läuft in einem Cron Job um regelmäßig über die GPIO Ports den Ultraschallsensor zu triggern und die Entfernung zur Wasseroberfläche zu messen.
Das Ergebnis wird dann per UDP an meine Loxone Installation gesendet. Mit einem einfachen Status Baustein zeige ich den aktuellen Füllstand (derzeit nur Voll/Halbvoll/Leer) an.

/images/2018/Ultraschall3_orig.jpg

Hier verwendete Produktlinks sind Amazon Affiliate Links. Wenn du sie benutzt, hilfst du mir mehr Gadgets zu kaufen.

Create a dev machine in the cloud for daily use

I’m a software developer, so today I want to show how to create a development VM in Azure.

Create VM

Go to Azure and create an account if you do not yet have one. If you have an MSDN (aka Visual Studio) subscription log in and activate your free Azure credits right there.
Now in the Azure Portal click Create a ressource and search for Visual Studio. Now select Visual Studio Community Edition which is free or Enterprise if you have an Enterprise subscription. I’ve choosen VS on Windows 10, but you can even select VS on Windows Server 2016.
/images/2018/azurevs_orig.jpg

First you have to give it a name and select the storage type. Default is SSD which I also recommend for the best performance. Then enter a username you want to use and a password.
/images/2018/azurevs1_orig.jpg

Now you have to choose a size of your new VM. As you can see, there are a lot of options available. The estimated price would be the price if your VM is up and running 24/7 for a month. However, my dev machine will only run if I’m using it, so I can choose a bigger machine even if I have not enough credits to run this machine for an entire month. Each ressource is billed per minute which is awesome. I will go with 4 CPUs and 16GB RAM. So running this machine for one hour will cost me about 0,20 EUR.
/images/2018/azurevs2_orig.jpg

In the last step you can define networking stuff, but I will use the defaults here for now.

Auto-shutdown

Just one setting is really important: Auto-shutdown. As you can see here, I have enabled auto-shutdown and set it to 18:00. That means: Whenever you leave the office and forgot to shutdown your machine, Azure will do it for you at the specified time. You can even send notifications before shutdown which can be configured later.
/images/2018/azurevs3_orig.jpg

Networking

Now wait a few minutes until the machine is provisioned.
The next step is to set a static IP for your machine and a DNS name if you want to. Click on your VM in the portal and then Networking. There you can see your public IP. If you click it, you can define a DNS name as well and switch from dynamic to a static IP.

Disks and Backup

Now go to the Disks tab in your VM and add a new data disk. There you can store all data independently from the rest of your VMs OS disk. Also it is on another LUN so you have done everything you can for the best performance ;-)

What I’ve done now is to go to the Backup tab and configure an automatic daily backup. With this backup you can restore the VM to any day in the last 30 days. You can even restore single files on your disks. Therefore Azure mounts the disk you selected locally and you can copy single files from the disks. Awesome!

Keep in mind: Disks/Storage and Backup have it’s own price tag, so check that before configuring it.

/images/2018/azurevs6_orig.jpg

Using it

You can now Remote Desktop into the machine via the Connect button on the VM overview tab. If you have selected a static IP and DNS name you can connect using them.
Now install all your favorite dev tools within the VM. Visual Studio is already installed but needs to be updated (of course).

How to use Microsoft Flow to start and stop the VM from my mobile

First of all, go to this blog post from Søren Rasmussen. He describes how to automate startup and shutdown of Azure VMs with the help of Azure Automation Services. After you have created the so called runbooks go to the startup runbook, click Webhooks->Add Webhook


/images/2018/azurevs9_orig.jpg
Make sure you copy the webhook URL before clicking OK, because there is no way to see the URL again.
The URL looks like: https://s2events.azure-automation.net/webhooks?token=some-secret-token
Do the same for the shutdown runbook.

Create Flow buttons

Login with your account to Flow. Click on My Flows -> Create from blank.
You should see a Flow button for mobile.
/images/2018/azurevs10_orig.jpg
Then add a new action. Search for http and selet POST as the method and paste the webhook URL from your runbook.
/images/2018/azurevs11_orig.jpg

That’s it! On your mobile download the Flow app and there you can see your buttons and start your VM on the way to the office.
/images/2018/azurevs12_orig.jpg

Note: It can take a minute (on my first try it took a few more minutes) to kick of the runbook and start the VM.