From 2ea6f2e2bbb2d90f11f07b7bc088697ca1264e87 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 15 Jul 2014 11:22:03 +0200 Subject: Reaktor config: fix typo --- Reaktor/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Reaktor') diff --git a/Reaktor/config.py b/Reaktor/config.py index 247838d6..1741be20 100644 --- a/Reaktor/config.py +++ b/Reaktor/config.py @@ -70,7 +70,7 @@ public_commands = [ }) ] commands = [ - default_command('reload') + default_command('reload'), default_command('nag', env={ 'workdir': workdir, 'hostsdir': '/home/tv/krebs/hosts', -- cgit v1.2.3 From e2b4d5270b996322583038e3e1037b4e5c339bb9 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 15 Jul 2014 12:12:28 +0200 Subject: Reaktor on_ping -> nag --- Reaktor/IRC/ircasy.py | 4 ++++ Reaktor/IRC/reaktor.py | 6 ++++++ Reaktor/config.py | 18 +++++++++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) (limited to 'Reaktor') diff --git a/Reaktor/IRC/ircasy.py b/Reaktor/IRC/ircasy.py index 99fbc324..38f202fc 100644 --- a/Reaktor/IRC/ircasy.py +++ b/Reaktor/IRC/ircasy.py @@ -110,6 +110,7 @@ class asybot(asychat): if command == 'PING': self.push('PONG :%s' % rest) self.log.debug("Replying to servers PING with PONG :%s" %rest) + self.on_ping(prefix, command, params, rest) elif command == 'PRIVMSG': self.on_privmsg(prefix, command, params, rest) @@ -185,6 +186,9 @@ class asybot(asychat): def on_join(self, prefix, command, params, rest): pass + def on_ping(self, prefix, command, params, rest): + pass + def on_privmsg(self, prefix, command, params, rest): pass diff --git a/Reaktor/IRC/reaktor.py b/Reaktor/IRC/reaktor.py index 9a3424a6..799fe555 100755 --- a/Reaktor/IRC/reaktor.py +++ b/Reaktor/IRC/reaktor.py @@ -39,6 +39,12 @@ class Reaktor(asybot): for command in getconf('on_join', []): self.execute_command(command, None, prefix, params) + def on_ping(self, prefix, command, params, rest): + for command in getconf('on_ping', []): + prefix = '!' # => env = { _prefix: '!', _from: '' } + params = command.get('targets') # TODO why don't we get a list here and use ','.join() ? + self.execute_command(command, None, prefix, params) + def on_privmsg(self, prefix, command, params, rest): for command in getconf('commands'): y = match(command['pattern'], rest) diff --git a/Reaktor/config.py b/Reaktor/config.py index 1741be20..98f17d67 100644 --- a/Reaktor/config.py +++ b/Reaktor/config.py @@ -71,11 +71,6 @@ public_commands = [ ] commands = [ default_command('reload'), - default_command('nag', env={ - 'workdir': workdir, - 'hostsdir': '/home/tv/krebs/hosts', - 'servicesdir': '/home/tv/krebs/services' - }) ] on_join = [ @@ -85,3 +80,16 @@ on_join = [ 'env': { 'state_file': workdir + '/tell.txt' } } ] + +on_ping = [ + { + 'capname': 'nag', + 'argv': [ 'commands/nag' ], + 'env': { + 'workdir': workdir, + 'hostsdir': '/home/tv/krebs/hosts', + 'servicesdir': '/home/tv/krebs/services' + }, + 'targets': irc_channels + } +] -- cgit v1.2.3 From 40b6bc968a5b6d1d12d2cddefeeb472fa8462f9a Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 15 Jul 2014 12:26:49 +0200 Subject: Reaktor nag: s/superfluous/obsolete/g --- Reaktor/commands/nag | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Reaktor') diff --git a/Reaktor/commands/nag b/Reaktor/commands/nag index 68035831..c07ed5b8 100755 --- a/Reaktor/commands/nag +++ b/Reaktor/commands/nag @@ -16,7 +16,8 @@ trap 'rm -f nag.hosts nag.services nag.patch' EXIT INT QUIT diff -u nag.hosts nag.services > nag.patch || : missing_services=$(sed -n '1d;2d;s/^-\(.*\)/\1/p' nag.patch | tr '\n' ' ') -superfluous_services=$(sed -n '1d;2d;s/^+\(.*\)/\1/p' nag.patch | tr '\n' ' ') +obsolete_services=$(sed -n '1d;2d;s/^+\(.*\)/\1/p' nag.patch | tr '\n' ' ') + # # output @@ -24,9 +25,9 @@ superfluous_services=$(sed -n '1d;2d;s/^+\(.*\)/\1/p' nag.patch | tr '\n' ' ') if test -n "$missing_services"; then echo missing services: $missing_services fi -if test -n "$superfluous_services"; then - echo superfluous services: $superfluous_services +if test -n "$obsolete_services"; then + echo obsolete services: $obsolete_services fi -if test -z "$missing_services$superfluous_services"; then +if test -z "$missing_services$obsolete_services"; then echo hosts and services are in sync fi -- cgit v1.2.3 From e5d8e8f1b13af2b61d61288a50dcc0cd56097735 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 15 Jul 2014 12:28:45 +0200 Subject: Reaktor nag: don't cd $workdir Because Reaktor already does it... --- Reaktor/commands/nag | 2 -- Reaktor/config.py | 1 - 2 files changed, 3 deletions(-) (limited to 'Reaktor') diff --git a/Reaktor/commands/nag b/Reaktor/commands/nag index c07ed5b8..8454d84b 100755 --- a/Reaktor/commands/nag +++ b/Reaktor/commands/nag @@ -1,8 +1,6 @@ #! /bin/sh set -euf -cd "$workdir" - if test -e nag.hosts; then echo "nag seems to run already... if not, then delete $workdir/nag.*, please" exit 23 diff --git a/Reaktor/config.py b/Reaktor/config.py index 98f17d67..a09d1bce 100644 --- a/Reaktor/config.py +++ b/Reaktor/config.py @@ -86,7 +86,6 @@ on_ping = [ 'capname': 'nag', 'argv': [ 'commands/nag' ], 'env': { - 'workdir': workdir, 'hostsdir': '/home/tv/krebs/hosts', 'servicesdir': '/home/tv/krebs/services' }, -- cgit v1.2.3 From 38769e12bfbc963e1bfd3226bdc0c907209bdb09 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 15 Jul 2014 12:36:30 +0200 Subject: Reaktor nag: don't nag when in-sync --- Reaktor/commands/nag | 3 --- 1 file changed, 3 deletions(-) (limited to 'Reaktor') diff --git a/Reaktor/commands/nag b/Reaktor/commands/nag index 8454d84b..56c34c01 100755 --- a/Reaktor/commands/nag +++ b/Reaktor/commands/nag @@ -26,6 +26,3 @@ fi if test -n "$obsolete_services"; then echo obsolete services: $obsolete_services fi -if test -z "$missing_services$obsolete_services"; then - echo hosts and services are in sync -fi -- cgit v1.2.3 From 0a39b3ecd80965002044cf7ba9d0a99c94ad1261 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 15 Jul 2014 12:37:34 +0200 Subject: Reaktor nag: maintain own copies of git repos --- Reaktor/commands/nag | 23 ++++++++++++++++++----- Reaktor/config.py | 4 ++-- 2 files changed, 20 insertions(+), 7 deletions(-) (limited to 'Reaktor') diff --git a/Reaktor/commands/nag b/Reaktor/commands/nag index 56c34c01..e5380fc3 100755 --- a/Reaktor/commands/nag +++ b/Reaktor/commands/nag @@ -1,17 +1,30 @@ #! /bin/sh set -euf -if test -e nag.hosts; then +if test -e nag.hosts.ls; then echo "nag seems to run already... if not, then delete $workdir/nag.*, please" exit 23 fi -trap 'rm -f nag.hosts nag.services nag.patch' EXIT INT QUIT +trap 'rm -f nag.hosts.ls nag.services.ls nag.patch' EXIT INT QUIT -(cd "$hostsdir" && ls | sort) > nag.hosts -(cd "$servicesdir" && ls | sort) > nag.services +if ! test -d nag.hosts; then + git clone "$hosts_repo" nag.hosts | grep -v 'Alreay up-to-date.' +else + (cd nag.hosts && git pull) +fi + +if ! test -d nag.services; then + git clone "$services_repo" nag.services | grep -v 'Already up-to-date.' +else + (cd nag.services && git pull) +fi + + +(cd nag.hosts && ls | sort) > nag.hosts.ls +(cd nag.services && ls | sort) > nag.services.ls -diff -u nag.hosts nag.services > nag.patch || : +diff -u nag.hosts.ls nag.services.ls > nag.patch || : missing_services=$(sed -n '1d;2d;s/^-\(.*\)/\1/p' nag.patch | tr '\n' ' ') obsolete_services=$(sed -n '1d;2d;s/^+\(.*\)/\1/p' nag.patch | tr '\n' ' ') diff --git a/Reaktor/config.py b/Reaktor/config.py index a09d1bce..0483d46b 100644 --- a/Reaktor/config.py +++ b/Reaktor/config.py @@ -86,8 +86,8 @@ on_ping = [ 'capname': 'nag', 'argv': [ 'commands/nag' ], 'env': { - 'hostsdir': '/home/tv/krebs/hosts', - 'servicesdir': '/home/tv/krebs/services' + 'hosts_repo': 'https://github.com/krebscode/hosts', + 'services_repo': '/home/tv/krebs/services' }, 'targets': irc_channels } -- cgit v1.2.3 From 0bead921a24d9856c74ee8c1f296c2a45e634647 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 15 Jul 2014 12:42:25 +0200 Subject: Reaktor nag: git pull|grep -v 'Already up-to-date' --- Reaktor/commands/nag | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Reaktor') diff --git a/Reaktor/commands/nag b/Reaktor/commands/nag index e5380fc3..2b33d5e1 100755 --- a/Reaktor/commands/nag +++ b/Reaktor/commands/nag @@ -9,15 +9,15 @@ fi trap 'rm -f nag.hosts.ls nag.services.ls nag.patch' EXIT INT QUIT if ! test -d nag.hosts; then - git clone "$hosts_repo" nag.hosts | grep -v 'Alreay up-to-date.' + git clone "$hosts_repo" nag.hosts else - (cd nag.hosts && git pull) + (cd nag.hosts && git pull) | grep -v 'Already up-to-date.' fi if ! test -d nag.services; then - git clone "$services_repo" nag.services | grep -v 'Already up-to-date.' + git clone "$services_repo" nag.services else - (cd nag.services && git pull) + (cd nag.services && git pull) | grep -v 'Already up-to-date.' fi -- cgit v1.2.3 From 55ce96f905c2abd96346abc007d87b35a0074656 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 15 Jul 2014 12:46:42 +0200 Subject: Reaktor nag: s/grep/sed/ --- Reaktor/commands/nag | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Reaktor') diff --git a/Reaktor/commands/nag b/Reaktor/commands/nag index 2b33d5e1..7c4fd3c6 100755 --- a/Reaktor/commands/nag +++ b/Reaktor/commands/nag @@ -11,13 +11,13 @@ trap 'rm -f nag.hosts.ls nag.services.ls nag.patch' EXIT INT QUIT if ! test -d nag.hosts; then git clone "$hosts_repo" nag.hosts else - (cd nag.hosts && git pull) | grep -v 'Already up-to-date.' + (cd nag.hosts && git pull) | sed '/Already up-to-date/d' fi if ! test -d nag.services; then git clone "$services_repo" nag.services else - (cd nag.services && git pull) | grep -v 'Already up-to-date.' + (cd nag.services && git pull) | sed '/Already up-to-date/d' fi -- cgit v1.2.3 From 5d975cef395e8e52b1abbd5f8a897532c386b9d8 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 15 Jul 2014 12:57:01 +0200 Subject: Reaktor nag: factor out git_pull_output_filter --- Reaktor/commands/nag | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'Reaktor') diff --git a/Reaktor/commands/nag b/Reaktor/commands/nag index 7c4fd3c6..338c083e 100755 --- a/Reaktor/commands/nag +++ b/Reaktor/commands/nag @@ -8,16 +8,22 @@ fi trap 'rm -f nag.hosts.ls nag.services.ls nag.patch' EXIT INT QUIT + +git_pull_output_filter() { + sed -n '/^ [0-9]\+ file change/p' +} + + if ! test -d nag.hosts; then git clone "$hosts_repo" nag.hosts else - (cd nag.hosts && git pull) | sed '/Already up-to-date/d' + (cd nag.hosts && git pull) | git_pull_output_filter fi if ! test -d nag.services; then git clone "$services_repo" nag.services else - (cd nag.services && git pull) | sed '/Already up-to-date/d' + (cd nag.services && git pull) | git_pull_output_filter fi -- cgit v1.2.3 From d4d6241b6b1e948bbc52fc8dab22f098d6130af6 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 15 Jul 2014 13:03:07 +0200 Subject: Reaktor nag: git_pull_output_filter REPO_NAME --- Reaktor/commands/nag | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Reaktor') diff --git a/Reaktor/commands/nag b/Reaktor/commands/nag index 338c083e..24414dd3 100755 --- a/Reaktor/commands/nag +++ b/Reaktor/commands/nag @@ -9,21 +9,22 @@ fi trap 'rm -f nag.hosts.ls nag.services.ls nag.patch' EXIT INT QUIT +# usage: git_pull_output_filter REPO_NAME git_pull_output_filter() { - sed -n '/^ [0-9]\+ file change/p' + sed -n 's/^ [0-9]\+ file change/'"$1"': &/p' } if ! test -d nag.hosts; then git clone "$hosts_repo" nag.hosts else - (cd nag.hosts && git pull) | git_pull_output_filter + (cd nag.hosts && git pull) | git_pull_output_filter hosts fi if ! test -d nag.services; then git clone "$services_repo" nag.services else - (cd nag.services && git pull) | git_pull_output_filter + (cd nag.services && git pull) | git_pull_output_filter services fi -- cgit v1.2.3