]>
Commit | Line | Data |
---|---|---|
f37913e8 | 1 | #!/usr/bin/python3 |
73db5226 MT |
2 | ############################################################################### |
3 | # # | |
4 | # collecty - A system statistics collection daemon for IPFire # | |
5 | # Copyright (C) 2012 IPFire development team # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
c968f6d9 | 22 | import argparse |
8ee5a71a | 23 | import datetime |
c968f6d9 | 24 | import dbus |
cb1ccb4f | 25 | import os |
73241420 | 26 | import platform |
c968f6d9 MT |
27 | import sys |
28 | ||
44cc4f59 | 29 | from . import bus |
f37913e8 | 30 | from .i18n import _ |
73db5226 | 31 | |
98e1046a | 32 | class Collecty(object): |
c968f6d9 MT |
33 | def __init__(self): |
34 | self.bus = dbus.SystemBus() | |
35 | ||
44cc4f59 | 36 | self.proxy = self.bus.get_object(bus.DOMAIN, "/GraphGenerator") |
c968f6d9 | 37 | |
6d7f3cac MT |
38 | def backup(self, filename): |
39 | """ | |
40 | Writes a backup of everything to file given filehandle | |
41 | """ | |
42 | self.proxy.Backup(filename) | |
43 | ||
8ee5a71a MT |
44 | def last_update(self, template_name, **kwargs): |
45 | last_update = self.proxy.LastUpdate(template_name, kwargs) | |
46 | ||
47 | if last_update: | |
48 | last_update["timestamp"] = datetime.datetime.strptime(last_update["timestamp"], "%Y-%m-%dT%H:%M:%S") | |
49 | ||
50 | return last_update | |
51 | ||
c968f6d9 MT |
52 | def list_templates(self): |
53 | templates = self.proxy.ListTemplates() | |
54 | ||
55 | return ["%s" % t for t in templates] | |
56 | ||
a3864812 MT |
57 | def graph_info(self, template_name, **kwargs): |
58 | graph_info = self.proxy.GraphInfo(template_name, kwargs, | |
59 | signature="sa{sv}") | |
60 | ||
61 | return dict(graph_info) | |
62 | ||
c968f6d9 | 63 | def generate_graph(self, template_name, **kwargs): |
a3864812 | 64 | graph = self.proxy.GenerateGraph(template_name, kwargs, |
c968f6d9 MT |
65 | signature="sa{sv}") |
66 | ||
67 | # Convert the byte array into a byte string again | |
a3864812 MT |
68 | if graph: |
69 | graph["image"] = bytes(graph["image"]) | |
70 | ||
71 | return graph | |
c968f6d9 | 72 | |
df5b7dcf MT |
73 | def version(self): |
74 | """ | |
75 | Returns the version of the daemon | |
76 | """ | |
77 | return self.proxy.Version() |