Friday, December 2, 2011

How to explain Nagios to grandma

So I visited grandma couple of days back and while talking about work and politics and all, she asked, so what’s this Nagios thing you guys are experts at?
I replied, its an “Enterprise Monitoring Solution” and she went like “Enterprise what now….”, and that actually got me thinking deep (something that i rarely do).
So anyway, to answer gramps pressing question, I gave this analogy.

Take for example a car


One thing cars these days come with are essential gauges to let us know what’s going on inside this technically complex electrical and mechanical marvel. This is called a dashboard.
So dashboards in a car gives us all these really cool information; and while cool, they’re also very essential for the well being and running of that car.

Most modern cars, you can tell the fuel levels, battery status, gear status, hand breaks statuses and what not. All essential right? And some more expensive cars like beamers, will even tell you that you’re due for a service soon!. Now, like many of us, the first thing I do when I power up my baby is to check this dashboard and see all that’s going on and when things are fine, engage gear, pull down that windscreen and breathe all the lovely smog from Kuala Lumpur air. {deep chesty cough x 2}
Now here’s where it gets difficult, lets take the challenge of watching over 10, or 100 or even 1000 cars all at the same time and to know at point in time and accuracy if one of these babies of yours isn’t behaving properly. While its possible to do one at a time but sometimes, it may be too late before you reach car no 99 to know that the battery has been completely discharged. Ouch!..can’t use that car until it gets fixed now… :-(

Fear not car lover, here’s where Nagios comes to play. It is designed in such a way, doesn’t matter which type of car you drive and how the dashboard works, if it is in that dashboard, we can take all the important status information and put them in an easy to use web page for all those cars you manage.
Not only that, when a car reaches a fuel level of less than 10% (or anything you think its important to know about before it goes bonkers), Nagios can..
a) email you
b) send you smses
c) call you
d) put up a message on facebook for you
e) set an appointment with you mechanic

And there ya go, she got it, and thereafter, she went back straight to her room to sleep. But I knew she understood, I do….
Now back in geek-land…
Imagine those cars as servers, devices, applications/software, virtual or cloud infrastructure and what not. Each of these in some small or elaborate way have their own “dashboards” that come in a form of a simple log entry to a popups on your device saying something is wrong and what not. Again, to manage just this one, perhaps its very fine. But imagine managing hundreds, on top of that, a single server can potentially host tens of important apps, making it alone “a lot” to monitor.
The cool thing about Nagios is, you can really literally monitor whatever that server/apps/device  shows you, no gimmicks no joke..Monitor just about any type of hardware, OS, application and of a bare minimum, a plain ole log file!
Give it a try and see the power of Nagios for yourself.
Happy weekend.

Tuesday, November 1, 2011

Nagios Plugin–Advance Traceroute to check between two devices


We had to create a plugin to basically do the following
1) Do a typical traceroute from the Nagios box to a destination IP
2) Instead of calculating the time between the Nagios to Destination Host, we are interested to know the time between two host in between

In other words, a typical traceroute will
NagionServer –> Gateway –> Hop 1 –> Hop 2 –> Hop 3 –> Destination

What this plugin can do is when defined correctly, to check the time (in ms) between Hop 1 up until Hop 3, plot a graph and put up warning and critical values for your alerting.
Here’s the sample plugin, and relevant configuration files you probably need.
NOTE: You may need to tweak for different  Oses other than Debian as this was created and tested with a Debian.
The plugin
  • The plugin (place typically in /usr/local/nagios/libexec)
  • Paste below into a file say trace_time
  • Make sure it belongs to user <nagios> and has execution right; e.g.
  • chown nagios:nagios /usr/local/nagios/libexec/trace_time
  • chmod +X /usr/local/nagios/libexec/trace_time
#####START PLUGIN#####
#!/bin/bash
#
# usage
# ./trace-time <final-dest> <startip> <endip> <warning> <critical>
# Note: You must define all three, there's no error checking
# tip: do a traceroute first, then determine from which ip to which ip do you want to calculate. If
#
#
DEST=$1
IP1=$2
IP2=$3
WARNING=$4
CRITICAL=$5
PROG=`which traceroute`
if [[ $DEST == "" ]]; then
   
    echo "UNKNOWN: No destination ip defined"
    exit 3
fi

if [[ $IP1 == "" ]]; then
        echo "UNKNOWN: No start ip defined"
    exit 3
fi

if [[ $IP2 == "" ]]; then
    IP2=$DEST
fi
if [[ $WARNING -eq "" ]]; then
        echo "UNKNOWN: No warning value defined"
        exit 3
fi
if [[ $CRITICAL == "" ]]; then
        echo "UNKNOWN: No critical value defined"
        exit 3
fi

if [[ $WARNING  >  $CRITICAL ]]; then
        echo "UNKNOWN: Warning value larger than critical value"
        exit 3
fi
#
myepoch=`date +%s`
filename=/tmp/$myepoch.tmp.txt
tempfile=/tmp/$myepoch.output
#
/bin/touch $filename
/bin/touch $tempfile
#
/bin/chown nagios:nagios $filename
/bin/chown nagios:nagios $tempfile
#
#
getreading=`$PROG -n -q 1 $DEST > $tempfile`
#
numberip1=`cat $tempfile | grep ms | grep $IP1 | awk {'print $1'}`
numberip2=`cat $tempfile | grep ms | grep $IP2 | awk {'print $1'}`
#
#
for i in $(seq $numberip1 $numberip2)
do
   
    getms=`cat $tempfile | sed -e 's/^[ \t]*//' | grep ^$i |  awk {'print $3'}`
    echo $getms >> $filename
