![]() |
![]() |
Subject: | Example of zenpacklib |
Author: | [Not Specified] |
Posted: | 2016-02-17 09:17 |
Can anyone point me to a ZenPack that uses zenpacklib and has multiple relations. I would like to see the zenpack.yaml and modelers files to see the syntax since the doc only show 1 relation and I need to figure out syntax for multiple relations.
Thanks
Manuel
Subject: | In http://zenpacklib.zenoss |
Author: | [Not Specified] |
Posted: | 2016-02-18 15:46 |
In http://zenpacklib.zenoss.com/en/latest/yaml-classes-and-relationships.html, there are examples of one-to-many (1:M or 1:MC) and many-to-many (M:M) relationships.
Subject: | Sorry for the lack of |
Author: | Chet Luther |
Posted: | 2016-02-18 16:12 |
Sorry for the lack of indentation and formatting on the code snippets. I can't figure out how to get them formatted properly.
First some background. Setting the relname and modname properties on the modeler plugin class, then using the self.relMap() and self.objectMap() methods within your modeler plugin are shortcuts that only work when a modeler plugin is modeling a single relationship. So you won't see relname or modname being set on the class, or the self.relMap() and self.objectMap() methods being called for modeler plugins that model more than one relationship.
The first thing to understand is what the allowable return values for a modeler plugin's process() method are.
None
None is special. It means, "don't change anything in the model." This is very different than returning a RelationshipMap with no ObjectMaps within. Returning an empty RelationshipMap will remove all components from that relationship. Returning None will cause nothing to happen. It's good to return None when your modeled plugin detects that it's failed to retrieve good data. Better to do nothing than to remove things that shouldn't be removed.
ObjectMap
A single "bare" ObjectMap can be returned to update properties on the device being modeled. Properties will only be changed if their current value is not the same as what's in the ObjectMap. Properties for which a corresponding key in the ObjectMap doesn't exist will not be changed. A "bare" ObjectMap intended to be applied to the device must not have an "id" key. For example..
return ObjectMap(data={
'snmpContact': 'Joe',
})
RelationshipMap
A single "bare"RelationshipMap can be returned to update a relationship. Any existing components that don't have a corresponding ObjectMap within the RelationshipMap will be removed. Any ObjectMaps within the RelationshipMap that don't have a corresponding component in the model will be created. Any components that have a corresponding ObjectMap within the RelationshipMap will be updated according to the rules of ObjectMap above. Every ObjectMap within a RelationshipMap must have an "id" key. For example..
return RelationshipMap(
relname="myThings",
objmaps=[
ObjectMap(
modname='ZenPacks.example.MyPack.MyThing',
data={
'id': self.prepId('value-unique-among-all-components-on-this-device'),
'myproperty': 'a-value-for-it',
}),
])
List of Maps: [ObjectMap(...), RelationshipMap(...), RelationshipMap(...)]
A list of maps is how multiple relationships can modeled by a single modeler plugin. In the example above you see a bare ObjectMap and two RelationshipMaps being returned. This would update some properties on the device, and two different relationships.
You'll need to import ObjectMap and RelationshipMap to use them in your modeler plugin. The imports are as follows.
from Products.DataCollector.plugins.DataMaps import ObjectMap, RelationshipsMap
Here's an example in the ZenPacks.zenoss.Microsoft.Windows ZenPack..
https://github.com/zenoss/ZenPacks.zenoss.Microsoft.Windows/blob/develop/ZenPacks/zenoss/Microsoft/Windows/modeler/plugins/zenoss/winrm/WinMSSQL.py#L495
Subject: | There are examples of what I |
Author: | Jane Curry |
Posted: | 2016-03-17 08:18 |
There are examples of what I think you want in the new Zenoss Developers Guide that I am writing, including ZenPack samples. It is not yet publicly available but contact me offline for a copy.
Cheers,
Jane
Email: jane.curry@skills-1st.co.uk Web: https://www.skills-1st.co.uk
< |
Previous Updating zProperties in zenpack.yaml not Propagating |
Next How should I publish a zenpack? |
> |