Package: sa-tools-core
SA Tools CoreSA Tools 顾名思义是 System Administrator 的工具集，包含一些实用工具，涉及 DNS 管理、远程批量执行脚本、日志分析查询、通知提醒等。Installationpip install sa-tools-coreDevelopment GuideCurrently support python3.6+Quick start# first clone this repo
cd sa-tools-core

make initSee Makefile for more details.Re-install after modify codesmake installConfigurationcp local_config.py.example local_config.py
# then edit local_config.py
vi local_config.pyYou can use a system-wide configuration path as well, by default it is/etc/sa-tools/config.py.Local configs will overridesa_tools_core/consts.py.For other third party service configs, seeexamples/config.You can put third party service configs to/etc/sa-tools/directory.Command Line ToolsFor all the CLI tools, you can type-hor--helpto get help messages and examples.sa-notify通知提醒工具，支持 wework(企业微信), email, sms, pushbullet, pushover, telegram 等多种通知类型。sa-notify--weworkuser1--content'xxx'echo'xxx'|sa-notify--weworkuser1,user2--emailuser1@example.comuser3@example.comsa-dnsDNS 管理工具，目前仅支持 DNSPod。# 切 A 记录sa-dnsensuremain--typeA--value1.1.1.1--enable# dry-runsa-dnsensuremain--typeA--value1.1.1.1--enable--dry-run# 切 A 记录，独占sa-dnsensuremain--typeA--value1.1.1.1--enable--excl# 调整 ttlsa-dnsensuremain--typeA--value1.1.1.1--ttl100--enable# 批量切 CNAME 记录，常用于 CNAME 到 CDN 等操作sa-dnsensuremain--typeCNAME--value{domain}.h1.aqb.so.--enable# 查找子域记录sa-dnslist-Smusic# 查找 aqb 相关记录（只返回符合该关键字的记录）sa-dnslist-saqb# 按正则查找子域（查看 aqb 的测试域名）sa-dnslist|grep-E'^.*aqb\s'# 支持通过 -d,--domain 指定其他域名sa-dns-ddou.bzlistsee moresa-scriptA remote script runner tool based on ansible. To use it, you need to prepare your ansible environment first.远程命令执行工具，目前基于 ansible，需要事先配置好 ansible 环境(/etc/ansible/hosts)。一些特点，兼容 ansible host pattern脚本可从 stdin 传入或指定文件路径，若都不指定则会调用 editor 进入编辑模式(类似 git commit 时的行为)。批量执行，有进度条执行完毕后会进入交互模式，可以对结果进行筛选，支持 shell 管道操作，支持再次发起执行$echo'uptime && echo $HOSTNAME $(whoami)'|sa-scripttest_zk
Executing...100%|######################################################|Elapsed Time: 0:00:09+----------+----+-------------------------------------------------------+--------+|host|rc|stdout|stderr|+----------+----+-------------------------------------------------------+--------+|test-zk3|0|11:40:15up384days,19:00,1user,loadaverage:|||||0.16,0.20,0.26test-zk3user1|||test-zk2|0|11:40:15up392days,20:00,1user,loadaverage:|||||0.25,0.22,0.30test-zk2user1|||test-zk1|0|11:40:15up392days,23:53,1user,loadaverage:|||||0.30,0.22,0.25test-zk1user1||+----------+----+-------------------------------------------------------+--------+Seesa-script -hfor more details.TODO: add a gif to demonstrate.sa-accessaccess log 查询分析工具，支持简单查询，聚合查询，时段对比分析等sa-accessquery
sa-accessquery--termip1.1.1.1
sa-accessquery-thostexample.com-xbandwidth--byip
sa-accessquery--termappnameapp1-xcount--by-script"doc['remote_addr'].value + ' ' + doc['normalize_url'].value"sa-accessquery--termappnameapp1-xcount--by-script"def ip=doc['remote_addr'].value; ip.substring(0, ip.lastIndexOf('.')) + ' ' + doc['normalize_url'].value"sa-accessanalyze--termhostexample.com-xsumbytes_sent--bynurl-a'2017-03-28 09:30'-d15-b'2017-03-28 10:30'see moresa-icinga一个 Icinga2 的 CLI 工具。icinga2 doc:http://docs.icinga.org/icinga2/latest/doc/module/icinga2/toc# try testsa-icinganotify--weworkuser1--emailuser1@example.com--test

sa-icinganotify--weworkuser1--emailuser1@example.com# need icinga pass os environment varssa-icingaack--hostsa--servicecheck-puppet--comment'hehe'sa-icingaack--host'sa*'--service'check-puppet'sa-icingaack--host'sa*'--service'check-puppet'--remove

sa-icingashow--filter'host.name == "sa" && service.name == "check-puppet"'sa-icingashow--typehost--filter'match("sa*", host.name)'|less
sa-icingashow--typeservice--filter'regex("check_[a-z]*", service.name)'|less
sa-icingashow--typenotification--filter'notification.host_name == "sa"'|less
sa-icingashow--typeuser|grepuser1
sa-icingashow--filter'service.name == "check-puppet"'--attrsacknowledgementsee moresa-disk磁盘相关工具，利用 ncdu 快速扫盘，并可以保存、分析结果。sa-diskusage
sa-diskusage-n5-d3sa-diskusage-r/data1/ncdu-export-%-20160513142844.gz
sa-diskusage-c/tmp
sa-diskusage-p/data
sa-diskusage--force-check

sa-diskcleansee moresa-tcsa-tc是对腾讯云 API 的封装，支持黑石、CVM 等产品。sa-tcbmdevices
sa-tcbmdevices-fyaml
sa-tcbmdevices--aliashostsa-githubsa-github是对 Github API V3 的封装, 支持 github.com 和 ghe, 目前功能还在完善中, 只支持 collaborator apisa-githubcollaborator--orgxxx--repoyyyadd--usernameuser_1--permissionadmin
sa-githubcollaborator--orgxxx--repoyyyremove--usernameuser_1ClientTools can be called from client as well.fromsa_tools_core.clientimportClientc=Client()c.notify(wework='user1',content='hehe')c.uptime()c.dns.list(S='@')Seesa_tools_core/client.pyfor more details.