done
#
startcalc=`awk '{s+=$0} END {print s}' $filename`
#
rm $filename
rm $tempfile
#
# OUTPUTS
#
grapher="$IP1-->$IP2"
#
if awk 'BEGIN{if(0+'$startcalc'>'$CRITICAL'+0)exit 0;exit 1}'
then
        echo "CRITICAL($startcalc): Time exceed critical value|$grapher=$startcalc;$WARNING;$CRITICAL"
        exit 2
fi
if awk 'BEGIN{if(0+'$startcalc'>'$WARNING'+0)exit 0;exit 1}'
then
        echo "WARNING($startcalc): Time exceed warning value|$grapher=$startcalc;$WARNING;$CRITICAL"
        exit 1
       
else
   
        echo "OK($startcalc): Time OK|'$grapher'=$startcalc;$WARNING;$CRITICAL;;"
        exit 0
fi
#####END PLUGIN#####

Nagios – Host.cfg
define host{
        use                     debian5-linuxserver
        host_name     Google WWW server
        alias                   For Tracing TimeHop Distances
        address            209.85.175.105
        }           

Nagios – commands.cfg
define command{
        command_name    check_time_between_hosts
        command_line    $USER1$/trace-time $HOSTADDRESS$ $ARG1$ $ARG2$ $ARG3$ $ARG4$
         }

Nagios – services.cfg
define service{
        use                                       debian5-linuxservice
        host_name                       Google WWW server
        service_description      Between IP 210.5.40.153 to 209.85.250.237
        action_url                          /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
        check_command            check_time_between_hosts!210.5.40.153!113.23.161.66!10!20
       }
* Note, the template debian5-linuxservice and debian5-linuxserver is not default and you need to define one first or use the defaults
Now, just restart Nagios to make it work.

More info
In order for you to know the hop you wish to monitor, simply do a traceroute;
# traceroute -n -q 1 209.85.175.105
-n = Numeric output
- q 1= Only do a single query
In this example below, I am tracing to one of Google’s servers at 209.85.175.105, the output of the trace is like below (NOTE!: actual IPs have been changed)
1  111.22.42.3  0.554 ms
2  111.22.40.153  0.667 ms
3  111.22.40.125  1.026 ms
4  203.188.233.121  1.218 ms
5  203.188.233.205  1.488 ms
6  113.23.161.66  1.627 ms
7  209.85.242.246  1.542 ms
8  209.85.242.125  2.322 ms
9  66.249.94.158  3.075 ms
10  209.85.175.105  2.801 ms

So lets say you wish to trace the time between IP 111.22.40.153 and IP113.23.161.66, simply use the plugin with these values on the CLI (to test);
# ./trace-time 209.85.175.105 111.2.40.153 113.23.161.66 10 20
And the output will look like this;
OK(5.909): Time OK|'111.22.40.153-->113.23.161.66'=5.909;10;20;;
*Which is a typical output expected by Nagios with PNP graphing enabled
Graphs will look like this
image

Sunday, August 28, 2011

pfSense and TM Unifi


This is to show you how to enable pfSense 2.x and use TMNet’s Unifi.
Important to note that inorder to “dial” into Unifi, you must fire the PPPoE through a VLAN and those are VLAN 500 for your regular internet browsing and VLAN 600 for your Video. This guide is to setup basic internet using pfSense.
Assuming you are using at least 2 interfaces, the LAN (in this guide, eth0), which all your local networks (or regular users) are connected, the other interface is WAN (in this guide, eth 1) which will be the one that will dial into Unifi.
image

Your LAN can be easily configured to any IP which you wish your users to connect to. This will typically be the gateway IP address for your users. The interface we will discuss here is the WAN interface.
So summary of the steps to get it working;
1) Define the WAN interface as null (or none)
2) Setup VLAN 500 and tie it to the WAN interface or eth1
3) Setup PPPoE inside VLAN interface

1) Defining WAN interface as null.
Simply go to WAN interface and set it up as none. Save it. Setup like below
image

2) Define a new interface:
On pfSense’s main menu, click on Interfaces and click on (assign). Click on VLANs. Select WAN (or eth1) as the parent interface. Inside VLAN tag, enter 500. Put a nice description, like VLAN-TMUnifi there if you so wish. Click on save.
image
3) Setup PPPoE on the VLANned interface:
Now, click on Interfaces again, click on (assign). Click on the + to add a new interface and select the newly created VLAN-TMUnifi. Notice the interface name that was created for you like OPT1 or OPT2. Click on interfaces again, select (and in this example), OPT1. Click to enable the interface. Under type, select PPPoE. Scroll down to the username and password part. Enter your username and password respectively.
You can also rename your interface as for example, from OPT1 to UNIFPPP (for example):
image

Before you click on save, make sure you select, Block private and bogon networks. They should not pass through this interface (unlike interface LAN).
Now, once you’ve save, click on the blue S icon on the top right of the page. If all config such as username and password is correct, you should see the interface come up like below;
image
If you have problems, click on, Status, click on System Log files then click on PPP. Any issues or errors will be shown there.

Once done, you need to setup gateways and routing correctly in order to route traffic over this new interface you just created and dialed.
image
You should set it up as default unless you have other gateways and such. Otherwise, setting it as default will quickly allow you to browse.
Well that’s it, also of course don’t forget to setup an allow rule from interface LAN to any (to begin with) and allow that connection.
If you need to allow incoming connections, select the UNIFPPP interface instead of WAN and setup your inbound rules there.
Enjoy pfSense and the speed of Unifi!
PS> If you are interested in our appliance, do write to sanjay@astiostech.com. Should cost you around US250/box with 4G flash, enclosure, 3 NICs, 2 USB ports (can use for 3G usb modems etc).

