Integrate with a push connector to connect to an external event source. Push connectors process the collected event messages and transform them to the required event format.

Before you begin

Ensure that the Event Management Connectors (sn_em_connector) plugin is installed.

Role required: evt_mgmt_admin

Note: If you are upgrading a Now Platform instance from Paris or earlier, you can use legacy listener transform scripts. See Use legacy listener transform scripts for further information.

About this task

The push connectors accept event messages that are generated by external event sources.

Configure a connector to listen to an external event source. Using a custom push connector, send the event messages through either the MID Server or the instance.

Note: You can use this generic JSON target URL to collect events:https:/<<INSTANCE>>/api/sn_em_connector/em/inbound_event?source=genericJson. This URL can be used as-is and requires that an event rule be configured.

Procedure

  1. Navigate to All > Event Management > Integrations > Push Connectors.
  2. Click New or click the push connector that you want to modify, for example, AWS or Azure.
  3. On the form, fill in the fields.
  4. In the Script section:
    • If the value selected for the Type field is MID, the Transform script field appears. In this field, specify or search for the name of the MID script include that accepts event messages that the required external event source generates and that the script parses into the required event format. Use this naming convention for the script: TransformEvents_<your source>
    • If the value selected for the Type field is Instance, the Script editor appears. In the Script editor, enter the customized script that accepts event messages that the required external event source generates and that the script parses into the required event format.
    This example shows the fields that have been transformed, being added to an event form.
    (function process(/*RESTAPIRequest*/ request, body) {
    	/*Function that receives a JSON object, adding all its fields to the Additional information object. The field name is a concatenation of the field key and the parent field key if it exists.*/
    	function updateAdditionalInfo(event, field,jsonObject,additionalInfo) {
            for (var key in jsonObject) {
                var newKey = key;
                if (field != "") {
                    newKey = field + '_' + key;
                }
    			// You can do some transformation here and set fields on the event
    			//if(key == "MySource")
    			//   event.source = jsonObject[key];
                additionalInfo[newKey] = jsonObject[key];
            }
        }
        
        try
    	{		
            gs.info("TransformEvents_generic received body:" + body);
    		var jsonObject = JSON.parse(body);
            var event = new GlideRecord('em_event');
    		event.source = "GenericJson"; //TODO: Need to define
            event.event_class = "GenericJsonClass"; //TODO: Need to define
            event.severity = "5";
    		
            var additionalInfo = {};
            updateAdditionalInfo(event, "",jsonObject,additionalInfo);
    		/*Iterates over Additional information JSON object and adds all nested objects' fields as fields of the Additional information object*/
            var notDone = true;
            while (notDone) {
                notDone = false;
                for (var key in additionalInfo) {
                    if (Object.prototype.toString.call(additionalInfo[key]) == '[object Object]') {
                        notDone = true;
                        updateAdditionalInfo(event, key,additionalInfo[key],additionalInfo);
    					additionalInfo[key] = "";
                    }
                }
            }
    		gs.info("TransformEvents_generic generated additional information:" + JSON.stringify(additionalInfo));
            event.additional_info = JSON.stringify(additionalInfo);
            event.insert();
    	}
    	catch(er){
    		gs.error(er);
    		status=500;
    		return er;
    	}
    	return "success";
    })(request, body);