From 9a0d3883b9d9a0c1ae8eb537775e007f2c61d292 Mon Sep 17 00:00:00 2001 From: neingeist Date: Tue, 22 Sep 2015 18:40:01 +0200 Subject: [PATCH 1/5] Add fetchmail-error to print fetchmail errors since yesterday --- fetchmail-errors | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 fetchmail-errors diff --git a/fetchmail-errors b/fetchmail-errors new file mode 100755 index 0000000..a0d297a --- /dev/null +++ b/fetchmail-errors @@ -0,0 +1,25 @@ +#!/usr/bin/python +"""Print fetchmail errors in journal since yesterday, if more than MINCOUNT""" + +import datetime +import systemd.journal as journal + + +yesterday = datetime.datetime.today() - datetime.timedelta(1) +SINCE = yesterday +MINCOUNT = 5 + + +j = journal.Reader() +j.log_level(journal.LOG_ERR) # or more severe +j.add_match(_COMM="fetchmail") + + +entries = [entry for entry in j + # j.seek_realtime() does not work as expected, so filtering here: + if entry['_SOURCE_REALTIME_TIMESTAMP'] >= SINCE] + +if len(entries) >= MINCOUNT: + for entry in entries: + print(entry['_SOURCE_REALTIME_TIMESTAMP']) + print(entry['MESSAGE']) From 40bcd9d842b4d775fa9ae7ff344a22866b61696c Mon Sep 17 00:00:00 2001 From: neingeist Date: Sun, 27 Sep 2015 08:30:30 +0200 Subject: [PATCH 2/5] Add docker-check-updates to check for updates in Docker images --- docker-check-updates | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 docker-check-updates diff --git a/docker-check-updates b/docker-check-updates new file mode 100755 index 0000000..ac51ffe --- /dev/null +++ b/docker-check-updates @@ -0,0 +1,21 @@ +#!/usr/bin/python +"""Check Docker images for security/distro updates. Assumes DNF.""" + +from __future__ import division, print_function +from docker import Client +import subprocess + +c = Client(base_url='unix://var/run/docker.sock') +for container in c.containers(): + name = container['Names'][0] + id_ = container['Id'] + image_id = c.inspect_container(id_)['Image'] + + print('Container: {}'.format(name)) + print('Image: {} '.format(image_id)) + + # Not using the API here for simplicity (for now) + subprocess.call(['docker', 'run', '-t', '--rm', + image_id, + '/bin/bash', '-c', + 'dnf -q check-update; if [ $? == 100 ]; then echo "Updates available"; fi']) From 1bbbabac2694fdeee0e80e4a5930c141e7b82cc1 Mon Sep 17 00:00:00 2001 From: neingeist Date: Sun, 27 Sep 2015 09:08:48 +0200 Subject: [PATCH 3/5] PEP8ify docker-check-updates --- docker-check-updates | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/docker-check-updates b/docker-check-updates index ac51ffe..7d1aefb 100755 --- a/docker-check-updates +++ b/docker-check-updates @@ -7,15 +7,17 @@ import subprocess c = Client(base_url='unix://var/run/docker.sock') for container in c.containers(): - name = container['Names'][0] - id_ = container['Id'] - image_id = c.inspect_container(id_)['Image'] + name = container['Names'][0] + id_ = container['Id'] + image_id = c.inspect_container(id_)['Image'] - print('Container: {}'.format(name)) - print('Image: {} '.format(image_id)) + print('Container: {}'.format(name)) + print('Image: {} '.format(image_id)) - # Not using the API here for simplicity (for now) - subprocess.call(['docker', 'run', '-t', '--rm', - image_id, - '/bin/bash', '-c', - 'dnf -q check-update; if [ $? == 100 ]; then echo "Updates available"; fi']) + # Not using the API here for simplicity (for now) + subprocess.call(['docker', 'run', '-t', '--rm', + image_id, + '/bin/bash', '-c', + + 'dnf -q check-update;' + + 'if [ $? == 100 ]; then echo "Updates available"; fi']) From 65b29098b5358b5c284ba5ae034a096d00d34d44 Mon Sep 17 00:00:00 2001 From: neingeist Date: Mon, 28 Sep 2015 08:45:02 +0200 Subject: [PATCH 4/5] maildir-zero: allow configuring in a config file --- maildir-zero | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/maildir-zero b/maildir-zero index a9ebe81..9fdeeef 100755 --- a/maildir-zero +++ b/maildir-zero @@ -7,7 +7,7 @@ from __future__ import division, print_function import os import os.path import re - +import yaml def maildirs(startdir): for dirpath, dirnames, _ in os.walk(startdir): @@ -35,9 +35,15 @@ def mailbox_name(maildir, root): return name -ignore_zero = True -ignore = [r'spam'] -sort_by_count = True +config_filename = '~/.config/maildir-zero.yml' +config = {} +try: + config = yaml.load(open(os.path.expanduser(config_filename))) +except: + pass +ignore_zero = config.setdefault('ignore_zero', True) +ignore = config.setdefault('ignore', [r'spam']) +sort_by_count = config.setdefault('sort_by_count', True) root = os.path.expanduser('~/Maildir') From bf643b1fa8c40ef0984eec8b40aaccf83ddd85a7 Mon Sep 17 00:00:00 2001 From: neingeist Date: Mon, 28 Sep 2015 08:51:22 +0200 Subject: [PATCH 5/5] maildir-zero: use dict.get() instead of dict.setdefault() --- maildir-zero | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/maildir-zero b/maildir-zero index 9fdeeef..5366c35 100755 --- a/maildir-zero +++ b/maildir-zero @@ -41,9 +41,9 @@ try: config = yaml.load(open(os.path.expanduser(config_filename))) except: pass -ignore_zero = config.setdefault('ignore_zero', True) -ignore = config.setdefault('ignore', [r'spam']) -sort_by_count = config.setdefault('sort_by_count', True) +ignore_zero = config.get('ignore_zero', True) +ignore = config.get('ignore', [r'spam']) +sort_by_count = config.get('sort_by_count', True) root = os.path.expanduser('~/Maildir')