
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 03-06-2019 03:08 PM
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.
General Tab
-Set a name for the activity.
-Click Continue.
Inputs Tab
-Add 2 inputs which are hostname and msmqcheck_script.
Execution Command Tab
-Set hostname to the target host.
-Set msmqcheck_script to command.
Outputs Tab
-Create two outputs which are output and errorMessages.
-Determine the parsing rule for outputs.
-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.)
Code1
var array = [];
// Start to get output and split breakline.
var desc = executionResult.output;
var sdesc = desc.split('\n');
for(var i =0;i<sdesc.length;i++){
//Get row which has \\ because msmq’s format should hostname\\msmqname
if(sdesc[i].indexOf('\\')>-1){
var ldesc = sdesc[i];
//Split row by row.Because result will be like hostname\\msmqname 10
var 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 == 0
Has Message -> activityOutput.errorMessages == null && activityOutput.output != 0
Error -> activityOutput.errorMessages == null && activityOutput.output != 0
After creating MSMQ Check activity, create a workflow to orchestrate it.
MSMQ Check Workflow
-Create workflow and add MSMQ Check activities and Run Script.
MSMQ_Check Activity Input
- Set workflow.scratchpad.msmqcheck_script to Msmqcheck script field.
- Set host name that this activity runs.
MSMQ Check Workflow Input
-Create workflow input that set MSMQs name.
-This column name used in Run Script.
Run Script (MSMQ List to Check)
This Run Script get MSMQ list and prepare PowerShell script that can change due to inputs dynamically.
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<list.length;i++){
if(list[i].indexOf('\\')>-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;t<array.length;t++){
if(t>0){
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;k<msmqdata.length;k++)
{
if(arrayUtil.contains(msmqdata[k],array[t])){
z++;
if(z==1) {
//gs.log('array[t]='+array[t]);
script = script + "\"name = \'"+msmqdata[k][1]+"\'";}
else if(z>1){
//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
- 996 Views