<s> import simplejson as json <EOL> from datadog . util . format import pretty_json <EOL> from datadog import api <EOL> from datadog . dogshell . common import report_errors , report_warnings <EOL> class MonitorClient ( object ) : <EOL> @ classmethod <EOL> def setup_parser ( cls , subparsers ) : <EOL> parser = subparsers . add_parser ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> verb_parsers = parser . add_subparsers ( title = '<STR_LIT>' , dest = '<STR_LIT>' ) <EOL> verb_parsers . required = True <EOL> post_parser = verb_parsers . add_parser ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> post_parser . add_argument ( '<STR_LIT:type>' , help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> post_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> post_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" , default = None ) <EOL> post_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" <EOL> "<STR_LIT>" , default = None ) <EOL> post_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" , default = None ) <EOL> post_parser . set_defaults ( func = cls . _post ) <EOL> update_parser = verb_parsers . add_parser ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> update_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> update_parser . add_argument ( '<STR_LIT:type>' , help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> update_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> update_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" , default = None ) <EOL> update_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" <EOL> "<STR_LIT>" , default = None ) <EOL> update_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" , default = None ) <EOL> update_parser . set_defaults ( func = cls . _update ) <EOL> show_parser = verb_parsers . add_parser ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> show_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> show_parser . set_defaults ( func = cls . _show ) <EOL> show_all_parser = verb_parsers . add_parser ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> show_all_parser . set_defaults ( func = cls . _show_all ) <EOL> delete_parser = verb_parsers . add_parser ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> delete_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> delete_parser . set_defaults ( func = cls . _delete ) <EOL> mute_all_parser = verb_parsers . add_parser ( '<STR_LIT>' , help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> mute_all_parser . set_defaults ( func = cls . _mute_all ) <EOL> unmute_all_parser = verb_parsers . add_parser ( '<STR_LIT>' , help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> unmute_all_parser . set_defaults ( func = cls . _unmute_all ) <EOL> mute_parser = verb_parsers . add_parser ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> mute_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> mute_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" <EOL> "<STR_LIT>" , default = [ ] ) <EOL> mute_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" <EOL> "<STR_LIT>" , default = None ) <EOL> mute_parser . set_defaults ( func = cls . _mute ) <EOL> unmute_parser = verb_parsers . add_parser ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> unmute_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> unmute_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" <EOL> "<STR_LIT>" , default = [ ] ) <EOL> unmute_parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" , <EOL> action = '<STR_LIT:store_true>' ) <EOL> unmute_parser . set_defaults ( func = cls . _unmute ) <EOL> @ classmethod <EOL> def _post ( cls , args ) : <EOL> api . _timeout = args . timeout <EOL> format = args . format <EOL> options = None <EOL> if args . options is not None : <EOL> try : <EOL> options = json . loads ( args . options ) <EOL> except : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> res = api . Monitor . create ( type = args . type , query = args . query , name = args . name , <EOL> message = args . message , options = options ) <EOL> report_warnings ( res ) <EOL> report_errors ( res ) <EOL> if format == '<STR_LIT>' : <EOL> print ( pretty_json ( res ) ) <EOL> else : <EOL> print ( json . dumps ( res ) ) <EOL> @ classmethod <EOL> def _update ( cls , args ) : <EOL> api . _timeout = args . timeout <EOL> format = args . format <EOL> options = None <EOL> if args . options is not None : <EOL> try : <EOL> options = json . loads ( args . options ) <EOL> except : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> res = api . Monitor . update ( args . monitor_id , type = args . type , query = args . query , <EOL> name = args . name , message = args . message , options = options ) <EOL> report_warnings ( res ) <EOL> report_errors ( res ) <EOL> if format == '<STR_LIT>' : <EOL> print ( pretty_json ( res ) ) <EOL> else : <EOL> print ( json . dumps ( res ) ) <EOL> @ classmethod <EOL> def _show ( cls , args ) : <EOL> api . _timeout = args . timeout <EOL> format = args . format <EOL> res = api . Monitor . get ( args . monitor_id ) <EOL> report_warnings ( res ) <EOL> report_errors ( res ) <EOL> if args . string_ids : <EOL> res [ "<STR_LIT:id>" ] = str ( res [ "<STR_LIT:id>" ] ) <EOL> if format == '<STR_LIT>' : <EOL> print ( pretty_json ( res ) ) <EOL> else : <EOL> print ( json . dumps ( res ) ) <EOL> @ classmethod <EOL> def _show_all ( cls , args ) : <EOL> api . _timeout = args . timeout <EOL> format = args . format <EOL> res = api . Monitor . get_all ( ) <EOL> report_warnings ( res ) <EOL> report_errors ( res ) <EOL> if args . string_ids : <EOL> for d in res : <EOL> d [ "<STR_LIT:id>" ] = str ( d [ "<STR_LIT:id>" ] ) <EOL> if format == '<STR_LIT>' : <EOL> print ( pretty_json ( res ) ) <EOL> elif format == '<STR_LIT>' : <EOL> print ( json . dumps ( res ) ) <EOL> else : <EOL> for d in res : <EOL> print ( "<STR_LIT:\t>" . join ( [ ( str ( d [ "<STR_LIT:id>" ] ) ) , <EOL> ( cls . _escape ( d [ "<STR_LIT:message>" ] ) ) , <EOL> ( cls . _escape ( d [ "<STR_LIT:name>" ] ) ) , <EOL> ( str ( d [ "<STR_LIT>" ] ) ) , <EOL> ( str ( d [ "<STR_LIT>" ] ) ) , <EOL> ( d [ "<STR_LIT>" ] ) , <EOL> ( d [ "<STR_LIT:type>" ] ) ] ) ) <EOL> @ classmethod <EOL> def _delete ( cls , args ) : <EOL> api . _timeout = args . timeout <EOL> res = api . Monitor . delete ( args . monitor_id ) <EOL> if res is not None : <EOL> report_warnings ( res ) <EOL> report_errors ( res ) <EOL> @ classmethod <EOL> def _escape ( cls , s ) : <EOL> return s . replace ( "<STR_LIT:\r>" , "<STR_LIT>" ) . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) . replace ( "<STR_LIT:\t>" , "<STR_LIT>" ) <EOL> @ classmethod <EOL> def _mute_all ( cls , args ) : <EOL> api . _timeout = args . timeout <EOL> format = args . format <EOL> res = api . Monitor . mute_all ( ) <EOL> report_warnings ( res ) <EOL> report_errors ( res ) <EOL> if format == '<STR_LIT>' : <EOL> print ( pretty_json ( res ) ) <EOL> else : <EOL> print ( json . dumps ( res ) ) <EOL> @ classmethod <EOL> def _unmute_all ( cls , args ) : <EOL> api . _timeout = args . timeout <EOL> res = api . Monitor . unmute_all ( ) <EOL> if res is not None : <EOL> report_warnings ( res ) <EOL> report_errors ( res ) <EOL> @ classmethod <EOL> def _mute ( cls , args ) : <EOL> api . _timeout = args . timeout <EOL> format = args . format <EOL> res = api . Monitor . mute ( args . monitor_id , scope = args . scope , end = args . end ) <EOL> report_warnings ( res ) <EOL> report_errors ( res ) <EOL> if format == '<STR_LIT>' : <EOL> print ( pretty_json ( res ) ) <EOL> else : <EOL> print ( json . dumps ( res ) ) <EOL> @ classmethod <EOL> def _unmute ( cls , args ) : <EOL> api . _timeout = args . timeout <EOL> res = api . Monitor . unmute ( args . monitor_id , scope = args . scope , all_scopes = args . all_scopes ) <EOL> report_warnings ( res ) <EOL> report_errors ( res ) <EOL> if format == '<STR_LIT>' : <EOL> print ( pretty_json ( res ) ) <EOL> else : <EOL> print ( json . dumps ( res ) ) </s>
