omdnotificationforwarder 2.8__tar.gz → 2.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/PKG-INFO +2 -2
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/bin/notificationforwarder +6 -2
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/pyproject.toml +2 -2
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/src/notificationforwarder/webhook/forwarder.py +28 -7
- omdnotificationforwarder-2.9/tests/pythonpath/local/lib/python/notificationforwarder/datadup/formatter.py +27 -0
- omdnotificationforwarder-2.9/tests/pythonpath/local/lib/python/notificationforwarder/datapost/formatter.py +13 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/test_webhook.py +147 -12
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/.gitignore +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/README.md +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/src/notificationforwarder/baseclass.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/src/notificationforwarder/email/formatter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/src/notificationforwarder/email/forwarder.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/src/notificationforwarder/example/formatter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/src/notificationforwarder/example/forwarder.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/src/notificationforwarder/naemonlog/reporter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/src/notificationforwarder/rabbitmq/formatter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/src/notificationforwarder/rabbitmq/forwarder.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/src/notificationforwarder/syslog/formatter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/src/notificationforwarder/syslog/forwarder.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/src/notificationforwarder/telegram/forwarder.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/lib/python/notificationforwarder/split1/forwarder.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/lib/python/notificationforwarder/split2/formatter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/lib/python/notificationforwarder/split2/forwarder.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/lib/python/notificationforwarder/split3/formatter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/lib/python/notificationforwarder/split3/forwarder.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/local/lib/python/notificationforwarder/alertmanager_servicenow/formatter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/local/lib/python/notificationforwarder/bayern/formatter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/local/lib/python/notificationforwarder/discard/formatter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/local/lib/python/notificationforwarder/split1/formatter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/local/lib/python/notificationforwarder/split2/forwarder.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/local/lib/python/notificationforwarder/split3/formatter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/local/lib/python/notificationforwarder/split3/forwarder.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/local/lib/python/notificationforwarder/split4/formatter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/local/lib/python/notificationforwarder/split4/forwarder.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/local/lib/python/notificationforwarder/ticketsystem/forwarder.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/local/lib/python/notificationforwarder/ticketsystem/reporter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/pythonpath/local/lib/python/notificationforwarder/vong/formatter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/test_alertmanager.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/test_classes.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/test_discard.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/test_formatter.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/test_package.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/test_paths.py +0 -0
- {omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/tests/test_reporter.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: omdnotificationforwarder
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.9
|
|
4
4
|
Summary: A framework for notification scripts for OMD
|
|
5
5
|
Project-URL: Homepage, https://github.com/lausser/noteventificationforhandlerwarder
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/lausser/noteventificationforhandlerwarder/issues
|
|
@@ -8,7 +8,7 @@ Author-email: Gerhard Lausser <lausser@yahoo.com>
|
|
|
8
8
|
Classifier: License :: OSI Approved :: MIT License
|
|
9
9
|
Classifier: Operating System :: OS Independent
|
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Requires-Python: >=3.6
|
|
11
|
+
Requires-Python: >=3.6.1
|
|
12
12
|
Requires-Dist: coshsh
|
|
13
13
|
Requires-Dist: jinja2
|
|
14
14
|
Provides-Extra: test
|
|
@@ -74,7 +74,7 @@ Example for an HTTP-based reporter:
|
|
|
74
74
|
help='Increase the log level to DEBUG',
|
|
75
75
|
default=False)
|
|
76
76
|
parser.add_argument('--version', action='version',
|
|
77
|
-
version=f'%(prog)s 2.
|
|
77
|
+
version=f'%(prog)s 2.9')
|
|
78
78
|
|
|
79
79
|
args = parser.parse_args()
|
|
80
80
|
if not hasattr(args, 'formatter'):
|
|
@@ -90,5 +90,9 @@ Example for an HTTP-based reporter:
|
|
|
90
90
|
logger.critical("there is no class for forwarder {} and formatter {}".format(args.forwarder, args.formatter))
|
|
91
91
|
sys.exit(1)
|
|
92
92
|
|
|
93
|
-
forwarder.
|
|
93
|
+
formatter_instance = forwarder.new_formatter()
|
|
94
|
+
if hasattr(formatter_instance, 'split_events'):
|
|
95
|
+
forwarder.forward_multiple(args.eventopt)
|
|
96
|
+
else:
|
|
97
|
+
forwarder.forward(args.eventopt)
|
|
94
98
|
|
|
@@ -21,13 +21,13 @@ packages = ["src/notificationforwarder"]
|
|
|
21
21
|
|
|
22
22
|
[project]
|
|
23
23
|
name = "omdnotificationforwarder"
|
|
24
|
-
version = "2.
|
|
24
|
+
version = "2.9"
|
|
25
25
|
authors = [
|
|
26
26
|
{ name="Gerhard Lausser", email="lausser@yahoo.com" },
|
|
27
27
|
]
|
|
28
28
|
description = "A framework for notification scripts for OMD"
|
|
29
29
|
readme = "README.md"
|
|
30
|
-
requires-python = ">=3.6"
|
|
30
|
+
requires-python = ">=3.6.1"
|
|
31
31
|
classifiers = [
|
|
32
32
|
"Programming Language :: Python :: 3",
|
|
33
33
|
"License :: OSI Approved :: MIT License",
|
|
@@ -36,7 +36,22 @@ class WebhookForwarder(NotificationForwarder):
|
|
|
36
36
|
# self.headers =
|
|
37
37
|
try:
|
|
38
38
|
request_params = {}
|
|
39
|
-
|
|
39
|
+
mode = event.forwarderopts.get("mode", "json")
|
|
40
|
+
if mode == "json":
|
|
41
|
+
request_params["json"] = event.payload
|
|
42
|
+
elif mode == "form":
|
|
43
|
+
if isinstance(event.payload, dict):
|
|
44
|
+
request_params["data"] = event.payload
|
|
45
|
+
else:
|
|
46
|
+
request_params["data"] = {"data": event.payload}
|
|
47
|
+
elif mode == "raw":
|
|
48
|
+
if isinstance(event.payload, (dict, list)):
|
|
49
|
+
request_params["data"] = json.dumps(event.payload)
|
|
50
|
+
else:
|
|
51
|
+
request_params["data"] = str(event.payload)
|
|
52
|
+
else:
|
|
53
|
+
raise ValueError(f"Unsupported forwarder mode: {mode}")
|
|
54
|
+
|
|
40
55
|
if self.username and self.password:
|
|
41
56
|
request_params["auth"] = requests.auth.HTTPBasicAuth(self.username, self.password)
|
|
42
57
|
if self.headers:
|
|
@@ -45,6 +60,9 @@ class WebhookForwarder(NotificationForwarder):
|
|
|
45
60
|
request_params["headers"] = json.loads(self.headers)
|
|
46
61
|
else:
|
|
47
62
|
request_params["headers"] = self.headers
|
|
63
|
+
if "url" in event.forwarderopts:
|
|
64
|
+
logger.debug(f"formatter overwrites the url with {event.forwarderopts['url']}")
|
|
65
|
+
self.url = event.forwarderopts["url"]
|
|
48
66
|
if "headers" in event.forwarderopts:
|
|
49
67
|
if isinstance(event.forwarderopts["headers"], str):
|
|
50
68
|
event.forwarderopts["headers"] = json.loads(event.forwarderopts["headers"])
|
|
@@ -53,12 +71,16 @@ class WebhookForwarder(NotificationForwarder):
|
|
|
53
71
|
request_params["headers"].update(event.forwarderopts["headers"])
|
|
54
72
|
if self.insecure == "yes":
|
|
55
73
|
request_params["verify"] = False
|
|
74
|
+
|
|
56
75
|
if "headers" not in request_params:
|
|
57
|
-
request_params["headers"] = {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
76
|
+
request_params["headers"] = {}
|
|
77
|
+
if "content-type" not in [k.lower() for k in request_params["headers"]]:
|
|
78
|
+
if mode == "json":
|
|
79
|
+
request_params["headers"]["Content-Type"] = "application/json"
|
|
80
|
+
elif mode == "form":
|
|
81
|
+
request_params["headers"]["Content-Type"] = "application/x-www-form-urlencoded"
|
|
82
|
+
elif mode == "raw":
|
|
83
|
+
request_params["headers"]["Content-Type"] = "text/xml"
|
|
62
84
|
|
|
63
85
|
response = requests.post(self.url, **request_params)
|
|
64
86
|
if response.status_code in [requests.codes.ok, requests.codes.accepted, requests.codes.created]:
|
|
@@ -78,4 +100,3 @@ class WebhookForwarder(NotificationForwarder):
|
|
|
78
100
|
except Exception as e:
|
|
79
101
|
logger.critical("POST had an exception: {}".format(str(e)))
|
|
80
102
|
return False
|
|
81
|
-
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from notificationforwarder.baseclass import NotificationFormatter
|
|
2
|
+
|
|
3
|
+
class DatadupFormatter(NotificationFormatter):
|
|
4
|
+
def format_event(self, event):
|
|
5
|
+
"""
|
|
6
|
+
Formats a single event.
|
|
7
|
+
"""
|
|
8
|
+
# This part is similar to datapost/formatter.py
|
|
9
|
+
event.payload = {
|
|
10
|
+
"source": event.eventopts["source"],
|
|
11
|
+
"action": event.eventopts["action"],
|
|
12
|
+
"site": event.eventopts["site"],
|
|
13
|
+
"split_id": event.eventopts["split_id"], # Add the split_id
|
|
14
|
+
}
|
|
15
|
+
event.summary = f"split event {event.eventopts['split_id']}"
|
|
16
|
+
|
|
17
|
+
def split_events(self, raw_event):
|
|
18
|
+
"""
|
|
19
|
+
Splits one incoming raw_event into two.
|
|
20
|
+
"""
|
|
21
|
+
event1 = raw_event.copy()
|
|
22
|
+
event1["split_id"] = 1
|
|
23
|
+
|
|
24
|
+
event2 = raw_event.copy()
|
|
25
|
+
event2["split_id"] = 2
|
|
26
|
+
|
|
27
|
+
return [event1, event2]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from notificationforwarder.baseclass import NotificationFormatter
|
|
2
|
+
|
|
3
|
+
class DatapostFormatter(NotificationFormatter):
|
|
4
|
+
def format_event(self, event):
|
|
5
|
+
"""
|
|
6
|
+
Creates a dictionary payload from eventopts.
|
|
7
|
+
"""
|
|
8
|
+
event.payload = {
|
|
9
|
+
"source": event.eventopts["source"],
|
|
10
|
+
"action": event.eventopts["action"],
|
|
11
|
+
"site": event.eventopts["site"],
|
|
12
|
+
}
|
|
13
|
+
event.summary = "dict payload"
|
|
@@ -80,18 +80,42 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler):
|
|
|
80
80
|
return False
|
|
81
81
|
|
|
82
82
|
def do_POST(self):
|
|
83
|
+
import urllib.parse
|
|
83
84
|
headers = self.headers
|
|
84
85
|
if not self.check_auth():
|
|
85
86
|
return
|
|
86
87
|
content_length = int(self.headers['Content-Length'])
|
|
87
88
|
post_data = self.rfile.read(content_length)
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
|
|
90
|
+
content_type = self.headers.get('Content-Type', '')
|
|
91
|
+
|
|
92
|
+
if 'application/json' in content_type:
|
|
93
|
+
with open('/tmp/received_payload.json', 'ab') as json_file:
|
|
94
|
+
json_file.write(post_data)
|
|
95
|
+
json_file.write(b'\n')
|
|
96
|
+
elif 'application/x-www-form-urlencoded' in content_type:
|
|
97
|
+
decoded_data = post_data.decode('utf-8')
|
|
98
|
+
parsed_data = urllib.parse.parse_qs(decoded_data)
|
|
99
|
+
# The user wants single values, not lists
|
|
100
|
+
# Weil urllib.parse.parse_qs liefert als value immer eine Liste.
|
|
101
|
+
# Kommt daher, daß man mehrmals den gleichen Key angeben kann
|
|
102
|
+
# abc=schmarrn&abc=kaas&xyz=glump wird zu
|
|
103
|
+
# abc: [schmarrn, kaas], xyz: [glump]
|
|
104
|
+
single_value_data = {k: v[0] for k, v in parsed_data.items()}
|
|
105
|
+
with open('/tmp/received_payload.json', 'a') as json_file:
|
|
106
|
+
json.dump(single_value_data, json_file)
|
|
107
|
+
json_file.write('\n')
|
|
108
|
+
else:
|
|
109
|
+
# Default to writing raw data
|
|
110
|
+
with open('/tmp/received_payload.json', 'ab') as json_file:
|
|
111
|
+
json_file.write(post_data)
|
|
112
|
+
json_file.write(b'\n')
|
|
113
|
+
|
|
90
114
|
self.send_response(200)
|
|
91
115
|
self.end_headers()
|
|
92
116
|
|
|
93
117
|
def start_server():
|
|
94
|
-
server = http.server.HTTPServer(('localhost',
|
|
118
|
+
server = http.server.HTTPServer(('localhost', 18888), RequestHandler)
|
|
95
119
|
server_thread = threading.Thread(target=server.serve_forever)
|
|
96
120
|
server_thread.daemon = True
|
|
97
121
|
server_thread.start()
|
|
@@ -113,7 +137,7 @@ def server_fixture(request):
|
|
|
113
137
|
return server
|
|
114
138
|
|
|
115
139
|
def xtest_send_json_payload_to_server(server_fixture):
|
|
116
|
-
url = "http://localhost:
|
|
140
|
+
url = "http://localhost:18888"
|
|
117
141
|
data = {"key": "value", "another_key": "another_value"}
|
|
118
142
|
|
|
119
143
|
response = requests.post(url, json=data)
|
|
@@ -127,7 +151,7 @@ def xtest_send_json_payload_to_server(server_fixture):
|
|
|
127
151
|
def test_forward_webhook_format_rabbitmq(server_fixture):
|
|
128
152
|
signature = hashlib.sha256(secrets.token_bytes(32)).hexdigest()
|
|
129
153
|
forwarderopts = {
|
|
130
|
-
"url": "http://localhost:
|
|
154
|
+
"url": "http://localhost:18888/api/v1",
|
|
131
155
|
"username": "i_bims",
|
|
132
156
|
"password": "i_bims_1_i_bims",
|
|
133
157
|
}
|
|
@@ -152,7 +176,7 @@ def test_forward_webhook_format_rabbitmq(server_fixture):
|
|
|
152
176
|
def test_forward_webhook_format_example(server_fixture):
|
|
153
177
|
signature = hashlib.sha256(secrets.token_bytes(32)).hexdigest()
|
|
154
178
|
forwarderopts = {
|
|
155
|
-
"url": "http://localhost:
|
|
179
|
+
"url": "http://localhost:18888",
|
|
156
180
|
"username": "i_bims",
|
|
157
181
|
"password": "i_bims_1_i_bims",
|
|
158
182
|
}
|
|
@@ -174,7 +198,7 @@ def test_forward_webhook_format_example(server_fixture):
|
|
|
174
198
|
|
|
175
199
|
def test_forward_webhook_format_vong(server_fixture):
|
|
176
200
|
forwarderopts = {
|
|
177
|
-
"url": "http://localhost:
|
|
201
|
+
"url": "http://localhost:18888",
|
|
178
202
|
"username": "i_bims",
|
|
179
203
|
"password": "i_bims_1_i_bims",
|
|
180
204
|
}
|
|
@@ -195,7 +219,7 @@ def test_forward_webhook_format_vong(server_fixture):
|
|
|
195
219
|
|
|
196
220
|
def test_forward_webhook_format_bayern(server_fixture):
|
|
197
221
|
forwarderopts = {
|
|
198
|
-
"url": "http://localhost:
|
|
222
|
+
"url": "http://localhost:18888",
|
|
199
223
|
"username": "i_bims",
|
|
200
224
|
"password": "i_bims_1_i_bims",
|
|
201
225
|
}
|
|
@@ -208,7 +232,7 @@ def test_forward_webhook_format_bayern(server_fixture):
|
|
|
208
232
|
webhook = notificationforwarder.baseclass.new("webhook", None, "bayern", True, True, forwarderopts)
|
|
209
233
|
webhook.forward(eventopts)
|
|
210
234
|
log = open(get_logfile(webhook)).read()
|
|
211
|
-
assert "INFO - success: des glump
|
|
235
|
+
assert "INFO - success: des glump "+eventopts["HOSTNAME"]+" is hi" in log
|
|
212
236
|
with open("/tmp/received_payload.json") as f:
|
|
213
237
|
payload = f.read()
|
|
214
238
|
payload = json.loads(payload)
|
|
@@ -216,7 +240,7 @@ def test_forward_webhook_format_bayern(server_fixture):
|
|
|
216
240
|
|
|
217
241
|
def test_forward_webhook_format_vong_bin_basic_auth(server_fixture):
|
|
218
242
|
forwarderopts = {
|
|
219
|
-
"url": "http://localhost:
|
|
243
|
+
"url": "http://localhost:18888",
|
|
220
244
|
"username": "i_bims",
|
|
221
245
|
"password": "i_bims_1_i_bims",
|
|
222
246
|
}
|
|
@@ -241,7 +265,7 @@ def test_forward_webhook_format_vong_bin_basic_auth(server_fixture):
|
|
|
241
265
|
def test_forward_webhook_format_vong_bin_token_auth(server_fixture):
|
|
242
266
|
# auth with token, token is in forwarderopts
|
|
243
267
|
forwarderopts = {
|
|
244
|
-
"url": "http://localhost:
|
|
268
|
+
"url": "http://localhost:18888",
|
|
245
269
|
"headers": '{"Authorization": "Bearer i_bims_1_token"}',
|
|
246
270
|
}
|
|
247
271
|
eventopts = {
|
|
@@ -266,7 +290,7 @@ def test_forward_webhook_format_vong_bin_token_auth(server_fixture):
|
|
|
266
290
|
def test_forward_webhook_format_vong_bin_token_auth_by_formatter(server_fixture):
|
|
267
291
|
# auth with token, token is created by the formatter
|
|
268
292
|
forwarderopts = {
|
|
269
|
-
"url": "http://localhost:
|
|
293
|
+
"url": "http://localhost:18888",
|
|
270
294
|
"username": "i_bims",
|
|
271
295
|
"password": "i_bims_1_i_bims",
|
|
272
296
|
}
|
|
@@ -291,3 +315,114 @@ def test_forward_webhook_format_vong_bin_token_auth_by_formatter(server_fixture)
|
|
|
291
315
|
payload = json.loads(payload)
|
|
292
316
|
assert payload["host_name"] == "vongsrv04"
|
|
293
317
|
|
|
318
|
+
def test_submit_form_with_xml_payload(server_fixture):
|
|
319
|
+
forwarderopts = {
|
|
320
|
+
"url": "http://localhost:18888",
|
|
321
|
+
"mode": "form",
|
|
322
|
+
"username": "i_bims",
|
|
323
|
+
"password": "i_bims_1_i_bims",
|
|
324
|
+
}
|
|
325
|
+
eventopts = {
|
|
326
|
+
"source": "nagios",
|
|
327
|
+
"action": "EskaMatrix",
|
|
328
|
+
"site": "p100"
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
webhook = notificationforwarder.baseclass.new("webhook", None, "datapost", True, True, forwarderopts)
|
|
332
|
+
webhook.forward(eventopts)
|
|
333
|
+
|
|
334
|
+
with open("/tmp/received_payload.json") as f:
|
|
335
|
+
payload = json.load(f)
|
|
336
|
+
|
|
337
|
+
assert payload['source'] == "nagios"
|
|
338
|
+
assert payload['action'] == "EskaMatrix"
|
|
339
|
+
assert payload['site'] == "p100"
|
|
340
|
+
|
|
341
|
+
def test_forward_multiple_events(server_fixture):
|
|
342
|
+
forwarderopts = {
|
|
343
|
+
"url": "http://localhost:18888",
|
|
344
|
+
"mode": "form",
|
|
345
|
+
"username": "i_bims",
|
|
346
|
+
"password": "i_bims_1_i_bims",
|
|
347
|
+
}
|
|
348
|
+
eventopts = {
|
|
349
|
+
"source": "nagios",
|
|
350
|
+
"action": "EskaMatrix",
|
|
351
|
+
"site": "p100"
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
webhook = notificationforwarder.baseclass.new("webhook", None, "datadup", True, True, forwarderopts)
|
|
355
|
+
webhook.forward_multiple(eventopts)
|
|
356
|
+
|
|
357
|
+
# Read the two payloads from the file
|
|
358
|
+
received_payloads = []
|
|
359
|
+
with open("/tmp/received_payload.json", "r") as f:
|
|
360
|
+
for line in f:
|
|
361
|
+
if line.strip(): # Avoid empty lines
|
|
362
|
+
received_payloads.append(json.loads(line))
|
|
363
|
+
|
|
364
|
+
assert len(received_payloads) == 2
|
|
365
|
+
|
|
366
|
+
# Check the first event
|
|
367
|
+
assert received_payloads[0]['source'] == "nagios"
|
|
368
|
+
assert received_payloads[0]['action'] == "EskaMatrix"
|
|
369
|
+
assert received_payloads[0]['site'] == "p100"
|
|
370
|
+
assert received_payloads[0]['split_id'] == '1'
|
|
371
|
+
|
|
372
|
+
# Check the second event
|
|
373
|
+
assert received_payloads[1]['source'] == "nagios"
|
|
374
|
+
assert received_payloads[1]['action'] == "EskaMatrix"
|
|
375
|
+
assert received_payloads[1]['site'] == "p100"
|
|
376
|
+
assert received_payloads[1]['split_id'] == '2'
|
|
377
|
+
|
|
378
|
+
def test_forward_multiple_events_bin(server_fixture):
|
|
379
|
+
forwarderopts = {
|
|
380
|
+
"url": "http://localhost:18888",
|
|
381
|
+
"mode": "form",
|
|
382
|
+
"username": "i_bims",
|
|
383
|
+
"password": "i_bims_1_i_bims",
|
|
384
|
+
}
|
|
385
|
+
eventopts = {
|
|
386
|
+
"source": "nagios",
|
|
387
|
+
"action": "EskaMatrix",
|
|
388
|
+
"site": "p100"
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
omd_root = os.environ["OMD_ROOT"]
|
|
392
|
+
pythonpath = omd_root+"/../src:"+omd_root+"/pythonpath/local/lib/python"+":"+omd_root+"/pythonpath/lib/python"
|
|
393
|
+
cmd = omd_root+"/../bin/notificationforwarder"
|
|
394
|
+
|
|
395
|
+
# Construct forwarderoptsparams
|
|
396
|
+
forwarderoptsparams = []
|
|
397
|
+
for k, v in forwarderopts.items():
|
|
398
|
+
if isinstance(v, dict): # Handle dicts for headers
|
|
399
|
+
forwarderoptsparams.append(f"--forwarderopt {k}='{json.dumps(v)}'")
|
|
400
|
+
else:
|
|
401
|
+
forwarderoptsparams.append(f"--forwarderopt {k}='{v}'")
|
|
402
|
+
forwarderoptsparams = " ".join(forwarderoptsparams)
|
|
403
|
+
|
|
404
|
+
# Construct eventoptsparams
|
|
405
|
+
eventoptsparams = " ".join([f"--eventopt {k}='{v}'" for k, v in eventopts.items()])
|
|
406
|
+
|
|
407
|
+
subprocess.call(f"OMD_SITE=my_devel_site OMD_ROOT={omd_root} PYTHONPATH={pythonpath} {cmd} --forwarder webhook --formatter datadup {forwarderoptsparams} {eventoptsparams}", shell=True)
|
|
408
|
+
|
|
409
|
+
# Read the two payloads from the file
|
|
410
|
+
received_payloads = []
|
|
411
|
+
with open("/tmp/received_payload.json", "r") as f:
|
|
412
|
+
for line in f:
|
|
413
|
+
if line.strip(): # Avoid empty lines
|
|
414
|
+
received_payloads.append(json.loads(line))
|
|
415
|
+
|
|
416
|
+
assert len(received_payloads) == 2
|
|
417
|
+
|
|
418
|
+
# Check the first event
|
|
419
|
+
assert received_payloads[0]['source'] == "nagios"
|
|
420
|
+
assert received_payloads[0]['action'] == "EskaMatrix"
|
|
421
|
+
assert received_payloads[0]['site'] == "p100"
|
|
422
|
+
assert received_payloads[0]['split_id'] == '1'
|
|
423
|
+
|
|
424
|
+
# Check the second event
|
|
425
|
+
assert received_payloads[1]['source'] == "nagios"
|
|
426
|
+
assert received_payloads[1]['action'] == "EskaMatrix"
|
|
427
|
+
assert received_payloads[1]['site'] == "p100"
|
|
428
|
+
assert received_payloads[1]['split_id'] == '2'
|
|
File without changes
|
|
File without changes
|
{omdnotificationforwarder-2.8 → omdnotificationforwarder-2.9}/src/notificationforwarder/baseclass.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|