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 AddHeartbeatAction(OpsGenieBaseAction): |
19
|
|
|
def run(self, name, interval=None, interval_unit=None, description=None, enabled=False): |
20
|
|
|
""" |
21
|
|
|
Add a Heartbeat to OpsGenie |
22
|
|
|
|
23
|
|
|
Args: |
24
|
|
|
- name: Name of the heartbeat |
25
|
|
|
- interval: Specifies how often a heartbeat message should be expected. |
26
|
|
|
- intervalUnit: interval specified as minutes, hours or days. |
27
|
|
|
- description: An optional description of the heartbeat. |
28
|
|
|
- enabled: Enable/disable heartbeat monitoring. |
29
|
|
|
|
30
|
|
|
Returns: |
31
|
|
|
- dict: Data from OpsGenie |
32
|
|
|
""" |
33
|
|
|
|
34
|
|
|
body = {"apiKey": self.api_key, |
35
|
|
|
"name": name, |
36
|
|
|
"enabled": enabled} |
37
|
|
|
|
38
|
|
|
if interval: |
39
|
|
|
body["interval"] = interval |
40
|
|
|
|
41
|
|
|
if interval_unit: |
42
|
|
|
body["intervalUnit"] = interval_unit |
43
|
|
|
|
44
|
|
|
if description: |
45
|
|
|
body["description"] = description |
46
|
|
|
|
47
|
|
|
data = self._req("POST", |
48
|
|
|
"v1/json/heartbeat", |
49
|
|
|
body=body) |
50
|
|
|
|
51
|
|
|
return data |
52
|
|
|
|