gatus icon indicating copy to clipboard operation
gatus copied to clipboard

poc: custom scripts

Open jcsaaddupuy opened this issue 1 year ago • 3 comments

Hi,

Using a custom script in a endpoint would allow anyone to support any custom target.

This MR is a poc to execute a custom script, and be able to check in conditions the exit code, the script stdout/stderr.

Example configuration :

  - name: custom script
    script:
      command: "echo -n HELLO"
    interval: 10s
    conditions:
      - "[EXIT_CODE] == 0"
      - "[STDOUT] == HELLO"

I did not implement tests yet, and the MR may not be clean. Let me know what you think !

jcsaaddupuy avatar Oct 18 '23 14:10 jcsaaddupuy

Gatus' Docker image doesn't have bash installed though, nor does it have curl, wget, echo, etc.

TwiN avatar Oct 18 '23 22:10 TwiN

Indeed. It's a good thing to keep the default image as light as possible.

But isn't it only a runtime issue?

As a gatus user, it's totally possible to either extend the base image, or build a docker image with a more complex setup and install gatus in it. This feature can stay totally optional.

Supporting custom script would be a simple way to let end-users implement usecases that are not covered out of the box by gatus.

For example, in my case, I need to check the correct execution of some pipelines persisting data in a bigquery database. With this feature, I'm able to implement a SQL check based on a python script, delegating all the setup/authentication mechanism outside of gatus.

That could be extended to others cases (for ex: having checks based on complex api calls, proprietary systems/...) while keeping the impact on gatus codebase low - we just check for the exit code after all :)

jcsaaddupuy avatar Oct 19 '23 08:10 jcsaaddupuy

To add more material on this proposal, one could build a custom image but still using gatus from the last official image :

FROM busybox # or any other base image, for ex python

COPY --from=twinproduction/gatus /gatus /gatus

COPY ./config /config # inject custom local config defining scripts endpoints
# also should copy custom scripts in PATH

ENV PORT=8080
EXPOSE ${PORT}
ENTRYPOINT ["/gatus"]

I see at least one or two issues (in addition to my own usecase) this would allow to easily support :

  • https://github.com/TwiN/gatus/issues/554
  • https://github.com/TwiN/gatus/issues/437

Let me know if you find interest in this feature, I can make a proper PR with unittests / clean a little the code.

jcsaaddupuy avatar Oct 25 '23 13:10 jcsaaddupuy