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
|
#!/usr/bin/python
#
# Copyright (C) 2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os
import smtplib
import getpass
import cliapp
import overseerlib
class TroveOverseer(cliapp.Application):
def add_settings(self):
self.settings.string(['config-path'], 'path to configuration file',
metavar='FILE', default='/etc/monitoring.conf')
def process_args(self, args):
# self.rungit(['remote', 'update', 'origin'])
# self.rungit(['reset', '--hard', 'origin/master'])
# self.rungit(['clean', '-fdx'])
cliapp.Application.process_args(self, args)
def human_to_bytes(self, threshold):
symbols = ('B', 'K', 'M', 'G', 'T')
s = threshold
letter = s[-1:].strip().upper()
num = s[:-1]
if letter not in symbols:
raise cliapp.AppException('Valid symbols: B, K, M, G, T')
num = float(num)
prefix = {symbols[0]:1}
for i, s in enumerate(symbols[1:]):
prefix[s] = 1 << (i+1)*10
return int(num * prefix[letter])
def rungit(self, args):
self.runcmd(['git']+args, cwd='/src/morph')
def write_to_html(self, html_file):
if html_file:
try:
with open(self.html_file + '.new', 'w') as ofh:
ofh.write('<!DOCTYPE html>\n')
ofh.write(self.gen_html())
ofh.write('\n')
target = self.filename
os.rename(self.filename + '.new', target)
except:
os.unlink(self.filename + '.new')
raise
def gen_footer(self):
curtime = format_time(time.time())
return self.tag('div', Class='footer', content=
'Generated by Trove Monitoring at ' + curtime)
def tag(self, tagname, content=None, gap=False, **kwargs):
tagval = ' '.join([tagname] +
['%s=%r' % (k.lower(), v)
for k, v in kwargs.iteritems()])
gap = '\n' if gap else ''
if content is None:
return '<%s />' % tagval
else:
return '<%s>%s%s%s</%s>' % (tagval, gap, content, gap, tagname)
|