@@ -25,7 +25,7 @@ def setup_parser(self, subparsers):
2525 post_parser .add_argument ('title' , help = 'title for the new dashboard' )
2626 post_parser .add_argument ('description' , help = 'short description of the dashboard' )
2727 post_parser .add_argument ('graphs' , help = 'graph definitions as a JSON string. if unset, reads from stdin.' , nargs = "?" )
28- post_parser .add_argument ('--template_variables' , help = 'a comma-separated list of template variables , e.g.: redis_port,availability-zone ' )
28+ post_parser .add_argument ('--template_variables' , help = 'a json list of template variable dicts , e.g. \' [{"name": "host", "prefix": "host", "default": "host:my-host"}] \' ' )
2929
3030 post_parser .set_defaults (func = self ._post )
3131
@@ -34,7 +34,7 @@ def setup_parser(self, subparsers):
3434 update_parser .add_argument ('title' , help = 'new title for the dashboard' )
3535 update_parser .add_argument ('description' , help = 'short description of the dashboard' )
3636 update_parser .add_argument ('graphs' , help = 'graph definitions as a JSON string. if unset, reads from stdin.' , nargs = "?" )
37- update_parser .add_argument ('--template_variables' , help = 'a comma-separated list of template variables , e.g.: redis_port,availability-zone ' )
37+ update_parser .add_argument ('--template_variables' , help = 'a json list of template variable dicts , e.g. \' [{"name": "host", "prefix": "host", "default": "host:my-host"}] \' ' )
3838 update_parser .set_defaults (func = self ._update )
3939
4040 show_parser = verb_parsers .add_parser ('show' , help = 'Show a dashboard definition.' )
@@ -157,14 +157,15 @@ def _push(self, args):
157157
158158 # Always convert to int, in case it was originally a string.
159159 dash_obj ["id" ] = int (dash_obj ["id" ])
160-
161160 if args .append_auto_text :
162161 datetime_str = datetime .now ().strftime ('%x %X' )
163162 auto_text = ("<br/>\n Updated at {0} from {1} ({2}) on {3}"
164163 .format (datetime_str , f .name , dash_obj ["id" ], platform .node ()))
165164 dash_obj ["description" ] += auto_text
166-
167- res = self .dog .update_dashboard (dash_obj ["id" ], dash_obj ["title" ], dash_obj ["description" ], dash_obj ["graphs" ])
165+ tpl_vars = dash_obj .get ("template_variables" , [])
166+ res = self .dog .update_dashboard (dash_obj ["id" ], dash_obj ["title" ], dash_obj ["description" ],
167+ dash_obj ["graphs" ], template_variables = tpl_vars )
168+ print tpl_vars
168169
169170 if 'errors' in res :
170171 print_err ('Upload of dashboard {0} from file {1} failed.' .format (dash_obj ["id" ], f .name ))
@@ -186,7 +187,11 @@ def _post(self, args):
186187 except :
187188 raise Exception ('bad json parameter' )
188189 if args .template_variables :
189- tpl_vars = [v .strip () for v in args .template_variables .split (',' )]
190+ try :
191+ tpl_vars = json .loads (args .template_variables )
192+ except Exception :
193+ raise Exception ('bad template_variable json parameter' )
194+
190195 else :
191196 tpl_vars = []
192197 res = self .dog .create_dashboard (args .title , args .description , graphs ,
@@ -209,7 +214,10 @@ def _update(self, args):
209214 except :
210215 raise Exception ('bad json parameter' )
211216 if args .template_variables :
212- tpl_vars = [v .strip () for v in args .template_variables .split (',' )]
217+ try :
218+ tpl_vars = json .loads (args .template_variables )
219+ except Exception :
220+ raise Exception ('bad template_variable json parameter' )
213221 else :
214222 tpl_vars = []
215223 res = self .dog .update_dashboard (args .dashboard_id , args .title , args .description ,
0 commit comments