{"id":15658617,"url":"https://github.com/long2ice/alarmer","last_synced_at":"2025-10-07T08:32:37.153Z","repository":{"id":57409483,"uuid":"410297232","full_name":"long2ice/alarmer","owner":"long2ice","description":"A tool focus on error reporting for your application, like sentry but lightweight","archived":false,"fork":false,"pushed_at":"2021-12-27T06:21:54.000Z","size":90,"stargazers_count":19,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"dev","last_synced_at":"2025-01-12T18:37:49.249Z","etag":null,"topics":["alert","exception","report","sentry"],"latest_commit_sha":null,"homepage":"https://github.com/long2ice/alarmer","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/long2ice.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-25T14:42:47.000Z","updated_at":"2023-01-24T02:42:10.000Z","dependencies_parsed_at":"2022-08-24T18:50:48.530Z","dependency_job_id":null,"html_url":"https://github.com/long2ice/alarmer","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/long2ice%2Falarmer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/long2ice%2Falarmer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/long2ice%2Falarmer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/long2ice%2Falarmer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/long2ice","download_url":"https://codeload.github.com/long2ice/alarmer/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235607126,"owners_count":19017302,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alert","exception","report","sentry"],"created_at":"2024-10-03T13:13:11.483Z","updated_at":"2025-10-07T08:32:36.794Z","avatar_url":"https://github.com/long2ice.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# alarmer\n\n[![image](https://img.shields.io/pypi/v/alarmer.svg?style=flat)](https://pypi.python.org/pypi/alarmer)\n[![image](https://img.shields.io/github/license/long2ice/alarmer)](https://github.com/long2ice/alarmer)\n[![pypi](https://github.com/long2ice/alarmer/actions/workflows/pypi.yml/badge.svg)](https://github.com/long2ice/alarmer/actions/workflows/pypi.yml)\n[![ci](https://github.com/long2ice/alarmer/actions/workflows/ci.yml/badge.svg)](https://github.com/long2ice/alarmer/actions/workflows/ci.yml)\n\n`Alarmer` is a tool focus on error reporting for your application, like [sentry](https://sentry.io) but lightweight.\n\n## Installation\n\n```shell\npip install alarmer\n```\n\n## Usage\n\nIt's simple to integrate `alarmer` in your application, just call `Alarmer.init` on startup of your application.\n\n```py\nimport os\n\nfrom alarmer import Alarmer\nfrom alarmer.provider.feishu import FeiShuProvider\n\n\ndef main():\n    Alarmer.init(providers=[FeiShuProvider(webhook_url=os.getenv(\"FEI_SHU_WEBHOOK_URL\"))])\n    raise Exception(\"test\")\n\n\nif __name__ == \"__main__\":\n    main()\n```\n\n### Intercept Error Logging\n\nIf you want to intercept the logging, you can use `LoggingHandler`.\n\n```py\nimport logging\nimport os\n\nfrom alarmer import Alarmer\nfrom alarmer.log import LoggingHandler\nfrom alarmer.provider.feishu import FeiShuProvider\n\n\ndef main():\n    Alarmer.init(providers=[FeiShuProvider(webhook_url=os.getenv(\"FEI_SHU_WEBHOOK_URL\"))])\n    logging.basicConfig(\n        level=logging.INFO,\n    )\n    logger = logging.getLogger()\n    logger.addHandler(LoggingHandler(level=logging.ERROR))  # only error and above should be send\n    logging.error(\"test logging\")\n\n\nif __name__ == \"__main__\":\n    main()\n\n```\n\nNow when you run the script, you will receive the errors in your provider.\n\n## Provider\n\nYou can set number of providers for error reporting. All kinds of providers can be found\nin [providers](./alarmer/provider).\n\nThanks to [Apprise](https://github.com/caronc/apprise), you can use lots of providers out of box.\n\n- [Apprise](https://github.com/caronc/apprise)\n- [FeiShu](https://www.feishu.cn/hc/zh-CN/articles/360024984973)\n- [WeCom](https://work.weixin.qq.com/api/doc/90000/90136/91770)\n\n### Custom Provider\n\nYou can write your own custom provider by inheriting the `Provider` class.\n\n```py\nfrom typing import Optional\nfrom alarmer.provider import Provider\n\n\nclass CustomProvider(Provider):\n\n    def send(self, message: str, exc: Optional[BaseException] = None, context: Optional[dict] = None):\n        # Send to your custom provider here\n        pass\n```\n\nIn addition to this, you can just write a callable function which takes `message` and `exc` arguments.\n\n```py\nfrom typing import Optional\n\n\ndef custom_provider(message: str, exc: Optional[BaseException] = None, context: Optional[dict] = None):\n    # Send to your custom provider here\n    pass\n```\n\nThen add it to `Alarmer.init`.\n\n```py\nfrom alarmer import Alarmer\n\nAlarmer.init(providers=[CustomProvider(), custom_provider])\n```\n\n## Throttling\n\n`Throttling` is used to throttling error messages if there are too many errors.\n\n```py\nfrom alarmer import Alarmer\nfrom alarmer.throttling import Throttling\n\nAlarmer.init(global_throttling=Throttling(), providers=[...])\n```\n\n### Custom Throttling\n\nYou can write your own throttling by inheriting the `Throttling` class.\n\n```py\nimport typing\n\nfrom alarmer.throttling import Throttling\n\nif typing.TYPE_CHECKING:\n    from alarmer.provider import Provider\n\n\nclass MyThrottling(Throttling):\n    def __call__(self, provider: \"typing.Union[Provider,typing.Callable]\", message: str,\n                 exc: typing.Optional[BaseException] = None, context: typing.Optional[dict] = None) -\u003e bool:\n        # check whether the error message should be send\n        return True\n```\n\n## Manual Send\n\nIf you want to manually send messages to the providers, just call `Alarmer.send`.\n\n```py\nfrom alarmer import Alarmer\n\nAlarmer.send(\"message\")\n```\n\n## License\n\nThis project is licensed under the\n[Apache-2.0](https://github.com/long2ice/alarmer/blob/master/LICENSE) License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flong2ice%2Falarmer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flong2ice%2Falarmer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flong2ice%2Falarmer/lists"}