Flow where output contains "x" OR "y" - VisualCron - Forum

Community forum

Scott Kemmeries
2021-02-12T22:56:12Z
How can I create a task flow that will Run Notification (or otherwise send an email) with this Task Condition:
"On error" "If output" string contains value "x" OR value "y".

If I create one flow for output contains value "x" and another flow for output contains "y", both will run the same notification, meaning that notification will run twice for the same task failure.

Likewise, is the a way to run a notification (or email through any other means), if the output contains both "x" and "y"?
Joey S
2021-02-17T23:12:37Z
I feel like the best way to do what you want is with a Condition

I am making a few assumptions..
1. "output contains x" means that your Standard Output of some task is "x"
2. notification, in this context would be an email
3. you are using v9.4.5 or above and 9.5 or 9.6 looks like 9.4.5 (that is what I am using)

The 1st assumption has to exist for what I am about to suggest but the second one is maybe irrelevant. The "notification" could really be anything since this is where the condition would exist

Here is my suggestion...

Task #1 is the thing that creates your output of "x"
Task #2 is an Email Task for when the output for Task #1 = "x"
Task #3 is an Email Task for when the output for Task #1 = "y"
Add additional tasks for additional conditions

After you create those tasks you will need to create your conditions. Open Task #2 and Click on "Conditions" at the top. Then select "Add"

Description Tab = whatever you want, I would use the name of Task #1 and the fact that we are looking for "X"
Conditions tab - Click Add - Again Add a Description - Then Click the VisualCron tab
Choose Specific - Select your job name and the Task #1 name -
Down below for 'Output' is x
- do not add any quotes or double quotes unless those characters are literally in the output.
Click Ok and Ok

Make sure you check mark the condition for that task

Create a another condition for the 3rd task for output = y

The condition is an inclusive one. Meaning, Task #2 will run IF Task #1 output = x
Task #3 will run if Task #1 output = y
This way will give you one notification for "x" and one for "y"
If the output could contain "x" and "y" and you only want one notification then your first, and only condition, should not be an "is" but a "contains"



Here is an example
I have a job that looks for open ports on a server. It runs through a list of 20 ports. All should be connected. If the reply for the "Check Port" task results in "Not Connected" an email is sent
Notice the "?" icon under conditions
image.png
My "Email Results" task includes references to the previous task, the Read File Log". You can do that too by simply using {TASK(PrevTask|StdOut)}
The previous Task would be whatever thing happened right before the email task

The condition looks like this
image.png

image.png

image.png

You will see my Condition is looking at a file. But I do not have to do that. I can look at the last output instead like this
image.png

If the output from the "Check port-looped from list" task results in "Not Connected" then the email WILL send

If the output is Anything else then the email will NOT send

If I also wanted to send an email when the output was "failed" then I could do this

image.png

Notice the option changed from "Is" to "Contains"

So, to recap. Use a condition. Use "Is" if you want a specific output to generate a specific email and use "contains" if you want a list of outputs to send a single email








Casper
2021-02-18T20:31:49Z
Originally Posted by: Scott Kemmeries 

How can I create a task flow that will Run Notification (or otherwise send an email) with this Task Condition:
"On error" "If output" string contains value "x" OR value "y".

If I create one flow for output contains value "x" and another flow for output contains "y", both will run the same notification, meaning that notification will run twice for the same task failure.

Likewise, is the a way to run a notification (or email through any other means), if the output contains both "x" and "y"?



Hi, you can use logic variables for create a condition. Something like that: {LOGIC(If|String|{TASK(Active|StdOut)}|==|x|xy|{LOGIC(If|String|{TASK(Active|StdOut)}|==|y|xy|)})}

And you can use contains symbol instead equal.

IMG_20210218_233025_960.jpg
Scott Kemmeries
2021-02-18T20:39:03Z
Thank you. I think that will do what I need. However, I was hoping to do this using Flow.

Re assumptions:
- Yes, I'm looking to take an action when the task "Output" contains "x" somewhere in the output. This question would also apply to looking in "Output (error)", but for this question we'll stick with what is in the Output.
- Notification can be an email task, but what I've been using in Flow is "Run Notification", which then uses one of the global object Notifications, and that's what I would prefer to use if possible.
- Current version is 9.3 but assume I'm running 9.6 for this conversation.

Here is an example task Flow. Is there a way to do an "or" statement in the Value/Variable field, or some other option I'm not thinking of?
TaskFlow.png
Scott Kemmeries
2021-02-18T20:46:01Z
My last response was to Joey. Casper, your image did not come through but that may be what I'm looking for if you could try re-attaching the image, please.
Joey S
2021-02-18T20:59:33Z
yeah, you just put a semicolon
Scott Kemmeries
2021-02-18T22:10:32Z
I tried using a semicolon and that did not work. Is this what you meant?
TaskFlow2.png
Joey S
2021-02-18T22:16:39Z
I did not test that way. You may or may not need double quotes or some other format.

your best bet is to click the red dot to the right and then go down to User Variables and then Add

Name it whatever you want, and add your two (or more) strings

Then click save Add then Select the thing you just made and thenclick "Select"

Like this

image.png

image.png

image.png

image.png

image.png

You should look like this when you did it right
image.png
Scott Kemmeries
2021-02-19T00:00:36Z
I still can't get this to work. I removed spaces just to rule out anything weird. If I create a user defined variable like your example, with this, it never runs the notification:
create;Disposing

