Validating a return code for heartbeat function

Hello,

I want to set up a heartbeat function to monitor the availability of a SaaS platform.

To do this, using a crownjob trigger, I send a GET request to this SaaS server every hour.

On a successful request I always receive a 5 digit code as return value: “alertID”: “12345”

Now, if anything else then a five digits code is returned, I want to start a new action that sends a notification to our help desk.

Can anyone help me how to set this up?

Thank you very much.

Hi @Sec2 , thanks for reaching out. I’d recommend checking out our docs on ending a workflow early. You should be able to add a new Node.js code step to your workflow and run something like this:

if (steps.get_request.$return_value.alertId === 12345) {
  $end("Alert code is 12345, so no need to alert")
}

This ends the workflow early when the status code is what you expect. Otherwise, the workflow would continue to the next step. So you can add an additional step after this one that runs the logic to send an alert to your helpdesk, since that step would only run if the alert code were different.

Take a look at this example workflow - someone else built an uptime checker for his app that solves a similar use case.

Let me know if that helps!

Hello Dylan,

This is clear to me, thanks a lot.
In this case, the server replies with a random 5 digits number. Is there a way to just check if the reply consist of 5 digits and not a specific number?

Kind regards,

@Sec2 yes, since you can use any JavaScript in a workflow, you can do something like this:

if (steps.get_request.$return_value.alertId.toString().length === 5) {
  $end("Alert code is 12345, so no need to alert")
}