# python monitoring client arke is a dumb python monitoring client i am currently working on to monitor http status and docker container runtime. ### http status: - monitor znc server http status - monitor pleroma server http status ### docker runtime: - slackbot ## structure - runtime file - vars file that points the client at my servers ## TODO - [X] Fix loading json from file - alright see "json loading" heading in this file. - [X] Fix state comparison and post to only post the item that has changed since last run - i thought I mostly had this fixed but i'm still running into issues. - requires some additional digging. - [X] update this readme. ## json loading confused here. in python, a dict is the key/value store that is used to map to json. all my functions return a dict: ``` python def monitor_HttpTargets(monitoringtargets): responseTable = {} ... return responseTable def monitor_DomainExpiry(targets): responseTable = {} ... return responseTable def monitor_TlsExpiry(targets): responseTable = {} ... return responseTable ``` Ok so that part's straight forward. Then, i combine all of them into a single keyed dict, so I have a dict of dicts: ``` python datastore = {} datastore['http'] = monitor_HttpTargets(arkevars.httpTargets) datastore['certs'] = monitor_TlsExpiry(arkevars.tlsTargets) datastore['whois'] = monitor_DomainExpiry(arkevars.domains_to_check) ``` OK again, straight forward. Here's where shit gets less obvious to me. I need to convert this variable containing a dict into a json object in a file. I do this like so: ```python # write new results to file with open(this_round_file, "a+", encoding="utf-8") as outfile: json.dump(datastore, outfile, ensure_ascii=False, sort_keys=True) ``` ok, so crafting the json object seems to make sense, and seems to be pretty straight forward. What about reading the 'json' object? WELL THEREIN LIES THE TALE MY GOOD BITCH ```python Traceback (most recent call last): File "arke.py", line 114, in json_data = json.load(json_File) File "/usr/lib/python3.8/json/__init__.py", line 293, in load return loads(fp.read(), File "/usr/lib/python3.8/json/__init__.py", line 357, in loads return _default_decoder.decode(s) File "/usr/lib/python3.8/json/decoder.py", line 340, in decode raise JSONDecodeError("Extra data", s, end) json.decoder.JSONDecodeError: Extra data: line 1 column 133 (char 132) ``` this is where I get. loading that file doesn't work. Which seems to suggest that how I'm crafting the json string written to the file with `json.dump` is problematic! But I haven't figured out /why/ ugh. ### fixed oh my god i wasn't cleaning up the file after last run so previous run charactes was fucking up the file!!! aaaah!