My goal is to generate a CDR report (possibly as a CSV file or similar) of all calls every 5 or 10 minutes.
I have been reading two old topic (which I can’t link since I am a new user) but honestly I know nothing about mySQL…
Is possible to do what I would like to achieve? I have been looking on google and stackoverflow so I think yes, but if someone can help me to correct my script it would be useful
/usr/bin/mysql -u ASTERISKCDRUSER -p ASTERISKCDRPASSWORD -e "my query'" > out.csv
Do you think it would work?
Also, I am not sure about how the query works if you have any resources about it please send me a link and I will try to help me out
This is the original script
/usr/bin/mysql -u ASTERISKCDRUSER -pASTERISKCDRPASSWORD -e "select calldate AS Timestamp, clid AS CallerID from cdr where calldate > date_sub(now(), interval 24 HOUR) AND dst like 'DESTINATION'" -H asteriskcdrdb | mail -s "$(echo -e "Custom Call Report\nContent-Type: text/html")" [email protected]
yes the first link is where I took the export CSV.
So it looks like that now the problem is just with the query. Can someone say me how to filter the database with only the last 10 minutes calls? I think this should be enough, right?
I have been looking in the asterisk documentation but the only file they seems to use is the /var/log/asterisk/cdr-csv/master.csv, but I tought that using freepbx was a better idea, if you think I should instead use the master.csv let me know
the -bs removes header names and columnar ‘decorations’ , replace the * with a csv list of columns that you want, ( a list of which from :- mysql asteriskcdrdb -e 'describe cdr')
Unfortunately I don’t have to necessary insight and knowledge to decide which solution (taking the data from FreePBX vs from Asterisk) would work better.
From a my simple point of view, since asterisk is under the hood of freePBX, maybe it would be better to use the master.csv, also I think that string manipulation would be faster than extraction ofthe data from mysql. But anyway I would like to hear the perspective of more experienced people
FreePBX is not involved in writing the cdr/cel records, it is purely Asterisk. Grouping records by date is built into mysql, csv records will need additional ‘function’ , python, perl, java etc. all have libraries to do that, but given the baked in nature of mysql used by FPBX to do it’s reporting, I would stick with mysql it’s ‘string manipulation’ is also fast and comprehensive.
actually I wasn’t able to find the -bs flag in the documentation of mysql
Anyway I saw that it is veryeasy to filter for col name,a s you said, example: SELECT calldate, ..., sequence FROM ....