Saturday, August 13, 2011

Using Asterisk call files with FreePBX (using Local channel)

Call files are perhaps one of the coolest things you can do with Asterisk. Just literally dump the file in a particular directory and voila, you can make a call. Past few days, I’ve been playing around with it quite a bit and would like to share some things with you on using the Local channel which is most beneficial since you may wish to take advantage of the dialplans and call flows defined in FreePBX (for instance).
Now, the Local channel does a lot such as checks if voicemail is enabled, call forwarding (follow-me) and other customization to the user’s account. It also would support the Device and User mode if that’s being used. The Local channel rather than using technology channels directly can help with several things again for example restrictions that may apply (context) for a particular user. Using channels like SIP/1000 and IAX/1000 will literally bypass all the good stuff that may have been setup.
In conjunction with asterisk call files e.g. .call. You can do lots! including lots of automation and what not just like how you would do using AMI or any AGI stuff if you know about them. Here I would like to show you how to take advantage of the Local channel in call files.
Channel: Local/2000@from-internal/n
CallerID: <0386892800>
MaxRetries: 0
RetryTime: 1
WaitTime: 10
Context: from-internal
Extension: 86892888
Priority: 1 
Archive: no
Set: AMPUSER=2000
Now try modifying these above values to match your specific needs, e.g. channel 2000 is a user 2000 attached to device 1000, change that, change Extension to the destination you wish to bridge a call and here’s what’s important for device/user mode, you must specify the AMPUSER value otherwise, the macro-set-callerid will not be able to set right variables such as outbound CID for you since the Local/2000 will eventually be using SIP/1000 and SIP 1000 doesn’t really have anything more than just a connection agreement (username/password).
Create this file anywhere and then dump it into /var/spool/asterisk/outgoing and voila, you’ve got call.
Also, would like to share a script to automatically create and move files for you; note this will work with FreePBX 2.8 or higher and Asterisk 1.8.
1) nano /root/callgenerator.sh
2) Paste the script below

#!/bin/bash
user=$1
dial=$2

if [[ "$user" -eq "" ]]; then
    echo "ERROR No User / Destination Defined"
    exit 2
fi

if [[ "$dial" -eq "" ]]; then
    echo "ERROR No Destination Number Specified"
    exit 2
fi

# generate call file
mydate=`date +%d%m%y_%H%M%S`
filename="$mydate.U-$user-D-$dial.call"
#
# SUPPORT ONLY SIP
echo -e "Channel: Local/$dial@from-internal/n
CallerID:
MaxRetries: 0
RetryTime: 1
WaitTime: 10
Context: from-internal
Extension:*60
Priority: 1
Archive: no
Set: AMPUSER=$user" > /var/spool/asterisk/$filename

# Call now
# File ops
chown asterisk:asterisk /var/spool/asterisk/$filename
mv /var/spool/asterisk/$filename /var/spool/asterisk/outgoing/ > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
    echo "ERROR Parsefile crashed"
    exit 2
else
    echo Start calling..
fi

exit 0


3) Make it executable chmod +x /root/callgenerator.sh
Test it out like this /root/callgenerator.sh 2000 986892888 (where 2000 is the user’s phone that will first ring and once picked up, it will proceed with the other leg of the call i.e. 986892888, its important here to use from-internal otherwise, your dialplan routing and prefix handingling (in this case, the number 9) will not be stripped off when calling).

Thursday, August 4, 2011

FreePBX IVR direct dial across multiple locations/asterisk servers/FreePBX servers


Assuming you have 2 FreePBX servers across two location that are connected via a trunk and the trunk dialling does work fine. Meaning you can already call SiteA and SiteB and vice-versa.
SiteA: Extensions 1000 and on
SiteB: Extensions 2000 and on
With the default IVR context in FreePBX it’s limited to local numbers only (in this case SiteA extensions). Imagine if you had a PRI line coming into Site A and the IVR direct dial would then need to reach extensions on Site B, this will by default will not work.
Here’s how to “extend” the IVR dialling to other locations. NOTE, we assume the outbound route doesn’t have a prefix to dial intersite between Site A or Site B.
1) nano /etc/asterisk/extensions_custom.conf
2) Enter the following codes (here’s Site A IVR trying to reach site B)
[from-did-direct-ivr-custom]
exten => _2XXX,1,ExecIf($["${BLKVM_OVERRIDE}" != ""]?Noop(Deleting: ${BLKVM_OVERRIDE}: ${DB_DELETE(${BLKVM_OVERRIDE})}))
exten => _2XXX,n,Set(__NODEST=)
exten => _2XXX,n,Goto(from-internal,${EXTEN},1)

#NOTE each line should start with exten like below, on single lines
image
3) Save the file and reload the dialplan
asterisk –rx “dialplan reload”
Lets say you use prefix 7 to dial site B from site A followed by the extension number. Just edit the part and as an example below;
exten => _2XXX,n,Goto(from-internal,7${EXTEN},1)
Where 7 prefixes automatically is entered before the extension number.
Have fun!

Sunday, July 31, 2011

The 4th Cloud Service? – VoIP As a Service (VaaS)


This weekend, i had a chance to present to Microsoft guests at their office here in Malaysia about cloud computing and focusing my talk on cloud technology security.
It was clear after a while jiving with those techies and seeing their responses and also doing much research, this concept, the relevant technologies wrapped around and more importantly, enjoying unwavering support from some of the big boys such as Google, Microsoft, Amazon, EMC, etc, one can easily deduce that the {{CLOUD}} is here to stay. This could mean a lot to consumers or business opportunists alike to ride on the wave (or as some may still insist, the hype)
In the weekend while on the treadmill at the local gym i started think about one particular service and of course being Astiostech’s core of 2 cores, Asterisk and VoIP and how it fits the 3 domains defined by the Cloud Security Alliance (CSA), and these are;
1) Software as a service
2) Platform as a service
3) Infrastructure as a service
Thinking about where would VoIP sit, it becomes quite clear to me after while that it doesn’t really belong to those categories (as far as I've understood them.) One would think it’s close to SaaS or Software as a service, but i beg to differ, Why?
1) VoIP is software in code, true, but its not offered as one, but rather a communication platform
2) Hosting VoIP is not the same as software, it breaks the boundaries of typical software running on computers and basically runs on IP phones rather.
3) It can connect to other software services to introduce Computer Telephony Integration or CTI to enrich one’s telephony experience but it in itself, isn’t one.
Hosted PBX isn’t something new. Astiostechtech has done so for almost 4 years now and rebranded it as e-fon ( www.efon.my ). We find such application of technology to be quite exciting then and over the years, seeing almost no downtime or complains, we are now convinced that it’s a technology and offering that could really change the way we do PBXes..
How has PBXes works for you currently and in the past.
image
Typically it was like the above diagram
1) Everything was at premise
2) Phones and servers communicated locally
3) Expansions were done as long as the PBX supports them
4) Most of the time, companies change their PBX when moving offices
5) Upgrades get done very sparingly as it can really blow a huge hole in the pocket
Lets talk about web servers and company websites, I can imagine almost all small and medium sized companies host their websites with local providers and do not host them internally. The reason why they host their websites is quite obvious, it’s because the service and support was there and it was just paying a very affordable monthly fee. This is closely tied to the economics of scale. They run operations of hundreds of servers and buy and rent stuff in bulk. Imagine a Hosted PBX like your Website server.
This elevates the need for running local servers, hiring experts to setup and run it and not to forget the cost of running and maintaining such infrastructure. Also to think about disaster recovery and business continuity, while, we businesses should be thinking about making money obviously, and not maintaining PBXes like we didn’t maintain our websites.
Now, imagine if the same like websites, were to be offered as a service to you in regards of telecommunications or simply, a hosted PBX instead of an on premise one.
image
Here’s a sample provider, like Astiostech (e-fon.my) can provide you. As an end user in a small and medium sized organization running your own onsite PBX is shortly becoming a thing of the past. Imagine again these infrastructures are now placed in cloud computing technology.
First and foremost; hosting outside your premise and into services like e-fon can help
1) Re-size on the fly
2) Gain mobility and do not lose your "favourite” phone numbers
3) It has all you need or even more than you can expect. (Economies of scale)
4) Its cheaper to have enterprise features, remember, the economies of scale! Make your organization sound like a multi-billion dollar setup (perception helps btw)
5) Connect to multiple types of Telcos that the PBX provider subscribes to and enjoy rates they enjoy as well
6) Connect to your other offices flawlessly if they use common protocols such as SIP or H323
7) Do not worry about upgrades as its done centrally
8) Use different types of phones or even free ones like softphones

Those you get with Hosted PBXes, i am sure or at least with e-fon you do. But here’s the kicker, with now cloud computing, e-fon gets hosted on cloud services. Not only you enjoy those highlighted list of benefits above, you also can enjoy that offered by putting stuff on cloud computing architecture such as;
1) Fabric on demand (CPU, disk, memory)
2) Auto and transparent redundancy
3) Strong network architecture and bandwidth
4) Probably more secure than if you ever had to put on premise
5) Ride on credible cloud providers for credible service offering

I can imagine in the next few years, this would be the “talk of town” per-se. Hosted PBX will be on just about all companies and hosting on premise even with a keyphone system isn’t attractive or make any sense anymore to business people. Just like how hosting websites took a while before just about all friends and companies i know in the small and medium category of companies have their websites with a provider or in a cloud alike.
From the Astiostechtech Engineering Office…

Tuesday, May 10, 2011

How to make FreePBX updates through Proxy

SInce FreePBX does not honour the proxy settings via the bash export, you need to tell Apache instead to use a proxy. This would apply for FreePBX as well.

Here’s a how to for Debians.

1) #nano  /etc/apache2/envvars

2) Add the following codes at the end. You will notice that there's repeats, sometimes they are needed so keep them there twice.

export ftp_proxy=http://10.50.19.206:8080
export http_proxy=http://10.50.19.206:8080
export FTP_PROXY=http://10.50.19.206:8080
export HTTP_PROXY=http://10.50.19.206:8080

3) #/etc/init.d/apache2 restart

Where 10.50.19.206 is the proxy server and 8080 is the proxy port, you can also insert an auth username like this for all instances above.

http://username:password@10.50.19.206:8080

Friday, April 15, 2011

Asterisk | FreePBX boss secretary module (updated)

In some of our migrations to Asterisk, users keep asking about this feature where the secretary can pickup calls from the boss using a function key in their phones that support them.

Here’s the challenge, the secretary asked us to setup in such a way that they can press this button and pickup their boss’s call. So, that was simple, in Asterisk core its just **<exten> e.g. **1003 and it will pickup 1003 and just program that in the feature code.

