/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk
24.1.116 by Björn Påhlsson
added a mandos list client program
1
#!/usr/bin/python
2
3
import dbus
4
from optparse import OptionParser
5
6
tablewords = {
7
    'name': 'Name',
8
    'enabled': 'Enabled',
9
    'timeout': 'Timeout',
10
    'last_checked_ok': 'Last Successful Check',
11
    'created': 'Created',
12
    'interval': 'Interval',
13
    'host': 'Host',
14
    'fingerprint': 'Fingerprint',
15
    'checker_running': 'Check Is Running',
16
    'last_enabled': 'Last Enabled',
17
    'checker': 'Checker',
18
    }
19
busname = 'org.mandos-system.Mandos'
20
object_path = '/Mandos'
21
interface = 'org.mandos_system.Mandos'
22
version = "1.0.0"
23
defaultkeywords = ('name', 'enabled', 'timeout', 'last_checked_ok', 'checker')
24
25
parser = OptionParser(version = "%%prog %s" % version)
26
parser.add_option("-a", "--all", action="store_true", default=False,
27
                      help="Print all fields")
28
options = parser.parse_args()[0]
29
if options.all:
30
    keywords = ( 'name', 'enabled', 'timeout', 'last_checked_ok',
31
                 'created', 'interval', 'host', 'fingerprint',
32
                 'checker_running', 'last_enabled', 'checker' )
33
else:
34
    keywords = defaultkeywords
35
36
37
bus = dbus.SystemBus()
38
mandos_dbus_objc = bus.get_object(busname, object_path)
39
mandos_serv = dbus.Interface(mandos_dbus_objc, dbus_interface = interface)
40
mandos_clients = mandos_serv.GetAllClientsWithProperties()
41
42
def valuetostring(x):
43
    if type(x) is dbus.Boolean:
44
        return "Yes" if x else "No"
45
    else:
46
        return str(x)
47
48
format_string = ' '.join('%%-%ds'
49
                         % max(len(tablewords[key]),
50
                               max(len(valuetostring(client[key]))
51
                                   for client
52
                                   in mandos_clients.itervalues()))
53
                         for key in keywords)
54
print format_string % tuple(tablewords[key] for key in keywords) 
55
for client in mandos_clients.itervalues():
56
    print format_string % tuple(valuetostring(client[key]) for key in keywords)
57
58