Skip to content

Instantly share code, notes, and snippets.

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