From 3af2af5b674c2f87fef91c8910a348fe8b3647d0 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 14 Jun 2012 23:16:09 +0200 Subject: [PATCH] moved mbots in here and renamed a couple of scripts to more speaking names --- connection_test.sh => bandwidth_test.sh | 0 mbots/README.please | 24 ++++ mbots/archive/README.please | 41 +++++++ mbots/archive/df.conf.sample | 16 +++ mbots/archive/df.sh | 85 ++++++++++++++ mbots/archive/df_bot.conf.sample | 9 ++ mbots/archive/df_bot.sh | 120 +++++++++++++++++++ mbots/archive/hb.sh | 53 +++++++++ mbots/archive/heartbeat.lst.sample | 1 + mbots/archive/heartbeat.sh | 147 ++++++++++++++++++++++++ mbots/archive/mem.sh | 12 ++ mbots/archive/ping.conf.sample | 12 ++ mbots/archive/ping.sh | 98 ++++++++++++++++ mbots/diskmon.lst.sample | 15 +++ mbots/diskmon.sh | 121 +++++++++++++++++++ mbots/heartbeat.sh | 113 ++++++++++++++++++ mail.sh => mbots/mail.sh | 10 +- mbots/mbots.conf.sample | 15 +++ telnet_mail.sh | 8 +- connect.sh => wpa_connect.sh | 0 20 files changed, 890 insertions(+), 10 deletions(-) rename connection_test.sh => bandwidth_test.sh (100%) create mode 100644 mbots/README.please create mode 100644 mbots/archive/README.please create mode 100644 mbots/archive/df.conf.sample create mode 100755 mbots/archive/df.sh create mode 100644 mbots/archive/df_bot.conf.sample create mode 100755 mbots/archive/df_bot.sh create mode 100755 mbots/archive/hb.sh create mode 100644 mbots/archive/heartbeat.lst.sample create mode 100755 mbots/archive/heartbeat.sh create mode 100755 mbots/archive/mem.sh create mode 100644 mbots/archive/ping.conf.sample create mode 100755 mbots/archive/ping.sh create mode 100644 mbots/diskmon.lst.sample create mode 100755 mbots/diskmon.sh create mode 100755 mbots/heartbeat.sh rename mail.sh => mbots/mail.sh (83%) create mode 100644 mbots/mbots.conf.sample rename connect.sh => wpa_connect.sh (100%) diff --git a/connection_test.sh b/bandwidth_test.sh similarity index 100% rename from connection_test.sh rename to bandwidth_test.sh diff --git a/mbots/README.please b/mbots/README.please new file mode 100644 index 0000000..85a43b8 --- /dev/null +++ b/mbots/README.please @@ -0,0 +1,24 @@ +**** README **** + +mbots are little bash scripts to monitor the +health of your most important linux boxes. + +author: david@socialnerds.org +version: 0.1 +giturl: git://git.socialnerds.org/mobots.git + + +--> installation + +1. clone mbots repository +cd /opt +git clone git://git.socialnerds.org:mbots.git + +2. run environment fix +./mbots.sh -f + +3. configure your mbots + +4. create cron job + + diff --git a/mbots/archive/README.please b/mbots/archive/README.please new file mode 100644 index 0000000..fd3d3a9 --- /dev/null +++ b/mbots/archive/README.please @@ -0,0 +1,41 @@ +this is my little mobot project. + +the concept is not to spend hundreds of hours to implement some massive +monitoring tool like nagios or something like this. +instead i want to use some simple message/notification scripts +which exactly tell me what i need to know. + +the first thing i have here is the df bot. it sends me a short jabber message +when one or more disks on the serving machine reaching a preconfigured threshold +(example: 90% disk usage). + +another tool i find really useful is the pingbot (ping.sh) +it works pretty much the same as the dfbot. + +feel free to use or improve this handy tools! + + +=== install notes === + +1. copy the scrip somewhere on your machine +you get the df.sh on gitorious.org +http://gitorious.org/sn/scripts/trees/master/mobots/df.sh + +2. create the configfile +use the df.conf.sample to create a config and put this file anywhere on the same machine +http://gitorious.org/sn/scripts/trees/master/mobots/df.conf.sample + +3. create a cronjob for it +add a line like this to your /etc/crontab +*/2 * * * * root /bin/bash --login /path/to/the/script/df.sh /path/to/configfile/df.conf >> /path/to/logfile/df.log +or (if you use the default configpath /etc/mobots) +*/5 * * * * root /bin/bash --login /path/to/script/df.sh >> /var/log/mobots/df.log + +the logdirectory must exist + +after this you have to restart your cron with something like +service cron restart + +of course there are several ways to create a cronjob but this is probably the easiest way + +any questions? mail me! (david@socialnerds.org) diff --git a/mbots/archive/df.conf.sample b/mbots/archive/df.conf.sample new file mode 100644 index 0000000..c9345d5 --- /dev/null +++ b/mbots/archive/df.conf.sample @@ -0,0 +1,16 @@ +## df monitoring jabber bot configfile + +## here i suggest you put the name of the machine you running this script on +hostname="somemachine.example.com" + +## jabber config +watchdogs="max@muster.com moriz@jabber.anotherdomain.com" +user="jabber-username" +pass="jabber-password" +server="jabber-server" +#port="5222" # uncomment if you want to use a specific port + +## define disks you wanna check? (whitespace seperated) +disks="hda1 hda2 hdd1" +## here the disks thresholds +thresholds="80 90 95" diff --git a/mbots/archive/df.sh b/mbots/archive/df.sh new file mode 100755 index 0000000..0453e73 --- /dev/null +++ b/mbots/archive/df.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +################################################### +## ## +## disk_free jabber monitoring bot ## +## Author: david@socialnerds.org ## +## v0.2 ## +## ## +################################################### + +## timestamp for logfile +timestamp=$(date '+%d %B %Y %H:%M') +echo "info: starting df bot $timestamp" + +## check if sendxmpp is installed +if [ $(aptitude search sendxmpp | awk '{print $1}') = "i" ]; then + echo "info: sendxmpp found" +else + if [ $(whoami) = "root" ]; then + apt-get install sendxmpp + else + echo "error: permission denied" + echo "info: install sendxmpp or run this scrip as superuser" + exit 1 + fi +fi + + +## set and load configfile +if [ -z $1 ]; then + configfile="/etc/mobots/df.conf" + if [ -f $configfile ]; then + source $configfile + else + echo "error: no config file $configfile" + exit 1 + fi +else + configfile=$1 + if [ -f $configfile ]; then + source $configfile + else + echo "error: no config file $configfile" + exit 1 + fi +fi + + +## check sendxmpp config +if [ -f ~/.sendxmpprc ]; then + echo "info: jabber config found in ~/.sendxmpprc" +else + + if [ -z $port ]; then + port="5222" + else + echo "info: using port $port" + fi + + echo "$user@$server:$port $pass" > ~/.sendxmpprc + chmod 600 ~/.sendxmpprc + echo "info: created sendxmpp config in ~/.sendxmpprc" +fi + + +## check disks +set -- $disks +i="1" + +for var in "$@" +do + data=$(df -Ph | grep $var | sed -e 's/%//g' | awk '{print $5}') + datathreshold=$(echo $thresholds | awk '{print $'$i'}') + + if [ $data -gt $datathreshold ]; then + echo "info: $var reached threshold with $data%, sending notification to $watchdogs" + echo "$hostname: $var is running out of space: $data%" | sendxmpp -r dfbot $watchdogs + fi + let i++ +done + + +## exiting +echo "info: done" +exit 0 diff --git a/mbots/archive/df_bot.conf.sample b/mbots/archive/df_bot.conf.sample new file mode 100644 index 0000000..4b5d96e --- /dev/null +++ b/mbots/archive/df_bot.conf.sample @@ -0,0 +1,9 @@ +# **** df_bot configfile **** + +# here i suggest you put the name of the machine you running this script on +hostname="somemachine.example.com" + +## define disks you wanna check? (whitespace seperated) +disks="hda1 hda2 hdd1" +## here the disks thresholds +thresholds="80 90 95" diff --git a/mbots/archive/df_bot.sh b/mbots/archive/df_bot.sh new file mode 100755 index 0000000..5fc3ec2 --- /dev/null +++ b/mbots/archive/df_bot.sh @@ -0,0 +1,120 @@ +#!/bin/bash + + +################################################### +## ## +## disk_free monitoring bot ## +## ## +################################################### + + +# **** in script config section **** +version="0.3_alpha" +author="david@socialnerds.org" +logwhat="df_bot" + +# **** configfile section **** +disks="sda1" +thresholds="90" +bashlibpath="/home/david/Documents/code/bashlib" +# logging +loglevel="4" +log2syslog="1" +log2file="0" +#logfile="/var/log/mbots.log" +log2stdout="1" + + +# **** bash trap initialisation **** +trap bashtrap INT + +# **** load bashlib **** +if [ -d $bashlibpath ]; then + source $bashlibpath/main + #source $bashlibpath/update + source $bashlibpath/logengine + log debug "preflight - bashlib loaded" +else + echo "ERROR: bashlib not found" + exit 1 +fi + +exit 0 +## timestamp for logfile +#timestamp=$(date '+%d %B %Y %H:%M') +#echo "info: starting df bot $timestamp" + +## check if sendxmpp is installed +#if [ $(aptitude search sendxmpp | awk '{print $1}') = "i" ]; then +# echo "info: sendxmpp found" +#else +# if [ $(whoami) = "root" ]; then +# apt-get install sendxmpp +# else +# echo "error: permission denied" +# echo "info: install sendxmpp or run this scrip as superuser" +# exit 1 +# fi +#fi + + +## set and load configfile +#if [ -z $1 ]; then +# configfile="/etc/mobots/df.conf" +# if [ -f $configfile ]; then +# source $configfile +# else +# echo "error: no config file $configfile" +# exit 1 +# fi +#else +# configfile=$1 +# if [ -f $configfile ]; then +# source $configfile +# else +# echo "error: no config file $configfile" +# exit 1 +# fi +#fi + + +## check sendxmpp config +#if [ -f ~/.sendxmpprc ]; then +# echo "info: jabber config found in ~/.sendxmpprc" +#else +# +# if [ -z $port ]; then +# port="5222" +# else +# echo "info: using port $port" +# fi +# +# echo "$user@$server:$port $pass" > ~/.sendxmpprc +# chmod 600 ~/.sendxmpprc +# echo "info: created sendxmpp config in ~/.sendxmpprc" +#fi + + +## check disks +set -- $disks +i="1" + +for var in "$@" +do + data=$(df -Ph | grep $var | sed -e 's/%//g' | awk '{print $5}') + datathreshold=$(echo $thresholds | awk '{print $'$i'}') + + if [ $data -gt $datathreshold ]; then + echo "info: $var reached threshold with $data%, sending notification to $watchdogs" + echo "$hostname: $var is running out of space: $data%" | sendxmpp -r dfbot $watchdogs + fi + let i++ +done + + +## exiting +#echo "info: done" + + +exit 0 +# **** end of script **** diff --git a/mbots/archive/hb.sh b/mbots/archive/hb.sh new file mode 100755 index 0000000..c0f0918 --- /dev/null +++ b/mbots/archive/hb.sh @@ -0,0 +1,53 @@ +#!/bin/bash + + #\ + # \ + # \_ _ _ _ _ _ _ _ _ _ _ _ _ + # #\ + # # \ + # heartbeat monitoring # \ + # script # / + # # / + # _ _ _ _ _ _ _ _ _ _ _ _ _#/ + # / + # / + #/ + +# **** config section **** +author="david@socialnerds.org" +version="0.2" +giturl="git://git.aec.at/mbots.git" +hostsfile="/etc/hosts" +log2stdout="1" +log2file="0" +#logfile=/var/log/mbots.log +log2syslog="1" +logwhat="mbots_hb" + + +# **** preflight **** + +#searching for bashlib +if [ -z $BASHLIB ]; then + echo "ERROR: bashlib environment variable not set. terminating." + exit 1 +else + $bashlibpath=$BASHLIB +fi + +#load bashlib +if [ -d $bashlibpath ]; then + source $bashlibpath/main + source $bashlibpath/logengine + log debug "preflight - logengine loaded." +else + echo "ERROR: bashlib not found. terminating." + exit 1 +fi + + + + + + +# **** end of script **** diff --git a/mbots/archive/heartbeat.lst.sample b/mbots/archive/heartbeat.lst.sample new file mode 100644 index 0000000..5fa4880 --- /dev/null +++ b/mbots/archive/heartbeat.lst.sample @@ -0,0 +1 @@ +# list of hostnames to monitor diff --git a/mbots/archive/heartbeat.sh b/mbots/archive/heartbeat.sh new file mode 100755 index 0000000..e1b3e9b --- /dev/null +++ b/mbots/archive/heartbeat.sh @@ -0,0 +1,147 @@ +#!/bin/bash + + #\ + # \ + # \_ _ _ _ _ _ _ _ _ _ _ _ _ + # #\ + # # \ + # heartbeat monitoring # \ + # script # / + # # / + # _ _ _ _ _ _ _ _ _ _ _ _ _#/ + # / + # / + #/ + +# **** config section **** +#do not touch as long as you're not me +author="david@socialnerds.org" +version="0.1" +giturl="git://git.aec.at/mbots.git" +configfile="/etc/mbots/mbots.conf" +log2stdout="1" +logwhat="mbots_heartbeat" +file="/etc/mbots/heartbeat.lst" + + +# **** preflight **** +#read configfile +if [ -r $configfile ]; then + source $configfile +else + echo "ERROR: configfile not found. terminating." + exit 1 +fi + +#load bashlib +if [ -d $bashlibpath ]; then + source $bashlibpath/main + source $bashlibpath/logengine + log debug "preflight - logengine loaded" +else + echo "ERROR: bashlib not found. terminating." + exit 1 +fi + +#check environment + + +log info "**** starting heartbeat bot ****" + +#set linecount to 1 +linecount="1" + +#read one line at a time +while read line; do + #find first letter to determine if line is empty or a comment + fletter=${line:0:1} + + #check for first letter + if [ -z $fletter ]; then + #skip line it's empty + log debug "config - skipping line $linecount in $file: it's empty" + elif [ $fletter = "#" ]; then + #skip line it's a comment + log debug "config - skipping line $linecount in $file: it's a comment" + else + # getting hostname from heartbeat.lst + hostname=$(echo $line | awk '{print $1}') + + log debug "checking $hostname" + + #check ipv6 + ipv6=$(dig $hostname AAAA +short | grep ":") + if [ -z "$ipv6" ]; then + log warning "no ipv6 record for $hostname" + log debug "checking /etc/hosts" + hosts=$(cat /etc/hosts | grep -iw $hostname | awk '{print $1}' | grep ":") + if [ -z $hosts ]; then + log warning "no ipv6 hosts entry found" + else + for var in $hosts; do + log info "pinging $hostname($var)" + ping6 -c 1 $var &> /dev/null + err=$? + if [ $err = "0" ]; then + log info "$hostname($var) is reachable" + else + log error "$hostname($var) is not reachable" + fi + done + fi + else + for var in $ipv6; do + log info "pinging $hostname($var)" + ping6 -c 1 $var &> /dev/null + err=$? + if [ $err = "0" ]; then + log info "$hostname($var) is reachable" + else + log error "$hostname($var) is not reachable" + fi + done + fi + + #check ipv4 + ipv4=$(dig $hostname A +noall +answer | grep -v ";" | grep -v "CNAME" | awk '{print $5}' | grep -v "^$") + if [ -z "$ipv4" ]; then + log warning "no ipv4 record for $hostname" + log debug "checking /etc/hosts" + hosts=$(cat /etc/hosts | grep -iw $hostname | awk '{print $1}' | grep ".") + if [ -z $hosts ]; then + log warning "no ipv4 hosts entry found" + else + for var in $hosts; do + log info "pinging $hostname($var)" + ping -c 1 $var &> /dev/null + err=$? + if [ $err = "0" ]; then + log info "$hostname($var) is reachable" + else + log error "$hostname($var) is not reachable" + fi + done + fi + else + for var in $ipv4; do + log info "pinging $hostname($var)" + ping -c 1 $var &> /dev/null + err=$? + if [ $err = "0" ]; then + log info "$hostname($var) is reachable" + else + log error "$hostname($var) is not reachable" + fi + done + fi + + fi + + let linecount++ + +done < $file + +log debug "**** all checks done ****" + + +# **** end of script **** diff --git a/mbots/archive/mem.sh b/mbots/archive/mem.sh new file mode 100755 index 0000000..b397ab2 --- /dev/null +++ b/mbots/archive/mem.sh @@ -0,0 +1,12 @@ +#!/bin/bash + + +# used mem +umem=$(free -m | grep buffers/cache | awk '{print $3}') +tmem=$(free -m | grep Mem: | awk '{print $2}') + +percent=$((100*$(free -m | grep buffers/cache | awk '{print $3}')/$(free -m | grep Mem: | awk '{print $2}'))) + +echo "Used memory: $percent% ($umem"MB"/$tmem"MB")" + + diff --git a/mbots/archive/ping.conf.sample b/mbots/archive/ping.conf.sample new file mode 100644 index 0000000..2cd3f9b --- /dev/null +++ b/mbots/archive/ping.conf.sample @@ -0,0 +1,12 @@ +# a whitespace seperated list of ip addresses or fqdnames +dest="192.168.1.13 somemachine.example.com" + +# jabber configuration +user="jid" +server="jabber-server" +#port="" ## if you want to use a special port (default: 5222) +pass="jabber-password" +res="pingbot" +watchdogs="someuser@jabber.example.com anotheruser@example.com" ## whitespace seperated list of JIDs + + diff --git a/mbots/archive/ping.sh b/mbots/archive/ping.sh new file mode 100755 index 0000000..d4ccc52 --- /dev/null +++ b/mbots/archive/ping.sh @@ -0,0 +1,98 @@ +#!/bin/bash + +## ## ## ## ## ## ## ## ## +## ## +## jabber ping bot ## +## ## +## v0.1 ## +## ## +## author: david@socialnerds.org ## +## ## +## ## ## ## ## ## ## ## ## + + +## timestamp for logfile +timestamp=$(date '+%d %B %Y %H:%M') +echo "info: starting jabber ping bot $timestamp" + + +## check if sendxmpp is installed +if [ $(aptitude search sendxmpp | awk '{print $1}') = "i" ]; then + echo "info: sendxmpp found" +else + if [ $(whoami) = "root" ]; then + apt-get install sendxmpp + else + echo "error: permission denied" + echo "info: install sendxmpp or run this scrip as superuser" + exit 1 + fi +fi + + +## set and load configfile +if [ -z $1 ]; then + configfile="/etc/mobots/ping.conf" + if [ -f $configfile ]; then + source $configfile + else + echo "error: no config file $configfile" + exit 1 + fi +else + configfile=$1 + if [ -f $configfile ]; then + source $configfile + else + echo "error: no config file $configfile" + exit 1 + fi +fi + + +## check sendxmpp config +if [ -f ~/.sendxmpprc ]; then + echo "info: jabber config found in ~/.sendxmpprc" +else + + if [ -z $port ]; then + port="5222" + else + echo "info: using port $port" + fi + + echo "$user@$server:$port $pass" > ~/.sendxmpprc + chmod 600 ~/.sendxmpprc + echo "info: created sendxmpp config in ~/.sendxmpprc" +fi + +## run the actual ping +set -- $dest + +for var in "$@" +do + #result=$(ping -c 05 $var | grep transmitted | awk '{print $4}') + ping -c 03 $var >/dev/null 2>&1 + errorcode=$? + if [ $errorcode = "0" ]; then + echo "info: $var is responding" + else + if [ $errorcode = "1" ]; then + echo "alert: $var is not responding" + ## sending jabber message + echo "alert: $var is not responding + ping errorcode: $errorcode" | sendxmpp -r $res $watchdogs + else + if [ $errorcode = "2" ]; then + echo "alert: $var cannot be resolved" + ## sending jabber message + echo "alert: $var cannot be resolved + ping errorcode: $errorcode" | sendxmpp -r $res $watchdogs + fi + fi + fi +done + +## the end +exit 0 + diff --git a/mbots/diskmon.lst.sample b/mbots/diskmon.lst.sample new file mode 100644 index 0000000..23d113d --- /dev/null +++ b/mbots/diskmon.lst.sample @@ -0,0 +1,15 @@ +# **** list of uuids to monitor **** +#put this file in /etc/mbots and rename it to +#"diskmon.lst" or use a custom file as first +#option. + +#ex. +#76c2a7e3-8765-4bb2-9093-ce495edb3833 90 98 +#or +#UUID="76c2a7e3-8765-4bb2-9093-ce495edb3833" 90 98 +#or +#/dev/sdb1 90 95 + + +# + diff --git a/mbots/diskmon.sh b/mbots/diskmon.sh new file mode 100755 index 0000000..0325f81 --- /dev/null +++ b/mbots/diskmon.sh @@ -0,0 +1,121 @@ +#!/bin/bash + + #\ + # \_ _ _ _ _ _ _ _ _ _ _ _ _ + # #\ + # # \ + # disk usage monitoring # \ + # script # / + # # / + # _ _ _ _ _ _ _ _ _ _ _ _ _#/ + # / + #/ + +# **** config section **** +#do not touch as long as you're not me +author="david@socialnerds.org" +version="0.1" +giturl="git://git.aec.at/mbots.git" +configfile="/etc/mbots/mbots.conf" +log2stdout="1" +logwhat="mbots_diskmon" +file="/etc/mbots/diskmon.lst" + + +# **** preflight **** +#read configfile +if [ -r $configfile ]; then + source $configfile +else + echo "ERROR: configfile not found. terminating." + exit 1 +fi + +#load bashlib +if [ -d $bashlibpath ]; then + source $bashlibpath/main + source $bashlibpath/logengine + log debug "preflight - logengine loaded" +else + echo "ERROR: bashlib not found. terminating." + exit 1 +fi + + +#check environment + +log info "**** starting disk monitoring bot ****" + +#first option triggers custom list +if [ -z $1 ]; then + log debug "preflight - no custom list given. using $file[default]" +else + file=$1 + log debug "preflight - list option given. using $file" +fi + + +# read file +linecount="1" +while read line; do + #find first letter to determine if line is empty or a comment + fletter=${line:0:1} + + #check for first letter + if [ -z $fletter ]; then + #skip line it's empty + log debug "skipping line $linecount in $file: it's empty" + elif [ $fletter = "#" ]; then + #skip line it's a comment + log debug "skipping line $linecount in $file: it's a comment" + else + #read line + log debug "reading line $linecount in $file" + + #getting values + disk=$(echo $line | awk '{print $1}') + th1=$(echo $line | awk '{print $2}') + + #if threshold2 not given set th2 eq th1 + th2=$(echo $line | awk '{print $3}') + if [ -z $th2 ]; then + th2=$th1 + fi + + devstring=$(blkid | grep $disk | awk '{print $1}') + uuidstring=$(blkid | grep $disk | awk '{print $2}') + + devname=$(echo ${devstring::$((${#devstring}-1))}) + uuid=$(echo ${uuidstring:6:$((${#uuidstring}-7))}) + + #getting diskusage + diskusage=$(df -hP --sync | grep $devname | awk '{print $5}') + diskusage=$(echo ${diskusage::$((${#diskusage}-1))}) + + if [ $diskusage -gt $th2 ]; then + #error, reached threshold2 + log error "$devname uses $diskusage% of disk space (warn: $th1%, err: $th2%)" + elif [ $diskusage -gt $th1 ]; then + #warning, reached threshold1 + log warning "$devname uses $diskusage% of disk space (warn: $th1%, err: $th2%)" + else + #info, everything ok + log info "$devname is at $diskusage% (warn: $th1%, err: $th2%)" + fi + + fi + + #linecount +1 + let linecount++ + +#source file to read (diskmon.lst) +done < $file + + +#battlestar galactica fun section :-) +log debug "adama: what do you hear starbuck?" +log debug "kara: nothin' but the rain sir!" + + +log info "**** disk monitoring bot finished ****" +# **** end of script **** diff --git a/mbots/heartbeat.sh b/mbots/heartbeat.sh new file mode 100755 index 0000000..7499434 --- /dev/null +++ b/mbots/heartbeat.sh @@ -0,0 +1,113 @@ +#!/bin/bash + +# +# heartbeat survaillance +# script +# + +# **** config section **** + +author="david@socialnerds.org" +version="0.1" +sourcefile="/etc/hosts" +excludes="127.0.0.1 127.0.1.1 ::1 fe00::0 ff00::0 ff02::1 ff02::2 ff02::3" +options="-n -c 5 -i 0.2 -W 1" +maxloss="20%" +log2stdout="1" +logwhat="mbots_heartbeat" +configfile="/etc/mbots/mbots.conf" +giturl="git://git.aec.at/mbots.git" + + +# **** preflight **** + +#read configfile +if [ -r $configfile ]; then + source $configfile +else + echo "ERROR: configfile not found. terminating." + exit 1 +fi + +#load bashlib +if [ -d $bashlibpath ]; then + source $bashlibpath/main + source $bashlibpath/logengine + log debug "preflight - logengine loaded" +else + echo "ERROR: bashlib not found. terminating." + exit 1 +fi + + +# **** function definition **** + +check() +{ + + local ip=$1 + + echo $ip | grep ":" &> /dev/null + local isv4=$? + if [ $isv4 = "1" ]; then + # run ipv4 ping + local value=$(ping $options $ip | grep -o -e "[0-9]*%") + elif [ $isv4 = "0" ]; then + # run ipv6 ping + local value=$(ping6 $options $ip | grep -o -e "[0-9]*%") + fi + + if [ ${value:0:$((${#value}-1))} -gt ${maxloss:0:$((${#maxloss}-1))} ]; then + log error "not able to reach $(echo $line | awk '{print $2}') at $ip" + fi + +} + + +# **** start of script **** + +# set linecount to 1 +linecount="1" + +# read line by line of $sourcefile +while read line; do + + #get first letter of line + fletter=${line:0:1} + if [ -z $fletter ]; then + #skip line, it's empty + : + elif [ $fletter = "#" ]; then + #skip line, it's a comment + : + else + #exclusion of $excludes + excluded="0" + for var in $excludes; do + #check if ip is excluded + if [ $(echo $line | awk '{print $1}') = $var ]; then + excluded="1" + break + fi + done + + #run check function for ip if not excluded + if [ $excluded = "1" ]; then + continue + else + #run actual ping + check "$(echo $line | awk '{print $1}')" + fi + + fi + + #count lines + let linecount++ + +done < $sourcefile + + +exit 0 +# **** end of script **** + + diff --git a/mail.sh b/mbots/mail.sh similarity index 83% rename from mail.sh rename to mbots/mail.sh index 27203b8..621e8ce 100755 --- a/mail.sh +++ b/mbots/mail.sh @@ -10,17 +10,13 @@ #don't touch as long as you're not me. feel me? version=".01" author="david@socialnerds.org" - -#script config +html="1" #html mail smtpserver="smtp.aec.at" -recipients="david@aec.at gerald.hochhauser@aec.at michael.grausgruber@aec.at daniel.weihrauch@aec.at" +recipients="test@socialnerds.org david@aec.at" from="mbots@aec.at" -subject="free memory on prix.aec.at" +subject="notification" line=$1 -#if [ -f $line ]; then -# line=$(cat $line) -#fi # ***** start of script ***** diff --git a/mbots/mbots.conf.sample b/mbots/mbots.conf.sample new file mode 100644 index 0000000..d0e9260 --- /dev/null +++ b/mbots/mbots.conf.sample @@ -0,0 +1,15 @@ +# central mbots configuration file + +#this file must be in /etc/mbots + + +#bashlib location +bashlibpath="/opt/bashlib" + +#logging +loglevel="4" +log2file="0" +logfile=/var/log/mbots.log +log2syslog="1" + + diff --git a/telnet_mail.sh b/telnet_mail.sh index c070052..a1d26cd 100755 --- a/telnet_mail.sh +++ b/telnet_mail.sh @@ -1,18 +1,20 @@ #!/bin/bash + ############################### # # # mbots mail routine # # # ############################### + # ***** config section ***** #don't touch as long as you're not me. feel me? -version=".01" +version=".1" author="david@socialnerds.org" smtpserver="smtp.aec.at" -recipients="david@aec.at danielwe@aec.at geraldho@aec.at michaelgr@aec.at" +recipients="person@domain.tld person2@domain.tld" from="releasechecker@aec.at" subject="ubuntu precise pangolin is out. download it. seed it." line=$1 @@ -21,8 +23,8 @@ line=$1 # line=$(cat $line) #fi -# ***** start of script ***** +# ***** start of script ***** #telnet connection { sleep 1 diff --git a/connect.sh b/wpa_connect.sh similarity index 100% rename from connect.sh rename to wpa_connect.sh