From: Brian Flowers Date: Fri, 4 Nov 2016 00:58:18 +0000 (-0400) Subject: Refactoring the directory structure X-Git-Url: http://git.slightlycyberpunk.com%2C%20git.slightlycyberpunk.com/git/?a=commitdiff_plain;h=872f10bcd17260cf36baf1e0a96dcc736c3f6488;p=bdsm.git Refactoring the directory structure --- diff --git a/README b/README index b5b07b6..3d92685 100644 --- a/README +++ b/README @@ -8,7 +8,6 @@ bdsm is the Bash Daemon for System Monitoring, a truly agentless system monitori a) A GNU system b) bash -c) vmstat 1) INSTALLATION INSTRUCTIONS diff --git a/TODO b/TODO index dd59d54..6b903a2 100644 --- a/TODO +++ b/TODO @@ -3,24 +3,38 @@ TODO BUGFIXES: - Fix sqlite3 logging -- needs to be globally writable May require folder structure refactoring + - Confirm configure correctly adds/removes services + - Fix deploy for refactored locations PLUGINS: - - Starting vmstat on monitor (but not www) echos SSH banner + - sqlite3/file processors to reject and log malformed records\ + - logging of processor start/stop + - I/O - iostat + - RAM - free/vmstat + - Network - netstat, netstat -D + - Uptime - uptime + - IP address - ipconfig + - updates - (package manager) + - Users active - ps -ef + - Processes active - ps -ef REFACTORING: - - Folder structure + - Folder structure -- add to PATH? + (WIP -- updated in main script, processors) bin/bdsm - etc/bdsm.d/monitors - etc/bdsm.d/processors - etc/bdsm.d/bdsm.db - etc/bdsm.d/bdsm.conf - etc/bdsm.d/out.fifo - etc/bdsm.d/in.fifo - etc/bdsm.d/pids - etc/bdsm.d/errors.log - etc/bdsm.d/bdsm.log + etc/bdsm/monitors/ + etc/bdsm/processors/ + etc/bdsm/bdsm.db + etc/bdsm/bdsm.conf + pids/ + bdsm.log + bdsm.err + out.fifo + in.fifo + - Move all pids to pid folder - Add a generic function for killing a process and deleting the pid file Then add checking for 'orphaned' pids - - Replace some of the /dev/null redirects with error logging \ No newline at end of file + - Replace some of the /dev/null redirects with error logging + - Have log levels and autologging from info/warn/error functions \ No newline at end of file diff --git a/bin/bdsm.sh b/bin/bdsm.sh new file mode 100755 index 0000000..fb26406 --- /dev/null +++ b/bin/bdsm.sh @@ -0,0 +1,499 @@ +#!/bin/bash +################################################################################ +# +# bdsm +# Bash Daemon for System Monitoring +# This script provides true agentless monitoring for Linux and Unix systems +# using a number of replaceable modules +# +# Return Codes: +# 1: User terminated +# +# 255: Unknown Signal Received +# +############################################################################### + +# CONFIGURATION +############################################################################### +#config_path="`basename $0`/../etc/bdsm" +config_path="/home/bdsm/etc/bdsm/" +pid_path="/home/bdsm/pids/" + +# TRAP UNKNOWN ERRORS +############################################################################### + +trap failure SIGFPE SIGHUP SIGABRT SIGALRM SIGQUIT +trap term SIGTERM SIGINT + +term() +{ + echo + echo + error "BDSM TERMINATED (Received signal $?)" + exit 1 +} + +failure() +{ + echo + echo + error "Something has gone SERIOUSLY wrong! (Received signal $?)" + exit 255 +} + + +# VARIABLES +############################################################################### + +if [ -f "$config_path/processors/$2.processor" ]; then + processor="${2}" +else + processor="" +fi + +# UTILITY FUNCTIONS +############################################################################### +error() +{ + printf "\e[41m" 1>&2 + printf "ERROR: $1" 1>&2 + printf "\e[0m\n" 1>&2 +} + +warn() +{ + printf "\e[30;43m" 1>&2 + printf "WARNING: $1" 1>&2 + printf "\e[0m\n" 1>&2 + +} + +header() +{ + echo + printf "\e[44m" 1>&2 + printf " $1" 1>&2 + printf "\e[0m\n" 1>&2 +} + +option() +{ + printf "\e[36m" 1>&2 + printf " $1" 1>&2 + printf "\e[0m\n" 1>&2 +} + +prompt() +{ + read -t .25 -n 1000 discard &2 + printf "\r$1" 1>&2 + printf "\e[0;0m " 1>&2 +} + +info() +{ + printf "\e[33m" + printf "INFO: $1" + printf "\e[0m\n" +} + +# Select an item from a list +# Arguments: