11# stdlib
2+ import argparse
23import json
34
45# 3p
@@ -30,6 +31,11 @@ def setup_parser(cls, subparsers):
3031 post_parser .add_argument ('--options' , help = "json options for the monitor" , default = None )
3132 post_parser .set_defaults (func = cls ._post )
3233
34+ file_post_parser = verb_parsers .add_parser ('fpost' , help = "Create a monitor from file" )
35+ file_post_parser .add_argument ('file' , help = 'json file holding all details' ,
36+ type = argparse .FileType ('r' ))
37+ file_post_parser .set_defaults (func = cls ._file_post )
38+
3339 update_parser = verb_parsers .add_parser ('update' , help = "Update existing monitor" )
3440 update_parser .add_argument ('monitor_id' , help = "monitor to replace with the new definition" )
3541 update_parser .add_argument ('type' , help = "type of the monitor, e.g. "
@@ -42,6 +48,12 @@ def setup_parser(cls, subparsers):
4248 update_parser .add_argument ('--options' , help = "json options for the monitor" , default = None )
4349 update_parser .set_defaults (func = cls ._update )
4450
51+ file_update_parser = verb_parsers .add_parser ('fupdate' , help = "Update existing"
52+ " monitor from file" )
53+ file_update_parser .add_argument ('file' , help = 'json file holding all details' ,
54+ type = argparse .FileType ('r' ))
55+ file_update_parser .set_defaults (func = cls ._file_update )
56+
4557 show_parser = verb_parsers .add_parser ('show' , help = "Show a monitor definition" )
4658 show_parser .add_argument ('monitor_id' , help = "monitor to show" )
4759 show_parser .set_defaults (func = cls ._show )
@@ -110,6 +122,21 @@ def _post(cls, args):
110122 else :
111123 print (json .dumps (res ))
112124
125+ @classmethod
126+ def _file_post (cls , args ):
127+ api ._timeout = args .timeout
128+ format = args .format
129+ monitor = json .load (args .file )
130+ res = api .Monitor .create (type = monitor ['type' ], query = monitor ['query' ],
131+ name = monitor ['name' ], message = monitor ['message' ],
132+ options = monitor ['options' ])
133+ report_warnings (res )
134+ report_errors (res )
135+ if format == 'pretty' :
136+ print (pretty_json (res ))
137+ else :
138+ print (json .dumps (res ))
139+
113140 @classmethod
114141 def _update (cls , args ):
115142 api ._timeout = args .timeout
@@ -129,6 +156,21 @@ def _update(cls, args):
129156 else :
130157 print (json .dumps (res ))
131158
159+ @classmethod
160+ def _file_update (cls , args ):
161+ api ._timeout = args .timeout
162+ format = args .format
163+ monitor = json .load (args .file )
164+ res = api .Monitor .update (monitor ['id' ], type = monitor ['type' ], query = monitor ['query' ],
165+ name = monitor ['name' ], message = monitor ['message' ],
166+ options = monitor ['options' ])
167+ report_warnings (res )
168+ report_errors (res )
169+ if format == 'pretty' :
170+ print (pretty_json (res ))
171+ else :
172+ print (json .dumps (res ))
173+
132174 @classmethod
133175 def _show (cls , args ):
134176 api ._timeout = args .timeout
0 commit comments