Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
cluther committed Sep 15, 2011
0 parents commit 4f7933b
Show file tree
Hide file tree
Showing 45 changed files with 1,706 additions and 0 deletions.
40 changes: 40 additions & 0 deletions CONTENT/ExampleComponent.py
@@ -0,0 +1,40 @@
from Products.ZenModel.DeviceComponent import DeviceComponent
from Products.ZenModel.ManagedEntity import ManagedEntity
from Products.ZenModel.ZenossSecurity import ZEN_CHANGE_DEVICE
from Products.ZenRelations.RelSchema import ToManyCont, ToOne


class ExampleComponent(DeviceComponent, ManagedEntity):
meta_type = portal_type = "ExampleComponent"

attributeOne = None
attributeTwo = None

_properties = ManagedEntity._properties + (
{'id': 'attributeOne', 'type': 'int', 'mode': ''},
{'id': 'attributeTwo', 'type': 'string', 'mode': ''},
)

_relations = ManagedEntity._relations + (
('exampleDevice', ToOne(ToManyCont,
'ZenPacks.NAMESPACE.PACKNAME.ExampleDevice.ExampleDevice',
'exampleComponents',
),
),
)

# Defining the "perfConf" action here causes the "Graphs" display to be
# available for components of this type.
factory_type_information = ({
'actions': ({
'id': 'perfConf',
'name': 'Template',
'action': 'objTemplates',
'permissions': (ZEN_CHANGE_DEVICE,),
},),
},)

# Custom components must always implement the device method. The method
# should return the device object that contains the component.
def device(self):
return self.exampleDevice()
28 changes: 28 additions & 0 deletions CONTENT/ExampleDevice.py
@@ -0,0 +1,28 @@
from Products.ZenModel.Device import Device
from Products.ZenRelations.RelSchema import ToManyCont, ToOne


class ExampleDevice(Device):
"""
Example device subclass. In this case the reason for creating a subclass of
device is to add a new type of relation. We want many "ExampleComponent"
components to be associated with each of these devices.
If you set the zPythonClass of a device class to
ZenPacks.NAMESPACE.PACKNAME.ExampleDevice, any devices created or moved
into that device class will become this class and be able to contain
ExampleComponents.
"""

meta_type = portal_type = 'ExampleDevice'

# This is where we extend the standard relationships of a device to add
# our "exampleComponents" relationship that must be filled with components
# of our custom "ExampleComponent" class.
_relations = Device._relations + (
('exampleComponents', ToManyCont(ToOne,
'ZenPacks.NAMESPACE.PACKNAME.ExampleComponent.ExampleComponent',
'exampleDevice',
),
),
)
47 changes: 47 additions & 0 deletions CONTENT/__init__.py
@@ -0,0 +1,47 @@
# Nothing is required in this __init__.py, but it is an excellent place to do
# many things in a ZenPack.
#
# The example below which is commented out by default creates a custom subclass
# of the ZenPack class. This allows you to define custom installation and
# removal routines for your ZenPack. If you don't need this kind of flexibility
# you should leave the section commented out and let the standard ZenPack
# class be used.
#
# Code included in the global scope of this file will be executed at startup
# in any Zope client. This includes Zope itself (the web interface) and zenhub.
# This makes this the perfect place to alter lower-level stock behavior
# through monkey-patching.

# import Globals
#
# from Products.ZenModel.ZenPack import ZenPack as ZenPackBase
# from Products.ZenUtils.Utils import unused
#
# unused(Globals)
#
#
# class ZenPack(ZenPackBase):
#
# # All zProperties defined here will automatically be created when the
# # ZenPack is installed.
# packZProperties = [
# ('zExampleString', 'default value', 'string'),
# ('zExampleInt', 411, 'int'),
# ('zExamplePassword', 'notsecure', 'password'),
# ]
#
# def install(self, dmd):
# ZenPackBase.install(self, dmd)
#
# # Put your customer installation logic here.
# pass
#
# def remove(self, dmd, leaveObjects=False):
# if not leaveObjects:
# # When a ZenPack is removed the remove method will be called with
# # leaveObjects set to False. This means that you likely want to
# # make sure that leaveObjects is set to false before executing
# # your custom removal code.
# pass
#
# ZenPackBase.remove(self, dmd, leaveObjects=leaveObjects)
31 changes: 31 additions & 0 deletions CONTENT/analytics.py
@@ -0,0 +1,31 @@
from zope.component import adapts
from zope.interface import implements

