Created
October 15, 2014 11:21
Revisions
-
drscream created this gist
Oct 15, 2014 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ #!/bin/bash MUNIN_CONF=${1-'/opt/local/etc/munin/munin.conf'} grep '^\[' ${MUNIN_CONF} | tr -d '[' | tr -d ']' |\ while read line; do if [[ "${line}" =~ ";" ]]; then # group exists group=$(echo ${line} | awk -F \; '{ print $1 }') node=$(echo ${line} | awk -F \; '{ print $2 }') group_insert='INSERT OR IGNORE INTO munin_group (`name`) VALUES ("'${group}'");' node_insert='INSERT INTO munin_host (`name`, `group_id`) VALUES ("'${node}'", (SELECT id FROM munin_group WHERE name = "'${group}'"));' else # no group exists node=${line} node_insert='INSERT INTO munin_host (`name`) VALUES ("'${node}'");' fi echo ${group_insert} echo ${node_insert} done | sort -r | uniq