Commit 2cd523c6 authored by Michael Völske's avatar Michael Völske

Merge branch 'master' of webis.uni-weimar.de:code-generic/code-webis-cmd

parents 1ab9c78c 77c99534
......@@ -26,7 +26,8 @@ betamng Low level scripts for managing Betaweb.
betaweb High level scripts for betaweb, e.g., Hadoop management.
check-ram
htop Show system load of all betaweb nodes using clusterssh and htop.
idrac-disks Get status of physical hard drives from Idrac
idrac-dimms Get status of dimms from idrac.
idrac-disks Get status of physical hard drives from idrac.
restart-hadoop-resourcemanager Restart hadoop ressource manager on betaweb020 and restarts nodemanager
rolling-restart Restart betaweb nodes one after another.
rolling-state Apply Salt state on nodes one after another.
......
......@@ -123,20 +123,20 @@ read_password() {
### \params $2 default ("y" or "n"), leave empty for no default
yes_no_prompt() {
if [ "y" == "$2" ]; then
echo -n "$1 [Y/n] " >&2
read -r yesno >&2
echo -en "$1 [Y/n] " >&2
read -er yesno >&2
if [ "$yesno" == "" ] || [ "$yesno" == "y" ] || [ "$yesno" == "Y" ]; then
return 0
fi
elif [ "n" == "$2" ]; then
echo -n "$1 [y/N] " >&2
read -r yesno >&2
echo -en "$1 [y/N] " >&2
read -er yesno >&2
if [ "$yesno" == "y" ] || [ "$yesno" == "Y" ]; then
return 0;
fi
else
echo -n "$1 [y/n] " >&2
read -r yesno >&2
echo -en "$1 [y/n] " >&2
read -er yesno >&2
if [ "$yesno" == "y" ] || [ "$yesno" == "Y" ]; then
return 0
......
......@@ -106,6 +106,7 @@ class ShellWrapperCommand(click.MultiCommand):
sub_argv = sub_argv[1:]
# Set cmdline environment variables with \t as split separator
sys.argv[0] = os.path.basename(sys.argv[0])
os.environ['WEBIS_CMDLINE'] = '\t'.join(sys.argv)
os.environ['WEBIS_ARGV'] = '\t'.join(sys.argv[1:])
os.environ['WEBIS_SUBCMD_ARGV'] = '\t'.join(sub_argv)
......@@ -197,11 +198,12 @@ class ShellWrapperCommand(click.MultiCommand):
match = func_regex.match(line)
if match:
name = match.group(1).replace('_', '-')
short_help = next_cmd_help[0] if next_cmd_help else ''
help_text_joined = '\n'.join(next_cmd_help).strip()
short_help = help_text_joined.strip('\n\b\t ').split('\n')[0] if help_text_joined else ''
params = self._parse_arg_defs(next_cmd_opts)
self.commands[name] = click.Command(name, params=params,
help='\n'.join(next_cmd_help).strip(), short_help=short_help,
help=help_text_joined, short_help=short_help,
callback=click.pass_context(self._cmd_callback))
next_cmd_help.clear()
......
#!/usr/bin/env bash
### \b
### Get status of ram dimms from Idrac
### Get status of dimms from idrac. The SSHPASS environment variable must be set.
### \b
### Copyright 2020-today
### Author: Alban Bruder
......
#!/bin/bash
#!/usr/bin/env bash
### \b
### Get status of physical hard drives from Idrac
### Get status of physical hard drives from idrac. The SSHPASS environment variable must be set.
### \b
### Copyright 2020-today
### \b
### Author: Michael Voelske
###
### : -p : --hostpattern : str : betamng%03.0f.medien.uni-weimar.de : seq-style pattern for hostnames to query
### : -f : --first : int : 1 : first host number to query
### : -l : --last : int : 135 : last host number to query
### : -a : --all ::: show all disks instead of only ones with errors
### : -s : --summary ::: show a summary by host instead of a full report (implies --all)
. "$WEBIS_LIB_PATH"/bashhelper.sh
. "$WEBIS_LIB_PATH"/shflags
check_tools ssh sshpass awk
### \b
### Define usage screen.
#
usage() {
echo "
Usage:
$(basename "$0")
Description:
Get status of physical hard disks as reported by idrac. The SSHPASS environment variable must be set.
"
exit 1
}
# Define and parse commandline arguments
DEFINE_string hostpattern 'betamng%03.0f.medien.uni-weimar.de' "seq-style pattern for hostnames to query" o
DEFINE_integer first 1 'first host number to query' f
DEFINE_integer last 135 'last host number to query' l
DEFINE_boolean all false "show all disks instead of only ones with errors" a
DEFINE_boolean summary false "show a summary by host instead of a full report (implies -a)" s
export FLAGS_HELP=$(usage)
FLAGS "$@" || exit 0
eval set -- "${FLAGS_ARGV}"
check_tools ssh sshpass awk column
summarize() {
awk 'BEGIN { FS="\t"; }
awk 'BEGIN { FS=","; }
{
split($1, host, "."); h=host[1];
if(!(h in total)) { total[h]=0; err[h]=0; bytes[h]=0; }
total[h] += 1;
if($3 != "OK/OK") { err[h] += 1; } else { ok[h] += 1; }
split($4, size, " "); bytes[h] += size[1];
model[$6 "(" $5 ")"] += 1;
model[$6 " (" $5 ")"] += 1;
}
END {
print "HOST\tDISKS(OK/ERR)\tSIZE";
print "HOST,DISKS (OK/ERR),SIZE";
n=asorti(total, hosts);
for(i=1; i<=n; i++) {
h=hosts[i];
print h "\t" total[h] " (" ok[h] "/" err[h] ")\t" (bytes[h] / (1024**4)) "TiB";
print h "," total[h] " (" ok[h] "/" err[h] ")," (bytes[h] / (1024**4)) "TiB";
}
print "----------";
print "DISK MODEL\tCOUNT";
print "DISK MODEL,COUNT";
for(m in model) {
print m "\t" model[m];
print m "," model[m];
}
}
'
' | column -t -s','
}
#
#
#
main() {
[ -z ${SSHPASS+x} ] && { >&2 echo "Error: SSHPASS environment variable is unset."; exit 1; }
......@@ -81,18 +56,22 @@ main() {
/^RollupStatus/ { statuses2[disk] = $2; }
END {
for(i in sizes) {
if (i > -1) print host "\t" i "\t" statuses[i] "/" statuses2[i] "\t" sizes[i] "\t" speeds[i] "\t" models[i] "\t" states[i];
if (i > -1) print host "," i "," statuses[i] "/" statuses2[i] "," sizes[i] "," speeds[i] "," models[i] "," states[i];
};
}'
SUMMARY=cat
[[ ${FLAGS_all} -eq 0 ]] && SUMMARY="grep -v 'OK/OK'";
[[ ${FLAGS_summary} -eq 0 ]] && SUMMARY="summarize";
[[ ${FLAGS_summary} -eq 1 ]] && echo -e "HOST\tDISK\tSTATUS\tSIZE\tSPEED\tMODEL\tFAILURE_STATE";
seq -f "${FLAGS_hostpattern}" ${FLAGS_first} ${FLAGS_last} \
SUMMARY=(cat)
[[ -z ${ARG_ALL} ]] && SUMMARY=(grep -v 'OK/OK');
[[ ! -z ${ARG_SUMMARY} ]] && SUMMARY=(summarize);
TABLE=(cat)
[[ -z ${ARG_SUMMARY} ]] && TABLE=(column -t -s',');
([[ -z ${ARG_SUMMARY} ]] && echo -e "HOST,DISK,STATUS,SIZE,SPEED,MODEL,FAILURE_STATE";
seq -f "${ARG_HOSTPATTERN}" ${ARG_FIRST} ${ARG_LAST} \
| xargs -P0 -I% bash -c "
sshpass -e ssh -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${USERNAME}@% racadm hwinventory | awk 'BEGIN { host=\"%\"; } $PARSER'
" | ${SUMMARY}
" | sort -t',' | "${SUMMARY[@]}") | "${TABLE[@]}"
}
### \b
......
import os
import click
from lib import LazyMultiCommand
@click.command(cls=LazyMultiCommand, tools_dir=os.path.dirname(__file__))
def yk():
"""YubiKey 2FA utilities."""
# YubiKey library functions.
assert_card_status() {
if ! gpg2 --card-status > /dev/null 2>&1; then
logError "Failed to retrieve card status, is it connected?"
exit 1
fi
}
This diff is collapsed.
#!/usr/bin/env bash
### \b
### SSH 2FA utilities for GnuPG-compatible smartcards.
### SSH 2FA utilities for OpenPGP-compatible smartcards.
### \b
### Author: Janek Bevendorff
### Year: 2020-today
. "${WEBIS_LIB_PATH}/bashhelper.sh"
. "${WEBIS_CMD_ROOT_PATH}/tools/yk/lib.sh"
check_tools ssh gpg2 /usr/lib/gnupg/scdaemon
assert_card_status() {
if ! gpg2 --card-status > /dev/null 2>&1; then
logError "Failed to retrieve card status, is it connected?"
exit 1
fi
}
### Check smartcard status and print stored information.
cmd_card_status() {
if ! gpg2 --card-status 2> /dev/null; then
logError "Failed to retrieve card status, is it connected?"
return 1
fi
}
### Print SSH-compatible public key of connected smartcard.
### : -u : --user : str :: Set username to add to comment section.
cmd_print_pubkey() {
assert_card_status
gpg2 --export-ssh-key "$(gpg --card-status | grep "sec#" | head -n1 | awk '{print $2}' | cut -d'/' -f2)"
if [ -z "$ARG_USER" ]; then
ARG_USER="$(id -un)"
fi
key="$(gpg --card-status | grep "^sec#\? " | head -n1 | awk '{print $2}' | cut -d'/' -f2)"
if [ -z "$key" ]; then
logError "No key found on card."
return 1
fi
gpg2 --export-ssh-key "$key" 2>&1 | sed "s/openpgp:\(0x[A-F0-9]\+\)\$/${ARG_USER}:\1/"
}
### Connect the SSH agent to the GPG agent socket.
......@@ -36,7 +32,7 @@ cmd_connect_agent() {
assert_card_status
if [ -t 1 ]; then
logInfo "Run this command as: \e[1meval \$($WEBIS_ARGV)\e[21m" >&2
logInfo "Run this command as: \e[1meval \$(${WEBIS_CMDLINE[*]})\e[0m" >&2
else
echo "SSH_AUTH_SOCK=\"$(gpgconf --list-dirs | grep agent-ssh-socket | cut -d":" -f2)\"; export SSH_AUTH_SOCK"
logInfo "You should now see your public key listed in \e[1mssh-add -l\e[21m."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment