Exemplo n.º 1
0
    def get(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:
            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))

            results = operations.get_all_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))
Exemplo n.º 2
0
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)