The problem was, they want to dial the boss using the same key. So, when you hit **1003 obviously it will not work cause that’s a pickup code being sent.

So here’s the solutions.

How it works? It does a check to see if the device state of the boss is RINGING, if yes, cool, we will pickup if not, we will do a dial. Simple Smile. Here’s the dialplan for Asterisk 1.6.2, see note below if using Asterisk 1.4 with ported DEVSTATE module. Also note that this dialplan is designed for four digits extension scheme. Modify yours accordingly, esp XXXX part …

Note the pickupchan module worked on asterisk 1.6.2. This is to pickup channels originating from other context (such as from-did-direct). Use the appropriate technology such as SIP/ IAX/ or SKINNY/ for instance to pickup that particular extension’s telephone technology.

Put this code up in /etc/asterisk/extensions_custom.conf.

[app-boss-sec]  
; Dialplan
;
exten => _*XXXX*,1,NoOp(Starting boss sec module)
exten => _*XXXX*,n,Macro(user-callerid,)
exten => _*XXXX*,n,Set(mydev=${DB(AMPUSER/${EXTEN:1:4}/device)})
exten => _*XXXX*,n,NoOp(mydev is = ${mydev})
exten => _*XXXX*,n,NoOp(SIP/${mydev} has state ${DEVICE_STATE(SIP/${mydev})})
exten => _*XXXX*,n,Set(MYDEVICESTATE=${DEVICE_STATE(SIP/${mydev})})
exten => _*XXXX*,n,NoOp(SIP/${mydev} has state ${MYDEVICESTATE})
;
exten => _*XXXX*,n,Gotoif($[${MYDEVICESTATE} = RINGING ]?pickup)
;
exten => _*XXXX*,n,NoOp(Just call)
exten => _*XXXX*,n,Goto(from-internal,${EXTEN:1:4},1)
exten => _*XXXX*,n,Hangup
;
; We do normal directed pickup
exten => _*XXXX*,n(pickup),NoOp(Pickup)
exten => _*XXXX*,n,Pickup(${EXTEN:1:4})
;
; Incase directed pickup don’t work, we do pickup group type pickup
; Make sure they are in the same pickup group..but of course

exten => _*XXXX*,n,PickupChan(SIP/${EXTEN:1:4})
exten => _*XXXX*,n,Hangup

In extensions_custom.conf, you must include this in your [from-internal-custom]. If you don’t have that context, create it like this. Remember to register the relevant BLFs so that the lights are blinking correctly. In this example, there are two bosses we will “monitor” 1003 and 1004.

[from-internal-custom]
; Register BLFs
exten => *1003*,hint,SIP/1003
exten => *1004*,hint,SIP/1004

include => app-boss-sec

Now, reload asterisk dialplan #asterisk –rx “dialplan reload”.

After reloading, check the hints if they are correctly registered. You should see Watchers 1 or as many as you’ve configured on the secretary's phone. To check,

#asterisk -rx "core show hints" | grep 1003

image

Now on your secretary’s phone, setup the function key (and if you have BLF, use BLF as the function) and enter the extension as *1003*. Now when boss’s 1003 rings, the BLF will blink, if he’s busy will indicate busy light and if he’s not will indicate free light (LED colours and style may vary from phone to phone). If the boss’s phone is ringing, the secretary picks up and if is not ringing state, it will simply do a dial to his extension.

If using Asterisk 1.4 change DEVICE_STATE in the dialplan above to DEVSTATE. Transferring calls are also fine when invoking *<exten>* through the function key or manually dialling.

Do try and let us know.

 

Monday, April 11, 2011

Asternic Stats Outbound Tracking with FreePBX

We at Astiostech use Asternic (www.asternic.biz) quite extensively for basic call centres that require a simple interface for wallboards, reports and recordings.
Asternic also provides some capabilities to monitor outbound callcenters where agents make random calls to introduce new services or businesses.
In this guide, i will attempt to setup outbound call center setup using Asternic and at the same time, show you how to enable recordings that play straight off the Asternic web UI.
This guide assumes the use of Asternic 1.8, FreePBX 2.x and Asterisk 1.6 on Debian systems. I also assume you’ve got all else working with Asternic like, the ioncube loaders, the license and the website is showing you like below;
If yes, great, login with admin and the default password admin.
image

PART 1 – ENABLING OUTBOUND MONITORING

1) Firstly, you must get a valid licensed and a 1.8 version of Asternic. Write to asternic@gmail.com and Nicolas will help you get those.
2) The way Asternic identifies if a particular someone is part of the outbound campaign is by looking for the accountcode value in SIP user as shown below in the FreePBX user configuration. In deviceuser mode, this would be the device, not user.
image
Here, i am creating an account code called C1 which is my outbound campaign 1. If you put things in perspective of an inbound this would then be a queue name. So all defined as C1 in their account code will then be agents of the queue C1. Simple as that right?
3) Next is to make some dialplan changes in FreePBX. There’s a file available from Asternic’s install source (/usr/src/asternic.source.dir/FreePBX/extensions_custom_asternic_outbound_freepbx.conf). Copy this file to /etc/asterisk. Now make sure the asterisk user owns this file since it was newly added.
Now edit it, and modify like below below.
IMPORTANT, THERE’S A SMALL OUTDATED LINE YOU NEED TO MODIFY. EDIT THE extensions_custom_asternic_outbound_freepbx.conf LIKE SHOWN BELOW; there’s one part which calls the mixmonitor dialplan, change the | pipes to , commas. Asterisk 1.4 and above will not accept pipes anymore.
exten => _X.,n,MixMonitor(${QDIALER_QUEUE}-${UNIQUEID}.wav|b|/usr/local/parselog/update_mix_mixmonitor.pl ${UNIQUEID} ${QDIALER_QUEUE}-${UNIQUEID}.wav)
change to
exten => _X.,n,MixMonitor(${QDIALER_QUEUE}-${UNIQUEID}.wav,b,/usr/local/parselog/update_mix_mixmonitor.pl ${UNIQUEID} ${QDIALER_QUEUE}-${UNIQUEID}.wav)
4) Edit /etc/asterisk/extensions_customs.conf and include the above file.
At the very top of extensions_customs.conf, add the line
#include extensions_custom_asternic_outbound_freepbx.conf
Now, if you have followed the INSTALL guide inside the binary archive. It will tell you to place a parselog into /usr/local/parselog/
Inside this directory, there’s an important perl file called update_mix_mixmonitor.pl which converts the WAV file to MP3 so that it can be played using the Asternic GUI (we will show you howto with that later). Make sure you edit this file.
edit /usr/local/parselog/update_mix_mixmonitor.pl
In there, make sure you
1) edit the database connection information, like the username and password particularly
2) edit the asterisk spool location (normally /var/spool/asterisk/monitor).
3) edit the destination dir (create one like /var/spool/asterisk/monitor-mp3)
4) Then go to the end of that file to the lame execution part (to convert WAV to MP3). Make sure the path to lame is correct.
Permission. Now pay attention to this!. Make sure you set the permissions correctly.
chown –R asterisk:asterisk /var/spool/asterisk/monitor
chown –R asterisk:asterisk /var/spool/asterisk/monitor-mp3
chown asterisk:asterisk /usr/local/bin/lame

Now, reload the dialplan, #asterisk –rx “dialplan reload”.
That should do the trick. Make sure you define the account code for the extension/device which need tracking and make that outbound call. Remember, these codes invoke dialout trunk prehook dialplan in FreePBX so internal calls won’t be tracked and if you have sip trunks and what not, make sure you set the correct context to those trunks. After making a couple of calls, you should see this;
image
Where C1 was my accountcode and Agent is my Outbound CID. I made some changes in the dialplan however to reflect the user/extension and not the Outbound CID. (email me if you need the codes for that)
image
As seen above, you can see the details of the calls being made by those in C1 “queue” or accountcode.

PART 2 – ENABLE WEB BASED CALL RECORDINGS FOR INBOUND

Now, as part of Asternic’s offering, you can rightfully with the above steps done properly, be able to see the recordings on the webUI. The only thing you need to do is add a value in the SETUP tab and look for the recordings_path parameter and set it to the destination directory as defined up there.
image
By using the above extra file called extensions_custom_asternic_outbound_freepbx.conf…. file by Asternic, all outbound calls with the accountcode defined will be recorded, of course, you can turn that off by commenting out the mixmonitor dialplan function but i am sure you would want to have that function for training and QA purposes right? Unlike the inbound Queues module in FreePBX, you can choose to record or not to record from the WebUI.
So, if all turns up well, you can see your recordings and play or download it straight from the Web! You need flash to play back by the way and use Firefox for best results.
image


At Astiostech, we do lots of customization of Asternic and call centre based solutions like Aheeva, Majuda that would suite just about any CallCenter types or sizes! Do write or calls us.
sales@astiostech.com
Or call us + 60 3 86892800

Sanjay W
From the engineering desk of Astiostech.

Saturday, March 12, 2011

FreePBX Device User Mode – Enforce login



I had responded to a thread on the FreePBX forum about how to restrict calling without a user first logging in on a device/user mode in FreePBX.
Here’s a simple dialplan which you can then use for your implementation. For FreePBX users, put these lines of codes in /etc/asterisk/extension_custom.conf
[devcheck]
exten => *11,1,Goto(from-internal,${EXTEN},1)
exten => *12,1,Goto(from-internal,${EXTEN},1)
exten => _.,1,Set(USEREXIST=$[${DB(DEVICE/${CALLERID(num)}/user)}])
exten => _.,n,GotoIf($[${USEREXIST}=none]?endit)
exten => _.,n,Goto(from-internal,${EXTEN},1)
exten => _.,n(endit),Playback(pbx-invalid)
exten => h,1,Hangup

Reload the dialplan asterisk –rx “dialplan reload”
Put this in each extension under context settings like below for each device in FreePBX UI.
image
Submit and apply.
At the end that context/dialplan, play anything you like in the Playback() macro. Here, you can record stuff like “You must first log in before making any calls”. I use the above one as a simple sample.
You can put in more exceptions like emergency numbers; besides the login and logoff feature codes in FreePBX at the top.
exten => 999,1,Goto(from-internal,${EXTEN},1)
Where 999 is our Malaysian emergency number.

Saturday, February 12, 2011

Google Voice extends free calls to US and Canada for whole of 2011


Google’s awesome quality Voice service which lets you make free calls to US and Canada is now extended to 2011. There was news that it will only be for 2010 ,but now, in their blog statement they offer this all the way through 2011. Use but don’t abuse.
http://googlevoiceblog.blogspot.com/2010/12/free-calling-in-gmail-extended-through.html

Tuesday, January 25, 2011

[UPDATED] Asterisk & FreePBX Faxing Solution with IAXModem + Hylafax + AvantFax

Updated: 04-11-2013

This guide attempts to walk you through installing a faxing solution on top of Asterisk that has FreePBX as it’s frontend GUI/dialplan generator.

