Skip to content

Commit 69de5dc

Browse files
committed
added newchannel monitor
1 parent 4b411b0 commit 69de5dc

File tree

6 files changed

+93
-0
lines changed

6 files changed

+93
-0
lines changed

README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ AsterTrace is extendable via "listeners". Currently these listeners exist:
1111
* event
1212
* dtmf
1313
* varset
14+
* newchannel
1415

1516
So currently, AsterTrace can monitor:
1617
* All events (event-listener)
1718
* Call activity (CDR like) (dial-listener)
1819
* DTMF's pressed (dtmf-listener)
1920
* VarSet's (varset-listener)
21+
* Newchannel (newchannel-listener)
2022

2123
Each listener is autosufficient, and get called by the container (Ding) whenever an
2224
interesting event occurs. Ding will get called by the pami helper, whenever AMI reports

conf/mysql.properties.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ mysql.table.call=call
77
mysql.table.dtmf=dtmf
88
mysql.table.event=event
99
mysql.table.var=var
10+
mysql.table.newchannel=newchannel
1011

conf/support/event-handlers.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
<import resource="event-handlers/dtmf.xml"/>
55
<import resource="event-handlers/event.xml"/>
66
<import resource="event-handlers/varset.xml"/>
7+
<import resource="event-handlers/newchannel.xml"/>
78
</beans>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans>
3+
<bean id="createNewChannelStatement" class="PDOStatement" scope="prototype"
4+
factory-bean="pdoMysql" factory-method="prepare">
5+
<constructor-arg><value>
6+
CREATE TABLE IF NOT EXISTS `${mysql.table.newchannel}` (
7+
`exten` varchar(32) NOT NULL,
8+
`context` varchar(32) NOT NULL,
9+
`clid_num` varchar(32) NOT NULL,
10+
`clid_name` varchar(32) NOT NULL,
11+
`uniqueid` varchar(32) NOT NULL,
12+
`channel` varchar(32) NOT NULL,
13+
`state` int NOT NULL,
14+
`description` varchar(32) NOT NULL,
15+
`created` timestamp NOT NULL default CURRENT_TIMESTAMP,
16+
KEY (`exten`),
17+
KEY (`context`),
18+
KEY (`channel`),
19+
KEY (`state`),
20+
KEY (`description`),
21+
KEY (`uniqueid`)
22+
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
23+
</value></constructor-arg>
24+
</bean>
25+
26+
<bean id="insertNewChannelStatement" class="PDOStatement" scope="prototype"
27+
factory-bean="pdoMysql" factory-method="prepare">
28+
<constructor-arg><value>
29+
INSERT INTO `${mysql.table.newchannel}` (`state`, `description`, `exten`, `context`, `clid_num`, `clid_name`, `uniqueid`, `channel`)
30+
VALUES(:state, :description, :exten, :context, :clid_num, :clid_name, :uniqueid, :channel)
31+
</value></constructor-arg>
32+
</bean>
33+
</beans>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans>
3+
<import resource="event-handlers/newchannel-pdo-mysql-statements.xml"/>
4+
<bean id="newChannelListener" class="AsterTrace\EventHandlers\NewChannelListener" scope="singleton"
5+
init-method="init" listens-on="newchannel">
6+
<property name="createStatement"><ref bean="createNewChannelStatement"/></property>
7+
<property name="insertStatement"><ref bean="insertNewChannelStatement"/></property>
8+
</bean>
9+
</beans>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* NewChannel listener, will capture all incoming calls.
4+
*
5+
* PHP Version 5
6+
*
7+
* @category AsterTrace
8+
* @package EventHandlers
9+
* @author Marcelo Gornstein <marcelog@gmail.com>
10+
* @license http://marcelog.github.com/ Apache License 2.0
11+
* @version SVN: $Id$
12+
* @link http://marcelog.github.com/
13+
*
14+
* Copyright 2011 Marcelo Gornstein <marcelog@gmail.com>
15+
*
16+
* Licensed under the Apache License, Version 2.0 (the "License");
17+
* you may not use this file except in compliance with the License.
18+
* You may obtain a copy of the License at
19+
*
20+
* http://www.apache.org/licenses/LICENSE-2.0
21+
*
22+
* Unless required by applicable law or agreed to in writing, software
23+
* distributed under the License is distributed on an "AS IS" BASIS,
24+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
* See the License for the specific language governing permissions and
26+
* limitations under the License.
27+
*
28+
*/
29+
namespace AsterTrace\EventHandlers;
30+
31+
class NewChannelListener extends PDOListener
32+
{
33+
public function onNewchannel($event)
34+
{
35+
$this->executeStatement($this->insertStatement, array(
36+
'uniqueid' => $event->getUniqueId(),
37+
'channel' => $event->getChannel(),
38+
'exten' => method_exists($event, 'getExtension') ? $event->getExtension() : '',
39+
'context' => method_exists($event, 'getContext') ? $event->getContext() : '',
40+
'state' => $event->getChannelState(),
41+
'description' => $event->getChannelStateDesc(),
42+
'clid_num' => $event->getCallerIdNum(),
43+
'clid_name' => $event->getCallerIdName()
44+
));
45+
}
46+
}
47+

0 commit comments

Comments
 (0)