summaryrefslogtreecommitdiffstats
path: root/Reaktor
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2014-07-15 15:22:03 +0200
committermakefu <github@syntax-fehler.de>2014-07-15 15:22:03 +0200
commitbae95b3f9e926e381fe429a182f232e9a6c0b857 (patch)
tree4a36affc350be40c933272110c2c9ebe94d0cc06 /Reaktor
parent058d1fcf51ad6cf7c6b334ac2cac4408b168d0d7 (diff)
parentde8c7b0950103fed60ce15e8474a270e96c688ad (diff)
Merge branch 'master' of ssh://github.com/krebscode/painload
Diffstat (limited to 'Reaktor')
-rw-r--r--Reaktor/IRC/ircasy.py4
-rwxr-xr-xReaktor/IRC/reaktor.py6
-rwxr-xr-xReaktor/commands/nag42
-rw-r--r--Reaktor/config.py19
4 files changed, 52 insertions, 19 deletions
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/commands/nag b/Reaktor/commands/nag
index 68035831..24414dd3 100755
--- a/Reaktor/commands/nag
+++ b/Reaktor/commands/nag
@@ -1,22 +1,41 @@
#! /bin/sh
set -euf
-cd "$workdir"
-
-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
+
+
+# usage: git_pull_output_filter REPO_NAME
+git_pull_output_filter() {
+ sed -n 's/^ [0-9]\+ file change/'"$1"': &/p'
+}
-(cd "$hostsdir" && ls | sort) > nag.hosts
-(cd "$servicesdir" && ls | sort) > nag.services
-diff -u nag.hosts nag.services > nag.patch || :
+if ! test -d nag.hosts; then
+ git clone "$hosts_repo" nag.hosts
+else
+ (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 services
+fi
+
+
+(cd nag.hosts && ls | sort) > nag.hosts.ls
+(cd nag.services && ls | sort) > nag.services.ls
+
+diff -u nag.hosts.ls nag.services.ls > 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 +43,6 @@ 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
-fi
-if test -z "$missing_services$superfluous_services"; then
- echo hosts and services are in sync
+if test -n "$obsolete_services"; then
+ echo obsolete services: $obsolete_services
fi
diff --git a/Reaktor/config.py b/Reaktor/config.py
index 247838d6..0483d46b 100644
--- a/Reaktor/config.py
+++ b/Reaktor/config.py
@@ -70,12 +70,7 @@ public_commands = [
})
]
commands = [
- default_command('reload')
- default_command('nag', env={
- 'workdir': workdir,
- 'hostsdir': '/home/tv/krebs/hosts',
- 'servicesdir': '/home/tv/krebs/services'
- })
+ default_command('reload'),
]
on_join = [
@@ -85,3 +80,15 @@ on_join = [
'env': { 'state_file': workdir + '/tell.txt' }
}
]
+
+on_ping = [
+ {
+ 'capname': 'nag',
+ 'argv': [ 'commands/nag' ],
+ 'env': {
+ 'hosts_repo': 'https://github.com/krebscode/hosts',
+ 'services_repo': '/home/tv/krebs/services'
+ },
+ 'targets': irc_channels
+ }
+]