#!/bin/bash
USER=root #mysql user
PASSWORD=astercc #mysql password
#呼入量
INBOUNDCOUNT=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curpbxcdrs where endtime='0000-00-00 00:00:00' and calltype='DIALIN' and memo != 'PREDICTIVE CALLER';" 2>/dev/null|awk 'NR==2{print $1}'`  
#呼出量
OUTBOUNDCOUNT=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curpbxcdrs where endtime='0000-00-00 00:00:00' and (userfield='DID DIALOUT' or calltype='DIALOUT') and answertime='0000-00-00 00:00:00';" 2>/dev/null|awk 'NR==2{print $1}'`
#呼出振铃量
OUTBOUNDRINGING=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curpbxcdrs where endtime='0000-00-00 00:00:00' and (userfield='DID DIALOUT' or calltype='DIALOUT') and answertime='0000-00-00 00:00:00';" 2>/dev/null|awk 'NR==2{print $1}'`
#呼出接通量
OUTBOUNDANSWER=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curpbxcdrs where endtime='0000-00-00  00:00:00' and (userfield='DID DIALOUT' or calltype='DIALOUT') and answertime!='0000-00-00 00:00:00';" 2>/dev/null|awk 'NR==2{print $1}'`
#话务量
TRAFFICCOUNT=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curpbxcdrs where endtime='0000-00-00 00:00:00' and memo != 'PREDICTIVE CALLER';" 2>/dev/null|awk 'NR==2{print $1}'`
#坐席总数
AGENTCOUNT=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_agents;" 2>/dev/null|awk 'NR==2{print $1}'`
#坐席签入数目
AGENTCHECKLOGIN=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curagents;" 2>/dev/null|awk 'NR==2{print $1}'`
#坐席通话数目
AGENTCALL=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curagents where status='ringing' and status='busy';" 2>/dev/null|awk 'NR==2{print $1}'`
#坐席呼出数目
AGENTOUTBOUND=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curpbxcdrs where endtime='0000-00-00 00:00:00' and (userfield='DID DIALOUT' or calltype='DIALOUT') and agentno!='';" 2>/dev/null|awk 'NR==2{print $1}'`
#坐席呼入数目
AGENTINBOUND=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curpbxcdrs where endtime='0000-00-00 00:00:00' and calltype='DIALIN' and memo !='PREDICTIVE CALLER' and agentno!='';" 2>/dev/null|awk 'NR==2{print $1}'`
#坐席话后数目
AGENTACW=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curagents where status='pause' and acw_status!='';" 2>/dev/null|awk 'NR==2{print $1}'`
#坐席暂停数目
AGENTPAUSE=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curagents where status='pause' and acw_status='';" 2>/dev/null|awk 'NR==2{print $1}'`
#小休
AGENTREST=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curagents where status='pause' and acw_status='' and pause_reason='rest';" 2>/dev/null|awk 'NR==2{print $1}'`
#午休
AGENTLUNCH=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curagents where status='pause' and acw_status='' and pause_reason='lunch';" 2>/dev/null|awk 'NR==2{print $1}'`
#请假
LEAVE=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curagents where status='pause' and acw_status='' and pause_reason='leave';" 2>/dev/null|awk 'NR==2{print $1}'`
#会议
MEETING=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curagents where status='pause' and acw_status='' and pause_reason='meeting';" 2>/dev/null|awk 'NR==2{print $1}'`
#培训
TRAINING=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curagents where status='pause' and acw_status='' and pause_reason='training';" 2>/dev/null|awk 'NR==2{print $1}'`
#其他
OTHER=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curagents where status='pause' and acw_status='' and pause_reason='other';" 2>/dev/null|awk 'NR==2{print $1}'`
#排队量
WAIT=`mysql -u$USER -p$PASSWORD astercc10 -e "select count(*) from cc10_curqueuecallers where status='wait';" 2>/dev/null|awk 'NR==2{print $1}'`
#channels
CHANNELS=`asterisk -rx 'core show channels count' 2>/dev/null|awk 'NR==3{print $1}'`
#calls
CALLS=`asterisk -rx 'core show calls' 2>/dev/null|awk 'NR==2{print $1}'`
if [ $1 = 'INBOUNDCOUNT' ]
    then
        echo $INBOUNDCOUNT
elif [ $1 = 'OUTBOUNDCOUNT' ]
    then
        echo $OUTBOUNDCOUNT
elif [ $1 = 'OUTBOUNDRINGING' ]
    then
        echo $OUTBOUNDRINGING
elif [ $1 = 'OUTBOUNDANSWER' ]
    then
        echo $OUTBOUNDANSWER
elif [ $1 = 'TRAFFICCOUNT' ]
    then
        echo $TRAFFICCOUNT
elif [ $1 = 'AGENTCOUNT' ]
    then
        echo $AGENTCOUNT
elif [ $1 = 'AGENTCHECKLOGIN' ]
    then
        echo $AGENTCHECKLOGIN
elif [ $1 = 'AGENTCALL' ]
    then
        echo $AGENTCALL
elif [ $1 = 'AGENTOUTBOUND' ]
    then
        echo $AGENTOUTBOUND
elif [ $1 = 'AGENTINBOUND' ]
    then
        echo $AGENTINBOUND
elif [ $1 = 'AGENTACW' ]
    then
        echo $AGENTACW
elif [ $1 = 'AGENTPAUSE' ]
    then
        echo $AGENTPAUSE
elif [ $1 = 'AGENTREST' ]
    then
        echo $AGENTREST
elif [ $1 = 'AGENTLUNCH' ]
    then
        echo $AGENTLUNCH
elif [ $1 = 'LEAVE' ]
    then
        echo $LEAVE
elif [ $1 = 'MEETING' ]
    then
        echo $MEETING
elif [ $1 = 'TRAINING' ]
    then
        echo $TRAINING
elif [ $1 = 'OTHER' ]
    then
        echo $OTHER
elif [ $1 = 'WAIT' ]
    then
        echo $WAIT
elif [ $1 = 'CHANNELS' ]
    then
        echo $CHANNELS
elif [ $1 = 'CALLS' ]
    then
        echo $CALLS
else
        echo "输入变量有误"
fi
