def get(self, operation_id): 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 ) ) operations = ( AgentOperationRetriever( customer_name, count, offset, sort, sort_by, username, uri, method ) ) operation_data = get_agent_operation(operation_id) if operation_data: if re.search('install', operation_data[AgentOperationKey.Operation]): results = operations.get_install_operation_by_id(operation_id) else: results = operations.get_operation_by_id(operation_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 __init__(self, username, agent_id, operation_id, success, error=None, status_code=None, uri=None, method=None): """ Args: username (str): The name of the user who made this api call agent_id (str): 36 character UUID of the agent. operation_id (str): 36 character UUID of the operation. success (str): true or false. Kwargs: error (str): The error message, if the operation failed. status_code (int): The exact status of this operation. uri (str): The uri which was called for the results. method (str): The method used to call this api. Basic Usage: >>> from vFense.operations.results import OperationResults >>> username = '******' >>> operation_id = '8fed3dc7-33d4-4278-9bd4-398a68bf7f22' >>> agent_id = 'db6bf07-c5da-4494-93bb-109db205ca64' >>> success = 'true' >>> results = OperationResults( username, agent_id, operation_id, success ) """ self.agent_id = agent_id self.operation_id = operation_id self.username = username self.uri = uri self.method = method self.agent_data = get_agent_info(self.agent_id) self.operation_data = get_agent_operation(self.operation_id) self.customer_name = self.agent_data[AgentKey.CustomerName] self.date_now = DbTime.time_now() self.begining_of_time = DbTime.begining_of_time() self.error = error self.success = success self.status_code = status_code self.operation = (AgentOperation( self.username, self.customer_name, ))
def __init__( self, username, agent_id, operation_id, success, error=None, status_code=None, uri=None, method=None ): """ Args: username (str): The name of the user who made this api call agent_id (str): 36 character UUID of the agent. operation_id (str): 36 character UUID of the operation. success (str): true or false. Kwargs: error (str): The error message, if the operation failed. status_code (int): The exact status of this operation. uri (str): The uri which was called for the results. method (str): The method used to call this api. Basic Usage: >>> from vFense.operations.results import OperationResults >>> username = '******' >>> operation_id = '8fed3dc7-33d4-4278-9bd4-398a68bf7f22' >>> agent_id = 'db6bf07-c5da-4494-93bb-109db205ca64' >>> success = 'true' >>> results = OperationResults( username, agent_id, operation_id, success ) """ self.agent_id = agent_id self.operation_id = operation_id self.username = username self.uri = uri self.method = method self.agent_data = get_agent_info(self.agent_id) self.operation_data = get_agent_operation(self.operation_id) self.customer_name = self.agent_data[AgentKey.CustomerName] self.date_now = DbTime.time_now() self.begining_of_time = DbTime.begining_of_time() self.error = error self.success = success self.status_code = status_code self.operation = ( AgentOperation( self.username, self.customer_name, ) )
def get(self, operation_id): 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)) operations = (AgentOperationRetriever(customer_name, count, offset, sort, sort_by, username, uri, method)) operation_data = get_agent_operation(operation_id) if operation_data: if re.search('install', operation_data[AgentOperationKey.Operation]): results = operations.get_install_operation_by_id( operation_id) else: results = operations.get_operation_by_id(operation_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 send_notifications(username, customer_name, operation_id, agent_id): try: notif_handler = RvNotificationHandler(customer_name, operation_id, agent_id) oper_info = get_agent_operation(operation_id) oper_plugin = oper_info[OperationKey.Plugin] oper_status = oper_info[OperationKey.OperationStatus] threshold = translate_opercodes_to_notif_threshold(oper_status) oper_type = return_notif_type_from_operation(oper_info[OperationKey.Operation]) notif_rules = ( notification_rule_exists( notif_handler, oper_plugin, oper_type, threshold ) ) if notif_rules: if oper_plugin == RV_PLUGIN or oper_plugin == CORE_PLUGIN: sender_addresses = ( notif_handler.get_sending_emails(notif_rules) ) oper = AgentOperationRetriever(username, customer_name, None, None) oper_data = oper.get_install_operation_for_email_alert(operation_id) if sender_addresses: subject, msg_body = ( parse_install_operation_data( oper_data, oper_type, oper_plugin, threshold ) ) send_data( customer_name, subject, msg_body, sender_addresses ) except Exception as e: logger.exception(e)