# -*- coding: utf-8 -*- # pragma pylint: disable=unused-argument, no-self-use """Function implementation""" import logging from resilient_circuits import ResilientComponent, function, handler, StatusMessage, FunctionResult, FunctionError class FunctionComponent(ResilientComponent): """Component that implements Resilient function 'testing_integration_function""" def __init__(self, opts): """constructor provides access to the configuration options""" super(FunctionComponent, self).__init__(opts) self.options = opts.get("testing_process", {}) @handler("reload") def _reload(self, event, opts): """Configuration options have changed, save new values""" self.options = opts.get("testing_process", {}) @function("testing_integration_function") def _testing_integration_function_function(self, event, *args, **kwargs): """Function: Testing ITSM Integration""" try: # Get the wf_instance_id of the workflow this Function was called in wf_instance_id = event.message["workflow_instance"]["workflow_instance_id"] # Get the function parameters: incident_id = kwargs.get("incident_id") # number description = self.get_textarea_param(kwargs.get("description")) # textarea log = logging.getLogger(__name__) log.info("incident_id: %s", incident_id) log.info("description: %s", description) requestinside = {} requestinside["request"] = {} requestinside['request']['requester'] = {} requestinside['request']['requester']['name'] = "guest" requestinside['request']['subject'] = "Created From Resilent" requestinside['request']['template'] = {} requestinside["request"]['template']['name'] = "Default Request" requestinside['request']['description'] = "Testing" requestinside['request']['status'] = {} requestinside['request']['status']['name'] = "Open" jsonData = json.dumps(requestinside) # Post a new artifact to the incident, using the provided REST API client new_artifact_uri = "http://manageengineserver/sdpapi/request?&TECHNICIAN_KEY=xxxxxxxx-zxxx-xzzz-zxxx-xxxzzzyyyasa&format=json&INPUT_DATA=" + jsonData self.rest_client().post(new_artifact_uri) # PUT YOUR FUNCTION IMPLEMENTATION CODE HERE # yield StatusMessage("starting...") # yield StatusMessage("done...") results = { "success": "true" } # Produce a FunctionResult with the results yield FunctionResult(results) except Exception: yield FunctionError()