Skip to content

Commit 5fafe9d

Browse files
authored
Merge pull request #21 from atlassian/conf-scripts
conf scripts for checkmk, connectwise-automate, labtechmail, salesfor…
2 parents 817d420 + c9bbac0 commit 5fafe9d

File tree

97 files changed

+32038
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+32038
-0
lines changed

LibreNMS/conf/jec-config.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"apiKey": "<API_KEY>",
3+
"baseUrl": "https://api.atlassian.com",
4+
"logLevel": "DEBUG",
5+
"globalArgs": [],
6+
"globalFlags": {
7+
"url": "<url>",
8+
"apiToken": "<api_token>"
9+
},
10+
"actionMappings": {
11+
"ackAlert": {
12+
"filepath": "<path_of_script>",
13+
"sourceType": "<local | git>",
14+
"env": [],
15+
"stdout": "<path_of_output_file_of_script>"
16+
},
17+
"unmuteAlert": {
18+
"filepath": "<path_of_script>",
19+
"sourceType": "<local | git>",
20+
"env": [],
21+
"stdout": "<path_of_output_file_of_script>"
22+
}
23+
},
24+
"pollerConf": {
25+
"pollingWaitIntervalInMillis": 100,
26+
"visibilityTimeoutInSec": 30,
27+
"maxNumberOfMessages": 10
28+
},
29+
"poolConf": {
30+
"maxNumberOfWorker": 12,
31+
"minNumberOfWorker": 4,
32+
"monitoringPeriodInMillis": 15000,
33+
"keepAliveTimeInMillis": 6000,
34+
"queueSize": 0
35+
}
36+
}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import argparse
2+
import json
3+
import logging
4+
import sys
5+
6+
import requests
7+
8+
parser = argparse.ArgumentParser()
9+
parser.add_argument('-payload', '--payload', help='Payload from queue', required=True)
10+
parser.add_argument('-apiKey', '--apiKey', help='The apiKey of the integration', required=True)
11+
parser.add_argument('-jsmUrl', '--jsmUrl', help='The url', required=True)
12+
parser.add_argument('-logLevel', '--logLevel', help='Level of log', required=True)
13+
parser.add_argument('-url', '--url', help='LibreNms Server Url', required=False)
14+
parser.add_argument('-apiToken', '--apiToken', help='Api Token', required=False)
15+
parser.add_argument('-timeout', '--timeout', help='Timeout', required=False)
16+
17+
args = vars(parser.parse_args())
18+
19+
logging.basicConfig(stream=sys.stdout, level=args['logLevel'])
20+
21+
queue_message_string = args['payload']
22+
queue_message = json.loads(queue_message_string)
23+
24+
alert_id = queue_message["alert"]["alertId"]
25+
mapped_action = queue_message["mappedActionV2"]["name"]
26+
27+
LOG_PREFIX = "[" + mapped_action + "]:"
28+
logging.info(LOG_PREFIX + " Will execute " + mapped_action + " for alertId " + alert_id)
29+
30+
31+
def parse_field(key, mandatory):
32+
variable = queue_message.get(key)
33+
if not variable:
34+
variable = args.get(key)
35+
if mandatory and not variable:
36+
logging.error(LOG_PREFIX + " Skipping action, Mandatory conf item '" + key +
37+
"' is missing. Check your configuration file.")
38+
raise ValueError(LOG_PREFIX + " Skipping action, Mandatory conf item '" + key +
39+
"' is missing. Check your configuration file.")
40+
return variable
41+
42+
43+
url = parse_field('url', True)
44+
if url.endswith("/") and len(url) >= 2:
45+
url = url[0:len(url) - 2]
46+
47+
api_token = parse_field('apiToken', True)
48+
rule = int(queue_message["rule"])
49+
device_id = int(queue_message["deviceId"])
50+
timestamp = queue_message["timestamp"]
51+
timeout = args.get('timeout')
52+
if timeout is None:
53+
timeout = 30000
54+
else:
55+
timeout = int(timeout)
56+
57+
logging.debug("Url: " + str(url))
58+
logging.debug("ApiToken " + str(api_token))
59+
logging.debug("Rule from JSM Alert Details: " + str(rule))
60+
logging.debug("Device ID from JSM Alert Details: " + str(device_id))
61+
logging.debug("Timestamp from JSM Alert Details: " + str(timestamp))
62+
63+
list_rules_endpoint = url + "/api/v0/rules"
64+
65+
logging.debug("Sending GET request to " + str(list_rules_endpoint))
66+
67+
list_rules_response = requests.get(list_rules_endpoint, None, headers={"X-Auth-Token": api_token}, timeout=timeout)
68+
69+
logging.debug("Response from " + str(list_rules_endpoint) + ": " + str(list_rules_response.text) + "Status Code: "
70+
+ str(list_rules_response.status_code))
71+
72+
if list_rules_response.status_code < 400:
73+
rules = list_rules_response.json()["rules"]
74+
rule_id = None
75+
76+
rule_list = [x["id"] for x in rules if x["id"] == rule]
77+
for x in rule_list:
78+
logging.debug(x)
79+
80+
if len(rule_list) > 0:
81+
rule_id = rule_list[0]
82+
logging.debug("Rule Id from LibreNMS: " + str(rule_id))
83+
84+
list_alerts_endpoint = url + "/api/v0/alerts"
85+
list_alerts_response = None
86+
87+
if mapped_action == "ackAlert":
88+
query_params = {"state": "1"}
89+
logging.debug("Sending GET request to " + str(list_alerts_endpoint) + "with parameters: "
90+
+ json.dumps(query_params))
91+
list_alerts_response = requests.get(list_alerts_endpoint, query_params, headers={"X-Auth-Token": api_token},
92+
timeout=timeout)
93+
94+
elif mapped_action == "unmuteAlert":
95+
query_params = {"state": "2"}
96+
logging.debug("Sending GET request to " + str(list_alerts_endpoint) + "with parameters: "
97+
+ json.dumps(query_params))
98+
list_alerts_response = requests.get(list_alerts_endpoint, query_params, headers={"X-Auth-Token": api_token},
99+
timeout=timeout)
100+
101+
logging.debug(
102+
"Response from " + str(list_alerts_endpoint) + ": " + str(list_alerts_response.content) + "Status Code: "
103+
+ str(list_alerts_response.status_code))
104+
105+
if list_alerts_response.status_code < 400:
106+
alerts = list_alerts_response.json()['alerts']
107+
alert_id = None
108+
109+
if len(alerts) > 0:
110+
alert_list = [x['id'] for x in alerts if (x['rule_id'] == rule and x['device_id'] == device_id and
111+
x['timestamp'] == timestamp)]
112+
if len(alert_list) > 0:
113+
alert_id = alert_list[0]
114+
logging.debug("Alert ID: " + str(alert_id))
115+
logging.debug(
116+
"Found alert that matches the timestamp from JSM alert, using that alert's alert id.")
117+
else:
118+
alert_list = [x['id'] for x in alerts if (x['rule_id'] == rule and x['device_id'] == device_id)]
119+
logging.debug("Timestamp did not match the timestamp retrieved from JSM alert,"
120+
+ " using that alert ID of the first alert matches the rule and the device id.")
121+
alert_id = alert_list[0]
122+
logging.debug("Alert ID: " + str(alert_id))
123+
else:
124+
logging.error(
125+
LOG_PREFIX + " Could not obtain alerts list from the list alerts response from LibreNMS API or found no matching alerts.")
126+
127+
logging.debug("Alert Id from LibreNMS: " + str(alert_id))
128+
if alert_id is not None:
129+
if mapped_action == "ackAlert":
130+
url = url + "/api/v0/alerts/" + str(alert_id)
131+
elif mapped_action == "unmuteAlert":
132+
url = url + "/api/v0/alerts/unmute/" + str(alert_id)
133+
134+
logging.debug("Sending PUT request to " + str(url))
135+
136+
response = requests.put(url, None, headers={"X-Auth-Token": api_token}, timeout=timeout)
137+
138+
logging.debug("Response from " + url + ": " + str(response.content) + "Status Code: "
139+
+ str(response.status_code))
140+
141+
if response.status_code < 400:
142+
logging.info(LOG_PREFIX + ' Succesfully executed at LibreNMS.')
143+
logging.debug(LOG_PREFIX + " LibreNMS response:" + str(response.content))
144+
else:
145+
logging.error(
146+
LOG_PREFIX + " Could not execute at LibreNMS; response: " + str(
147+
response.status_code) + ' ' + str(response.text))
148+
else:
149+
logging.error(LOG_PREFIX + " Alert Id from the LibreNMS API was null.")
150+
else:
151+
logging.error(
152+
LOG_PREFIX + " Could not get alert list from LibreNMS; response: " + str(
153+
list_alerts_response.status_code) + ' ' + str(list_alerts_response.text))
154+
else:
155+
logging.error(LOG_PREFIX + " Rule Id from the LibreNMS API was null.")
156+
else:
157+
logging.error(
158+
LOG_PREFIX + " Could not get rules list from LibreNMS; response: " + str(
159+
list_rules_response.status_code) + ' ' + str(list_rules_response.text))
160+

