Completed
Pull Request — master (#504)
by
unknown
02:56
created

CreateAlertAction   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 56
rs 10
wmc 14

1 Method

Rating   Name   Duplication   Size   Complexity  
F run() 0 55 14
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 CreateAlertAction(OpsGenieBaseAction):
19
    def run(self, message, teams=None, alias=None,
20
            description=None, recipients=None, actions=None,
21
            source="StackStorm", tags=None, details=None,
22
            entity=None, user=None, note=None):
23
        """
24
        """
25
26
        if len(message) > 130:
27
            raise ValueError("Message length ({}) is over 130 chars".format(
28
                len(message)))
29
30
        body = {"apiKey": self.api_key,
31
                "message": message}
32
33
        if teams:
34
            body["teams"] = teams
35
36
        if alias:
37
            body["alias"] = alias
38
39
        if description:
40
            if len(description) > 15000:
41
                raise ValueError("Description is too long, can't be over 15000 chars")
42
            else:
43
                body["description"] = description
44
45
        if recipients:
46
            body["recipients"] = recipients
47
48
        if actions:
49
            body["actions"] = actions
50
51
        if source:
52
            body["source"] = source
53
54
        if tags:
55
            body["tags"] = tags
56
57
        if details:
58
            body["details"] = details
59
60
        if entity:
61
            body["entity"] = entity
62
63
        if user:
64
            body['user'] = user
65
66
        if note:
67
            body['note'] = note
68
69
        data = self._req("POST",
70
                         "v1/json/alert",
71
                         body=body)
72
73
        return data
74