def post(self): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method name = self.arguments.get('name', None) release_date = self.arguments.get('release_date', None) severity = self.arguments.get('severity', 'Optional') description = self.arguments.get('description', None) kb = self.arguments.get('kb', '') support_url = self.arguments.get('support_url', '') major_version = self.arguments.get('major_version', None) minor_version = self.arguments.get('minor_version', None) vendor_name = self.arguments.get('vendor_name', None) operating_system = self.arguments.get('operating_system', None) size = self.arguments.get('size', None) md5 = self.arguments.get('md5_hash', None) cli_options = self.arguments.get('cli_options', None) arch = self.arguments.get('arch', None) uuid = self.arguments.get('id', None) result = ( store_package_info_in_db( username, customer_name, uri, method, size, md5, operating_system, uuid, name, severity, arch, major_version, minor_version, release_date, vendor_name, description, cli_options, support_url, kb ) ) self.set_header('Content-Type', 'application/json') self.write(json.dumps(result, indent=4))
def get(self): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri=self.request.uri method=self.request.method try: results= None os_code=self.get_argument('os_code', None) tag_id=self.get_argument('tag_id', None) results = systems_cpu_details(username=username, customer_name=customer_name, tag_id=tag_id, os_code=os_code, uri=uri, method=method ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke('no stats', '', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self): username = self.get_current_user().encode('utf-8') customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: results = ( get_all_notifications( username, customer_name, uri, method ) ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke('Get list of notifications', 'notifications', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def delete(self, agent_id): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) tag_id = self.arguments.get('tag_id', None) uri = self.request.uri method = self.request.method tag = ( TagsManager( username, customer_name, uri, method ) ) if tag_id: results = tag.remove_tag_from_agent(tag_id, agent_id) else: results = ( GenericResults( username, uri, method ).incorrect_arguments() ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri=self.request.uri method=self.request.method try: self.sched = self.application.scheduler results = job_lister( sched=self.sched, username=username, customer_name=customer_name.encode('utf-8'), uri=uri, method=method ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke('getting schedules', '', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self, tag_id): username = self.get_current_user().encode('utf-8') customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: count = self.get_argument('limit', 3) results = ( tag_stats_by_os( username, customer_name, uri, method, tag_id, count ) ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke('customer os stats', 'os stats', e) ) logger.exception(results) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self, tag_id): username = self.get_current_user().encode('utf-8') customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: results = ( get_severity_bar_chart_stats_for_tag( username, customer_name, uri, method, tag_id ) ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke('tag severity stats', 'sev stats', e) ) logger.exception(results) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self): username = self.get_current_user().encode('utf-8') customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: app_stats = ( get_all_app_stats_by_customer(customer_name) ) results = ( GenericResults( username, uri, method ).information_retrieved(app_stats) ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke('widget handler', 'widgets', e) ) logger.exception(results) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: count = ( int( self.get_argument(ApiArguments.COUNT, DefaultQueryValues.COUNT ) ) ) offset = ( int( self.get_argument( ApiArguments.OFFSET, DefaultQueryValues.OFFSET ) ) ) sort = self.get_argument(ApiArguments.SORT, SortValues.DESC) sort_by = ( self.get_argument( ApiArguments.SORT_BY, AgentOperationKey.CreatedTime ) ) operation = self.get_argument(ApiArguments.OPERATION, None) operations = ( AgentOperationRetriever( customer_name, count, offset, sort, sort_by, username, uri, method ) ) if operation: results = operations.get_all_by_operation(operation) else: results = operations.get_all() self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke('operation', 'search by oper type', e) ) logger.exception(results) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def put(self, agent_id): try: username = self.get_current_user() customer_name = get_user_property(username, UserKeys.CurrentCustomer) uri = self.request.uri method = self.request.method rebooted = self.arguments.get(AgentKey.Rebooted) plugins = self.arguments.get(AgentKey.Plugins) system_info = self.arguments.get(AgentKey.SystemInfo) hardware = self.arguments.get(AgentKey.Hardware) logger.info("data received on startup: %s" % self.request.body) agent_data = update_agent(agent_id, system_info, hardware, rebooted, username, customer_name, uri, method) uris = get_result_uris(agent_id, username, uri, method) uris[AgentOperationKey.Operation] = AgentOperations.REFRESH_RESPONSE_URIS agent_data.pop("data") agent_data["data"] = [uris] self.set_status(agent_data["http_status"]) if agent_data["http_status"] == 200: if "rv" in plugins: RvHandOff(username, customer_name, uri, method).startup_operation(agent_id, plugins["rv"]["data"]) if "ra" in plugins: RaHandoff.startup(agent_id, plugins["ra"]) self.set_header("Content-Type", "application/json") self.write(dumps(agent_data)) except Exception as e: status = GenericResults(username, uri, method).something_broke(agent_id, "startup", e) logger.exception(status["message"]) self.write(dumps(status))
def get(self): username = self.get_current_user().encode('utf-8') customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: os_code = self.get_argument('os_code', None) os_string = self.get_argument('os_string', None) if not os_code and not os_string or os_code and not os_string: data = get_supported_os_codes() elif os_string: data = get_supported_os_strings(customer_name) results = ( GenericResults( username, uri, method ).information_retrieved(data, len(data)) ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke('Get OS Codes', 'Agent', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def delete(self, agent_id): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: agent = AgentManager(agent_id, customer_name=customer_name) delete_oper = StorePatchingOperation(username, customer_name, uri, method) delete_oper.uninstall_agent(agent_id) results = agent.delete_agent(uri, method) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke(agent_id, 'delete agent', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def put(self, agent_id): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: operation_id = self.arguments.get('operation_id') error = self.arguments.get('error', None) success = self.arguments.get('success') results = ( AgentOperationResults( username, agent_id, operation_id, success, error, uri, method ) ) results_data = results.shutdown() self.set_status(results_data['http_status']) self.set_header('Content-Type', 'application/json') self.write(dumps(results_data, indent=4)) send_notifications(username, customer_name, operation_id, agent_id) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke(agent_id, 'shutdown results', e) ) logger.exception(results) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(dumps(results, indent=4))
def delete(self, jobname): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri=self.request.uri method=self.request.method try: self.sched = self.application.scheduler results = ( remove_job( self.sched, jobname, uri=uri,method=method, customer_name=customer_name, username=username ) ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke('delete schedule', '', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def post(self): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: mouse_name = self.arguments.get('name') address = self.arguments.get('address') customers = self.arguments.get('customers', None) mm = MightyMouse(username, customer_name, uri, method) results = mm.add(mouse_name, address, customers) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke(agent_id, '', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def delete(self): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: tag_id = self.arguments.get('id', None) if tag_id: tag = TagsManager(username, customer_name, uri, method) results = tag.remove_tag(tag_id) else: results = ( GenericResults( username, uri, method ).incorrect_arguments() ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke('agentids and tag_id', 'delete agents_in_tagid', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def delete(self): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: mouse_names = self.arguments.get('names') mm = MightyMouse(username, customer_name, uri, method) for mouse in mouse_names: results = mm.remove(mouse_name) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke(agent_id, 'delete agent', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) query = self.get_argument('query', None) count = int(self.get_argument('count', 30)) offset = int(self.get_argument('offset', 0)) uri = self.request.uri method = self.request.method sort = self.get_argument('sort', 'asc') sort_by = self.get_argument('sort_by', TagsKey.TagName) tag = ( TagSearcher( username, customer_name, uri, method, count, offset, sort, sort_by ) ) if not query: results = tag.get_all() else: results = tag.search_by_name(query) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self, mouse_name): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: mouse = mouse_exists(mouse_name) mouse = [mouse] results = ( GenericResults( username, uri, method ).information_retrieved(mouse, len(mouse)) ) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke(mouse_name, 'get mouse', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def put(self, agent_id): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: displayname = self.arguments.get('display_name', None) hostname = self.arguments.get('hostname', None) prod_level = self.arguments.get('production_level', None) new_customer = self.arguments.get('customer_name', None) agent = AgentManager(agent_id, customer_name=customer_name) if (displayname and not hostname and not prod_level and not new_customer): results = agent.displayname_changer(displayname, uri, method) elif (hostname and not prod_level and not displayname and not new_customer): results = agent.hostname_changer(hostname, uri, method) elif (prod_level and not hostname and not displayname and not new_customer): results = agent.production_state_changer(prod_level, uri, method) elif prod_level and hostname and displayname and not new_customer: agent_data = { 'host_name': hostname, 'production_level': prod_level, 'display_name': displayname } results = agent.update_fields(agent_data, uri, method) elif (new_customer and not prod_level and not hostname and not displayname): results = agent.change_customer(new_customer, uri, method) else: results = ( GenericResults( username, uri, method ).incorrect_arguments() ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke(agent_id, 'modify agent', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def put(self, agent_id): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: logger.info(self.request.body) operation_id = self.arguments.get('operation_id') data = self.arguments.get('data') apps_to_delete = self.arguments.get('apps_to_delete', []) apps_to_add = self.arguments.get('apps_to_add', []) error = self.arguments.get('error', None) reboot_required = self.arguments.get('reboot_required') app_id = self.arguments.get('app_id') success = self.arguments.get('success') status_code = self.arguments.get('status_code', None) logger.info("self.arguments: {0}".format(self.arguments)) if not isinstance(reboot_required, bool): if reboot_required == CommonKeys.TRUE: reboot_required = True else: reboot_required = False results = ( PatchingOperationResults( username, agent_id, operation_id, success, error, status_code, uri, method ) ) results_data = ( results.install_agent_apps( app_id, reboot_required, apps_to_delete, apps_to_add ) ) print results_data # TODO: what is this meant for? #data = results.install_agent_update(data) self.set_status(results_data['http_status']) self.set_header('Content-Type', 'application/json') self.write(dumps(results_data, indent=4)) send_notifications(username, customer_name, operation_id, agent_id) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke(agent_id, 'install_agent_apps results', e) ) logger.exception(results) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(dumps(results, indent=4))
def post(self): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri=self.request.uri method=self.request.method try: result = None sched = self.application.scheduler operation = self.arguments.get('operation') pkg_type = self.arguments.get('pkg_type') severity = self.arguments.get('severity') jobname = self.arguments.get('jobname') node_ids = self.arguments.get('nodes', None) tag_ids = self.arguments.get('tags', None) all_tags = self.arguments.get('all_tags', False) all_agents = self.arguments.get('all_agents', False) epoch_time = self.arguments.get('epoch_time') every = self.arguments.get('every', None) custom = self.arguments.get('custom', None) if operation and jobname: results = ( add_yearly_recurrent( sched, customer_name=customer_name, username=username, agent_ids=node_ids, all_agents=all_agents, tag_ids=tag_ids, all_tags=all_tags, severity=severity, pkg_type=pkg_type, operation=operation, name=jobname, every = every, custom = custom, epoch_time= epoch_time, uri=uri, method=method, ) ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke('add yearly recurrent schedule', '', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def post(self): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) mail_host = self.get_argument('host', None) mail_user = self.get_argument('user', None) mail_password = self.get_argument('password', None) mail_port = self.get_argument('port', 25) from_email = self.get_argument('from_email', None) to_email = self.get_arguments('to_email') is_tls = self.get_argument('is_tls', False) is_ssl = self.get_argument('is_ssl', False) if is_tls: is_tls = return_bool(is_tls) if is_ssl: is_ssl = return_bool(is_ssl) if mail_host and mail_user and mail_password and \ mail_port and from_email and len(to_email) >0: create_or_modify_mail_config( modifying_username=username, customer_name=customer_name, server=mail_host, username=mail_user, password=mail_password, port=mail_port, is_tls=is_tls, is_ssl=is_ssl, from_email=from_email, to_email=to_email ) mail = MailClient(customer_name) mail.connect() if mail.logged_in: message = '%s - Valid Mail Settings' % (username) logger.info(message) result = { 'pass': True, 'message': 'Valid Mail Settings' } elif not mail.logged_in: message = '%s - Incorrect Authentication Settings' % (username) logger.error(message) result = { 'pass': False, 'message': 'Incorrect Authentication Settings' } elif not mail.connnected: message = '%s - Invalid Connection Settings' % (username) logger.error(message) result = { 'pass': False, 'message': 'Invalid Connection Settings' } else: message = '%s - Incorrect Parameters Passed' % (username) logger.error(message) result = { 'pass': False, 'message': 'Incorrect Parameters Passed' } self.set_header('Content-Type', 'application/json') self.write(json.dumps(result, indent=4))
def put(self, app_id): username = self.get_current_user().encode('utf-8') customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method try: agent_ids = self.arguments.get('agent_ids') epoch_time = self.arguments.get('time', None) label = self.arguments.get('label', None) restart = self.arguments.get('restart', 'none') cpu_throttle = self.arguments.get('cpu_throttle', 'normal') net_throttle = self.arguments.get('net_throttle', 0) if not epoch_time and not label and app_id: operation = (StorePatchingOperation(username, customer_name, uri, method)) results = (operation.install_supported_apps( [app_id], cpu_throttle, net_throttle, restart, agentids=agent_ids)) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) elif epoch_time and label and agent_ids: date_time = datetime.fromtimestamp(int(epoch_time)) sched = self.application.scheduler job = ({ 'cpu_throttle': cpu_throttle, 'net_throttle': net_throttle, 'pkg_type': 'supported_apps', 'restart': restart, 'app_ids': [app_id] }) add_install_job = (schedule_once(sched, customer_name, username, agent_ids=agent_ids, operation='install', name=label, date=date_time, uri=uri, method=method, job_extra=job)) result = add_install_job self.set_header('Content-Type', 'application/json') self.write(json.dumps(result)) except Exception as e: results = (GenericResults(username, uri, method).something_broke( app_id, 'install_supported_apps', e)) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method data = {"uuid": gen_uuid()} results = (GenericResults(username, uri, method).information_retrieved(data, 0)) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self): username = self.get_current_user().encode('utf-8') customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) appid = self.get_argument('id', None) result = bar_chart_for_appid_by_status(app_id=appid, customer_name=customer_name) self.set_header('Content-Type', 'application/json') self.write(json.dumps(result, indent=4))
def get(self, tag_id): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method tag = TagSearcher(username, customer_name, uri, method) results = tag.get_tag(tag_id) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def post(self): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: result = None sched = self.application.scheduler operation = self.arguments.get('operation', None) pkg_type = self.arguments.get('pkg_type', None) severity = self.arguments.get('severity', None) epoch_time = self.arguments.get('epoch_time') date_to_execute = datetime.fromtimestamp(int(epoch_time)) jobname = self.arguments.get('jobname') node_ids = self.arguments.get('nodes', None) tag_ids = self.arguments.get('tags', None) all_agents=self.arguments.get('all_agents', False) all_tags = self.arguments.get('all_tags', False) results = ( schedule_once( sched, customer_name=customer_name, username=username, agent_ids=node_ids, all_agents=all_agents, tag_ids=tag_ids, all_tags=all_tags, severity=severity, pkg_type=pkg_type, operation=operation, name=jobname, date=date_to_execute, uri=uri, method=method ) ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke('add schedule, once', '', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def post(self, app_id): username = self.get_current_user().encode('utf-8') customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method try: severity = self.arguments.get('severity', None) install_options = self.get_arguments.get('install_options', None) if severity: if severity in CommonSeverityKeys.ValidRvSeverities: severity = severity.capitalize() sev_data = ({AppsKey.RvSeverity: severity}) update_app_data_by_app_id(app_id, sev_data, AppCollections.CustomApps) results = (GenericResults(username, uri, method).object_updated( app_id, 'app severity', [sev_data])) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) else: results = (PackageResults( username, uri, method).invalid_severity(severity)) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) elif install_options: install_options_hash = ({ CustomAppsKey.CliOptions: install_options }) update_app_data_by_app_id(app_id, sev_data, AppCollections.CustomApps) results = (GenericResults(username, uri, method).object_updated( app_id, 'install options updated', [install_options_hash])) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = (GenericResults(username, uri, method).something_broke( app_id, 'update_severity', e)) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def post(self, username): active_user = self.get_current_user() active_customer = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method results = None try: customer_context = (self.arguments.get( ApiArguments.CUSTOMER_CONTEXT, active_customer)) action = self.arguments.get(ApiArguments.ACTION, ApiValues.ADD) ###Update Groups### group_ids = self.arguments.get(ApiArguments.GROUP_IDS, None) if group_ids and isinstance(group_ids, list): if action == ApiValues.ADD: results = (add_user_to_groups(username, customer_context, group_ids, username, uri, method)) if action == ApiValues.DELETE: results = (remove_groups_from_user(username, group_ids, username, uri, method)) ###Update Customers### customer_names = self.arguments.get('customer_names') if customer_names and isinstance(customer_names, list): if action == 'add': results = (add_user_to_customers(username, customer_names, username, uri, method)) elif action == 'delete': results = (remove_customers_from_user( username, customer_names, username, uri, method)) if results: self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) else: results = (GenericResults(active_user, uri, method).incorrect_arguments()) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = (GenericResults(active_user, uri, method).something_broke( active_user, 'User', e)) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self, cve_id): username = self.get_current_user().encode('utf-8') customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method vuln = (RetrieveByCveId(username, customer_name, cve_id, uri, method)) results = vuln.get_cve() self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self, app_id): username = self.get_current_user().encode('utf-8') customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method patches = (RetrieveCustomAppsByAppId(username, customer_name, app_id, uri, method)) results = patches.get_by_app_id(stats=True) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def post(self): current_user = self.get_current_user() customer_name = get_user_property(current_user, UserKeys.CurrentCustomer) body = json.loads(self.request.body) password = body.get("password") results = ra_settings.save_rd_password(password=password, user=current_user, customer=current_customer) self.set_header("Content-Type", "application/json") self.write(json.dumps(results, indent=4))
def get(self, tag_id): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method tag = TagSearcher(username, customer_name, uri, method) results = tag.get_tag(tag_id) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self): username = self.get_current_user().encode('utf-8') customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) result = ( get_valid_fields( customer_name=customer_name ) ) self.set_header('Content-Type', 'application/json') self.write(json.dumps(result, indent=4))
def get(self): active_user = self.get_current_user() uri = self.request.uri method = self.request.method active_customer = (get_user_property(active_user, UserKeys.CurrentCustomer)) customer_context = self.get_argument(ApiArguments.CUSTOMER_CONTEXT, None) all_customers = self.get_argument(ApiArguments.ALL_CUSTOMERS, None) user_name = self.get_argument(ApiArguments.USER_NAME, None) count = 0 user_data = [] try: granted, status_code = (verify_permission_for_user( active_user, Permissions.ADMINISTRATOR)) if granted and not customer_context and not all_customers and not user_name: user_data = get_properties_for_all_users(active_customer) elif granted and customer_context and not all_customers and not user_name: user_data = get_properties_for_all_users(customer_context) elif granted and all_customers and not customer_context and not user_name: user_data = get_properties_for_all_users() elif granted and user_name and not customer_context and not all_customers: user_data = get_properties_for_user(user_name) if user_data: user_data = [user_data] else: user_data = [] elif customer_context and not granted or all_customers and not granted: results = (return_results_for_permissions( active_user, granted, status_code, Permissions.ADMINISTRATOR, uri, method)) count = len(user_data) results = (GenericResults(active_user, uri, method).information_retrieved( user_data, count)) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = (GenericResults(active_user, uri, method).something_broke( active_user, 'User', e)) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def post(self): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) mail_host = self.get_argument('host', None) mail_user = self.get_argument('user', None) mail_password = self.get_argument('password', None) mail_port = self.get_argument('port', 25) from_email = self.get_argument('from_email', None) to_email = self.get_arguments('to_email') is_tls = self.get_argument('is_tls', False) is_ssl = self.get_argument('is_ssl', False) if is_tls: is_tls = return_bool(is_tls) if is_ssl: is_ssl = return_bool(is_ssl) if mail_host and mail_user and mail_password and \ mail_port and from_email and len(to_email) >0: create_or_modify_mail_config(modifying_username=username, customer_name=customer_name, server=mail_host, username=mail_user, password=mail_password, port=mail_port, is_tls=is_tls, is_ssl=is_ssl, from_email=from_email, to_email=to_email) mail = MailClient(customer_name) mail.connect() if mail.logged_in: message = '%s - Valid Mail Settings' % (username) logger.info(message) result = {'pass': True, 'message': 'Valid Mail Settings'} elif not mail.logged_in: message = '%s - Incorrect Authentication Settings' % (username) logger.error(message) result = { 'pass': False, 'message': 'Incorrect Authentication Settings' } elif not mail.connnected: message = '%s - Invalid Connection Settings' % (username) logger.error(message) result = { 'pass': False, 'message': 'Invalid Connection Settings' } else: message = '%s - Incorrect Parameters Passed' % (username) logger.error(message) result = {'pass': False, 'message': 'Incorrect Parameters Passed'} self.set_header('Content-Type', 'application/json') self.write(json.dumps(result, indent=4))
def post(self, agent_id): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method try: reboot = self.arguments.get('reboot', None) shutdown = self.arguments.get('shutdown', None) apps_refresh = self.arguments.get('apps_refresh', None) operation = (StoreAgentOperations(username, customer_name, uri, method)) if reboot: granted, status_code = (verify_permission_for_user( username, Permissions.REBOOT)) if granted: results = (operation.reboot([agent_id])) else: results = (return_results_for_permissions( username, granted, status_code, Permissions.REBOOT, uri, method)) elif shutdown: granted, status_code = (verify_permission_for_user( username, Permissions.SHUTDOWN)) if granted: results = (operation.shutdown([agent_id])) else: results = (return_results_for_permissions( username, granted, status_code, Permissions.SHUTDOWN, uri, method)) elif apps_refresh: operation = (StorePatchingOperation(username, customer_name, uri, method)) results = (operation.apps_refresh([agent_id])) else: results = (GenericResults(username, uri, method).incorrect_arguments()) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = (GenericResults(username, uri, method).something_broke(agent_id, '', e)) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def put(self, agent_id): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: operation_id = self.arguments.get('operation_id', None) error = self.arguments.get('error', None) success = self.arguments.get('success', 'true') apps_data = self.arguments.get('data') status_code = self.arguments.get('status_code', None) RvHandOff( username, customer_name, uri, method ).refresh_apps_operation(agent_id, apps_data) if operation_id: logger.info("self.arguments: {0}".format(self.arguments)) results = PatchingOperationResults( username, agent_id, operation_id, success, error, status_code, uri, method ) results_data = results.apps_refresh() print results_data results_apps_refresh = results.apps_refresh() self.set_status(results_apps_refresh['http_status']) self.write(dumps(results_apps_refresh)) else: results = ( UpdateApplicationsResults(username, uri, method) .applications_updated(agent_id, apps_data) ) results['data'] = [] self.set_status(results['http_status']) self.write(dumps(results)) except Exception as e: results = GenericResults( username, uri, method ).something_broke(agent_id, AgentOperations.REFRESH_APPS, e) logger.exception(results) self.set_status(results['http_status']) self.write(dumps(results))
def put(self, agent_id): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method try: displayname = self.arguments.get('display_name', None) hostname = self.arguments.get('hostname', None) prod_level = self.arguments.get('production_level', None) new_customer = self.arguments.get('customer_name', None) agent = AgentManager(agent_id, customer_name=customer_name) if (displayname and not hostname and not prod_level and not new_customer): results = agent.displayname_changer(displayname, uri, method) elif (hostname and not prod_level and not displayname and not new_customer): results = agent.hostname_changer(hostname, uri, method) elif (prod_level and not hostname and not displayname and not new_customer): results = agent.production_state_changer( prod_level, uri, method) elif prod_level and hostname and displayname and not new_customer: agent_data = { 'host_name': hostname, 'production_level': prod_level, 'display_name': displayname } results = agent.update_fields(agent_data, uri, method) elif (new_customer and not prod_level and not hostname and not displayname): results = agent.change_customer(new_customer, uri, method) else: results = (GenericResults(username, uri, method).incorrect_arguments()) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = (GenericResults(username, uri, method).something_broke( agent_id, 'modify agent', e)) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self): active_user = self.get_current_user() uri = self.request.uri method = self.request.method active_customer = (get_user_property(active_user, UserKeys.CurrentCustomer)) customer_context = self.get_argument('customer_context', None) group_id = self.get_argument('group_id', None) all_customers = self.get_argument('all_customers', None) count = 0 group_data = {} try: granted, status_code = (verify_permission_for_user( active_user, Permissions.ADMINISTRATOR, customer_context)) if granted and not customer_context and not all_customers and not group_id: group_data = get_properties_for_all_groups(active_customer) elif granted and customer_context and not all_customers and not group_id: group_data = get_properties_for_all_groups(customer_context) elif granted and all_customers and not customer_context and not group_id: group_data = get_properties_for_all_groups() elif granted and group_id and not customer_context and not all_customers: group_data = get_group_properties(group_id) if group_data: group_data = [group_data] else: group_data = [] elif customer_context and not granted or all_customers and not granted: results = (return_results_for_permissions( active_user, granted, status_code, Permissions.ADMINISTRATOR, uri, method)) count = len(group_data) results = (GenericResults(active_user, uri, method).information_retrieved( group_data, count)) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = (GenericResults(active_user, uri, method).something_broke( active_user, 'Group', e)) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def post(self): current_user = self.get_current_user() customer_name = (get_user_property(current_user, UserKeys.CurrentCustomer)) body = json.loads(self.request.body) password = body.get('password') results = ra_settings.save_rd_password(password=password, user=current_user, customer=current_customer) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def post(self, tag_id): username = self.get_current_user() customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) uri = self.request.uri method = self.request.method try: reboot = self.arguments.get('reboot', None) shutdown = self.arguments.get('shutdown', None) apps_refresh = self.arguments.get('apps_refresh', None) operation = ( StoreOperation( username, customer_name, uri, method ) ) if reboot: results = ( operation.reboot(tag_id) ) elif shutdown: results = ( operation.shutdown(tag_id) ) elif apps_refresh: results = ( operation.apps_refresh(tag_id) ) else: results = ( GenericResults( username, uri, method ).incorrect_arguments() ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = ( GenericResults( username, uri, method ).something_broke(tag_id, '', e) ) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self, agent_id): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) name = self.get_argument('query', None) uri = self.request.uri method = self.request.method if name: tag = TagSearcher(username, customer_name, uri, method) results = tag.search_by_name(name) else: tag = AgentManager(agent_id, customer_name, username) results = tag.get_tags(uri, method) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) mail = MailClient(customer_name) result = { 'host': mail.server, 'username': mail.username, 'port': mail.port, 'from_email': mail.from_email, 'to_email': mail.to_email, 'is_tls': mail.is_tls, 'is_ssl': mail.is_ssl } self.set_header('Content-Type', 'application/json') self.write(json.dumps(result, indent=4))
def put(self, agent_id): try: username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method rebooted = self.arguments.get(AgentKey.Rebooted) plugins = self.arguments.get(AgentKey.Plugins) system_info = self.arguments.get(AgentKey.SystemInfo) hardware = self.arguments.get(AgentKey.Hardware) logger.info('data received on startup: %s' % self.request.body) agent_data = (update_agent( agent_id, system_info, hardware, rebooted, username, customer_name, uri, method, )) uris = get_result_uris(agent_id, username, uri, method) uris[AgentOperationKey.Operation] = ( AgentOperations.REFRESH_RESPONSE_URIS) agent_data.pop('data') agent_data['data'] = [uris] self.set_status(agent_data['http_status']) if agent_data['http_status'] == 200: if 'rv' in plugins: RvHandOff(username, customer_name, uri, method).startup_operation( agent_id, plugins['rv']['data']) if 'ra' in plugins: RaHandoff.startup(agent_id, plugins['ra']) self.set_header('Content-Type', 'application/json') self.write(dumps(agent_data)) except Exception as e: status = (GenericResults(username, uri, method).something_broke( agent_id, 'startup', e)) logger.exception(status['message']) self.write(dumps(status))
def put(self, agent_id): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method try: logger.info(self.request.body) operation_id = self.arguments.get('operation_id') data = self.arguments.get('data') apps_to_delete = self.arguments.get('apps_to_delete', []) apps_to_add = self.arguments.get('apps_to_add', []) error = self.arguments.get('error', None) reboot_required = self.arguments.get('reboot_required') app_id = self.arguments.get('app_id') success = self.arguments.get('success') status_code = self.arguments.get('status_code', None) logger.info("self.arguments: {0}".format(self.arguments)) if not isinstance(reboot_required, bool): if reboot_required == CommonKeys.TRUE: reboot_required = True else: reboot_required = False results = (PatchingOperationResults(username, agent_id, operation_id, success, error, status_code, uri, method)) results_data = (results.install_agent_apps(app_id, reboot_required, apps_to_delete, apps_to_add)) print results_data # TODO: what is this meant for? #data = results.install_agent_update(data) self.set_status(results_data['http_status']) self.set_header('Content-Type', 'application/json') self.write(dumps(results_data, indent=4)) send_notifications(username, customer_name, operation_id, agent_id) except Exception as e: results = (GenericResults(username, uri, method).something_broke( agent_id, 'install_agent_apps results', e)) logger.exception(results) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(dumps(results, indent=4))
def put(self, agent_id): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method try: operation_id = self.arguments.get('operation_id', None) error = self.arguments.get('error', None) success = self.arguments.get('success', 'true') apps_data = self.arguments.get('data') status_code = self.arguments.get('status_code', None) RvHandOff(username, customer_name, uri, method).refresh_apps_operation(agent_id, apps_data) if operation_id: logger.info("self.arguments: {0}".format(self.arguments)) results = PatchingOperationResults(username, agent_id, operation_id, success, error, status_code, uri, method) results_data = results.apps_refresh() print results_data results_apps_refresh = results.apps_refresh() self.set_status(results_apps_refresh['http_status']) self.write(dumps(results_apps_refresh)) else: results = (UpdateApplicationsResults( username, uri, method).applications_updated(agent_id, apps_data)) results['data'] = [] self.set_status(results['http_status']) self.write(dumps(results)) except Exception as e: results = GenericResults(username, uri, method).something_broke( agent_id, AgentOperations.REFRESH_APPS, e) logger.exception(results) self.set_status(results['http_status']) self.write(dumps(results))
def get(self, tag_id): username = self.get_current_user().encode('utf-8') customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) query = self.get_argument('query', None) count = int(self.get_argument('count', 30)) offset = int(self.get_argument('offset', 0)) status = self.get_argument('status', 'installed') severity = self.get_argument('severity', None) sort = self.get_argument('sort', 'asc') sort_by = self.get_argument('sort_by', CustomAppsKey.Name) uri = self.request.uri method = self.request.method patches = (RetrieveCustomAppsByTagId(username, customer_name, tag_id, uri, method, count, offset, sort, sort_by)) if not query and not severity and status: results = patches.filter_by_status(status) elif not query and status and severity: results = patches.filter_by_status_and_sev(status, severity) elif severity and not query and not status: results = patches.filter_by_severity(severity) elif severity and status and query: results = (patches.filter_by_status_and_query_by_name_and_sev( query, status, severity)) elif status and query: results = (patches.filter_by_status_and_query_by_name( query, status)) elif severity and query: results = (patches.filter_by_sev_and_query_by_name( query, severity)) elif query and not severity and not status: results = patches.query_by_name(query) else: results = (GenericResults(username, uri, method).incorrect_arguments()) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def post(self): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) tag_name = self.arguments.get('name', None) uri = self.request.uri method = self.request.method if tag_name: tag = TagsManager(username, customer_name, uri, method) results = tag.create_tag(tag_name) else: results = (GenericResults(username, uri, method).incorrect_arguments()) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def delete(self, agent_id): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) tag_id = self.arguments.get('tag_id', None) uri = self.request.uri method = self.request.method tag = (TagsManager(username, customer_name, uri, method)) if tag_id: results = tag.remove_tag_from_agent(tag_id, agent_id) else: results = (GenericResults(username, uri, method).incorrect_arguments()) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self, tag_id): username = self.get_current_user().encode('utf-8') customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) available = self.get_argument('available', True) if not isinstance(available, bool): available = return_bool(available) results = ( get_avail_over_time( tag_id=tag_id, available=available, customer_name=customer_name ) ) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method try: results = (get_all_mouseys(username, uri, method)) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = (GenericResults(username, uri, method).something_broke( agent_id, 'get agent_info', e)) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def put(self, agent_id): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) tag_name = self.arguments.get('tag_name', None) tag_id = self.arguments.get('tag_id', None) uri = self.request.uri method = self.request.method tag = (TagsManager(username, customer_name, uri, method)) if tag_name and not tag_id: tag_created = tag.create_tag(tag_name) if tag_created['http_status'] == 200: agent_added = (tag.add_agents_to_tag( agent_id, tag_created['data']['tag_id'])) if agent_added['http_status'] == 200: if tag_created[ 'rv_status_code'] == GenericCodes.ObjectExists: results = (TagResults( username, uri, method).tag_exists_and_agent_added( tag_created['data']['tag_id'], agent_id, agent_added['data'])) else: results = (TagResults( username, uri, method).tag_created_and_agent_added( tag_name, agent_id, agent_added['data'])) else: results = agent_added elif tag_id and not tag_name: agent_added = tag.add_agents_to_tag(agent_id, tag_id) if agent_added['http_status'] == 200: results = (TagResults(username, uri, method).tag_created_and_agent_added( tag_name, agent_id, agent_added['data'])) else: results = agent_added else: results = (GenericResults(username, uri, method).incorrect_arguments()) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self, notification_id): username = self.get_current_user().encode('utf-8') customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method try: alert = AlertSearcher(username, customer_name, uri, method) results = alert.get_notification(notification_id) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = (GenericResults(username, uri, method).something_broke( notification_id, 'notifications', e)) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def delete(self, mouse_name): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) uri = self.request.uri method = self.request.method try: mm = MightyMouse(username, customer_name, uri, method) results = mm.remove(mouse_name) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: results = (GenericResults(username, uri, method).something_broke( agent_id, 'delete agent', e)) logger.exception(e) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self, app_id): username = self.get_current_user().encode('utf-8') customer_name = ( get_user_property(username, UserKeys.CurrentCustomer) ) query = self.get_argument('query', None) count = int(self.get_argument('count', 30)) offset = int(self.get_argument('offset', 0)) status = self.get_argument('status', 'installed') uri = self.request.uri method = self.request.method agents = ( RetrieveAgentsByAppId( username, customer_name, app_id, uri, method, count, offset ) ) if status and not query: results = ( agents.filter_by_status( status ) ) elif status and query: results = ( agents.filter_by_status_and_query_by_name( query, status ) ) else: results = ( GenericResults( username, uri, method ).incorrect_arguments() ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))
def get(self): username = self.get_current_user() customer_name = (get_user_property(username, UserKeys.CurrentCustomer)) query = self.get_argument('query', None) count = int(self.get_argument('count', 30)) offset = int(self.get_argument('offset', 0)) uri = self.request.uri method = self.request.method sort = self.get_argument('sort', 'asc') sort_by = self.get_argument('sort_by', TagsKey.TagName) tag = (TagSearcher(username, customer_name, uri, method, count, offset, sort, sort_by)) if not query: results = tag.get_all() else: results = tag.search_by_name(query) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4))