Package ZenModel :: Module NagiosTemplate
[hide private]
[frames] | no frames]

Source Code for Module ZenModel.NagiosTemplate

  1  ########################################################################### 
  2  # 
  3  # This program is part of Zenoss Core, an open source monitoring platform. 
  4  # Copyright (C) 2007, Zenoss Inc. 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify it 
  7  # under the terms of the GNU General Public License version 2 as published by 
  8  # the Free Software Foundation. 
  9  # 
 10  # For complete information please visit: http://www.zenoss.com/oss/ 
 11  # 
 12  ########################################################################### 
 13   
 14  from Globals import InitializeClass 
 15  from AccessControl import ClassSecurityInfo 
 16  from AccessControl import Permissions 
 17  from Acquisition import aq_base 
 18   
 19  from Products.ZenRelations.RelSchema import * 
 20   
 21  from ZenModelRM import ZenModelRM 
 22  from NagiosCmd import NagiosCmd 
 23   
 24  import warnings 
 25  warnings.warn("NagiosTemplate is deprecated", DeprecationWarning) 
 26   
27 -def crumbspath(templ, crumbs, idx=-1):
28 """Create the crumbs path for sub objects of an RRDTemplate. 29 """ 30 dc = templ.deviceClass() 31 pt = "/nagiosConfig" 32 if not dc: 33 dc = templ.getPrimaryParent() 34 pt = "/objNagiosTemplate" 35 url = dc.getPrimaryUrlPath()+pt 36 if pt == "/objNagiosTemplate": 37 del crumbs[-2] 38 idx = -1 39 crumbs.insert(idx,(url,'NagConf')) 40 return crumbs
41 42 43
44 -def manage_addNagiosTemplate(context, id, REQUEST = None):
45 """make a NagiosTemplate""" 46 tt = NagiosTemplate(id) 47 context._setObject(tt.id, tt) 48 if REQUEST is not None: 49 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
50 51
52 -class NagiosTemplate(ZenModelRM):
53 54 description = "" 55 56 _properties = ( 57 {'id':'description', 'type':'string', 'mode':'w'}, 58 ) 59 60 _relations = ( 61 ("deviceClass", ToOne(ToManyCont, "Products.ZenModel.DeviceClass", "nagiosTemplates")), 62 ("nagiosCmds", ToManyCont(ToOne, "Products.ZenModel.NagiosCmd", "nagiosTemplate")), 63 ) 64 65 factory_type_information = ( 66 { 67 'immediate_view' : 'viewNagiosTemplate', 68 'actions' : 69 ( 70 { 'name' : 'Nagios Config' 71 , 'action' : 'viewNagiosTemplate' 72 , 'permissions' : ( Permissions.view, ) 73 }, 74 { 'name' : 'Modifications' 75 , 'action' : 'viewHistory' 76 , 'permissions' : ( Permissions.view, ) 77 }, 78 ) 79 }, 80 ) 81 82 security = ClassSecurityInfo() 83 84
85 - def breadCrumbs(self, terminator='dmd'):
86 """Return the breadcrumb links for this object add ActionRules list. 87 [('url','id'), ...] 88 """ 89 crumbs = super(NagiosTemplate, self).breadCrumbs(terminator) 90 return crumbspath(self, crumbs)
91 92
93 - def isEditable(self, context):
94 """Is this template editable in context. 95 """ 96 return (self.isManager() and 97 (context == self or self.id.endswith('_Nagios')))
98 99
100 - def getNagiosTemplatePath(self):
101 """Return the path on which this template is defined. 102 """ 103 return self.getPrimaryParent().getPrimaryDmdId(subrel="nagiosTemplates")
104 105 115 116 security.declareProtected('Add DMD Objects', 'manage_addNagiosCmd')
117 - def manage_addNagiosCmd(self, id, REQUEST=None):
118 """Add an NagiosCmd to this DeviceClass. 119 """ 120 if not id: return self.callZenScreen(REQUEST) 121 org = NagiosCmd(id) 122 self.nagiosCmds._setObject(org.id, org) 123 if REQUEST: return self.callZenScreen(REQUEST)
124 125
126 - def manage_deleteNagiosCmds(self, ids=(), REQUEST=None):
127 """Delete NagiosCmds from this DeviceClass 128 (skips ones in other Classes) 129 """ 130 if not ids: return self.callZenScreen(REQUEST) 131 for id in ids: 132 if (getattr(aq_base(self), 'nagiosCmds', False) 133 and getattr(aq_base(self.nagiosCmds),id,False)): 134 self.nagiosCmds._delObject(id) 135 if REQUEST: return self.callZenScreen(REQUEST)
136 137
138 - def manage_copyNagiosCmds(self, ids=(), REQUEST=None):
139 """Put a reference to the objects named in ids in the clip board""" 140 import warnings 141 warnings.warn('manage_copyNagiosCmds is deprecated', DeprecationWarning) 142 if not ids: return self.callZenScreen(REQUEST) 143 ids = [ id for id in ids if self.nagiosCmds._getOb(id, None) != None] 144 if not ids: return self.callZenScreen(REQUEST) 145 cp = self.nagiosCmds.manage_copyObjects(ids) 146 if REQUEST: 147 resp=REQUEST['RESPONSE'] 148 resp.setCookie('__cp', cp, path='/zport/dmd') 149 REQUEST['__cp'] = cp 150 return self.callZenScreen(REQUEST) 151 return cp
152 153
154 - def manage_pasteNagiosCmds(self, cb_copy_data=None, REQUEST=None):
155 """Paste NagiosCmds that have been copied before. 156 """ 157 import warnings 158 warnings.warn('manage_copyNagiosCmds is deprecated', DeprecationWarning) 159 cp = None 160 if cb_copy_data: cp = cb_copy_data 161 elif REQUEST: 162 cp = REQUEST.get("__cp",None) 163 if cp: self.nagiosCmds.manage_pasteObjects(cp) 164 if REQUEST: 165 REQUEST['RESPONSE'].setCookie('__cp', 'deleted', path='/zport/dmd', 166 expires='Wed, 31-Dec-97 23:59:59 GMT') 167 REQUEST['__cp'] = None 168 return self.callZenScreen(REQUEST)
169 170 171 172 InitializeClass(NagiosTemplate) 173