AppSense EM: Node Groups and If..Then..Else

Please note the wording of conditions in AppSense 8.5 onward has changed to make things a bit clearer. However 8.4 and below have the wording highlighted here.

Issue

When using Node Groups with If..Then..Else conditions as nested actions you may find that sub nodes will never execute no matter what order of conditioning you try.not-sure-if-its-a-bug-or-a-feature

Node Groups act like any other node in most respects with a few significant exceptions;

  • All nested actions within the Node Group are executed prior to any sub nodes.
    As you can imagine a badly written script could very easily add delays to any nested actions.
  • Only reusable nodes can be nested within a Node Group, no individual actions.
    All other actions must be added as sub nodes dependent on nested actions completing.
  • All conditioning nested within the node group must return a true result.
    As covered in a previous post regarding scripting within EM; scripts by default will always return a true result without proper exit codes.

The condition that all conditioning within a node group must return a true result means technically the node group is working exactly as it is intended to do so. A support call to AppSense will yield the result of “working as intended”.

Reproducing the issue

In this section we will reproduce the issue in AppSense Environment Manager 8.4. Please feel free to skip this section if you would prefer to go straight to the solution below.

First we will create a User Process Start rule for notepad.exe.

The reason for this is that we can repeat testing quickly without having to initiate a full log off and log on process.The node can simply be moved to the relevant section in the Logon node when satisfied it is behaving correctly.

Please bear in mind when using this approach that a full session has already been loaded. When performing any actions take into account timing of processes and services being launched at logon.

1. Open Environment Manager Console
2. Create a new User Process rule
a. Navigate to
User\Process Started
  b. Right click
Process Started
  c. Click
Node
AppSenseEM_IfThenElse_UserProcessNotepad_2_15012015
3. Choose a process name
a. Condition: Equal to (Default)
b. Match: notepad.exe
c. Click
Ok
AppSenseEM_IfThenElse_UserProcessNotepad_3_15012015
4. Rename node to notepad.exe (Best Practice: Give nodes meaningful names)
a. Right Click newly created node
b. Click
Rename
  c. Name the node
notepad.exe
AppSenseEM_IfThenElse_UserProcessNotepad_4_15012015
The next stage is to create a Reusable Node to nest in our Node Group
1. Navigate to Library\Reusable Nodes
2. Create a new Node
a. Right click Reusable Nodes
b. Click Node
c. Name the node
IfThenElse_Reusable
AppSenseEM_IfThenElse_Reusable_2_15012015
3. Create the If..Then..Else rule
a. Click the newly create IfThenElse_Reusable node
b. Right click in the blank space within the Actions tab \
c. Click Conditions
d. Click Flow Control
e. Click
If Condition
AppSenseEM_IfThenElse_Reusable_3_15012015 
For our rule we will use a simple IF folder exists to be our condition to test the logic.
4. If Condition Expression builder
a. Click Conditions in the top left of the window
b. Click File & Folder
c. Click
Folder Exists
AppSenseEM_IfThenElse_Reusable_4a_15012015

d. Condition: Does not exist
e. Folder: C:\Test\IF_Condition
f. Description:
C:\Test\IF_Condition folder does NOT exist
g. If group description: IfThenElse Test
h. Click
Ok
AppSenseEM_IfThenElse_Reusable_4b_15012015
Now we need to nest an action under this condition to check if it is executed
5. Create IF test action
a. Right click If C:\Test\IF_Condition folder does NOT exist
b. Click Actions
c. Click File & Folder
d. Click Create folder
AppSenseEM_IfThenElse_Reusable_5a_15012015
e. Create folder
– Click Create Folder tab
– Folder: C:\Test\IF_Condition
f. Click
Ok
AppSenseEM_IfThenElse_Reusable_5f_15012015
Nest an action to check if the Else condition is executed
6. Create Else test action
a. Right click Else
b. Click Actions
c. Click File & Folder
d. Click Create folder
e. Create folder
– Click Create Folder tab
– Folder: C:\Test\Else_Condition
7. Click Ok
The finished condition should look as below
AppSenseEM_IfThenElse_Reusable_Final_15012015
Create a Node Group within our User Process notepad.exe
1. Create a Node Group under notepad.exe
a. Navigate to
User\Process Started\notepad.exe
  b. Right click
