moved mbots in here and renamed a couple of scripts to more speaking names
This commit is contained in:
parent
1c60fbfaa2
commit
3af2af5b67
|
@ -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
|
||||
|
||||
|
|
@ -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)
|
|
@ -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"
|
|
@ -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
|
|
@ -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"
|
|
@ -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 ****
|
|
@ -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 ****
|
|
@ -0,0 +1 @@
|
|||
# list of hostnames to monitor
|
|
@ -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 ****
|
|
@ -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")"
|
||||
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
||||
#<disk> <threshold1> <threshold2>
|
||||
|
|
@ -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 ****
|
|
@ -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 ****
|
||||
|
||||
|
|
@ -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 *****
|
||||
|
|
@ -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"
|
||||
|
||||
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue