{"id":15049989,"url":"https://github.com/douban/sa-tools-core","last_synced_at":"2025-06-10T14:09:08.553Z","repository":{"id":46095499,"uuid":"200020269","full_name":"douban/sa-tools-core","owner":"douban","description":"Handy tools for sysadmin.","archived":false,"fork":false,"pushed_at":"2023-02-20T09:05:06.000Z","size":209,"stargazers_count":17,"open_issues_count":2,"forks_count":11,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-10T02:13:03.305Z","etag":null,"topics":["ansible","cli","disk","dns","elasticsearch","icinga"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/douban.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-01T09:27:21.000Z","updated_at":"2024-08-19T06:45:41.000Z","dependencies_parsed_at":"2025-02-16T09:32:29.298Z","dependency_job_id":"92cc761c-1e24-4aca-967c-99d91faae32b","html_url":"https://github.com/douban/sa-tools-core","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douban%2Fsa-tools-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douban%2Fsa-tools-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douban%2Fsa-tools-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douban%2Fsa-tools-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/douban","download_url":"https://codeload.github.com/douban/sa-tools-core/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142902,"owners_count":21054671,"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":["ansible","cli","disk","dns","elasticsearch","icinga"],"created_at":"2024-09-24T21:24:02.888Z","updated_at":"2025-04-10T02:13:33.677Z","avatar_url":"https://github.com/douban.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SA Tools Core\n\n![](https://img.shields.io/pypi/status/sa-tools-core)\n![](https://img.shields.io/pypi/v/sa-tools-core)\n![](https://img.shields.io/pypi/pyversions/sa-tools-core)\n![](https://img.shields.io/pypi/wheel/sa-tools-core)\n![](https://img.shields.io/pypi/l/sa-tools-core)\n\nSA Tools 顾名思义是 System Administrator 的工具集，包含一些实用工具，涉及 DNS 管理、远程批量执行脚本、日志分析查询、通知提醒等。\n\n## Installation\n\n```\npip install sa-tools-core\n```\n\n## Development Guide\n\nCurrently support python3.6+\n\n### Quick start\n\n```\n# first clone this repo\ncd sa-tools-core\n\nmake init\n```\n\nSee Makefile for more details.\n\n### Re-install after modify codes\n\n```\nmake install\n```\n\n## Configuration\n\n```\ncp local_config.py.example local_config.py\n# then edit local_config.py\nvi local_config.py\n```\n\nYou can use a system-wide configuration path as well, by default it is `/etc/sa-tools/config.py`.\n\nLocal configs will override [sa_tools_core/consts.py](sa_tools_core/consts.py).\n\nFor other third party service configs, see [examples/config](examples/config).\n\nYou can put third party service configs to `/etc/sa-tools/` directory.\n\n## Command Line Tools\n\nFor all the CLI tools, you can type `-h` or `--help` to get help messages and examples.\n\n### sa-notify\n\n通知提醒工具，支持 wework(企业微信), email, sms, pushbullet, pushover, telegram 等多种通知类型。\n\n```shell\nsa-notify --wework user1 --content 'xxx'\necho 'xxx' | sa-notify --wework user1,user2 --email user1@example.com user3@example.com\n```\n\n### sa-dns\n\nDNS 管理工具，目前仅支持 DNSPod。\n\n```shell\n# 切 A 记录\nsa-dns ensure main --type A --value 1.1.1.1 --enable\n# dry-run\nsa-dns ensure main --type A --value 1.1.1.1 --enable --dry-run\n# 切 A 记录，独占\nsa-dns ensure main --type A --value 1.1.1.1 --enable --excl\n# 调整 ttl\nsa-dns ensure main --type A --value 1.1.1.1 --ttl 100 --enable\n# 批量切 CNAME 记录，常用于 CNAME 到 CDN 等操作\nsa-dns ensure main --type CNAME --value {domain}.h1.aqb.so. --enable\n\n# 查找子域记录\nsa-dns list -S music\n# 查找 aqb 相关记录（只返回符合该关键字的记录）\nsa-dns list -s aqb\n# 按正则查找子域（查看 aqb 的测试域名）\nsa-dns list | grep -E '^.*aqb\\s'\n\n# 支持通过 -d,--domain 指定其他域名\nsa-dns -d dou.bz list\n```\n\n[see more](docs/sa-dns.md)\n\n### sa-script\n\nA remote script runner tool based on ansible. To use it, you need to prepare your ansible environment first.\n\n远程命令执行工具，目前基于 ansible，需要事先配置好 ansible 环境(/etc/ansible/hosts)。\n\n一些特点，\n\n- 兼容 ansible host pattern\n- 脚本可从 stdin 传入或指定文件路径，若都不指定则会调用 editor 进入编辑模式(类似 git commit 时的行为)。\n- 批量执行，有进度条\n- 执行完毕后会进入交互模式，可以对结果进行筛选，支持 shell 管道操作，支持再次发起执行\n\n```shell\n$ echo 'uptime \u0026\u0026 echo $HOSTNAME $(whoami)' | sa-script test_zk\nExecuting...\n100%|######################################################|Elapsed Time: 0:00:09\n\n+----------+----+-------------------------------------------------------+--------+\n| host     | rc | stdout                                                | stderr |\n+----------+----+-------------------------------------------------------+--------+\n| test-zk3 | 0  |  11:40:15 up 384 days, 19:00,  1 user,  load average: |        |\n|          |    | 0.16, 0.20, 0.26 test-zk3 user1                       |        |\n| test-zk2 | 0  |  11:40:15 up 392 days, 20:00,  1 user,  load average: |        |\n|          |    | 0.25, 0.22, 0.30 test-zk2 user1                       |        |\n| test-zk1 | 0  |  11:40:15 up 392 days, 23:53,  1 user,  load average: |        |\n|          |    | 0.30, 0.22, 0.25 test-zk1 user1                       |        |\n+----------+----+-------------------------------------------------------+--------+\n```\n\nSee `sa-script -h` for more details.\n\nTODO: add a gif to demonstrate.\n\n### sa-access\n\naccess log 查询分析工具，支持简单查询，聚合查询，时段对比分析等\n\n```shell\nsa-access query\nsa-access query --term ip 1.1.1.1\nsa-access query -t host example.com -x bandwidth --by ip\nsa-access query --term appname app1 -x count --by-script \"doc['remote_addr'].value + ' ' + doc['normalize_url'].value\"\nsa-access query --term appname app1 -x count --by-script \"def ip=doc['remote_addr'].value; ip.substring(0, ip.lastIndexOf('.')) + ' ' + doc['normalize_url'].value\"\nsa-access analyze --term host example.com -x sum bytes_sent --by nurl -a '2017-03-28 09:30' -d 15 -b '2017-03-28 10:30'\n```\n\n[see more](docs/sa-access.md)\n\n### sa-icinga\n\n一个 Icinga2 的 CLI 工具。\n\nicinga2 doc: \u003chttp://docs.icinga.org/icinga2/latest/doc/module/icinga2/toc\u003e\n\n```shell\n# try test\nsa-icinga notify --wework user1 --email user1@example.com --test\n\nsa-icinga notify --wework user1 --email user1@example.com  # need icinga pass os environment vars\n\nsa-icinga ack --host sa --service check-puppet --comment 'hehe'\nsa-icinga ack --host 'sa*' --service 'check-puppet'\nsa-icinga ack --host 'sa*' --service 'check-puppet' --remove\n\nsa-icinga show --filter 'host.name == \"sa\" \u0026\u0026 service.name == \"check-puppet\"'\nsa-icinga show --type host --filter 'match(\"sa*\", host.name)' | less\nsa-icinga show --type service --filter 'regex(\"check_[a-z]*\", service.name)' | less\nsa-icinga show --type notification --filter 'notification.host_name == \"sa\"' | less\nsa-icinga show --type user | grep user1\nsa-icinga show --filter 'service.name == \"check-puppet\"' --attrs acknowledgement\n```\n\n[see more](docs/sa-icinga.md)\n\n### sa-disk\n\n磁盘相关工具，利用 ncdu 快速扫盘，并可以保存、分析结果。\n\n```shell\nsa-disk usage\nsa-disk usage -n 5 -d 3\nsa-disk usage -r /data1/ncdu-export-%-20160513142844.gz\nsa-disk usage -c /tmp\nsa-disk usage -p /data\nsa-disk usage --force-check\n\nsa-disk clean\n```\n\n[see more](docs/sa-disk.md)\n\n### sa-tc\n\n`sa-tc` 是对腾讯云 API 的封装，支持黑石、CVM 等产品。\n\n```shell\nsa-tc bm devices\nsa-tc bm devices -f yaml\nsa-tc bm devices --alias host\n```\n\n### sa-github\n\n`sa-github` 是对 Github API V3 的封装, 支持 github.com 和 ghe, 目前功能还在完善中, 只支持 collaborator api\n\n```shell\nsa-github collaborator --org xxx --repo yyy add --username user_1 --permission admin\nsa-github collaborator --org xxx --repo yyy remove --username user_1\n```\n\n## Client\n\nTools can be called from client as well.\n\n```python\nfrom sa_tools_core.client import Client\n\nc = Client()\nc.notify(wework='user1', content='hehe')\nc.uptime()\nc.dns.list(S='@')\n```\n\nSee [sa_tools_core/client.py](sa_tools_core/client.py) for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdouban%2Fsa-tools-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdouban%2Fsa-tools-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdouban%2Fsa-tools-core/lists"}