Git Product home page Git Product logo

virtual-machines-python-scheduled-events-central-logging's Introduction

page_type languages products description urlFragment
sample
python
azure
The sample project demonstrates how to monitor upcoming events on multiple Virtual Machines by forwarding them to a single Event Hub.
virtual-machines-python-scheduled-events-central-logging

Collecting Scheduled Events with Event Hub

About this sample

The sample project demonstrates how to monitor upcoming events on multiple Virtual Machines by forwarding them to a single Event Hub.

Scheduled Events is one of the subservices under Azure Metadata Service that surfaces information regarding upcoming events (for example, reboot). Scheduled events give your application sufficient time to perform preventive tasks to minimize the effect of such events. Being part of the Azure Metadata Service, scheduled events are surfaced using a REST Endpoint from within the VM. The information is available via a Non-routable IP so that it is not exposed outside the VM.

However, there are cases where you wish to have a single endpoint from which you can monitor multiple VMs across one or more Azure regions. This sample, installed in each of your VMs (potentially as VM extension) monitors the Metadata endpoint and forward scheduled events to a central Event Hub.

Building the sample

  1. You will need an Event Hub created before running the sample. To do this, refer to the article Create an Event Hub through Azure Portal.

  2. Copy the connection string for your Event Hub and paste it in the configuration file. This is the 'RootManageSharedAccessKey' under Shared Access Policies.

  3. At the end of the Event Hub connection string, add ";EntityPath=[your-eventhub-name]", where your-eventhub-name is the name of the event hub that will be handling the events.

  4. This sample was tested on Python 3.5

Running the sample

You can run this sample interactively from your command prompt or shell window.

  1. Modify scheduledEventsInteractiveToolConfig.ini with your Event Hub connection string and event hub name.

  2. Run the sample from your shell

     python3 scheduledEventsInteractiveTool.py
    

    A successful run will emit some info and debug data (which you can filter out):

    2017-04-17 18:18:06,632 [DEBUG] Azure Scheduled Events Interactive Tool
    2017-04-17 18:18:06,632 [DEBUG] get_scheduled_events was called
    2017-04-17 18:18:06,639 [INFO] handle_scheduled_events was called with 0
    2017-04-17 18:18:07,816 [DEBUG] send_to_event_hub returned
    

    In case a scheduled event is detected, the sample sends a notification to Event Hub and acknowledges the scheduled event.

    myuser@mysrv:~$ python3 scheduledEventsInteractiveTool.py
    2017-04-17 18:30:35,169 [DEBUG] Azure Scheduled Events Interactive Tool
    2017-04-17 18:30:35,169 [DEBUG] get_scheduled_events was called
    2017-04-17 18:30:35,175 [INFO] handle_scheduled_events was called with 1
    2017-04-17 18:30:35,175 [INFO] EventId: 762D06A2-8289-469B-AB27-4D26C9C745B3 Type: Redeploy Status: Scheduled Resource: _mysrv
    2017-04-17 18:30:35,507 [DEBUG] send_to_event_hub returned
    2017-04-17 18:30:35,507 [INFO] THIS host is scheduled for Redeploy not before Mon,_17_Apr_2017_18:40:06_GMT
    Are you looking to acknowledge the event (y/n)? n
    
    

You can also acknowledge the event from the sample. In this case, you ask Azure to move faster with the impact.

  1. Check your Event Hub for messages. You can use Service Bus Explorer to check for the messages sent to Event Hub.

virtual-machines-python-scheduled-events-central-logging's People

Contributors

elipinkertonmicrosoft avatar mauriciomolinamicrosoft avatar v-hearya avatar zivraf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.