#!/usr/bin/python3

import argparse
import json
import socket
import time
from ws4py.client import threadedclient


parser = argparse.ArgumentParser(description='iconograph fetcher')
parser.add_argument(
    '--server',
    dest='server',
    action='store',
    required=True)
parser.add_argument(
    '--https-ca-cert',
    dest='https_ca_cert',
    action='store',
    required=True)
parser.add_argument(
    '--https-client-cert',
    dest='https_client_cert',
    action='store',
    required=True)
parser.add_argument(
    '--https-client-key',
    dest='https_client_key',
    action='store',
    required=True)
parser.add_argument(
    '--image-type',
    dest='image_type',
    action='store',
    required=True)
FLAGS = parser.parse_args()


class Client(threadedclient.WebSocketClient):

  def Loop(self):
    self.daemon = True
    self.connect()
    while True:
      self.send(json.dumps({
        'type': 'report',
        'data': {
          'hostname': socket.gethostname(),
          'uptime_seconds': self._Uptime(),
          'image_type': FLAGS.image_type,
        },
      }), False)
      time.sleep(5.0)

  def _Uptime(self):
    with open('/proc/uptime', 'r') as fh:
      return int(float(fh.readline().split(' ', 1)[0]))

  def received_message(self, msg):
    parsed = json.loads(str(msg))
    if parsed['type'] == 'image_types':
      assert FLAGS.image_type in parsed['data']['image_types']


def main():
  ssl_options = {
    'keyfile': FLAGS.https_client_key,
    'certfile': FLAGS.https_client_cert,
    'ca_certs': FLAGS.https_ca_cert,
  }
  client = Client('wss://%s/ws/slave' % FLAGS.server, protocols=['iconograph-slave'], ssl_options=ssl_options)
  client.Loop()


if __name__ == '__main__':
  main()

@@ -41,16 +41,26 @@
 rt json%0A
+import os%0A
 import s
@@ -214,22 +214,22 @@
 %0A    '--
-server
+config
 ',%0A    d
@@ -233,22 +233,22 @@
   dest='
-server
+config
 ',%0A    a
@@ -262,37 +262,54 @@
 store',%0A    
-required=True
+default='/etc/iconograph.json'
 )%0Aparser.add
@@ -671,18 +671,14 @@
  '--
-image-type
+server
 ',%0A 
@@ -686,26 +686,22 @@
   dest='
-image_type
+server
 ',%0A    a
@@ -811,16 +811,181 @@
 ient):%0A%0A
+  def __init__(self, config_path, *args, **kwargs):%0A    super().__init__(*args, **kwargs)%0A    with open(config_path, 'r') as fh:%0A      self._config = json.load(fh)%0A%0A
   def Lo
@@ -1062,77 +1062,19 @@
     
-self.send(json.dumps(%7B%0A        'type': 'report',%0A        'data':
+report =
  %7B%0A
-  
     
@@ -1107,26 +1107,24 @@
 hostname(),%0A
-  
         'upt
@@ -1165,51 +1165,168 @@
     
-  'image_type': FLAGS.image_type,%0A        %7D
+'next_timestamp': self._NextTimestamp(),%0A      %7D%0A      report.update(self._config)%0A      self.send(json.dumps(%7B%0A        'type': 'report',%0A        'data': report
 ,%0A  
@@ -1483,16 +1483,169 @@
 )%5B0%5D))%0A%0A
+  def _NextTimestamp(self):%0A    next_image = os.path.basename(os.readlink('/isodevice/iconograph/current'))%0A    return int(next_image.split('.', 1)%5B0%5D)%0A%0A
   def re
@@ -1699,15 +1699,30 @@
 ads(
-str(msg
+msg.data.decode('utf8'
 ))%0A 
@@ -1773,22 +1773,30 @@
  assert 
-FLAGS.
+self._config%5B'
 image_ty
@@ -1797,16 +1797,18 @@
 age_type
+'%5D
  in pars
@@ -2004,16 +2004,43 @@
  Client(
+%0A      FLAGS.config,%0A      
 'wss://%25
@@ -2066,16 +2066,22 @@
 .server,
+%0A     
  protoco
@@ -2104,16 +2104,22 @@
 slave'%5D,
+%0A     
  ssl_opt

Make client report more data, use system config