Using syslog to get caller id name and number from the OBi110

<< < (2/5) > >>

etc6849:
For a regular expressions example, here's what my parsing script looks like in vbscript (I didn't know perl that well, so I decided to let my home automation program do all of the hard work):
Code:

'
' gOBiHAI
' Extracts the parameters out of an OBiHAI syslog packet (only tested on the OBi110).
' Parses sPkt and populates an array called aParms
' Returns the upper bound of aParms
' The i=0,2,4... index of aParms is a string indicating the packet type
' The i=1,3,5... index of aParms is the data pair to data type i-1
'
' Packet types followed by data values:
' State, followed by one of the following integers: 0 = Unknown,1 = OffHook,2=OnHook,3=Ringing
' Status, followed by a string containing miscellaneous information
' ICMState, followed by one of the following integers: 0 = Unknown,1 = OffHook,2=OnHook,3=Ringing
' CallerIDNumber, followed by number, CallerIDName, followed by name
' IMPORTANT NOTE: CallerIDNumber has a lower index than CallerIDName
' Therefore, CallerIDName will be processed last by OBi110.OnChangeOnNewData

function gOBiHAIParser(sPkt, aParms)
dim oRegEx, oMatches, oMatch
dim Tmp
dim bStatusFlag

'grab status packet
bStatusFlag = true

iCmdLength = len(sPkt)

set oRegEx = New RegExp
with oRegEx
.ignoreCase = true
.global = true

' Test for off hook status response
'
' Note offhook will also correspond to in-call
' incall appears in syslog following a call being answered
' if we didn't do this, status would be stuck on "Ringing" during the entire call
' until the phone is hung up.
.pattern = "((offhook)|(off hook)|(state=incall)|(state:incall))"
set oMatches = .Execute(sPkt)
if oMatches.Count = 1  then
' Confirmed it is a valid off hook packet
redim aParms(1)
aParms(0) = "State"
aParms(1) = 1

'do not grab status packet
bStatusFlag = false
end if

' Test for on hook status response
.pattern = "((onhook)|(on hook))"
set oMatches = .Execute(sPkt)
if oMatches.Count = 1  then
' Confirmed it is a valid on hook packet
redim aParms(1)
aParms(0) = "State"
aParms(1) = 2

'do not grab status packet
bStatusFlag = false
end if

' Test for on ring status
.pattern = "((incoming new call)|(start ring))"
set oMatches = .Execute(sPkt)
if oMatches.Count = 1  then
' Confirmed it is a valid on hook packet
redim aParms(1)
aParms(0) = "State"
aParms(1) = 3

'do not grab status packet
bStatusFlag = false
end if

' Test for caller id data
' I assume that the OBi110 will dump name and number in the same packet
' and that a number will always be present, but a name may be blank...
.pattern = "(cid)"
set oMatches = .Execute(sPkt)
if oMatches.Count = 1  then
' Confirmed it is a valid on CID packet, now find number
.pattern = "([0-9]{7,})"
set oMatches = .Execute(sPkt)
if oMatches.Count > 0  then
redim aParms(3)
aParms(0) = "CallerIDNumber"
aParms(2) = "CallerIDName"

if oMatches.Count = 1  then
aParms(1) = oMatches(0)
' Now parse name information
' If name is less than two characters "Unknown Caller" is returned.
.pattern = "('.{2,}')"
set oMatches = .Execute(sPkt)
if oMatches.Count = 0  then
aParms(3) = "Unknown Caller"
else
aParms(3) = oMatches(0)
end if
elseif oMatches.Count = 2 then
' Handles case where a packet containing a phone number in the single quotes is received
' e.g. [SLIC] to deliver: CID '1235551234' 1233334567
aParms(1) = oMatches(1)
aParms(3) = "Unknown Caller" ' Don't return a number as name!
end if

end if
' Do not grab status packet
bStatusFlag = false
end if

' If no other packets are found, populate "Status" information
if bStatusFlag then
' Report Status info from FXS (foreign exchange server) packet
.pattern = "(<7> fxs:)"
set oMatches = .Execute(sPkt)
if oMatches.Count = 1  then
' Confirmed it is an FXS packet
redim aParms(1)
aParms(0) = "Status"
aParms(1) = .Replace(sPkt, "")
end if
bStatusFlag = false
end if
end with

set oRegEx = nothing
set oMatches = nothing
set oMatch = nothing
gOBiHAIParser = ubound(aParms)
end function

infin8loop:
etc6849,

Looks like the: "<7> [0]DAA CND 10190152,1231234567,LNAME FNAME    ,,,"
message only shows up for calls on the LINE port.  It's most likely redundant to the "<7> [SLIC] CID to deliver:" message. When I wrote the script I thought I saw at times when both messages didn't always come in.  But maybe I dreamed that.  I have attached a commented syslog showing test calls I made to the LINE port (AT&T PSTN), SP1 (GV) and SP2 (voip.ms).  The first three calls originated from another AT&T land line not connected to the OBi110. The last call was made from my cell phone to an iNum local access number and then routed to my iNum supplied by voip.ms on SP2.  I answered each call that's listed in the attached syslog after the callerid number and name  (if available) showed up on the cordless phone attached to the OBi110 phone port.  Hopefully the comments in the syslog will tell you everything you need to know.  I had sip debug messages disabled -- just too much info for this exercise.

And I forgot to mention I masked names, phone numbers, ip addresses, etc. with string values of identical length to the originals.
          

etc6849:
Thanks, this is very helpful.  It appears my parsing script will work on land lines and VOIP.ms as is. :)

Do these extra spaces always show up following FNAME?
 <7> [SLIC] CID to deliver: 'LNAME FNAME    ' 1231234567 

If so, my script needs to trim extra spaces.

infin8loop:
Quote from: etc6849 on October 19, 2011, 06:06:03 am

Do these extra spaces always show up following FNAME?
 <7> [SLIC] CID to deliver: 'LNAME FNAME    ' 1231234567 
If so, my script needs to trim extra spaces.


Regex is definitely the way to go.  I didn't have voip.ms at the time I wrote my script so I didn't see callerid names shorter than 15 characters with trailing spaces as necessary.  Looks like AT&T PSTN calls always show up with the trailing spaces if needed to pad out to 15 characters.  It was my first perl script, so to make things simple for myself I just went with fixed positions.  I didn't think it would hold up in real use. 

If you haven't already you might want to include code to lookup numbers with no callerid name.  Someone posted this link elsewhere in the forums:  http://freecnam.org/dip?q=12146301210  (I put this particular number in the query).  It should return a one line callerid name if the number is found.

   

etc6849:
This is a great idea to look up the caller id name...

I plugged several number into the link by replacing the x with the number:
http://freecnam.org/dip?q=1xxxxxxxxxx

None of the numbers I tried showed a company or individual name?  Am I doing something wrong or is the success rate just low for that particular site?

Also thanks for the info on the padding; this is very helpful!

Navigation

[0] Message Index

[#] Next page

[*] Previous page