If I enter just "create" or just "Disposing" in the Variable value, it does run the notification. In other words, I'm still not able to get an "OR" value working.
thomas
2021-02-19T10:52:51Z
Here is a solution that works (I have tested it). It requires a tiny bit of setup the first time, but after that it is fairly easy to reuse

First of all, 'contains' in the flow is buggy. I have tried it many times, and depending on what you pass in it may or may not work. Especially if you search for strings with spaces it fails more often than not. Don't use contains here (pic below)

image.png

You have to rewrite to logic to use equals, but before that we will need a .net snippet. You can use VC variables for one OR statement, but for more than one it becomes difficult to write. Its' not hard to write the .net code. If you want to, I can push my code to the online repo and you can download it from there. Here is the code with some tests above:

image.png

Now you can use it in the flow. Here I check if the output in the task contains 'a' or 'b' separated by comma

image.png

you find the task repo stuff in here:

image.png
Scott Kemmeries
2021-02-19T15:27:14Z
Fantastic. I'm glad to hear I wasn't missing something stupid. I tried all kinds of methods with and without regex and nothing worked. If you wouldn't mind pushing your .net code to the online repo, that would certainly save me some time. Thanks for the info.
Gary_W
2021-02-19T21:58:37Z
Sorry I'm late to the party. Just for the fun of it, here's a regex that will return the string "True" if BOTH substrings "Can't create file" AND "disposing" are in the main string (STDOUT in this case):

{REGEX(Replace|{TASK(Active|StdOut)}|(\bCan't create file\b).*(\bdisposing\b)|True)}


CAVEAT: The strings must be in this order in the original string as the VC implementation of regex does not seem to support lookaheads.
NOTE: Replace will return the original input string if the match cannot be found. The \b's are word boundary's (a space, tab, end of line, etc.) This ensures just the word itself is matched, not if it happens to be part of another word (like indisposing).

Here's a regex that will return the substring if it is found OR if the other substring is found:

{REGEX(~MatchGetGroup~{TASK(Active|StdOut)}~((\bCan't create file\b)|(\bdisposing\b))~1)}


NOTE: The regex OR operator is the pipe symbol which is also the default VC function argument delimiter so it must be changed. Here I change it to a tilda. Use a character that will not be in your data.
MatchGetGroup will return NULL if a match cannot be found. The \b's are word boundary's (a space, tab, end of line, etc.) This ensures just the word itself is matched, not if it happens to be part of another word (like indisposing).

I hope this can help when using a regex in a task flow condition.
thomas
2021-02-20T16:46:08Z
I have added the function to the online task repo now

Support
2021-02-24T10:19:26Z
Thank you Thomas and Gary for your fairly complex, yet great solutions to his issue. Much appreciated!
Michael
Support
http://www.visualcron.com 

Please like  VisualCron on facebook!
Scott Kemmeries
2021-02-25T23:05:04Z
It took me a few days to test these out (and get other things done). I finally got it working, so thank you.

What worked was @  Casper 's suggestion:
On error, If other value:
{LOGIC(If|String|{TASK(Active|StdOut)}|=%|create|true|{LOGIC(If|String|{TASK(Active|StdOut)}|=%|Disposing|true|)})}
String = true

Flow using LOGIC.png

I could not get the other suggestions to work, though it's quite likely user error on my part was the reason. Note that the LOGIC method worked using either String or Boolean = true (I'm not sure which is more appropriate here?), whereas the other two did not work using either.

From what I understand from what @  Joey S said, this should have worked, but the notification was not triggered:
On error, If other value:
{REGEX(Replace|{TASK(Active|StdOut)}|(\bcreate\b).*(\bDisposing\b)|True)}
Boolean = True

Flow using REGEXs.png

And from what I understand form what @  Angie Thomas said, this should have worked but the notification was not triggered. I downloaded the "StringContains" task repository variable, selected it, then changed it to this:
On error, If other value:
{TASKREPOSITORY(d6ca5c3b-02bc-432e-8438-fa8006fe79dd|StringContainsOneOf({TASK(Active|StdOut)}(String);create,Disposing(String);,(String))|)}
Boolean = true

Flow using task repository StringContains.png
Gary_W
2021-02-26T00:19:36Z
Thanks for posting back what worked. Just to clarify:

The regex returns a string "True".

In the flow, on success - if other value
{REGEX(Replace|{TASK(Active|StdOut)}|(\bcreate\b).*(\bDisposing\b)|True)}
string = True
(choose action)
thomas
2021-02-26T07:24:51Z
Hi

You have to check the StdErr output in your case:

{TASKREPOSITORY(d6ca5c3b-02bc-432e-8438-fa8006fe79dd|StringContains({TASK(Active|StdErr)}(String);Create,Disposing(String);,(String))|)}

I changed the name to StringContains also. Download the latest from the repo, as I changed the code to be case-insensitive
Scott Kemmeries
2021-03-02T18:48:35Z
@  Angie Thomas that worked this time, so thank you. But I had to use StdOut and not StdErr, since the output I'm searching in is "Output", not "Output (error)"? For reference, this is what I used:
On error, If other value:
{TASKREPOSITORY(d6ca5c3b-02bc-432e-8438-fa8006fe79dd|StringContains({TASK(Active|StdOut)}(String);create,Disposing(String);,(String))|)}

String = true
Scott Kemmeries
2021-03-02T18:53:19Z
@Gary_W I was not able to get Joey's REGEX method to work. Probably user error on my part. I was able to get thomas's TASKREPOSITORY method to work, and also Casper's LOGIC method, as explained above.
Gary_W
2021-03-02T19:18:36Z
Great, this was an interesting one for sure.
Scroll to Top