Chef Inspec control status capture

I want to perform some action if my control fails, example, I may want to send an email or execute some ruby code, how can I capture the control execution result, I tried ruby begin rescue block but it did not work, how to do this

I would suggest a custom reporter plugin. You can perform the inspec run, then examine all the results and perform any Ruby code you wish based on the results. See inspec/plugins.md at master · inspec/inspec · GitHub for a development guide for plugins and inspec/lib/plugins/inspec-reporter-html2 at master · inspec/inspec · GitHub and GitHub - tecracer-chef/inspec-reporter-flex: Flexible, templating reporter for InSpec for examples of custom reporters. While both of those produce templated output, there is no reason why you couldn't take some other action, such as sending an email or connecting to a monitoring system.

Happy coding!