JasonRivers / nagios-plugins

Nagios plugins

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cannot get result of Calls using check_asterisk_ami

ChenYiHsiang opened this issue · comments

commented

Hi,
Nice plug-in for asterisk monitoring,
But I found one issue and I don't know how to fix.

the result I've got below.

[root@localhost libexec]# ./check_asterisk_ami -H XXXXXXXX -q sippeers -u admin -p XXXXXXXX -P 5038 -w 100 -c 20 OK: 20 online, 6 offline SIP peers|online=20 offline=6
[root@localhost libexec]# ./check_asterisk_ami -H XXXXXXXX -q channels -u admin -p XXXXXXXX -P 5038 -w 100 -c 20 OK: 0 Asterisk calls active|channels=0
[root@localhost libexec]# ./check_asterisk_ami -H XXXXXXXX -q calls -u admin -p XXXXXXXX -P 5038 -w 100 -c 20
./check_asterisk_ami: line 166: [: Output:: integer expression expected
./check_asterisk_ami: line 169: [: Output:: integer expression expected
./check_asterisk_ami: line 172: [: Output:: integer expression expected

and the code is :
...
166 if [ $CALLS -lt $WARNINGNUMBER ]; then
167 exitstatus=$STATE_OK
168 MSG="OK: ${CALLS} Asterisk calls active|calls=${CALLS}"
169 elif [ $CALLS -lt $CRITICALNUMBER ]; then
170 exitstatus=$STATE_WARNING
171 MSG="WARNING: ${CALLS} Asterisk calls active|calls=${CALLS}"
172 elif [ $CALLS -ge $CRITICALNUMBER ]; then
173 exitstatus=$STATE_CRITICAL
174 MSG="CRITICAL: ${CALLS} Asterisk calls active|calls=${CALLS}"
175 fi
...

I'm using lastest Nagios Core and CentOS 7
Is there any way to fix?

Sam

Hi Sam, Sorry I completely missed this, There's no reason this shouldn't work so I'm possibly doing something silly.
I will take a look and see what is going on.
J

Hello, same problem here
[root@nagios]# /usr/local/nagios/libexec/check_asterisk_ami -H myiphere -u myuser -p mypassword -q calls -w 10 -c 30
/usr/local/nagios/libexec/check_asterisk_ami: line 183: [: Output:: integer expression expected
/usr/local/nagios/libexec/check_asterisk_ami: line 186: [: Output:: integer expression expected
/usr/local/nagios/libexec/check_asterisk_ami: line 189: [: Output:: integer expression expected

Other commands work fine and also this same calls query works on some asterisk servers and on some not
Maybe asterisk has changed, using Asterisk 16

Hello,
went into same issue, @dinaras is right, Asterisk16 changed format of AMI output significantly (yes I agree, that it is stupid approach, but anyway):

Response: Success
Message: Command output follows
Output: Channel              Location             State   Application(Data)             
Output: 0 active channels
Output: 0 active calls
Output: 11 calls processed

so current awk expression is not catching correct column. But solution is rather simple, find around line 175 awk command:

awk '/active call/ {print $1}' | tr -d "\r"

and change it into

awk '/active call/ {print $2}' | tr -d "\r"

simple ;-)

Wouldn't the print $2 break pre-asterisk 16 ?

Maybe the right thing here is to default to print $2 and have a "-lagacy" flag on the script for the old one.

It's probably safe (hah) to change to $2 now and have that as the default going forwards.

but yes... changing the format of something that people use to monitor their systems .... would be good it if had a real key / value output or api for monitoring! :-)

Wouldn't the print $2 break pre-asterisk 16 ?

Maybe the right thing here is to default to print $2 and have a "-lagacy" flag on the script for the old one.

It's probably safe (hah) to change to $2 now and have that as the default going forwards.

You are correct it would break compatibility with asterisk <= 13, but none should use it anyway, it is out of the support. :-), Version 16 is still supported in stable Debian.

but yes... changing the format of something that people use to monitor their systems .... would be good it if had a real key / value output or api for monitoring! :-)

This would be only one of the many wishes I would have. :-D