LibreNMS/scripts/transport.jsm.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
$url = $opts['url'];
2+
3+
$curl = curl_init();
4+
5+
set_curl_proxy($curl);
6+
curl_setopt($curl, CURLOPT_URL, $url );
7+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
8+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
9+
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
10+
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($obj));
11+
12+
$ret = curl_exec($curl);
13+
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
14+
15+
var_dump("Response from JSM: " . $ret); //FIXME: proper debugging
16+
17+
if($code != 200) {
18+
var_dump("Error when sending post request to JSM. Response code: " . $code); //FIXME: proper debugging
19+
return false;
20+
}
21+
22+
return true;

catchpoint/conf/template.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"testName": "${TestName}",
3+
"testId": "${TestId}",
4+
"testUrl": "${TestUrl}",
5+
"alertTypeId": "${AlertTypeId}",
6+
"productName": "${ProductName}",
7+
"clientId": "${ClientId}",
8+
"notificationLevel": "${switch("${notificationLevelId}","0","WARNING","1","CRITICAL","3","OK")}",
9+
"nodeName":"${nodeDetails("${nodeName}")}",
10+
"nodeServerAddress":"${nodeDetails("${NodeServerAddress}")}"
11+
}

check_mk/conf/jsm

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/python
2+
# Jira Service Management
3+
4+
import json
5+
import os
6+
import urllib2
7+
8+
9+
def main():
10+
context = dict([(var[7:], value.decode("utf-8"))
11+
for (var, value) in os.environ.items()
12+
if var.startswith("NOTIFY_")])
13+
14+
if "PARAMETER_1" in context:
15+
jsm_api_url = context["PARAMETER_1"]
16+
17+
if "PARAMETER_1" in context.keys():
18+
del context["PARAMETER_1"]
19+
if "PARAMETERS" in context.keys():
20+
del context["PARAMETERS"]
21+
else:
22+
return "No API Key Specified."
23+
24+
req = urllib2.Request(url=jsm_api_url)
25+
req.add_header('Content-Type', 'application/json')
26+
27+
try:
28+
urllib2.urlopen(req, json.dumps(context))
29+
is_success = True
30+
except:
31+
is_success = False
32+
33+
if is_success:
34+
return "Script finished successfully."
35+
else:
36+
return "Script failed."
37+
38+
main()

