cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

Pondering Automation: Back to the Basics Part 2

375
Views
10
Helpful
3
Comments
Cisco Employee

Howdy out there in automation land!!! I hope everyone is having a nice ramp down to the school year and is getting ready for summer. I know we are :) I hope plenty of you folks are heading to Cisco Live in San Diego in a few weeks too!!!! I plan to be there, so feel free to hit me up on email or look me up in the NOC. I would love to meet some of the readers and viewers and have automation chats. So what do I have for you this time? This time we are going to look at workflow creation... basic workflow creation.

 

Now what movie poster would this be you say? Well I like to think of new workflows as a "New Hope" for automation... so how about this?

 

backToBasics2MP.jpg

 

This might be a bit of a replication of some of the *really* old CPO stuff, but Action Orchestrator is a *NEW* product. It is the NextGen, but is net new as well. So I want you guys to treat this as such. On top of that, know that (unless otherwise) most of my blog going forward will be centered around AO. So get excited!

 

I will give you guys some steps to follow here... but of course there is a video below as well :)

 

Now, for this, something you can do first is create the users and targets. In the recording I already had them and talked to creating them on the fly, but you might find it easier to create them first... for this "lab" we need a web target(http) and an email server.

 

Setup Steps

  1. Create a category under Admin->Categories and use your CEC ID as the category.
  2. Create a runtime user under Account Keys. Click NEW ACCOUNT KEY, select HTTP Basic Authentication and fill out the information. The actual information does not matter. You can use test/test if you like. Click SUBMIT.
  3. Create a target under Targets. Click NEW TARGET, select HTTP Endpoint and fill out the information. Set DEFAULT ACCOUNT KEYS to your user from #2. Select HTTPS protocol. Set the HOST/IPADDRESS to jsonplaceholder.typicode.com. Set the PORT to 443 and select DISABLE SERVER CERTIFICATE VALIDATION. Click SUBMIT.
  4. Create another target under Targets. Click NEW TARGET, select SMTP Target and fill out the information. Under DEFAULT ACCOUNT KEYS click the Add New option and use your CEC email/CEC Password. Then select that user. Set the SMTP SERVER to outbound.cisco.com and set the SMTP PORT to 25.

backToBasics2Target.JPG

 

Let's Create a Basic Workflow

 

  1. Create a new workflow under Workflows. Click NEW WORKFLOW. Go down the right side and select your category under the CATEGORY drop down.
  2. Under Variables click ADD VARIABLE.
  3. For the first variable Select Data Type as String. Display Name as path and SCOPE as Input. Set the value or default as users. Click SAVE.
  4. Click ADD VARIABLE again. Select Data Type as String. Display Name as output json and SCOPE as Output. Click SAVE.
  5. Continue down to Target. Select Execute On This Target and then select HTTP Endpoint under the TARGET TYPE drop down and then select your target under the TARGET drop down.
  6. Search for http in your toolbox and drag and drop the HTTP Request activity. This is the basic activity to make any API call.
  7. Click on the HTTP Request activity. Change the DISPLAY NAME to GET JSONPATH.
  8. Scroll down to RELATIVE URL. Click the puzzle-piece icon(or insert variable reference) and a new dialog should appear called Browse Variables.
  9. Click Workflow, then Input, then you should see your path variable. Click it and then click SAVE. You should now see a VARIABLE REFERENCE showing in your RELATIVE URL field.
  10. Set METHOD to GET. Scroll down and set the CONTENT TYPE to JSON.
  11. Search for the Set Variables activity. Drag and down it BELOW your GET JSONPATH activity. Change the DISPLAY NAME to Set Output. Click ADD. For VARIABLE TO UPDATE, click the insert variable reference icon, and browse to your output variable. Workflow->Output->output json. Click SAVE.

  12. For VARIABLE VALUE NEW, click the insert variable reference icon. Now browse to Activities, then your activity GET JSONPATH, then select Body. Click SAVE.

  13. Create a new variable of type Integer and call it Status Code. It should be an output scope.

  14. Add your new variable to the Set Output activity. Click ADD below your first entry and set your Status Code Variable to the value in Activities->GET JSONPATH->Status code. Validate the workflow and run it. See what your variables are set to.



    backToBasics2Insert.JPG

 

