Skip to content

Instantly share code, notes, and snippets.

@drscream
Created October 15, 2014 11:21

Revisions

  1. drscream created this gist Oct 15, 2014.
    21 changes: 21 additions & 0 deletions munin_master_admin_migrate.sh
    Original 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