When building a workflow in InsightConnect, you’ll see that one of the available step types is “Loop.” So what exactly is a loop, and when would you use it? Let’s delve a little further into them so we can see.
There are two types of loops in InsightConnect workflows under the Loop step type: Repeat Over and Repeat Until. For now we’re going to focus on the Repeat Over type since it’s most commonly used.
Repeat Over
Do you have a bunch of data in your workflow, and want to do something with each piece of that data? This is the loop type you’re looking for. It takes a list or array of data (you can think of list and array as the same thing) and iterates through it, meaning that it executes the steps that you’ve configured within the loop for each item in the list. Let’s look at an example to better demonstrate.
In my workflow, I have a list that contains three IP’s. Here’s my list:
[198.51.84.100, 198.51.85.100, 198.51.86.100]
I want to block each of these IP’s with Palo Alto (or if you use a different tool, imagine that one). Since I want to do it for every item in my list, I’m going to configure a Repeat Over loop by clicking + in the builder to add a new step, then Loop to configure one.
Here’s the Repeat Over Loop configuration. The “Get IPs.ips” variable comes from the Get IPs step you can see in the image below, where we’re extracting a list of IP’s from the body of an email. This variable refers to the list of IP’s I mentioned above that I want to block. In our workflow, when we say we’re going to “repeat over” this variable, it means we’re going to execute all of the steps inside this loop for every item in the list.
“Process IPs” is the newly configured loop step. If I click on it, I get taken “inside” that loop where I can configure which steps will occur for each item in my list when the loop executes.
I created two steps inside my loop. The first one blocks whatever IP we pass in, and the second one prints out whether that block was successful on an artifact card.
Now that we have our loop setup, we’re ready to go. Here’s a basic idea of what the logic will be when this loop is executed in our workflow:
- Extract the first item in the list that we specified (this would be the value 198.51.84.100)
- Block that IP in our “Block IP” step
- Print out whether we successfully blocked that IP
- Repeat!
The “Repeat!” means we’re going to go back to the beginning, get the next item in our IP list (so 198.51.85.100), then do the same steps all over again. It’ll keep going until it gets through our entire list. We have three items in our list so the loop will execute these steps three times, but imagine doing this with hundreds of items in your list! And once the loop finishes processing the last item in the list, it will “exit” the loop and continue through the rest of the workflow.
Hopefully that example helps you better understand loops and provides you with a starting point for using them in your own workflows. If you’re looking to expand upon your loop usage, you can also check out the Repeat Until loop type, which allows you to define exactly how many times your loop will execute. Keep an eye out for another post where we dive a little deeper into Repeat Until loops.