Create vROPS Resource Object and Custom Metrics with PowerShell

Create vROPS Resource Object and Custom Metrics with PowerShell

Create vROPS Resource Object and Custom Metrics with PowerShell

Recently we had a customer requirement where he wanted to monitor his active directory password expiry for his vRA Service Account using vROPS, unfortunately this is not part of the AD management pack with vROPS and we had to create a custom solution to attain the same.

We need to tap into the vROPS REST API to attain the same, i wont be going in details on the same as i have other blogs which detail them, please refer the below if you are getting started !.

Access Internal REST API’s in vROPS with PowerShell

First lets create the resource object which is basically the vRA service account used by vRA, we would also define the adapter kind and the resource kind for this object, for our testing we would create it as “AD” as the adapter kind and resource kind as “AD-Password” for this resource object.

We will use the XML structure as below and use the Invoke-RestMethod to invoke the REST API’s to create this resource object

Here’s the code below !

Once you execute the above REST call you would see that we get a success in the response.

Now, lets head over to vROPS and you would see the Resource object created with its resource kind and adapter type.

You will see that the icons used by the objects show up as a folder and would change if you give it some time, in my case it changed to a time bomb 🙂 lol ! .

a bigger image of the bomb!! 😀

Changing this icon is simple, head over to administration -> search for the object, in our case its “AD-Password” and change the icon type

Refresh the page again and you should see the new icon in effect.

Now as the object is created, we need to create the custom metrics under them which would hold the password age.

Before we do this we need to convert  a PowerShell/.NET DateTime to a unix timestamp (Milliseconds since 1 Jan, 1970) This is required to create JSON that can be understood by the .NET JavaScriptSerializer

The below github page contains a small function which allows you to do so

As vROPS colllects at default of 5 minutes, you can have a scheduled task which runs the powershell script to collect the AD password age, also the date using the above function and also execute the REST API to update the password age so you get live data.

Also make sure that you update the metric name and its property and value and also the units for the same (1)

Ok so lets get onto the code to get the metrics for the resource object and its values, you would see the XML has multiple metric names and values, this was just to test how it handles when we throw multiple metrics at it and values, you can delete the ones you dont need from the XML file.

Next lets head over to vROPS and see if the values are populated, and indeed we see them!!

Hope this helped you out to dig deep into creating custom vROPS resource objects and metrics and helps you to modify and create your own resource for any of the use case !.


Please follow and like us:

Share this post

Post Comment