-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from autodon/checkmk_v2_opsgenie_integration_a…
…pi_v1 support Check_MK v2.x python3 environment
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python3 | ||
# OpsGenie_APIv1_CMKv2 | ||
|
||
import json | ||
import os | ||
import requests | ||
|
||
def main(): | ||
header_type = {'Content-Type':'application/json'} | ||
context = dict([(var[7:], value) | ||
for (var, value) in os.environ.items() | ||
if var.startswith("NOTIFY_")]) | ||
|
||
if "PARAMETER_1" in context: | ||
opsgenie_api_url = context["PARAMETER_1"] | ||
|
||
if "PARAMETER_1" in context.keys(): | ||
del context["PARAMETER_1"] | ||
if "PARAMETERS" in context.keys(): | ||
del context["PARAMETERS"] | ||
else: | ||
return "No API Key Specified." | ||
|
||
try: | ||
req = requests.post(opsgenie_api_url, headers=header_type, data=json.dumps(context)) | ||
is_success = True | ||
except: | ||
is_success = False | ||
|
||
if is_success: | ||
return "Script finished successfully." | ||
else: | ||
return "Script failed." | ||
|
||
main() |