notepad.exe
  c. Click Node Group
AppSenseEM_IfThenElse_NodeGroup_8_15012015
d. Name the Node Group
IfThenElse
AppSenseEM_IfThenElse_NodeGroup_8d_15012015 
2. Add Reusable Condition IfThenElse node to Node Group IfThenElse
a. Navigate to
User\Process Started\notepad.exe
  b. Click Node Group
IfThenElse
  c. Right Click in a white space under Reusable Nodes
d. Click Node Group Member
  e. Click IfThenElse_Reusable
AppSenseEM_IfThenElse_NodeGroup_2g_15012015
 
If you would like to check your work thus far;Save, Unlock and Deploy to a client using the method you prefer (management server, live configuration on the machine, exported MSI etc..)
The final piece to add is to nest another test action in a sub node of the Node Group, the action will fail but this is expected.
1. Create new sub node of IfThenElse Node Group
a. Navigate to
User\Process Started\notepad.exe
  b. Right Click Node Group
IfThenElse
  c. Click Node
AppSenseEM_IfThenElse_SubNode_1d_15012015
  d. Name the node IfThenElse_Subnode 
5. Create Sub Node test action
a. Click IfThenElse_Subnode
b. Right Click in the blank space within the Actions tab
  c. Click Actions
d. Click File & Folder
e. Click Create folder
 AppSenseEM_IfThenElse_SubNode_5d_15012015
f. Create folder
– Click Create Folder tab
– Click Add
– Folder: C:\Test\SubNode_Executed
g. Click
Ok
AppSenseEM_IfThenElse_SubNode_5f_15012015

Testing the Scenario

1. Run Notepad.exe
a. Press
Windows + R
  b. Type
Notepad.exe
  c. Click Ok
2. Navigate to C:\Test
You will notice both IF_Condition and SubNode_Executed have been created.AppSenseEM_IfThenElse_FailTest_1_15012015This is because no action has returned a fail condition.
3. Delete C:\Test\SubNode_Executed
4. Run Notepad.exe
This time however you will notice SubNode_Executed has not been created.However we have evidence that the Node Group has been processed since the Else_Condition folder has been created.AppSenseEM_IfThenElse_FailTest_2_15012015

This is because the condition C:\Test\IF_Condition folder does NOT exist is now false, causing the whole node group to stop processing sub nodes.

Solution

Logically the above scenario is actually working as intended, one of the conditions are failing and we have told the EM Agent that in the case of a fail condition stop processing sub nodes.

The confusion creating a If..Then..Else condition within a node group is actually caused by poor UI design on the part of AppSense.

What needs to be done is to untick (the default setting) the stop if fails option within the If condition.

This is because the If..Then..Else condition is inherently performing the Stop If Fails conditioning by its very nature.By enabling Stop If Fails within condition what we are actually doing is performing a second conditional argument within the IF..Then..Else condition.AppSenseEM_IfThenElse_Solution_1_15012015By disabling the Stop If Fail option you will find the group starts to behave as expected.AppSenseEM_IfThenElse_FixSolution_2e_15012015.jpg

Fixing our test scenario

1. Navigate to \Reusable Nodes\IfThenElse_Reusable
2. Edit If Condition
a. Expand If Else Group
b. Right Click C:\Test\IF_Condition folder does NOT exist
c. Click Edit

AppSenseEM_IfThenElse_FixSolution_2c_15012015
d. Uncheck Stop if fails
  e. Click Ok

AppSenseEM_IfThenElse_FixSolution_2e_15012015

Testing the Scenario

1. Run Notepad.exe
a. Press
Windows + R
  b. Type
Notepad.exe
  c. Click Ok
2. Navigate to C:\Test
You will notice both IF_Condition and SubNode_Executed have been created.AppSenseEM_IfThenElse_FailTest_1_15012015.
3. Delete C:\Test\SubNode_Executed
4. Run Notepad.exe
This time however you will notice SubNode_Executed has been created.

AppSenseEM_IfThenElse_PassTest_2_15012015

Advertisements

2 responses to “AppSense EM: Node Groups and If..Then..Else

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s