All pastes #186098 Raw Edit

Untitled

public text v1 · immutable
#186098 ·published 2006-09-29 15:15 UTC
rendered paste body
#!/bin/bash
#
# This script collect some infos from Flizy
# and interacts with Zabbix.
#

FLIZY="sudo /usr/sbin/asterisk -rx"

# show sip peers.
show_sip_peers() {
        while [ -z "$LERO" ]; do
                LERO=`$FLIZY "sip show peers" | grep peers | awk '{ print $1 }' | grep '[0-9]'`
        done
        echo $LERO
}

# show iax peers.
show_iax_peers() {
        while [ -z "$LERO" ]; do
                LERO=`$FLIZY "iax2 show peers registered" | grep peers | awk '{ print $ 1 }' | grep '[0-9]'`
        done
        echo $LERO
}

# show active channels or active calls.
show_channels() {
        while [ -z "$LERO" ]; do
                LERO=`$FLIZY "show channels" | grep $1 | awk '{ print $ 1 }' | grep '[0-9]'`
        done
        echo $LERO
}

# show voicemail users.
show_voicemail() {
        while [ -z "$LERO" ]; do
                LERO=`$FLIZY "show voicemail users" | egrep -v "Context|maxmsg" | wc -l | grep '[0-9]'`
        done
        echo $LERO
}

# switch case.
case "$1" in
        'sip show peers')
        show_sip_peers
        ;;
        'iax2 show peers registered')
        show_iax_peers
        ;;
        'show channels')
        show_channels $2
        ;;
        'show voicemail users')
        show_voicemail
        ;;
        *)
esac