How to programmatically push data in vRealize Operations Manager

Purpose:

Did you ever feel the need to push custom data to vRealize Operations Manager (vROps)? Did you wish, you could see that one parameter or metric specific to your environment in vROps? This post provides exactly that information. Here I demonstrate a script which pushes custom data into vROps. At the same time, I explained how you can customize it according to your requirement.

Introduction:

A few weeks back I got the request from two of my colleagues for friends Luciano Gomes and Iwan (e1) Rahabok about a script which can push data into vRealize Operations Manager. Both of them requested similar task albeit the data was different. So I picked Luciano's request as he already had the script which will generate the input. All I had to do is modify the script a bit so that I can consume the data in my required format and push the data to vROps.

His script generates "Creation Time" and "Hostname inside guest" for each virtual machine in an environment. He wanted to see these two values under each VM resource in vROps. So the task is defined in front of me.

Prior Work on pushing data to vRealize Operations Manager:

Understand, this is not a new topic. Very good blog posts are already available on similar topics.

But before I explain my method, please check the following excellent blogs on similar topics:

Why a new method?

If you are wondering why a new method and script?  The topic and method of these blog posts can be divided into two categories. In the first category, you have an easy way, but the method used is to push a whole new set of information, e.g, creating a new adapter, resource kind, and type. Then push custom data in this new resource.

Here, my end goal is not that. All the VM's are already present in the environment. All I need to do is push custom value into it.

In the second category, custom data is pushed to vRealize Operations Manager, but the method is direct REST API calls. Which makes the script pretty complex.

So I tried to find an easy way and hence this post and script.

What I chose and why?

I chose to create new Properties for existing resources (VM's). Since the data I am pushing is text in nature so created new Properties. If the data was of numeric in nature, then I would have chosen new stats. Based on the requirement you can chose either of them. They are detailed in the following locations:

https://<vrops server>/suite-api/docs/rest/index.html

The methods are:

  • POST /api/resources/{id}/stats
  • POST /api/resources/{id}/properties

Note, I did not create any new adapter or resourcekind or resource type. All I am doing is adding properties or stats.

Where to get it?

You can get the script by going to GitHub page (https://github.com/sajaldebnath/vrops-metric-collection)and downloading it from there.

There are samples provided with the script.

What is included:

There are two Python script files and three PowerShell script files. The Powershell scripts are used to gather the data that needs to be pushed to vROPs.

The Python files are used to process and push the data to vROps

Pre-Requisites:

These programs were written in Python2.7 and Powershell 5.0 versions.So your system should have Python 2.7 and Powershell 5.0. Also, download and install the nagini module from vRealize Operations Manager. It can be found at "https:///suite-api" . Visit the page, download and install the Python Client. Typically Windows boxes don't have Python installed in it. Download and install Python 2.7.x version on your Windows machine.

How to run:

Download all the files to the same location. The program has three parts.

Part 1: Setting up the environment:

For the first time run, Set-VCdetails.ps1 using PowerShell. You can simply open PowerShell windows and run the script with C:\ .\Set-VCdetails.ps1

This will ask you for the following information:

  • vCenter Server Name:
  • vCenter User Id:
  • Password:

Once this information is provided, it will create vcdetails.txt (contains vCenter server name and user name) and passwd.txt (contains the password in encrypted format).

Next run set-env.py file. You can run it like following:

#python set-env.py, this will ask for the following inputs:

  • Adapter Kind:
  • Resource Kind:
  • vROPs server IP/FQDN:
  • user id:
  • vROps password:

Once all the above information is provided, the script generates env.json in the same location. The provided password is saved in encrypted format.

Part 2: Getting the data from vCenter server:

Run the "Get-VMDetails.ps1" file with PowerShell cmdline. This will get values from vcdetails.txt and passwd.txt file and generate data.json file in the same location. This data.json will have the desired output values.

Part 3: Pushing the data to vROps server:

Next run data-push.py from cmdline with #python data-push.py. This will gather required information from env.json, data.json and push data to vROps server

You should schedule two jobs, one for Get-VMDetails.ps1 and another for data-push.py to run these scripts one after other.

Check the format of the data-push.json file to further utilize the data.

Points to Note:

Though this has specific use cases implemented, you should be able to easily modify the scripts to suit your need.

Acknowledgement:

Python client for vRealize Operations Manager (nagini) is not very well documented. I struggled with a particular method call as I couldn't figure out which format it expects data. Thanks to Vibhu Rastogi for arranging a call and Shankar Kommineni, thank you. You rock man. Thanks for the help and explanation.

Conclusion:

You can use the script if you want to get push custom data directly to vROps server. I did not test the script extensively. It will be a real help if you can test it out and let me know the outcome. Also, any further suggestions are welcome. I hope this helps you as it helped me. Customize it as per your requirement.