from Products.Zuul.interfaces import IReportable

from ZenPacks.zenoss.ZenETL.reportable \
import Reportable, MARKER_LENGTH, DEFAULT_STRING_LENGTH

from .ExampleComponent import ExampleComponent


class ExampleComponentReportable(Reportable):
implements(IReportable)
adapts(ExampleComponent)

@property
def entity_class_name(self):
return 'example_component'

def reportProperties(self):
"""
We want to export our two custom properties to the data warehouse for
reporting.
"""
return [
('attributeOne', 'int',
self.context.attribuetOne, MARKER_LENGTH),

('attributeTwo', 'string',
self.context.attributeTwo, DEFAULT_STRING_LENGTH),
]
Empty file added CONTENT/bin/placeholder.txt
Empty file.
Empty file added CONTENT/browser/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions CONTENT/browser/configure.zcml
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<configure xmlns="http://namespaces.zope.org/browser">

<!-- A resource directory contains static web content.
<resourceDirectory
name="example"
directory="resources"
/>
-->

<!-- Register custom JavaScript for ExampleDevices.
<viewlet
name="js-exampledevice"
paths="/++resource++example/js/ExampleDevice.js"
weight="10"
for="..ExampleDevice.ExampleDevice"
manager="Products.ZenUI3.browser.interfaces.IJavaScriptSrcManager"
class="Products.ZenUI3.browser.javascript.JavaScriptSrcBundleViewlet"
permission="zope2.Public"
/>
-->

</configure>
Empty file.
Empty file.
81 changes: 81 additions & 0 deletions CONTENT/browser/resources/js/ExampleDevice.js
@@ -0,0 +1,81 @@
/*
* Based on the configuration in ../../configure.zcml this JavaScript will only
* be loaded when the user is looking at an ExampleDevice in the web interface.
*/

(function(){

var ZC = Ext.ns('Zenoss.component');


/*
* Friendly names for the components. First parameter is the meta_type in your
* custom component class. Second parameter is the singular form of the
* friendly name to be displayed in the UI. Third parameter is the plural form.
*/
ZC.registerName('ExampleComponent', _t('Example'), _t('Examples'));


/*
* Custom component grid panel. This controls the grid that gets displayed for
* components of the type set in "componenType".
*/
ZC.ExampleComponentGridPanel = Ext.extend(ZC.ComponentGridPanel, {
subComponentGridPanel: false,

constructor: function(config) {
config = Ext.applyIf(config||{}, {
autoExpandColumn: 'name',
componentType: 'ExampleComponent',
sortInfo: {
field: 'name',
direction: 'ASC'
},
fields: [
{name: 'uid'},
{name: 'name'},
{name: 'severity'},
{name: 'attributeOne'},
{name: 'attributeTwo'},
{name: 'monitor'},
{name: 'monitored'}
],
columns: [{
id: 'severity',
dataIndex: 'severity',
header: _t('Events'),
renderer: Zenoss.render.severity,
sortable: true,
width: 50
},{
id: 'name',
dataIndex: 'name',
header: _t('Name')
},{
id: 'attributeOne',
dataIndex: 'attributeOne',
header: _t('Attribute #1'),
sortable: true,
width: 70
},{
id: 'attributeTwo',
dataIndex: 'attributeTwo',
header: _t('Attribute #2'),
sortable: true,
width: 70
},{
id: 'monitored',
dataIndex: 'monitored',
header: _t('Monitored'),
renderer: Zenoss.render.checkbox,
sortable: true,
width: 65
}]
});
ZC.ExampleComponentGridPanel.superclass.constructor.call(this, config);
}
});

Ext.reg('ExampleComponentGridPanel', ZC.ExampleComponentGridPanel);

})();

0 comments on commit 4f7933b

Please sign in to comment.