1 # -*- coding: utf-8 -*-
8 """Clear the console using curses
10 This utility function empties the console ("clear").
13 sys
.stdout
.write(curses
.tigetstr("clear"))
16 def read_monitor_config(configfile
):
17 """Reads the monitor configuration file for the Aggregator
19 @param configfile: path of the config file
20 @return: a list of Monitor or PipeMonitor objects
22 config
= ConfigParser
.ConfigParser()
23 config
.read(configfile
)
24 for section
in config
.sections():
25 c
= dict(config
.items(section
))
27 if c
['type'] == 'monitor':
28 ignorelocal
= parse_bool(c
.get('ignorelocal', False))
30 mon
= monitor
.Monitor(ignorelocal
=ignorelocal
)
31 inc
= [c
.get('include', '')]
32 exc
= [c
.get('exclude', '')]
33 mon
.set_filter(inc
, exc
)
35 elif c
['type'] == 'pipe':
38 newhost
= c
['newhost']
39 newport
= int(c
['newport'])
41 mon
= pipe
.PipeMonitor(pipe
.Pipe(port
, newhost
, newport
))
42 #mon.set_shape(c.get('shape_threshold', 0))
46 print 'unknown monitor type %s' % c
['type']
53 """Convert a string to a boolean value
55 @param val: The string value (or boolean)
56 @return: True or False, depending on "val"
58 if isinstance(val
, bool):
61 if string
.lower() == 'true':
67 def read_notification_config(configfile
):
68 """Reads the notification config file for the Aggregator
70 @param configfile: path to the config file
71 @return: a list of tuples representing the notification settings (process_regex, in_threshold, out_threshold, interval, command)
73 config
= ConfigParser
.ConfigParser()
74 config
.read(configfile
)
75 for section
in config
.sections():
76 c
= dict(config
.items(section
))
77 yield ( c
['process_filter'], int(c
.get('in_threshold', 0)), int(c
.get('out_threshold', 0)), int(c
.get('interval', 1)), c
.get('notification_command', '') )
84 def __init__(self
,size_max
):
85 """Initiates a new ringbuffer with the given size
87 @param size_max: maximum number of entries
93 """Append an element at the end of the buffer
95 @param x: The element to append
98 if len(self
.data
) == self
.max:
100 self
.__class
__ = RingBufferFull
103 """Get a list of contained elements
105 @return: A list of ements from oldest to newesta
110 class RingBufferFull
:
111 """A full ringbuffer - not initialized directly
114 def __init__(self
, n
):
115 """Don't initialize this object directly!"""
116 raise "don't initialize FullRingBuffer directly"
119 """Append an element at the end of the buffer
121 @param x: The element to append
123 self
.data
[self
.cur
]=x
124 self
.cur
=(self
.cur
+1) % self
.max
127 """Get a list of contained elements
129 @return: A list of ements from oldest to newesta
131 return self
.data
[self
.cur
:]+self
.data
[:self
.cur
]