Completed
Pull Request — master (#504)
by
unknown
03:04
created

CloseAlertAction   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 39 5
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 CloseAlertAction(OpsGenieBaseAction):
19
    def run(self, alert_id=None, alias=None, user=None, note=None, source="StackStorm"):
20
        """
21
        Close alert request is used to close open alerts in OpsGenie.
22
23
        Args:
24
        - alert_id: Id of the alert that will be closed.
25
        - alias: Alias of the alert that will be closed.
26
        - user: Default owner of the execution.
27
        - note: Additional alert note
28
        - source: User defined field to specify source of close action.
29
30
        Returns:
31
        - dict: Data from OpsGenie
32
33
        Raises:
34
        - ValueError: If alias and alert_id are None.
35
        """
36
37
        body = {"apiKey": self.api_key,
38
                "source": source}
39
40
        if alias:
41
            body["alias"] = alias
42
        elif alert_id:
43
            body["id"] = alert_id
44
        else:
45
            raise ValueError("Need one of alias or alert_id to be set.")
46
47
        if user:
48
            body['user'] = user
49
50
        if note:
51
            body['note'] = note
52
53
        data = self._req("POST",
54
                         "v1/json/alert/close",
55
                         body=body)
56
57
        return data
58