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 send_notifications(username, customer_name, operation_id, agent_id): try: notif_handler = RvNotificationHandler(customer_name, operation_id, agent_id) oper_info = get_oper_info(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 = OperationRetriever(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)