def get(self): username = self.get_current_user() customer_name = get_current_customer_name(username) 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 put(self): username = self.get_current_user() customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: agent_ids = self.arguments.get('agent_ids') new_customer = self.arguments.get('customer_name') if not isinstance(agent_ids, list): agent_ids = agent_ids.split() agentids_moved = [] agentids_not_moved = [] for agent_id in agent_ids: agent = AgentManager(agent_id, customer_name=customer_name) results = agent.change_customer(new_customer, uri, method) if results['http_status'] == 200: agentids_moved.append(agent_id) else: agentids_not_moved.append(agent_id) results['data'] = { 'agentids_moved': agentids_moved, 'agentids_not_moved': agentids_not_moved } 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_ids', 'delete agentids', 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): username = self.get_current_user().encode('utf-8') customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: app_ids = self.arguments.get('app_ids') toggle = self.arguments.get('hide', 'toggle') results = ( update_hidden_status( username, customer_name, uri, method, app_ids, toggle, CustomAppsCollection ) ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: logger.exception(e) results = ( GenericResults( username, uri, method ).something_broke(app_ids, 'toggle hidden on custom_apps', 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_current_customer_name(username) 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().encode('utf-8') customer_name = get_current_customer_name(username) 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', None) severity = self.get_argument('severity', None) sort = self.get_argument('sort', 'asc') sort_by = self.get_argument('sort_by', CustomAppsKey.Name) hidden = self.get_argument('hidden', 'false') if hidden == 'false': hidden = NO else: hidden = YES uri = self.request.uri method = self.request.method patches = (RetrieveCustomApps(username, customer_name, uri, method, count, offset, sort, sort_by, show_hidden=hidden)) if not query and not severity and not status: results = patches.get_all_apps() 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 not query and not severity: results = (patches.filter_by_status(status)) 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 delete(self): username = self.get_current_user() customer_name = get_current_customer_name(username) 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 put(self, agent_id): username = self.get_current_user() customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: oper_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') results = (AddAppResults(username, uri, method, agent_id, app_id, oper_id, reboot_required, success, data, apps_to_delete, apps_to_add, error)) data = results.install_supported_apps(data) self.set_status(data['http_status']) self.set_header('Content-Type', 'application/json') self.set_header('Content-Type', 'application/json') self.write(dumps(data, indent=4)) send_notifications(username, customer_name, oper_id, agent_id) except Exception as e: results = (GenericResults(username, uri, method).something_broke( agent_id, 'install_supported_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 get(self): username = self.get_current_user().encode('utf-8') customer_name = get_current_customer_name(username) 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 get(self): username = self.get_current_user().encode('utf-8') customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: results = ( customer_apps_by_type_count( 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('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_current_customer_name(username) 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_hardware_details(username=username, customer_name=customer_name, os_code=os_code, tag_id=tag_id, 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, tag_id): username = self.get_current_user().encode('utf-8') customer_name = get_current_customer_name(username) 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_current_customer_name(username) 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() customer_name = get_current_customer_name(username) 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, tag_id): username = self.get_current_user().encode('utf-8') customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: status = self.get_argument('status', 'available') start_date = self.get_argument('start_date', None) end_date = self.get_argument('end_date', None) if start_date: start_date = int(start_date) if end_date: end_date = int(end_date) results = (get_os_apps_history_for_tag(username, customer_name, uri, method, tag_id, status, start_date, end_date)) 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, mouse_name): username = self.get_current_user() customer_name = get_current_customer_name(username) 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 post(self, app_id): username = self.get_current_user().encode('utf-8') customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: severity = self.arguments.get('severity').capitalize() if severity in ValidRvSeverities: sev_data = ({AppsKey.RvSeverity: severity}) update_agent_app(app_id, sev_data) 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)) 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 = self.get_current_user() customer_name = get_current_customer_name(username) 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 put(self): username = self.get_current_user().encode('utf-8') customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: app_ids = self.arguments.get('app_ids') toggle = self.arguments.get('hide', 'toggle') results = ( update_hidden_status( username, customer_name, uri, method, app_ids, toggle ) ) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: logger.exception(e) results = ( GenericResults( username, uri, method ).something_broke(app_ids, 'toggle hidden on os_apps', 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_current_customer_name(username) uri = self.request.uri method = self.request.method try: oper_id = self.arguments.get('operation_id') error = self.arguments.get('error', None) success = self.arguments.get('success') results = ( AddResults( username, uri, method, agent_id, oper_id, success, error ) ) 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, oper_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, agent_id): username = self.get_current_user() customer_name = get_current_customer_name(username) 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() customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: count = int(self.get_argument('count', 20)) offset = int(self.get_argument('offset', 0)) sort = self.get_argument('sort', 'desc') sort_by = self.get_argument('sort_by', OperationKey.CreatedTime) operations = (OperationRetriever(username, customer_name, uri, method, count, offset, sort, sort_by)) results = operations.get_all_operations_by_tagid(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( '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 get(self, agent_id): username = self.get_current_user() customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: agent_queue = '[]' rqueue = QueueWorker({'agent_id': agent_id}, username) queue_exists = rqueue.exists() agent_queue = (process_queue_data(rqueue, queue_exists, agent_id, username, customer_name, uri, method)) status = (AgentResults(username, uri, method).check_in(agent_id, agent_queue)) logger.info(status) update_agent_status(agent_id, username, self.request.uri, self.request.method) self.set_status(status['http_status']) self.set_header('Content-Type', 'application/json') self.write(dumps(status)) except Exception as e: status = (GenericResults(username, uri, method).something_broke( agent_id, 'check_in', e)) logger.exception(e) self.set_status(status['http_status']) self.set_header('Content-Type', 'application/json') self.write(dumps(status))
def get(self): username = self.get_current_user() customer_name = get_current_customer_name(username) uri=self.request.uri method=self.request.method try: results= None key=self.get_argument('key') query=self.get_argument('query') results = systems_hardware_details(username=username, customer_name=customer_name, key=key, query=query, 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, tag_id): username = self.get_current_user().encode('utf-8') customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: status = self.get_argument('status', 'available') start_date = self.get_argument('start_date', None) end_date = self.get_argument('end_date', None) if start_date: start_date = int(start_date) if end_date: end_date = int(end_date) results = ( get_os_apps_history_for_tag( username, customer_name, uri, method, tag_id, status, start_date, end_date ) ) 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 delete(self): username = self.get_current_user().encode('utf-8') customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: #app_ids = self.arguments.get('app_ids') The UI needs to past the options as the body not as arguments app_ids = self.get_arguments('app_ids') appids_deleted = 0 appids_failed = 0 for appid in app_ids: deleted = (delete_app_from_rv(appid, CustomAppsCollection, CustomAppsPerAgentCollection)) if deleted: appids_deleted += 1 else: appids_failed += 1 results = (PackageResults(username, uri, method).packages_deleted( app_ids, appids_deleted, appids_failed)) self.set_status(results['http_status']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(results, indent=4)) except Exception as e: logger.exception(e) results = (GenericResults(username, uri, method).something_broke( app_ids, 'failed to delete custom_apps', 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_current_customer_name(username) 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_current_customer_name(username) 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 delete(self, jobname): username = self.get_current_user() customer_name = get_current_customer_name(username) 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 delete(self, jobname): username = self.get_current_user() customer_name = get_current_customer_name(username) 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, agent_id): username = self.get_current_user() customer_name = get_current_customer_name(username) 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([agent_id])) elif shutdown: results = (operation.shutdown([agent_id])) elif apps_refresh: 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 get(self): username = self.get_current_user() customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: results = None key = self.get_argument('key') query = self.get_argument('query') results = systems_cpu_details(username=username, customer_name=customer_name, query=query, key=key, 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, app_id): username = self.get_current_user().encode('utf-8') customer_name = get_current_customer_name(username) 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 = (RetrieveAgentsByCustomAppId(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 delete(self, notification_id): username = self.get_current_user().encode('utf-8') customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: notification = ( Notifier( username, customer_name, uri, method ) ) results = ( notification.delete_alerting_rule(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('delete notification', '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 get(self, agent_id): username = self.get_current_user() customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: count = int(self.get_argument('count', 20)) offset = int(self.get_argument('offset', 0)) sort = self.get_argument('sort', 'desc') sort_by = self.get_argument('sort_by', OperationKey.CreatedTime) operations = ( OperationRetriever( username, customer_name, uri, method, count, offset, sort, sort_by ) ) results = operations.get_all_operations_by_agentid(agent_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('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 get(self): username = self.get_current_user().encode('utf-8') customer_name = get_current_customer_name(username) 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 post(self): passed = False logged_in = False username = self.get_current_user() customer_name = get_current_customer_name(username) 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, agent_id): username = self.get_current_user() customer_name = get_current_customer_name(username) 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, tag_id): username = self.get_current_user() customer_name = get_current_customer_name(username) 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_current_customer_name(username) 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): username = self.get_current_user() customer_name = get_current_customer_name(username) 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() customer_name = get_current_customer_name(username) 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 post(self): username = self.get_current_user() customer_name = get_current_customer_name(username) uri = self.request.uri method = self.request.method try: result = None sched = self.application.scheduler uri = self.request.uri method = self.request.method operation = self.arguments.get('operation', None) pkg_type = self.arguments.get('pkg_type', None) severity = self.arguments.get('severity', None) jobname = self.arguments.get('jobname', None) 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_monthly_recurrent( sched, agent_ids=node_ids,all_agents=all_agents, all_tags=all_tags,tag_ids=tag_ids, severity=severity, pkg_type=pkg_type,operation=operation, name=jobname, epoch_time= epoch_time, custom = custom, every = every, customer_name=customer_name, username=username, 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 monthly 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 put(self, agent_id): try: username = self.get_current_user() customer_name = get_current_customer_name(username) 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( username, customer_name, uri, method, agent_id, system_info, hardware, rebooted ) ) agent_data.pop('data') agent_data['data'] = [] logger.info(agent_data) self.set_status(agent_data['http_status']) if agent_data['http_status'] == 200: if 'rv' in plugins: RvHandOff( username, customer_name, uri, method, agent_id, plugins['rv']['data'], oper_type='updates_applications' ) 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, tag_id): username = self.get_current_user().encode('utf-8') customer_name = get_current_customer_name(username) 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, app_id): username = self.get_current_user().encode('utf-8') customer_name = get_current_customer_name(username) 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() current_customer = get_current_customer_name(current_user) 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): username = self.get_current_user() customer_name = get_current_customer_name(username) 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))