Check the status of an external HTTP service¶
Description¶
In this tutorial you will learn how to create a script that periodically checks the availability of an external HTTP service.
The script will be executed every 30 seconds and report the service status as a boolean value.
Steps¶
1. Create an integer value script that will be executed every 10 seconds¶
root/examples/scripts/external-service/status/value.ospp
{
"name": "Service status",
"description": "The status of an external service",
"type": "BOOLEAN"
}
root/examples/scripts/external-service/status/owner.scripts
{
"moduleId": "modules.scripts.scripts-1",
"scheduledExecutions": ["0/30 * * ? * * *"],
"accessedValues": [],
"sourceFile": "root/scripts/external-service/status/script.js"
}
2. Write a script that issue an HTTP GET request to an external service and returns the result¶
root/examples/scripts/external-service/status/script.js
main();
function main() {
let result = http.doGet("http://external-service.url");
if (!result.isSuccess()) {
log.warn("The service is unavailable cause [{}].", result.getError());
}
return result.isSuccess();
}