Reporting end of license on temp products with Chocolatey, Python, Telegraf and Grafana

fabien lenoir
Sep 11, 2018 · 3 min read

I must say that I try to organize myself as well as I can to facilitate the management of the software and hardware I handle, but sometimes I go through the renewal dates of the temporary licenses that we use as part of the development of our applications.

As we have just implemented the Grafana suite with Telegraf agents, I thought it would be nice to be able to automate the alerts on the end of the license.

The alert system at Grafana is quite recent and needs to be improved. For the moment, we have to go through “graphs”.

The objective is therefore to retrieve a date from a text file, to modify it to be processed in a script that will compare this date with the current date. The exit is done in the form of remaining days.

We then integrate in telegraf, a regular call to this script (a bash windows) and we retrieve the information in Telegraf with an alert if the value is less than 5 days.

The first thing to do is to configure the machine that hosts this famous software with temporary link and the telegraf agent. This is Windows 2012 r2 so we start by installing Chocolatey and then install python and create our script.

Ok let’s go ,

First of all, open CMD as admin and paste the Chocolatey install line below

then python ( here it will be Python 3.7 but you can specify a version)

You need to close and re-open CMD as admin in order to have Python avalable in your $PATH

Ok so now we need to create a Python file

Please excuse if the code is not as clean as it could be, this is subject to improvment. If you copy and paste, be careful at indentation.

So now, we have to update our ‘telegraf.conf’ file

locate the file in C:\Program Files\telegraf and add

Here i just ask telegraf to lauch the python script each 6 hours. I use powershell but it should also run on CMD.

Then restart the telegraf service

We now need to add this new data to Grafana. Add a panel and set the metrics depending on your host. Here it remains 42 days before end of license.

The create the alert when number of days is below 5

That’s it.

fabien lenoir

Written by

#Angevin délocalisé,passionné de #code, #python, etc…,

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade