-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathraidinfo.py
More file actions
executable file
·69 lines (55 loc) · 1.87 KB
/
raidinfo.py
File metadata and controls
executable file
·69 lines (55 loc) · 1.87 KB
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
#!/usr/bin/python3
import socket
import smtplib
import datetime
import sys
import os
import argparse
from email.mime.text import MIMEText
from io import StringIO
from lib import *
import configparser
def loadconfig():
config = configparser.ConfigParser()
config.read('raidinfo.conf')
if 'mail' not in config:
return None
return config['mail']
def main():
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--help', help='show this help message and exit', action='store_true')
parser.add_argument('-e', '--email', help='send report via email', action='store_true')
args = parser.parse_args()
if args.help:
print('Makes a compact report about RAID controllers')
parser.print_help()
return 0
if not os.name == 'nt':
if os.getenv('USER') != 'root':
print('This script requires Administrator privileges')
sys.exit(5)
if args.email:
old_stdout = sys.stdout
sys.stdout = body = StringIO()
controllers = raid.RaidController.probe()
for controller in controllers:
controller.printInfo()
if args.email:
sys.stdout = old_stdout
msg = MIMEText(body.getvalue())
config = loadconfig()
if config is None:
print('Error loading config file')
return
msg['From'] = config['fromaddr']
msg['To'] = config['toaddr']
msg['Subject'] = 'Information about RAID controllers on {}'.format(socket.getfqdn())
msg['Date'] = datetime.datetime.now().ctime()
server = smtplib.SMTP(config['mailserver'], config['mailserverport'])
server.starttls()
server.login(config['maillogin'], config['mailpassword'])
text = msg.as_string()
server.sendmail(config['fromaddr'], config['toaddr'], text)
server.quit()
if __name__ == '__main__':
main()