Commit b7ffbc29 authored by Curt Dennis's avatar Curt Dennis
Browse files

Added initial public scripts

parents
#!/bin/bash
#This script gets the current power information
#from the main UPS
#The time we are going to sleep between readings
sleeptime=30
#Prepare to start the loop and warn the user
echo "Press [CTRL+C] to stop..."
while :
do
#Get the current dump of the stats
upsstats=`pwrstat -status`
#Lets try to find the lines we are looking for
while read -r line; do
#Check if we have the line we are looking for
if [[ $line == *"State."* ]]
then
state=$line
fi
if [[ $line == *"Power Supply by"* ]]
then
supply=$line
fi
if [[ $line == *"Utility Voltage"* ]]
then
involts=$line
fi
if [[ $line == *"Output Voltage"* ]]
then
outvolts=$line
fi
if [[ $line == *"Battery Capacity"* ]]
then
capacity=$line
fi
if [[ $line == *"Remaining Runtime"* ]]
then
runtime=$line
fi
if [[ $line == *"Load."* ]]
then
load=$line
fi
if [[ $line == *"Line Interaction"* ]]
then
interaction=$line
fi
done <<< "$upsstats"
#Remove the long string of .s
state=$(echo $state | tr -s '[.]')
supply=$(echo $supply | tr -s '[.]')
involts=$(echo $involts | tr -s '[.]')
outvolts=$(echo $outvolts | tr -s '[.]')
capacity=$(echo $capacity | tr -s '[.]')
runtime=$(echo $runtime | tr -s '[.]')
load=$(echo $load | tr -s '[.]')
interaction=$(echo $interaction | tr -s '[.]')
#Lets parse out thevalues from the strings
#First split on the .
IFS='.' read -ra statearr <<< "$state"
state=${statearr[1]}
IFS='.' read -ra supplyarr <<< "$supply"
supply=${supplyarr[1]}
IFS='.' read -ra involtsarr <<< "$involts"
involts=${involtsarr[1]}
IFS='.' read -ra outvoltsarr <<< "$outvolts"
outvolts=${outvoltsarr[1]}
IFS='.' read -ra capacityarr <<< "$capacity"
capacity=${capacityarr[1]}
IFS='.' read -ra runtimearr <<< "$runtime"
runtime=${runtimearr[1]}
IFS='.' read -ra loadarr <<< "$load"
load=${loadarr[1]}
IFS='.' read -ra interactionarr <<< "$interaction"
interaction=${interactionarr[1]}
#We need an extra split for the load
IFS='(' read -ra loadarr <<< "$load"
loadwatt=${loadarr[0]}
loadpercent=${loadarr[1]}
#Remove unneeded spaces
state=$(echo $state | xargs)
supply=$(echo $supply | xargs)
involts=$(echo $involts | xargs)
outvolts=$(echo $outvolts | xargs)
capacity=$(echo $capacity | xargs)
runtime=$(echo $runtime | xargs)
loadwatt=$(echo $loadwatt | xargs)
loadpercent=$(echo $loadpercent | xargs)
interaction=$(echo $interaction | xargs)
#Now we just strip off some of the unneeded
#info from the end of the strings
involts=$(echo $involts | grep -o '[0-9]*')
outvolts=$(echo $involts | grep -o '[0-9]*')
runtime=$(echo $runtime | grep -o '[0-9]*')
capacity=$(echo $capacity | grep -o '[0-9]*')
loadwatt=$(echo $loadwatt | grep -o '[0-9]*')
loadpercent=$(echo $loadpercent | grep -o '[0-9]*')
echo "state: $state"
echo "supply: $supply"
echo "involts: $involts"
echo "outvolts: $outvolts"
echo "runtime: $runtime"
echo "capacity: $capacity"
echo "loadwatt: $loadwatt"
echo "loadpercent: $loadpercent"
echo "interaction: $interaction"
#Finally we can write it to the database
curl -i -XPOST 'http://10.0.0.11:8086/write?db=home' --data-binary "ups_data,host=host1,sensor=battcharge value=$capacity"
curl -i -XPOST 'http://10.0.0.11:8086/write?db=home' --data-binary "ups_data,host=host1,sensor=battload value=$loadpercent"
curl -i -XPOST 'http://10.0.0.11:8086/write?db=home' --data-binary "ups_data,host=host1,sensor=battloadwatt value=$loadwatt"
curl -i -XPOST 'http://10.0.0.11:8086/write?db=home' --data-binary "ups_data,host=host1,sensor=inputvoltage value=$involts"
curl -i -XPOST 'http://10.0.0.11:8086/write?db=home' --data-binary "ups_data,host=host1,sensor=runtime value=$runtime"
#Wait for a bit before checking again
sleep "$sleeptime"
done
\ No newline at end of file
#!/bin/bash
# chkconfig: 2345 90 90
# description: esxmon
### BEGIN INIT INFO
# Provides: esxmon
# Required-Start: networking
# Required-Stop: networking
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Start the program
### END INIT INFO
### Fill in these bits:
START_CMD="/path/to/your/script/esxmon.sh > /var/log/esxmon.log 2>&1 &"
NAME="esxmon"
PGREP_STRING="/path/to/your/script/esxmon.sh"
PID_FILE="/var/run/esxmon/esxmon.pid"
USER="root"
### No further muckin' about needed!
#CUR_USER=`whoami`
CUR_USER="root"
killproc() {
pkill -u $USER -f $PGREP_STRING
}
start_daemon() {
eval "$*"
}
log_success_msg() {
echo "$*"
logger "$_"
}
log_failure_msg() {
echo "$*"
logger "$_"
}
check_proc() {
pgrep -u $USER -f $PGREP_STRING >/dev/null
}
start_script() {
if [ "${CUR_USER}" != "root" ] ; then
log_failure_msg "$NAME can only be started as 'root'."
exit -1
fi
check_proc
if [ $? -eq 0 ]; then
log_success_msg "$NAME is already running."
exit 0
fi
[ -d /var/run/$NAME ] || (mkdir /var/run/$NAME )
# make go now
start_daemon /bin/su $USER -c "$START_CMD"
# Sleep for a while to see if anything cries
sleep 5
check_proc
if [ $? -eq 0 ]; then
log_success_msg "Started $NAME."
else
log_failure_msg "Error starting $NAME."
exit -1
fi
}
stop_script() {
if [ "${CUR_USER}" != "root" ] ; then
log_failure_msg "You do not have permission to stop $NAME."
exit -1
fi
check_proc
if [ $? -eq 0 ]; then
killproc -p $PID_FILE >/dev/null
# Make sure it's dead before we return
until [ $? -ne 0 ]; do
sleep 1
check_proc
done
check_proc
if [ $? -eq 0 ]; then
log_failure_msg "Error stopping $NAME."
exit -1
else
log_success_msg "Stopped $NAME."
fi
else
log_failure_msg "$NAME is not running or you don't have permission to stop it"
fi
}
check_status() {
check_proc
if [ $? -eq 0 ]; then
log_success_msg "$NAME is running."
else
log_failure_msg "$NAME is stopped."
exit -1
fi
}
case "$1" in
start)
start_script
;;
stop)
stop_script
;;
restart)
stop_script
start_script
;;
status)
check_status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
\ No newline at end of file
#!/bin/bash
# chkconfig: 2345 90 90
# description: custom-esxi
### BEGIN INIT INFO
# Provides: custom-esxi
# Required-Start: network
# Required-Stop: network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Start the program
### END INIT INFO
### Fill in these bits:
START_CMD="/path/to/your/script/esxmon.sh > /var/log/custom-esxi.log 2>&1 &"
NAME="custom-esxi"
PGREP_STRING="//path/to/your/script/esxmon.sh"
PID_FILE="/var/run/custom-esxi/custom-esxi.pid"
USER="root"
### No further muckin' about needed!
#CUR_USER=`whoami`
CUR_USER="root"
killproc() {
pkill -u $USER -f $PGREP_STRING
}
start_daemon() {
eval "$*"
}
log_success_msg() {
echo "$*"
logger "$_"
}
log_failure_msg() {
echo "$*"
logger "$_"
}
check_proc() {
pgrep -u $USER -f $PGREP_STRING >/dev/null
}
start_script() {
if [ "${CUR_USER}" != "root" ] ; then
log_failure_msg "$NAME can only be started as 'root'."
exit -1
fi
check_proc
if [ $? -eq 0 ]; then
log_success_msg "$NAME is already running."
exit 0
fi
[ -d /var/run/$NAME ] || (mkdir /var/run/$NAME )
# make go now
start_daemon /bin/su $USER -c "$START_CMD"
# Sleep for a while to see if anything cries
sleep 5
check_proc
if [ $? -eq 0 ]; then
log_success_msg "Started $NAME."
else
log_failure_msg "Error starting $NAME."
exit -1
fi
}
stop_script() {
if [ "${CUR_USER}" != "root" ] ; then
log_failure_msg "You do not have permission to stop $NAME."
exit -1
fi
check_proc
if [ $? -eq 0 ]; then
killproc -p $PID_FILE >/dev/null
# Make sure it's dead before we return
until [ $? -ne 0 ]; do
sleep 1
check_proc
done
check_proc
if [ $? -eq 0 ]; then
log_failure_msg "Error stopping $NAME."
exit -1
else
log_success_msg "Stopped $NAME."
fi
else
log_failure_msg "$NAME is not running or you don't have permission to stop it"
fi
}
check_status() {
check_proc
if [ $? -eq 0 ]; then
log_success_msg "$NAME is running."
else
log_failure_msg "$NAME is stopped."
exit -1
fi
}
case "$1" in
start)
start_script
;;
stop)
stop_script
;;
restart)
stop_script
start_script
;;
status)
check_status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
\ No newline at end of file
#!/bin/bash
# chkconfig: 2345 90 90
# description: healthmon
### BEGIN INIT INFO
# Provides: healthmon
# Required-Start: networking
# Required-Stop: networking
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Start the program
### END INIT INFO
### Fill in these bits:
START_CMD="/path/to/your/script/healthmon.sh > /var/log/healthmon.log 2>&1 &"
NAME="healthmon"
PGREP_STRING="/path/to/your/script/healthmon.sh"
PID_FILE="/var/run/healthmon/healthmon.pid"
USER="root"
### No further muckin' about needed!
#CUR_USER=`whoami`
CUR_USER="root"
killproc() {
pkill -u $USER -f $PGREP_STRING
}
start_daemon() {
eval "$*"
}
log_success_msg() {
echo "$*"
logger "$_"
}
log_failure_msg() {
echo "$*"
logger "$_"
}
check_proc() {
pgrep -u $USER -f $PGREP_STRING >/dev/null
}
start_script() {
if [ "${CUR_USER}" != "root" ] ; then
log_failure_msg "$NAME can only be started as 'root'."
exit -1
fi
check_proc
if [ $? -eq 0 ]; then
log_success_msg "$NAME is already running."
exit 0
fi
[ -d /var/run/$NAME ] || (mkdir /var/run/$NAME )
# make go now
start_daemon /bin/su $USER -c "$START_CMD"
# Sleep for a while to see if anything cries
sleep 5
check_proc
if [ $? -eq 0 ]; then
log_success_msg "Started $NAME."
else
log_failure_msg "Error starting $NAME."
exit -1
fi
}
stop_script() {
if [ "${CUR_USER}" != "root" ] ; then
log_failure_msg "You do not have permission to stop $NAME."
exit -1
fi
check_proc
if [ $? -eq 0 ]; then
killproc -p $PID_FILE >/dev/null
# Make sure it's dead before we return
until [ $? -ne 0 ]; do
sleep 1
check_proc
done
check_proc
if [ $? -eq 0 ]; then
log_failure_msg "Error stopping $NAME."
exit -1
else
log_success_msg "Stopped $NAME."
fi
else
log_failure_msg "$NAME is not running or you don't have permission to stop it"
fi
}
check_status() {
check_proc
if [ $? -eq 0 ]; then
log_success_msg "$NAME is running."
else
log_failure_msg "$NAME is stopped."
exit -1
fi
}
case "$1" in
start)
start_script
;;
stop)
stop_script
;;
restart)
stop_script
start_script
;;
status)
check_status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
\ No newline at end of file
#!/bin/bash
# chkconfig: 2345 90 90
# description: inetmon
### BEGIN INIT INFO
# Provides: inetmon
# Required-Start: networking
# Required-Stop: networking
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Start the program
### END INIT INFO
### Fill in these bits:
START_CMD="/path/to/your/script/inetmon.sh > /var/log/inetmon.log 2>&1 &"
NAME="inetmon"
PGREP_STRING="/path/to/your/script/inetmon.sh"
PID_FILE="/var/run/inetmon/inetmon.pid"
USER="root"
### No further muckin' about needed!
#CUR_USER=`whoami`
CUR_USER="root"
killproc() {
pkill -u $USER -f $PGREP_STRING
}
start_daemon() {
eval "$*"
}
log_success_msg() {
echo "$*"
logger "$_"
}
log_failure_msg() {
echo "$*"
logger "$_"
}
check_proc() {
pgrep -u $USER -f $PGREP_STRING >/dev/null
}
start_script() {
if [ "${CUR_USER}" != "root" ] ; then
log_failure_msg "$NAME can only be started as 'root'."
exit -1
fi
check_proc
if [ $? -eq 0 ]; then
log_success_msg "$NAME is already running."
exit 0
fi
[ -d /var/run/$NAME ] || (mkdir /var/run/$NAME )
# make go now
start_daemon /bin/su $USER -c "$START_CMD"
# Sleep for a while to see if anything cries
sleep 5
check_proc
if [ $? -eq 0 ]; then
log_success_msg "Started $NAME."
else
log_failure_msg "Error starting $NAME."
exit -1
fi
}
stop_script() {
if [ "${CUR_USER}" != "root" ] ; then
log_failure_msg "You do not have permission to stop $NAME."
exit -1
fi
check_proc
if [ $? -eq 0 ]; then
killproc -p $PID_FILE >/dev/null
# Make sure it's dead before we return
until [ $? -ne 0 ]; do
sleep 1
check_proc
done
check_proc
if [ $? -eq 0 ]; then
log_failure_msg "Error stopping $NAME."
exit -1
else
log_success_msg "Stopped $NAME."
fi
else
log_failure_msg "$NAME is not running or you don't have permission to stop it"
fi
}
check_status() {
check_proc
if [ $? -eq 0 ]; then
log_success_msg "$NAME is running."
else
log_failure_msg "$NAME is stopped."
exit -1
fi
}