So for it to work, you need to be
1) Using Debian (this is a Debian guide btw). Tested working on Debian 5,6
2) Have a working Asterisk (tested on 1.6,1.8,10,11) either locally or remote. If locally, the IAXModem as shown below, points to itself i.e. 127.0.0.1, if its somewhere, just change the IP
3) Running FreePBX 2.7 or higher (don’t need that if you do manual dialplans tho)

The process is as follow:
1) Create an IAX extension on FreePBX
2) Install IAXModem – Configure at least one virtual serial port
3) Install Hylafax – “Bind” the modem you just created above into Hylafax
4) Install Avantfax, create users and bind users to each virtual modem
5) Use Avantfax to login and retrieve/send faxes

FreePBX IAX extensions (the FAX number)
1) Create an IAX extension in FreePBX, insert the DID and CID so that calls can come into that extension
2) Click on the newly created IAX extension and modify the port (do not use port 4569, use anything else that does not conflict with your system’s UDP listening ports), example below is 4800 and the next IAX extension for fax can then use 4801, so on... This corresponds to the ttyIAX0 file setup below. 
image
3) Apply configuration
4) Go back to that IAX extension again you just created, and set requirecalltoken to no or auto (FreePBX 2.11).

Update apt and fix any broken apt installs
1) # apt-get update
2) # apt-get -f install

Install and configure IAXModem
Install and configure first IAXModem which will then map to the newly created extension above. If you use device/user mode you need to fix the user to an extension and use the user as the username and password in the IAXModem setup below.
1) # apt-get install gcc libtiff-tools libtiff4-dev
2) # apt-get install iaxmodem
3) # cd /etc/iaxmodem/
4) # Create our first modem config as below
5) # nano ttyIAX0 (see something like this below). Note, if you are running Asterisk on this same box, then use 127.0.0.1 as your server IP
device          /dev/ttyIAX0
owner           uucp:uucp
mode            660
port            4800
refresh         3600
server          127.0.0.1
peername        5500
secret          myCOMPLEX123pass
codec           ulaw

6) Edit your inittab to add two lines for each ttyIAX modem you just created, example below
7) # nano /etc/inittab (NOTE: The last zeros are running numbers on IA00, m0, ttyIAX0)

# Load iaxmodem
IA00:23:respawn:/usr/bin/iaxmodem ttyIAX0

# Load hylafax modem listener agent
m0:2345:respawn:/usr/sbin/faxgetty ttyIAX0


7b) #telinit q
The above will initialize /dev/ttyIAX0 or others if you’ve configured them

8) Load your modems
9) #/etc/init.d/iaxmodem stop, then start
10) #ps -ef |grep iaxmodem (you should see your first modem there)
11) On your asterisk server (run on the same server if it runs asterisk as well)
12) # asterisk –rx “iax2 show peers” (you should see that your extension above is now registered, in this case 5500) should show you OK, it may take a while before registration spawns into action.

IAXModem is now done and is registered to Asterisk (ready to receive calls, you can try and you will hear the ringing but no picks up yet, this is hylafax’s job done below..)

Install and configure Hylafax
1) # apt-get install openssh-server hylafax-server
2) Time to configure hylafax
3) #faxsetup
When the faxsetup calls the faxaddmodem script, when it asks "Serial port that modem....enter the modem name above which like ttyIAX0), it will then ask you to enter you country code, area code and phone number, enter anything you wish there. For the rest of the questions, enter default values [press enter all the way till the end unless you know this stuff, i don't, but you may want to set the "Local Identification String" to say your company name on headers..].  Finally it will probe our modem and if that worked it will say OK and tell you what class modem you’re running. If it prompts you to create another modem just terminate by pressing <CTRL+C>
3b) If you are merely adding new users/faxmodems just run # faxaddmodem instead of # faxsetup (which is done only once)
4) #telinit q (run #ps –ef |grep fax and you should see faxgetty there now)
5) For each modem you created in #faxaddmodem a file will be created in /etc/hylafax
6)  #nano /etc/hylafax/config.ttyIAX0, at the end of this file add the following

## Add for AvantFAX use each time you add new modems
#
FaxRcvdCmd:     bin/faxrcvd.php
DynamicConfig:  bin/dynconf.php
UseJobTSI:      true


8) #/etc/init.d/hylafax restart
Hylafax setup done, the modem should pickup and you hear the modem sound

Install and configure AvantFax
1) # apt-get install -y apache2-mpm-prefork apache2-utils apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libpq5 libsqlite3-0 php5-cli php5-common mysql-server imagemagick libtiff4-dev netpbm libnetpbm10-dev libungif-bin libungif4-dev sudo php-mail php-mail-mime php-file php-db php5-mysql sudo php-mail php-mail-mime php-file php-db php5-mysql

(NOTE: if you get a disclaimer file from mysql5.1 and you see the word "END" after scrolling down, do a ":q!" to quit that screen and continue)

Note: During the Avantfax install script for debian below, it may disable or remove other SMTP engine. This script WILL ATTEMPT TO REMOVE OTHER SMTP and INSTALL POSTFIX, continue first, we will show you how to fix that below...
2) #cd /usr/src
3) #wget http://downloads.sourceforge.net/project/avantfax/avantfax-3.3.3.tgz
4) #tar -zxvf avantfax-3.3.3.tgz
5) #cd avantfax-3.3.3
6) #mv /usr/src/avantfax-3.3.3/avantfax /var/www/
7) #chmod -R 777 /var/www/avantfax/tmp /var/www/avantfax/faxes
8) #cd /var/spool/hylafax/bin
9) #mv faxrcvd faxrcvd.old
10) #mv notify notify.old
11) #ln -s /var/www/avantfax/includes/faxrcvd.php /var/spool/hylafax/bin/faxrcvd
12) #ln -s /var/www/avantfax/includes/notify.php /var/spool/hylafax/bin/notify
13) #mv /usr/bin/faxcover /usr/bin/faxcover.old
14) #ln -s /var/www/avantfax/includes/faxcover.php /usr/bin/faxcover
15) #cd /usr/src/avantfax-3.3.3
16) #nano create_tables.sql
17) When editing this file, right on top of this file insert “USE avantfax;” without quotes
18) # nano debian-prefs.txt (IMPORTANT!: Ensure the settings here are correct, e.g. ROOTMYSQLPWD is the root MySQL user, supply its password, pay attention to the httpuser and httpgroup (you can do a ps –ef |grep apache and see what user apache2 is running)
19) Fix some apache logging requirements for Avantfax
20) #mkdir /etc/apache2/logs
21) #touch /etc/apache2/logs/avantfax-error_log
22) #/etc/init.d/apache2 restart

Start install script. This will be the install script for debian then...below.

IMPORTANT: if you do not want to use postfix because you already have an email server, like exim, edit the debian-install.sh script and remove the existence of the word postfix normally found at the line that says apt-get install, then, start. Install will start downloading packages, configuring postfix (if enabled), getting some pear perl stuff. (YOU SHOULD NOT SEE ANY ERRORS!) .

23) #./debian-install.sh
24) When install completes, it may point you to /admin URL, ignore that, we go into /avantfax/admin instead. Do note, that htaccess may interfere with Avantfax, if you face issues being unable to login, remote .htaccess where the avantfax directory also got affected. Once done, you can now login to the WebUI at http(s)://<IPADDRESS>/avantfax/admin. You will be asked to change the password, please do that!

Creating new users/faxes/devices etc...
Firstly, create a category, e.g. Engineering Team, using the pulldown menu.
For each modem you create (iaxmodem), create it also in AvantFax. Modems can be mapped to users, which is what we will do now. Under the pull-down menu, select modems. Create the modem when you configured iaxmodem above.
image
Now, you need to create a new user:
Under the pull-down menu, select new user: create a user and make sure you map him/her to a modem like below;
 image
IMPORTANT! – When you create a new user, there’s a “bug” in hylafax that you also need to manually do it over the cli. So in this case, I've created user sanjay and must delete this user and recreate via cli like below; YOU MUST FOLLOW THE ORDER IN WHICH IS SHOWN AFTER CREATING A USER IN AVANTFAX UI ABOVE.
# faxdeluser sanjay
# faxadduser sanjay
image
It should not have any other objects/characters after the @ for the newly created regular users! as seen corrected above by the faxadduser command.. Make sure the name you created in Avantfax is similar and unique and match that name with the faxadduser command. Be sure to restart hylafax after doing that.

#/etc/init.d/hylafax restart

Now, you should be able to send the fax in to this user/extension and log on to the WebUI or you can receive an fax-to-email email. Regular users can login to: http(s)://<IPADDRESS>/avantfax/ and start receiving and sending faxes. Here’s a test fax i just received without any modification to the graphics and what not:

image

To create more users/devices/faxes:
1) Create a FreePBX extension like shown above (make sure you use unique port numbers, like 4801….4802….4803…etc)
2) Create an IAX modem (you can copy the ttyIAX0 config file to another file, say #cp ttyIAX0 ttyIAX1, modify that 1 file to match the FreePBX extension info you just created on FreePBX), follow the rest of the steps there to restart and create the inittab entry, like below (for ttyIAX1) : NOTICE the underlined values go up as we add new modems.

# Load modem
IA00:23:respawn:/usr/bin/iaxmodem ttyIAX0
IA01:23:respawn:/usr/bin/iaxmodem ttyIAX1

# Faxgetty
m0:2345:respawn:/usr/sbin/faxgetty ttyIAX0
m1:2345:respawn:/usr/sbin/faxgetty ttyIAX1


3) # /etc/init.d/iaxmodem restart && tellinit q
4) Add hylafax, faxmodem, #faxaddmodem, choose ttyIAX1 now and so on..
5) # /etc/init.d/hylafax restart
6) Create modem in AvantFax called ttyIAX1, create user, say john and map to ttyIAX1
7) # faxdeluser john
8) # faxadduser john
9) # /etc/init.d/hylafax restart
10) That user can log in to http(s)://<IPADDRESS>/avantfax/

If you wish to get help with all of these and more customization, contact us at info[@@@]astiostech.com – use one @ of course

As usual, your feedback is much appreciated.

Friday, January 21, 2011

Cancelling an iPhone AppStore Application Install


Thought i’d write this if someone needs some assistance.
Iphone installations using the Appstore while it’s a magical experience, it freaked me out when i had tried to download a game that was over 240MB but i wanted to cancel it and can’t do it on the phone itself (at least for when i tried it). Even though it was on a WiFi i am not fitting my lil pocket rocket with that kinda sized app!
Anyway, to do this is simple. If you wish to cancel or delete a download happening in your Phone right now, simply go to your PC’s/Mac’s iTunes, plug in the iPhone and stop the download there, under the Downloads below STORE (see pic below). Click or Right click (on PCs) and say delete or something…and you’re done! And it will sync the action back to the phone and no more downloading baby!+