summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xminimunin59
1 files changed, 40 insertions, 19 deletions
diff --git a/minimunin b/minimunin
index 4743009..15289bc 100755
--- a/minimunin
+++ b/minimunin
@@ -1,17 +1,14 @@
1#!/bin/sh 1#!/bin/sh
2 2
3PLUGIN_DIR=/usr/local/etc/minimunin-plugins 3PLUGIN_DIR=/usr/local/etc/minimunin-plugins
4CONFIG_DIR=/usr/local/etc/minimunin-configs
4BUILTIN="cpu load swap systat iostat uptime memory open_files" 5BUILTIN="cpu load swap systat iostat uptime memory open_files"
6SYSCTL=/sbin/sysctl
7[ -f ${SYSCTL} ] || SYSCTL=/usr/sbin/sysctl
5 8
6# list plugins 9# list plugins, read configs
7PLUGINS=`/usr/bin/find ${PLUGIN_DIR} -type f -perm +111 -exec basename {} \; 2> /dev/null | /usr/bin/xargs` 10PLUGINS=`/usr/bin/find ${PLUGIN_DIR} -type f -perm +111 -exec basename {} \; 2> /dev/null | /usr/bin/xargs`
8 11CONFIGS=`/usr/bin/find ${CONFIG_DIR} -type f -exec /usr/bin/grep -v -e ^\# -e ^$ {} \; -exec /bin/echo [] \; 2> /dev/null`
9get_plugin() {
10 plug=`/usr/bin/find ${PLUGIN_DIR} -type f -perm +111 -name $1 | /usr/bin/head -n 1`
11 [ -z "${plug}" ] && return 1
12 printf %s ${plug}
13 return 0
14}
15 12
16main() { 13main() {
17 # print banner 14 # print banner
@@ -49,11 +46,7 @@ main() {
49print_fetch() { 46print_fetch() {
50 47
51# see if we're serving a plugin 48# see if we're serving a plugin
52plug=`get_plugin $1` 49call_plugin $1 fetch && return 0
53if [ $? = 0 ]; then
54 eval ${plug}
55 return
56fi
57 50
58# if not, let our builtins answer 51# if not, let our builtins answer
59case $1 in 52case $1 in
@@ -105,11 +98,7 @@ esac
105print_config() { 98print_config() {
106 99
107# see if we're configuring a plugin 100# see if we're configuring a plugin
108plug=`get_plugin $1` 101call_plugin $1 config && return 0
109if [ $? = 0 ]; then
110 eval ${plug} config
111 return
112fi
113 102
114# if not, execute built in commands 103# if not, execute built in commands
115case $1 in 104case $1 in
@@ -309,7 +298,39 @@ esac
309} 298}
310 299
311get_sys() { 300get_sys() {
312 LANG=C LC_ALL=C /sbin/sysctl -n $@ 301 LANG=C LC_ALL=C ${SYSCTL} -n $@
302}
303
304env_for_plugin_from_config() {
305 unset in_sect
306 while read line; do
307 case ${line## } in
308 \[*\]) v="${line#*[}"; v="${v%%]*}"
309 case $1 in ${v}) in_sect=true;; *) unset in_sect ;; esac
310 ;;
311 env.*) [ "${in_sect}" ] || continue
312 _pref=${line#*env.};
313 printf "%s " ${_pref%% *}=\'${_pref#* }\'
314 ;;
315 esac
316 done
317}
318
319call_plugin() {
320 _param=$2
321 _plug=`/usr/bin/find ${PLUGIN_DIR} -type f -perm +111 -name $1 2>/dev/null | /usr/bin/head -n 1`
322 [ -z "${_plug}" ] && return 1
323
324 printf %s "${CONFIGS}" | while read line; do
325 case line in
326 \[*\]) start_section;;
327 *) in_section;;
328 esac
329 done
330
331 _env=$( printf "%s\n" "${CONFIGS}" | env_for_plugin_from_config ${_plug} )
332 eval env ${_env} ${_plug} ${_param}
333 return $?
313} 334}
314 335
315# After function definitions, main() can use them 336# After function definitions, main() can use them