#!/bin/bash

output_config() {
    echo "graph_order node_crc node_io node_coll"
    echo "graph_title Node 2 Bus Probleme"
#    echo "graph_args --base 1000 -u 50 -l -20"
    echo "graph_args --base 1000 -l 0"
    echo "graph_vlabel Nachrichten"
    echo "graph_scale no"
    echo "graph_category aqhome"

    echo "node_crc.label CRC errors"
    echo "node_io.label IO errors"
    echo "node_coll.label collisions"
}


output_values() {
    printf "node_crc.value %f\n" $(get_var_crc)
    printf "node_io.value %f\n" $(get_var_io)
    printf "node_coll.value %f\n" $(get_var_coll)
}


get_var_crc() {
    /usr/local/bin/aqhome-tool getdata -N nodes/5d91f355/net/crcerrors -tb -300 -M | cut -d$'\t' -f 2
}


get_var_io() {
    /usr/local/bin/aqhome-tool getdata -N nodes/5d91f355/net/ioerrors -tb -300 -M | cut -d$'\t' -f 2
}


get_var_coll() {
    /usr/local/bin/aqhome-tool getdata -N nodes/5d91f355/net/collisions -tb -300 -M | cut -d$'\t' -f 2
}






output_usage() {
    printf >&2 "%s - munin plugin to monitor packets\n" ${0##*/}
    printf >&2 "Usage: %s [config]\n" ${0##*/}
}

case $# in
    0)
        output_values
        ;;
    1)
        case $1 in
            config)
                output_config
                ;;
            *)
                output_usage
                exit 1
                ;;
        esac
        ;;
    *)
        output_usage
        exit 1
        ;;
esac

