Laur IVAN

Monitor ethOS Distro with Elastic Search – 2

Posted by in IT, Software, Tutorial

Following the previous post, we are now in position to install the monitoring code on the monitoried machine, of course. The easiest way is to download the code on the machine in /home/ethos. Following steps will assume you have the unpacked code in

Once you have downloaded the code, you need to add the location of the ElasticSearch server to the local.conf:

Dissecting the scripts The scripts are written in PHP, like ethOS‘s own scripts. I did that for two reasons: Take advantage of the already written code…read more

Monitor ethOS Distro with Elastic Search – 1

Posted by in IT, Software

TL;DR: It’s possible to monitor your ethos distro install on an ElasticSearch instance. I like EthOS. I like its panel too, but at the time of writing it had some issues on updating values This was somewhat unfortunate because it’s the same time when I set up my rig so monitoring without typing show stats every minute or so was quite important. So, I’ve proceeded to try and find a replacement for the panel. Initially, I’ve thought to develop my own solution with something like django, but since I’m not…read more

Match String on Multiple Columns

Posted by in Software

TL;DR: Use concatenation, Luke! I had to search a name for an user in a table containing the first and last names in separate columns. After a while I got tired on looking up the first_name and last_name columns one at a time and I decided to try and search both. The result is something like:

I have to do the LOWER() call because the names are provided by user input. At first I’ve been worried about performance, but since this is not a recurrent query, it’s acceptable (0.25s…read more

Make a Shell Script with Arguments (Native)

Posted by in Software, Tutorial

I was building a bash script and I needed several arguments to make it more versatile (e.g. dry-run). The list of parameters was: help as -h or –help dry run ad -d or –dry-run to go through the motions without actually executing commands keep last N images ad -k num or –keep num to keep last N images (default 5) As one can see, none of the parameters are compulsory and have default values:

The snipped taking care of my input parameters is:

The idea is that we…read more

Handler for Global Logger in Python

Posted by in Software, Tutorial

While writing a command line tool, I’ve stumbled upon a strange situation: Some logs were written to a file while some others were printed to console. Quite annoying, particularly since every module I use has its own logger via logging.getLogger(__name__). After some investigation I found out you can access the global logger via logging.getLogger() (note the lack of parameters). So, my new setup is:

Simple. HTH, A little experiment: If you find this post and ad below useful, please check the ad out :-)

Some Resources for Sony Alpha Development

Posted by in Idea, Software

Every time I get a gadget I think of building something for it. Since I’ve gotten a Sony A6000 things are not different, particularly because I have some issues with the default Sony Android app requiring GPS location (and insisting not to work without it). Therefore, I would like to build an app which makes various permissions optional (e.g. storage access, GPS) and another one to allow me to add some metadata to images on the fly (ideally). While investigating, I stumbled upon the following resources: Official Sony API for…read more

DRF: What is ‘source’ in Fields?

Posted by in Software, Tutorial

For a couple of days I’ve been trying to de-serialise a JSON to a model. My problem is the model and the JSON have different fields, mainly to keep the model pythonic and independent of a specific JSON source. So… I’ve been trying to use the source parameter for each Field in my serialiser to map to the JSON. E.g. if my Django Model field would be named timestamp and my JSON would be named time, I would have a serialiser Field like this:

THIS IS WRONG! It’s actually…read more

Timestamp to DateTime Serializer Field for DRF

Posted by in Software, Tutorial

I’m currently trying to deserialize JSON data to a Django model. This is quite straight forward for most numeric fields, but I have a DateTime field which is stored as a timestamp in the original JSON. At first, I thought I should read the timestamp as an integer and convert it through post-processing. Then, after reading more of the DRF docs, it became evident I needed a custom field. The code is below:

The idea is that to_representation converts a DateTime field into a timestamp value for serialisation and…read more

Run Celery 4.1.0 on Windows 10

Posted by in Software, Tutorial

TL;DR: Use set FORKED_BY_MULTIPROCESSING=1 on the worker script/shell When running Celery on Windows 10, I got the following error: ValueError: not enough values to unpack (expected 3, got 0) This is quite unfortunate as Windows is supported on “best effort”. A pull request has a change, but it’s not pretty to patch an installation. To get around, you can just define an environment variable:

I only defined it on the worker’s side. HTH, A little experiment: If you find this post and ad below useful, please check the ad…read more

Use Docker Behind Proxy on Windows 8

Posted by in Software, Tutorial

The other day I had to install Docker at work, aka behind a corporate proxy (on Windows 8). While the docker installer is stand-alone and all is good, dealing with the VM is a different matter… The problem popped up when I tried to create a Django image and pip install failed miserably. To get around, you need to create a docker machine:

You also need to pass in the proxy as a build argument to build:

You can also pass the build argument to docker-compose but, in…read more