]> git.ipfire.org Git - collecty.git/blame - src/collecty/client.py
collectly-client: Move CLI code into CLI script
[collecty.git] / src / collecty / client.py
CommitLineData
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 22import argparse
8ee5a71a 23import datetime
c968f6d9 24import dbus
cb1ccb4f 25import os
73241420 26import platform
c968f6d9
MT
27import sys
28
f37913e8
MT
29from .constants import *
30from .i18n import _
73db5226
MT
31
32import logging
33log = logging.getLogger("collectly.client")
34
35class CollectyClient(object):
c968f6d9
MT
36 def __init__(self):
37 self.bus = dbus.SystemBus()
38
39 self.proxy = self.bus.get_object(BUS_DOMAIN, "/GraphGenerator")
40
6d7f3cac
MT
41 def backup(self, filename):
42 """
43 Writes a backup of everything to file given filehandle
44 """
45 self.proxy.Backup(filename)
46
8ee5a71a
MT
47 def last_update(self, template_name, **kwargs):
48 last_update = self.proxy.LastUpdate(template_name, kwargs)
49
50 if last_update:
51 last_update["timestamp"] = datetime.datetime.strptime(last_update["timestamp"], "%Y-%m-%dT%H:%M:%S")
52
53 return last_update
54
c968f6d9
MT
55 def list_templates(self):
56 templates = self.proxy.ListTemplates()
57
58 return ["%s" % t for t in templates]
59
a3864812
MT
60 def graph_info(self, template_name, **kwargs):
61 graph_info = self.proxy.GraphInfo(template_name, kwargs,
62 signature="sa{sv}")
63
64 return dict(graph_info)
65
c968f6d9 66 def generate_graph(self, template_name, **kwargs):
a3864812 67 graph = self.proxy.GenerateGraph(template_name, kwargs,
c968f6d9
MT
68 signature="sa{sv}")
69
70 # Convert the byte array into a byte string again
a3864812
MT
71 if graph:
72 graph["image"] = bytes(graph["image"])
73
74 return graph
c968f6d9 75
df5b7dcf
MT
76 def version(self):
77 """
78 Returns the version of the daemon
79 """
80 return self.proxy.Version()