From 4c36f9a8b7bef05aa39ab1ca45d619bdf924955d Mon Sep 17 00:00:00 2001 From: Brian Flowers Date: Thu, 15 Sep 2016 12:16:47 -0400 Subject: [PATCH] Bugfixes and tuning in vmstat plugin and bdsm configure/deploy/start --- bdsm.d/vmstat.generic | 6 +++--- bdsm.sh | 47 ++++++++++++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/bdsm.d/vmstat.generic b/bdsm.d/vmstat.generic index e34a079..ad1ac0b 100755 --- a/bdsm.d/vmstat.generic +++ b/bdsm.d/vmstat.generic @@ -69,14 +69,14 @@ start() fi # Check what options awk supports - if [ ! -z `ssh $HOSTNAME "echo | awk -W interactive '{print 1}' 2>&1 >/dev/null"` ]; then + if [ "`ssh $HOSTNAME \"echo | awk -W interactive '{print 1}' 2>&1 1>/dev/null\"`" != "" ]; then awkopt="" else awkopt="-W interactive" fi ssh -q $HOSTNAME <> $OUTPATH & + }' >> $OUTPATH 2>/home/bdsm/err.log & EOF ssh -q $HOSTNAME "ps aux | \ grep bdsm | \ diff --git a/bdsm.sh b/bdsm.sh index c2b4622..86f2f0d 100755 --- a/bdsm.sh +++ b/bdsm.sh @@ -5,7 +5,7 @@ # Bash Daemon for System Monitoring # # TODO: -# 1) Fully shakeout configure +# 1) Finish configure options # 2) Finish Deploy # ) Plugins: # 3) iostat @@ -155,6 +155,11 @@ help() start() { + # Start the processor + #TODO: Plugin system? + cat /home/bdsm/in.fifo > /home/bdsm/bdsm.log & + echo $! > /home/bdsm/.processor.pid + i=0 while [ $i -lt ${#hosts[@]} ]; do type=`echo ${hosts[$i]} | cut -d':' -f1` @@ -162,6 +167,10 @@ start() info "Starting $type monitors on $host..." functions=`cat /home/bdsm/.bdsm.conf.tmp | grep "$type:$host" | sed 's/.*{\(.*\)}.*/\1/'` + ssh $host "cat /home/bdsm/out.fifo" > /home/bdsm/in.fifo & + echo $! > /home/bdsm/pids/$host.in + + j=0 echo $functions | tr ';' '\n' | sed 's/[(),]/ /g' | while read line; do command=`echo $line | cut -d' ' -f1` @@ -174,10 +183,7 @@ start() error "Could not find plugin for $command on $type:$host!" fi done - - ssh $host "cat /home/bdsm/out.fifo" > /home/bdsm/in.fifo & - echo $! > /home/bdsm/pids/$host.in - + i=`expr $i + 1` done } @@ -293,7 +299,7 @@ configure() read host if [ `confirm "Confirm creation of $type:$host?"` -eq 0 ]; then - echo "$host{}" >> /home/bdsm/.bdsm.conf.tmp + echo "$type:$host{}" >> /home/bdsm/.bdsm.conf.tmp else host="" fi @@ -314,9 +320,6 @@ configure() header "Configuring $service" if [ `confirm "Disable $service?"` -eq 0 ]; then - # TODO - # This may need fixed - # TODO cat /home/bdsm/.bdsm.conf.tmp | \ sed 's/\(.*:$host{.*\)$service;\(.*\)/\1\2/g' \ > /home/bdsm/.bdsm.conf.tmp2 @@ -346,7 +349,8 @@ configure() done newservice=`echo $newservice | sed 's/,$/)/g'` fi - + +set -x # TODO # Validate removal/replacement of old service # TODO @@ -359,6 +363,7 @@ configure() mv /home/bdsm/.bdsm.conf.tmp2 /home/bdsm/.bdsm.conf.tmp # Reload the hosts list hosts=$(cat /home/bdsm/.bdsm.conf.tmp | cut -d'{' -f1) +set +x done # Convert config back to a more readable format @@ -382,18 +387,22 @@ deploy() host=`echo ${hosts[$i]} | cut -d':' -f2-` info "Deploying on $host..." - ssh -q bdsm@$host + ssh -q -o PreferredAuthentications=publickey bdsm@$host "echo > /dev/null" ret=$? - if [ ! $ret ]; then - info "Passwordless SSH not configured. Creating bdsm user as root..." - ssh root@$host "useradd --home-dir /home/bdsm bdsm" + if [ $ret -ne 0 ]; then + info "Passwordless SSH not configured. Login as root to configure:" + cat /home/bdsm/.ssh/id_rsa.pub | ssh -q root@$host "cat >> /tmp/bdsmid; useradd --home-dir /home/bdsm bdsm; mkdir -p /home/bdsm/.ssh/; cat /tmp/bdsmid >> /home/bdsm/.ssh/authorized_keys" - info "Logging in as bdsm user to transfer SSH key..." - cat /home/bdsm/.ssh/id_rsa.pub | ssh bdsm@$host 'cat >> ~/.ssh/authorized_keys' + #info "Logging in as bdsm user to transfer SSH key..." + #cat /home/bdsm/.ssh/id_rsa.pub | ssh bdsm@$host 'cat >> ~/.ssh/authorized_keys' fi - ssh bdsm@$host "mkfifo /home/bdsm/out.fifo" + ssh -q bdsm@$host "mkfifo /home/bdsm/out.fifo" + i=`expr $i + 1` done + + mkfifo /home/bdsm/in.fifo + mkdir /home/bdsm/pids } # SCRIPT START @@ -406,7 +415,7 @@ cat /home/bdsm/bdsm.conf | tr '\n' ' ' | sed "s/[[:space:]]//g" | sed 's/}/}\ > /home/bdsm/.bdsm.conf.tmp # Get a list of configured hosts -hosts=$(cat /home/bdsm/.bdsm.conf.tmp | cut -d'{' -f1) +hosts=($(cat /home/bdsm/.bdsm.conf.tmp | cut -d'{' -f1)) if [ -z $1 ]; then help @@ -422,4 +431,4 @@ elif [ $1 == "deploy" ]; then deploy else help -fi \ No newline at end of file +fi -- 1.8.3.1