Website monitoring with SimWorkflow
This tutorial shows how to create and test a workflow definition that monitors a website for uptime. Use third party APIs to send email alerts, SMS alerts, and Slack messages when the website is down.
- Prerequisites
- Step 1: Sign up to an SMS gateway
- Step 2: Setup sandbox destination phone numbers
- Step 3: Create Identity and Access Management (IAM) policy to publish SMS messages
- Step 4: Create IAM user with AmazonSNSPublishSMS policy
- Step 5: Create access key and secret access key for user_to_send_sms user
- Step 6: Create AWS credentials
- Step 7: Sign up to Slack
- Step 8: Create a Slack app
- Step 9: Request scopes for Slack app
- Step 10: Installing and authorizing the Slack app
- Step 11: Create Slack OAuth 2.0 credentials
- Step 12: Create SimWorkflow Personal Access Token
- Step 13: Create SimWorkflow Bearer token credentials
- Step 14: Create SimWorkflow workflow definitions
- Step 15: Define variables
- Step 16: Run the workflow definition
- Step 17: Define the schedule with cron expression
- Summary
Prerequisites
To perform the steps in this tutorial, you must already have the following:
- An account with a third-party SMS gateway to send SMS messages.
- An account with Slack to send Slack messages.
- A SimWorkflow account that you can log in to create pages and workflow definitions.
Step 1: Sign up to an SMS gateway
An SMS gateway is required to send SMS messages.
For this tutorial, we're using Amazon Simple Notification Service (SNS).
If you're a first-time user of AWS, your first step is to sign up for an AWS account.
Step 2: Setup sandbox destination phone numbers
- Login to AWS.
- Navigate to AWS Console.
- Select an AWS region.
- Click Services and select Simple Notification Service.
- Under Mobile left menu, click Text messaging (SMS).
- Click Add phone number button in Sandbox destination phone numbers section.
- Enter the phone number to receive text SMS messages.
- Click Add phone number button.
Step 3: Create Identity and Access Management (IAM) policy to publish SMS messages
-
On AWS Console.
-
Click Services and select IAM.
-
Under Access management left menu, click Policies.
-
Click Create policy button in Policies section.
-
Select JSON Policy editor.
-
Define the following policy to allow
sns:Publish
action:{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "sns:Publish" ], "Resource": "*" } ] }
-
Click Next button.
-
Enter the policy name. For this tutorial, we're using
AmazonSNSPublishSMS
. -
Click Create policy button.
Step 4: Create IAM user with AmazonSNSPublishSMS policy
- On AWS Console.
- Click Services and select IAM.
- Under Access management left menu, click Users.
- Click Create user button in Users section.
- Enter the username. For this tutorial, we're using
user_to_send_sms
. - Click Next button.
- Select Attach policies directly for Permissions options.
- Search for
AmazonSNSPublishSMS
and check its checkbox. - Click Next button.
- Click Create user button.
Step 5: Create access key and secret access key for user_to_send_sms user
- On AWS Console.
- Click Services and select IAM.
- Under Access management left menu, click Users.
- Select
user_to_send_sms
from the Users section. - Click Create access key for Access key 1 in Summary section.
- Select Command Line Interface (CLI) for Use case.
- Check Confirmation checkbox.
- Click Next button.
- Enter the description.
- Click Next button.
- Copy Access key, we'll paste it later.
- Copy Secret access key, we'll paste it later.
- Click Done button.
Step 6: Create AWS credentials
-
Log in to the SimWorkflow.
-
Navigate to Credentials.
-
Click Create credentials button.
-
Select AWS tab.
-
Enter Amazon SNS in the Name field.
-
Paste the Access key in the Access key ID field.
-
Paste the Secret access key in the Secret access key field.
-
Click Create credentials button.
We'll use this credentials in the workflow definition when we integrate with AWS SNS to send SMS alerts.
Step 7: Sign up to Slack
If you're a first-time user of Slack, your first step is to sign up for a Slack account.
Step 8: Create a Slack app
-
On the Your Apps page, select Create New App.
-
Select From scratch.
-
Enter SimWorkflow in the App Name field.
-
Select the Workspace where you'll be developing your app.
-
Select Create App.
Step 9: Request scopes for Slack app
-
Within OAuth & Permissions, scroll down to Scopes.
-
Under Bot Token Scopes, select Add an OAuth Scope.
-
To allow your app to post messages, add the
chat:write
scope.
Step 10: Installing and authorizing the Slack app
-
Return to the Basic Information section of the app management page.
-
Install your app by selecting the Install to Workspace button.
-
You'll now be sent through the Slack OAuth flow. Select Allow on the following screen.
-
After installation, navigate back to the OAuth & Permissions page.
-
Click Add New Redirect URL button under Redirect URLs.
-
Enter https://www.simworkflow.com/credentials/callback to the input field and click Add button.
-
Return to the Basic Information section of the app management page.
-
Under App Credentials, copy Client ID and Client Secret.
Step 11: Create Slack OAuth 2.0 credentials
- Log in to the SimWorkflow.
- Navigate to Credentials.
- Click Create credentials button.
- Select OAuth 2.0 tab.
- Select Slack from the Provider dropdown.
- Enter Slack in the Name field.
- Paste the Client ID in the Client ID field.
- Paste the Client Secret in the Client secret field.
- Enter chat:write to the Scopes field.
- Click Create credentials button.
We'll use this credentials in the workflow definition when we integrate with Slack to send alerts.
Step 12: Create SimWorkflow Personal Access Token
- Log in to the SimWorkflow.
- Navigate to Settings > Personal access tokens.
- Enter SimWorkflow in the Name field.
- Enter 30 in the Token expiration in days fields.
- Click Create personal access token button.
- Copy the Token text.
Step 13: Create SimWorkflow Bearer token credentials
- Log in to the SimWorkflow.
- Navigate to Credentials.
- Click Create credentials button.
- Select Bearer token tab.
- Enter SimWorkflow in the Name field.
- Paste the Token in the Bearer token field.
- Click Create credentials button.
We'll use this credentials in the workflow definition when we integrate with SimWorkflow to fetch workflow details.
Step 14: Create SimWorkflow workflow definitions
Step 14.1: Plan error handling workflow definition
We consider the website is down when the website URL we're checking returns a non 2xx
response status.
When a website is down, the error handling workflow definition will be started to perform the following tasks:
- Fetch the failed workflow for the failure state.
- Then execute the following parallel tasks:
- Send Email alert.
- Send SMS alert.
- Send Slack alert.
Step 14.2: Define error handling workflow definition
-
Log in to the SimWorkflow.
-
Navigate to Workflow definitions.
-
Click Create workflow definition button.
-
Select General tab of the workflow definition.
-
Enter Error handling to the Name field.
-
Click HTTP Task to add a system task and name it Fetch WF details.
-
Connect the Start task to the Fetch WF details task.
-
Click Fetch WF details task and select Input Parameters tab.
-
Enter the following JSON object to the Input parameters field:
{ "failureWorkflow": "${workflow.input['swf:failureWorkflow']}" }
The system will reference the "swf:failureWorkflow" field from the workflow input to the "failureWorkflow" field.
-
Click Fetch WF details task and select Configuration tab.
-
Select SimWorkflow (Bearer token) for Credentials field.
-
Enter the following JSON object to the HTTP request field:
{ "url": "https://api.simworkflow.com/workflow-definitions/${failureWorkflow['swf:workflowDefinitionId']}", "method": "GET", "headers": { "Accept": "application/json", "Content-Type": "application/json" } }
The HTTP request configuration will call the SimWorkflow API to retrieve the workflow definition of the failed workflow.
-
Click Fetch WF details task and select Routing tab.
-
Check Take all routes for Take routes of field.
-
Click Email Task to add a system task and name it Email.
-
Connect the Fetch WF details task to the Email task.
-
Click Email task and select Input Parameters tab.
-
Enter the following JSON object to the Input parameters field:
{ "text": "! Workflow '${['Fetch WF details'].output.body.name}' <https://www.simworkflow.com/workflows/${workflow.input['swf:failureWorkflow']['swf:workflowId']}> failed due to: ${workflow.input['swf:failureWorkflow']['swf:cause']}", "subject": "Workflow ${['Fetch WF details'].output.body.name} failed", "fromName": "SimWorkflow", "toAddress": "${['swf:variables'].emailAddress}" }
-
Click Email task and select Configuration tab.
-
Enter the following JSON object to the Email field:
{ "text": "${text}", "subject": "${subject}", "fromName": "${fromName}", "toAddresses": [ "${toAddress}" ] }
-
Click HTTP Task to add a system task and name it Slack.
-
Connect the Start task to the Slack task.
-
Click Slack task and select Input Parameters tab.
-
Enter the following JSON object to the Input parameters field:
{ "body": { "text": "Workflow *${['Fetch WF details'].output.body.name}* failed due to `${workflow.input['swf:failureWorkflow']['swf:cause']}`", "channel": "${['swf:variables'].slackChannelId}" } }
-
Click Slack task and select Configuration tab.
-
Select Slack (OAuth 2.0) for Credentials field.
-
Enter the following JSON object to the HTTP request field:
{ "url": "https://slack.com/api/chat.postMessage", "body": "${body}", "method": "POST", "headers": { "Accept": "application/json", "Content-Type": "application/json" } }
The HTTP request configuration will call the Slack API to post the alert message to the Slack channel.
-
Click HTTP Task to add a system task and name it SMS.
-
Connect the Start task to the SMS task.
-
Click SMS task and select Input Parameters tab.
-
Enter the following JSON object to the Input parameters field:
{ "message": "Workflow '${['Fetch WF details'].output.body.name}' failed due to: ${workflow.input['swf:failureWorkflow']['swf:cause']}", "mobileNumber": "${['swf:variables'].mobileNumber}", "senderId": "SimWorkflow", "awsRegion": "${['swf:variables'].awsRegion}" }
-
Click SMS task and select Configuration tab.
-
Select Amazon SNS (AWS) for Credentials field.
-
Enter the following JSON object to the HTTP request field:
{ "url": "https://sns.${awsRegion}.amazonaws.com/?Action=Publish&Message=${jsonata:$encodeUrl(message)}&PhoneNumber=${jsonata:$encodeUrl(mobileNumber)}&MessageAttributes.entry.1.Name=AWS.SNS.SMS.SenderID&MessageAttributes.entry.1.Value.DataType=String&MessageAttributes.entry.1.Value.StringValue=${jsonata:$encodeUrl(senderId)}&Version=2010-03-31&AUTHPARAMS", "method": "GET" }
The HTTP request configuration will call the AWS API to publish the SMS message to the mobile phone number.
-
Click End Task to add a system task and name it End.
-
Connect the Email task to the End task.
-
Connect the Slack task to the End task.
-
Connect the SMS task to the End task.
-
Click End task and select Routing tab.
-
Check Collector task checkbox.
-
Click Save button.
-
Toggle the Enable checkbox to enable the workflow definition.
Step 14.3: Define monitor website workflow definition
-
Log in to the SimWorkflow.
-
Navigate to Workflow definitions.
-
Click Create workflow definition button.
-
Select General tab of the workflow definition.
-
Enter Monitor website to the Name field.
-
Select Error Handling tab of the workflow definition.
-
Select Monitor website error handling to the Workflow definition field.
-
Click HTTP Task to add a system task and name it Ping website.
-
Connect the Start task to the Ping website task.
-
Click Ping website task and select Input Parameters tab.
-
Enter the following JSON object to the Input parameters field:
{ "checkEndpoint": "${['swf:variables'].urlToCheck}" }
-
Click Ping website task and select Configuration tab.
-
Enter the following JSON object to the HTTP request field:
{ "url": "${checkEndpoint}", "method": "GET" }
The HTTP request configuration will call the
checkEndpoint
. The workflow will complete if the endpoints return a2xx
response status, otherwise the workflow will fail. -
Click Save button.
-
Toggle the Enable checkbox to enable the workflow definition.
Step 15: Define variables
-
Log in to the SimWorkflow.
-
Navigate to Workflow definitions.
-
Click Variables menu item from the three dots (more options) menu of the Monitor website workflow definition.
Step 15.1: URL to check
-
Enter urlToCheck in the Variable key field.
-
Enter the full URL monitor in the Variable value field.
-
Click Save variable button.
Step 15.2: Email address
-
Enter emailAddress in the Variable key field.
-
Enter the email address to receive the notification in the Variable value field.
-
Click Save variable button.
Step 15.3: Mobile phone number
-
Enter mobileNumber in the Variable key field.
-
Enter the mobile number to receive the SMS message in the Variable value field.
-
Click Save variable button.
Step 15.4: AWS region
-
Enter awsRegion to the Variable key field.
-
Enter AWS region to the Variable value field.
-
Click Save variable button.
Step 16: Run the workflow definition
- Log in to the SimWorkflow.
- Navigate to Workflow definitions.
- Click Run menu item from the three dots (more options) menu of the Monitor website workflow definition.
- The system checks the website and the workflow Completed.
- If the check fails, the error handling workflow definition will be started to send email alert, SMS alert, and Slack alert.
Step 17: Define the schedule with cron expression
-
Log in to the SimWorkflow.
-
Navigate to Workflow definitions.
-
Click Schedule trigger menu item from the three dots (more options) menu of the Monitor website workflow definition.
-
Turn on Schedule trigger on field.
-
Select a user for User to start the workflow as field.
-
Enter 0 */2 * ? * * to the Schedule cron expression field. This will execute the check every two minutes.
-
Click Save schedule trigger button.
Summary
You've now successfully completed all the steps necessary to define a workflow definition to monitor a website for uptime. You've learned how to integrate with a third party APIs with different authentication methods: AWS, OAuth 2.0, Bearer token. As a result, you are able to have an automated process to check a website and send alerts when the website is down.