check_mk/conf/jsm_api-v1_cmk-v2

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
# JSM_APIv1_CMKv2
3+
4+
import json
5+
import os
6+
import requests
7+
8+
def main():
9+
header_type = {'Content-Type':'application/json'}
10+
context = dict([(var[7:], value)
11+
for (var, value) in os.environ.items()
12+
if var.startswith("NOTIFY_")])
13+
14+
if "PARAMETER_1" in context:
15+
jsm_api_url = context["PARAMETER_1"]
16+
17+
if "PARAMETER_1" in context.keys():
18+
del context["PARAMETER_1"]
19+
if "PARAMETERS" in context.keys():
20+
del context["PARAMETERS"]
21+
else:
22+
return "No API Key Specified."
23+
24+
try:
25+
req = requests.post(jsm_api_url, headers=header_type, data=json.dumps(context))
26+
is_success = True
27+
except:
28+
is_success = False
29+
30+
if is_success:
31+
return "Script finished successfully."
32+
else:
33+
return "Script failed."
34+
35+
main()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Script Parameters for CW: "@eu" "@apiKey@" "@Status@" "%clientname%" "%computername%" "%locationname%" "@Fieldname@" "@Result@" "%when%" "%ContactName%" "@Monitor@"
2+
3+
param (
4+
[string]$eu = "False",
5+
[string]$apiKey = "apiKey",
6+
[string]$status = "status",
7+
[string]$clientname = "client",
8+
[string]$computername = "computer",
9+
[string]$locationname = "location",
10+
[string]$fieldname = "field",
11+
[string]$result = "result",
12+
[string]$when = "when",
13+
[string]$contactName = "contact",
14+
[string]$monitorName = "monitor"
15+
)
16+
17+
$uri = "https://api.atlassian.com/jsm/ops/integration/v1/json/integrations/webhooks/connectwiseautomate?apiKey=" + $apiKey;
18+
19+
$body = ConvertTo-Json @{
20+
status = $status
21+
clientName = $clientname
22+
computerName = $computername
23+
locationName = $locationname
24+
fieldName = $fieldname
25+
result = $result
26+
when = $when
27+
contactName = $contactName
28+
monitorName = $monitorName
29+
}
30+
$headers = [Hashtable] @{
31+
Type = 'application/json'
32+
};
33+
$result = Invoke-RestMethod -Method "Post" -Uri $uri -Headers $headers -Body $body -ContentType 'application/json'
34+
Write-Output $result
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<LabTech_Expansion
2+
Version="120.428"
3+
Name="LabTech Script Expansion"
4+
Type="PackedScript">
5+
<PackedScript>
6+
<NewDataSet>
7+
<Table>
8+
<ScriptId>377</ScriptId>
9+
<FolderId>34</FolderId>
10+
<ScriptName>Jira Service Management Alert</ScriptName>
11+
<ScriptNotes>Please, paste your API key in Globals and Parameters tab, then save.</ScriptNotes>
12+
<Permission>0,</Permission>
13+
<EditPermission>0,</EditPermission>
14+
<ComputerScript>1</ComputerScript>
15+
<LocationScript>0</LocationScript>
16+
<MaintenanceScript>0</MaintenanceScript>
17+
<FunctionScript>1</FunctionScript>
18+
<LicenseData>H4sIAAAAAAAEAFWPTQrCMBSE94J3yAEa0gSjoTwC4t9GN1bct8kLZGEa0hTs7aVFoa6GmeEbGLh6g6HHY5MbDY8xoubAZoX7EA7dEDImXQJbODi9o08Tg/qcvG3GgtQYM75aTETwgoiSK8J5VapKbMj+BmyBQG2Sj/mJqfddmLb/g29/GbzVW+kUN9bR1ipHOUdFlRQ7WjbWSCGdUYg/fgaALR+tVx/sr8Vz4QAAAA==</LicenseData>
19+
<ScriptData>H4sIAAAAAAAEAM1WUW/TMBB+r9T/YEWd2MSyrN0KFbSlMOg2YGxaBzxMe3CT62qW2iF2NibEf8d3cdIksL0h8eS7+86+83dfnQ5nYSoS85YbPm63GBvmvibHuu9+mJQjOhUQR5oFBXDGU74CA2kldhirOY/1mCfiA9yPEq4N+JoO9JeQwjZko6lNgGFQpLqdedUv9jSh5Lg7DOqBWtZhJqLxs/5i0A2jhT+PBgu/24WBP+j3nvu7PAr7vf4iHAAUp9AGulxQvZ07bmYgKft4HRrXgLNcfJpJ8o8jxCpelY1ug51ew99r+PsNv7/2Zyo1413bL64udqCkETIDjJe2w071R7EStKUwHXIsI5CG02UsWnWrlKxZeISW3iO09Pb6DxODlZ1VI2ic4MI2MXipTSrk9VUHMjZiHunE264hua4Qza0GrO29Mo1wbjXgMBb26tKqFlNyr5miVklmNV0mOb+RFquQGCzSCr+RtsCfTJFDTiMhBZ3FBtHcasB3S5AI4vpHo3aIoflU9kluI2mlpDAqLZKc67VbW+0WJorFJpLtw3fmXaQZeFvsJ8Y7WSpww9KYRL8IAkv2DmQ7KtHXIAXsWFaC227wTSsZCGngOqXb6+AO5kulbnRg+5EQmjuhgWdGrbiBV+5R8NhT5gb5st361W6BnfPDdf9R0XarM1cRSsn+km4hNRfKf2+PZhPqpFSS0xTGcsE4MitiIszppEQrOkK8EEiBVwWEOImjAEvZIFJKxIkFY04XpI+8elUMVW0gWldBVRTERGcJPMJXfMQuj7heGj6P4crxwNjFfYLbnvAkiUXeNM3gid1sqVxL+Fjeqhvwz0GbEzBLFTHfrd6Z0sZj/mc7XRqxf+RKlrX9NziMfCQ+vm2WW6r8t7pfU2E/K6eZsRSvaXEPTK/+4o69CWQTj3mTfPpkzmimaG6sx7hBbmVuFKgOCgOTaTEcOumcitNJOAzacrCmn3ac5IRPPNfhXv0bUD6N+//dt6Dw3Z+D30mmC+4rCAAA</ScriptData>
20+
<ScriptVersion>1</ScriptVersion>
21+
<ScriptGuid>65f81cdf-bd8f-11e8-8527-0adc525fc8ee</ScriptGuid>
22+
<ScriptFlags>0</ScriptFlags>
23+
<Parameters></Parameters>
24+
</Table>
25+
</NewDataSet>
26+
<ScriptFolder>
27+
<NewDataSet>
28+
<Table>
29+
<FolderID>34</FolderID>
30+
<ParentID>0</ParentID>
31+
<Name>Software</Name>
32+
<GUID>31866f37-8f0a-47b9-b1fd-11bd855f8391</GUID>
33+
</Table>
34+
</NewDataSet>
35+
</ScriptFolder>
36+
</PackedScript>
37+
</LabTech_Expansion>

labtech-email/conf/messageContent.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name:%NAME%,status:%STATUS%,clientName:%CLIENTNAME%,computerName:%COMPUTERNAME%,locationName:%LOCATIONNAME%,fieldName:%FIELDNAME%,result:%RESULT%,failCount:%FailCount%,when:%when%,contactName:%ContactName%

0 commit comments

Comments
 (0)