From b62400bcfa8f5551ea8c3ef7c5f2aecf008bd7f0 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 11 Aug 2014 21:41:42 +0200 Subject: Reaktor nag: add support for service inspection --- Reaktor/commands/nag | 17 ++++++++++++++++- Reaktor/config.py | 16 ++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Reaktor/commands/nag b/Reaktor/commands/nag index e552e11c..fabeec8d 100755 --- a/Reaktor/commands/nag +++ b/Reaktor/commands/nag @@ -35,17 +35,32 @@ 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' ' ') +if test "${inspect_services-false}" = true; then + missing_owners=$(set +f; cd nag.services && grep '^owner:$' * | cut -d: -f1) + missing_mailtos=$(set +f; cd nag.services && grep '^mailto:$' * | cut -d: -f1) +fi # # output # +did_nag=false if test -n "$missing_services"; then echo missing services: $missing_services + did_nag=true fi if test -n "$obsolete_services"; then echo obsolete services: $obsolete_services + did_nag=true +fi +if test -n "${missing_owners-}"; then + echo services with missing owner entry: $missing_owners + did_nag=true +fi +if test -n "${missing_mailtos-}"; then + echo services with missing mailto entry: $missing_mailtos + did_nag=true fi # if asked directly, answer if there is nothing to nag about -if test -z "$missing_services$obsolete_services" -a -n "${_from:-}";then +if test $did_nag = false -a -n "${_from:-}";then echo "nothing to nag about" fi diff --git a/Reaktor/config.py b/Reaktor/config.py index 9feecbaf..8a83b28e 100644 --- a/Reaktor/config.py +++ b/Reaktor/config.py @@ -21,6 +21,12 @@ irc_channels = [ admin_file=workdir+'/admin.lst' auth_file=workdir+'/auth.lst' +nag_env={ + 'hosts_repo': 'https://github.com/krebscode/hosts', + 'services_repo': 'gitolite@localhost:services', + 'inspect_services': 'false' +} + config_filename = abspath(__file__) # me is used, so name cannot kill our patterns below @@ -58,10 +64,7 @@ public_commands = [ default_command('tell', cmd='tell-on_privmsg', env={ 'state_file': workdir + '/tell.txt' }), - default_command('nag',env={ - 'hosts_repo': 'https://github.com/krebscode/hosts', - 'services_repo': 'gitolite@localhost:services' - }), + default_command('nag', env=nag_env), simple_command('identify', env={ 'config_filename': config_filename }), @@ -89,10 +92,7 @@ on_ping = [ { 'capname': 'nag', 'argv': [ 'commands/nag' ], - 'env': { - 'hosts_repo': 'https://github.com/krebscode/hosts', - 'services_repo': 'gitolite@localhost:services' - }, + 'env': nag_env, 'targets': irc_channels } ] -- cgit v1.2.3 From 2bcb24199008ae2852af9a62e12959da5f67411b Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 11 Aug 2014 22:01:41 +0200 Subject: Reaktor nag: dry up output function with eval^_^ --- Reaktor/commands/nag | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/Reaktor/commands/nag b/Reaktor/commands/nag index fabeec8d..8962d9fb 100755 --- a/Reaktor/commands/nag +++ b/Reaktor/commands/nag @@ -40,26 +40,28 @@ if test "${inspect_services-false}" = true; then missing_mailtos=$(set +f; cd nag.services && grep '^mailto:$' * | cut -d: -f1) fi +nag_missing_services='missing services' +nag_obsolete_services='obsolete services' +nag_missing_owners='services with missing owner entry' +nag_missing_mailtos='services with missing mailto entry' + # # output # did_nag=false -if test -n "$missing_services"; then - echo missing services: $missing_services - did_nag=true -fi -if test -n "$obsolete_services"; then - echo obsolete services: $obsolete_services - did_nag=true -fi -if test -n "${missing_owners-}"; then - echo services with missing owner entry: $missing_owners - did_nag=true -fi -if test -n "${missing_mailtos-}"; then - echo services with missing mailto entry: $missing_mailtos - did_nag=true -fi +for i in \ + missing_services \ + obsolete_services \ + missing_owners \ + missing_mailtos +do + eval "offenders=\$$i; nag_msg=\$nag_$i" + if test -n "$offenders"; then + echo $nag_msg: $offenders + did_nag=true + fi +done + # if asked directly, answer if there is nothing to nag about if test $did_nag = false -a -n "${_from:-}";then echo "nothing to nag about" -- cgit v1.2.3