{"action":"created","issue":{"url":"https://api.github.com/repos/ClearcodeHQ/ianitor/issues/7","labels_url":"https://api.github.com/repos/ClearcodeHQ/ianitor/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/ClearcodeHQ/ianitor/issues/7/comments","events_url":"https://api.github.com/repos/ClearcodeHQ/ianitor/issues/7/events","html_url":"https://github.com/ClearcodeHQ/ianitor/pull/7","id":78227716,"number":7,"title":"allow the setting of script or http checks","user":{"login":"mruwnik","id":3942390,"avatar_url":"https://avatars.githubusercontent.com/u/3942390?v=3","gravatar_id":"","url":"https://api.github.com/users/mruwnik","html_url":"https://github.com/mruwnik","followers_url":"https://api.github.com/users/mruwnik/followers","following_url":"https://api.github.com/users/mruwnik/following{/other_user}","gists_url":"https://api.github.com/users/mruwnik/gists{/gist_id}","starred_url":"https://api.github.com/users/mruwnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mruwnik/subscriptions","organizations_url":"https://api.github.com/users/mruwnik/orgs","repos_url":"https://api.github.com/users/mruwnik/repos","events_url":"https://api.github.com/users/mruwnik/events{/privacy}","received_events_url":"https://api.github.com/users/mruwnik/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-05-19T19:49:25Z","updated_at":"2015-05-25T13:46:42Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ClearcodeHQ/ianitor/pulls/7","html_url":"https://github.com/ClearcodeHQ/ianitor/pull/7","diff_url":"https://github.com/ClearcodeHQ/ianitor/pull/7.diff","patch_url":"https://github.com/ClearcodeHQ/ianitor/pull/7.patch"},"body":"This allows the consul check to be a file or http check, rather than just allowing TTL checks. Only one check can be registered, so different checks have different priorities"},"comment":{"url":"https://api.github.com/repos/ClearcodeHQ/ianitor/issues/comments/105237188","html_url":"https://github.com/ClearcodeHQ/ianitor/pull/7#issuecomment-105237188","issue_url":"https://api.github.com/repos/ClearcodeHQ/ianitor/issues/7","id":105237188,"user":{"login":"swistakm","id":1258054,"avatar_url":"https://avatars.githubusercontent.com/u/1258054?v=3","gravatar_id":"","url":"https://api.github.com/users/swistakm","html_url":"https://github.com/swistakm","followers_url":"https://api.github.com/users/swistakm/followers","following_url":"https://api.github.com/users/swistakm/following{/other_user}","gists_url":"https://api.github.com/users/swistakm/gists{/gist_id}","starred_url":"https://api.github.com/users/swistakm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/swistakm/subscriptions","organizations_url":"https://api.github.com/users/swistakm/orgs","repos_url":"https://api.github.com/users/swistakm/repos","events_url":"https://api.github.com/users/swistakm/events{/privacy}","received_events_url":"https://api.github.com/users/swistakm/received_events","type":"User","site_admin":false},"created_at":"2015-05-25T13:46:42Z","updated_at":"2015-05-25T13:46:42Z","body":"Ok, I understand the case. This is exactly what I expected.\r\n\r\n> What do you mean by 'additional python code'?\r\n\r\nI had an idea that we could have some new optional parameter that could be used multiple times like:\r\n\r\n    ianitor (...) --check=call:some_module.callable --check:exec:some_script.sh\r\n\r\nWhere for each case:\r\n* `call:<callable>`: the `<callable>` is an import path to any object that has `__call__` attribute and is expected to return check result on call.\r\n* `exec:<script>`: the `<script>` is any command to run. Process exit code is the health status.\r\n\r\nEvery check would be then run (call on callable or exec) on each heartbeat tick. If process still exists and every check is fine then service is in healthy state. Failure on any check will mark service as failing.\r\n\r\nI still have not decided what form of result should be expected because it would be nice to be able to construct sensible notes in consul check \"Notes\" field. In case of executing script the solution is easy: simply follow the way how consul does that. Consul treats process exit code as health value and any captured stdout as additional notes. We could imply \"call\" checks to return either single bool value or two-tuple of `(result, notes)`. Then if any service check fails we would have some additional output in notes like:\r\n\r\n    some_shell_script.sh: passing\r\n    some_other_script.sh: critical\r\n    some.check.module.check_something: critical\r\n\r\nNote that this approach allows leveraging existing script checks and also using more sophisticated python code.\r\n\r\nOther ideas/issues in my mind about how this could work:\r\n* callable on `call` checks could receive `Service` class object as an argument. This would allow to write some generic checks (`ianitor.contrib.checks` module/package?)\r\n* maybe we could use doctoring of callable to have more human readable health check notes?\r\n* maybe we could allow switching between notes format (text, yaml, json, etc.)?\r\n* maybe some syntax for passing arbitrary args and kwargs to call checks? In case of `exec` this is already possible by design, maybe `call` should also support that.\r\n* how to treat exceptions on call script? Probably we need to catch all. But what is this? A `critical` or `unknown`. How about notes then?\r\n* consul allows for `warning` state. How to handle that in case of multiple checks?\r\n\r\nIf you find this idea reasonable I think we should close this PR and create a separate issue where we would draft this new feature and decide what will be implemented and in which version because this will be quite big functionality. I think that the first to go is script/exec, because there is not a lot to think about since everything is provided thanks to POSIX and this obviously covers also code run in python externally.\r\n\r\nWhat do you think?"}}