@@ 52-126 (lines=75) @@ | ||
49 | _EMPTY_POLICY_ID = '085569ce-73ed-11df-83c3-002264764cea' |
|
50 | ||
51 | ||
52 | def _check_event( |
|
53 | event: AlertEvent, condition: AlertCondition, method: AlertMethod |
|
54 | ): |
|
55 | if event == AlertEvent.TASK_RUN_STATUS_CHANGED: |
|
56 | if not condition: |
|
57 | raise RequiredArgument( |
|
58 | "condition is required for event {}".format(event.name), |
|
59 | ) |
|
60 | ||
61 | if not method: |
|
62 | raise RequiredArgument( |
|
63 | "method is required for event {}".format(event.name), |
|
64 | ) |
|
65 | ||
66 | if condition not in ( |
|
67 | AlertCondition.ALWAYS, |
|
68 | AlertCondition.FILTER_COUNT_CHANGED, |
|
69 | AlertCondition.FILTER_COUNT_AT_LEAST, |
|
70 | AlertCondition.SEVERITY_AT_LEAST, |
|
71 | ): |
|
72 | raise InvalidArgument( |
|
73 | "Invalid condition {} for event {}".format( |
|
74 | condition.name, event.name |
|
75 | ) |
|
76 | ) |
|
77 | if method not in ( |
|
78 | AlertMethod.SCP, |
|
79 | AlertMethod.SEND, |
|
80 | AlertMethod.SMB, |
|
81 | AlertMethod.SNMP, |
|
82 | AlertMethod.SYSLOG, |
|
83 | AlertMethod.EMAIL, |
|
84 | AlertMethod.START_TASK, |
|
85 | AlertMethod.HTTP_GET, |
|
86 | AlertMethod.SOURCEFIRE_CONNECTOR, |
|
87 | AlertMethod.VERINICE_CONNECTOR, |
|
88 | AlertMethod.TIPPINGPOINT, |
|
89 | AlertMethod.ALEMBA_VFIRE, |
|
90 | ): |
|
91 | raise InvalidArgument( |
|
92 | "Invalid method {} for event {}".format(method.name, event.name) |
|
93 | ) |
|
94 | elif event in ( |
|
95 | AlertEvent.NEW_SECINFO_ARRIVED, |
|
96 | AlertEvent.UPDATED_SECINFO_ARRIVED, |
|
97 | ): |
|
98 | if not condition: |
|
99 | raise RequiredArgument( |
|
100 | "condition is required for event {}".format(event.name), |
|
101 | ) |
|
102 | ||
103 | if not method: |
|
104 | raise RequiredArgument( |
|
105 | "method is required for event {}".format(event.name), |
|
106 | ) |
|
107 | ||
108 | if condition not in (AlertCondition.ALWAYS,): |
|
109 | raise InvalidArgument( |
|
110 | "Invalid condition {} for event {}".format( |
|
111 | condition.name, event.name |
|
112 | ) |
|
113 | ) |
|
114 | if method not in ( |
|
115 | AlertMethod.SCP, |
|
116 | AlertMethod.SEND, |
|
117 | AlertMethod.SMB, |
|
118 | AlertMethod.SNMP, |
|
119 | AlertMethod.SYSLOG, |
|
120 | AlertMethod.EMAIL, |
|
121 | ): |
|
122 | raise InvalidArgument( |
|
123 | "Invalid method {} for event {}".format(method.name, event.name) |
|
124 | ) |
|
125 | elif event is not None: |
|
126 | raise InvalidArgument('Invalid event "{}"'.format(event.name)) |
|
127 | ||
128 | ||
129 | class GmpV9Mixin(GvmProtocol): |
@@ 102-174 (lines=73) @@ | ||
99 | return isinstance(value, (list, tuple)) |
|
100 | ||
101 | ||
102 | def _check_event( |
|
103 | event: AlertEvent, condition: AlertCondition, method: AlertMethod |
|
104 | ): |
|
105 | if event == AlertEvent.TASK_RUN_STATUS_CHANGED: |
|
106 | if not condition: |
|
107 | raise RequiredArgument( |
|
108 | "condition is required for event {}".format(event.name), |
|
109 | ) |
|
110 | ||
111 | if not method: |
|
112 | raise RequiredArgument( |
|
113 | "method is required for event {}".format(event.name), |
|
114 | ) |
|
115 | ||
116 | if condition not in ( |
|
117 | AlertCondition.ALWAYS, |
|
118 | AlertCondition.FILTER_COUNT_CHANGED, |
|
119 | AlertCondition.FILTER_COUNT_AT_LEAST, |
|
120 | AlertCondition.SEVERITY_AT_LEAST, |
|
121 | ): |
|
122 | raise InvalidArgument( |
|
123 | "Invalid condition {} for event {}".format( |
|
124 | condition.name, event.name |
|
125 | ) |
|
126 | ) |
|
127 | if method not in ( |
|
128 | AlertMethod.SCP, |
|
129 | AlertMethod.SEND, |
|
130 | AlertMethod.SMB, |
|
131 | AlertMethod.SNMP, |
|
132 | AlertMethod.SYSLOG, |
|
133 | AlertMethod.EMAIL, |
|
134 | AlertMethod.START_TASK, |
|
135 | AlertMethod.HTTP_GET, |
|
136 | AlertMethod.SOURCEFIRE_CONNECTOR, |
|
137 | AlertMethod.VERINICE_CONNECTOR, |
|
138 | ): |
|
139 | raise InvalidArgument( |
|
140 | "Invalid method {} for event {}".format(method.name, event.name) |
|
141 | ) |
|
142 | elif event in ( |
|
143 | AlertEvent.NEW_SECINFO_ARRIVED, |
|
144 | AlertEvent.UPDATED_SECINFO_ARRIVED, |
|
145 | ): |
|
146 | if not condition: |
|
147 | raise RequiredArgument( |
|
148 | "condition is required for event {}".format(event.name), |
|
149 | ) |
|
150 | ||
151 | if not method: |
|
152 | raise RequiredArgument( |
|
153 | "method is required for event {}".format(event.name), |
|
154 | ) |
|
155 | ||
156 | if condition not in (AlertCondition.ALWAYS,): |
|
157 | raise InvalidArgument( |
|
158 | "Invalid condition {} for event {}".format( |
|
159 | condition.name, event.name |
|
160 | ) |
|
161 | ) |
|
162 | if method not in ( |
|
163 | AlertMethod.SCP, |
|
164 | AlertMethod.SEND, |
|
165 | AlertMethod.SMB, |
|
166 | AlertMethod.SNMP, |
|
167 | AlertMethod.SYSLOG, |
|
168 | AlertMethod.EMAIL, |
|
169 | ): |
|
170 | raise InvalidArgument( |
|
171 | "Invalid method {} for event {}".format(method.name, event.name) |
|
172 | ) |
|
173 | elif event is not None: |
|
174 | raise InvalidArgument('Invalid event "{}"'.format(event.name)) |
|
175 | ||
176 | ||
177 | class GmpV7Mixin(GvmProtocol): |