Completed
Push — master ( 8bd3ea...0334cb )
by Tomaz
03:06
created

DeleteAlertAction.run()   B

Complexity

Conditions 4

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
dl 0
loc 35
rs 8.5806
1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
15
from lib.actions import OpsGenieBaseAction
16
17
18
class DeleteAlertAction(OpsGenieBaseAction):
19
    def run(self, alert_id=None, alias=None, user=None, source="StackStorm"):
20
        """
21
        Delete an OpsGenie alert.
22
23
        Args
24
        - alert_id: Id of the alert that will be deleted.
25
        - alias: Alias of the alert will be deleted.
26
        - user: Default owner of the execution.
27
        - source: User defined field to specify source of delete action.
28
29
        Returns:
30
        - dict: Data from OpsGenie.
31
32
        Raises:
33
        - ValueError: If alert_id and alias are None.
34
        """
35
36
        payload = {"apiKey": self.api_key,
37
                   "source": source}
38
39
        if alias:
40
            payload["alias"] = alias
41
        elif alert_id:
42
            payload["id"] = alert_id
43
        else:
44
            raise ValueError("Need one of alert_id or alias.")
45
46
        if user:
47
            payload['user'] = user
48
49
        data = self._req("DELETE",
50
                         "v1/json/alert",
51
                         payload=payload)
52
53
        return data
54