Alert on VM conditions with Azure Functions and Python

  • In Azure Portal will search for Function App and select the corresponding blade
  • We will select a Resource Group, a unique App name and Python as Runtime stack. We can leave other setting as default for now and choose Review + Create
import logging

import azure.functions as func

def main(req: func.HttpRequest, outputBlob: func.Out[str]) -> func.HttpResponse:'Python HTTP trigger function processed a request.')

date = req.params.get('date')
host = req.params.get('host')
message = req.params.get('message')

if not date:
req_body = req.get_json()
except ValueError:
date = req_body.get('date')

if not host:
req_body = req.get_json()
except ValueError:
host = req_body.get('host')

if not message:
req_body = req.get_json()
except ValueError:
message = req_body.get('message')

if date and host and message:
az_output = str(date) + str(host) + str(message)
return func.HttpResponse(f"Hello, {host}. This HTTP triggered function executed successfully.")
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",

1. Implementation of Sender app

import requests
import os
import subprocess as sp

treshold = 1

used_memory = sp.getoutput("free -m | awk '/^Mem/ {print $3}'")

available_memory = sp.getoutput("free -m | awk '/^Mem/ {print $2}'")

memory_consumption = (float(used_memory) * 100/float(available_memory))

if memory_consumption > treshold:
print("Memory Usage Alert. Sending data to Storage")
output = sp. getoutput('ps aux')
data['date'] = "OvidiuBlabla"
data['host'] = "myhost"
data['message'] = output
params = {'code': 'ze7CDK1Qk_PHQFEBaM6bdgMknhM7OvPnMYtwqywVyjqI3AzIFuW0XxMQ=='}
response ='', params=params, json=data)

In params we add a dictionary with the key of “code” and the value of the content of our secret code.




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The most popular Fedora Linux in years rolls out

Using Mad Tea to Engage the Neural Network of Groups

🔥 🅗🅞🅣 | Shine Like a ! 🌠 Supernova !🏆 ICP HACKATON

How to do rapid prototyping with Flask, uWSGI, NGINX, and Docker on OpenShift

Enum Data Type in Java

CXL — CRO Minidegree Review — Week 8

How I digitally organize my online homework

Deploy Spring Boot Application in Azure through Azure CLI

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ovidiu Borlean

Ovidiu Borlean

More from Medium

Newsletter of Carlos Santana — Issue #39

Pull Images into ACR and Build Helm Chart Using ACR images and deploy applications in Kubernetes

Installation and Configuration Rancher

Backup an entire Kubernetes cluster using Velero to AWS S3