forked from jcurry/ZenPacks.skills1st.MenuExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First commit - definitely got bugs with action menus
- Loading branch information
0 parents
commit 0482c8b
Showing
76 changed files
with
4,159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__import__('pkg_resources').declare_namespace(__name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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" | ||
|
||
devDescr = None | ||
devStatus = None | ||
devErrors = None | ||
|
||
_properties = ManagedEntity._properties + ( | ||
{'id': 'devDescr', 'type': 'string', 'mode': ''}, | ||
{'id': 'devStatus', 'type': 'int', 'mode': ''}, | ||
{'id': 'devErrors', 'type': 'int', 'mode': ''}, | ||
) | ||
|
||
_relations = ManagedEntity._relations + ( | ||
('exampleDevice', ToOne(ToManyCont, | ||
'ZenPacks.skills1st.MenuExamples.ExampleDevice', | ||
'exampleComponents', | ||
), | ||
), | ||
) | ||
|
||
# Defining the "perfConf" action here causes "Example Component Template" to be available in | ||
# the display dropdown for components of this type. | ||
# The action "objTemplates" is a standard Zenoss page template defined in | ||
# /usr/local/zenoss/zenoss/Products/ZenModel/skins/zenmodel/objTemplates.pt | ||
|
||
factory_type_information = ({ | ||
'actions': ({ | ||
'id': 'perfConf', | ||
'name': 'Example Component 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() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from Products.ZenModel.Device import Device | ||
from Products.ZenRelations.RelSchema import ToManyCont, ToOne | ||
from copy import deepcopy | ||
from AccessControl import Permissions | ||
|
||
|
||
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.skills1st.MenuExamples.ExampleComponent', | ||
'exampleDevice', | ||
), | ||
), | ||
) | ||
|
||
# The menus for this particular device class will have all the standard menus | ||
# for a Device and then add on this new menu. The "action" field specifies | ||
# the page template (.pt) file that defines the menu. | ||
|
||
factory_type_information = deepcopy(Device.factory_type_information) | ||
factory_type_information[0]['actions'] += ( | ||
{ 'id' : 'ExampleDevice' | ||
, 'name' : 'My Example Menu 2 (Example Devices only)' | ||
, 'action' : 'myExampleMenuTwo' | ||
, 'permissions' : ( Permissions.view,) }, | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
########################################################################################### | ||
# | ||
# Author: Jane Curry, jane.curry@skills-1st.co.uk | ||
# Date: September 26th, 2011 | ||
# Revised: | ||
# | ||
# ZenPack to demonstrate ways of creating menus | ||
########################################################################################### | ||
|
||
# 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'), | ||
# ] | ||
|
||
# | ||
# Code that is run when the ZenPack is installed | ||
# | ||
def install(self, dmd): | ||
ZenPackBase.install(self, dmd) | ||
# | ||
# To create an organizer when the ZenPack is installed, uncomment the next few lines | ||
# | ||
dc = dmd.Devices.createOrganizer('/Example/TestClass') | ||
dc.setZenProperty('zCollectorPlugins', | ||
('zenoss.snmp.NewDeviceMap', | ||
'zenoss.snmp.DeviceMap', | ||
'zenoss.snmp.InterfaceMap', | ||
'zenoss.snmp.RouteMap', | ||
'community.snmp.ExampleSNMP', | ||
'community.snmp.ExampleHostResourcesSNMP', | ||
'community.cmd.ExampleCMD',)) | ||
# If we want to use a Command modeler plugin, then cmd userid and password need to be setup | ||
dc.setZenProperty('zCommandUsername', 'mollie') | ||
dc.setZenProperty('zCommandPassword', 'fiddle') | ||
|
||
# | ||
# Ensure that properties for this organizer class will be of device object class ExampleDevice | ||
# | ||
dc.setZenProperty('zPythonClass', 'ZenPacks.skills1st.MenuExamples.ExampleDevice') | ||
# | ||
#Create an instance of this device class, checking first whether sucha an instance exists | ||
|
||
if dc.devices._getOb('ExampleDevice1', None): return | ||
myInst = dc.createInstance('ExampleDevice1') | ||
myInst.setPerformanceMonitor('localhost') | ||
|
||
|
||
# Code that is run when the ZenPack is removed | ||
|
||
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. | ||
# | ||
# Delete all instances of devices in /Example/TestClass - completely - including history and events | ||
# | ||
for dev in dmd.Devices.Example.TestClass.getSubDevices(): | ||
dev.deleteDevice(deleteStatus=True, deleteHistory=True, deletePerf=True) | ||
# | ||
# Now delete the device class organizer hierarchy we created | ||
# | ||
# Next line delete all subclasses too | ||
# | ||
dmd.Devices.manage_deleteOrganizer('/Devices/Example') | ||
|
||
ZenPackBase.remove(self, dmd, leaveObjects=leaveObjects) | ||
|
||
# | ||
# The rest is global stuff | ||
# | ||
import logging | ||
log = logging.getLogger('zen.ZenPack') | ||
|
||
import os.path | ||
|
||
|
||
# Register the skins directory - we don't need this now if we put page template | ||
# files under browser/resources in Zenoss 3 style. It IS needed if you want to | ||
# find NEW pt files in the ZenPack's skins directory (all versions of Zenoss). | ||
# Note from Zenoss 3.2 that pt files that OVERRIDE Core pt files may NOT be | ||
# picked up from the skins directory (even with the skinsDir registered as below). | ||
# pt files that override Core pt files should actively be "wired in" with | ||
# statements in a configure.zcml file | ||
# | ||
skinsDir = os.path.join(os.path.dirname(__file__), 'skins') | ||
from Products.CMFCore.DirectoryView import registerDirectory | ||
if os.path.isdir(skinsDir): | ||
registerDirectory(skinsDir, globals()) | ||
|
||
# In older-style Zenoss 2.x ZenPacks the pt files are under skins/<ZenPack name> | ||
# The new Zenoss 3 convention is to put them under browser/templates and use the zcml files | ||
# to 'wire-in' this directory | ||
# | ||
|
||
# | ||
# Create a new menu item in the left-hand menu for all devices | ||
# | ||
# The label of the menu is the 'name' parameter | ||
# The 'action' parameter refers to a page template (.pt) file (without the .pt) if using | ||
# Zenoss 2 skins directory or refers to the "name" field in a page stanza | ||
# if using Zenoss 3 browser/configure.zcml wiring. | ||
# | ||
# The 'permissions' field defines the permission that a role must have for this to be valid for a user | ||
# | ||
from AccessControl import Permissions | ||
from Products.ZenModel.Device import Device | ||
|
||
myExampleMenu1 = { 'id': 'myExampleMenu1', | ||
'name' : 'My Example Menu 1', | ||
'action' : 'myExampleMenuOne', | ||
'permissions' : ( Permissions.view,) | ||
} | ||
|
||
# Add this menu for certain object classes. Adding to "Device" means | ||
# it is available for all subclasses of /Device | ||
|
||
Device.factory_type_information[0]['actions'] += (myExampleMenu1,) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
Empty file.
Oops, something went wrong.