Announcement

Collapse
No announcement yet.

Send Alert Variables To A Channel

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Send Alert Variables To A Channel

    I want to create a reusable "Alert Receiver" channel that receives alert variables and writes them to a table.

    I have an alert; rather than send an email (Actions -> Protocol -> Email), I have it configured to run the "Alert Receiver" channel (Actions -> Protocol -> Channel). Will all of the alert variables (e.g. alertId, error, channelName) be available to the channel?

  • #2
    They will not be available in the destination channel. However, your alert template will be passed as the message, so you can add them all to the template.

    Comment


    • #3
      So it sounds like I won't be able to write the name/value pairs (i.e. the values of the alert variables) to a database? They'll only be available via an email?
      Attached Files

      Comment


      • #4
        What you have in the template will be passed as the message to the channel in the same way it would appear in an email body. You can parse the message to get all of the name/value pairs.

        Comment


        • #5
          Ah, so instead of setting the Action Protocol to Email I should set it to Channel (refer to the attached screen shot) and then those variables will be available in the destination channel (in this case, the "Alert Receiver" channel)?
          Attached Files

          Comment


          • #6
            What you have in the template of your screenshot will be in msg in your transformer. You'll have to pull the values back out from there.

            You can try formatting your template as JSON or xml to make it easier to get the values by setting the appropriate data type in your channel. The way you have it now, you'll probably have to set your inbound type to Raw.

            Comment


            • #7
              I appreciate your help on this.

              I modified the alert to only pass one variable (errorMessage) to the Alert Receiver channel (for testing purposes). I attached that screen shot.

              Also attached is the Alert Receiver channel. Data types are set to Raw. I created a Source Transformer:

              Type: Mapper
              Variable: errorMessage
              Mapping: msg['errorMessage'].toString()

              The Destination contains a simple script that will (hopefully) write the value or errorMessage to a table.

              I don't have a Destination transformer.

              The error I'm getting (which has to do with the Source Transformer) is:

              Cannot call method "toString" of undefined
              Attached Files

              Comment


              • #8
                In this case, msg is your errorMessage. Look at the raw content of your message.

                Probably what I would do so that you don't have to worry about escaping is use the delimited data type, and pick some really weird delimiters that are unlikely to ever come up in your real data.

                For example,
                Code:
                Column Delimiter = |&|
                Record Delimiter = @#@
                Quote Token = $$%
                Column Names = alertId,alertName,errorMessage,errorType
                Then in your alert template,
                Code:
                ${alertId}|&|${alertName}|&|${errorMessage}|&|${errorType}
                Add as many as you want and make sure the column names in the delimited data type property match. Then you can either map them one at a time like you were trying to do, or you should be able to create all of your channelMap variables at once in a javascript step like this,

                Code:
                for each (var col in msg.row.children()) {
                    $c(col.name().toString(), col.toString());
                }

                Comment


                • #9
                  This is the new error that is being generated:

                  5be48cdf-6f87-4527-9b24-7adf39a23c82|&|Call Alert Receiver|&|
                  CHANNEL: Alert Receiver
                  CONNECTOR: sourceConnector
                  SCRIPT SOURCE: TRANSFORMER
                  SOURCE CODE:
                  504: function doScript() {
                  505: if (connectorMessage.getProcessedRawData() != null) { msg = new String(connectorMessage.getProcessedRawData()); } else { msg = new String(connectorMessage.getRawData()); }
                  506: function doFilter() { phase[0] = 'filter'; return true; }function doTransform() { phase[0] = 'transformer'; logger = Packages.org.apache.log4j.Logger.getLogger(phase[0]);
                  507:
                  508:
                  509: for each (var col in msg.row.children()) {
                  510: $c(col.name().toString(), col.toString());
                  511: }
                  512: if ('xml' === typeof msg) {
                  513: if (msg.hasSimpleContent()) {
                  LINE NUMBER: 509
                  DETAILS: TypeError: Cannot call method "children" of undefined
                  at 3bb5b51e-81ae-49b5-85ca-a40970ad0ab3:509 (doTransform)
                  at 3bb5b51e-81ae-49b5-85ca-a40970ad0ab3:533 (doScript)
                  at 3bb5b51e-81ae-49b5-85ca-a40970ad0ab3:535|&|Transformer

                  Comment


                  • #10
                    Attached are the latest files.
                    Attached Files

                    Comment


                    • #11
                      You still have your inbound/outbound type set to Raw. They need to be changed to delimited, and then you have to set up the properties like I showed.

                      Comment


                      • #12
                        Thank you for your help and patience. I got it to work, attached is the final version.

                        Again, many thanks.

                        - Kirby
                        Attached Files

                        Comment

                        Working...
                        X