You can add failure recovery code to your monitors, when a monitored system fails the failure recovery code will be excuted by Ragios.
You can add 2 types of failure recovery code:
- Code to be excuted when a monitored system fails, and
- Code to be excuted when a monitored system recovers from failure.
When a server is being monitored for availability, failure recovery code could be used to switch to a backup server when the main server goes down, and then switch back to the main server when it recovers. This also applies to any type of system being monitored databases, websites, datafeeds, API etc.
Lets say you want your web app to switch to a backup datafeed when your main datafeed goes offline.
run_when_failed = lambda{ puts 'switch to backup datafeed' puts 'do something' } run_when_fixed = lambda{ puts 'switch to main datafeed' puts 'do something' } monitoring = [{ monitor: 'url', every: '2m', test: 'XYZ data feed', url: 'http://www.website.com/89843/videos.xml', contact: 'admin@mail.com', via: 'gmail', notify_interval: '6h', failed: run_when_failed, fixed: run_when_fixed }] Ragios::Monitor.start monitoring
failed: points to a code block that will be excuted when the monitored system goes down while fixed: points to a code block that will be excuted when the monitored system recovers from failure.
In the example above, When the monitored url fails, the code block run_when_failed will be excuted and when it recovers from failure, the code block run_when_fixed will be executed.
Both code blocks are only excuted once. The failed:code_block is only excuted when the monitored system goes into a FAILED state, while fixed:code_block is only excuted when the monitored system recovers from a FAILED state.