sa-tools-core

Handy tools for sysadmin.

Downloads
261
Stars
17
Committers
11

SA Tools Core

SA Tools System Administrator DNS

Installation

pip install sa-tools-core

Development Guide

Currently support python3.6+

Quick start

# first clone this repo
cd sa-tools-core

make init

See Makefile for more details.

Re-install after modify codes

make install

Configuration

cp local_config.py.example local_config.py
# then edit local_config.py
vi local_config.py

You can use a system-wide configuration path as well, by default it is /etc/sa-tools/config.py.

Local configs will override sa_tools_core/consts.py.

For other third party service configs, see examples/config.

You can put third party service configs to /etc/sa-tools/ directory.

Command Line Tools

For all the CLI tools, you can type -h or --help to get help messages and examples.

sa-notify

wework(), email, sms, pushbullet, pushover, telegram

sa-notify --wework user1 --content 'xxx'
echo 'xxx' | sa-notify --wework user1,user2 --email [email protected] [email protected]

sa-dns

DNS DNSPod

#  A 
sa-dns ensure main --type A --value 1.1.1.1 --enable
# dry-run
sa-dns ensure main --type A --value 1.1.1.1 --enable --dry-run
#  A 
sa-dns ensure main --type A --value 1.1.1.1 --enable --excl
#  ttl
sa-dns ensure main --type A --value 1.1.1.1 --ttl 100 --enable
#  CNAME  CNAME  CDN 
sa-dns ensure main --type CNAME --value {domain}.h1.aqb.so. --enable

# 
sa-dns list -S music
#  aqb 
sa-dns list -s aqb
#  aqb 
sa-dns list | grep -E '^.*aqb\s'

#  -d,--domain 
sa-dns -d dou.bz list

see more

sa-script

A 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-script test_zk
Executing...
100%|######################################################|Elapsed Time: 0:00:09

+----------+----+-------------------------------------------------------+--------+
| host     | rc | stdout                                                | stderr |
+----------+----+-------------------------------------------------------+--------+
| test-zk3 | 0  |  11:40:15 up 384 days, 19:00,  1 user,  load average: |        |
|          |    | 0.16, 0.20, 0.26 test-zk3 user1                       |        |
| test-zk2 | 0  |  11:40:15 up 392 days, 20:00,  1 user,  load average: |        |
|          |    | 0.25, 0.22, 0.30 test-zk2 user1                       |        |
| test-zk1 | 0  |  11:40:15 up 392 days, 23:53,  1 user,  load average: |        |
|          |    | 0.30, 0.22, 0.25 test-zk1 user1                       |        |
+----------+----+-------------------------------------------------------+--------+

See sa-script -h for more details.

TODO: add a gif to demonstrate.

sa-access

access log

sa-access query
sa-access query --term ip 1.1.1.1
sa-access query -t host example.com -x bandwidth --by ip
sa-access query --term appname app1 -x count --by-script "doc['remote_addr'].value + ' ' + doc['normalize_url'].value"
sa-access query --term appname app1 -x count --by-script "def ip=doc['remote_addr'].value; ip.substring(0, ip.lastIndexOf('.')) + ' ' + doc['normalize_url'].value"
sa-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'

see more

sa-icinga

Icinga2 CLI

icinga2 doc: http://docs.icinga.org/icinga2/latest/doc/module/icinga2/toc

# try test
sa-icinga notify --wework user1 --email [email protected] --test

sa-icinga notify --wework user1 --email [email protected]  # need icinga pass os environment vars

sa-icinga ack --host sa --service check-puppet --comment 'hehe'
sa-icinga ack --host 'sa*' --service 'check-puppet'
sa-icinga ack --host 'sa*' --service 'check-puppet' --remove

sa-icinga show --filter 'host.name == "sa" && service.name == "check-puppet"'
sa-icinga show --type host --filter 'match("sa*", host.name)' | less
sa-icinga show --type service --filter 'regex("check_[a-z]*", service.name)' | less
sa-icinga show --type notification --filter 'notification.host_name == "sa"' | less
sa-icinga show --type user | grep user1
sa-icinga show --filter 'service.name == "check-puppet"' --attrs acknowledgement

see more

sa-disk

ncdu

sa-disk usage
sa-disk usage -n 5 -d 3
sa-disk usage -r /data1/ncdu-export-%-20160513142844.gz
sa-disk usage -c /tmp
sa-disk usage -p /data
sa-disk usage --force-check

sa-disk clean

see more

sa-tc

sa-tc API CVM

sa-tc bm devices
sa-tc bm devices -f yaml
sa-tc bm devices --alias host

sa-github

sa-github Github API V3 , github.com ghe, , collaborator api

sa-github collaborator --org xxx --repo yyy add --username user_1 --permission admin
sa-github collaborator --org xxx --repo yyy remove --username user_1

Client

Tools can be called from client as well.

from sa_tools_core.client import Client

c = Client()
c.notify(wework='user1', content='hehe')
c.uptime()
c.dns.list(S='@')

See sa_tools_core/client.py for more details.

Package Rankings
Top 18.69% on Pypi.org
Related Projects