diff --git a/README.md b/README.md index 5d35d95..f535498 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,36 @@ -# Manage Engine Service Desk Plus (mesdp) +# Manage Engine Service Desk Plus (mesdp) https://www.manageengine.com/products/service-desk/ ### Overview -ServiceDesk Plus is a game changer in turning IT teams from daily fire-fighting to delivering awesome customer service. It provides great visibility and central control in dealing with IT issues to ensure that businesses suffer no downtime. This all-in-one solution delivers comprehensive Incident Management, Self-service portal, Knowledge base, Multi-site support, SLA Management and Help Desk Reports. +ServiceDesk Plus is a game changer in turning IT teams from daily fire-fighting to delivering awesome customer service. It provides great visibility and central control in dealing with IT issues to ensure that businesses suffer no downtime. This all-in-one solution delivers comprehensive Incident Management, Self-service portal, Knowledge base, Multi-site support, SLA Management and Help Desk Reports. - -##### PRE-REQUISITES to use mesdp and DNIF + +##### PRE-REQUISITES to use mesdp and DNIF Outbound access required for github to clone the plugin -| Protocol | Source IP | Source Port | Direction | Destination Domain | Destination Port | -|:------------- |:-------------|:-------------|:-------------|:-------------|:-------------| +| Protocol | Source IP | Source Port | Direction | Destination Domain | Destination Port | +|:------------- |:-------------|:-------------|:-------------|:-------------|:-------------| | TCP | DS,CR,A10 | Any | Egress | github.com | 443 | - + ## mesdp trigger plugin functions Details of the function that can be used with the ClickSend trigger is given in this section. -### create_ticket -This function allows for creating a ticket against an observerd event using the defined (custom/default template) . +### create_ticket +This function allows for creating a service ticket against an observerd event using the defined (custom/default template) . -### Input -- Subject of ticket.(Note Commas(,) cannot be used as they are used for Input parameters seperation ) +### Input +- Subject of ticket.(Note Commas(,) cannot be used as they are used for Input parameters seperation ) - Event Field prenset in the event . -- Template name to be triggered.(Note if this field is not provided the default template gets triggered) +- Template name to be triggered.(Note if this field is not provided the default template gets triggered) ### Example ``` _fetch * from event where $Action=LOGIN_FAIL limit 1 ->>_trigger api mesdp create_ticket Login Failed for User : ,$User , default.xml +>>_trigger api mesdp create_ticket "Login Failed for User :" ,$User , default.txt ``` -### Output -![mesdp](https://user-images.githubusercontent.com/37173181/44776438-b7631180-ab95-11e8-8f47-a42ea723f424.jpg) +### Output +![mesdp](https://user-images.githubusercontent.com/51116848/65764893-5b760e00-e144-11e9-99d6-653cad322b7c.png) The trigger call returns output in the following structure for available data @@ -42,8 +42,8 @@ The trigger call returns output in the following structure for available data | $MESDPWorkOrderID | Work order id associated with the newly created ticket | -### Using the mesdp API and DNIF -The mesdp API is found on github at +### Using the mesdp API and DNIF +The mesdp API is found on github at https://github.com/dnif/trigger-mesdp @@ -51,18 +51,18 @@ The following process has to be repeated on all of the following components ### Getting started with mesdp API and DNIF -1. #### Login to your Data Store, Correlator, and A10 containers. +1. #### Login to your Data Store, Correlator, and A10 containers. [ACCESS DNIF CONTAINER VIA SSH](https://dnif.it/docs/guides/tutorials/access-dnif-container-via-ssh.html) 2. #### Move to the `‘/dnif//trigger_plugins’` folder path. ``` $cd /dnif/CnxxxxxxxxxxxxV8/trigger_plugins/ ``` -3. #### Clone using the following command -``` +3. #### Clone using the following command +``` git clone https://github.com/dnif/trigger-mesdp.git mesdp ``` -4. #### Move to the `‘/dnif//trigger_plugins/mesdp/’` folder path and open dnifconfig.yml configuration file - +4. #### Move to the `‘/dnif//trigger_plugins/mesdp/’` folder path and open dnifconfig.yml configuration file + Replace the tags: with your mesdp credentials ``` trigger_plugin: @@ -72,8 +72,8 @@ trigger_plugin: MESDP_NAME: ``` -5. #### For using userdefined templates - Move to the `‘/dnif//trigger_plugins/mesdp/’` folder path and paste your template.xml file here. - #### Note: - Refer to default.xml template to create your customised templates - +5. #### For using userdefined templates + Move to the `‘/dnif//trigger_plugins/mesdp/’` folder path and paste your template.txt file here. + #### Note: + Refer to default.txt template to create your customised templates + diff --git a/default.txt b/default.txt new file mode 100644 index 0000000..bf15757 --- /dev/null +++ b/default.txt @@ -0,0 +1,8 @@ +"requester": "{$Name}", +"subject": "{$Subject}", +"description": "Action: {$Action} Authentication Protocol: {$AuthProtocol} Log Name: {$LogName} Login Source: {$LoginSrc} Source IP: {$SrcIP} Sub Status: {$SubStatus} System Name: {$SystemName} User : {$User} Message: {$Message}", +"status": "open", +"service": "Email", +"category": "Network", +"subcategory": "WiFi", +"requesttemplate": "Spyware Detect on PaloAlto" diff --git a/default.xml b/default.xml deleted file mode 100644 index af3a07e..0000000 --- a/default.xml +++ /dev/null @@ -1,11 +0,0 @@ - -
- {$Name} - {$Subject} - Action: {$Action} Authentication Protocol: {$AuthProtocol} Log Name: {$LogName} Login Source: {$LoginSrc} Source IP: {$SrcIP} Sub Status: {$SubStatus} System Name: {$SystemName} User : {$User} Message: {$Message} - open - Email - Network - WiFi -
-
\ No newline at end of file diff --git a/mesdp.py b/mesdp.py index 366bd25..684db1d 100644 --- a/mesdp.py +++ b/mesdp.py @@ -3,7 +3,8 @@ import requests import logging import json -import xml.etree.ElementTree as ET +import ast +from pprint import pprint path = os.environ["WORKDIR"] @@ -13,57 +14,74 @@ mesdp_server = cfg['trigger_plugin']['MESDP_SERVER'] mesdp_port = cfg['trigger_plugin']['MESDP_PORT'] mesdp_name = cfg['trigger_plugin']['MESDP_NAME'] - def select_template(dt,tmp_name): try: with open(path+"/trigger_plugins/mesdp/"+tmp_name, "r") as f: - ds = str(f.read()) + ds = str(f.read()) d = dict((x[1], '~~') for x in ds._formatter_parser()) d.update(dt) - xml_content = ds.format(**d) + c = ds.format(**d) + c = c.replace("\n", "") + json_content = ast.literal_eval("{" + c + "}") + #print "printing c...",c + #json_content["requestType"] = "Service Request" + #json_content["requesttemplate"] = "Spyware Detect on PaloAlto" + json_content = {"operation": {"details": json_content}} + #pprint(json_content) url = "https://{0}:{1}/sdpapi/request?OPERATION_NAME=ADD_REQUEST&TECHNICIAN_KEY={2}".format(mesdp_server, mesdp_port, mesdp_key) - args = {'OPERATION_NAME': 'ADD_REQUEST', 'TECHNICIAN_KEY': '5D6E2445-ACA7-4FFD-862D-47C26C91CC83', 'format': 'xml', - 'INPUT_DATA': xml_content} + args = {'OPERATION_NAME': 'ADD_REQUEST', 'TECHNICIAN_KEY': mesdp_key, 'format': 'json', + 'INPUT_DATA': json.dumps(json_content)} response = requests.post(url, params=args, verify=False) - s = str(response.content) - root = ET.fromstring(s) - out = {} - out['$MESDPStatus'] = root[0][0][0][1].text - out['$MESDPMessage'] = root[0][0][0][2].text - out['$MESDPWorkOrderID'] = root[0][0][1][0].text + #print "printing response: ", response.content + resp_data = response.json() + #print "Status code: {}".format(response.status_code) + #s = str(response.content) + #root = ET.fromstring(s) + out = {} + out["$MESDPMessage"]=resp_data["operation"]["result"]["message"] + out["$MESDPStatus"]=resp_data["operation"]["result"]["status"] + + out["$MESDPWorkOrderID"]=resp_data["operation"]["Details"]["WORKORDERID"] + + ''' + out['$MESDPStatus'] = root[0][0][0][1].text + out['$MESDPMessage'] = root[0][0][0][2].text + out['$MESDPWorkOrderID'] = root[0][0][1][0].text + ''' return out - except Exception,e : + + except Exception, e: out = {} s1 = "Error in API {}".format(e) logging.error("MESDPError :{}".format(e)) - out['$MESDPErrorMessage'] = s1 + out['$MESDPErrorMessage'] = s1 + #out["$MESDPStatus"]=response.status_code + #out["$MESDPContent"]=response.content return out def create_ticket(inward_array, var_array): tmp_lst = [] var_array[0] = var_array[0].strip() - var_array[1] =str(var_array[1]).replace(" ","") + var_array[1] =str(var_array[1]).replace(" ", "") for i in inward_array: try: if var_array[1] in i: tmp_dict = {} tmp_dict.update(i) tmp_dict['$Name'] = mesdp_name - tmp_dict['$Subject'] = str(var_array[0])+str(i[var_array[1]]) + tmp_dict['$Subject'] = str(var_array[0].strip('"'))+str(i[var_array[1]]) if (len(var_array) == 3): fname = var_array[2].replace(" ", "") else: - fname ="default.xml" - d = select_template(tmp_dict,fname) + fname ="default.txt" + d = select_template(tmp_dict, fname) i.update(d) tmp_lst.append(i) except Exception, e: tmp_lst.append(i) logging.error("%s", e) return tmp_lst - -