Let's get it running in layered!!!

  1. Exit your current workflow and create a new one called "Master" or similar
  2. Scroll down and select Execute On This Target. Select HTTP ENDPOINT as the TARGET TYPE and then select your JSONPATH holder target in the TARGET select.
  3. Drag and drop your workflow to your canvas. It should look a little different.
  4. Add an input variable call name of type string.
  5. Find the JSONPath Query activity. Drag and drop it below your atomic workflow in the MASTER workflow.
  6. On the JSONPath Query activity, click insert variable reference and point it to the output of your previous activity. This should be Activites->Your Activity->output json. Click SAVE.
  7. Scroll down and click ADD below JSONPATH QUERIES. Leave the PROPERTY TYPE as String. Make the PROPERTY NAME be name and make the JSONPATH QUERY be $.[?(@.username==“<input name>)].
  8. Select the checkbox for CONTINUE WORKFLOW EXECUTION ON FAILURE
    backToBasics2JSON.JPG
  9. Go the middle icon in your toolbox, this is the Program Logic or Flow Control area.
  10. Find the Condition Block and drag and drop it below your JSONPath Query.
  11. Click the Condition Block in your canvas and change the Display Name to If found name.
  12. Click on the left most CONDITION BRANCH and you should see the conditional dialog.
  13. Under CONDITION, title it THEN, then select the insert variable reference icon for the first field and map it to Activity->JSONPath Query->Succeeded. This is a boolean value that tells us if the activity succeeded or not. Select Equals in the second field and then type true into the last field.
  14. Click on the other CONDITION BRANCH, and do the same as #5, but set the last field to false. Title this block ELSE. This will work because the JSONPath query activity will error if it does not find what you are looking for.
  15. Search for the EMAIL activity. Drag and drop it into the left CONDITION BRANCH blocks.

  16. On the email activity, go to Target and select Override Workflow Target. Select your SMTP server from above.
    Scroll down and input your email into the TO field. Input something into the SUBJECT line and something into the MESSAGE field. Something like We found them!

  17. On your email block, click the ... and select duplicate. Drag the duplicate over to the other CONDITION BRANCH. (Your else branch)

  18. Change the SUBJECT and MESSAGE to reflect not finding the person.

  19. Validate and run the workflow. Search for bill. Did it email you? Now run again and search for Bret.

 

This is a great lab that I adapted from some things I built before but I hope you were able to get through it!!! If you run into issues or have questions, please post below. As always, I have a VOD to go along with this of course :) .... now....


ONTO THE VIDEO!

 

Play recording

Password: JiEUHzy2 

 

Standard End-O-Blog Disclaimer:

 

Thanks as always to all my wonderful readers and those who continue to stick with and use CPO and now those learning AO! I have always wanted to find good questions, scenarios, stories, etc... if you have a question, please ask, if you want to see more, please ask... if you have topic ideas that you want me to blog on, Please ask! I am happy to cater to the readers and make this the best blog you will find :)

 

AUTOMATION BLOG DISCLAIMER: As always, this is a blog and my (Shaun Roberts) thoughts on CPO, AO, CCS, orchestration, and automation, my thoughts on best practices, and my experiences with the products and customers. The above views are in no way representative of Cisco or any of it's partners, etc. None of these views, etc are supported and this is not a place to find standard product support. If you need standard product support please do so via the current call in numbers on Cisco.com or email tac@cisco.com

 

Thanks and Happy Automating!!!

 

--Shaun Roberts

shaurobe@cisco.com

3 Comments
Cisco Employee

nice 

Cisco Employee

Good blog post, Shaun!  Way to organize this too so people can understand the layered approach!

Cisco Employee

I have been waiting for AO write-up from you. Thank you very much. 

CreatePlease to create content
Content for Community-Ad
August's Community Spotlight Awards