-
Notifications
You must be signed in to change notification settings - Fork 0
/
saltbox-motd.py
executable file
·129 lines (103 loc) · 4.15 KB
/
saltbox-motd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python3
import logging
import os
import sys
from logging.handlers import RotatingFileHandler
import utils
############################################################
# INIT
############################################################
# Logging
log_format = '%(asctime)s - %(levelname)-10s - %(name)-35s - %(funcName)-35s - %(message)s'
log_formatter = logging.Formatter(log_format)
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger('urllib3').setLevel(logging.ERROR)
log_file_path = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "activity.log")
file_handler = RotatingFileHandler(
log_file_path,
maxBytes=1024 * 1024 * 5,
backupCount=5
)
file_handler.setFormatter(log_formatter)
root_logger.addHandler(file_handler)
root_logger.setLevel(logging.DEBUG)
log = root_logger.getChild("saltbox-motd")
############################################################
# MAIN
############################################################
if __name__ == "__main__":
# Load config
from utils.config import Config
cfg = Config(config_path=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "config.json"),
logger=log).cfg
# Parse args
if len(sys.argv) < 3:
print("ERROR: Not enough arguments")
exit(1)
cmd_type = sys.argv[1].lower()
cmd_func = sys.argv[2].lower()
# Process types
if cmd_type == 'config':
# Process funcs
if cmd_func == 'upgrade':
exit(0)
elif cmd_type == 'autoscan':
autoscan = utils.Autoscan(cfg["autoscan"]["url"], cfg["autoscan"]["api_key"])
# Process funcs
if cmd_func == 'get_queue_count':
print(autoscan.get_queue_count())
exit(0)
elif cmd_type == 'disk':
# Process funcs
if cmd_func == 'usage':
total_space, used_space, used_percent, free_space = utils.disk.get_disk_usage(cfg["disk"]["path"])
print("%s|%s|%s|%s" % (total_space, used_space, used_percent, free_space))
exit(0)
elif cmd_type == 'rtorrent':
rtorrent = utils.Rtorrent(cfg["rtorrent"]["url"])
# Process funcs
if cmd_func == 'get_download_total':
print(rtorrent.get_download_total())
exit(0)
elif cmd_func == 'get_upload_total':
print(rtorrent.get_upload_total())
exit(0)
elif cmd_func == 'get_download_rate':
print(rtorrent.get_download_rate())
exit(0)
elif cmd_func == 'get_upload_rate':
print(rtorrent.get_upload_rate())
exit(0)
elif cmd_func == 'get_torrent_counts':
torrent_count, downloading_count, seeding_count = rtorrent.get_torrent_counts()
print("%d.%d.%d" % (torrent_count, downloading_count, seeding_count))
exit(0)
elif cmd_type == 'nzbget':
nzbget = utils.Nzbget(cfg["nzbget"]["url"])
# Process funcs
if cmd_func == "get_download_total":
print(nzbget.get_download_total())
exit(0)
elif cmd_func == "get_download_rate":
print(nzbget.get_download_rate())
exit(0)
elif cmd_func == "get_nzb_counts":
nzb_count, downloading_count, paused_count, unpacking_count, repairing_count, verifying_count = \
nzbget.get_nzb_counts()
print("%d.%d.%d.%d.%d.%d" % (nzb_count, downloading_count, paused_count, unpacking_count, repairing_count,
verifying_count))
exit(0)
elif cmd_type == 'tautulli':
tautulli = utils.Tautulli(cfg["tautulli"]["url"], cfg["tautulli"]["api_key"])
# Process funcs
if cmd_func == "get_stream_bandwidth":
print(tautulli.get_stream_bandwidth())
exit(0)
elif cmd_func == "get_stream_counts":
transcodes, direct_play, direct_streams = tautulli.get_stream_counts()
print("%d.%d.%d" % (transcodes, direct_play, direct_streams))
exit(0)
print("ERROR: Unknown cmd=%r, func=%r" % (cmd_type, cmd_func))
exit(1)