def run(self, params={}): handler = error_handling.ErrorHelper() search = params.get(Input.SEARCH_PARAMETERS) uri = f"api/arsys/v1/entry/HPD%3AIncidentInterface/?q={search}" url = urllib.parse.urljoin(self.connection.url, uri) headers = self.connection.make_headers_and_refresh_token() result = requests.get(url, headers=headers) handler.error_handling(result) try: incident = result.json() except json.JSONDecodeError as e: raise PluginException(preset=PluginException.Preset.INVALID_JSON, data=e) try: incident_list = incident["entries"] except KeyError: raise PluginException( cause= 'The response did not contain a correctly formatted list.', assistance= "Please contact support with the status code and error information.", data=incident) return {Output.ENTRIES: komand.helper.clean(incident_list)}
def run(self, params={}): handler = error_handling.ErrorHelper() incident_id = params.pop(Input.INCIDENT_ID) uri = f"api/arsys/v1/entry/HPD%3AIncidentInterface/{incident_id}|{incident_id}" other_inputs = params.pop(Input.OTHER_INPUTS) url = urllib.parse.urljoin(self.connection.url, uri) headers = self.connection.make_headers_and_refresh_token() original_incident_response = requests.get(url, headers=headers) handler.error_handling(original_incident_response) try: original_incident = komand.helper.clean( original_incident_response.json()) except json.JSONDecodeError as e: raise PluginException(preset=PluginException.Preset.INVALID_JSON, data=e) values = dict() for key, value in self._CONVERSION_KEY.items(): if params.get(value): values.update({key: params[value]}) values.update(other_inputs) try: for key, value in values: original_incident.get("values")[key] = value except KeyError: raise PluginException( cause="One or more of the input keys is invalid.", assistance= "Check that the input keys in 'Other Inputs' are all valid.", data=values, ) result = requests.put(url, headers=headers, json=original_incident) handler.error_handling(result) original_incident_response = requests.get(url, headers=headers) # If we made it this far, and this call fails, something really unexpected happened. if not original_incident_response.status_code == 200: raise PluginException(preset=PluginException.Preset.SERVER_ERROR, data=original_incident_response.text) try: original_incident = original_incident_response.json() except json.JSONDecodeError as e: raise PluginException(preset=PluginException.Preset.INVALID_JSON, data=e) return {Output.INCIDENT: komand.helper.clean(original_incident)}
def run(self, params={}): handler = error_handling.ErrorHelper() values = {"values": {"z1D_Action": "CREATE"}} other_inputs = params.pop(Input.OTHER_INPUTS) for key, value in self._CONVERSION_KEY.items(): if params.get(value): values["values"].update({key: params[value]}) values["values"].update(other_inputs) url = urllib.parse.urljoin(self.connection.url, self._URI) headers = self.connection.make_headers_and_refresh_token() result = requests.post(url, headers=headers, json=values) handler.error_handling(result) return {Output.SUCCESS: True}
def run(self, params={}): # To update the status on a ticket, we have to get the original ticket, update the status, then # send the original back with the updated status. handler = error_handling.ErrorHelper() incident_id = params.get(Input.INCIDENT_ID) status = params.get(Input.STATUS) resolution = params.get(Input.RESOLUTION) uri = f"api/arsys/v1/entry/HPD%3AIncidentInterface/{incident_id}|{incident_id}" url = urllib.parse.urljoin(self.connection.url, uri) headers = self.connection.make_headers_and_refresh_token() original_incident_response = requests.get(url, headers=headers) handler.error_handling(original_incident_response) try: original_incident = komand.helper.clean( original_incident_response.json()) except json.JSONDecodeError as e: raise PluginException(preset=PluginException.Preset.INVALID_JSON, data=e) original_incident.get("values")["Status"] = status original_incident.get("values")["z1D Action"] = "Modify" if resolution: original_incident.get("values")["Resolution"] = resolution result = requests.put(url, headers=headers, json=original_incident) handler.error_handling(result) original_incident_response = requests.get(url, headers=headers) # If we made it this far, and this call fails, something really unexpected happened. if not original_incident_response.status_code == 200: raise PluginException(preset=PluginException.Preset.SERVER_ERROR, data=original_incident_response.text) try: original_incident = original_incident_response.json() except json.JSONDecodeError as e: raise PluginException(preset=PluginException.Preset.INVALID_JSON, data=e) return {Output.INCIDENT: komand.helper.clean(original_incident)}
def run(self, params={}): handler = error_handling.ErrorHelper() incident_id = params.get(Input.INCIDENT_ID) work_note = params.get(Input.WORK_NOTE) uri = f"api/arsys/v1/entry/HPD%3AIncidentInterface/{incident_id}|{incident_id}" url = urllib.parse.urljoin(self.connection.url, uri) headers = self.connection.make_headers_and_refresh_token() try: original_incident_response = requests.get(url, headers=headers) except json.JSONDecodeError as e: raise PluginException(preset=PluginException.Preset.INVALID_JSON, data=e) handler.error_handling(original_incident_response) try: original_incident = komand.helper.clean( original_incident_response.json()) except json.JSONDecodeError as e: raise PluginException(preset=PluginException.Preset.INVALID_JSON, data=e) original_incident.get("values")["z1D Action"] = "Modify" original_incident.get("values")["z1D_Details"] = work_note result = requests.put(url, headers=headers, json=original_incident) handler.error_handling(result) original_incident_response = requests.get(url, headers=headers) # If we made it this far, and this call fails, something really unexpected happened. if not original_incident_response.status_code == 200: raise PluginException(preset=PluginException.Preset.SERVER_ERROR, data=original_incident_response.text) try: original_incident = original_incident_response.json() except json.JSONDecodeError as e: raise PluginException(preset=PluginException.Preset.INVALID_JSON, data=e) return {Output.INCIDENT: komand.helper.clean(original_incident)}
def run(self, params={}): handler = error_handling.ErrorHelper() incident_id = params.get(Input.INCIDENT_ID) get_incident_id_endpoint = f"api/arsys/v1/entry/HPD%3AHelp%20Desk/{incident_id}" url = urllib.parse.urljoin(self.connection.url, get_incident_id_endpoint) headers = self.connection.make_headers_and_refresh_token() self.logger.info(f"Attempting to retrieve: {url}") result = requests.get(url, headers=headers) handler.error_handling(result) try: incident = result.json() except json.JSONDecodeError as e: raise PluginException(preset=PluginException.Preset.INVALID_JSON, data=e) return {Output.INCIDENT: komand.helper.clean(incident)}