logo

NJP

Microsoft Message Queuing(MSMQ) Check Activity - Get more than one result in one transaction

Import · Mar 06, 2019 · article

I would like to share some information about creating an activity to check more than one MSMQ and getting more than one result in one transaction. By using this activity, save the number of licensed transactions.

Details are below;

Create New Activity

-Open Workflow Editor and add new activity under Custom Tab.

-Select PowerShell.

image

General Tab

-Set a name for the activity.

-Click Continue.

image

Inputs Tab

-Add 2 inputs which are hostname and msmqcheck_script.

image

Execution Command Tab

-Set hostname to the target host.

-Set msmqcheck_script to command.

image

Outputs Tab

-Create two outputs which are output and errorMessages.

-Determine the parsing rule for outputs.

image

-Click Go to Post-Processing.

Post Processing Tab

In this tab, the output should be parsed by using javascript.

(Note: If not click Go to Post-Processing under outputs tab, Post Processing tab will not be visible.)

image

Code1

var array = [];// Start to get output and split breakline.var desc = executionResult.output;var sdesc = desc.split('\n');for(var i =0;i-1){var ldesc = sdesc[i];//Split row by row.Because result will be like hostname\\msmqname 10var lastdesc = ldesc.split(' ');if(lastdesc[1]!=0){array.push(ldesc+'\n');}}}//If msmq’ value is empty, output will be 0.if(array.toString()!=''){activityOutput.output = array.toString();}else if(array.toString()==''){activityOutput.output = '0';

}

Conditions Tab

No Message -> activityOutput.errorMessages == null && activityOutput.output == 0Has Message -> activityOutput.errorMessages == null && activityOutput.output != 0

Error -> activityOutput.errorMessages == null && activityOutput.output != 0

image

After creating MSMQ Check activity, create a workflow to orchestrate it.

MSMQ Check Workflow

-Create workflow and add MSMQ Check activities and Run Script.

image

MSMQ_Check Activity Input

- Set workflow.scratchpad.msmqcheck_script to Msmqcheck script field.

- Set host name that this activity runs.

image

MSMQ Check Workflow Input

-Create workflow input that set MSMQs name.

-This column name used in Run Script.

image

Run Script (MSMQ List to Check)

This Run Script get MSMQ list and prepare PowerShell script that can change due to inputs dynamically.

image

Code2

// u_msmqs_to_be_checked – inputs column name of field

//This code get all msmqs. Firstly, get host name and msmqs name. Then, system is created Powershell script.

var msmqs_list = workflow.inputs.u_msmq_list;var arrayUtil = new ArrayUtil();var array = [];var msmqdata = [];var list = msmqs_list.split(';');for(var i =0;i-1){var msmqrec = list[i];var host = msmqrec.substr(0, msmqrec.indexOf('\\'));msmqdata.push([host,msmqrec]);if(arrayUtil.contains(array, host)){}else{array.push(host);}}}var script = '';for(t=0;t0){script= script +"\";$queues | ft -property Name,MessagesInQueue;";}if(script == '') script = "$queues = Get-WmiObject Win32_PerfRawData_MSMQ_MSMQQueue -computer "+array[t]+" -Filter ";else script = script + "$queues = Get-WmiObject Win32_PerfRawData_MSMQ_MSMQQueue -computer "+array[t]+" -Filter ";var z = 0;for(k=0;k1){//gs.log('array[t]1='+array[t]);script = script + " or name = \'"+msmqdata[k][1]+"\'";}//gs.log('ep='+msmqdata[k][1]);}}}script = script + "\";$queues | ft -property Name,MessagesInQueue";workflow.info("script="+script);

workflow.scratchpad.msmqcheck_script = script;

Example of the PowerShell script that created by javascript is below.

Get-WmiObject Win32_PerfRawData_MSMQ_MSMQQueue -computer hostname1 -Filter "name = 'hostname1\\msmq1' or name = 'hostname1\\msmq2' or name = 'hostname1\\msmq3' '";$queues | ft -property Name,MessagesInQueue;$queues = Get-WmiObject Win32_PerfRawData_MSMQ_MSMQQueue -computer hostname2 -Filter "name = 'hostname2\\msmq4'";$queues | ft -property Name,MessagesInQueue

image

View original source

https://www.servicenow.com/community/now-platform-articles/microsoft-message-queuing-msmq-check-activity-get-more-than-one/ta-p/2311205