11# -*- coding: utf-8 -*-
2- from xml .dom import minidom
32from mamonsu .lib .const import Template
43from mamonsu .lib .plugin import Plugin
54import re
@@ -118,14 +117,14 @@ def turn_agent_type(self, xml):
118117 xml = re .sub (r"<type>2" , "<type>0" , xml )
119118 return xml
120119
121- def xml (self , type , plugins = [] ):
120+ def xml (self , type , plugins = None ):
122121 # sort plugins!
122+ if plugins is None :
123+ plugins = []
123124 plugins .sort (key = lambda x : x .__class__ .__name__ )
124125 self .plg_type = type
125126 # create template
126- template_data = {}
127- template_data ['template' ] = self .Template
128- template_data ['application' ] = self .Application
127+ template_data = {'template' : self .Template , 'application' : self .Application }
129128 if Plugin .Type == 'agent' :
130129 template_data ['macros' ] = self ._macro ()
131130 else :
@@ -139,7 +138,9 @@ def xml(self, type, plugins=[]):
139138 output_xml = ZbxTemplate .turn_agent_type (self , output_xml )
140139 return output_xml
141140
142- def _get_all (self , items = 'items' , plugins = []):
141+ def _get_all (self , items = 'items' , plugins = None ):
142+ if plugins is None :
143+ plugins = []
143144 result = ''
144145 for plugin in plugins :
145146 if plugin .AgentPluginType == self .plg_type or self .plg_type == 'all' :
@@ -157,12 +158,16 @@ def _macro(self, xml_key='macro'):
157158 result += '<{1}>{0}</{1}>' .format (self ._format_args (self .macro_defaults , value ), xml_key )
158159 return result
159160
160- def item (self , args = {}, xml_key = 'item' ):
161+ def item (self , args = None , xml_key = 'item' ):
162+ if args is None :
163+ args = {}
161164 return '<{2}>{0}{1}</{2}>' .format (
162165 self ._format_args (self .item_defaults , args ),
163166 self ._application (), xml_key )
164167
165- def trigger (self , args = {}, xml_key = 'trigger' , defaults = None ):
168+ def trigger (self , args = None , xml_key = 'trigger' , defaults = None ):
169+ if args is None :
170+ args = {}
166171 if defaults is None :
167172 defaults = self .trigger_defaults
168173 try :
@@ -175,7 +180,9 @@ def trigger(self, args={}, xml_key='trigger', defaults=None):
175180 self ._format_args (defaults , args ),
176181 xml_key )
177182
178- def graph (self , args = {}, xml_key = 'graph' ):
183+ def graph (self , args = None , xml_key = 'graph' ):
184+ if args is None :
185+ args = {}
179186 try :
180187 items = args ['items' ]
181188 except KeyError :
@@ -201,7 +208,9 @@ def graph(self, args={}, xml_key='graph'):
201208 graph_items , xml_key )
202209
203210 # condition for template creation for zabbix version 4.4
204- def condition (self , args = {}, xml_key = 'condition' ):
211+ def condition (self , args = None , xml_key = 'condition' ):
212+ if args is None :
213+ args = {}
205214 try :
206215 conditions = args ['condition' ]
207216 except KeyError :
@@ -216,8 +225,18 @@ def condition(self, args={}, xml_key='condition'):
216225
217226 return res
218227
219- def discovery_rule (self , rule = {}, conditions = [] , items = [] , triggers = [] , graphs = [] ):
228+ def discovery_rule (self , rule = None , conditions = None , items = None , triggers = None , graphs = None ):
220229
230+ if rule is None :
231+ rule = {}
232+ if conditions is None :
233+ conditions = []
234+ if items is None :
235+ items = []
236+ if triggers is None :
237+ triggers = []
238+ if graphs is None :
239+ graphs = []
221240 result_items = '<item_prototypes>'
222241 for item in items :
223242 result_items += self .item (item , xml_key = 'item_prototype' )
@@ -237,7 +256,6 @@ def discovery_rule(self, rule={},conditions=[], items=[], triggers=[], graphs=[]
237256 result_graphs += '</graph_prototypes>'
238257
239258 if len (conditions ) > 0 :
240-
241259 result_conditions = '<filter>'
242260 for condition in conditions :
243261 result_conditions += self .condition (
0 commit comments