vRealize Operation and Telegram integration! – Get alerts on your mobile!

As you know, vROps is a great tool for monitoring the virtual environment, but it can also monitor the health of our hardware. vRealize Operation creates alerts and displays them with details, but to see them, we need to log in to vROps. What if you could get such alerts on your mobile phone?

Today I will show you how to integrate vROps with Telegram to be able to receive alerts on a mobile phone using the Telegram application.

What do we need:

  • Telegram
  • Bot
  • REST API call for Telegram
  • vRealize Operation

Let’s create a new Telegram bot:

To create a bot in Telegram, we need to talk to BotFather. If you’ve never spoken to @BotFather before, just open your contacts and search for it.

Start the conversation with the command:

/start

This command will display all available options. We are interested in the option of creating a new bot. Issue the following command:

/newbot

Now you need to give a bot name and bot user name. If the username is taken already, BotFater will inform you about this and you will need to provide the new username:

After this, the BotFather will display information about your new bot. The most important part of that information is the token to access HTTP API. Keep your token secure and store it safely, it can be used by anyone to control your bot.

Next step in order to use your new bot to send messages you’ll need to add your bot as a group member to the designated Telegram group/chat. I created a group called vROps_Alerts and added my bot to the group. Once this is done, grab the group ID from the URL (including the minus “-” sign) and note it somewhere. In this example, my group ID is -717272464

This is the Telegram API call for sending messages:

https://api.telegram.org/bot$token/sendMessage?chat_id=$chat&text=Hello+World

To send messages to our group you need to modify the API. You need to bot token after /bot and chat ID after chat_id= for example:

https://api.telegram.org/bot655790190:AAEtNozH7-am3rOINAIhzmWq8VJjSKhjQK4/sendMessage?chat_id=-717272464

The POST content looks like this :

{
  "text": "my message"
}

Add new vROps outbound instance

In vROps go to: Configure -> Alerts -> Outbound Settings.

  • Click add.
  • Pick Webhook Notification Plugin from Plugin Type.
  • In Url: field paste Telegram API with your bot token and chat ID.

NOTE: There is no username or password as API contains all the necessary credentials to send a message.

NOTE: Once you test the connection, you will receive an error message, however, you can ignore it.

To confirm the connection is working, add &text=Hello+World on the end of the API URL and test again:

You will see the Hello World message also on the Telegram channel.

Now, remove &text=Hello+World and click on SAVE. Again ignore the error message and proceed anyway.

Creating vROps Payload Template

In the payload, we can define what we would like to send. There are three sections we can customize:

  • Details:
    • Contain the name, description, and the Outbound Method we would like to use for our payload. In this example, we are going to pick Webhook Notification Plugin.
  • Object Content:
    • This is a very important section, where you can decide what metrics and properties would you like to send in the payload.
  • Payload Details:
    • Specifies the actual REST call, like method or content type, and describes the body of the call as required by the receiving instance. There are also predefined metrics and properties we can use.

Let’s create a payload:

  • Go to Alerts -> Payload Templates.
  • Click on ADD.
  • Type name for payload template.
  • Type description.
  • Pick Outbound method – > Webhook Notification Plugin.
  • Click NEXT on the bottom of the site.
  • In the Object Content select metrics and properties.
    • In my example, I decided to monitor Datastore.
  • Click NEXT on the bottom of the site.
  • In Payload Details set:
    • Content type -> application/json
    • HTTP Method -> POST
    • Payload of the request is JSON formatted. For example :
{
    "text": "${ALERT_DEFINITION}: ${RESOURCE_NAME}: Available GB: ${VMWARE|Datastore|capacity|available_space}: Used in %: ${VMWARE|Datastore|capacity|usedSpacePct}: Snapshots Space used: ${VMWARE|Datastore|diskspace|snapshot}"
}

NOTE: You can set up different payload details for new, updated, and canceled alerts.

Set up vROps Notification

Now is the time to set up a notification. Go to Alerts -> Notifications. There are four sections here:

  • Notification:
    • Give notification a name and enable it
  • Define Criteria:
    • This section is huge. You can specify when the notification should be triggered.
  • Set Outbound Method:
    •  Here you define the Outbound Method (Webhook Notification Plugin) and the Outbound Instance we created for Telegram.
  • Select Payload Template:
    • You can select a payload template to use.

In the Define Criteria, I selected Object Type -> datastore.

As the outbound method, I selected Webhook Notification Plugin and the outbound instance we created:

And as the last step I selected our template:

Once the alert on the datastore will be triggered, we will receive the message. One word of explanation. On the screenshot and on my video you can see that message is displayed in curly brackets {}. This is due to my error. I configured JSON output without keyword “text”

However, if you followed this article, where JSON is correct, you will receive this nice output:

Please like and share to spread the knowledge in the community.

 

If you want to chat with me please use Twitter: @AngrySysOps

Join my  VMware Knowledge Base Group: https://bit.ly/3w54tbc

Visit my FB page: https://www.facebook.com/AngrySysOps

Read my blog: https://angrysysops.com

Subscribe to my channel: https://bit.ly/3vY16CT

VMWare goodies, grab your own version of VMware Workstation!  


Please leave the comment