Created
October 15, 2014 11:21
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 characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment