(self, params, **kwargs)
| 1080 | return alert_add_parser |
| 1081 | |
| 1082 | def execute(self, params, **kwargs): |
| 1083 | name = kwargs.get('name') |
| 1084 | if not name: |
| 1085 | raise CommandError('alert add', 'Alert name is required parameter') |
| 1086 | |
| 1087 | settings = self.load_settings(params) |
| 1088 | alert_filter = settings.get('AuditAlertFilter') or [] |
| 1089 | |
| 1090 | exists = next((True for x in alert_filter if x['name'].lower() == name.lower()), False) |
| 1091 | if exists: |
| 1092 | raise CommandError('alert add', f'Alert name \"{name}\" is not unique') |
| 1093 | |
| 1094 | last_id = max((x['id'] for x in alert_filter), default=0) |
| 1095 | if not last_id: |
| 1096 | last_id = 0 |
| 1097 | alert_id = last_id + 1 |
| 1098 | |
| 1099 | alert = { |
| 1100 | 'id': alert_id, |
| 1101 | 'alertUid': secrets.randbelow(2**31), |
| 1102 | 'name': name, |
| 1103 | 'frequency': { |
| 1104 | 'period': 'event' |
| 1105 | }, |
| 1106 | 'filter': {} |
| 1107 | } |
| 1108 | self.apply_alert_options(params, alert, **kwargs) |
| 1109 | |
| 1110 | rq = { |
| 1111 | 'command': 'put_enterprise_setting', |
| 1112 | 'type': 'AuditAlertFilter', |
| 1113 | 'settings': alert, |
| 1114 | } |
| 1115 | api.communicate(params, rq) |
| 1116 | |
| 1117 | active = kwargs.get('active') |
| 1118 | if isinstance(active, str): |
| 1119 | if active == 'off': |
| 1120 | rq = { |
| 1121 | 'command': 'put_enterprise_setting', |
| 1122 | 'type': 'AuditAlertContext', |
| 1123 | 'settings': { |
| 1124 | 'id': alert_id, |
| 1125 | 'disabled': True |
| 1126 | } |
| 1127 | } |
| 1128 | api.communicate(params, rq) |
| 1129 | |
| 1130 | self.invalidate_alerts() |
| 1131 | command = AuditAlertView() |
| 1132 | command.execute(params, target=str(alert_id)) |
| 1133 | |
| 1134 | |
| 1135 | class AuditAlertEdit(EnterpriseCommand, AuditSettingMixin): |
nothing calls this directly
no test coverage detected