12

We are using rundeck to scan logfiles for a service, and take action depending on what is found there. Basically, for each item found, for which a records does not exists, a git repository is initialized and a few rest endpoints are called, but that's not the point.

We are setting up the job to run as scheduled, say every couple of hours, and to send notification on failure, and additionally to send notification on success only when at least one action has been taken (ie. the shell script in the task entered the loop at least once). The script is written so that it only emits output on stdout when items to be actioned are found.

Is there a way in rundeck to trigger notification with this requirement? Or a way to script it without writing a plugin from scratch?

One possible workaround would be to switch the failure notification trigger off, and make the script return non-zero in case of no items actioned, but I am not comfortable in doing that.

ᴳᵁᴵᴰᴼ
  • 1,173
  • 10
  • 22

2 Answers2

7

The way I could think of are:

Writing your own plugin, from the notification plugin example page, adapting the example mail notification code could be a way.

Disabling success notifications in rundeck, and handle the success notification part in your script itself. This way that's your script responsibility to warn it did something in normal state and it's still rundeck responsibility to warn you the script failed.

Tensibai
  • 11,416
  • 2
  • 37
  • 63
1

I was able to get around this issue in a bit of a dodgy way by changing the command to:

/bin/bash -c "your-command-here | { ! grep '^'; }"

This pipes the output through grep and fails if there is any output at all, but grep still passes it through so you still get to see the output in Rundeck upon failure.

One drawback is that I believe you lose any blank lines but we don't output any so no big deal for us, and it will tide us over until we can update the app to terminate with a proper exit code.

Malvineous
  • 111
  • 3