Background
Since I wrote the post about vraidmon, I’ve gotten some requests for a more generic framework. Although what I’m describing here isn’t so much a framework as a simple template, some may find it useful. You can find it here.
What does it do?
In a nutshell, this template helps you with three things:
- Parsing a config file
- Simplifying metric and properties posting
- Simplifying management of parent-child relationships.
The config file
The template takes the name of a configuration file as its single argument. The file contains a list of simple name/value pairs. Here is an example:
vropshost=vrops-01.rydin.nu vropsuser=admin vropspassword=secret adapterSpecific1=bla adapterSpecific2=blabla
The vropshost, vropsuser and vropspassword are mandatory and specify the host address, username and password for connecting to vR Ops. In addition to this, adapter specific configuration items can be specified.
Writing the adapter
Using this template is very easy. Just locate the “YOUR CODE GOES HERE” marker and start coding! The only requirement is that you have to set the adapterKind and adapterName variables.
Setting the adapter type and name
The adapterKind is the “adapter kind key” for the adapter you’re building. It basically tells the system what kind of adapter you are. You can really put anything in here, but it should be descriptive to the adapter type, such as “SAPAdapter” or “CISCORouterAdapter”.
The “adapterName” is a name of this particular instance of the adapter. There could very well be multiple adapters of the same type, so a unique name is needed to tell them apart.
Posting data
Once we’ve got the adapter naming out of the way, we can start posting data. This is done through the “sendData” function. It takes 5 parameters:
- The vR Ops connection we’re using
- The resource type we’re posting for. This should uniquely specify what kind of object the data is for. E.g. “CISCORouterPort” if we’re posting data about a port.
- Resource name. This uniquely identities the object we’re posting data for, e.g. “port-4711”.
- A name-value pair list of metrics we’re posting for the resource, e.g. { “throughput”: 1234, “errors”: 55 }
- A name-value pair list of properties we’re posting e.g. { “state”: “functional”, “vendor”: “VMware” }
The sendData function returns the resource we posted data for. Note that if the resource didn’t already exist, it will be created for you.
Building relationships
Sometimes you want your monitored resources to be connected to some parent object. For example, if you are monitoring tables in a database, you may want them to be children of a database object. This way, they will show up correctly in dependency graphs in vR Ops and your users will find it easier to navigate to them.
To form a parent-child relationship, use the addChild function. It takes the following parameters:
- The vR Ops connection to use
- The adapter kind of the parent object
- The adapter name of the parent object
- The resource kind of the parent object
- The resource name of the adapter object
- The child resource to add
- (Optional) A flag determining whether parent objects should be automatically created if they don’t exist. By default, they are not automatically created and adding a child results in a no-op.
Here’s an example of an agent using this template that monitors Linux processes. As you can see, we’ve used the “addChild” function to add the Linux process objects to a Linux host.
Downloadable content
Github repository: https://github.com/prydin/vrops-py-template