summaryrefslogtreecommitdiffstats
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
parent058d1fcf51ad6cf7c6b334ac2cac4408b168d0d7 (diff)
parentde8c7b0950103fed60ce15e8474a270e96c688ad (diff)
Merge branch 'master' of ssh://github.com/krebscode/painload
-rw-r--r--Reaktor/IRC/ircasy.py4
-rwxr-xr-xReaktor/IRC/reaktor.py6
-rwxr-xr-xReaktor/commands/nag42
-rw-r--r--Reaktor/config.py19
-rw-r--r--retiolum/hosts/bergwerk11
-rw-r--r--retiolum/hosts/irvis11
-rw-r--r--sites/reaktor-nag/setup-reaktor-nag.journal10
7 files changed, 62 insertions, 41 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
+ }
+]
diff --git a/retiolum/hosts/bergwerk b/retiolum/hosts/bergwerk
deleted file mode 100644
index 89aa7ca5..00000000
--- a/retiolum/hosts/bergwerk
+++ /dev/null
@@ -1,11 +0,0 @@
-Subnet = 42:a7ff:3577:0526:3986:650f:c175:30a5/128
-Subnet = 10.243.0.51/32
-Compression = 9
------BEGIN RSA PUBLIC KEY-----
-MIIBCgKCAQEAuCX8FVI6xQepPf0goaErA35grHcBNbYvzKIXzEIOEuxiVLX4FXoY
-aHdUaz9Z2/rECuDQCVzke3TLZgBn9ai7ruT5U077h0q69pS/vI/Hr2e3s50tQVcu
-eD4DuudxIZ+DlMSeEaYed5OcH7C7KGL8Dg/2kzoTUjFqG2zwfHft8/Yszkwzt7/W
-FwIkekkPTY+dpLVlFBKQnqXtcB5FvgL55MwhLXbQRWIqJnOuMdqzp4KwHku2PVs6
-0LW8saAzxTzIyEjJGd6rT+zDirhKmmWd/08YhgJ00XiYNkrFFyJPwtF/0CISTjBO
-Uy0jafckZyAleQCzhg2753fEh8+n8NARNQIDAQAB
------END RSA PUBLIC KEY-----
diff --git a/retiolum/hosts/irvis b/retiolum/hosts/irvis
deleted file mode 100644
index 923a0dd7..00000000
--- a/retiolum/hosts/irvis
+++ /dev/null
@@ -1,11 +0,0 @@
-Subnet = 10.243.159.20
-Subnet = 42:db9b:ea89:dca4:fc6e:309b:23f0:ec09
-
------BEGIN RSA PUBLIC KEY-----
-MIIBCgKCAQEAr9EwWsVkeNqkFIvMYt/QalEGhKYTpM1MxR4DCG7hhZJcXOpigSC0
-fsB61FM/LkvG32/OTt7vPXSRfPW8RnRL0lxedNbMnax3pjgzP4yl4BAvEQW7AW/A
-silSYFAr+4Br9ng99kQniXg+RJ9QHLq4Rg0V1/aOZWNWmSk4PmAzQfzINpTXZC3G
-dUidZRIWJPTE1lJQfEpML1OI0UfiaYIAOE7Jhx+3vpzsePLF9s6iiw66ANg8mfFC
-fb8OHP4zPrnoR/NSNLGjrhyXxiq2EMUmcG38xn769cMEvElzPd0pHYuEzTeYxlk5
-0YEqAsjMYIdaxVDMczRmP+BFH/+sdUcjAwIDAQAB
------END RSA PUBLIC KEY-----
diff --git a/sites/reaktor-nag/setup-reaktor-nag.journal b/sites/reaktor-nag/setup-reaktor-nag.journal
new file mode 100644
index 00000000..6227aa37
--- /dev/null
+++ b/sites/reaktor-nag/setup-reaktor-nag.journal
@@ -0,0 +1,10 @@
+2014-07-15
+ useradd -m Reaktor
+ visudo # add Reaktor
+ sudo -u Reaktor -i mkdir /home/Reaktor/state
+ cd krebs/painload/Reaktor
+ $EDITOR config.py
+ # edit on_ping to point to some valid services_repo
+ # edit anything else relevant
+ # deploy Reaktor's pubkey to services_repo-host
+ sudo -u Reaktor -i $PWD/index